Commit d9b83e8b authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

widl: Add support for character constants in expressions.

parent 3fecf9dd
...@@ -87,7 +87,9 @@ expr_t *make_exprs(enum expr_type type, char *val) ...@@ -87,7 +87,9 @@ expr_t *make_exprs(enum expr_type type, char *val)
e->u.sval = val; e->u.sval = val;
e->is_const = FALSE; e->is_const = FALSE;
/* check for predefined constants */ /* check for predefined constants */
if (type == EXPR_IDENTIFIER) switch (type)
{
case EXPR_IDENTIFIER:
{ {
var_t *c = find_const(val, 0); var_t *c = find_const(val, 0);
if (c) if (c)
...@@ -97,6 +99,21 @@ expr_t *make_exprs(enum expr_type type, char *val) ...@@ -97,6 +99,21 @@ expr_t *make_exprs(enum expr_type type, char *val)
e->is_const = TRUE; e->is_const = TRUE;
e->cval = c->eval->cval; e->cval = c->eval->cval;
} }
break;
}
case EXPR_CHARCONST:
if (!val[0])
error_loc("empty character constant\n");
else if (val[1])
error_loc("multi-character constants are endian dependent\n");
else
{
e->is_const = TRUE;
e->cval = *val;
}
break;
default:
break;
} }
return e; return e;
} }
...@@ -457,6 +474,11 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc ...@@ -457,6 +474,11 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc
result.is_temporary = TRUE; result.is_temporary = TRUE;
result.type = type_new_pointer(RPC_FC_UP, type_new_int(TYPE_BASIC_WCHAR, 0), NULL); result.type = type_new_pointer(RPC_FC_UP, type_new_int(TYPE_BASIC_WCHAR, 0), NULL);
break; break;
case EXPR_CHARCONST:
result.is_variable = FALSE;
result.is_temporary = TRUE;
result.type = type_new_int(TYPE_BASIC_CHAR, 0);
break;
case EXPR_DOUBLE: case EXPR_DOUBLE:
result.is_variable = FALSE; result.is_variable = FALSE;
result.is_temporary = TRUE; result.is_temporary = TRUE;
...@@ -655,6 +677,9 @@ void write_expr(FILE *h, const expr_t *e, int brackets, ...@@ -655,6 +677,9 @@ void write_expr(FILE *h, const expr_t *e, int brackets,
case EXPR_WSTRLIT: case EXPR_WSTRLIT:
fprintf(h, "L\"%s\"", e->u.sval); fprintf(h, "L\"%s\"", e->u.sval);
break; break;
case EXPR_CHARCONST:
fprintf(h, "'%s'", e->u.sval);
break;
case EXPR_LOGNOT: case EXPR_LOGNOT:
fprintf(h, "!"); fprintf(h, "!");
write_expr(h, e->ref, 1, toplevel, toplevel_prefix, cont_type, local_var_prefix); write_expr(h, e->ref, 1, toplevel, toplevel_prefix, cont_type, local_var_prefix);
...@@ -804,6 +829,7 @@ int compare_expr(const expr_t *a, const expr_t *b) ...@@ -804,6 +829,7 @@ int compare_expr(const expr_t *a, const expr_t *b)
case EXPR_IDENTIFIER: case EXPR_IDENTIFIER:
case EXPR_STRLIT: case EXPR_STRLIT:
case EXPR_WSTRLIT: case EXPR_WSTRLIT:
case EXPR_CHARCONST:
return strcmp(a->u.sval, b->u.sval); return strcmp(a->u.sval, b->u.sval);
case EXPR_COND: case EXPR_COND:
ret = compare_expr(a->ref, b->ref); ret = compare_expr(a->ref, b->ref);
......
...@@ -37,6 +37,7 @@ double [0-9]+\.[0-9]+([eE][+-]?[0-9]+)* ...@@ -37,6 +37,7 @@ double [0-9]+\.[0-9]+([eE][+-]?[0-9]+)*
%x WSTRQUOTE %x WSTRQUOTE
%x ATTR %x ATTR
%x PP_LINE %x PP_LINE
%x SQUOTE
%{ %{
...@@ -157,10 +158,17 @@ UUID *parse_uuid(const char *u) ...@@ -157,10 +158,17 @@ UUID *parse_uuid(const char *u)
parser_lval.str = get_buffered_cstring(); parser_lval.str = get_buffered_cstring();
return aWSTRING; return aWSTRING;
} }
<QUOTE,WSTRQUOTE>\\\\ | <INITIAL,ATTR>\' yy_push_state(SQUOTE); cbufidx = 0;
<SQUOTE>\' {
yy_pop_state();
parser_lval.str = get_buffered_cstring();
return aSQSTRING;
}
<QUOTE,WSTRQUOTE,SQUOTE>\\\\ |
<QUOTE,WSTRQUOTE>\\\" addcchar(yytext[1]); <QUOTE,WSTRQUOTE>\\\" addcchar(yytext[1]);
<QUOTE,WSTRQUOTE>\\. addcchar('\\'); addcchar(yytext[1]); <SQUOTE>\\\' addcchar(yytext[1]);
<QUOTE,WSTRQUOTE>. addcchar(yytext[0]); <QUOTE,WSTRQUOTE,SQUOTE>\\. addcchar('\\'); addcchar(yytext[1]);
<QUOTE,WSTRQUOTE,SQUOTE>. addcchar(yytext[0]);
<INITIAL,ATTR>\[ yy_push_state(ATTR); return '['; <INITIAL,ATTR>\[ yy_push_state(ATTR); return '[';
<ATTR>\] yy_pop_state(); return ']'; <ATTR>\] yy_pop_state(); return ']';
<ATTR>{cident} return attr_token(yytext); <ATTR>{cident} return attr_token(yytext);
......
...@@ -186,7 +186,7 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s ...@@ -186,7 +186,7 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s
%token <str> aKNOWNTYPE %token <str> aKNOWNTYPE
%token <num> aNUM aHEXNUM %token <num> aNUM aHEXNUM
%token <dbl> aDOUBLE %token <dbl> aDOUBLE
%token <str> aSTRING aWSTRING %token <str> aSTRING aWSTRING aSQSTRING
%token <uuid> aUUID %token <uuid> aUUID
%token aEOF %token aEOF
%token SHL SHR %token SHL SHR
...@@ -632,6 +632,7 @@ expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); } ...@@ -632,6 +632,7 @@ expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
| tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); } | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
| aSTRING { $$ = make_exprs(EXPR_STRLIT, $1); } | aSTRING { $$ = make_exprs(EXPR_STRLIT, $1); }
| aWSTRING { $$ = make_exprs(EXPR_WSTRLIT, $1); } | aWSTRING { $$ = make_exprs(EXPR_WSTRLIT, $1); }
| aSQSTRING { $$ = make_exprs(EXPR_CHARCONST, $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 ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
| expr LOGICALOR expr { $$ = make_expr2(EXPR_LOGOR, $1, $3); } | expr LOGICALOR expr { $$ = make_expr2(EXPR_LOGOR, $1, $3); }
......
...@@ -186,6 +186,7 @@ enum expr_type ...@@ -186,6 +186,7 @@ enum expr_type
EXPR_POS, EXPR_POS,
EXPR_STRLIT, EXPR_STRLIT,
EXPR_WSTRLIT, EXPR_WSTRLIT,
EXPR_CHARCONST,
}; };
enum type_kind enum type_kind
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment