66 | 66 |
type_exprs = []
|
67 | 67 |
i = 0
|
68 | 68 |
field_defns = ast.children[0].children
|
69 | |
scope_idents = ast.children[1].children if len(ast.children) > 1 else None
|
|
69 |
scope_idents = None
|
|
70 |
if len(ast.children) > 1:
|
|
71 |
scope_idents = [a.value for a in ast.children[1].children]
|
70 | 72 |
for child in field_defns:
|
71 | 73 |
assert child.tag == 'FieldDefn', child.tag
|
72 | 74 |
field_name = child.value
|
|
242 | 244 |
raise CastileTypeError("undefined struct %s" % t.name)
|
243 | 245 |
struct_defn = self.structs[t.name]
|
244 | 246 |
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)
|
|
247 |
if self.current_defn not in struct_defn.scope_idents:
|
|
248 |
raise CastileTypeError("inaccessible struct %s for make: %s not in %s" %
|
|
249 |
(t.name, self.current_defn, struct_defn.scope_idents)
|
249 | 250 |
)
|
250 | 251 |
if len(struct_defn.content_types) != len(ast.children) - 1:
|
251 | |
raise CastileTypeError("argument mismatch")
|
|
252 |
raise CastileTypeError("argument mismatch; expected {}, got {} in {}".format(
|
|
253 |
len(struct_defn.content_types), len(ast.children) - 1, ast
|
|
254 |
))
|
252 | 255 |
i = 0
|
253 | 256 |
for defn in ast.children[1:]:
|
254 | 257 |
name = defn.value
|
|
262 | 265 |
ast.type = self.type_of(ast.children[0])
|
263 | 266 |
elif ast.tag == 'Index':
|
264 | 267 |
t = self.type_of(ast.children[0])
|
|
268 |
struct_defn = self.structs[t.name]
|
|
269 |
if struct_defn.scope_idents is not None:
|
|
270 |
if self.current_defn not in struct_defn.scope_idents:
|
|
271 |
raise CastileTypeError("inaccessible struct %s for access: %s not in %s" %
|
|
272 |
(t.name, self.current_defn, struct_defn.scope_idents)
|
|
273 |
)
|
265 | 274 |
field_name = ast.value
|
266 | |
struct_fields = self.structs[t.name].field_names
|
|
275 |
struct_fields = struct_defn.field_names
|
267 | 276 |
if field_name not in struct_fields:
|
268 | 277 |
raise CastileTypeError("undefined field")
|
269 | 278 |
index = struct_fields[field_name]
|
270 | 279 |
# we make this value available to compiler backends
|
271 | 280 |
ast.aux = index
|
272 | 281 |
# we look up the type from the StructDefinition
|
273 | |
ast.type = self.structs[t.name].content_types[index]
|
|
282 |
ast.type = struct_defn.content_types[index]
|
274 | 283 |
elif ast.tag == 'TypeCase':
|
275 | 284 |
t1 = self.type_of(ast.children[0])
|
276 | 285 |
t2 = self.type_of(ast.children[1])
|