<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Mar 5, 2012, at 2:06 PM, Kaelyn Uhrain wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On Sun, Mar 4, 2012 at 9:48 PM, Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:akyrtzi@gmail.com" target="_blank">akyrtzi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">

Author: akirtzidis<br>
Date: Sun Mar  4 23:48:09 2012<br>
New Revision: 152017<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=152017&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=152017&view=rev</a><br>
Log:<br>
[preprocessor] Enhance the preprocessor callbacks:<br>
<br>
-Add location parameter for the directives callbacks<br>
-Skip callbacks if the directive is inside a skipped range.<br>
-Make sure the directive callbacks are invoked in source order.<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Lex/PPCallbacks.h<br>
    cfe/trunk/lib/Lex/PPDirectives.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=152017&r1=152016&r2=152017&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=152017&r1=152016&r2=152017&view=diff</a><br>


==============================================================================<br>
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)<br>
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Sun Mar  4 23:48:09 2012<br>
@@ -192,33 +192,34 @@<br>
   /// If -- This hook is called whenever an #if is seen.<br>
   /// \param Range The SourceRange of the expression being tested.<br>
   // FIXME: better to pass in a list (or tree!) of Tokens.<br>
-  virtual void If(SourceRange Range) {<br>
+  virtual void If(SourceLocation Loc, SourceRange ConditionRange) {<br></blockquote><div><br></div><div>Don't forget to update the doxygen comments about the method parameters here and for the other callback methods you modified.</div></div></blockquote><div><br></div><div>In r152075.</div><div><br></div><div>-Argyrios</div><br><blockquote type="cite"><div class="gmail_quote">

<div><br></div><div>Thanks,</div><div>Kaelyn</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   }<br>
<br>
   /// Elif -- This hook is called whenever an #elif is seen.<br>
   /// \param Range The SourceRange of the expression being tested.<br>
   // FIXME: better to pass in a list (or tree!) of Tokens.<br>
-  virtual void Elif(SourceRange Range) {<br>
+  virtual void Elif(SourceLocation Loc, SourceRange ConditionRange,<br>
+                    SourceLocation IfLoc) {<br>
   }<br>
<br>
   /// Ifdef -- This hook is called whenever an #ifdef is seen.<br>
   /// \param Loc The location of the token being tested.<br>
   /// \param II Information on the token being tested.<br>
-  virtual void Ifdef(const Token &MacroNameTok) {<br>
+  virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok) {<br>
   }<br>
<br>
   /// Ifndef -- This hook is called whenever an #ifndef is seen.<br>
   /// \param Loc The location of the token being tested.<br>
   /// \param II Information on the token being tested.<br>
-  virtual void Ifndef(const Token &MacroNameTok) {<br>
+  virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok) {<br>
   }<br>
<br>
   /// Else -- This hook is called whenever an #else is seen.<br>
-  virtual void Else() {<br>
+  virtual void Else(SourceLocation Loc, SourceLocation IfLoc) {<br>
   }<br>
<br>
   /// Endif -- This hook is called whenever an #endif is seen.<br>
-  virtual void Endif() {<br>
+  virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) {<br>
   }<br>
 };<br>
<br>
@@ -335,39 +336,40 @@<br>
   }<br>
<br>
   /// If -- This hook is called whenever an #if is seen.<br>
-  virtual void If(SourceRange Range) {<br>
-    First->If(Range);<br>
-    Second->If(Range);<br>
+  virtual void If(SourceLocation Loc, SourceRange ConditionRange) {<br>
+    First->If(Loc, ConditionRange);<br>
+    Second->If(Loc, ConditionRange);<br>
   }<br>
<br>
   /// Elif -- This hook is called whenever an #if is seen.<br>
-  virtual void Elif(SourceRange Range) {<br>
-    First->Elif(Range);<br>
-    Second->Elif(Range);<br>
+  virtual void Elif(SourceLocation Loc, SourceRange ConditionRange,<br>
+                    SourceLocation IfLoc) {<br>
+    First->Elif(Loc, ConditionRange, IfLoc);<br>
+    Second->Elif(Loc, ConditionRange, IfLoc);<br>
   }<br>
<br>
   /// Ifdef -- This hook is called whenever an #ifdef is seen.<br>
-  virtual void Ifdef(const Token &MacroNameTok) {<br>
-    First->Ifdef(MacroNameTok);<br>
-    Second->Ifdef(MacroNameTok);<br>
+  virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok) {<br>
+    First->Ifdef(Loc, MacroNameTok);<br>
+    Second->Ifdef(Loc, MacroNameTok);<br>
   }<br>
<br>
   /// Ifndef -- This hook is called whenever an #ifndef is seen.<br>
-  virtual void Ifndef(const Token &MacroNameTok) {<br>
-    First->Ifndef(MacroNameTok);<br>
-    Second->Ifndef(MacroNameTok);<br>
+  virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok) {<br>
+    First->Ifndef(Loc, MacroNameTok);<br>
+    Second->Ifndef(Loc, MacroNameTok);<br>
   }<br>
<br>
   /// Else -- This hook is called whenever an #else is seen.<br>
-  virtual void Else() {<br>
-    First->Else();<br>
-    Second->Else();<br>
+  virtual void Else(SourceLocation Loc, SourceLocation IfLoc) {<br>
+    First->Else(Loc, IfLoc);<br>
+    Second->Else(Loc, IfLoc);<br>
   }<br>
<br>
   /// Endif -- This hook is called whenever an #endif is seen.<br>
-  virtual void Endif() {<br>
-    First->Endif();<br>
-    Second->Endif();<br>
+  virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) {<br>
+    First->Endif(Loc, IfLoc);<br>
+    Second->Endif(Loc, IfLoc);<br>
   }<br>
 };<br>
<br>
<br>
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=152017&r1=152016&r2=152017&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=152017&r1=152016&r2=152017&view=diff</a><br>


==============================================================================<br>
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)<br>
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sun Mar  4 23:48:09 2012<br>
@@ -313,9 +313,6 @@<br>
         CurPPLexer->pushConditionalLevel(Tok.getLocation(), /*wasskipping*/true,<br>
                                        /*foundnonskip*/false,<br>
                                        /*foundelse*/false);<br>
-<br>
-        if (Callbacks)<br>
-          Callbacks->Endif();<br>
       }<br>
     } else if (Directive[0] == 'e') {<br>
       StringRef Sub = Directive.substr(1);<br>
@@ -328,8 +325,11 @@<br>
         assert(!InCond && "Can't be skipping if not in a conditional!");<br>
<br>
         // If we popped the outermost skipping block, we're done skipping!<br>
-        if (!CondInfo.WasSkipping)<br>
+        if (!CondInfo.WasSkipping) {<br>
+          if (Callbacks)<br>
+            Callbacks->Endif(Tok.getLocation(), CondInfo.IfLoc);<br>
           break;<br>
+        }<br>
       } else if (Sub == "lse") { // "else".<br>
         // #else directive in a skipping conditional.  If not in some other<br>
         // skipping conditional, and if #else hasn't already been seen, enter it<br>
@@ -342,14 +342,13 @@<br>
         // Note that we've seen a #else in this conditional.<br>
         CondInfo.FoundElse = true;<br>
<br>
-        if (Callbacks)<br>
-          Callbacks->Else();<br>
-<br>
         // If the conditional is at the top level, and the #if block wasn't<br>
         // entered, enter the #else block now.<br>
         if (!CondInfo.WasSkipping && !CondInfo.FoundNonSkip) {<br>
           CondInfo.FoundNonSkip = true;<br>
           CheckEndOfDirective("else");<br>
+          if (Callbacks)<br>
+            Callbacks->Else(Tok.getLocation(), CondInfo.IfLoc);<br>
           break;<br>
         } else {<br>
           DiscardUntilEndOfDirective();  // C99 6.10p4.<br>
@@ -378,12 +377,13 @@<br>
         // If this is a #elif with a #else before it, report the error.<br>
         if (CondInfo.FoundElse) Diag(Tok, diag::pp_err_elif_after_else);<br>
<br>
-        if (Callbacks)<br>
-          Callbacks->Elif(SourceRange(ConditionalBegin, ConditionalEnd));<br>
-<br>
         // If this condition is true, enter it!<br>
         if (ShouldEnter) {<br>
           CondInfo.FoundNonSkip = true;<br>
+          if (Callbacks)<br>
+            Callbacks->Elif(Tok.getLocation(),<br>
+                            SourceRange(ConditionalBegin, ConditionalEnd),<br>
+                            CondInfo.IfLoc);<br>
           break;<br>
         }<br>
       }<br>
@@ -1897,6 +1897,13 @@<br>
   if (MI)  // Mark it used.<br>
     markMacroAsUsed(MI);<br>
<br>
+  if (Callbacks) {<br>
+    if (isIfndef)<br>
+      Callbacks->Ifndef(DirectiveTok.getLocation(), MacroNameTok);<br>
+    else<br>
+      Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok);<br>
+  }<br>
+<br>
   // Should we include the stuff contained by this directive?<br>
   if (!MI == isIfndef) {<br>
     // Yes, remember that we are inside a conditional, then lex the next token.<br>
@@ -1909,13 +1916,6 @@<br>
                                  /*Foundnonskip*/false,<br>
                                  /*FoundElse*/false);<br>
   }<br>
-<br>
-  if (Callbacks) {<br>
-    if (isIfndef)<br>
-      Callbacks->Ifndef(MacroNameTok);<br>
-    else<br>
-      Callbacks->Ifdef(MacroNameTok);<br>
-  }<br>
 }<br>
<br>
 /// HandleIfDirective - Implements the #if directive.<br>
@@ -1939,6 +1939,10 @@<br>
       CurPPLexer->MIOpt.EnterTopLevelConditional();<br>
   }<br>
<br>
+  if (Callbacks)<br>
+    Callbacks->If(IfToken.getLocation(),<br>
+                  SourceRange(ConditionalBegin, ConditionalEnd));<br>
+<br>
   // Should we include the stuff contained by this directive?<br>
   if (ConditionalTrue) {<br>
     // Yes, remember that we are inside a conditional, then lex the next token.<br>
@@ -1949,9 +1953,6 @@<br>
     SkipExcludedConditionalBlock(IfToken.getLocation(), /*Foundnonskip*/false,<br>
                                  /*FoundElse*/false);<br>
   }<br>
-<br>
-  if (Callbacks)<br>
-    Callbacks->If(SourceRange(ConditionalBegin, ConditionalEnd));<br>
 }<br>
<br>
 /// HandleEndifDirective - Implements the #endif directive.<br>
@@ -1977,7 +1978,7 @@<br>
          "This code should only be reachable in the non-skipping case!");<br>
<br>
   if (Callbacks)<br>
-    Callbacks->Endif();<br>
+    Callbacks->Endif(EndifToken.getLocation(), CondInfo.IfLoc);<br>
 }<br>
<br>
 /// HandleElseDirective - Implements the #else directive.<br>
@@ -2001,12 +2002,12 @@<br>
   // If this is a #else with a #else before it, report the error.<br>
   if (CI.FoundElse) Diag(Result, diag::pp_err_else_after_else);<br>
<br>
+  if (Callbacks)<br>
+    Callbacks->Else(Result.getLocation(), CI.IfLoc);<br>
+<br>
   // Finally, skip the rest of the contents of this block.<br>
   SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true,<br>
                                /*FoundElse*/true, Result.getLocation());<br>
-<br>
-  if (Callbacks)<br>
-    Callbacks->Else();<br>
 }<br>
<br>
 /// HandleElifDirective - Implements the #elif directive.<br>
@@ -2033,12 +2034,13 @@<br>
<br>
   // If this is a #elif with a #else before it, report the error.<br>
   if (CI.FoundElse) Diag(ElifToken, diag::pp_err_elif_after_else);<br>
+<br>
+  if (Callbacks)<br>
+    Callbacks->Elif(ElifToken.getLocation(),<br>
+                    SourceRange(ConditionalBegin, ConditionalEnd), CI.IfLoc);<br>
<br>
   // Finally, skip the rest of the contents of this block.<br>
   SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true,<br>
                                /*FoundElse*/CI.FoundElse,<br>
                                ElifToken.getLocation());<br>
-<br>
-  if (Callbacks)<br>
-    Callbacks->Elif(SourceRange(ConditionalBegin, ConditionalEnd));<br>
 }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br>
</blockquote></div><br></body></html>