@@ -10,7 +10,8 @@ class ASTNode {
10
10
public:
11
11
enum Type {
12
12
NODE_INVALID, NODE_LIST, NODE_OBJECT, NODE_UNARY, NODE_BINARY,
13
- NODE_COMPARE, NODE_STORE, NODE_RETURN, NODE_NAME, NODE_DELETE
13
+ NODE_COMPARE, NODE_STORE, NODE_RETURN, NODE_NAME, NODE_DELETE,
14
+ NODE_FUNCTION, NODE_CLASS, NODE_CALL, NODE_PASS
14
15
};
15
16
16
17
ASTNode (int type = NODE_INVALID) : m_refs(0 ), m_type(type) { }
@@ -38,7 +39,10 @@ class ASTNodeList : public ASTNode {
38
39
ASTNodeList (list_t nodes)
39
40
: ASTNode(NODE_LIST), m_nodes(nodes) { }
40
41
41
- list_t nodes () const { return m_nodes; }
42
+ const list_t & nodes () const { return m_nodes; }
43
+ void removeFirst ();
44
+ void removeLast ();
45
+ void append (PycRef<ASTNode> node) { m_nodes.push_back (node); }
42
46
43
47
private:
44
48
list_t m_nodes;
@@ -71,11 +75,22 @@ class ASTUnary : public ASTNode {
71
75
72
76
class ASTBinary : public ASTNode {
73
77
public:
74
- ASTBinary (PycRef<ASTNode> left, PycRef<ASTNode> right, int type = NODE_BINARY)
75
- : ASTNode(type), m_left(left), m_right(right) { }
78
+ enum BinOp {
79
+ BIN_POWER, BIN_MULTIPLY, BIN_DIVIDE, BIN_MODULO, BIN_ADD,
80
+ BIN_SUBTRACT, BIN_LSHIFT, BIN_RSHIFT, BIN_AND, BIN_XOR, BIN_OR
81
+ };
82
+
83
+ ASTBinary (PycRef<ASTNode> left, PycRef<ASTNode> right, int op,
84
+ int type = NODE_BINARY)
85
+ : ASTNode(type), m_op(op), m_left(left), m_right(right) { }
76
86
77
87
PycRef<ASTNode> left () const { return m_left; }
78
88
PycRef<ASTNode> right () const { return m_right; }
89
+ int op () const { return m_op; }
90
+ virtual const char * op_str () const ;
91
+
92
+ protected:
93
+ int m_op;
79
94
80
95
private:
81
96
PycRef<ASTNode> m_left;
@@ -91,14 +106,10 @@ class ASTCompare : public ASTBinary {
91
106
CMP_EXCEPTION, CMP_BAD
92
107
};
93
108
94
- ASTCompare (PycRef<ASTNode> left, PycRef<ASTNode> right, CompareOp op)
95
- : ASTBinary(left, right, NODE_COMPARE), m_op(op ) { }
109
+ ASTCompare (PycRef<ASTNode> left, PycRef<ASTNode> right, int op)
110
+ : ASTBinary(left, right, op, NODE_COMPARE ) { }
96
111
97
- CompareOp op () const { return m_op; }
98
112
const char * op_str () const ;
99
-
100
- private:
101
- CompareOp m_op;
102
113
};
103
114
104
115
@@ -135,7 +146,7 @@ class ASTName : public ASTNode {
135
146
ASTName (PycRef<PycString> name)
136
147
: ASTNode(NODE_NAME) { m_name.push_back (name); }
137
148
138
- name_t name () const { return m_name; }
149
+ const name_t & name () const { return m_name; }
139
150
void add (PycRef<PycString> name) { m_name.push_back (name); }
140
151
141
152
private:
@@ -154,4 +165,51 @@ class ASTDelete : public ASTNode {
154
165
PycRef<ASTNode> m_value;
155
166
};
156
167
168
+
169
+ class ASTFunction : public ASTNode {
170
+ public:
171
+ typedef std::list<PycRef<ASTNode> > defarg_t ;
172
+
173
+ ASTFunction (PycRef<ASTNode> code, defarg_t defArgs)
174
+ : ASTNode(NODE_FUNCTION), m_code(code) { }
175
+
176
+ PycRef<ASTNode> code () const { return m_code; }
177
+ const defarg_t & defargs () const { return m_defargs; }
178
+
179
+ private:
180
+ PycRef<ASTNode> m_code;
181
+ defarg_t m_defargs;
182
+ };
183
+
184
+
185
+ class ASTClass : public ASTNode {
186
+ public:
187
+ ASTClass (PycRef<ASTNode> code)
188
+ : ASTNode(NODE_CLASS), m_code(code) { }
189
+
190
+ PycRef<ASTNode> code () const { return m_code; }
191
+
192
+ private:
193
+ PycRef<ASTNode> m_code;
194
+ };
195
+
196
+
197
+ class ASTCall : public ASTNode {
198
+ public:
199
+ typedef std::list<PycRef<ASTNode> > pparam_t ;
200
+ typedef std::list<std::pair<PycRef<ASTNode>, PycRef<ASTNode> > > kwparam_t ;
201
+
202
+ ASTCall (PycRef<ASTNode> func, pparam_t pparams, kwparam_t kwparams)
203
+ : ASTNode(NODE_CALL), m_func(func), m_pparams(pparams), m_kwparams(kwparams) { }
204
+
205
+ PycRef<ASTNode> func () const { return m_func; }
206
+ const pparam_t & pparams () const { return m_pparams; }
207
+ const kwparam_t & kwparams () const { return m_kwparams; }
208
+
209
+ private:
210
+ PycRef<ASTNode> m_func;
211
+ pparam_t m_pparams;
212
+ kwparam_t m_kwparams;
213
+ };
214
+
157
215
#endif
0 commit comments