def subscript(self):
sub = Expr.parse_variable_location(self.expr.value, self.context)
if isinstance(sub.typ, (MappingType, ListType)):
if 'value' not in vars(self.expr.slice):
raise StructureException("Array access must access a single element, not a slice", self.expr)
index = Expr.parse_value_expr(self.expr.slice.value, self.context)
elif isinstance(sub.typ, TupleType):
if not isinstance(self.expr.slice.value, ast.Num) or self.expr.slice.value.n < 0 or self.expr.slice.value.n >= len(sub.typ.members):
raise TypeMismatchException("Tuple index invalid", self.expr.slice.value)
index = self.expr.slice.value.n
else:
raise TypeMismatchException("Bad subscript attempt", self.expr.value)
o = add_variable_offset(sub, index)
o.mutable = sub.mutable
return o
评论列表
文章目录