r175978 - [preprocessor] Use MacroDirective in the preprocessor callbacks to make available the

Argyrios Kyrtzidis akyrtzi at gmail.com
Sat Feb 23 16:05:14 PST 2013


Author: akirtzidis
Date: Sat Feb 23 18:05:14 2013
New Revision: 175978

URL: http://llvm.org/viewvc/llvm-project?rev=175978&view=rev
Log:
[preprocessor] Use MacroDirective in the preprocessor callbacks to make available the
full information about the macro (e.g if it was imported and where).

Modified:
    cfe/trunk/include/clang/Lex/PPCallbacks.h
    cfe/trunk/include/clang/Lex/PPConditionalDirectiveRecord.h
    cfe/trunk/include/clang/Lex/PreprocessingRecord.h
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/ARCMigrate/ARCMT.cpp
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
    cfe/trunk/lib/Lex/PPConditionalDirectiveRecord.cpp
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/PPExpressions.cpp
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp
    cfe/trunk/lib/Lex/PreprocessingRecord.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/tools/libclang/Indexing.cpp
    cfe/trunk/unittests/Basic/SourceManagerTest.cpp

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Sat Feb 23 18:05:14 2013
@@ -26,7 +26,7 @@ namespace clang {
   class SourceLocation;
   class Token;
   class IdentifierInfo;
-  class MacroInfo;
+  class MacroDirective;
 
 /// \brief This interface provides a way to observe the actions of the
 /// preprocessor as it does its thing.
@@ -184,23 +184,25 @@ public:
 
   /// \brief Called by Preprocessor::HandleMacroExpandedIdentifier when a
   /// macro invocation is found.
-  virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI,
+  virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD,
                             SourceRange Range) {
   }
 
   /// \brief Hook called whenever a macro definition is seen.
-  virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) {
+  virtual void MacroDefined(const Token &MacroNameTok,
+                            const MacroDirective *MD) {
   }
 
   /// \brief Hook called whenever a macro \#undef is seen.
   ///
-  /// MI is released immediately following this callback.
-  virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
+  /// MD is released immediately following this callback.
+  virtual void MacroUndefined(const Token &MacroNameTok,
+                              const MacroDirective *MD) {
   }
   
   /// \brief Hook called whenever the 'defined' operator is seen.
-  /// \param MI The MacroInfo if the name was a macro, null otherwise.
-  virtual void Defined(const Token &MacroNameTok, const MacroInfo *MI) {
+  /// \param MD The MacroDirective if the name was a macro, null otherwise.
+  virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD) {
   }
   
   /// \brief Hook called when a source range is skipped.
@@ -229,17 +231,17 @@ public:
   /// \brief Hook called whenever an \#ifdef is seen.
   /// \param Loc the source location of the directive.
   /// \param MacroNameTok Information on the token being tested.
-  /// \param MI The MacroInfo if the name was a macro, null otherwise.
+  /// \param MD The MacroDirective if the name was a macro, null otherwise.
   virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
-                     const MacroInfo *MI) {
+                     const MacroDirective *MD) {
   }
 
   /// \brief Hook called whenever an \#ifndef is seen.
   /// \param Loc the source location of the directive.
   /// \param MacroNameTok Information on the token being tested.
-  /// \param MI The MacroInfo if the name was a macro, null otherwise.
+  /// \param MD The MacroDirective if the name was a macro, null otherwise.
   virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
-                      const MacroInfo *MI) {
+                      const MacroDirective *MD) {
   }
 
   /// \brief Hook called whenever an \#else is seen.
@@ -351,25 +353,26 @@ public:
     Second->PragmaDiagnostic(Loc, Namespace, mapping, Str);
   }
 
-  virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI,
+  virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD,
                             SourceRange Range) {
-    First->MacroExpands(MacroNameTok, MI, Range);
-    Second->MacroExpands(MacroNameTok, MI, Range);
+    First->MacroExpands(MacroNameTok, MD, Range);
+    Second->MacroExpands(MacroNameTok, MD, Range);
   }
 
-  virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) {
-    First->MacroDefined(MacroNameTok, MI);
-    Second->MacroDefined(MacroNameTok, MI);
+  virtual void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) {
+    First->MacroDefined(MacroNameTok, MD);
+    Second->MacroDefined(MacroNameTok, MD);
   }
 
-  virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
-    First->MacroUndefined(MacroNameTok, MI);
-    Second->MacroUndefined(MacroNameTok, MI);
+  virtual void MacroUndefined(const Token &MacroNameTok,
+                              const MacroDirective *MD) {
+    First->MacroUndefined(MacroNameTok, MD);
+    Second->MacroUndefined(MacroNameTok, MD);
   }
 
-  virtual void Defined(const Token &MacroNameTok, const MacroInfo *MI) {
-    First->Defined(MacroNameTok, MI);
-    Second->Defined(MacroNameTok, MI);
+  virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD) {
+    First->Defined(MacroNameTok, MD);
+    Second->Defined(MacroNameTok, MD);
   }
 
   virtual void SourceRangeSkipped(SourceRange Range) {
@@ -392,16 +395,16 @@ public:
 
   /// \brief Hook called whenever an \#ifdef is seen.
   virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
-                     const MacroInfo *MI) {
-    First->Ifdef(Loc, MacroNameTok, MI);
-    Second->Ifdef(Loc, MacroNameTok, MI);
+                     const MacroDirective *MD) {
+    First->Ifdef(Loc, MacroNameTok, MD);
+    Second->Ifdef(Loc, MacroNameTok, MD);
   }
 
   /// \brief Hook called whenever an \#ifndef is seen.
   virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
-                      const MacroInfo *MI) {
-    First->Ifndef(Loc, MacroNameTok, MI);
-    Second->Ifndef(Loc, MacroNameTok, MI);
+                      const MacroDirective *MD) {
+    First->Ifndef(Loc, MacroNameTok, MD);
+    Second->Ifndef(Loc, MacroNameTok, MD);
   }
 
   /// \brief Hook called whenever an \#else is seen.

Modified: cfe/trunk/include/clang/Lex/PPConditionalDirectiveRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPConditionalDirectiveRecord.h?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPConditionalDirectiveRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PPConditionalDirectiveRecord.h Sat Feb 23 18:05:14 2013
@@ -90,9 +90,9 @@ private:
   virtual void Elif(SourceLocation Loc, SourceRange ConditionRange,
                     SourceLocation IfLoc);
   virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
-                     const MacroInfo *MI);
+                     const MacroDirective *MD);
   virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
-                      const MacroInfo *MI);
+                      const MacroDirective *MD);
   virtual void Else(SourceLocation Loc, SourceLocation IfLoc);
   virtual void Endif(SourceLocation Loc, SourceLocation IfLoc);
 };

Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Sat Feb 23 18:05:14 2013
@@ -26,6 +26,7 @@
 
 namespace clang {
   class IdentifierInfo;
+  class MacroInfo;
   class PreprocessingRecord;
 }
 
@@ -557,10 +558,10 @@ namespace clang {
     MacroDefinition *findMacroDefinition(const MacroInfo *MI);
         
   private:
-    virtual void MacroExpands(const Token &Id, const MacroInfo* MI,
+    virtual void MacroExpands(const Token &Id, const MacroDirective *MD,
                               SourceRange Range);
-    virtual void MacroDefined(const Token &Id, const MacroInfo *MI);
-    virtual void MacroUndefined(const Token &Id, const MacroInfo *MI);
+    virtual void MacroDefined(const Token &Id, const MacroDirective *MD);
+    virtual void MacroUndefined(const Token &Id, const MacroDirective *MD);
     virtual void InclusionDirective(SourceLocation HashLoc,
                                     const Token &IncludeTok,
                                     StringRef FileName,
@@ -571,11 +572,11 @@ namespace clang {
                                     StringRef RelativePath,
                                     const Module *Imported);
     virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
-                       const MacroInfo *MI);
+                       const MacroDirective *MD);
     virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
-                        const MacroInfo *MI);
+                        const MacroDirective *MD);
     /// \brief Hook called whenever the 'defined' operator is seen.
-    virtual void Defined(const Token &MacroNameTok, const MacroInfo *MI);
+    virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD);
 
     void addMacroExpansion(const Token &Id, const MacroInfo *MI,
                            SourceRange Range);

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sat Feb 23 18:05:14 2013
@@ -303,10 +303,10 @@ class Preprocessor : public RefCountedBa
 
   struct MacroExpandsInfo {
     Token Tok;
-    MacroInfo *MI;
+    MacroDirective *MD;
     SourceRange Range;
-    MacroExpandsInfo(Token Tok, MacroInfo *MI, SourceRange Range)
-      : Tok(Tok), MI(MI), Range(Range) { }
+    MacroExpandsInfo(Token Tok, MacroDirective *MD, SourceRange Range)
+      : Tok(Tok), MD(MD), Range(Range) { }
   };
   SmallVector<MacroExpandsInfo, 2> DelayedMacroExpandsCallbacks;
 
@@ -560,10 +560,10 @@ public:
   MacroDirective *getMacroDirectiveHistory(const IdentifierInfo *II) const;
 
   /// \brief Specify a macro for this identifier.
-  void setMacroDirective(IdentifierInfo *II, MacroInfo *MI,
-                         SourceLocation Loc, bool isImported);
-  void setMacroDirective(IdentifierInfo *II, MacroInfo *MI) {
-    setMacroDirective(II, MI, MI->getDefinitionLoc(), false);
+  MacroDirective *setMacroDirective(IdentifierInfo *II, MacroInfo *MI,
+                                    SourceLocation Loc, bool isImported);
+  MacroDirective *setMacroDirective(IdentifierInfo *II, MacroInfo *MI) {
+    return setMacroDirective(II, MI, MI->getDefinitionLoc(), false);
   }
   /// \brief Add a MacroInfo that was loaded from an AST file.
   void addLoadedMacroInfo(IdentifierInfo *II, MacroDirective *MD,
@@ -1333,7 +1333,7 @@ private:
   /// HandleMacroExpandedIdentifier - If an identifier token is read that is to
   /// be expanded as a macro, handle it and return the next token as 'Tok'.  If
   /// the macro should not be expanded return true, otherwise return false.
-  bool HandleMacroExpandedIdentifier(Token &Tok, MacroInfo *MI);
+  bool HandleMacroExpandedIdentifier(Token &Tok, MacroDirective *MD);
 
   /// \brief Cache macro expanded tokens for TokenLexers.
   //

Modified: cfe/trunk/lib/ARCMigrate/ARCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ARCMT.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ARCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ARCMT.cpp Sat Feb 23 18:05:14 2013
@@ -481,7 +481,7 @@ public:
   ARCMTMacroTrackerPPCallbacks(std::vector<SourceLocation> &ARCMTMacroLocs)
     : ARCMTMacroLocs(ARCMTMacroLocs) { }
 
-  virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo *MI,
+  virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD,
                             SourceRange Range) {
     if (MacroNameTok.getIdentifierInfo()->getName() == getARCMTMacroName())
       ARCMTMacroLocs.push_back(MacroNameTok.getLocation());

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Sat Feb 23 18:05:14 2013
@@ -847,7 +847,8 @@ class MacroDefinitionTrackerPPCallbacks
 public:
   explicit MacroDefinitionTrackerPPCallbacks(unsigned &Hash) : Hash(Hash) { }
   
-  virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) {
+  virtual void MacroDefined(const Token &MacroNameTok,
+                            const MacroDirective *MD) {
     Hash = llvm::HashString(MacroNameTok.getIdentifierInfo()->getName(), Hash);
   }
 };

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Sat Feb 23 18:05:14 2013
@@ -160,10 +160,10 @@ public:
   void HandleNewlinesInToken(const char *TokStr, unsigned Len);
 
   /// MacroDefined - This hook is called whenever a macro definition is seen.
-  void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI);
+  void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD);
 
   /// MacroUndefined - This hook is called whenever a macro #undef is seen.
-  void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI);
+  void MacroUndefined(const Token &MacroNameTok, const MacroDirective *MD);
 };
 }  // end anonymous namespace
 
@@ -317,7 +317,8 @@ void PrintPPOutputPPCallbacks::Ident(Sou
 
 /// MacroDefined - This hook is called whenever a macro definition is seen.
 void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,
-                                            const MacroInfo *MI) {
+                                            const MacroDirective *MD) {
+  const MacroInfo *MI = MD->getInfo();
   // Only print out macro definitions in -dD mode.
   if (!DumpDefines ||
       // Ignore __FILE__ etc.
@@ -329,7 +330,7 @@ void PrintPPOutputPPCallbacks::MacroDefi
 }
 
 void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok,
-                                              const MacroInfo *MI) {
+                                              const MacroDirective *MD) {
   // Only print out macro definitions in -dD mode.
   if (!DumpDefines) return;
 

Modified: cfe/trunk/lib/Lex/PPConditionalDirectiveRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPConditionalDirectiveRecord.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPConditionalDirectiveRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PPConditionalDirectiveRecord.cpp Sat Feb 23 18:05:14 2013
@@ -83,14 +83,14 @@ void PPConditionalDirectiveRecord::If(So
 
 void PPConditionalDirectiveRecord::Ifdef(SourceLocation Loc,
                                          const Token &MacroNameTok,
-                                         const MacroInfo *MI) {
+                                         const MacroDirective *MD) {
   addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back()));
   CondDirectiveStack.push_back(Loc);
 }
 
 void PPConditionalDirectiveRecord::Ifndef(SourceLocation Loc,
                                           const Token &MacroNameTok,
-                                          const MacroInfo *MI) {
+                                          const MacroDirective *MD) {
   addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back()));
   CondDirectiveStack.push_back(Loc);
 }

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sat Feb 23 18:05:14 2013
@@ -1938,7 +1938,7 @@ void Preprocessor::HandleDefineDirective
       WarnUnusedMacroLocs.erase(OtherMI->getDefinitionLoc());
   }
 
-  setMacroDirective(MacroNameTok.getIdentifierInfo(), MI);
+  MacroDirective *MD = setMacroDirective(MacroNameTok.getIdentifierInfo(), MI);
 
   assert(!MI->isUsed());
   // If we need warning for not using the macro, add its location in the
@@ -1952,7 +1952,7 @@ void Preprocessor::HandleDefineDirective
 
   // If the callbacks want to know, tell them about the macro definition.
   if (Callbacks)
-    Callbacks->MacroDefined(MacroNameTok, MI);
+    Callbacks->MacroDefined(MacroNameTok, MD);
 }
 
 /// HandleUndefDirective - Implements \#undef.
@@ -1977,7 +1977,7 @@ void Preprocessor::HandleUndefDirective(
   // If the callbacks want to know, tell them about the macro #undef.
   // Note: no matter if the macro was defined or not.
   if (Callbacks)
-    Callbacks->MacroUndefined(MacroNameTok, MI);
+    Callbacks->MacroUndefined(MacroNameTok, MD);
 
   // If the macro is not defined, this is a noop undef, just return.
   if (MI == 0) return;
@@ -2035,7 +2035,8 @@ void Preprocessor::HandleIfdefDirective(
   CheckEndOfDirective(isIfndef ? "ifndef" : "ifdef");
 
   IdentifierInfo *MII = MacroNameTok.getIdentifierInfo();
-  MacroInfo *MI = getMacroInfo(MII);
+  MacroDirective *MD = getMacroDirective(MII);
+  MacroInfo *MI = MD ? MD->getInfo() : 0;
 
   if (CurPPLexer->getConditionalStackDepth() == 0) {
     // If the start of a top-level #ifdef and if the macro is not defined,
@@ -2055,9 +2056,9 @@ void Preprocessor::HandleIfdefDirective(
 
   if (Callbacks) {
     if (isIfndef)
-      Callbacks->Ifndef(DirectiveTok.getLocation(), MacroNameTok, MI);
+      Callbacks->Ifndef(DirectiveTok.getLocation(), MacroNameTok, MD);
     else
-      Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MI);
+      Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MD);
   }
 
   // Should we include the stuff contained by this directive?

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Sat Feb 23 18:05:14 2013
@@ -111,20 +111,20 @@ static bool EvaluateDefined(PPValue &Res
   Result.Val = II->hasMacroDefinition();
   Result.Val.setIsUnsigned(false);  // Result is signed intmax_t.
 
-  MacroInfo *Macro = 0;
+  MacroDirective *Macro = 0;
   // If there is a macro, mark it used.
   if (Result.Val != 0 && ValueLive) {
-    Macro = PP.getMacroInfo(II);
-    PP.markMacroAsUsed(Macro);
+    Macro = PP.getMacroDirective(II);
+    PP.markMacroAsUsed(Macro->getInfo());
   }
 
   // Invoke the 'defined' callback.
   if (PPCallbacks *Callbacks = PP.getPPCallbacks()) {
-    MacroInfo *MI = Macro;
+    MacroDirective *MD = Macro;
     // Pass the MacroInfo for the macro name even if the value is dead.
-    if (!MI && Result.Val != 0)
-      MI = PP.getMacroInfo(II);
-    Callbacks->Defined(PeekTok, MI);
+    if (!MD && Result.Val != 0)
+      MD = PP.getMacroDirective(II);
+    Callbacks->Defined(PeekTok, MD);
   }
 
   // If we are in parens, ensure we have a trailing ).

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sat Feb 23 18:05:14 2013
@@ -41,10 +41,10 @@ Preprocessor::getMacroDirectiveHistory(c
   return Pos->second;
 }
 
-/// setMacroInfo - Specify a macro for this identifier.
-///
-void Preprocessor::setMacroDirective(IdentifierInfo *II, MacroInfo *MI,
-                                     SourceLocation Loc, bool isImported) {
+/// \brief Specify a macro for this identifier.
+MacroDirective *
+Preprocessor::setMacroDirective(IdentifierInfo *II, MacroInfo *MI,
+                                SourceLocation Loc, bool isImported) {
   assert(MI && "MacroInfo should be non-zero!");
 
   MacroDirective *MD = AllocateMacroDirective(MI, Loc, isImported);
@@ -54,6 +54,8 @@ void Preprocessor::setMacroDirective(Ide
   II->setHasMacroDefinition(true);
   if (II->isFromAST())
     II->setChangedSinceDeserialization();
+
+  return MD;
 }
 
 void Preprocessor::addLoadedMacroInfo(IdentifierInfo *II, MacroDirective *MD,
@@ -304,7 +306,9 @@ bool Preprocessor::isNextPPTokenLParen()
 /// HandleMacroExpandedIdentifier - If an identifier token is read that is to be
 /// expanded as a macro, handle it and return the next token as 'Identifier'.
 bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
-                                                 MacroInfo *MI) {
+                                                 MacroDirective *MD) {
+  MacroInfo *MI = MD->getInfo();
+
   // If this is a macro expansion in the "#if !defined(x)" line for the file,
   // then the macro could expand to different things in other contexts, we need
   // to disable the optimization in this case.
@@ -312,7 +316,7 @@ bool Preprocessor::HandleMacroExpandedId
 
   // If this is a builtin macro, like __LINE__ or _Pragma, handle it specially.
   if (MI->isBuiltinMacro()) {
-    if (Callbacks) Callbacks->MacroExpands(Identifier, MI,
+    if (Callbacks) Callbacks->MacroExpands(Identifier, MD,
                                            Identifier.getLocation());
     ExpandBuiltinMacro(Identifier);
     return false;
@@ -365,13 +369,13 @@ bool Preprocessor::HandleMacroExpandedId
       // MacroExpands callbacks still happen in source order, queue this
       // callback to have it happen after the function macro callback.
       DelayedMacroExpandsCallbacks.push_back(
-                              MacroExpandsInfo(Identifier, MI, ExpansionRange));
+                              MacroExpandsInfo(Identifier, MD, ExpansionRange));
     } else {
-      Callbacks->MacroExpands(Identifier, MI, ExpansionRange);
+      Callbacks->MacroExpands(Identifier, MD, ExpansionRange);
       if (!DelayedMacroExpandsCallbacks.empty()) {
         for (unsigned i=0, e = DelayedMacroExpandsCallbacks.size(); i!=e; ++i) {
           MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i];
-          Callbacks->MacroExpands(Info.Tok, Info.MI, Info.Range);
+          Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range);
         }
         DelayedMacroExpandsCallbacks.clear();
       }

Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Sat Feb 23 18:05:14 2013
@@ -382,33 +382,34 @@ void PreprocessingRecord::addMacroExpans
 }
 
 void PreprocessingRecord::Ifdef(SourceLocation Loc, const Token &MacroNameTok,
-                                const MacroInfo *MI) {
+                                const MacroDirective *MD) {
   // This is not actually a macro expansion but record it as a macro reference.
-  if (MI)
-    addMacroExpansion(MacroNameTok, MI, MacroNameTok.getLocation());
+  if (MD)
+    addMacroExpansion(MacroNameTok, MD->getInfo(), MacroNameTok.getLocation());
 }
 
 void PreprocessingRecord::Ifndef(SourceLocation Loc, const Token &MacroNameTok,
-                                 const MacroInfo *MI) {
+                                 const MacroDirective *MD) {
   // This is not actually a macro expansion but record it as a macro reference.
-  if (MI)
-    addMacroExpansion(MacroNameTok, MI, MacroNameTok.getLocation());
+  if (MD)
+    addMacroExpansion(MacroNameTok, MD->getInfo(), MacroNameTok.getLocation());
 }
 
 void PreprocessingRecord::Defined(const Token &MacroNameTok,
-                                  const MacroInfo *MI) {
+                                  const MacroDirective *MD) {
   // This is not actually a macro expansion but record it as a macro reference.
-  if (MI)
-    addMacroExpansion(MacroNameTok, MI, MacroNameTok.getLocation());
+  if (MD)
+    addMacroExpansion(MacroNameTok, MD->getInfo(), MacroNameTok.getLocation());
 }
 
-void PreprocessingRecord::MacroExpands(const Token &Id, const MacroInfo* MI,
+void PreprocessingRecord::MacroExpands(const Token &Id,const MacroDirective *MD,
                                        SourceRange Range) {
-  addMacroExpansion(Id, MI, Range);
+  addMacroExpansion(Id, MD->getInfo(), Range);
 }
 
 void PreprocessingRecord::MacroDefined(const Token &Id,
-                                       const MacroInfo *MI) {
+                                       const MacroDirective *MD) {
+  const MacroInfo *MI = MD->getInfo();
   SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc());
   MacroDefinition *Def
       = new (*this) MacroDefinition(Id.getIdentifierInfo(), R);
@@ -417,10 +418,10 @@ void PreprocessingRecord::MacroDefined(c
 }
 
 void PreprocessingRecord::MacroUndefined(const Token &Id,
-                                         const MacroInfo *MI) {
+                                         const MacroDirective *MD) {
   // Note: MI may be null (when #undef'ining an undefined macro).
-  if (MI)
-    MacroDefinitions.erase(MI);
+  if (MD)
+    MacroDefinitions.erase(MD->getInfo());
 }
 
 void PreprocessingRecord::InclusionDirective(

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Sat Feb 23 18:05:14 2013
@@ -642,10 +642,11 @@ void Preprocessor::HandleIdentifier(Toke
   }
 
   // If this is a macro to be expanded, do it.
-  if (MacroInfo *MI = getMacroInfo(&II)) {
+  if (MacroDirective *MD = getMacroDirective(&II)) {
+    MacroInfo *MI = MD->getInfo();
     if (!DisableMacroExpansion) {
       if (!Identifier.isExpandDisabled() && MI->isEnabled()) {
-        if (!HandleMacroExpandedIdentifier(Identifier, MI))
+        if (!HandleMacroExpandedIdentifier(Identifier, MD))
           return;
       } else {
         // C99 6.10.3.4p2 says that a disabled macro may never again be

Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Sat Feb 23 18:05:14 2013
@@ -281,16 +281,17 @@ public:
   }
 
   /// MacroDefined - This hook is called whenever a macro definition is seen.
-  virtual void MacroDefined(const Token &Id, const MacroInfo *MI) {
+  virtual void MacroDefined(const Token &Id, const MacroDirective *MD) {
   }
 
   /// MacroUndefined - This hook is called whenever a macro #undef is seen.
   /// MI is released immediately following this callback.
-  virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
+  virtual void MacroUndefined(const Token &MacroNameTok,
+                              const MacroDirective *MD) {
   }
 
   /// MacroExpands - This is called by when a macro invocation is found.
-  virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI,
+  virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD,
                             SourceRange Range) {
   }
 

Modified: cfe/trunk/unittests/Basic/SourceManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/SourceManagerTest.cpp?rev=175978&r1=175977&r2=175978&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/SourceManagerTest.cpp (original)
+++ cfe/trunk/unittests/Basic/SourceManagerTest.cpp Sat Feb 23 18:05:14 2013
@@ -249,12 +249,13 @@ class MacroTracker : public PPCallbacks
 public:
   explicit MacroTracker(std::vector<MacroAction> &Macros) : Macros(Macros) { }
   
-  virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) {
-    Macros.push_back(MacroAction(MI->getDefinitionLoc(),
+  virtual void MacroDefined(const Token &MacroNameTok,
+                            const MacroDirective *MD) {
+    Macros.push_back(MacroAction(MD->getLocation(),
                                  MacroNameTok.getIdentifierInfo()->getName(),
                                  true));
   }
-  virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI,
+  virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD,
                             SourceRange Range) {
     Macros.push_back(MacroAction(MacroNameTok.getLocation(),
                                  MacroNameTok.getIdentifierInfo()->getName(),





More information about the cfe-commits mailing list