From d60a76abd178d04ab3aba684c7b56cf8fac67153 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Mon, 12 Nov 2012 23:35:47 +0100 Subject: [PATCH] allowing inexing of array-fields --- ast.c | 9 +++++++++ parser.c | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ast.c b/ast.c index bfdcf62..aa65da2 100644 --- a/ast.c +++ b/ast.c @@ -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; } diff --git a/parser.c b/parser.c index b81d06c..250a75a 100644 --- a/parser.c +++ b/parser.c @@ -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; -- 2.39.2