Mercurial > lcfOS
comparison python/c3/astnodes.py @ 165:598d3888a11c
Added front class and fided AST view
author | Windel Bouwman |
---|---|
date | Fri, 22 Mar 2013 15:12:38 +0100 |
parents | 8104fc8b5e90 |
children | da0087b82fbe |
comparison
equal
deleted
inserted
replaced
164:e023d3ce1d63 | 165:598d3888a11c |
---|---|
21 | 21 |
22 class BaseType(Type): | 22 class BaseType(Type): |
23 def __init__(self, name): | 23 def __init__(self, name): |
24 self.name = name | 24 self.name = name |
25 def __repr__(self): | 25 def __repr__(self): |
26 return '[TYPE {0}]'.format(self.name) | 26 return '{0}'.format(self.name) |
27 | 27 |
28 class FunctionType(Type): | 28 class FunctionType(Type): |
29 def __init__(self, parameters, returntype): | 29 def __init__(self, parameters, returntype): |
30 self.parameters = parameters | 30 self.parameters = parameters |
31 self.returntype = returntype | 31 self.returntype = returntype |
32 def __repr__(self): | 32 def __repr__(self): |
33 return '[FUNCTYPE {0} RET {1}]'.format(self.parameters, self.returntype) | 33 params = ','.join([str(v) for v in self.parameters]) |
34 return '{1} f({0})'.format(params, self.returntype) | |
34 | 35 |
35 class DefinedType(Type): | 36 class DefinedType(Type): |
36 def __init__(self, name, typ): | 37 def __init__(self, name, typ): |
37 self.name = name | 38 self.name = name |
38 self.typ = typ | 39 self.typ = typ |
65 self.ival = ival | 66 self.ival = ival |
66 self.isLocal = False | 67 self.isLocal = False |
67 self.isReadOnly = False | 68 self.isReadOnly = False |
68 self.isParameter = False | 69 self.isParameter = False |
69 def __repr__(self): | 70 def __repr__(self): |
70 return 'VAR {0} : {1} usage: {2}'.format(self.name, self.typ, self.References) | 71 return '{0}'.format(self.name) |
71 | 72 |
72 # Procedure types | 73 # Procedure types |
73 class Function(Symbol): | 74 class Function(Symbol): |
74 """ Actual implementation of a function """ | 75 """ Actual implementation of a function """ |
75 def __init__(self, name, typ=None, block=None): | 76 def __init__(self, name, typ=None, block=None): |
76 super().__init__(name) | 77 super().__init__(name) |
77 self.body = block | 78 self.body = block |
78 self.typ = typ | 79 self.typ = typ |
79 def __repr__(self): | 80 def __repr__(self): |
80 return 'PROCEDURE {0} {1}'.format(self.name, self.typ) | 81 return '{0}'.format(self.name) |
81 | 82 |
82 # Operations / Expressions: | 83 # Operations / Expressions: |
83 class Unop(Node): | 84 class Unop(Node): |
84 def __init__(self, a, op): | 85 def __init__(self, a, op): |
85 self.a = a | 86 self.a = a |