On Sun, Mar 4, 2012 at 9:48 PM, Argyrios Kyrtzidis <[email protected]>wrote:
> Author: akirtzidis > Date: Sun Mar 4 23:48:09 2012 > New Revision: 152017 > > URL: http://llvm.org/viewvc/llvm-project?rev=152017&view=rev > Log: > [preprocessor] Enhance the preprocessor callbacks: > > -Add location parameter for the directives callbacks > -Skip callbacks if the directive is inside a skipped range. > -Make sure the directive callbacks are invoked in source order. > > Modified: > cfe/trunk/include/clang/Lex/PPCallbacks.h > cfe/trunk/lib/Lex/PPDirectives.cpp > > Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=152017&r1=152016&r2=152017&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Lex/PPCallbacks.h (original) > +++ cfe/trunk/include/clang/Lex/PPCallbacks.h Sun Mar 4 23:48:09 2012 > @@ -192,33 +192,34 @@ > /// If -- This hook is called whenever an #if is seen. > /// \param Range The SourceRange of the expression being tested. > // FIXME: better to pass in a list (or tree!) of Tokens. > - virtual void If(SourceRange Range) { > + virtual void If(SourceLocation Loc, SourceRange ConditionRange) { > Don't forget to update the doxygen comments about the method parameters here and for the other callback methods you modified. Thanks, Kaelyn > } > > /// Elif -- This hook is called whenever an #elif is seen. > /// \param Range The SourceRange of the expression being tested. > // FIXME: better to pass in a list (or tree!) of Tokens. > - virtual void Elif(SourceRange Range) { > + virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, > + SourceLocation IfLoc) { > } > > /// Ifdef -- This hook is called whenever an #ifdef is seen. > /// \param Loc The location of the token being tested. > /// \param II Information on the token being tested. > - virtual void Ifdef(const Token &MacroNameTok) { > + virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok) { > } > > /// Ifndef -- This hook is called whenever an #ifndef is seen. > /// \param Loc The location of the token being tested. > /// \param II Information on the token being tested. > - virtual void Ifndef(const Token &MacroNameTok) { > + virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok) { > } > > /// Else -- This hook is called whenever an #else is seen. > - virtual void Else() { > + virtual void Else(SourceLocation Loc, SourceLocation IfLoc) { > } > > /// Endif -- This hook is called whenever an #endif is seen. > - virtual void Endif() { > + virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) { > } > }; > > @@ -335,39 +336,40 @@ > } > > /// If -- This hook is called whenever an #if is seen. > - virtual void If(SourceRange Range) { > - First->If(Range); > - Second->If(Range); > + virtual void If(SourceLocation Loc, SourceRange ConditionRange) { > + First->If(Loc, ConditionRange); > + Second->If(Loc, ConditionRange); > } > > /// Elif -- This hook is called whenever an #if is seen. > - virtual void Elif(SourceRange Range) { > - First->Elif(Range); > - Second->Elif(Range); > + virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, > + SourceLocation IfLoc) { > + First->Elif(Loc, ConditionRange, IfLoc); > + Second->Elif(Loc, ConditionRange, IfLoc); > } > > /// Ifdef -- This hook is called whenever an #ifdef is seen. > - virtual void Ifdef(const Token &MacroNameTok) { > - First->Ifdef(MacroNameTok); > - Second->Ifdef(MacroNameTok); > + virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok) { > + First->Ifdef(Loc, MacroNameTok); > + Second->Ifdef(Loc, MacroNameTok); > } > > /// Ifndef -- This hook is called whenever an #ifndef is seen. > - virtual void Ifndef(const Token &MacroNameTok) { > - First->Ifndef(MacroNameTok); > - Second->Ifndef(MacroNameTok); > + virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok) { > + First->Ifndef(Loc, MacroNameTok); > + Second->Ifndef(Loc, MacroNameTok); > } > > /// Else -- This hook is called whenever an #else is seen. > - virtual void Else() { > - First->Else(); > - Second->Else(); > + virtual void Else(SourceLocation Loc, SourceLocation IfLoc) { > + First->Else(Loc, IfLoc); > + Second->Else(Loc, IfLoc); > } > > /// Endif -- This hook is called whenever an #endif is seen. > - virtual void Endif() { > - First->Endif(); > - Second->Endif(); > + virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) { > + First->Endif(Loc, IfLoc); > + Second->Endif(Loc, IfLoc); > } > }; > > > Modified: cfe/trunk/lib/Lex/PPDirectives.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=152017&r1=152016&r2=152017&view=diff > > ============================================================================== > --- cfe/trunk/lib/Lex/PPDirectives.cpp (original) > +++ cfe/trunk/lib/Lex/PPDirectives.cpp Sun Mar 4 23:48:09 2012 > @@ -313,9 +313,6 @@ > CurPPLexer->pushConditionalLevel(Tok.getLocation(), > /*wasskipping*/true, > /*foundnonskip*/false, > /*foundelse*/false); > - > - if (Callbacks) > - Callbacks->Endif(); > } > } else if (Directive[0] == 'e') { > StringRef Sub = Directive.substr(1); > @@ -328,8 +325,11 @@ > assert(!InCond && "Can't be skipping if not in a conditional!"); > > // If we popped the outermost skipping block, we're done skipping! > - if (!CondInfo.WasSkipping) > + if (!CondInfo.WasSkipping) { > + if (Callbacks) > + Callbacks->Endif(Tok.getLocation(), CondInfo.IfLoc); > break; > + } > } else if (Sub == "lse") { // "else". > // #else directive in a skipping conditional. If not in some other > // skipping conditional, and if #else hasn't already been seen, > enter it > @@ -342,14 +342,13 @@ > // 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) { > CondInfo.FoundNonSkip = true; > CheckEndOfDirective("else"); > + if (Callbacks) > + Callbacks->Else(Tok.getLocation(), CondInfo.IfLoc); > break; > } else { > DiscardUntilEndOfDirective(); // C99 6.10p4. > @@ -378,12 +377,13 @@ > // 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; > + if (Callbacks) > + Callbacks->Elif(Tok.getLocation(), > + SourceRange(ConditionalBegin, ConditionalEnd), > + CondInfo.IfLoc); > break; > } > } > @@ -1897,6 +1897,13 @@ > if (MI) // Mark it used. > markMacroAsUsed(MI); > > + if (Callbacks) { > + if (isIfndef) > + Callbacks->Ifndef(DirectiveTok.getLocation(), MacroNameTok); > + else > + Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok); > + } > + > // Should we include the stuff contained by this directive? > if (!MI == isIfndef) { > // Yes, remember that we are inside a conditional, then lex the next > token. > @@ -1909,13 +1916,6 @@ > /*Foundnonskip*/false, > /*FoundElse*/false); > } > - > - if (Callbacks) { > - if (isIfndef) > - Callbacks->Ifndef(MacroNameTok); > - else > - Callbacks->Ifdef(MacroNameTok); > - } > } > > /// HandleIfDirective - Implements the #if directive. > @@ -1939,6 +1939,10 @@ > CurPPLexer->MIOpt.EnterTopLevelConditional(); > } > > + if (Callbacks) > + Callbacks->If(IfToken.getLocation(), > + SourceRange(ConditionalBegin, ConditionalEnd)); > + > // Should we include the stuff contained by this directive? > if (ConditionalTrue) { > // Yes, remember that we are inside a conditional, then lex the next > token. > @@ -1949,9 +1953,6 @@ > SkipExcludedConditionalBlock(IfToken.getLocation(), > /*Foundnonskip*/false, > /*FoundElse*/false); > } > - > - if (Callbacks) > - Callbacks->If(SourceRange(ConditionalBegin, ConditionalEnd)); > } > > /// HandleEndifDirective - Implements the #endif directive. > @@ -1977,7 +1978,7 @@ > "This code should only be reachable in the non-skipping case!"); > > if (Callbacks) > - Callbacks->Endif(); > + Callbacks->Endif(EndifToken.getLocation(), CondInfo.IfLoc); > } > > /// HandleElseDirective - Implements the #else directive. > @@ -2001,12 +2002,12 @@ > // If this is a #else with a #else before it, report the error. > if (CI.FoundElse) Diag(Result, diag::pp_err_else_after_else); > > + if (Callbacks) > + Callbacks->Else(Result.getLocation(), CI.IfLoc); > + > // Finally, skip the rest of the contents of this block. > SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true, > /*FoundElse*/true, Result.getLocation()); > - > - if (Callbacks) > - Callbacks->Else(); > } > > /// HandleElifDirective - Implements the #elif directive. > @@ -2033,12 +2034,13 @@ > > // If this is a #elif with a #else before it, report the error. > if (CI.FoundElse) Diag(ElifToken, diag::pp_err_elif_after_else); > + > + if (Callbacks) > + Callbacks->Elif(ElifToken.getLocation(), > + SourceRange(ConditionalBegin, ConditionalEnd), > CI.IfLoc); > > // Finally, skip the rest of the contents of this block. > SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true, > /*FoundElse*/CI.FoundElse, > ElifToken.getLocation()); > - > - if (Callbacks) > - Callbacks->Elif(SourceRange(ConditionalBegin, ConditionalEnd)); > } > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
