- Handle "? :" conditionals.

- Allow [handle] attribute for types.
This commit is contained in:
Robert Shearman 2004-04-19 23:08:22 +00:00 committed by Alexandre Julliard
parent a98056191d
commit 7f0abaffe5
4 changed files with 42 additions and 0 deletions

View File

@ -378,6 +378,15 @@ static void do_write_expr(FILE *h, expr_t *e, int p)
do_write_expr(h, e->u.ext, 1); do_write_expr(h, e->u.ext, 1);
if (p) fprintf(h, ")"); if (p) fprintf(h, ")");
break; 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;
} }
} }

View File

@ -221,6 +221,7 @@ static struct keyword {
/* ... */ /* ... */
{"float", tFLOAT}, {"float", tFLOAT},
/* ... */ /* ... */
{"handle", tHANDLE},
{"handle_t", tHANDLET}, {"handle_t", tHANDLET},
/* ... */ /* ... */
{"helpstring", tHELPSTRING}, {"helpstring", tHELPSTRING},

View File

@ -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_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_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_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 type_t *make_type(BYTE type, type_t *ref);
static typeref_t *make_tref(char *name, type_t *ref); static typeref_t *make_tref(char *name, type_t *ref);
static typeref_t *uniq_tref(typeref_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 tENTRY tENUM tERRORSTATUST
%token tEXTERN %token tEXTERN
%token tFLOAT %token tFLOAT
%token tHANDLE
%token tHANDLET %token tHANDLET
%token tHELPSTRING %token tHELPSTRING
%token tHYPER tID tIDEMPOTENT %token tHYPER tID tIDEMPOTENT
@ -327,6 +329,7 @@ attribute:
| tDUAL { $$ = make_attr(ATTR_DUAL); } | tDUAL { $$ = make_attr(ATTR_DUAL); }
| tENTRY '(' aSTRING ')' { $$ = make_attrp(ATTR_ENTRY_STRING, $3); } | tENTRY '(' aSTRING ')' { $$ = make_attrp(ATTR_ENTRY_STRING, $3); }
| tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY_ORDINAL, $3); } | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY_ORDINAL, $3); }
| tHANDLE { $$ = make_attr(ATTR_HANDLE); }
| tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); } | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
| tID '(' expr_const ')' { $$ = make_attrp(ATTR_ID, $3); } | tID '(' expr_const ')' { $$ = make_attrp(ATTR_ID, $3); }
| tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); } | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
@ -430,6 +433,7 @@ m_expr: { $$ = make_expr(EXPR_VOID); }
expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); } expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
| aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); } | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
| aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $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_OR , $1, $3); }
| expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); } | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
| expr '+' expr { $$ = make_expr2(EXPR_ADD, $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; 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) static type_t *make_type(BYTE type, type_t *ref)
{ {
type_t *t = xmalloc(sizeof(type_t)); type_t *t = xmalloc(sizeof(type_t));

View File

@ -62,6 +62,7 @@ enum attr_type
ATTR_DUAL, ATTR_DUAL,
ATTR_ENTRY_STRING, ATTR_ENTRY_STRING,
ATTR_ENTRY_ORDINAL, ATTR_ENTRY_ORDINAL,
ATTR_HANDLE,
ATTR_HELPSTRING, ATTR_HELPSTRING,
ATTR_ID, ATTR_ID,
ATTR_IDEMPOTENT, ATTR_IDEMPOTENT,
@ -109,6 +110,7 @@ enum expr_type
EXPR_SUB, EXPR_SUB,
EXPR_AND, EXPR_AND,
EXPR_OR, EXPR_OR,
EXPR_COND,
}; };
struct _attr_t { struct _attr_t {
@ -130,6 +132,7 @@ struct _expr_t {
expr_t *ext; expr_t *ext;
typeref_t *tref; typeref_t *tref;
} u; } u;
expr_t *ext2;
int is_const; int is_const;
long cval; long cval;
/* parser-internal */ /* parser-internal */