Prevent `make` where struct is inaccessible.
Chris Pressey
3 years ago
33 | 33 | self.context = ScopedContext(global_context, level='global') |
34 | 34 | self.toplevel_context = ScopedContext({}, self.context, level='toplevel') |
35 | 35 | self.context = self.toplevel_context |
36 | self.current_defn = None | |
36 | 37 | |
37 | 38 | self.forwards = {} |
38 | 39 | self.structs = {} # struct name -> StructDefinition |
240 | 241 | if t.name not in self.structs: |
241 | 242 | raise CastileTypeError("undefined struct %s" % t.name) |
242 | 243 | struct_defn = self.structs[t.name] |
244 | if struct_defn.scope_idents is not None: | |
245 | scope_idents = [ast.value for ast in struct_defn.scope_idents] | |
246 | if self.current_defn not in scope_idents: | |
247 | raise CastileTypeError("inaccessible struct %s for make: %s not in %s" % | |
248 | (t.name, self.current_defn, scope_idents) | |
249 | ) | |
243 | 250 | if len(struct_defn.content_types) != len(ast.children) - 1: |
244 | 251 | raise CastileTypeError("argument mismatch") |
245 | 252 | i = 0 |
286 | 293 | ast.type = Void() |
287 | 294 | self.resolve_structs(ast) |
288 | 295 | elif ast.tag == 'Defn': |
296 | self.current_defn = ast.value | |
289 | 297 | t = self.type_of(ast.children[0]) |
298 | self.current_defn = None | |
290 | 299 | if ast.value in self.forwards: |
291 | 300 | self.assert_eq(self.forwards[ast.value], t) |
292 | 301 | del self.forwards[ast.value] |