From 7f0abaffe5817b01ef62008a6c3401e3686ebba9 Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Mon, 19 Apr 2004 23:08:22 +0000 Subject: [PATCH] - Handle "? :" conditionals. - Allow [handle] attribute for types. --- tools/widl/header.c | 9 +++++++++ tools/widl/parser.l | 1 + tools/widl/parser.y | 29 +++++++++++++++++++++++++++++ tools/widl/widltypes.h | 3 +++ 4 files changed, 42 insertions(+) diff --git a/tools/widl/header.c b/tools/widl/header.c index 2c5b5c18a06..f863a0d09b5 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -378,6 +378,15 @@ static void do_write_expr(FILE *h, expr_t *e, int p) do_write_expr(h, e->u.ext, 1); if (p) fprintf(h, ")"); break; + case EXPR_COND: + if (p) fprintf(h, "("); + do_write_expr(h, e->ref, 1); + fprintf(h, " ? "); + do_write_expr(h, e->u.ext, 1); + fprintf(h, " : "); + do_write_expr(h, e->ext2, 1); + if (p) fprintf(h, ")"); + break; } } diff --git a/tools/widl/parser.l b/tools/widl/parser.l index ef26b42fa42..5639f91ef1d 100644 --- a/tools/widl/parser.l +++ b/tools/widl/parser.l @@ -221,6 +221,7 @@ static struct keyword { /* ... */ {"float", tFLOAT}, /* ... */ + {"handle", tHANDLE}, {"handle_t", tHANDLET}, /* ... */ {"helpstring", tHELPSTRING}, diff --git a/tools/widl/parser.y b/tools/widl/parser.y index f699ee29713..9a85a3ba203 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -72,6 +72,7 @@ static expr_t *make_exprs(enum expr_type type, char *val); static expr_t *make_exprt(enum expr_type type, typeref_t *tref, expr_t *expr); static expr_t *make_expr1(enum expr_type type, expr_t *expr); static expr_t *make_expr2(enum expr_type type, expr_t *exp1, expr_t *exp2); +static expr_t *make_expr3(enum expr_type type, expr_t *exp1, expr_t *exp2, expr_t *exp3); static type_t *make_type(BYTE type, type_t *ref); static typeref_t *make_tref(char *name, type_t *ref); static typeref_t *uniq_tref(typeref_t *ref); @@ -134,6 +135,7 @@ static type_t std_uhyper = { "MIDL_uhyper" }; %token tENTRY tENUM tERRORSTATUST %token tEXTERN %token tFLOAT +%token tHANDLE %token tHANDLET %token tHELPSTRING %token tHYPER tID tIDEMPOTENT @@ -327,6 +329,7 @@ attribute: | tDUAL { $$ = make_attr(ATTR_DUAL); } | tENTRY '(' aSTRING ')' { $$ = make_attrp(ATTR_ENTRY_STRING, $3); } | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY_ORDINAL, $3); } + | tHANDLE { $$ = make_attr(ATTR_HANDLE); } | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); } | tID '(' expr_const ')' { $$ = make_attrp(ATTR_ID, $3); } | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); } @@ -430,6 +433,7 @@ m_expr: { $$ = make_expr(EXPR_VOID); } expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); } | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); } | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); } + | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); } | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); } | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); } | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); } @@ -884,6 +888,31 @@ static expr_t *make_expr2(enum expr_type type, expr_t *expr1, expr_t *expr2) return e; } +static expr_t *make_expr3(enum expr_type type, expr_t *expr1, expr_t *expr2, expr_t *expr3) +{ + expr_t *e; + e = xmalloc(sizeof(expr_t)); + e->type = type; + e->ref = expr1; + e->u.ext = expr2; + e->ext2 = expr3; + e->is_const = FALSE; + INIT_LINK(e); + /* check for compile-time optimization */ + if (expr1->is_const && expr2->is_const && expr3->is_const) { + e->is_const = TRUE; + switch (type) { + case EXPR_COND: + e->cval = expr1->cval ? expr2->cval : expr3->cval; + break; + default: + e->is_const = FALSE; + break; + } + } + return e; +} + static type_t *make_type(BYTE type, type_t *ref) { type_t *t = xmalloc(sizeof(type_t)); diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index c4843f34821..a5722c12336 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -62,6 +62,7 @@ enum attr_type ATTR_DUAL, ATTR_ENTRY_STRING, ATTR_ENTRY_ORDINAL, + ATTR_HANDLE, ATTR_HELPSTRING, ATTR_ID, ATTR_IDEMPOTENT, @@ -109,6 +110,7 @@ enum expr_type EXPR_SUB, EXPR_AND, EXPR_OR, + EXPR_COND, }; struct _attr_t { @@ -130,6 +132,7 @@ struct _expr_t { expr_t *ext; typeref_t *tref; } u; + expr_t *ext2; int is_const; long cval; /* parser-internal */