Commit | Line | Data |
---|---|---|
bd98e2ac CH |
1 | /* |
2 | * pCopy.c | |
3 | * a collection of functions | |
4 | * to copy pi's tree nodes | |
5 | * to pTree pNodes. | |
6 | */ | |
7 | ||
8 | #include "whoami" | |
9 | ||
10 | #ifdef PTREE | |
11 | ||
12 | #include "0.h" | |
13 | ||
14 | /* | |
15 | * get all the pi tree tags | |
16 | */ | |
17 | #include "tree.h" | |
18 | ||
19 | /* constructs a ThreadNode to a declaration | |
20 | * given an identifier char * symbol | |
21 | */ | |
22 | pPointer | |
23 | ThreadSymbol( symbol ) | |
24 | char *symbol; | |
25 | { | |
26 | pPointer Thread; | |
27 | struct nl *symbp = nllook( symbol ); | |
28 | ||
29 | if ( symbp == NIL || symbp -> inTree == pNIL ) | |
30 | return pNIL; | |
31 | Thread = pNewNode( ThreadTAG , sizeof( struct ThreadNode ) ); | |
32 | pDEF( Thread ).ThreadPointer = symbp -> inTree; | |
33 | return Thread; | |
34 | } | |
35 | ||
36 | /* constructs a ThreadNode to a declaration | |
37 | * given a namelist pointer | |
38 | */ | |
39 | pPointer | |
40 | ThreadName( nlp ) | |
41 | struct nl *nlp; | |
42 | { | |
43 | pPointer Thread; | |
44 | ||
45 | if ( nlp == NIL || nlp -> inTree == pNIL ) | |
46 | return pNIL; | |
47 | Thread = pNewNode( ThreadTAG , sizeof( struct ThreadNode ) ); | |
48 | pDEF( Thread ).ThreadPointer = nlp -> inTree; | |
49 | return Thread; | |
50 | } | |
51 | ||
52 | /* | |
53 | * copies a unary operator node to an appropriate pNode. | |
54 | * unary operators come in two flavors, | |
55 | * those with known constant operands (T_PLUSC and T_MINUSC), | |
56 | * and those (T_PLUS, T_MINUS, and T_NOT) | |
57 | * which carry around with them whether they have a constant operand | |
58 | * unop [0] T_PLUSC, T_MINUSC or [0] T_PLUS, T_MINUS, T_NOT | |
59 | * [1] expression [1] constant operand? | |
60 | * [2] expression | |
61 | */ | |
62 | pPointer | |
63 | UnOpCopy( unop ) | |
64 | int *unop; | |
65 | { | |
66 | pPointer UnOp; | |
67 | pPointer Expr; | |
68 | ||
69 | switch ( unop[0] ) { | |
70 | case T_PLUSC: | |
71 | case T_PLUS: | |
72 | UnOp = pNewNode( PlusTAG , sizeof( struct PlusNode ) ); | |
73 | break; | |
74 | case T_MINUSC: | |
75 | case T_MINUS: | |
76 | UnOp = pNewNode( MinusTAG , sizeof( struct MinusNode ) ); | |
77 | break; | |
78 | case T_NOT: | |
79 | UnOp = pNewNode( NotTAG , sizeof( struct NotNode ) ); | |
80 | break; | |
81 | default: | |
82 | panic("UnOpCopy"); | |
83 | } | |
84 | switch ( unop[0] ) { | |
85 | case T_PLUSC: | |
86 | case T_MINUSC: | |
87 | Expr = tCopy( unop[1] ); | |
88 | break; | |
89 | case T_PLUS: | |
90 | case T_MINUS: | |
91 | case T_NOT: | |
92 | Expr = tCopy( unop[2] ); | |
93 | break; | |
94 | default: | |
95 | panic("UnOpCopy"); | |
96 | } | |
97 | pDEF( UnOp ).UnOpExpr = Expr; | |
98 | return UnOp; | |
99 | } | |
100 | ||
101 | /* | |
102 | * returns an empty PtrTNode | |
103 | * to be filled in by foredecl | |
104 | * typtr [0] T_TYPTR | |
105 | * [1] lineof "^" | |
106 | * [2][0] T_ID | |
107 | * [1] type name | |
108 | */ | |
109 | pPointer | |
110 | PtrTCopy( typtr ) | |
111 | int *typtr; | |
112 | { | |
113 | pPointer PtrT = pNewNode( PtrTTAG , sizeof( struct PtrTNode ) ); | |
114 | ||
115 | pDEF( PtrT ).PtrTType = pNIL; | |
116 | return PtrT; | |
117 | } | |
118 | ||
119 | /* | |
120 | * copy a PACKED declaration to a PackTNode | |
121 | * typack [0] T_TYPACK | |
122 | * [1] lineof "packed" | |
123 | * [2] structured type | |
124 | */ | |
125 | pPointer | |
126 | PackTCopy( typack ) | |
127 | int *typack; | |
128 | { | |
129 | pPointer PackT = pNewNode( PackTTAG , sizeof( struct PackTNode ) ); | |
130 | pPointer Type = tCopy( typack[2] ); | |
131 | ||
132 | pDEF( PackT ).PackTType = Type; | |
133 | return PackT; | |
134 | } | |
135 | ||
136 | /* | |
137 | * copy a T_TYRANG node to a RangeTNode | |
138 | * tyrang [0] T_TYRANG | |
139 | * [1] lineof ".." | |
140 | * [2] lower const | |
141 | * [3] upper const | |
142 | */ | |
143 | pPointer | |
144 | RangeTCopy( tyrang ) | |
145 | int *tyrang; | |
146 | { | |
147 | pPointer RangeT = pNewNode( RangeTTAG , sizeof ( struct RangeTNode ) ); | |
148 | pPointer Lower = tCopy( tyrang[2] ); | |
149 | pPointer Upper = tCopy( tyrang[3] ); | |
150 | ||
151 | pDEF( RangeT ).RangeTLower = Lower; | |
152 | pDEF( RangeT ).RangeTUpper = Upper; | |
153 | return RangeT; | |
154 | } | |
155 | ||
156 | /* | |
157 | * ArrayTCopy | |
158 | * copy a T_TYARY node to an ArrayTNode | |
159 | * tyary [0] T_TYARY | |
160 | * [1] lineof "array" | |
161 | * [2] simple_type_list | |
162 | * [3] type | |
163 | */ | |
164 | pPointer | |
165 | ArrayTCopy( tyary ) | |
166 | int *tyary; | |
167 | { | |
168 | pPointer ArrayT = pNewNode( ArrayTTAG , sizeof( struct ArrayTNode ) ); | |
169 | pPointer Dims = tCopy( tyary[2] ); | |
170 | pPointer Type = tCopy( tyary[3] ); | |
171 | ||
172 | pDEF( ArrayT ).ArrayTDims = Dims; | |
173 | pDEF( ArrayT ).ArrayTType = Type; | |
174 | return ArrayT; | |
175 | } | |
176 | ||
177 | /* | |
178 | * copy a T_TYFILE node to a FileTNode | |
179 | * tyfile [0] T_TYFILE | |
180 | * [1] lineof file | |
181 | * [2] type | |
182 | */ | |
183 | pPointer | |
184 | FileTCopy( tyfile ) | |
185 | int *tyfile; | |
186 | { | |
187 | pPointer FileT = pNewNode( FileTTAG , sizeof( struct FileTNode ) ); | |
188 | pPointer Type = tCopy( tyfile[2] ); | |
189 | ||
190 | pDEF( FileT ).FileTType = Type; | |
191 | return FileT; | |
192 | } | |
193 | ||
194 | /* | |
195 | * copy a T_TYSET node of a SetTNode | |
196 | * tyset [0] T_TYSET | |
197 | * [1] lineof "set" | |
198 | * [2] simple type | |
199 | */ | |
200 | pPointer | |
201 | SetTCopy( tyset ) | |
202 | int *tyset; | |
203 | { | |
204 | pPointer SetT = pNewNode( SetTTAG , sizeof( struct SetTNode ) ); | |
205 | pPointer Type = tCopy( tyset[2] ); | |
206 | ||
207 | pDEF( SetT ).SetTType = Type; | |
208 | return SetT; | |
209 | } | |
210 | ||
211 | /* | |
212 | * copy an extended T_TYREC node to a RecTNode | |
213 | * tyrec [0] T_TYREC | |
214 | * [1] lineof field_list | |
215 | * [2] pointer to field_list | |
216 | * [3] >>pTree extension<< struct nl * to record in namelist | |
217 | * sets extern inrecord so fields know in which record they are. | |
218 | * saved previous inrecord to deal with nested records. | |
219 | */ | |
220 | pPointer | |
221 | RecTCopy( tyrec ) | |
222 | int *tyrec; | |
223 | { | |
224 | extern struct nl *inrecord; | |
225 | struct nl *saverecord; | |
226 | pPointer RecT = pNewNode( RecTTAG , sizeof( struct RecTNode ) ); | |
227 | pPointer Fldlst; | |
228 | ||
229 | saverecord = inrecord; | |
230 | inrecord = (struct nl *) tyrec[3]; | |
231 | Fldlst = tCopy( tyrec[2] ); | |
232 | pDEF( RecT ).RecTFldlst = Fldlst; | |
233 | inrecord = saverecord; | |
234 | return RecT; | |
235 | } | |
236 | ||
237 | /* | |
238 | * copy an extended T_FLDLST node to a FldlstNode | |
239 | * fldlst [0] T_FLDLST | |
240 | * [1] 0 | |
241 | * [2] fixed part (list of T_RFIELDs) | |
242 | * [3] variant part (pointer to T_TYVARPT node) | |
243 | */ | |
244 | pPointer | |
245 | FldlstCopy( fldlst ) | |
246 | int *fldlst; | |
247 | { | |
248 | pPointer Fldlst = pNewNode( FldlstTAG , sizeof( struct FldlstNode ) ); | |
249 | pPointer Fixed; | |
250 | pPointer Varpt; | |
251 | ||
252 | Fixed = tCopy( fldlst[2] ); | |
253 | Varpt = tCopy( fldlst[3] ); | |
254 | pDEF( Fldlst ).FldlstFixed = Fixed; | |
255 | pDEF( Fldlst ).FldlstVariant = Varpt; | |
256 | return Fldlst; | |
257 | } | |
258 | ||
259 | /* | |
260 | * copies a T_TYVARNT to a VCaseNode | |
261 | * tyvarnt [0] T_TYVARNT | |
262 | * [1] lineof ":" | |
263 | * [2] constant list | |
264 | * [3] nil or &(T_FLDLST node) | |
265 | */ | |
266 | pPointer | |
267 | VCaseCopy( tyvarnt ) | |
268 | int *tyvarnt; | |
269 | { | |
270 | pPointer VCase = pNewNode( VCaseTAG , sizeof( struct VCaseNode ) ); | |
271 | pPointer Consts = tCopy( tyvarnt[2] ); | |
272 | pPointer Rec = tCopy( tyvarnt[3] ); | |
273 | ||
274 | pDEF( VCase ).VCaseConsts = Consts; | |
275 | pDEF( VCase ).VCaseRec = Rec; | |
276 | return VCase; | |
277 | } | |
278 | ||
279 | /* | |
280 | * copy a T_CSTAT to a CasedNode | |
281 | * cstat [0] T_CSTAT | |
282 | * [1] lineof ":" | |
283 | * [2] constant list | |
284 | * [3] statement | |
285 | */ | |
286 | pPointer | |
287 | CasedCopy( cstat ) | |
288 | int *cstat; | |
289 | { | |
290 | pPointer Cased = pNewNode( CasedTAG , sizeof( struct CasedNode ) ); | |
291 | pPointer Label = tCopy( cstat[2] ); | |
292 | pPointer Stat = tCopy( cstat[3] ); | |
293 | ||
294 | pDEF( Cased ).CasedLabel = Label; | |
295 | pDEF( Cased ).CasedStat = Stat; | |
296 | return Cased; | |
297 | } | |
298 | ||
299 | /* | |
300 | * copy a T_LABEL to a ListNode | |
301 | * whose ListUp is a LabelNode and | |
302 | * whose ListDown is the labelled statement | |
303 | * (cf. the hack in ListAppend ) | |
304 | * label [0] T_LABEL | |
305 | * [1] lineof : | |
306 | * [2] hash of integer label | |
307 | * [3] statement | |
308 | */ | |
309 | pPointer | |
310 | LabelCopy( label ) | |
311 | int *label; | |
312 | { | |
313 | pPointer List; | |
314 | pPointer Label = pNewNode( LabelTAG , sizeof( struct LabelNode ) ); | |
315 | pPointer Stat; | |
316 | ||
317 | Stat = tCopy( label[3] ); | |
318 | pDEF( Label ).LabelLabel = nllook( label[2] ) -> inTree; | |
319 | List = ListAppend( pNIL , Stat ); | |
320 | pDEF( List ).ListUp = Label; | |
321 | return List; | |
322 | } | |
323 | ||
324 | /* | |
325 | * copy a T_PCALL node to a PCallNode | |
326 | * pcall [0] T_PCALL | |
327 | * [1] lineof yyline or "(" | |
328 | * [2] proc_id | |
329 | * [3] actual list | |
330 | */ | |
331 | pPointer | |
332 | PCallCopy( pcall ) | |
333 | int *pcall; | |
334 | { | |
335 | pPointer PCall = pNewNode( PCallTAG , sizeof( struct PCallNode ) ); | |
336 | pPointer Id = ThreadSymbol( pcall[2] ); | |
337 | pPointer Actuals = tCopy( pcall[3] ); | |
338 | ||
339 | pDEF( PCall ).PCallId = Id; | |
340 | pDEF( PCall ).PCallActuals = Actuals; | |
341 | return PCall; | |
342 | } | |
343 | ||
344 | /* | |
345 | * copy a T_CASE node to a CaseSNode | |
346 | * tcase [0] T_CASE | |
347 | * [1] lineof "case" | |
348 | * [2] expression | |
349 | * [3] list of cases | |
350 | */ | |
351 | pPointer | |
352 | CaseSCopy( tcase ) | |
353 | int *tcase; | |
354 | { | |
355 | pPointer CaseS = pNewNode( CaseSTAG , sizeof( struct CaseSNode ) ); | |
356 | pPointer Expr = tCopy( tcase[2] ); | |
357 | pPointer Caselist = tCopy( tcase[3] ); | |
358 | ||
359 | pDEF( CaseS ).CaseSExpr = Expr; | |
360 | pDEF( CaseS ).CaseSStat = Caselist; | |
361 | return CaseS; | |
362 | } | |
363 | ||
364 | /* | |
365 | * copy a T_WITH node to a WithNode | |
366 | * with [0] T_WITH | |
367 | * [1] lineof "with" | |
368 | * [2] variable list | |
369 | * [3] statement | |
370 | */ | |
371 | pPointer | |
372 | WithCopy( with ) | |
373 | int *with; | |
374 | { | |
375 | pPointer With = pNewNode( WithTAG , sizeof( struct WithNode ) ); | |
376 | pPointer Vars = tCopy( with[2] ); | |
377 | pPointer Stat = tCopy( with[3] ); | |
378 | ||
379 | pDEF( With ).WithVars = Vars; | |
380 | pDEF( With ).WithStat = Stat; | |
381 | return With; | |
382 | } | |
383 | ||
384 | /* | |
385 | * copy a T_WHILE node to a WhileNode | |
386 | * twhile [0] T_WHILE | |
387 | * [1] lineof "while" | |
388 | * [2] expression | |
389 | * [3] statement | |
390 | */ | |
391 | pPointer | |
392 | WhileCopy( twhile ) | |
393 | int *twhile; | |
394 | { | |
395 | pPointer While = pNewNode( WhileTAG , sizeof( struct WhileNode ) ); | |
396 | pPointer Expr = tCopy( twhile[2] ); | |
397 | pPointer Stat = tCopy( twhile[3] ); | |
398 | ||
399 | pDEF( While ).WhileExpr = Expr; | |
400 | pDEF( While ).WhileStat = Stat; | |
401 | return While; | |
402 | } | |
403 | ||
404 | /* | |
405 | * copy a T_REPEAT node to a RepeatNode | |
406 | * trepeat [0] T_REPEAT | |
407 | * [1] lineof "repeat" | |
408 | * [2] statement list | |
409 | * [3] expression | |
410 | */ | |
411 | pPointer | |
412 | RepeatCopy( trepeat ) | |
413 | int *trepeat; | |
414 | { | |
415 | pPointer Repeat = pNewNode( RepeatTAG , sizeof( struct RepeatNode ) ); | |
416 | pPointer Stat = tCopy( trepeat[2] ); | |
417 | pPointer Expr = tCopy( trepeat[3] ); | |
418 | ||
419 | pDEF( Repeat ).RepeatStat = Stat; | |
420 | pDEF( Repeat ).RepeatExpr = Expr; | |
421 | return Repeat; | |
422 | } | |
423 | ||
424 | /* | |
425 | * copy a T_FORU or T_FORD node to a ForUNode or a ForDNode | |
426 | * tfor [0] T_FORU or T_FORD | |
427 | * [1] lineof "for" | |
428 | * [2] assignment | |
429 | * [3] termination expression | |
430 | * [4] statement | |
431 | */ | |
432 | pPointer | |
433 | ForCopy( tfor ) | |
434 | int *tfor; | |
435 | { | |
436 | pPointer For; | |
437 | pPointer Assign; | |
438 | pPointer Expr; | |
439 | pPointer Stat; | |
440 | ||
441 | switch ( tfor[0] ) { | |
442 | case T_FORU: | |
443 | For = pNewNode( ForUTAG , sizeof( struct ForUNode ) ); | |
444 | break; | |
445 | case T_FORD: | |
446 | For = pNewNode( ForDTAG , sizeof( struct ForDNode ) ); | |
447 | break; | |
448 | default: | |
449 | panic("ForCopy"); | |
450 | } | |
451 | Assign = tCopy( tfor[2] ); | |
452 | Expr = tCopy( tfor[3] ); | |
453 | Stat = tCopy( tfor[4] ); | |
454 | pDEF( For ).ForUAssign = Assign; | |
455 | pDEF( For ).ForUExpr = Expr; | |
456 | pDEF( For ).ForUStat = Stat; | |
457 | return For; | |
458 | } | |
459 | ||
460 | /* | |
461 | * copy a T_FORD node to a ForDNode | |
462 | * ford [0] T_FORD | |
463 | * [1] lineof "for" | |
464 | * [2] assignment | |
465 | * [3] termination expression | |
466 | * [4] statement | |
467 | */ | |
468 | pPointer | |
469 | ForDCopy( ford ) | |
470 | int *ford; | |
471 | { | |
472 | pPointer ForD = pNewNode( ForDTAG , sizeof( struct ForDNode ) ); | |
473 | pPointer Assign = tCopy( ford[2] ); | |
474 | pPointer Expr = tCopy( ford[3] ); | |
475 | pPointer Stat = tCopy( ford[4] ); | |
476 | ||
477 | pDEF( ForD ).ForDAssign = Assign; | |
478 | pDEF( ForD ).ForDExpr = Expr; | |
479 | pDEF( ForD ).ForDStat = Stat; | |
480 | return ForD; | |
481 | } | |
482 | ||
483 | /* | |
484 | * copy a T_GOTO node to a GotoNode | |
485 | * tgoto [0] T_GOTO | |
486 | * [1] lineof "goto" | |
487 | * [2] hash of integer label | |
488 | */ | |
489 | pPointer | |
490 | GotoCopy( tgoto ) | |
491 | int *tgoto; | |
492 | { | |
493 | pPointer Goto = pNewNode( GotoTAG , sizeof( struct GotoNode ) ); | |
494 | ||
495 | pDEF( Goto ).GotoLabel = nllook( tgoto[2] ) -> inTree; | |
496 | return Goto; | |
497 | } | |
498 | ||
499 | /* | |
500 | * copy T_IF or T_IFEL nodes to IfNodes | |
501 | * tif [0] T_IF or T_IFEL | |
502 | * [1] lineof "if" | |
503 | * [2] expression | |
504 | * [3] then statement | |
505 | * [4] else statement | |
506 | */ | |
507 | pPointer | |
508 | IfCopy( tif ) | |
509 | int *tif; | |
510 | { | |
511 | pPointer If = pNewNode( IfTAG , sizeof( struct IfNode ) ); | |
512 | pPointer Cond = tCopy( tif[2] ); | |
513 | pPointer Then = tCopy( tif[3] ); | |
514 | pPointer Else = tCopy( tif[4] ); | |
515 | ||
516 | pDEF( If ).IfCond = Cond; | |
517 | pDEF( If ).IfThen = Then; | |
518 | pDEF( If ).IfElse = Else; | |
519 | return If; | |
520 | } | |
521 | ||
522 | /* | |
523 | * copy a T_ASRT node to an AssertNode | |
524 | * asrt [0] T_ASRT | |
525 | * [1] lineof "assert" | |
526 | * [2] expression | |
527 | */ | |
528 | pPointer | |
529 | AssertCopy( asrt ) | |
530 | int *asrt; | |
531 | { | |
532 | pPointer Assert = pNewNode( AssertTAG , sizeof( struct AssertNode ) ); | |
533 | pPointer Expr = tCopy( asrt[2] ); | |
534 | ||
535 | pDEF( Assert ).AssertExpr = Expr; | |
536 | return Assert; | |
537 | } | |
538 | ||
539 | /* | |
540 | * copy a T_ASGN node to an AssignNode | |
541 | * asgn [0] T_ASGN | |
542 | * [1] lineof ":" (of ":=") | |
543 | * [2] variable | |
544 | * [3] expression | |
545 | */ | |
546 | pPointer | |
547 | AssignCopy( asgn ) | |
548 | int *asgn; | |
549 | { | |
550 | pPointer Assign = pNewNode( AssignTAG , sizeof( struct AssignNode ) ); | |
551 | pPointer Var = tCopy( asgn[2] ); | |
552 | pPointer Expr = tCopy( asgn[3] ); | |
553 | ||
554 | pDEF( Assign ).AssignVar = Var; | |
555 | pDEF( Assign ).AssignExpr = Expr; | |
556 | return Assign; | |
557 | } | |
558 | ||
559 | /* | |
560 | * copy a binary operator to an appropriate pNode | |
561 | * binop [0] T_EQ, T_LT, T_GT, T_LE, T_GE, T_NE, | |
562 | * T_ADD, T_SUB, T_MULT, T_DIV, T_DIVD, T_MOD | |
563 | * T_IN, T_OR, T_AND | |
564 | * [1] SAWCON | |
565 | * [2] left operand expression | |
566 | * [3] right operand expression | |
567 | */ | |
568 | pPointer | |
569 | BinOpCopy( binop ) | |
570 | int *binop; | |
571 | { | |
572 | pPointer BinOp; | |
573 | pPointer Left; | |
574 | pPointer Right; | |
575 | ||
576 | switch ( binop[0] ) { | |
577 | case T_EQ: | |
578 | BinOp = pNewNode( EqTAG , sizeof( struct EqNode ) ); | |
579 | break; | |
580 | case T_LT: | |
581 | BinOp = pNewNode( LtTAG , sizeof( struct LtNode ) ); | |
582 | break; | |
583 | case T_GT: | |
584 | BinOp = pNewNode( GtTAG , sizeof( struct GtNode ) ); | |
585 | break; | |
586 | case T_LE: | |
587 | BinOp = pNewNode( LeTAG , sizeof( struct LeNode ) ); | |
588 | break; | |
589 | case T_GE: | |
590 | BinOp = pNewNode( GeTAG , sizeof( struct GeNode ) ); | |
591 | break; | |
592 | case T_NE: | |
593 | BinOp = pNewNode( NeTAG , sizeof( struct NeNode ) ); | |
594 | break; | |
595 | case T_ADD: | |
596 | BinOp = pNewNode( AddTAG , sizeof( struct AddNode ) ); | |
597 | break; | |
598 | case T_SUB: | |
599 | BinOp = pNewNode( SubTAG , sizeof( struct SubNode ) ); | |
600 | break; | |
601 | case T_MULT: | |
602 | BinOp = pNewNode( MultTAG , sizeof( struct MultNode ) ); | |
603 | break; | |
604 | case T_DIV: | |
605 | BinOp = pNewNode( DivTAG , sizeof( struct DivNode ) ); | |
606 | break; | |
607 | case T_DIVD: | |
608 | BinOp = pNewNode( DivdTAG , sizeof( struct DivdNode ) ); | |
609 | break; | |
610 | case T_MOD: | |
611 | BinOp = pNewNode( ModTAG , sizeof( struct ModNode ) ); | |
612 | break; | |
613 | case T_IN: | |
614 | BinOp = pNewNode( InTAG , sizeof( struct InNode ) ); | |
615 | break; | |
616 | case T_OR: | |
617 | BinOp = pNewNode( OrTAG , sizeof( struct OrNode ) ); | |
618 | break; | |
619 | case T_AND: | |
620 | BinOp = pNewNode( AndTAG , sizeof( struct AndNode ) ); | |
621 | break; | |
622 | default: | |
623 | panic("BinOpCopy"); | |
624 | } | |
625 | Left = tCopy( binop[2] ); | |
626 | Right = tCopy( binop[3] ); | |
627 | pDEF( BinOp ).BinOpLeft = Left; | |
628 | pDEF( BinOp ).BinOpRight = Right; | |
629 | return BinOp; | |
630 | } | |
631 | ||
632 | /* | |
633 | * copy a T_NIL node to a NilNode | |
634 | * tnil [0] T_NIL | |
635 | * [1] NOCON | |
636 | */ | |
637 | pPointer | |
638 | NilCopy( tnil ) | |
639 | int *tnil; | |
640 | { | |
641 | pPointer Nil = pNewNode( NilTAG , 0 ); | |
642 | ||
643 | return Nil; | |
644 | } | |
645 | ||
646 | /* | |
647 | * copy an T_FCALL node to an FCallNode | |
648 | * fcall [0] T_FCALL | |
649 | * [1] NOCON | |
650 | * [2] func_id | |
651 | * [3] actual expression list | |
652 | */ | |
653 | pPointer | |
654 | FCallCopy( fcall ) | |
655 | int *fcall; | |
656 | { | |
657 | pPointer FCall = pNewNode( FCallTAG , sizeof( struct FCallNode ) ); | |
658 | pPointer Id = ThreadSymbol( fcall[2] ); | |
659 | pPointer Actuals = tCopy( fcall[3] ); | |
660 | ||
661 | pDEF( FCall ).FCallId = Id; | |
662 | pDEF( FCall ).FCallActuals = Actuals; | |
663 | return FCall; | |
664 | } | |
665 | ||
666 | /* | |
667 | * copy a T_CSET node to a SetNode | |
668 | * cset [0] T_CSET | |
669 | * [1] SAWCON | |
670 | * [2] element list | |
671 | */ | |
672 | pPointer | |
673 | SetCopy( cset ) | |
674 | int *cset; | |
675 | { | |
676 | pPointer Set = pNewNode( SetTAG , sizeof( struct SetNode ) ); | |
677 | pPointer Elements = tCopy( cset[2] ); | |
678 | ||
679 | pDEF( Set ).SetElements = Elements; | |
680 | return Set; | |
681 | } | |
682 | ||
683 | /* | |
684 | * copy a T_RANG node to a RangeNode | |
685 | * rang [0] T_RANG | |
686 | * [1] lower limit | |
687 | * [2] upper limit | |
688 | */ | |
689 | pPointer | |
690 | RangeCopy( rang ) | |
691 | int *rang; | |
692 | { | |
693 | pPointer Range = pNewNode( RangeTAG , sizeof( struct RangeNode ) ); | |
694 | pPointer Lower = tCopy( rang[1] ); | |
695 | pPointer Upper = tCopy( rang[2] ); | |
696 | ||
697 | pDEF( Range ).RangeLower = Lower; | |
698 | pDEF( Range ).RangeUpper = Upper; | |
699 | return Range; | |
700 | } | |
701 | ||
702 | /* | |
703 | * copies an extended T_VAR node to a VarNode | |
704 | * var [0] T_VAR | |
705 | * [1] NOCON | |
706 | * [2] variable id (may be variable or field name in WITH) | |
707 | * [3] qualifications list | |
708 | * [4] >>pTree extension<< struct nl * or NIL. | |
709 | * NIL if this is a real variable, | |
710 | * struct nl * to field, | |
711 | * otherwise we'd never find it in the right record. | |
712 | * see setupvar | |
713 | */ | |
714 | pPointer | |
715 | VarCopy( var ) | |
716 | int *var; | |
717 | { | |
718 | pPointer Var = pNewNode( VarTAG , sizeof( struct VarNode ) ); | |
719 | pPointer Id; | |
720 | pPointer Quals = tCopy( var[3] ); | |
721 | ||
722 | if ( var[4] == NIL ) | |
723 | Id = ThreadSymbol( var[2] ); | |
724 | else Id = ThreadName( var[4] ); | |
725 | pDEF( Var ).VarId = Id; | |
726 | pDEF( Var ).VarQuals = Quals; | |
727 | return Var; | |
728 | } | |
729 | ||
730 | /* | |
731 | * copy a T_ARY qualification to a SubscNode | |
732 | * ary [0] T_ARY | |
733 | * [1] subscript expression list | |
734 | */ | |
735 | pPointer | |
736 | SubscCopy( ary ) | |
737 | int *ary; | |
738 | { | |
739 | pPointer Subsc = pNewNode( SubscTAG , sizeof( struct SubscNode ) ); | |
740 | pPointer Exprs = tCopy( ary[1] ); | |
741 | ||
742 | pDEF( Subsc ).SubscSubsc = Exprs; | |
743 | return Subsc; | |
744 | } | |
745 | ||
746 | /* | |
747 | * copy an extended T_FIELD qualification to a SelNode | |
748 | * field [0] T_FIELD | |
749 | * [1] field_id | |
750 | * [2] NIL | |
751 | * [3] >>pTree extension<< struct nl * to field | |
752 | * otherwise we'd never know where it is | |
753 | * put in by lvalue | |
754 | */ | |
755 | pPointer | |
756 | SelCopy( field ) | |
757 | int *field; | |
758 | { | |
759 | pPointer Sel = pNewNode( SelTAG , sizeof( struct SelNode ) ); | |
760 | pPointer Field = ThreadName( field[3] ); | |
761 | ||
762 | pDEF( Sel ).SelField = Field; | |
763 | return Sel; | |
764 | } | |
765 | ||
766 | /* | |
767 | * copy a T_PTR qualification to a PtrNode | |
768 | * ptr [0] T_PTR | |
769 | */ | |
770 | pPointer | |
771 | PtrCopy( ptr ) | |
772 | int *ptr; | |
773 | { | |
774 | pPointer Ptr = pNewNode( PtrTAG , 0 ); | |
775 | ||
776 | return Ptr; | |
777 | } | |
778 | ||
779 | /* | |
780 | * copy a T_WEXP node to a WidthNode and maybe an OctNode or a HexNode | |
781 | * for expr : width | |
782 | * or expr : width : places | |
783 | * or expr radix | |
784 | * or expr : width radix | |
785 | * wexp [0] T_WEXP | |
786 | * [1] expr | |
787 | * [2] width or NIL | |
788 | * [3] places or OCT or HEX | |
789 | */ | |
790 | pPointer | |
791 | WidthCopy( wexp ) | |
792 | int *wexp; | |
793 | { | |
794 | pPointer Width = pNewNode( WidthTAG , sizeof( struct WidthNode ) ); | |
795 | pPointer expr = tCopy( wexp[1] ); | |
796 | pPointer width = tCopy( wexp[2] ); | |
797 | pPointer places; | |
798 | pPointer radix; | |
799 | ||
800 | pDEF( Width ).WidthExpr = expr; | |
801 | pDEF( Width ).WidthWidth = width; | |
802 | switch ( wexp[3] ) { | |
803 | default: | |
804 | places = tCopy( wexp[3] ); | |
805 | radix = pNIL; | |
806 | break; | |
807 | case OCT: | |
808 | places = pNIL; | |
809 | radix = pNewNode( OctTAG , 0 ); | |
810 | break; | |
811 | case HEX: | |
812 | places = pNIL; | |
813 | radix = pNewNode( HexTAG , 0 ); | |
814 | break; | |
815 | } | |
816 | pDEF( Width ).WidthPlaces = places; | |
817 | pDEF( Width ).WidthRadix = radix; | |
818 | return Width; | |
819 | } | |
820 | ||
821 | #endif PTREE |