From d27c7601e5d1e4b6107aae11a0273a91235f6a98 Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Sun, 20 Apr 2008 22:16:00 +0100 Subject: [PATCH] widl: Add support for arrays in expressions. --- tools/widl/header.c | 8 ++++++++ tools/widl/parser.y | 3 ++- tools/widl/typegen.c | 9 +++++++++ tools/widl/widltypes.h | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/widl/header.c b/tools/widl/header.c index d2f7ca77688..6989149ca1f 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -559,6 +559,14 @@ void write_expr(FILE *h, const expr_t *e, int brackets) fprintf(h, "&"); write_expr(h, e->ref, 1); break; + case EXPR_ARRAY: + if (brackets) fprintf(h, "("); + write_expr(h, e->ref, 1); + fprintf(h, "["); + write_expr(h, e->u.ext, 1); + fprintf(h, "]"); + if (brackets) fprintf(h, ")"); + break; } } diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 61a1252c87a..32752bf15da 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -295,7 +295,7 @@ static void add_explicit_handle_if_necessary(func_t *func); %left '-' '+' %left '*' '/' %left SHL SHR -%left '.' MEMBERPTR +%left '.' MEMBERPTR '[' ']' %right '~' %right CAST %right PPTR @@ -644,6 +644,7 @@ expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); } | expr '.' expr { $$ = make_expr2(EXPR_MEMBER, $1, $3); } | '(' type ')' expr %prec CAST { $$ = make_exprt(EXPR_CAST, $2, $4); } | tSIZEOF '(' type ')' { $$ = make_exprt(EXPR_SIZEOF, $3, NULL); } + | expr '[' expr ']' { $$ = make_expr2(EXPR_ARRAY, $1, $3); } | '(' expr ')' { $$ = $2; } ; diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c index b298403abec..da5c95aa262 100644 --- a/tools/widl/typegen.c +++ b/tools/widl/typegen.c @@ -358,6 +358,7 @@ static int compare_expr(const expr_t *a, const expr_t *b) case EXPR_SHR: case EXPR_MEMBERPTR: case EXPR_MEMBER: + case EXPR_ARRAY: ret = compare_expr(a->ref, b->ref); if (ret != 0) return ret; @@ -3186,6 +3187,14 @@ static void write_struct_expr(FILE *h, const expr_t *e, int brackets, fprintf(h, "&"); write_struct_expr(h, e->ref, 1, fields, structvar); break; + case EXPR_ARRAY: + if (brackets) fprintf(h, "("); + write_struct_expr(h, e->ref, 1, fields, structvar); + fprintf(h, "["); + write_struct_expr(h, e->u.ext, 1, fields, structvar); + fprintf(h, "]"); + if (brackets) fprintf(h, ")"); + break; } } diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 256a3ad8435..31c7599a554 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -163,6 +163,7 @@ enum expr_type EXPR_ADDRESSOF, EXPR_MEMBERPTR, EXPR_MEMBER, + EXPR_ARRAY, }; enum type_kind