1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Handles keywords in expression evaluator, bug 246369.

This commit is contained in:
Markus Schorn 2008-09-08 08:39:33 +00:00
parent 8d99a621b3
commit cce773e663
2 changed files with 36 additions and 0 deletions

View file

@ -149,4 +149,20 @@ public class PreprocessorBugsTests extends PreprocessorTestsBase {
validateEOF();
validateProblemCount(0);
}
// #if if
// no
// #else
// yes
// #endif
// #if or
// no
// #endif
public void testKeywordsInConditionalExpression_Bug246369() throws Exception {
initializeScanner();
validateIdentifier("yes");
validateEOF();
validateProblemCount(1);
validateProblem(0, IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR, null);
}
}

View file

@ -257,7 +257,27 @@ class ExpressionEvaluator {
case IToken.tIDENTIFIER:
consume();
return 0;
// 16.1.4 alternate keywords are not replaced by a 0
case IToken.tAND:
case IToken.tOR:
case IToken.tBITOR:
case IToken.tBITORASSIGN:
case IToken.tXOR:
case IToken.tXORASSIGN:
case IToken.tAMPER:
case IToken.tAMPERASSIGN:
case IToken.tSTRING:
case IToken.tLSTRING:
throw new EvalException(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR, null);
default:
// 16.1.4 keywords are replaced by 0
final char[] image= fTokens.getCharImage();
if (image.length > 0) {
final char c= image[0];
if ((c>='a' && c<='z') || (c>='A' && c<='Z') || c == '_' || c=='$' || c=='@')
return 0;
}
throw new EvalException(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR, null);
}
}