From 53c70aec87a9f7706175cd94399ef81a8e37fe25 Mon Sep 17 00:00:00 2001 From: Elizabeth Figura Date: Fri, 21 Jun 2024 19:20:38 -0500 Subject: [PATCH] widl: Respect u and l modifiers in expressions. --- tools/widl/expr.c | 6 +++++- tools/widl/parser.l | 2 ++ tools/widl/widltypes.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/widl/expr.c b/tools/widl/expr.c index e51ed6c94c4..be818de2e83 100644 --- a/tools/widl/expr.c +++ b/tools/widl/expr.c @@ -512,7 +512,7 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc case EXPR_NUM: case EXPR_TRUEFALSE: result.is_temporary = FALSE; - result.type = type_new_int(TYPE_BASIC_INT, 0); + result.type = type_new_int(e->u.integer.is_long ? TYPE_BASIC_LONG : TYPE_BASIC_INT, e->u.integer.is_unsigned); break; case EXPR_STRLIT: result.is_temporary = TRUE; @@ -690,6 +690,10 @@ void write_expr(FILE *h, const expr_t *e, int brackets, fprintf(h, "0x%x", e->u.integer.value); else fprintf(h, "%u", e->u.integer.value); + if (e->u.integer.is_unsigned) + fprintf(h, "u"); + if (e->u.integer.is_long) + fprintf(h, "l"); break; case EXPR_DOUBLE: fprintf(h, "%#.15g", e->u.dval); diff --git a/tools/widl/parser.l b/tools/widl/parser.l index 1e7c543e8af..87a9fc55f07 100644 --- a/tools/widl/parser.l +++ b/tools/widl/parser.l @@ -158,6 +158,8 @@ static int token_num( const char *yytext, YYSTYPE *yylval, int is_hex ) { yylval->integer.value = xstrtoul( yytext, NULL, 0 ); yylval->integer.is_hex = is_hex; + yylval->integer.is_long = !!strchr(yytext, 'l'); + yylval->integer.is_unsigned = !!strchr(yytext, 'u'); return is_hex ? aHEXNUM : aNUM; } diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 44559e9f2ef..5ee1323793d 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -351,6 +351,8 @@ struct _attr_t { struct integer { int value; + int is_unsigned; + int is_long; int is_hex; };