mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 20:35:38 +02:00
bug 156137 - Expression Evaluator does not handle %
This commit is contained in:
parent
354a0a70da
commit
5c49412ff9
2 changed files with 18 additions and 4 deletions
|
@ -2414,4 +2414,15 @@ public class Scanner2Test extends BaseScanner2Test
|
||||||
initializeScanner(buffer.toString(), ParserLanguage.CPP);
|
initializeScanner(buffer.toString(), ParserLanguage.CPP);
|
||||||
fullyTokenize();
|
fullyTokenize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug156137() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("#if (3 % 2 == 1) \n");
|
||||||
|
buffer.append("C \n");
|
||||||
|
buffer.append("#endif \n");
|
||||||
|
|
||||||
|
initializeScanner(buffer.toString());
|
||||||
|
validateIdentifier("C");
|
||||||
|
validateEOF();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -382,7 +382,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
|
|
||||||
private long multiplicativeExpression() throws EvalException {
|
private long multiplicativeExpression() throws EvalException {
|
||||||
long r1 = unaryExpression();
|
long r1 = unaryExpression();
|
||||||
for (int t = LA(); t == tMULT || t == tDIV; t = LA()) {
|
for (int t = LA(); t == tMULT || t == tDIV || t == tMOD; t = LA()) {
|
||||||
int position = pos; // for IProblem /0 below, need position
|
int position = pos; // for IProblem /0 below, need position
|
||||||
// before
|
// before
|
||||||
// consume()
|
// consume()
|
||||||
|
@ -390,9 +390,12 @@ abstract class BaseScanner implements IScanner {
|
||||||
long r2 = unaryExpression();
|
long r2 = unaryExpression();
|
||||||
if (t == tMULT)
|
if (t == tMULT)
|
||||||
r1 = r1 * r2;
|
r1 = r1 * r2;
|
||||||
else if (r2 != 0)// t == tDIV;
|
else if (r2 != 0) {
|
||||||
r1 = r1 / r2;
|
if (t == tDIV)
|
||||||
else {
|
r1 = r1 / r2;
|
||||||
|
else
|
||||||
|
r1 = r1 % r2; //tMOD
|
||||||
|
} else {
|
||||||
handleProblem(IProblem.SCANNER_DIVIDE_BY_ZERO, position);
|
handleProblem(IProblem.SCANNER_DIVIDE_BY_ZERO, position);
|
||||||
throw new EvalException("Divide by 0 encountered"); //$NON-NLS-1$
|
throw new EvalException("Divide by 0 encountered"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue