1 using System;
2 using System.Collections;
3
4
5
6
7
8 namespace soulcm.scmpg
9 {
10 public class CodeEvaluationVisitor : Cm.Ast.Visitor
11 {
12 public CodeEvaluationVisitor() :
13 hasReturn(false), hasPass(false), hasSpan(false)
14 {
15 }
16 public bool HasReturn() const
17 {
18 return hasReturn;
19 }
20 public bool HasPass() const
21 {
22 return hasPass;
23 }
24 public bool HasSpan() const
25 {
26 return hasSpan;
27 }
28 public override void Visit(Cm.Ast.LabeledStatementNode& labeledStatementNode)
29 {
30 labeledStatementNode.Stmt()->Accept(*this);
31 }
32 public override void Visit(Cm.Ast.CompoundStatementNode& compoundStatementNode)
33 {
34 int n = compoundStatementNode.Statements().Count();
35 for (int i = 0; i < n; ++i;)
36 {
37 compoundStatementNode.Statements()[i]->Accept(*this);
38 }
39 }
40 public override void Visit(Cm.Ast.ReturnStatementNode& returnStatementNode)
41 {
42 hasReturn = true;
43 returnStatementNode.Expression()->Accept(*this);
44 }
45 public override void Visit(Cm.Ast.IfStatementNode& ifStatementNode)
46 {
47 ifStatementNode.Condition()->Accept(*this);
48 ifStatementNode.ThenS()->Accept(*this);
49 if ((ifStatementNode.ElseS() != null))
50 {
51 ifStatementNode.ElseS()->Accept(*this);
52 }
53 }
54 public override void Visit(Cm.Ast.WhileStatementNode& whileStatementNode)
55 {
56 whileStatementNode.Condition()->Accept(*this);
57 whileStatementNode.Statement()->Accept(*this);
58 }
59 public override void Visit(Cm.Ast.DoStatementNode& doStatementNode)
60 {
61 doStatementNode.Statement()->Accept(*this);
62 doStatementNode.Condition()->Accept(*this);
63 }
64 public override void Visit(Cm.Ast.ForStatementNode& forStatementNode)
65 {
66 forStatementNode.InitS()->Accept(*this);
67 if ((forStatementNode.Condition() != null))
68 {
69 forStatementNode.Condition()->Accept(*this);
70 }
71 forStatementNode.LoopS()->Accept(*this);
72 forStatementNode.ActionS()->Accept(*this);
73 }
74 public override void Visit(Cm.Ast.BreakStatementNode& breakStatementNode)
75 {
76 }
77 public override void Visit(Cm.Ast.ContinueStatementNode& continueStatementNode)
78 {
79 }
80 public override void Visit(Cm.Ast.GotoStatementNode& gotoStatementNode)
81 {
82 }
83 public override void Visit(Cm.Ast.ConstructionStatementNode& constructionStatementNode)
84 {
85 constructionStatementNode.TypeExpr()->Accept(*this);
86 constructionStatementNode.Id()->Accept(*this);
87 int n = constructionStatementNode.Arguments().Count();
88 for (int i = 0; i < n; ++i;)
89 {
90 constructionStatementNode.Arguments()[i]->Accept(*this);
91 }
92 }
93 public override void Visit(Cm.Ast.DeleteStatementNode& deleteStatementNode)
94 {
95 deleteStatementNode.Expression()->Accept(*this);
96 }
97 public override void Visit(Cm.Ast.DestroyStatementNode& destroyStatementNode)
98 {
99 destroyStatementNode.Expression()->Accept(*this);
100 }
101 public override void Visit(Cm.Ast.AssignmentStatementNode& assignmentStatementNode)
102 {
103 assignmentStatementNode.SourceExpr()->Accept(*this);
104 assignmentStatementNode.TargetExpr()->Accept(*this);
105 }
106 public override void Visit(Cm.Ast.ExpressionStatementNode& expressionStatementNode)
107 {
108 expressionStatementNode.Expression()->Accept(*this);
109 }
110 public override void Visit(Cm.Ast.EmptyStatementNode& emptyStatementNode)
111 {
112 }
113 public override void Visit(Cm.Ast.RangeForStatementNode& rangeForStatementNode)
114 {
115 rangeForStatementNode.TypeExpr()->Accept(*this);
116 rangeForStatementNode.Id()->Accept(*this);
117 rangeForStatementNode.Container()->Accept(*this);
118 rangeForStatementNode.Action()->Accept(*this);
119 }
120 public override void Visit(Cm.Ast.SwitchStatementNode& switchStatementNode)
121 {
122 switchStatementNode.Condition()->Accept(*this);
123 int n = switchStatementNode.Cases().Count();
124 for (int i = 0; i < n; ++i;)
125 {
126 switchStatementNode.Cases()[i]->Accept(*this);
127 }
128 if ((switchStatementNode.Default() != null))
129 {
130 switchStatementNode.Default()->Accept(*this);
131 }
132 }
133 public override void Visit(Cm.Ast.CaseStatementNode& caseStatementNode)
134 {
135 int nc = caseStatementNode.CaseExprs().Count();
136 for (int i = 0; i < nc; ++i;)
137 {
138 caseStatementNode.CaseExprs()[i]->Accept(*this);
139 }
140 int n = caseStatementNode.Statements().Count();
141 for (int i = 0; i < n; ++i;)
142 {
143 caseStatementNode.Statements()[i]->Accept(*this);
144 }
145 }
146 public override void Visit(Cm.Ast.DefaultStatementNode& defaultStatementNode)
147 {
148 int n = defaultStatementNode.Statements().Count();
149 for (int i = 0; i < n; ++i;)
150 {
151 defaultStatementNode.Statements()[i]->Accept(*this);
152 }
153 }
154 public override void Visit(Cm.Ast.GotoCaseStatementNode& gotoCaseStatementNode)
155 {
156 gotoCaseStatementNode.CaseExpr()->Accept(*this);
157 }
158 public override void Visit(Cm.Ast.GotoDefaultStatementNode& gotoDefaultStatementNode)
159 {
160 }
161 public override void Visit(Cm.Ast.ThrowStatementNode& throwStatementNode)
162 {
163 throwStatementNode.Expression()->Accept(*this);
164 }
165 public override void Visit(Cm.Ast.TryStatementNode& tryStatementNode)
166 {
167 tryStatementNode.TryBlock()->Accept(*this);
168 int n = tryStatementNode.Catches().Count();
169 for (int i = 0; i < n; ++i;)
170 {
171 tryStatementNode.Catches()[i]->Accept(*this);
172 }
173 }
174 public override void Visit(Cm.Ast.CatchNode& catchNode)
175 {
176 catchNode.TypeExpr()->Accept(*this);
177 catchNode.Id()->Accept(*this);
178 catchNode.CatchBlock()->Accept(*this);
179 }
180 public override void Visit(Cm.Ast.AssertStatementNode& assertStatementNode)
181 {
182 assertStatementNode.AssertExpr()->Accept(*this);
183 }
184 public override void Visit(Cm.Ast.ConditionalCompilationPartNode& conditionalCompilationPartNode)
185 {
186 conditionalCompilationPartNode.Expr()->Accept(*this);
187 int n = conditionalCompilationPartNode.Statements().Count();
188 for (int i = 0; i < n; ++i;)
189 {
190 conditionalCompilationPartNode.Statements()[i]->Accept(*this);
191 }
192 }
193 public override void Visit(Cm.Ast.ConditionalCompilationDisjunctionNode& conditionalCompilationDisjunctionNode)
194 {
195 conditionalCompilationDisjunctionNode.Left()->Accept(*this);
196 conditionalCompilationDisjunctionNode.Right()->Accept(*this);
197 }
198 public override void Visit(Cm.Ast.ConditionalCompilationConjunctionNode& conditionalCompilationConjunctionNode)
199 {
200 conditionalCompilationConjunctionNode.Left()->Accept(*this);
201 conditionalCompilationConjunctionNode.Right()->Accept(*this);
202 }
203 public override void Visit(Cm.Ast.ConditionalCompilationNotNode& conditionalCompilationNotNode)
204 {
205 conditionalCompilationNotNode.Expr()->Accept(*this);
206 }
207 public override void Visit(Cm.Ast.ConditionalCompilationPrimaryNode& conditionalCompilationPrimaryNode)
208 {
209 }
210 public override void Visit(Cm.Ast.ParenthesizedConditionalCompilationExpressionNode& parenthesizeCondCompExprNode)
211 {
212 parenthesizeCondCompExprNode.Expr()->Accept(*this);
213 }
214 public override void Visit(Cm.Ast.ConditionalCompilationStatementNode& conditionalCompilationStatementNode)
215 {
216 conditionalCompilationStatementNode.IfPart()->Accept(*this);
217 int ne = conditionalCompilationStatementNode.ElifParts().Count();
218 for (int i = 0; i < ne; ++i;)
219 {
220 conditionalCompilationStatementNode.ElifParts()[i]->Accept(*this);
221 }
222 if ((conditionalCompilationStatementNode.ElsePart() != null))
223 {
224 conditionalCompilationStatementNode.ElsePart()->Accept(*this);
225 }
226 }
227 public override void Visit(Cm.Ast.ConstNode& constNode)
228 {
229 constNode.Subject()->Accept(*this);
230 }
231 public override void Visit(Cm.Ast.LValueRefNode& lvalueRefNode)
232 {
233 lvalueRefNode.Subject()->Accept(*this);
234 }
235 public override void Visit(Cm.Ast.RValueRefNode& rvalueRefNode)
236 {
237 rvalueRefNode.Subject()->Accept(*this);
238 }
239 public override void Visit(Cm.Ast.PointerNode& pointerNode)
240 {
241 pointerNode.Subject()->Accept(*this);
242 }
243 public override void Visit(Cm.Ast.ArrayNode& arrayNode)
244 {
245 arrayNode.Subject()->Accept(*this);
246 if ((arrayNode.Size() != null))
247 {
248 arrayNode.Size()->Accept(*this);
249 }
250 }
251 public override void Visit(Cm.Ast.DotNode& dotNode)
252 {
253 dotNode.Subject()->Accept(*this);
254 dotNode.MemberId()->Accept(*this);
255 }
256 public override void Visit(Cm.Ast.ArrowNode& arrowNode)
257 {
258 arrowNode.Subject()->Accept(*this);
259 arrowNode.MemberId()->Accept(*this);
260 }
261 public override void Visit(Cm.Ast.EquivalenceNode& equivalenceNode)
262 {
263 equivalenceNode.Left()->Accept(*this);
264 equivalenceNode.Right()->Accept(*this);
265 }
266 public override void Visit(Cm.Ast.ImplicationNode& implicationNode)
267 {
268 implicationNode.Left()->Accept(*this);
269 implicationNode.Right()->Accept(*this);
270 }
271 public override void Visit(Cm.Ast.DisjunctionNode& disjunctionNode)
272 {
273 disjunctionNode.Left()->Accept(*this);
274 disjunctionNode.Right()->Accept(*this);
275 }
276 public override void Visit(Cm.Ast.ConjunctionNode& conjunctionNode)
277 {
278 conjunctionNode.Left()->Accept(*this);
279 conjunctionNode.Right()->Accept(*this);
280 }
281 public override void Visit(Cm.Ast.BitOrNode& bitOrNode)
282 {
283 bitOrNode.Left()->Accept(*this);
284 bitOrNode.Right()->Accept(*this);
285 }
286 public override void Visit(Cm.Ast.BitXorNode& bitXorNode)
287 {
288 bitXorNode.Left()->Accept(*this);
289 bitXorNode.Right()->Accept(*this);
290 }
291 public override void Visit(Cm.Ast.BitAndNode& bitAndNode)
292 {
293 bitAndNode.Left()->Accept(*this);
294 bitAndNode.Right()->Accept(*this);
295 }
296 public override void Visit(Cm.Ast.EqualNode& equalNode)
297 {
298 equalNode.Left()->Accept(*this);
299 equalNode.Right()->Accept(*this);
300 }
301 public override void Visit(Cm.Ast.NotEqualNode& notEqualNode)
302 {
303 notEqualNode.Left()->Accept(*this);
304 notEqualNode.Right()->Accept(*this);
305 }
306 public override void Visit(Cm.Ast.LessNode& lessNode)
307 {
308 lessNode.Left()->Accept(*this);
309 lessNode.Right()->Accept(*this);
310 }
311 public override void Visit(Cm.Ast.GreaterNode& greaterNode)
312 {
313 greaterNode.Left()->Accept(*this);
314 greaterNode.Right()->Accept(*this);
315 }
316 public override void Visit(Cm.Ast.LessOrEqualNode& lessOrEqualNode)
317 {
318 lessOrEqualNode.Left()->Accept(*this);
319 lessOrEqualNode.Right()->Accept(*this);
320 }
321 public override void Visit(Cm.Ast.GreaterOrEqualNode& greaterOrEqualNode)
322 {
323 greaterOrEqualNode.Left()->Accept(*this);
324 greaterOrEqualNode.Right()->Accept(*this);
325 }
326 public override void Visit(Cm.Ast.ShiftLeftNode& shiftLeftNode)
327 {
328 shiftLeftNode.Left()->Accept(*this);
329 shiftLeftNode.Right()->Accept(*this);
330 }
331 public override void Visit(Cm.Ast.ShiftRightNode& shiftRightNode)
332 {
333 shiftRightNode.Left()->Accept(*this);
334 shiftRightNode.Right()->Accept(*this);
335 }
336 public override void Visit(Cm.Ast.AddNode& addNode)
337 {
338 addNode.Left()->Accept(*this);
339 addNode.Right()->Accept(*this);
340 }
341 public override void Visit(Cm.Ast.SubNode& subNode)
342 {
343 subNode.Left()->Accept(*this);
344 subNode.Right()->Accept(*this);
345 }
346 public override void Visit(Cm.Ast.MulNode& mulNode)
347 {
348 mulNode.Left()->Accept(*this);
349 mulNode.Right()->Accept(*this);
350 }
351 public override void Visit(Cm.Ast.DivNode& divNode)
352 {
353 divNode.Left()->Accept(*this);
354 divNode.Right()->Accept(*this);
355 }
356 public override void Visit(Cm.Ast.RemNode& remNode)
357 {
358 remNode.Left()->Accept(*this);
359 remNode.Right()->Accept(*this);
360 }
361 public override void Visit(Cm.Ast.NotNode& notNode)
362 {
363 notNode.Subject()->Accept(*this);
364 }
365 public override void Visit(Cm.Ast.UnaryPlusNode& unaryPlusNode)
366 {
367 unaryPlusNode.Subject()->Accept(*this);
368 }
369 public override void Visit(Cm.Ast.UnaryMinusNode& unaryMinusNode)
370 {
371 unaryMinusNode.Subject()->Accept(*this);
372 }
373 public override void Visit(Cm.Ast.PrefixIncrementNode& prefixIncrementNode)
374 {
375 prefixIncrementNode.Subject()->Accept(*this);
376 }
377 public override void Visit(Cm.Ast.PrefixDecrementNode& prefixDecrementNode)
378 {
379 prefixDecrementNode.Subject()->Accept(*this);
380 }
381 public override void Visit(Cm.Ast.DerefNode& derefNode)
382 {
383 derefNode.Subject()->Accept(*this);
384 }
385 public override void Visit(Cm.Ast.AddrOfNode& addrOfNode)
386 {
387 addrOfNode.Subject()->Accept(*this);
388 }
389 public override void Visit(Cm.Ast.ComplementNode& complementNode)
390 {
391 complementNode.Subject()->Accept(*this);
392 }
393 public override void Visit(Cm.Ast.IsNode& isNode)
394 {
395 isNode.TargetTypeExpr()->Accept(*this);
396 isNode.Expr()->Accept(*this);
397 }
398 public override void Visit(Cm.Ast.AsNode& asNode)
399 {
400 asNode.TargetTypeExpr()->Accept(*this);
401 asNode.Expr()->Accept(*this);
402 }
403 public override void Visit(Cm.Ast.IndexingNode& indexingNode)
404 {
405 indexingNode.Subject()->Accept(*this);
406 indexingNode.Index()->Accept(*this);
407 }
408 public override void Visit(Cm.Ast.InvokeNode& invokeNode)
409 {
410 invokeNode.Subject()->Accept(*this);
411 int n = invokeNode.Arguments().Count();
412 for (int i = 0; i < n; ++i;)
413 {
414 invokeNode.Arguments()[i]->Accept(*this);
415 }
416 }
417 public override void Visit(Cm.Ast.PostfixIncrementNode& postfixIncrementNode)
418 {
419 postfixIncrementNode.Subject()->Accept(*this);
420 }
421 public override void Visit(Cm.Ast.PostfixDecrementNode& postfixDecrementNode)
422 {
423 postfixDecrementNode.Subject()->Accept(*this);
424 }
425 public override void Visit(Cm.Ast.SizeOfNode& sizeOfNode)
426 {
427 sizeOfNode.Expression()->Accept(*this);
428 }
429 public override void Visit(Cm.Ast.TypeNameNode& typeNameNode)
430 {
431 typeNameNode.Expression()->Accept(*this);
432 }
433 public override void Visit(Cm.Ast.TypeIdNode& typeIdNode)
434 {
435 typeIdNode.Expression()->Accept(*this);
436 }
437 public override void Visit(Cm.Ast.CastNode& castNode)
438 {
439 castNode.TargetTypeExpr()->Accept(*this);
440 castNode.SourceExpr()->Accept(*this);
441 }
442 public override void Visit(Cm.Ast.ConstructNode& constructNode)
443 {
444 constructNode.TypeExpr()->Accept(*this);
445 int n = constructNode.Arguments().Count();
446 for (int i = 0; i < n; ++i;)
447 {
448 constructNode.Arguments()[i]->Accept(*this);
449 }
450 }
451 public override void Visit(Cm.Ast.NewNode& newNode)
452 {
453 newNode.TypeExpr()->Accept(*this);
454 int n = newNode.Arguments().Count();
455 for (int i = 0; i < n; ++i;)
456 {
457 newNode.Arguments()[i]->Accept(*this);
458 }
459 }
460 public override void Visit(Cm.Ast.ParenthesizedExpressionNode& parenthesizedExpressionNode)
461 {
462 parenthesizedExpressionNode.Subject()->Accept(*this);
463 }
464 public override void Visit(Cm.Ast.IdentifierNode& node)
465 {
466 if (node.Str() == u"pass")
467 {
468 hasPass = true;
469 }
470 else if (node.Str() == u"span")
471 {
472 hasSpan = true;
473 }
474 }
475 private bool hasReturn;
476 private bool hasPass;
477 private bool hasSpan;
478 }
479 }