[cfe-commits] r122755 - /cfe/trunk/lib/Lex/PPDirectives.cpp
Chandler Carruth
chandlerc at gmail.com
Mon Jan 3 09:40:17 PST 2011
Author: chandlerc
Date: Mon Jan 3 11:40:17 2011
New Revision: 122755
URL: http://llvm.org/viewvc/llvm-project?rev=122755&view=rev
Log:
Fix PR8654, ensuring each branch of an #if, #elif, #else, ... chain
receives a PPCallback.
Patch by Richard Smith.
Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=122755&r1=122754&r2=122755&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Mon Jan 3 11:40:17 2011
@@ -298,7 +298,10 @@
DiscardUntilEndOfDirective();
CurPPLexer->pushConditionalLevel(Tok.getLocation(), /*wasskipping*/true,
/*foundnonskip*/false,
- /*fnddelse*/false);
+ /*foundelse*/false);
+
+ if (Callbacks)
+ Callbacks->Endif();
}
} else if (Directive[0] == 'e') {
llvm::StringRef Sub = Directive.substr(1);
@@ -326,6 +329,9 @@
// Note that we've seen a #else in this conditional.
CondInfo.FoundElse = true;
+ if (Callbacks)
+ Callbacks->Else();
+
// If the conditional is at the top level, and the #if block wasn't
// entered, enter the #else block now.
if (!CondInfo.WasSkipping && !CondInfo.FoundNonSkip) {
@@ -336,6 +342,7 @@
PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel();
bool ShouldEnter;
+ const SourceLocation ConditionalBegin = CurPPLexer->getSourceLocation();
// If this is in a skipping block or if we're already handled this #if
// block, don't bother parsing the condition.
if (CondInfo.WasSkipping || CondInfo.FoundNonSkip) {
@@ -350,10 +357,14 @@
ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro);
CurPPLexer->LexingRawMode = true;
}
+ const SourceLocation ConditionalEnd = CurPPLexer->getSourceLocation();
// If this is a #elif with a #else before it, report the error.
if (CondInfo.FoundElse) Diag(Tok, diag::pp_err_elif_after_else);
+ if (Callbacks)
+ Callbacks->Elif(SourceRange(ConditionalBegin, ConditionalEnd));
+
// If this condition is true, enter it!
if (ShouldEnter) {
CondInfo.FoundNonSkip = true;
More information about the cfe-commits
mailing list