comparison python/c3/analyse.py @ 289:bd2593de3ff8

Semifix burn2
author Windel Bouwman
date Thu, 21 Nov 2013 15:46:50 +0100
parents a747a45dcd78
children 6aa721e7b10b
comparison
equal deleted inserted replaced
288:a747a45dcd78 289:bd2593de3ff8
69 """ 69 """
70 70
71 def analyzePackage(self, pkg, packageDict): 71 def analyzePackage(self, pkg, packageDict):
72 self.ok = True 72 self.ok = True
73 # Prepare top level scope and set scope to all objects: 73 # Prepare top level scope and set scope to all objects:
74 AddScope(self.diag).addScope(pkg)
75 74
76 self.logger.info('Resolving imports for package {}'.format(pkg.name)) 75 self.logger.info('Resolving imports for package {}'.format(pkg.name))
77 # Handle imports: 76 # Handle imports:
78 for i in pkg.imports: 77 for i in pkg.imports:
79 ip = packageDict[i] 78 ip = packageDict[i]
89 def fixRefs(self, pkg): 88 def fixRefs(self, pkg):
90 self.visitor.visit(pkg, self.findRefs) 89 self.visitor.visit(pkg, self.findRefs)
91 90
92 # Reference fixups: 91 # Reference fixups:
93 def resolveDesignator(self, d, scope): 92 def resolveDesignator(self, d, scope):
94 assert type(d) is Designator, type(d) 93 assert isinstance(d, Designator), type(d)
94 assert type(scope) is Scope
95 if scope.hasSymbol(d.tname):
96 s = scope.getSymbol(d.tname)
97 if isinstance(d, ImportDesignator):
98 if s.innerScope.hasSymbol(d.vname):
99 return s.innerScope.getSymbol(d.vname)
100 else:
101 if hasattr(s, 'addRef'):
102 # TODO: make this nicer
103 s.addRef(None)
104 return s
105 else:
106 self.error('Cannot resolve name {0}'.format(d.tname), d.loc)
107
108 def resolveImportDesignator(self, d, scope):
109 assert isinstance(d, ImportDesignator), type(d)
95 assert type(scope) is Scope 110 assert type(scope) is Scope
96 if scope.hasSymbol(d.tname): 111 if scope.hasSymbol(d.tname):
97 s = scope.getSymbol(d.tname) 112 s = scope.getSymbol(d.tname)
98 if hasattr(s, 'addRef'): 113 if hasattr(s, 'addRef'):
99 # TODO: make this nicer 114 # TODO: make this nicer
112 mem.offset = offset 127 mem.offset = offset
113 mem.typ = self.resolveType(mem.typ, scope) 128 mem.typ = self.resolveType(mem.typ, scope)
114 offset += theType(mem.typ).bytesize 129 offset += theType(mem.typ).bytesize
115 t.bytesize = offset 130 t.bytesize = offset
116 return t 131 return t
117 elif type(t) is Designator: 132 elif isinstance(t, Designator):
118 t = self.resolveDesignator(t, scope) 133 t = self.resolveDesignator(t, scope)
119 if t: 134 if t:
120 return self.resolveType(t, scope) 135 return self.resolveType(t, scope)
121 elif isinstance(t, Type): 136 elif isinstance(t, Type):
122 # Already resolved?? 137 # Already resolved??