[cfe-commits] r119845 - in /cfe/trunk: include/clang/Lex/PPCallbacks.h include/clang/Lex/PreprocessingRecord.h lib/Frontend/PrintPreprocessedOutput.cpp lib/Lex/PPDirectives.cpp lib/Lex/PreprocessingRecord.cpp

Craig Silverstein csilvers2000 at yahoo.com
Fri Nov 19 13:33:15 PST 2010


Author: csilvers
Date: Fri Nov 19 15:33:15 2010
New Revision: 119845

URL: http://llvm.org/viewvc/llvm-project?rev=119845&view=rev
Log:
Several PPCallbacks take an SourceLocation + IdentifierInfo, rather
than a Token that holds the same information all in one easy-to-use
package.  There's no technical reason to prefer the former -- the
information comes from a Token originally -- and it's clumsier to use,
so I've changed the code to use tokens everywhere.

Approved by clattner

Modified:
    cfe/trunk/include/clang/Lex/PPCallbacks.h
    cfe/trunk/include/clang/Lex/PreprocessingRecord.h
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/PreprocessingRecord.cpp

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=119845&r1=119844&r2=119845&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Fri Nov 19 15:33:15 2010
@@ -113,17 +113,16 @@
   /// MacroExpands - This is called by
   /// Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is
   /// found.
-  virtual void MacroExpands(const Token &Id, const MacroInfo* MI) {
+  virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI) {
   }
 
   /// MacroDefined - This hook is called whenever a macro definition is seen.
-  virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) {
+  virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) {
   }
 
   /// MacroUndefined - This hook is called whenever a macro #undef is seen.
   /// MI is released immediately following this callback.
-  virtual void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
-                              const MacroInfo *MI) {
+  virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
   }
 
   /// If -- This hook is called whenever an #if is seen.
@@ -141,13 +140,13 @@
   /// 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(SourceLocation Loc, const IdentifierInfo* II) {
+  virtual void Ifdef(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(SourceLocation Loc, const IdentifierInfo* II) {
+  virtual void Ifndef(const Token &MacroNameTok) {
   }
 
   /// Else -- This hook is called whenever an #else is seen.
@@ -205,20 +204,19 @@
     Second->PragmaMessage(Loc, Str);
   }
 
-  virtual void MacroExpands(const Token &Id, const MacroInfo* MI) {
-    First->MacroExpands(Id, MI);
-    Second->MacroExpands(Id, MI);
+  virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI) {
+    First->MacroExpands(MacroNameTok, MI);
+    Second->MacroExpands(MacroNameTok, MI);
   }
 
-  virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) {
-    First->MacroDefined(II, MI);
-    Second->MacroDefined(II, MI);
+  virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) {
+    First->MacroDefined(MacroNameTok, MI);
+    Second->MacroDefined(MacroNameTok, MI);
   }
 
-  virtual void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
-                              const MacroInfo *MI) {
-    First->MacroUndefined(Loc, II, MI);
-    Second->MacroUndefined(Loc, II, MI);
+  virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
+    First->MacroUndefined(MacroNameTok, MI);
+    Second->MacroUndefined(MacroNameTok, MI);
   }
 
   /// If -- This hook is called whenever an #if is seen.
@@ -234,15 +232,15 @@
   }
 
   /// Ifdef -- This hook is called whenever an #ifdef is seen.
-  virtual void Ifdef(SourceLocation Loc, const IdentifierInfo* II) {
-    First->Ifdef(Loc, II);
-    Second->Ifdef(Loc, II);
+  virtual void Ifdef(const Token &MacroNameTok) {
+    First->Ifdef(MacroNameTok);
+    Second->Ifdef(MacroNameTok);
   }
 
   /// Ifndef -- This hook is called whenever an #ifndef is seen.
-  virtual void Ifndef(SourceLocation Loc, const IdentifierInfo* II) {
-    First->Ifndef(Loc, II);
-    Second->Ifndef(Loc, II);
+  virtual void Ifndef(const Token &MacroNameTok) {
+    First->Ifndef(MacroNameTok);
+    Second->Ifndef(MacroNameTok);
   }
 
   /// Else -- This hook is called whenever an #else is seen.

Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=119845&r1=119844&r2=119845&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Fri Nov 19 15:33:15 2010
@@ -325,9 +325,8 @@
     MacroDefinition *findMacroDefinition(const MacroInfo *MI);
     
     virtual void MacroExpands(const Token &Id, const MacroInfo* MI);
-    virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI);
-    virtual void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
-                                const MacroInfo *MI);
+    virtual void MacroDefined(const Token &Id, const MacroInfo *MI);
+    virtual void MacroUndefined(const Token &Id, const MacroInfo *MI);
     virtual void InclusionDirective(SourceLocation HashLoc,
                                     const Token &IncludeTok,
                                     llvm::StringRef FileName,

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=119845&r1=119844&r2=119845&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Fri Nov 19 15:33:15 2010
@@ -147,11 +147,10 @@
   void HandleNewlinesInToken(const char *TokStr, unsigned Len);
 
   /// MacroDefined - This hook is called whenever a macro definition is seen.
-  void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI);
+  void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI);
 
   /// MacroUndefined - This hook is called whenever a macro #undef is seen.
-  void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
-                      const MacroInfo *MI);
+  void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI);
 };
 }  // end anonymous namespace
 
@@ -323,7 +322,7 @@
 }
 
 /// MacroDefined - This hook is called whenever a macro definition is seen.
-void PrintPPOutputPPCallbacks::MacroDefined(const IdentifierInfo *II,
+void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,
                                             const MacroInfo *MI) {
   // Only print out macro definitions in -dD mode.
   if (!DumpDefines ||
@@ -331,18 +330,17 @@
       MI->isBuiltinMacro()) return;
 
   MoveToLine(MI->getDefinitionLoc());
-  PrintMacroDefinition(*II, *MI, PP, OS);
+  PrintMacroDefinition(*MacroNameTok.getIdentifierInfo(), *MI, PP, OS);
   EmittedMacroOnThisLine = true;
 }
 
-void PrintPPOutputPPCallbacks::MacroUndefined(SourceLocation Loc,
-                                              const IdentifierInfo *II,
+void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok,
                                               const MacroInfo *MI) {
   // Only print out macro definitions in -dD mode.
   if (!DumpDefines) return;
 
-  MoveToLine(Loc);
-  OS << "#undef " << II->getName();
+  MoveToLine(MacroNameTok.getLocation());
+  OS << "#undef " << MacroNameTok.getIdentifierInfo()->getName();
   EmittedMacroOnThisLine = true;
 }
 
@@ -616,4 +614,3 @@
   PrintPreprocessedTokens(PP, Tok, Callbacks, *OS);
   *OS << '\n';
 }
-

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=119845&r1=119844&r2=119845&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Nov 19 15:33:15 2010
@@ -1532,7 +1532,7 @@
 
   // If the callbacks want to know, tell them about the macro definition.
   if (Callbacks)
-    Callbacks->MacroDefined(MacroNameTok.getIdentifierInfo(), MI);
+    Callbacks->MacroDefined(MacroNameTok, MI);
 }
 
 /// HandleUndefDirective - Implements #undef.
@@ -1561,8 +1561,7 @@
 
   // If the callbacks want to know, tell them about the macro #undef.
   if (Callbacks)
-    Callbacks->MacroUndefined(MacroNameTok.getLocation(),
-                              MacroNameTok.getIdentifierInfo(), MI);
+    Callbacks->MacroUndefined(MacroNameTok, MI);
 
   // Free macro definition.
   ReleaseMacroInfo(MI);
@@ -1633,9 +1632,9 @@
 
   if (Callbacks) {
     if (isIfndef)
-      Callbacks->Ifndef(MacroNameTok.getLocation(), MII);
+      Callbacks->Ifndef(MacroNameTok);
     else
-      Callbacks->Ifdef(MacroNameTok.getLocation(), MII);
+      Callbacks->Ifdef(MacroNameTok);
   }
 }
 

Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=119845&r1=119844&r2=119845&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Fri Nov 19 15:33:15 2010
@@ -127,17 +127,18 @@
                                                       Def));
 }
 
-void PreprocessingRecord::MacroDefined(const IdentifierInfo *II, 
+void PreprocessingRecord::MacroDefined(const Token &Id,
                                        const MacroInfo *MI) {
   SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc());
   MacroDefinition *Def
-    = new (*this) MacroDefinition(II, MI->getDefinitionLoc(), R);
+      = new (*this) MacroDefinition(Id.getIdentifierInfo(),
+                                    MI->getDefinitionLoc(),
+                                    R);
   MacroDefinitions[MI] = Def;
   PreprocessedEntities.push_back(Def);
 }
 
-void PreprocessingRecord::MacroUndefined(SourceLocation Loc,
-                                         const IdentifierInfo *II,
+void PreprocessingRecord::MacroUndefined(const Token &Id,
                                          const MacroInfo *MI) {
   llvm::DenseMap<const MacroInfo *, MacroDefinition *>::iterator Pos
     = MacroDefinitions.find(MI);





More information about the cfe-commits mailing list