diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-01-03 17:40:17 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-01-03 17:40:17 +0000 |
commit | 540960f4a28c45079c2f9bddc23ec3bff808b45b (patch) | |
tree | 90781c9094394d3b631ca83c5fae39462bd476eb /clang/lib/Lex/PPDirectives.cpp | |
parent | dc276c315cec9e33df8e0e171b686f79143f651d (diff) | |
download | bcm5719-llvm-540960f4a28c45079c2f9bddc23ec3bff808b45b.tar.gz bcm5719-llvm-540960f4a28c45079c2f9bddc23ec3bff808b45b.zip |
Fix PR8654, ensuring each branch of an #if, #elif, #else, ... chain
receives a PPCallback.
Patch by Richard Smith.
llvm-svn: 122755
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 00cdbd774e3..5f4c321715d 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -298,7 +298,10 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, 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 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, // 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 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, 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 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, 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; |