Mercurial > lcfOS
comparison python/c3/astnodes.py @ 228:7f18ed9b6b7e
Removal of emptystatement class
author | Windel Bouwman |
---|---|
date | Sat, 13 Jul 2013 11:12:24 +0200 |
parents | 82dfe6a32717 |
children | 88a1e0baef65 |
comparison
equal
deleted
inserted
replaced
227:82dfe6a32717 | 228:7f18ed9b6b7e |
---|---|
30 Type classes | 30 Type classes |
31 | 31 |
32 types must be comparable. | 32 types must be comparable. |
33 | 33 |
34 There are the following types: | 34 There are the following types: |
35 - base type | 35 - base type -> basic type (built in) |
36 - struct type | 36 - struct type -> a composite type that contains a list of named fields |
37 - pointer type | 37 of other types |
38 - typedef type | 38 - pointer type -> a type that points to some other type |
39 - typedef type -> a named type indicating another type | |
39 - function type | 40 - function type |
40 """ | 41 """ |
41 | 42 |
42 class Type(Node): | 43 class Type(Node): |
43 def isType(self, b): | 44 def isType(self, b): |
188 | 189 |
189 def __repr__(self): | 190 def __repr__(self): |
190 return 'BINOP {}'.format(self.op) | 191 return 'BINOP {}'.format(self.op) |
191 | 192 |
192 class VariableUse(Expression): | 193 class VariableUse(Expression): |
193 def __init__(self, target, loc): | 194 def __init__(self, target, loc): |
194 self.target = target | 195 self.target = target |
195 self.loc = loc | 196 self.loc = loc |
196 def __repr__(self): | 197 def __repr__(self): |
197 nm = self.target.name if hasattr(self.target, 'name') else '' | 198 nm = self.target |
198 return 'VAR USE {}'.format(nm) | 199 return 'VAR USE {}'.format(nm) |
199 | 200 |
200 class Literal(Expression): | 201 class Literal(Expression): |
201 def __init__(self, val, loc): | 202 def __init__(self, val, loc): |
202 self.val = val | 203 self.val = val |
203 self.loc = loc | 204 self.loc = loc |
204 def __repr__(self): | 205 def __repr__(self): |
205 return 'LITERAL {}'.format(self.val) | 206 return 'LITERAL {}'.format(self.val) |
206 | 207 |
207 class FunctionCall(Expression): | 208 class FunctionCall(Expression): |
208 def __init__(self, proc, args, loc): | 209 def __init__(self, proc, args, loc): |
209 self.proc = proc | 210 self.proc = proc |
210 self.args = args | 211 self.args = args |
211 self.loc = loc | 212 self.loc = loc |
212 def __repr__(self): | 213 def __repr__(self): |
213 return 'CALL {0} '.format(self.proc) | 214 return 'CALL {0} '.format(self.proc) |
214 | 215 |
215 # Statements | 216 # Statements |
216 class Statement(Node): | 217 class Statement(Node): |
217 pass | 218 def __init__(self, loc): |
219 self.loc = loc | |
220 | |
218 | 221 |
219 class CompoundStatement(Statement): | 222 class CompoundStatement(Statement): |
220 def __init__(self, statements): | 223 def __init__(self, statements): |
221 self.statements = statements | 224 self.statements = statements |
225 for s in self.statements: | |
226 assert isinstance(s, Statement) | |
222 | 227 |
223 def __repr__(self): | 228 def __repr__(self): |
224 return 'COMPOUND STATEMENT' | 229 return 'COMPOUND STATEMENT' |
225 | 230 |
226 class EmptyStatement(Statement): | |
227 def __repr__(self): | |
228 return 'NOP' | |
229 | 231 |
230 class ReturnStatement(Statement): | 232 class ReturnStatement(Statement): |
231 def __init__(self, expr, loc): | 233 def __init__(self, expr, loc): |
232 self.expr = expr | 234 super().__init__(loc) |
233 self.loc = loc | 235 self.expr = expr |
234 def __repr__(self): | 236 |
235 return 'RETURN STATEMENT' | 237 def __repr__(self): |
238 return 'RETURN STATEMENT' | |
236 | 239 |
237 class Assignment(Statement): | 240 class Assignment(Statement): |
238 def __init__(self, lval, rval, loc): | 241 def __init__(self, lval, rval, loc): |
242 super().__init__(loc) | |
239 assert isinstance(lval, Node) | 243 assert isinstance(lval, Node) |
240 assert isinstance(rval, Node) | 244 assert isinstance(rval, Node) |
241 assert isinstance(loc, SourceLocation) | |
242 self.lval = lval | 245 self.lval = lval |
243 self.rval = rval | 246 self.rval = rval |
244 self.loc = loc | |
245 | 247 |
246 def __repr__(self): | 248 def __repr__(self): |
247 return 'ASSIGNMENT' | 249 return 'ASSIGNMENT' |
248 | 250 |
249 class ExpressionStatement(Statement): | 251 class ExpressionStatement(Statement): |
250 def __init__(self, ex, loc): | 252 def __init__(self, ex, loc): |
253 super().__init__(loc) | |
251 self.ex = ex | 254 self.ex = ex |
252 self.loc = loc | 255 |
253 assert isinstance(loc, SourceLocation) | |
254 def __repr__(self): | 256 def __repr__(self): |
255 return 'Epression' | 257 return 'Epression' |
256 | 258 |
259 | |
257 class IfStatement(Statement): | 260 class IfStatement(Statement): |
258 def __init__(self, condition, truestatement, falsestatement, loc): | 261 def __init__(self, condition, truestatement, falsestatement, loc): |
259 self.condition = condition | 262 super().__init__(loc) |
260 self.truestatement = truestatement | 263 self.condition = condition |
261 self.falsestatement = falsestatement | 264 self.truestatement = truestatement |
262 self.loc = loc | 265 self.falsestatement = falsestatement |
263 def __repr__(self): | 266 |
264 return 'IF-statement' | 267 def __repr__(self): |
268 return 'IF-statement' | |
269 | |
265 | 270 |
266 class WhileStatement(Statement): | 271 class WhileStatement(Statement): |
267 def __init__(self, condition, statement, loc): | 272 def __init__(self, condition, statement, loc): |
268 self.condition = condition | 273 super().__init__(loc) |
269 self.statement = statement | 274 self.condition = condition |
270 self.loc = loc | 275 self.statement = statement |
271 def __repr__(self): | 276 |
272 return 'WHILE-statement' | 277 def __repr__(self): |
273 | 278 return 'WHILE-statement' |
279 |