Mercurial > lcfOS
comparison python/ppci/c3/visitor.py @ 306:b145f8e6050b
Start on c3 rewrite
author | Windel Bouwman |
---|---|
date | Mon, 09 Dec 2013 19:00:21 +0100 |
parents | 158068af716c |
children | e609d5296ee9 |
comparison
equal
deleted
inserted
replaced
305:0615b5308710 | 306:b145f8e6050b |
---|---|
10 self.f_pre = f_pre | 10 self.f_pre = f_pre |
11 self.f_post = f_post | 11 self.f_post = f_post |
12 self.do(node) | 12 self.do(node) |
13 | 13 |
14 def do(self, node): | 14 def do(self, node): |
15 # Run visitor: | 15 # Run pre function: |
16 if self.f_pre: | 16 if self.f_pre: |
17 self.f_pre(node) | 17 self.f_pre(node) |
18 | 18 |
19 # Descent into subnodes: | 19 # Descent into subnodes: |
20 if type(node) is Package: | 20 if type(node) is Package: |
21 for decl in node.declarations: | 21 for decl in node.declarations: |
22 self.do(decl) | 22 self.do(decl) |
23 elif type(node) is Function: | 23 elif type(node) is Function: |
24 for s in node.declarations: | 24 for s in node.declarations: |
25 self.do(s) | 25 self.do(s) |
26 self.do(node.typ) | |
26 self.do(node.body) | 27 self.do(node.body) |
27 elif type(node) is CompoundStatement: | 28 elif type(node) is CompoundStatement: |
28 for s in node.statements: | 29 for s in node.statements: |
29 self.do(s) | 30 self.do(s) |
30 elif type(node) is IfStatement: | 31 elif type(node) is IfStatement: |
31 self.do(node.condition) | 32 self.do(node.condition) |
32 self.do(node.truestatement) | 33 self.do(node.truestatement) |
33 if node.falsestatement: | 34 self.do(node.falsestatement) |
34 self.do(node.falsestatement) | |
35 elif type(node) is FunctionCall: | 35 elif type(node) is FunctionCall: |
36 for arg in node.args: | 36 for arg in node.args: |
37 self.do(arg) | 37 self.do(arg) |
38 self.do(node.proc) | |
38 elif type(node) is Assignment: | 39 elif type(node) is Assignment: |
39 self.do(node.lval) | 40 self.do(node.lval) |
40 self.do(node.rval) | 41 self.do(node.rval) |
41 elif type(node) is ReturnStatement: | 42 elif type(node) is ReturnStatement: |
42 self.do(node.expr) | 43 self.do(node.expr) |
47 self.do(node.a) | 48 self.do(node.a) |
48 elif type(node) is ExpressionStatement: | 49 elif type(node) is ExpressionStatement: |
49 self.do(node.ex) | 50 self.do(node.ex) |
50 elif type(node) is TypeCast: | 51 elif type(node) is TypeCast: |
51 self.do(node.a) | 52 self.do(node.a) |
52 elif type(node) is FieldRef: | 53 elif type(node) is Member: |
53 self.do(node.base) | 54 self.do(node.base) |
54 elif type(node) is Deref: | 55 elif type(node) is Deref: |
55 self.do(node.ptr) | 56 self.do(node.ptr) |
56 elif type(node) is Constant: | 57 elif type(node) is Constant: |
57 self.do(node.value) | 58 self.do(node.value) |
58 elif type(node) in [VariableUse, Variable, Literal, FunctionType, | 59 elif type(node) is DefinedType: |
59 DefinedType, FormalParameter, LocalVariable]: | 60 self.do(node.typ) |
61 elif isinstance(node, Variable): | |
62 self.do(node.typ) | |
63 elif type(node) is PointerType: | |
64 self.do(node.ptype) | |
65 elif type(node) is StructureType: | |
66 for m in node.mems: | |
67 self.do(m.typ) | |
68 elif type(node) is FunctionType: | |
69 for pt in node.parametertypes: | |
70 self.do(pt) | |
71 self.do(node.returntype) | |
72 elif type(node) in [Identifier, Literal, EmptyStatement]: | |
60 # Those nodes do not have child nodes. | 73 # Those nodes do not have child nodes. |
61 pass | 74 pass |
62 elif type(node) is WhileStatement: | 75 elif type(node) is WhileStatement: |
63 self.do(node.condition) | 76 self.do(node.condition) |
64 self.do(node.statement) | 77 self.do(node.statement) |