* a collection of functions
* to copy pi's tree nodes
* get all the pi tree tags
/* constructs a ThreadNode to a declaration
* given an identifier char * symbol
struct nl
*symbp
= nllook( symbol
);
if ( symbp
== NIL
|| symbp
-> inTree
== pNIL
)
Thread
= pNewNode( ThreadTAG
, sizeof( struct ThreadNode
) );
pDEF( Thread
).ThreadPointer
= symbp
-> inTree
;
/* constructs a ThreadNode to a declaration
* given a namelist pointer
if ( nlp
== NIL
|| nlp
-> inTree
== pNIL
)
Thread
= pNewNode( ThreadTAG
, sizeof( struct ThreadNode
) );
pDEF( Thread
).ThreadPointer
= nlp
-> inTree
;
* copies a unary operator node to an appropriate pNode.
* unary operators come in two flavors,
* those with known constant operands (T_PLUSC and T_MINUSC),
* and those (T_PLUS, T_MINUS, and T_NOT)
* which carry around with them whether they have a constant operand
* unop [0] T_PLUSC, T_MINUSC or [0] T_PLUS, T_MINUS, T_NOT
* [1] expression [1] constant operand?
UnOp
= pNewNode( PlusTAG
, sizeof( struct PlusNode
) );
UnOp
= pNewNode( MinusTAG
, sizeof( struct MinusNode
) );
UnOp
= pNewNode( NotTAG
, sizeof( struct NotNode
) );
pDEF( UnOp
).UnOpExpr
= Expr
;
* returns an empty PtrTNode
* to be filled in by foredecl
pPointer PtrT
= pNewNode( PtrTTAG
, sizeof( struct PtrTNode
) );
pDEF( PtrT
).PtrTType
= pNIL
;
* copy a PACKED declaration to a PackTNode
pPointer PackT
= pNewNode( PackTTAG
, sizeof( struct PackTNode
) );
pPointer Type
= tCopy( typack
[2] );
pDEF( PackT
).PackTType
= Type
;
* copy a T_TYRANG node to a RangeTNode
pPointer RangeT
= pNewNode( RangeTTAG
, sizeof ( struct RangeTNode
) );
pPointer Lower
= tCopy( tyrang
[2] );
pPointer Upper
= tCopy( tyrang
[3] );
pDEF( RangeT
).RangeTLower
= Lower
;
pDEF( RangeT
).RangeTUpper
= Upper
;
* copy a T_TYARY node to an ArrayTNode
pPointer ArrayT
= pNewNode( ArrayTTAG
, sizeof( struct ArrayTNode
) );
pPointer Dims
= tCopy( tyary
[2] );
pPointer Type
= tCopy( tyary
[3] );
pDEF( ArrayT
).ArrayTDims
= Dims
;
pDEF( ArrayT
).ArrayTType
= Type
;
* copy a T_TYFILE node to a FileTNode
pPointer FileT
= pNewNode( FileTTAG
, sizeof( struct FileTNode
) );
pPointer Type
= tCopy( tyfile
[2] );
pDEF( FileT
).FileTType
= Type
;
* copy a T_TYSET node of a SetTNode
pPointer SetT
= pNewNode( SetTTAG
, sizeof( struct SetTNode
) );
pPointer Type
= tCopy( tyset
[2] );
pDEF( SetT
).SetTType
= Type
;
* copy an extended T_TYREC node to a RecTNode
* [2] pointer to field_list
* [3] >>pTree extension<< struct nl * to record in namelist
* sets extern inrecord so fields know in which record they are.
* saved previous inrecord to deal with nested records.
extern struct nl
*inrecord
;
pPointer RecT
= pNewNode( RecTTAG
, sizeof( struct RecTNode
) );
inrecord
= (struct nl
*) tyrec
[3];
Fldlst
= tCopy( tyrec
[2] );
pDEF( RecT
).RecTFldlst
= Fldlst
;
* copy an extended T_FLDLST node to a FldlstNode
* [2] fixed part (list of T_RFIELDs)
* [3] variant part (pointer to T_TYVARPT node)
pPointer Fldlst
= pNewNode( FldlstTAG
, sizeof( struct FldlstNode
) );
Fixed
= tCopy( fldlst
[2] );
Varpt
= tCopy( fldlst
[3] );
pDEF( Fldlst
).FldlstFixed
= Fixed
;
pDEF( Fldlst
).FldlstVariant
= Varpt
;
* copies a T_TYVARNT to a VCaseNode
* [3] nil or &(T_FLDLST node)
pPointer VCase
= pNewNode( VCaseTAG
, sizeof( struct VCaseNode
) );
pPointer Consts
= tCopy( tyvarnt
[2] );
pPointer Rec
= tCopy( tyvarnt
[3] );
pDEF( VCase
).VCaseConsts
= Consts
;
pDEF( VCase
).VCaseRec
= Rec
;
* copy a T_CSTAT to a CasedNode
pPointer Cased
= pNewNode( CasedTAG
, sizeof( struct CasedNode
) );
pPointer Label
= tCopy( cstat
[2] );
pPointer Stat
= tCopy( cstat
[3] );
pDEF( Cased
).CasedLabel
= Label
;
pDEF( Cased
).CasedStat
= Stat
;
* copy a T_LABEL to a ListNode
* whose ListUp is a LabelNode and
* whose ListDown is the labelled statement
* (cf. the hack in ListAppend )
* [2] hash of integer label
pPointer Label
= pNewNode( LabelTAG
, sizeof( struct LabelNode
) );
Stat
= tCopy( label
[3] );
pDEF( Label
).LabelLabel
= nllook( label
[2] ) -> inTree
;
List
= ListAppend( pNIL
, Stat
);
pDEF( List
).ListUp
= Label
;
* copy a T_PCALL node to a PCallNode
* [1] lineof yyline or "("
pPointer PCall
= pNewNode( PCallTAG
, sizeof( struct PCallNode
) );
pPointer Id
= ThreadSymbol( pcall
[2] );
pPointer Actuals
= tCopy( pcall
[3] );
pDEF( PCall
).PCallId
= Id
;
pDEF( PCall
).PCallActuals
= Actuals
;
* copy a T_CASE node to a CaseSNode
pPointer CaseS
= pNewNode( CaseSTAG
, sizeof( struct CaseSNode
) );
pPointer Expr
= tCopy( tcase
[2] );
pPointer Caselist
= tCopy( tcase
[3] );
pDEF( CaseS
).CaseSExpr
= Expr
;
pDEF( CaseS
).CaseSStat
= Caselist
;
* copy a T_WITH node to a WithNode
pPointer With
= pNewNode( WithTAG
, sizeof( struct WithNode
) );
pPointer Vars
= tCopy( with
[2] );
pPointer Stat
= tCopy( with
[3] );
pDEF( With
).WithVars
= Vars
;
pDEF( With
).WithStat
= Stat
;
* copy a T_WHILE node to a WhileNode
pPointer While
= pNewNode( WhileTAG
, sizeof( struct WhileNode
) );
pPointer Expr
= tCopy( twhile
[2] );
pPointer Stat
= tCopy( twhile
[3] );
pDEF( While
).WhileExpr
= Expr
;
pDEF( While
).WhileStat
= Stat
;
* copy a T_REPEAT node to a RepeatNode
pPointer Repeat
= pNewNode( RepeatTAG
, sizeof( struct RepeatNode
) );
pPointer Stat
= tCopy( trepeat
[2] );
pPointer Expr
= tCopy( trepeat
[3] );
pDEF( Repeat
).RepeatStat
= Stat
;
pDEF( Repeat
).RepeatExpr
= Expr
;
* copy a T_FORU or T_FORD node to a ForUNode or a ForDNode
* tfor [0] T_FORU or T_FORD
* [3] termination expression
For
= pNewNode( ForUTAG
, sizeof( struct ForUNode
) );
For
= pNewNode( ForDTAG
, sizeof( struct ForDNode
) );
Assign
= tCopy( tfor
[2] );
pDEF( For
).ForUAssign
= Assign
;
pDEF( For
).ForUExpr
= Expr
;
pDEF( For
).ForUStat
= Stat
;
* copy a T_FORD node to a ForDNode
* [3] termination expression
pPointer ForD
= pNewNode( ForDTAG
, sizeof( struct ForDNode
) );
pPointer Assign
= tCopy( ford
[2] );
pPointer Expr
= tCopy( ford
[3] );
pPointer Stat
= tCopy( ford
[4] );
pDEF( ForD
).ForDAssign
= Assign
;
pDEF( ForD
).ForDExpr
= Expr
;
pDEF( ForD
).ForDStat
= Stat
;
* copy a T_GOTO node to a GotoNode
* [2] hash of integer label
pPointer Goto
= pNewNode( GotoTAG
, sizeof( struct GotoNode
) );
pDEF( Goto
).GotoLabel
= nllook( tgoto
[2] ) -> inTree
;
* copy T_IF or T_IFEL nodes to IfNodes
pPointer If
= pNewNode( IfTAG
, sizeof( struct IfNode
) );
pPointer Cond
= tCopy( tif
[2] );
pPointer Then
= tCopy( tif
[3] );
pPointer Else
= tCopy( tif
[4] );
pDEF( If
).IfCond
= Cond
;
pDEF( If
).IfThen
= Then
;
pDEF( If
).IfElse
= Else
;
* copy a T_ASRT node to an AssertNode
pPointer Assert
= pNewNode( AssertTAG
, sizeof( struct AssertNode
) );
pPointer Expr
= tCopy( asrt
[2] );
pDEF( Assert
).AssertExpr
= Expr
;
* copy a T_ASGN node to an AssignNode
* [1] lineof ":" (of ":=")
pPointer Assign
= pNewNode( AssignTAG
, sizeof( struct AssignNode
) );
pPointer Var
= tCopy( asgn
[2] );
pPointer Expr
= tCopy( asgn
[3] );
pDEF( Assign
).AssignVar
= Var
;
pDEF( Assign
).AssignExpr
= Expr
;
* copy a binary operator to an appropriate pNode
* binop [0] T_EQ, T_LT, T_GT, T_LE, T_GE, T_NE,
* T_ADD, T_SUB, T_MULT, T_DIV, T_DIVD, T_MOD
* [2] left operand expression
* [3] right operand expression
BinOp
= pNewNode( EqTAG
, sizeof( struct EqNode
) );
BinOp
= pNewNode( LtTAG
, sizeof( struct LtNode
) );
BinOp
= pNewNode( GtTAG
, sizeof( struct GtNode
) );
BinOp
= pNewNode( LeTAG
, sizeof( struct LeNode
) );
BinOp
= pNewNode( GeTAG
, sizeof( struct GeNode
) );
BinOp
= pNewNode( NeTAG
, sizeof( struct NeNode
) );
BinOp
= pNewNode( AddTAG
, sizeof( struct AddNode
) );
BinOp
= pNewNode( SubTAG
, sizeof( struct SubNode
) );
BinOp
= pNewNode( MultTAG
, sizeof( struct MultNode
) );
BinOp
= pNewNode( DivTAG
, sizeof( struct DivNode
) );
BinOp
= pNewNode( DivdTAG
, sizeof( struct DivdNode
) );
BinOp
= pNewNode( ModTAG
, sizeof( struct ModNode
) );
BinOp
= pNewNode( InTAG
, sizeof( struct InNode
) );
BinOp
= pNewNode( OrTAG
, sizeof( struct OrNode
) );
BinOp
= pNewNode( AndTAG
, sizeof( struct AndNode
) );
Left
= tCopy( binop
[2] );
Right
= tCopy( binop
[3] );
pDEF( BinOp
).BinOpLeft
= Left
;
pDEF( BinOp
).BinOpRight
= Right
;
* copy a T_NIL node to a NilNode
pPointer Nil
= pNewNode( NilTAG
, 0 );
* copy an T_FCALL node to an FCallNode
* [3] actual expression list
pPointer FCall
= pNewNode( FCallTAG
, sizeof( struct FCallNode
) );
pPointer Id
= ThreadSymbol( fcall
[2] );
pPointer Actuals
= tCopy( fcall
[3] );
pDEF( FCall
).FCallId
= Id
;
pDEF( FCall
).FCallActuals
= Actuals
;
* copy a T_CSET node to a SetNode
pPointer Set
= pNewNode( SetTAG
, sizeof( struct SetNode
) );
pPointer Elements
= tCopy( cset
[2] );
pDEF( Set
).SetElements
= Elements
;
* copy a T_RANG node to a RangeNode
pPointer Range
= pNewNode( RangeTAG
, sizeof( struct RangeNode
) );
pPointer Lower
= tCopy( rang
[1] );
pPointer Upper
= tCopy( rang
[2] );
pDEF( Range
).RangeLower
= Lower
;
pDEF( Range
).RangeUpper
= Upper
;
* copies an extended T_VAR node to a VarNode
* [2] variable id (may be variable or field name in WITH)
* [3] qualifications list
* [4] >>pTree extension<< struct nl * or NIL.
* NIL if this is a real variable,
* otherwise we'd never find it in the right record.
pPointer Var
= pNewNode( VarTAG
, sizeof( struct VarNode
) );
pPointer Quals
= tCopy( var
[3] );
Id
= ThreadSymbol( var
[2] );
else Id
= ThreadName( var
[4] );
pDEF( Var
).VarQuals
= Quals
;
* copy a T_ARY qualification to a SubscNode
* [1] subscript expression list
pPointer Subsc
= pNewNode( SubscTAG
, sizeof( struct SubscNode
) );
pPointer Exprs
= tCopy( ary
[1] );
pDEF( Subsc
).SubscSubsc
= Exprs
;
* copy an extended T_FIELD qualification to a SelNode
* [3] >>pTree extension<< struct nl * to field
* otherwise we'd never know where it is
pPointer Sel
= pNewNode( SelTAG
, sizeof( struct SelNode
) );
pPointer Field
= ThreadName( field
[3] );
pDEF( Sel
).SelField
= Field
;
* copy a T_PTR qualification to a PtrNode
pPointer Ptr
= pNewNode( PtrTAG
, 0 );
* copy a T_WEXP node to a WidthNode and maybe an OctNode or a HexNode
* or expr : width : places
* [3] places or OCT or HEX
pPointer Width
= pNewNode( WidthTAG
, sizeof( struct WidthNode
) );
pPointer expr
= tCopy( wexp
[1] );
pPointer width
= tCopy( wexp
[2] );
pDEF( Width
).WidthExpr
= expr
;
pDEF( Width
).WidthWidth
= width
;
places
= tCopy( wexp
[3] );
radix
= pNewNode( OctTAG
, 0 );
radix
= pNewNode( HexTAG
, 0 );
pDEF( Width
).WidthPlaces
= places
;
pDEF( Width
).WidthRadix
= radix
;