[cfe-commits] r38651 - /cfe/cfe/trunk/Lex/PPExpressions.cpp
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:23:32 PDT 2007
Author: sabre
Date: Wed Jul 11 11:23:32 2007
New Revision: 38651
URL: http://llvm.org/viewvc/llvm-project?rev=38651&view=rev
Log:
refactor code a little, no functionality change
Modified:
cfe/cfe/trunk/Lex/PPExpressions.cpp
Modified: cfe/cfe/trunk/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/PPExpressions.cpp?rev=38651&r1=38650&r2=38651&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/PPExpressions.cpp (original)
+++ cfe/cfe/trunk/Lex/PPExpressions.cpp Wed Jul 11 11:23:32 2007
@@ -7,7 +7,8 @@
//
//===----------------------------------------------------------------------===//
//
-// This file implements the Preprocessor::EvaluateDirectiveExpression method.
+// This file implements the Preprocessor::EvaluateDirectiveExpression method,
+// which parses and evaluates integer constant expressions for #if directives.
//
//===----------------------------------------------------------------------===//
//
@@ -26,8 +27,8 @@
using namespace clang;
/// EvaluateDirectiveExpression - Evaluate an integer constant expression that
-/// may occur after a #if or #elif directive. If the
-/// expression is equivalent to "!defined(X)" return X in IfNDefMacro.
+/// may occur after a #if or #elif directive. If the expression is equivalent
+/// to "!defined(X)" return X in IfNDefMacro.
bool Preprocessor::
EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) {
// Peek ahead one token.
@@ -35,9 +36,24 @@
Lex(Tok);
int ResVal = 0;
- if (EvaluateValue(ResVal, Tok) ||
- EvaluateDirectiveSubExpr(ResVal, 1, Tok)) {
- // Skip the rest of the macro line.
+ if (EvaluateValue(ResVal, Tok)) {
+ // Parse error, skip the rest of the macro line.
+ if (Tok.getKind() != tok::eom)
+ DiscardUntilEndOfDirective();
+ return false;
+ }
+
+ // If we are at the end of the expression after just parsing a value, there
+ // must be no (unparenthesized) binary operators involved, so we can exit
+ // directly.
+ if (Tok.getKind() == tok::eom) {
+ return ResVal != 0;
+ }
+
+ // Otherwise, we must have a binary operator (e.g. "#if 1 < 2"), so parse the
+ // operator and the stuff after it.
+ if (EvaluateDirectiveSubExpr(ResVal, 1, Tok)) {
+ // Parse error, skip the rest of the macro line.
if (Tok.getKind() != tok::eom)
DiscardUntilEndOfDirective();
return false;
More information about the cfe-commits
mailing list