commit 28e44b2545e3c82482006f86c48f36e0786ddc7b
parent 18602f1f32899cb74170a42ec4a1dc90fcb093b9
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 21 Apr 2014 11:21:35 +0200
Check integer operands in modulo operator
Modulo operator only can be used with integer operands, so it has the
same requirements than bitlogic(), so we can change the name and use it
for bit logic and modulo operators.
Diffstat:
M | expr.c | | | 34 | +++++++++++++++++----------------- |
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/expr.c b/expr.c
@@ -59,10 +59,10 @@ typeconv(Node **p1, Node **p2)
}
static Node *
-bitlogic(char op, Node *np1, Node *np2)
+integerop(char op, Node *np1, Node *np2)
{
if (np1->typeop != INT || np2->typeop != INT)
- error("No integer operand in bit logical operation");
+ error("operator requires integer operands");
typeconv(&np1, &np2);
return bincode(op, np1->type, np1, np2);
}
@@ -510,19 +510,19 @@ cast(void)
static Node *
mul(void)
{
- register Node *np;
+ register Node *np, *(*fun)(char, Node *, Node *);
register char op;
np = cast();
for (;;) {
switch (yytoken) {
- case '*': op = OMUL; break;
- case '/': op = ODIV; break;
- case '%': op = OMOD; break; /* TODO: check int type */
+ case '*': op = OMUL; fun = arithmetic; break;
+ case '/': op = ODIV; fun = arithmetic; break;
+ case '%': op = OMOD; fun = integerop; break;
default: return np;
}
next();
- np = arithmetic(op, np, cast());
+ np = (*fun)(op, np, cast());
}
}
@@ -558,7 +558,7 @@ shift(void)
default: return np;
}
next();
- np = bitlogic(op, np, add());
+ np = integerop(op, np, add());
}
}
@@ -607,7 +607,7 @@ bit_and(void)
np = eq();
while (accept('&'))
- np = bitlogic(OBAND, np, eq());
+ np = integerop(OBAND, np, eq());
return np;
}
@@ -618,7 +618,7 @@ bit_xor(void)
np = bit_and();
while (accept('^'))
- np = bitlogic(OBXOR, np, bit_and());
+ np = integerop(OBXOR, np, bit_and());
return np;
}
@@ -629,7 +629,7 @@ bit_or(void)
np = bit_xor();
while (accept('|'))
- np = bitlogic(OBOR, np, bit_xor());
+ np = integerop(OBOR, np, bit_xor());
return np;
}
@@ -684,14 +684,14 @@ assign(void)
case '=': op = OASSIGN; fun = assignop; break;
case MUL_EQ: op = OA_MUL; fun = arithmetic; break;
case DIV_EQ: op = OA_DIV; fun = arithmetic; break;
- case MOD_EQ: op = OA_MOD; fun = bitlogic; break;
+ case MOD_EQ: op = OA_MOD; fun = integerop; break;
case ADD_EQ: op = OA_ADD; fun = arithmetic; break;
case SUB_EQ: op = OA_SUB; fun = arithmetic; break;
- case SHL_EQ: op = OA_SHL; fun = bitlogic; break;
- case SHR_EQ: op = OA_SHR; fun = bitlogic; break;
- case AND_EQ: op = OA_AND; fun = bitlogic; break;
- case XOR_EQ: op = OA_XOR; fun = bitlogic; break;
- case OR_EQ: op = OA_OR; fun = bitlogic; break;
+ case SHL_EQ: op = OA_SHL; fun = integerop; break;
+ case SHR_EQ: op = OA_SHR; fun = integerop; break;
+ case AND_EQ: op = OA_AND; fun = integerop; break;
+ case XOR_EQ: op = OA_XOR; fun = integerop; break;
+ case OR_EQ: op = OA_OR; fun = integerop; break;
default: return np;
}
if (!np->b.lvalue)