Mercurial > lcfOS
diff 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 |
line wrap: on
line diff
--- a/python/c3/astnodes.py Fri Jul 12 17:42:39 2013 +0200 +++ b/python/c3/astnodes.py Sat Jul 13 11:12:24 2013 +0200 @@ -32,10 +32,11 @@ types must be comparable. There are the following types: -- base type -- struct type -- pointer type -- typedef type +- base type -> basic type (built in) +- struct type -> a composite type that contains a list of named fields + of other types +- pointer type -> a type that points to some other type +- typedef type -> a named type indicating another type - function type """ @@ -190,84 +191,89 @@ return 'BINOP {}'.format(self.op) class VariableUse(Expression): - def __init__(self, target, loc): - self.target = target - self.loc = loc - def __repr__(self): - nm = self.target.name if hasattr(self.target, 'name') else '' - return 'VAR USE {}'.format(nm) + def __init__(self, target, loc): + self.target = target + self.loc = loc + def __repr__(self): + nm = self.target + return 'VAR USE {}'.format(nm) class Literal(Expression): - def __init__(self, val, loc): - self.val = val - self.loc = loc - def __repr__(self): - return 'LITERAL {}'.format(self.val) + def __init__(self, val, loc): + self.val = val + self.loc = loc + def __repr__(self): + return 'LITERAL {}'.format(self.val) class FunctionCall(Expression): - def __init__(self, proc, args, loc): - self.proc = proc - self.args = args - self.loc = loc - def __repr__(self): - return 'CALL {0} '.format(self.proc) + def __init__(self, proc, args, loc): + self.proc = proc + self.args = args + self.loc = loc + def __repr__(self): + return 'CALL {0} '.format(self.proc) # Statements class Statement(Node): - pass + def __init__(self, loc): + self.loc = loc + class CompoundStatement(Statement): def __init__(self, statements): self.statements = statements + for s in self.statements: + assert isinstance(s, Statement) def __repr__(self): return 'COMPOUND STATEMENT' -class EmptyStatement(Statement): - def __repr__(self): - return 'NOP' class ReturnStatement(Statement): - def __init__(self, expr, loc): - self.expr = expr - self.loc = loc - def __repr__(self): - return 'RETURN STATEMENT' + def __init__(self, expr, loc): + super().__init__(loc) + self.expr = expr + + def __repr__(self): + return 'RETURN STATEMENT' class Assignment(Statement): def __init__(self, lval, rval, loc): + super().__init__(loc) assert isinstance(lval, Node) assert isinstance(rval, Node) - assert isinstance(loc, SourceLocation) self.lval = lval self.rval = rval - self.loc = loc def __repr__(self): return 'ASSIGNMENT' class ExpressionStatement(Statement): def __init__(self, ex, loc): + super().__init__(loc) self.ex = ex - self.loc = loc - assert isinstance(loc, SourceLocation) + def __repr__(self): return 'Epression' + class IfStatement(Statement): - def __init__(self, condition, truestatement, falsestatement, loc): - self.condition = condition - self.truestatement = truestatement - self.falsestatement = falsestatement - self.loc = loc - def __repr__(self): - return 'IF-statement' + def __init__(self, condition, truestatement, falsestatement, loc): + super().__init__(loc) + self.condition = condition + self.truestatement = truestatement + self.falsestatement = falsestatement + + def __repr__(self): + return 'IF-statement' + class WhileStatement(Statement): - def __init__(self, condition, statement, loc): - self.condition = condition - self.statement = statement - self.loc = loc - def __repr__(self): - return 'WHILE-statement' + def __init__(self, condition, statement, loc): + super().__init__(loc) + self.condition = condition + self.statement = statement + def __repr__(self): + return 'WHILE-statement' +