allowing inexing of array-fields

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-11-12 23:35:47 +01:00
parent dbdcdb059e
commit d60a76abd1
2 changed files with 13 additions and 1 deletions

9
ast.c
View file

@ -588,6 +588,15 @@ ast_array_index* ast_array_index_new(lex_ctx ctx, ast_expression *array, ast_exp
ast_array_index_delete(self);
return NULL;
}
if (array->expression.vtype == TYPE_FIELD && outtype->expression.vtype == TYPE_ARRAY) {
if (self->expression.vtype != TYPE_ARRAY) {
asterror(ast_ctx(self), "array_index node on type");
ast_array_index_delete(self);
return NULL;
}
self->array = outtype;
self->expression.vtype = TYPE_FIELD;
}
return self;
}

View file

@ -464,7 +464,10 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
break;
case opid1('['):
if (exprs[0]->expression.vtype != TYPE_ARRAY) {
if (exprs[0]->expression.vtype != TYPE_ARRAY &&
!(exprs[0]->expression.vtype == TYPE_FIELD &&
exprs[0]->expression.next->expression.vtype == TYPE_ARRAY))
{
ast_type_to_string(exprs[0], ty1, sizeof(ty1));
parseerror(parser, "cannot index value of type %s", ty1);
return false;