comparison python/c3/astnodes.py @ 150:4ae0e02599de

Added type check start and analyze phase
author Windel Bouwman
date Fri, 01 Mar 2013 16:53:22 +0100
parents 74241ca312cc
children b28a11c01dbe
comparison
equal deleted inserted replaced
149:74241ca312cc 150:4ae0e02599de
15 for mi in member: 15 for mi in member:
16 if isinstance(mi, Node): 16 if isinstance(mi, Node):
17 children.append(mi) 17 children.append(mi)
18 return children 18 return children
19 19
20 20 class Designator(Node):
21 class Id(Node): 21 def __init__(self, tname):
22 def __init__(self, tok, pub): 22 self.tname = tname
23 self.name = tok.val
24 self.is_public = pub
25 def __repr__(self): 23 def __repr__(self):
26 return 'ID {0}'.format(self.name) 24 return 'DESIGNATOR {0}'.format(self.tname)
27
28 # Selectors:
29 class Designator(Node):
30 def __init__(self, obj, selectors, typ):
31 self.obj = obj
32 self.selectors = selectors
33 self.typ = typ
34 def __repr__(self):
35 return 'DESIGNATOR {0}, selectors {1}, type {2}'.format(self.obj, self.selectors, self.typ)
36 25
37 """ 26 """
38 Type classes 27 Type classes
39 """ 28 """
40 def isType(a, b): 29 def isType(a, b):
107 self.isReadOnly = False 96 self.isReadOnly = False
108 self.isParameter = False 97 self.isParameter = False
109 def __repr__(self): 98 def __repr__(self):
110 return 'VAR {0} : {1}'.format(self.name, self.typ) 99 return 'VAR {0} : {1}'.format(self.name, self.typ)
111 100
112 class Parameter(Node): 101 # Procedure types
113 """ A parameter has a passing method, name and typ """ 102 class Function(Symbol):
114 def __init__(self, name, typ): 103 """ Actual implementation of a function """
104 def __init__(self, name, typ=None, block=None):
115 self.name = name 105 self.name = name
106 self.body = block
116 self.typ = typ 107 self.typ = typ
117 def __repr__(self): 108 def __repr__(self):
118 return 'PARAM {0} {1}'.format(self.name, self.typ) 109 return 'PROCEDURE {0} {1}'.format(self.name, self.typ)
119 110
120 # Operations: 111 # Operations:
121 class Unop(Node): 112 class Unop(Node):
122 def __init__(self, a, op): 113 def __init__(self, a, op):
123 self.a = a 114 self.a = a
131 self.b = b 122 self.b = b
132 self.op = op # Operation: '+', '-', '*', '/', 'mod' 123 self.op = op # Operation: '+', '-', '*', '/', 'mod'
133 def __repr__(self): 124 def __repr__(self):
134 return 'BINOP {0}'.format(self.op) 125 return 'BINOP {0}'.format(self.op)
135 126
127 class VariableUse(Node):
128 def __init__(self, target):
129 self.target = target
130 def __repr__(self):
131 return 'VAR USE {0}'.format(self.target)
132
136 # Modules 133 # Modules
137 class Package(Node): 134 class Package(Node):
138 def __init__(self, name): 135 def __init__(self, name):
139 self.name = name 136 self.name = name
140 def __repr__(self): 137 def __repr__(self):
141 return 'PACKAGE {0}'.format(self.name) 138 return 'PACKAGE {0}'.format(self.name)
142
143 # Procedure types
144 class Procedure(Symbol):
145 """ Actual implementation of a function """
146 def __init__(self, name, typ=None, block=None):
147 self.name = name
148 self.body = block
149 self.typ = typ
150 def __repr__(self):
151 return 'PROCEDURE {0} {1}'.format(self.name, self.typ)
152 139
153 # Statements 140 # Statements
154 class CompoundStatement(Node): 141 class CompoundStatement(Node):
155 def __init__(self, statements): 142 def __init__(self, statements):
156 self.statements = statements 143 self.statements = statements