Another conversion away from self.context.fetch to self.declare.
Chris Pressey
6 years ago
55 | 55 | self.syntax_error('Undefined symbol "{}"'.format(name)) |
56 | 56 | return model |
57 | 57 | |
58 | def declare(self, name, symentry): | |
58 | def declare(self, name, symentry, static=False): | |
59 | 59 | if self.context.fetch(name): |
60 | 60 | self.syntax_error('Symbol "%s" already declared' % name) |
61 | self.context.symbols[name] = symentry | |
61 | if static: | |
62 | self.context.statics[name] = symentry | |
63 | else: | |
64 | self.context.symbols[name] = symentry | |
65 | ||
66 | def clear_statics(self): | |
67 | self.context.statics = {} | |
62 | 68 | |
63 | 69 | # --- grammar productions |
64 | 70 | |
285 | 291 | else: |
286 | 292 | statics = self.statics() |
287 | 293 | |
288 | self.context.statics = self.compose_statics_dict(statics) | |
289 | block = self.block() | |
290 | self.context.statics = {} | |
294 | self.clear_statics() | |
295 | for defn in statics: | |
296 | self.declare(defn.name, SymEntry(defn, defn.location), static=True) | |
297 | block = self.block() | |
298 | self.clear_statics() | |
291 | 299 | |
292 | 300 | addr = None |
293 | 301 | location = LocationRef(type_, name) |
296 | 304 | name=name, block=block, addr=addr, |
297 | 305 | location=location, statics=statics |
298 | 306 | ) |
299 | ||
300 | def compose_statics_dict(self, statics): | |
301 | c = {} | |
302 | for defn in statics: | |
303 | name = defn.name | |
304 | if self.context.fetch(name): | |
305 | self.syntax_error('Symbol "%s" already declared' % name) | |
306 | c[name] = SymEntry(defn, defn.location) | |
307 | return c | |
308 | 307 | |
309 | 308 | def labels(self): |
310 | 309 | accum = [] |