3 #include "node_internal.h"
9 SLTTreeIteratorCallback callback
;
10 SLTTreeIteratorCallback postCallback
;
12 } TreeIteratorCallbackDetails
;
14 static SLTNode
*treeIterateCallback(SLTNode
*node
, void *extra
);
15 static SLTNode
*treeIteratePostCallback(SLTNode
*node
, void *extra
);
17 void sltTreeIterate(SLTNode
*root
, SLTTreeIteratorCallback callback
, SLTTreeIteratorCallback postCallback
, void *userParameter
) {
18 TreeIteratorCallbackDetails details
= {
20 .postCallback
= postCallback
,
21 .userParameter
= userParameter
,
23 sltTreeMap(root
, (callback
!= NULL
) ? treeIterateCallback
: NULL
, (postCallback
!= NULL
) ? treeIteratePostCallback
: NULL
, &details
);
26 SLTNode
*sltTreeMap(SLTNode
*root
, SLTTreeMapCallback callback
, SLTTreeMapCallback postCallback
, void *userParameter
){
29 if (callback
!= NULL
&& n
!= NULL
&& n
->type
!= SLTNodeTypeSequence
) {
30 n
= callback(n
, userParameter
);
36 case SLTNodeTypeUnknown
:
40 /* These have no child nodes */
41 case SLTNodeTypeIdentifier
:
42 case SLTNodeTypeInteger
:
43 case SLTNodeTypeFloat
:
44 case SLTNodeTypeString
:
45 case SLTNodeTypeOperator
:
48 case SLTNodeTypeCompound
:
49 n
->compoundSubexpression
= sltTreeMap(n
->compoundSubexpression
, callback
, postCallback
, userParameter
);
52 case SLTNodeTypeArgument
:
53 n
->argumentExpression
= sltTreeMap(n
->argumentExpression
, callback
, postCallback
, userParameter
);
56 case SLTNodeTypeArrayAccess
:
57 n
->arrayAccessArray
= sltTreeMap(n
->arrayAccessArray
, callback
, postCallback
, userParameter
);
58 n
->arrayAccessAccess
= sltTreeMap(n
->arrayAccessAccess
, callback
, postCallback
, userParameter
);
61 case SLTNodeTypeTypeAccess
:
62 n
->typeAccessType
= sltTreeMap(n
->typeAccessType
, callback
, postCallback
, userParameter
);
63 n
->typeAccessAccess
= sltTreeMap(n
->typeAccessAccess
, callback
, postCallback
, userParameter
);
66 case SLTNodeTypeFunctionCall
:
67 n
->functionCallFunction
= sltTreeMap(n
->functionCallFunction
, callback
, postCallback
, userParameter
);
68 n
->functionCallArguments
= sltTreeMap(n
->functionCallArguments
, callback
, postCallback
, userParameter
);
71 case SLTNodeTypeUnaryOperation
:
72 n
->unaryOperationOperator
= sltTreeMap(n
->unaryOperationOperator
, callback
, postCallback
, userParameter
);
73 n
->unaryOperationOperand
= sltTreeMap(n
->unaryOperationOperand
, callback
, postCallback
, userParameter
);
76 case SLTNodeTypeBinaryOperation
:
77 n
->binaryOperationOperator
= sltTreeMap(n
->binaryOperationOperator
, callback
, postCallback
, userParameter
);
78 n
->binaryOperationLHS
= sltTreeMap(n
->binaryOperationLHS
, callback
, postCallback
, userParameter
);
79 n
->binaryOperationRHS
= sltTreeMap(n
->binaryOperationRHS
, callback
, postCallback
, userParameter
);
82 case SLTNodeTypeAssignment
:
83 n
->assignmentTarget
= sltTreeMap(n
->assignmentTarget
, callback
, postCallback
, userParameter
);
84 n
->assignmentSource
= sltTreeMap(n
->assignmentSource
, callback
, postCallback
, userParameter
);
87 case SLTNodeTypeReturn
:
88 n
->returnExpression
= sltTreeMap(n
->returnExpression
, callback
, postCallback
, userParameter
);
91 //case SLTNodeTypeIteration:
92 case SLTNodeTypeForIteration
:
93 case SLTNodeTypeDoIteration
:
94 case SLTNodeTypeWhileIteration
:
95 n
->iterationInitialExpression
= sltTreeMap(n
->iterationInitialExpression
, callback
, postCallback
, userParameter
);
96 n
->iterationPreValidExpression
= sltTreeMap(n
->iterationPreValidExpression
, callback
, postCallback
, userParameter
);
97 n
->iterationPostValidExpression
= sltTreeMap(n
->iterationPostValidExpression
, callback
, postCallback
, userParameter
);
98 n
->iterationLoopExpression
= sltTreeMap(n
->iterationLoopExpression
, callback
, postCallback
, userParameter
);
99 n
->iterationStatement
= sltTreeMap(n
->iterationStatement
, callback
, postCallback
, userParameter
);
102 case SLTNodeTypeSelection
:
103 n
->selectionValidExpression
= sltTreeMap(n
->selectionValidExpression
, callback
, postCallback
, userParameter
);
104 n
->selectionValidStatement
= sltTreeMap(n
->selectionValidStatement
, callback
, postCallback
, userParameter
);
105 n
->selectionInvalidStatement
= sltTreeMap(n
->selectionInvalidStatement
, callback
, postCallback
, userParameter
);
108 case SLTNodeTypeStatementBlock
:
109 n
->statementBlockContents
= sltTreeMap(n
->statementBlockContents
, callback
, postCallback
, userParameter
);
112 case SLTNodeTypeVariableDefinition
:
113 n
->variableDefinitionType
= sltTreeMap(n
->variableDefinitionType
, callback
, postCallback
, userParameter
);
114 n
->variableDefinitionIdentifier
= sltTreeMap(n
->variableDefinitionIdentifier
, callback
, postCallback
, userParameter
);
115 n
->variableDefinitionDefaultExpression
= sltTreeMap(n
->variableDefinitionDefaultExpression
, callback
, postCallback
, userParameter
);
118 case SLTNodeTypeTypeDefinition
:
119 n
->typeDefinitionIdentifier
= sltTreeMap(n
->typeDefinitionIdentifier
, callback
, postCallback
, userParameter
);
120 n
->typeDefinitionMembers
= sltTreeMap(n
->typeDefinitionMembers
, callback
, postCallback
, userParameter
);
123 case SLTNodeTypeTypeMemberDefinition
:
124 n
->typeMemberDefinitionType
= sltTreeMap(n
->typeMemberDefinitionType
, callback
, postCallback
, userParameter
);
125 n
->typeMemberDefinitionIdentifier
= sltTreeMap(n
->typeMemberDefinitionIdentifier
, callback
, postCallback
, userParameter
);
128 case SLTNodeTypeFunctionDefinition
:
129 n
->functionDefinitionType
= sltTreeMap(n
->functionDefinitionType
, callback
, postCallback
, userParameter
);
130 n
->functionDefinitionIdentifier
= sltTreeMap(n
->functionDefinitionIdentifier
, callback
, postCallback
, userParameter
);
131 n
->functionDefinitionParameters
= sltTreeMap(n
->functionDefinitionParameters
, callback
, postCallback
, userParameter
);
132 n
->functionDefinitionBody
= sltTreeMap(n
->functionDefinitionBody
, callback
, postCallback
, userParameter
);
135 case SLTNodeTypeFunctionParameterDefinition
:
136 n
->functionParameterDefinitionType
= sltTreeMap(n
->functionParameterDefinitionType
, callback
, postCallback
, userParameter
);
137 n
->functionParameterDefinitionIdentifier
= sltTreeMap(n
->functionParameterDefinitionIdentifier
, callback
, postCallback
, userParameter
);
140 case SLTNodeTypeModule
:
141 n
->moduleStatementsAndDefinitions
= sltTreeMap(n
->moduleStatementsAndDefinitions
, callback
, postCallback
, userParameter
);
144 case SLTNodeTypeSequence
: {
145 SLTNode
*readHead
= n
;
146 SLTNode
*writeHead
= n
;
147 SLTNode
**writeLast
= &n
;
151 while (readHead
!= NULL
) {
152 writeHead
->sequenceNode
= sltTreeMap(readHead
->sequenceNode
, callback
, postCallback
, userParameter
);
153 readHead
= readHead
->sequenceNext
;
155 if (writeHead
->sequenceNode
!= NULL
) {
156 *writeLast
= writeHead
;
157 writeLast
= &writeHead
->sequenceNext
;
158 writeHead
= writeHead
->sequenceNext
;
168 if (postCallback
!= NULL
&& n
!= NULL
&& n
->type
!= SLTNodeTypeSequence
) {
169 n
= postCallback(n
, userParameter
);
175 SLTNode
*treeIterateCallback(SLTNode
*node
, void *extra
) {
176 TreeIteratorCallbackDetails
*details
= (TreeIteratorCallbackDetails
*)extra
;
177 details
->callback(node
, details
->userParameter
);
181 SLTNode
*treeIteratePostCallback(SLTNode
*node
, void *extra
) {
182 TreeIteratorCallbackDetails
*details
= (TreeIteratorCallbackDetails
*)extra
;
183 details
->postCallback(node
, details
->userParameter
);