comparison python/c3/analyse.py @ 226:240111e0456f

Work on named types
author Windel Bouwman
date Fri, 12 Jul 2013 17:25:31 +0200
parents 1c7364bd74c7
children 82dfe6a32717
comparison
equal deleted inserted replaced
225:1c7364bd74c7 226:240111e0456f
76 def resolveType(self, t, scope): 76 def resolveType(self, t, scope):
77 # TODO: what about structs? 77 # TODO: what about structs?
78 if type(t) is PointerType: 78 if type(t) is PointerType:
79 t.ptype = self.resolveType(t.ptype, scope) 79 t.ptype = self.resolveType(t.ptype, scope)
80 return t 80 return t
81 elif type(t) is StructureType:
82 for mem in t.mems:
83 mem.typ = self.resolveType(mem.typ, scope)
84 return t
81 elif type(t) is Designator: 85 elif type(t) is Designator:
82 return self.resolveDesignator(t, scope) 86 t = self.resolveDesignator(t, scope)
87 return self.resolveType(t)
83 elif isinstance(t, Type): 88 elif isinstance(t, Type):
84 # Already resolved?? 89 # Already resolved??
85 return t 90 return t
86 else: 91 else:
87 raise Exception('Error resolving type {} {}'.format(t, type(t))) 92 raise Exception('Error resolving type {} {}'.format(t, type(t)))
99 elif type(sym) is Function: 104 elif type(sym) is Function:
100 # Checkup function type: 105 # Checkup function type:
101 ft = sym.typ 106 ft = sym.typ
102 ft.returntype = self.resolveType(ft.returntype, sym.scope) 107 ft.returntype = self.resolveType(ft.returntype, sym.scope)
103 ft.parametertypes = [self.resolveType(pt, sym.scope) for pt in ft.parametertypes] 108 ft.parametertypes = [self.resolveType(pt, sym.scope) for pt in ft.parametertypes]
109 elif type(sym) is DefinedType:
110 sym.typ = self.resolveType(sym.typ, sym.scope)
104 111
105 def sanity(self, sym): 112 def sanity(self, sym):
106 if type(sym) is FunctionType: 113 if type(sym) is FunctionType:
107 pass 114 pass
108 elif type(sym) is Function: 115 elif type(sym) is Function: