widl: Add support for '%' operator in expressions.
This commit is contained in:
parent
d27c7601e5
commit
ea9932557a
|
@ -520,6 +520,7 @@ void write_expr(FILE *h, const expr_t *e, int brackets)
|
|||
break;
|
||||
case EXPR_SHL:
|
||||
case EXPR_SHR:
|
||||
case EXPR_MOD:
|
||||
case EXPR_MUL:
|
||||
case EXPR_DIV:
|
||||
case EXPR_ADD:
|
||||
|
@ -533,6 +534,7 @@ void write_expr(FILE *h, const expr_t *e, int brackets)
|
|||
switch (e->type) {
|
||||
case EXPR_SHL: fprintf(h, " << "); break;
|
||||
case EXPR_SHR: fprintf(h, " >> "); break;
|
||||
case EXPR_MOD: fprintf(h, " %% "); break;
|
||||
case EXPR_MUL: fprintf(h, " * "); break;
|
||||
case EXPR_DIV: fprintf(h, " / "); break;
|
||||
case EXPR_ADD: fprintf(h, " + "); break;
|
||||
|
|
|
@ -293,7 +293,7 @@ static void add_explicit_handle_if_necessary(func_t *func);
|
|||
%left '|'
|
||||
%left '&'
|
||||
%left '-' '+'
|
||||
%left '*' '/'
|
||||
%left '*' '/' '%'
|
||||
%left SHL SHR
|
||||
%left '.' MEMBERPTR '[' ']'
|
||||
%right '~'
|
||||
|
@ -632,6 +632,7 @@ expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
|
|||
| expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
|
||||
| expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
|
||||
| expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
|
||||
| expr '%' expr { $$ = make_expr2(EXPR_MOD, $1, $3); }
|
||||
| expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
|
||||
| expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
|
||||
| expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
|
||||
|
@ -1238,6 +1239,13 @@ static expr_t *make_expr2(enum expr_type type, expr_t *expr1, expr_t *expr2)
|
|||
case EXPR_SUB:
|
||||
e->cval = expr1->cval - expr2->cval;
|
||||
break;
|
||||
case EXPR_MOD:
|
||||
if (expr2->cval == 0) {
|
||||
error_loc("divide by zero in expression\n");
|
||||
e->cval = 0;
|
||||
} else
|
||||
e->cval = expr1->cval % expr2->cval;
|
||||
break;
|
||||
case EXPR_MUL:
|
||||
e->cval = expr1->cval * expr2->cval;
|
||||
break;
|
||||
|
|
|
@ -352,6 +352,7 @@ static int compare_expr(const expr_t *a, const expr_t *b)
|
|||
case EXPR_AND:
|
||||
case EXPR_ADD:
|
||||
case EXPR_SUB:
|
||||
case EXPR_MOD:
|
||||
case EXPR_MUL:
|
||||
case EXPR_DIV:
|
||||
case EXPR_SHL:
|
||||
|
@ -3148,6 +3149,7 @@ static void write_struct_expr(FILE *h, const expr_t *e, int brackets,
|
|||
break;
|
||||
case EXPR_SHL:
|
||||
case EXPR_SHR:
|
||||
case EXPR_MOD:
|
||||
case EXPR_MUL:
|
||||
case EXPR_DIV:
|
||||
case EXPR_ADD:
|
||||
|
@ -3161,6 +3163,7 @@ static void write_struct_expr(FILE *h, const expr_t *e, int brackets,
|
|||
switch (e->type) {
|
||||
case EXPR_SHL: fprintf(h, " << "); break;
|
||||
case EXPR_SHR: fprintf(h, " >> "); break;
|
||||
case EXPR_MOD: fprintf(h, " %% "); break;
|
||||
case EXPR_MUL: fprintf(h, " * "); break;
|
||||
case EXPR_DIV: fprintf(h, " / "); break;
|
||||
case EXPR_ADD: fprintf(h, " + "); break;
|
||||
|
|
|
@ -164,6 +164,7 @@ enum expr_type
|
|||
EXPR_MEMBERPTR,
|
||||
EXPR_MEMBER,
|
||||
EXPR_ARRAY,
|
||||
EXPR_MOD,
|
||||
};
|
||||
|
||||
enum type_kind
|
||||
|
|
Loading…
Reference in New Issue