Mercurial > lcfOS
comparison python/ppci/c3/visitor.py @ 307:e609d5296ee9
Massive rewrite of codegenerator
author | Windel Bouwman |
---|---|
date | Thu, 12 Dec 2013 20:42:56 +0100 |
parents | b145f8e6050b |
children | 04cf4d26a3bc |
comparison
equal
deleted
inserted
replaced
306:b145f8e6050b | 307:e609d5296ee9 |
---|---|
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.typ) |
27 self.do(node.body) | 27 self.do(node.body) |
28 elif type(node) is CompoundStatement: | 28 elif type(node) is Compound: |
29 for s in node.statements: | 29 for s in node.statements: |
30 self.do(s) | 30 self.do(s) |
31 elif type(node) is IfStatement: | 31 elif type(node) is If: |
32 self.do(node.condition) | 32 self.do(node.condition) |
33 self.do(node.truestatement) | 33 self.do(node.truestatement) |
34 self.do(node.falsestatement) | 34 self.do(node.falsestatement) |
35 elif type(node) is While: | |
36 self.do(node.condition) | |
37 self.do(node.statement) | |
38 elif type(node) is Assignment: | |
39 self.do(node.lval) | |
40 self.do(node.rval) | |
35 elif type(node) is FunctionCall: | 41 elif type(node) is FunctionCall: |
36 for arg in node.args: | 42 for arg in node.args: |
37 self.do(arg) | 43 self.do(arg) |
38 self.do(node.proc) | 44 self.do(node.proc) |
39 elif type(node) is Assignment: | 45 elif type(node) is Return: |
40 self.do(node.lval) | |
41 self.do(node.rval) | |
42 elif type(node) is ReturnStatement: | |
43 self.do(node.expr) | 46 self.do(node.expr) |
44 elif type(node) is Binop: | 47 elif type(node) is Binop: |
45 self.do(node.a) | 48 self.do(node.a) |
46 self.do(node.b) | 49 self.do(node.b) |
47 elif type(node) is Unop: | 50 elif type(node) is Unop: |
48 self.do(node.a) | 51 self.do(node.a) |
49 elif type(node) is ExpressionStatement: | 52 elif type(node) is ExpressionStatement: |
50 self.do(node.ex) | 53 self.do(node.ex) |
51 elif type(node) is TypeCast: | 54 elif type(node) is TypeCast: |
52 self.do(node.a) | 55 self.do(node.a) |
56 self.do(node.to_type) | |
53 elif type(node) is Member: | 57 elif type(node) is Member: |
54 self.do(node.base) | 58 self.do(node.base) |
55 elif type(node) is Deref: | 59 elif type(node) is Deref: |
56 self.do(node.ptr) | 60 self.do(node.ptr) |
57 elif type(node) is Constant: | 61 elif type(node) is Constant: |
67 self.do(m.typ) | 71 self.do(m.typ) |
68 elif type(node) is FunctionType: | 72 elif type(node) is FunctionType: |
69 for pt in node.parametertypes: | 73 for pt in node.parametertypes: |
70 self.do(pt) | 74 self.do(pt) |
71 self.do(node.returntype) | 75 self.do(node.returntype) |
72 elif type(node) in [Identifier, Literal, EmptyStatement]: | 76 elif type(node) in [Identifier, Literal, Empty]: |
73 # Those nodes do not have child nodes. | 77 # Those nodes do not have child nodes. |
74 pass | 78 pass |
75 elif type(node) is WhileStatement: | |
76 self.do(node.condition) | |
77 self.do(node.statement) | |
78 else: | 79 else: |
79 raise Exception('Could not visit "{0}"'.format(node)) | 80 raise Exception('Could not visit "{0}"'.format(node)) |
80 | 81 |
81 # run post function | 82 # run post function |
82 if self.f_post: | 83 if self.f_post: |