r236400 - Rename MacroDefinition -> MacroDefinitionRecord, Preprocessor::MacroDefinition -> MacroDefinition.

Richard Smith richard-llvm at metafoo.co.uk
Sun May 3 19:25:32 PDT 2015


Author: rsmith
Date: Sun May  3 21:25:31 2015
New Revision: 236400

URL: http://llvm.org/viewvc/llvm-project?rev=236400&view=rev
Log:
Rename MacroDefinition -> MacroDefinitionRecord, Preprocessor::MacroDefinition -> MacroDefinition.

clang::MacroDefinition now models the currently-defined value of a macro. The
previous MacroDefinition type, which represented a record of a macro definition
directive for a detailed preprocessing record, is now called MacroDefinitionRecord.

Modified:
    cfe/trunk/include/clang/Index/USRGeneration.h
    cfe/trunk/include/clang/Lex/MacroInfo.h
    cfe/trunk/include/clang/Lex/PreprocessingRecord.h
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/include/clang/Serialization/ASTDeserializationListener.h
    cfe/trunk/include/clang/Serialization/ASTWriter.h
    cfe/trunk/lib/Frontend/FrontendAction.cpp
    cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
    cfe/trunk/lib/Index/USRGeneration.cpp
    cfe/trunk/lib/Lex/PPExpressions.cpp
    cfe/trunk/lib/Lex/PreprocessingRecord.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/CIndexer.h
    cfe/trunk/tools/libclang/CXCursor.cpp
    cfe/trunk/tools/libclang/CXCursor.h

Modified: cfe/trunk/include/clang/Index/USRGeneration.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/USRGeneration.h?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/USRGeneration.h (original)
+++ cfe/trunk/include/clang/Index/USRGeneration.h Sun May  3 21:25:31 2015
@@ -15,7 +15,7 @@
 
 namespace clang {
 class Decl;
-class MacroDefinition;
+class MacroDefinitionRecord;
 class SourceManager;
 
 namespace index {
@@ -52,8 +52,8 @@ void generateUSRForObjCProtocol(StringRe
 /// \brief Generate a USR for a macro, including the USR prefix.
 ///
 /// \returns true on error, false on success.
-bool generateUSRForMacro(const MacroDefinition *MD, const SourceManager &SM,
-                         SmallVectorImpl<char> &Buf);
+bool generateUSRForMacro(const MacroDefinitionRecord *MD,
+                         const SourceManager &SM, SmallVectorImpl<char> &Buf);
 
 } // namespace index
 } // namespace clang

Modified: cfe/trunk/include/clang/Lex/MacroInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/MacroInfo.h (original)
+++ cfe/trunk/include/clang/Lex/MacroInfo.h Sun May  3 21:25:31 2015
@@ -18,6 +18,7 @@
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Allocator.h"
 #include <cassert>
@@ -565,9 +566,56 @@ public:
 
   /// Get the number of macros that override this one.
   unsigned getNumOverridingMacros() const { return NumOverriddenBy; }
+};
+
+/// \brief A description of the current definition of a macro.
+///
+/// The definition of a macro comprises a set of (at least one) defining
+/// entities, which are either local MacroDirectives or imported ModuleMacros.
+class MacroDefinition {
+  llvm::PointerIntPair<DefMacroDirective *, 1, bool> LatestLocalAndAmbiguous;
+  ArrayRef<ModuleMacro *> ModuleMacros;
 
+public:
+  MacroDefinition() : LatestLocalAndAmbiguous(), ModuleMacros() {}
+  MacroDefinition(DefMacroDirective *MD, ArrayRef<ModuleMacro *> MMs,
+                  bool IsAmbiguous)
+      : LatestLocalAndAmbiguous(MD, IsAmbiguous), ModuleMacros(MMs) {}
+
+  /// \brief Determine whether there is a definition of this macro.
+  explicit operator bool() const {
+    return getLocalDirective() || !ModuleMacros.empty();
+  }
+
+  /// \brief Get the MacroInfo that should be used for this definition.
+  MacroInfo *getMacroInfo() const {
+    if (!ModuleMacros.empty())
+      return ModuleMacros.back()->getMacroInfo();
+    if (auto *MD = getLocalDirective())
+      return MD->getMacroInfo();
+    return nullptr;
+  }
+
+  /// \brief \c true if the definition is ambiguous, \c false otherwise.
+  bool isAmbiguous() const { return LatestLocalAndAmbiguous.getInt(); }
+
+  /// \brief Get the latest non-imported, non-\#undef'd macro definition
+  /// for this macro.
+  DefMacroDirective *getLocalDirective() const {
+    return LatestLocalAndAmbiguous.getPointer();
+  }
+
+  /// \brief Get the active module macros for this macro.
+  ArrayRef<ModuleMacro *> getModuleMacros() const { return ModuleMacros; }
+
+  template <typename Fn> void forAllDefinitions(Fn F) const {
+    if (auto *MD = getLocalDirective())
+      F(MD->getMacroInfo());
+    for (auto *MM : getModuleMacros())
+      F(MM->getMacroInfo());
+  }
 };
 
-}  // end namespace clang
+} // end namespace clang
 
 #endif

Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Sun May  3 21:25:31 2015
@@ -36,11 +36,11 @@ void* operator new(size_t bytes, clang::
                    unsigned alignment = 8) throw();
 
 /// \brief Frees memory allocated in a Clang preprocessing record.
-void operator delete(void* ptr, clang::PreprocessingRecord& PR,
+void operator delete(void *ptr, clang::PreprocessingRecord &PR,
                      unsigned) throw();
 
 namespace clang {
-  class MacroDefinition;
+  class MacroDefinitionRecord;
   class FileEntry;
 
   /// \brief Base class that describes a preprocessed entity, which may be a
@@ -133,19 +133,20 @@ namespace clang {
              PD->getKind() <= LastPreprocessingDirective;
     }
   };
-  
+
   /// \brief Record the location of a macro definition.
-  class MacroDefinition : public PreprocessingDirective {
+  class MacroDefinitionRecord : public PreprocessingDirective {
     /// \brief The name of the macro being defined.
     const IdentifierInfo *Name;
 
   public:
-    explicit MacroDefinition(const IdentifierInfo *Name, SourceRange Range)
-      : PreprocessingDirective(MacroDefinitionKind, Range), Name(Name) { }
-    
+    explicit MacroDefinitionRecord(const IdentifierInfo *Name,
+                                   SourceRange Range)
+        : PreprocessingDirective(MacroDefinitionKind, Range), Name(Name) {}
+
     /// \brief Retrieve the name of the macro being defined.
     const IdentifierInfo *getName() const { return Name; }
-    
+
     /// \brief Retrieve the location of the macro name in the definition.
     SourceLocation getLocation() const { return getSourceRange().getBegin(); }
     
@@ -159,31 +160,31 @@ namespace clang {
   class MacroExpansion : public PreprocessedEntity {
     /// \brief The definition of this macro or the name of the macro if it is
     /// a builtin macro.
-    llvm::PointerUnion<IdentifierInfo *, MacroDefinition *> NameOrDef; 
+    llvm::PointerUnion<IdentifierInfo *, MacroDefinitionRecord *> NameOrDef;
 
   public:
     MacroExpansion(IdentifierInfo *BuiltinName, SourceRange Range)
-      : PreprocessedEntity(MacroExpansionKind, Range),
-        NameOrDef(BuiltinName) { }
+        : PreprocessedEntity(MacroExpansionKind, Range),
+          NameOrDef(BuiltinName) {}
 
-    MacroExpansion(MacroDefinition *Definition, SourceRange Range)
-      : PreprocessedEntity(MacroExpansionKind, Range),
-        NameOrDef(Definition) { }
+    MacroExpansion(MacroDefinitionRecord *Definition, SourceRange Range)
+        : PreprocessedEntity(MacroExpansionKind, Range), NameOrDef(Definition) {
+    }
 
     /// \brief True if it is a builtin macro.
     bool isBuiltinMacro() const { return NameOrDef.is<IdentifierInfo *>(); }
-    
+
     /// \brief The name of the macro being expanded.
     const IdentifierInfo *getName() const {
-      if (MacroDefinition *Def = getDefinition())
+      if (MacroDefinitionRecord *Def = getDefinition())
         return Def->getName();
-      return NameOrDef.get<IdentifierInfo*>();
+      return NameOrDef.get<IdentifierInfo *>();
     }
-    
+
     /// \brief The definition of the macro being expanded. May return null if
     /// this is a builtin macro.
-    MacroDefinition *getDefinition() const {
-      return NameOrDef.dyn_cast<MacroDefinition *>();
+    MacroDefinitionRecord *getDefinition() const {
+      return NameOrDef.dyn_cast<MacroDefinitionRecord *>();
     }
 
     // Implement isa/cast/dyncast/etc.
@@ -330,7 +331,7 @@ namespace clang {
     }
 
     /// \brief Mapping from MacroInfo structures to their definitions.
-    llvm::DenseMap<const MacroInfo *, MacroDefinition *> MacroDefinitions;
+    llvm::DenseMap<const MacroInfo *, MacroDefinitionRecord *> MacroDefinitions;
 
     /// \brief External source of preprocessed entities.
     ExternalPreprocessingRecordSource *ExternalSource;
@@ -361,12 +362,12 @@ namespace clang {
     unsigned allocateLoadedEntities(unsigned NumEntities);
 
     /// \brief Register a new macro definition.
-    void RegisterMacroDefinition(MacroInfo *Macro, MacroDefinition *Def);
-    
+    void RegisterMacroDefinition(MacroInfo *Macro, MacroDefinitionRecord *Def);
+
   public:
     /// \brief Construct a new preprocessing record.
     explicit PreprocessingRecord(SourceManager &SM);
-    
+
     /// \brief Allocate memory in the preprocessing record.
     void *Allocate(unsigned Size, unsigned Align = 8) {
       return BumpAlloc.Allocate(Size, Align);
@@ -476,10 +477,10 @@ namespace clang {
     ExternalPreprocessingRecordSource *getExternalSource() const {
       return ExternalSource;
     }
-    
+
     /// \brief Retrieve the macro definition that corresponds to the given
     /// \c MacroInfo.
-    MacroDefinition *findMacroDefinition(const MacroInfo *MI);
+    MacroDefinitionRecord *findMacroDefinition(const MacroInfo *MI);
 
     /// \brief Retrieve all ranges that got skipped while preprocessing.
     const std::vector<SourceRange> &getSkippedRanges() const {

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sun May  3 21:25:31 2015
@@ -755,52 +755,6 @@ public:
   }
   /// \}
 
-  /// \brief A description of the current definition of a macro.
-  class MacroDefinition {
-    llvm::PointerIntPair<DefMacroDirective*, 1, bool> LatestLocalAndAmbiguous;
-    ArrayRef<ModuleMacro*> ModuleMacros;
-  public:
-    MacroDefinition() : LatestLocalAndAmbiguous(), ModuleMacros() {}
-    MacroDefinition(DefMacroDirective *MD, ArrayRef<ModuleMacro *> MMs,
-                    bool IsAmbiguous)
-        : LatestLocalAndAmbiguous(MD, IsAmbiguous), ModuleMacros(MMs) {}
-
-    /// \brief Determine whether there is a definition of this macro.
-    explicit operator bool() const {
-      return getLocalDirective() || !ModuleMacros.empty();
-    }
-
-    /// \brief Get the MacroInfo that should be used for this definition.
-    MacroInfo *getMacroInfo() const {
-      if (!ModuleMacros.empty())
-        return ModuleMacros.back()->getMacroInfo();
-      if (auto *MD = getLocalDirective())
-        return MD->getMacroInfo();
-      return nullptr;
-    }
-
-    /// \brief \c true if the definition is ambiguous, \c false otherwise.
-    bool isAmbiguous() const { return LatestLocalAndAmbiguous.getInt(); }
-
-    /// \brief Get the latest non-imported, non-\#undef'd macro definition
-    /// for this macro.
-    DefMacroDirective *getLocalDirective() const {
-      return LatestLocalAndAmbiguous.getPointer();
-    }
-
-    /// \brief Get the active module macros for this macro.
-    ArrayRef<ModuleMacro *> getModuleMacros() const {
-      return ModuleMacros;
-    }
-
-    template<typename Fn> void forAllDefinitions(Fn F) const {
-      if (auto *MD = getLocalDirective())
-        F(MD->getMacroInfo());
-      for (auto *MM : getModuleMacros())
-        F(MM->getMacroInfo());
-    }
-  };
-
   bool isMacroDefined(StringRef Id) {
     return isMacroDefined(&Identifiers.get(Id));
   }

Modified: cfe/trunk/include/clang/Serialization/ASTDeserializationListener.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTDeserializationListener.h?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTDeserializationListener.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTDeserializationListener.h Sun May  3 21:25:31 2015
@@ -23,10 +23,10 @@ namespace clang {
 class Decl;
 class ASTReader;
 class QualType;
-class MacroDefinition;
+class MacroDefinitionRecord;
 class MacroInfo;
 class Module;
-  
+
 class ASTDeserializationListener {
 public:
   virtual ~ASTDeserializationListener();
@@ -46,14 +46,13 @@ public:
   /// \brief A decl was deserialized from the AST file.
   virtual void DeclRead(serialization::DeclID ID, const Decl *D) { }
   /// \brief A selector was read from the AST file.
-  virtual void SelectorRead(serialization::SelectorID iD, Selector Sel) { }
+  virtual void SelectorRead(serialization::SelectorID iD, Selector Sel) {}
   /// \brief A macro definition was read from the AST file.
-  virtual void MacroDefinitionRead(serialization::PreprocessedEntityID, 
-                                   MacroDefinition *MD) { }
+  virtual void MacroDefinitionRead(serialization::PreprocessedEntityID,
+                                   MacroDefinitionRecord *MD) {}
   /// \brief A module definition was read from the AST file.
-  virtual void ModuleRead(serialization::SubmoduleID ID, Module *Mod) { }
+  virtual void ModuleRead(serialization::SubmoduleID ID, Module *Mod) {}
 };
-
 }
 
 #endif

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Sun May  3 21:25:31 2015
@@ -49,7 +49,7 @@ class FPOptions;
 class HeaderSearch;
 class HeaderSearchOptions;
 class IdentifierResolver;
-class MacroDefinition;
+class MacroDefinitionRecord;
 class MacroDirective;
 class MacroInfo;
 class OpaqueValueExpr;
@@ -284,8 +284,8 @@ private:
 
   /// \brief Mapping from macro definitions (as they occur in the preprocessing
   /// record) to the macro IDs.
-  llvm::DenseMap<const MacroDefinition *, serialization::PreprocessedEntityID>
-      MacroDefinitions;
+  llvm::DenseMap<const MacroDefinitionRecord *,
+                 serialization::PreprocessedEntityID> MacroDefinitions;
 
   /// \brief Cache of indices of anonymous declarations within their lexical
   /// contexts.
@@ -827,7 +827,7 @@ public:
   void TypeRead(serialization::TypeIdx Idx, QualType T) override;
   void SelectorRead(serialization::SelectorID ID, Selector Sel) override;
   void MacroDefinitionRead(serialization::PreprocessedEntityID ID,
-                           MacroDefinition *MD) override;
+                           MacroDefinitionRecord *MD) override;
   void ModuleRead(serialization::SubmoduleID ID, Module *Mod) override;
 
   // ASTMutationListener implementation.

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Sun May  3 21:25:31 2015
@@ -71,7 +71,7 @@ public:
       Previous->SelectorRead(ID, Sel);
   }
   void MacroDefinitionRead(serialization::PreprocessedEntityID PPID,
-                           MacroDefinition *MD) override {
+                           MacroDefinitionRecord *MD) override {
     if (Previous)
       Previous->MacroDefinitionRead(PPID, MD);
   }

Modified: cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/MultiplexConsumer.cpp?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/MultiplexConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/MultiplexConsumer.cpp Sun May  3 21:25:31 2015
@@ -37,9 +37,10 @@ public:
   void DeclRead(serialization::DeclID ID, const Decl *D) override;
   void SelectorRead(serialization::SelectorID iD, Selector Sel) override;
   void MacroDefinitionRead(serialization::PreprocessedEntityID,
-                           MacroDefinition *MD) override;
+                           MacroDefinitionRecord *MD) override;
+
 private:
-  std::vector<ASTDeserializationListener*> Listeners;
+  std::vector<ASTDeserializationListener *> Listeners;
 };
 
 MultiplexASTDeserializationListener::MultiplexASTDeserializationListener(
@@ -78,7 +79,7 @@ void MultiplexASTDeserializationListener
 }
 
 void MultiplexASTDeserializationListener::MacroDefinitionRead(
-    serialization::PreprocessedEntityID ID, MacroDefinition *MD) {
+    serialization::PreprocessedEntityID ID, MacroDefinitionRecord *MD) {
   for (size_t i = 0, e = Listeners.size(); i != e; ++i)
     Listeners[i]->MacroDefinitionRead(ID, MD);
 }

Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Sun May  3 21:25:31 2015
@@ -847,7 +847,7 @@ bool clang::index::generateUSRForDecl(co
   return UG.ignoreResults();
 }
 
-bool clang::index::generateUSRForMacro(const MacroDefinition *MD,
+bool clang::index::generateUSRForMacro(const MacroDefinitionRecord *MD,
                                        const SourceManager &SM,
                                        SmallVectorImpl<char> &Buf) {
   // Don't generate USRs for things with invalid locations.

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Sun May  3 21:25:31 2015
@@ -108,9 +108,9 @@ static bool EvaluateDefined(PPValue &Res
 
   // Otherwise, we got an identifier, is it defined to something?
   IdentifierInfo *II = PeekTok.getIdentifierInfo();
-  Preprocessor::MacroDefinition Macro = PP.getMacroDefinition(II);
+  MacroDefinition Macro = PP.getMacroDefinition(II);
   Result.Val = !!Macro;
-  Result.Val.setIsUnsigned(false);  // Result is signed intmax_t.
+  Result.Val.setIsUnsigned(false); // Result is signed intmax_t.
 
   // If there is a macro, mark it used.
   if (Result.Val != 0 && ValueLive)

Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Sun May  3 21:25:31 2015
@@ -246,10 +246,11 @@ PreprocessingRecord::addPreprocessedEnti
   assert(Entity);
   SourceLocation BeginLoc = Entity->getSourceRange().getBegin();
 
-  if (isa<MacroDefinition>(Entity)) {
+  if (isa<MacroDefinitionRecord>(Entity)) {
     assert((PreprocessedEntities.empty() ||
-            !SourceMgr.isBeforeInTranslationUnit(BeginLoc,
-                   PreprocessedEntities.back()->getSourceRange().getBegin())) &&
+            !SourceMgr.isBeforeInTranslationUnit(
+                BeginLoc,
+                PreprocessedEntities.back()->getSourceRange().getBegin())) &&
            "a macro definition was encountered out-of-order");
     PreprocessedEntities.push_back(Entity);
     return getPPEntityID(PreprocessedEntities.size()-1, /*isLoaded=*/false);
@@ -318,7 +319,7 @@ unsigned PreprocessingRecord::allocateLo
 }
 
 void PreprocessingRecord::RegisterMacroDefinition(MacroInfo *Macro,
-                                                  MacroDefinition *Def) {
+                                                  MacroDefinitionRecord *Def) {
   MacroDefinitions[Macro] = Def;
 }
 
@@ -355,9 +356,10 @@ PreprocessingRecord::getLoadedPreprocess
   return Entity;
 }
 
-MacroDefinition *PreprocessingRecord::findMacroDefinition(const MacroInfo *MI) {
-  llvm::DenseMap<const MacroInfo *, MacroDefinition *>::iterator Pos
-    = MacroDefinitions.find(MI);
+MacroDefinitionRecord *
+PreprocessingRecord::findMacroDefinition(const MacroInfo *MI) {
+  llvm::DenseMap<const MacroInfo *, MacroDefinitionRecord *>::iterator Pos =
+      MacroDefinitions.find(MI);
   if (Pos == MacroDefinitions.end())
     return nullptr;
 
@@ -372,11 +374,10 @@ void PreprocessingRecord::addMacroExpans
     return;
 
   if (MI->isBuiltinMacro())
-    addPreprocessedEntity(
-                      new (*this) MacroExpansion(Id.getIdentifierInfo(),Range));
-  else if (MacroDefinition *Def = findMacroDefinition(MI))
-    addPreprocessedEntity(
-                       new (*this) MacroExpansion(Def, Range));
+    addPreprocessedEntity(new (*this)
+                              MacroExpansion(Id.getIdentifierInfo(), Range));
+  else if (MacroDefinitionRecord *Def = findMacroDefinition(MI))
+    addPreprocessedEntity(new (*this) MacroExpansion(Def, Range));
 }
 
 void PreprocessingRecord::Ifdef(SourceLocation Loc, const Token &MacroNameTok,
@@ -418,8 +419,8 @@ void PreprocessingRecord::MacroDefined(c
                                        const MacroDirective *MD) {
   const MacroInfo *MI = MD->getMacroInfo();
   SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc());
-  MacroDefinition *Def
-      = new (*this) MacroDefinition(Id.getIdentifierInfo(), R);
+  MacroDefinitionRecord *Def =
+      new (*this) MacroDefinitionRecord(Id.getIdentifierInfo(), R);
   addPreprocessedEntity(Def);
   MacroDefinitions[MI] = Def;
 }

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sun May  3 21:25:31 2015
@@ -1432,10 +1432,10 @@ MacroInfo *ASTReader::ReadMacroRecord(Mo
         PreprocessedEntityID
             GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]);
         PreprocessingRecord &PPRec = *PP.getPreprocessingRecord();
-        PreprocessingRecord::PPEntityID
-          PPID = PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true);
-        MacroDefinition *PPDef =
-          cast_or_null<MacroDefinition>(PPRec.getPreprocessedEntity(PPID));
+        PreprocessingRecord::PPEntityID PPID =
+            PPRec.getPPEntityID(GlobalID - 1, /*isLoaded=*/true);
+        MacroDefinitionRecord *PPDef = cast_or_null<MacroDefinitionRecord>(
+            PPRec.getPreprocessedEntity(PPID));
         if (PPDef)
           PPRec.RegisterMacroDefinition(Macro, PPDef);
       }
@@ -4621,13 +4621,14 @@ PreprocessedEntity *ASTReader::ReadPrepr
   case PPD_MACRO_EXPANSION: {
     bool isBuiltin = Record[0];
     IdentifierInfo *Name = nullptr;
-    MacroDefinition *Def = nullptr;
+    MacroDefinitionRecord *Def = nullptr;
     if (isBuiltin)
       Name = getLocalIdentifier(M, Record[1]);
     else {
-      PreprocessedEntityID
-          GlobalID = getGlobalPreprocessedEntityID(M, Record[1]);
-      Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1));
+      PreprocessedEntityID GlobalID =
+          getGlobalPreprocessedEntityID(M, Record[1]);
+      Def = cast<MacroDefinitionRecord>(
+          PPRec.getLoadedPreprocessedEntity(GlobalID - 1));
     }
 
     MacroExpansion *ME;
@@ -4643,8 +4644,7 @@ PreprocessedEntity *ASTReader::ReadPrepr
     // Decode the identifier info and then check again; if the macro is
     // still defined and associated with the identifier,
     IdentifierInfo *II = getLocalIdentifier(M, Record[0]);
-    MacroDefinition *MD
-      = new (PPRec) MacroDefinition(II, Range);
+    MacroDefinitionRecord *MD = new (PPRec) MacroDefinitionRecord(II, Range);
 
     if (DeserializationListener)
       DeserializationListener->MacroDefinitionRead(PPID, MD);

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Sun May  3 21:25:31 2015
@@ -2217,13 +2217,13 @@ void ASTWriter::WritePreprocessorDetail(
        (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) {
     Record.clear();
 
-    PreprocessedEntityOffsets.push_back(PPEntityOffset((*E)->getSourceRange(),
-                                                     Stream.GetCurrentBitNo()));
+    PreprocessedEntityOffsets.push_back(
+        PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo()));
 
-    if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) {
+    if (MacroDefinitionRecord *MD = dyn_cast<MacroDefinitionRecord>(*E)) {
       // Record this macro definition's ID.
       MacroDefinitions[MD] = NextPreprocessorEntityID;
-      
+
       AddIdentifierRef(MD->getName(), Record);
       Stream.EmitRecord(PPD_MACRO_DEFINITION, Record);
       continue;
@@ -5545,7 +5545,7 @@ void ASTWriter::SelectorRead(SelectorID
 }
 
 void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID,
-                                    MacroDefinition *MD) {
+                                    MacroDefinitionRecord *MD) {
   assert(MacroDefinitions.find(MD) == MacroDefinitions.end());
   MacroDefinitions[MD] = ID;
 }

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Sun May  3 21:25:31 2015
@@ -454,14 +454,14 @@ bool CursorVisitor::visitPreprocessedEnt
     if (MacroExpansion *ME = dyn_cast<MacroExpansion>(PPE)) {
       if (Visit(MakeMacroExpansionCursor(ME, TU)))
         return true;
-      
+
       continue;
     }
-    
-    if (MacroDefinition *MD = dyn_cast<MacroDefinition>(PPE)) {
+
+    if (MacroDefinitionRecord *MD = dyn_cast<MacroDefinitionRecord>(PPE)) {
       if (Visit(MakeMacroDefinitionCursor(MD, TU)))
         return true;
-      
+
       continue;
     }
     
@@ -568,8 +568,8 @@ bool CursorVisitor::VisitChildren(CXCurs
     SourceLocation Loc = AU->mapLocationToPreamble(BeginLoc);
     const MacroInfo *MI =
         getMacroInfo(cxcursor::getCursorMacroDefinition(Cursor), TU);
-    if (MacroDefinition *MacroDef =
-          checkForMacroInMacroDefinition(MI, Loc, TU))
+    if (MacroDefinitionRecord *MacroDef =
+            checkForMacroInMacroDefinition(MI, Loc, TU))
       return Visit(cxcursor::MakeMacroExpansionCursor(MacroDef, BeginLoc, TU));
   }
 
@@ -4887,9 +4887,10 @@ CXCursor clang_getCursorReferenced(CXCur
 
     return clang_getNullCursor();
   }
-  
+
   if (C.kind == CXCursor_MacroExpansion) {
-    if (const MacroDefinition *Def = getCursorMacroExpansion(C).getDefinition())
+    if (const MacroDefinitionRecord *Def =
+            getCursorMacroExpansion(C).getDefinition())
       return MakeMacroDefinitionCursor(Def, tu);
   }
 
@@ -6064,11 +6065,12 @@ static void annotatePreprocessorTokens(C
         if (MI) {
           SourceLocation SaveLoc = Tok.getLocation();
           Tok.setLocation(CXXUnit->mapLocationToPreamble(SaveLoc));
-          MacroDefinition *MacroDef = checkForMacroInMacroDefinition(MI,Tok,TU);
+          MacroDefinitionRecord *MacroDef =
+              checkForMacroInMacroDefinition(MI, Tok, TU);
           Tok.setLocation(SaveLoc);
           if (MacroDef)
-            Cursors[NextIdx-1] = MakeMacroExpansionCursor(MacroDef,
-                                                         Tok.getLocation(), TU);
+            Cursors[NextIdx - 1] =
+                MakeMacroExpansionCursor(MacroDef, Tok.getLocation(), TU);
         }
       } while (!Tok.isAtStartOfLine());
 
@@ -7156,7 +7158,7 @@ MacroInfo *cxindex::getMacroInfo(const I
   return nullptr;
 }
 
-const MacroInfo *cxindex::getMacroInfo(const MacroDefinition *MacroDef,
+const MacroInfo *cxindex::getMacroInfo(const MacroDefinitionRecord *MacroDef,
                                        CXTranslationUnit TU) {
   if (!MacroDef || !TU)
     return nullptr;
@@ -7167,9 +7169,9 @@ const MacroInfo *cxindex::getMacroInfo(c
   return getMacroInfo(*II, MacroDef->getLocation(), TU);
 }
 
-MacroDefinition *cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI,
-                                                         const Token &Tok,
-                                                         CXTranslationUnit TU) {
+MacroDefinitionRecord *
+cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI, const Token &Tok,
+                                        CXTranslationUnit TU) {
   if (!MI || !TU)
     return nullptr;
   if (Tok.isNot(tok::raw_identifier))
@@ -7208,9 +7210,9 @@ MacroDefinition *cxindex::checkForMacroI
   return PPRec->findMacroDefinition(InnerMD->getMacroInfo());
 }
 
-MacroDefinition *cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI,
-                                                         SourceLocation Loc,
-                                                         CXTranslationUnit TU) {
+MacroDefinitionRecord *
+cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI, SourceLocation Loc,
+                                        CXTranslationUnit TU) {
   if (Loc.isInvalid() || !MI || !TU)
     return nullptr;
 

Modified: cfe/trunk/tools/libclang/CIndexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.h?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexer.h (original)
+++ cfe/trunk/tools/libclang/CIndexer.h Sun May  3 21:25:31 2015
@@ -25,12 +25,12 @@ namespace llvm {
 }
 
 namespace clang {
-  class ASTUnit;
-  class MacroInfo;
-  class MacroDefinition;
-  class SourceLocation;
-  class Token;
-  class IdentifierInfo;
+class ASTUnit;
+class MacroInfo;
+class MacroDefinitionRecord;
+class SourceLocation;
+class Token;
+class IdentifierInfo;
 
 class CIndexer {
   bool OnlyLocalDecls;
@@ -92,27 +92,26 @@ public:
     /// \brief If \c MacroDefLoc points at a macro definition with \c II as
     /// its name, this retrieves its MacroInfo.
     MacroInfo *getMacroInfo(const IdentifierInfo &II,
-                            SourceLocation MacroDefLoc,
-                            CXTranslationUnit TU);
+                            SourceLocation MacroDefLoc, CXTranslationUnit TU);
 
-    /// \brief Retrieves the corresponding MacroInfo of a MacroDefinition.
-    const MacroInfo *getMacroInfo(const MacroDefinition *MacroDef,
+    /// \brief Retrieves the corresponding MacroInfo of a MacroDefinitionRecord.
+    const MacroInfo *getMacroInfo(const MacroDefinitionRecord *MacroDef,
                                   CXTranslationUnit TU);
 
     /// \brief If \c Loc resides inside the definition of \c MI and it points at
     /// an identifier that has ever been a macro name, this returns the latest
-    /// MacroDefinition for that name, otherwise it returns NULL.
-    MacroDefinition *checkForMacroInMacroDefinition(const MacroInfo *MI,
-                                                    SourceLocation Loc,
-                                                    CXTranslationUnit TU);
+    /// MacroDefinitionRecord for that name, otherwise it returns NULL.
+    MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
+                                                          SourceLocation Loc,
+                                                          CXTranslationUnit TU);
 
     /// \brief If \c Tok resides inside the definition of \c MI and it points at
     /// an identifier that has ever been a macro name, this returns the latest
-    /// MacroDefinition for that name, otherwise it returns NULL.
-    MacroDefinition *checkForMacroInMacroDefinition(const MacroInfo *MI,
-                                                    const Token &Tok,
-                                                    CXTranslationUnit TU);
-  }
-}
+    /// MacroDefinitionRecord for that name, otherwise it returns NULL.
+    MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
+                                                          const Token &Tok,
+                                                          CXTranslationUnit TU);
+    }
+    }
 
 #endif

Modified: cfe/trunk/tools/libclang/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)
+++ cfe/trunk/tools/libclang/CXCursor.cpp Sun May  3 21:25:31 2015
@@ -750,28 +750,28 @@ SourceRange cxcursor::getCursorPreproces
   return TU->mapRangeFromPreamble(Range);
 }
 
-CXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinition *MI,
+CXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinitionRecord *MI,
                                              CXTranslationUnit TU) {
-  CXCursor C = { CXCursor_MacroDefinition, 0, { MI, nullptr, TU } };
+  CXCursor C = {CXCursor_MacroDefinition, 0, {MI, nullptr, TU}};
   return C;
 }
 
-const MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
+const MacroDefinitionRecord *cxcursor::getCursorMacroDefinition(CXCursor C) {
   assert(C.kind == CXCursor_MacroDefinition);
-  return static_cast<const MacroDefinition *>(C.data[0]);
+  return static_cast<const MacroDefinitionRecord *>(C.data[0]);
 }
 
-CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI, 
+CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI,
                                             CXTranslationUnit TU) {
   CXCursor C = { CXCursor_MacroExpansion, 0, { MI, nullptr, TU } };
   return C;
 }
 
-CXCursor cxcursor::MakeMacroExpansionCursor(MacroDefinition *MI,
+CXCursor cxcursor::MakeMacroExpansionCursor(MacroDefinitionRecord *MI,
                                             SourceLocation Loc,
                                             CXTranslationUnit TU) {
   assert(Loc.isValid());
-  CXCursor C = { CXCursor_MacroExpansion, 0, { MI, Loc.getPtrEncoding(), TU } };
+  CXCursor C = {CXCursor_MacroExpansion, 0, {MI, Loc.getPtrEncoding(), TU}};
   return C;
 }
 
@@ -780,7 +780,8 @@ const IdentifierInfo *cxcursor::MacroExp
     return getAsMacroDefinition()->getName();
   return getAsMacroExpansion()->getName();
 }
-const MacroDefinition *cxcursor::MacroExpansionCursor::getDefinition() const {
+const MacroDefinitionRecord *
+cxcursor::MacroExpansionCursor::getDefinition() const {
   if (isPseudo())
     return getAsMacroDefinition();
   return getAsMacroExpansion()->getDefinition();
@@ -1291,18 +1292,15 @@ CXCompletionString clang_getCursorComple
                                  true);
       return String;
     }
-  }
-  else if (kind == CXCursor_MacroDefinition) {
-    const MacroDefinition *definition = getCursorMacroDefinition(cursor);
+  } else if (kind == CXCursor_MacroDefinition) {
+    const MacroDefinitionRecord *definition = getCursorMacroDefinition(cursor);
     const IdentifierInfo *MacroInfo = definition->getName();
     ASTUnit *unit = getCursorASTUnit(cursor);
     CodeCompletionResult Result(MacroInfo);
-    CodeCompletionString *String
-      = Result.CreateCodeCompletionString(unit->getASTContext(),
-                                          unit->getPreprocessor(),
-                                 unit->getCodeCompletionTUInfo().getAllocator(),
-                                 unit->getCodeCompletionTUInfo(),
-                                 false);
+    CodeCompletionString *String = Result.CreateCodeCompletionString(
+        unit->getASTContext(), unit->getPreprocessor(),
+        unit->getCodeCompletionTUInfo().getAllocator(),
+        unit->getCodeCompletionTUInfo(), false);
     return String;
   }
   return nullptr;

Modified: cfe/trunk/tools/libclang/CXCursor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.h?rev=236400&r1=236399&r2=236400&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.h (original)
+++ cfe/trunk/tools/libclang/CXCursor.h Sun May  3 21:25:31 2015
@@ -30,7 +30,7 @@ class Expr;
 class FieldDecl;
 class InclusionDirective;
 class LabelStmt;
-class MacroDefinition;
+class MacroDefinitionRecord;
 class MacroExpansion;
 class NamedDecl;
 class ObjCInterfaceDecl;
@@ -145,20 +145,19 @@ CXCursor MakePreprocessingDirectiveCurso
 SourceRange getCursorPreprocessingDirective(CXCursor C);
 
 /// \brief Create a macro definition cursor.
-CXCursor MakeMacroDefinitionCursor(const MacroDefinition *,
+CXCursor MakeMacroDefinitionCursor(const MacroDefinitionRecord *,
                                    CXTranslationUnit TU);
 
 /// \brief Unpack a given macro definition cursor to retrieve its
 /// source range.
-const MacroDefinition *getCursorMacroDefinition(CXCursor C);
+const MacroDefinitionRecord *getCursorMacroDefinition(CXCursor C);
 
 /// \brief Create a macro expansion cursor.
-CXCursor MakeMacroExpansionCursor(MacroExpansion *,
-                                  CXTranslationUnit TU);
+CXCursor MakeMacroExpansionCursor(MacroExpansion *, CXTranslationUnit TU);
 
 /// \brief Create a "pseudo" macro expansion cursor, using a macro definition
 /// and a source location.
-CXCursor MakeMacroExpansionCursor(MacroDefinition *, SourceLocation Loc,
+CXCursor MakeMacroExpansionCursor(MacroDefinitionRecord *, SourceLocation Loc,
                                   CXTranslationUnit TU);
 
 /// \brief Wraps a macro expansion cursor and provides a common interface
@@ -171,12 +170,10 @@ CXCursor MakeMacroExpansionCursor(MacroD
 class MacroExpansionCursor {
   CXCursor C;
 
-  bool isPseudo() const {
-    return C.data[1] != nullptr;
-  }
-  const MacroDefinition *getAsMacroDefinition() const {
+  bool isPseudo() const { return C.data[1] != nullptr; }
+  const MacroDefinitionRecord *getAsMacroDefinition() const {
     assert(isPseudo());
-    return static_cast<const MacroDefinition *>(C.data[0]);
+    return static_cast<const MacroDefinitionRecord *>(C.data[0]);
   }
   const MacroExpansion *getAsMacroExpansion() const {
     assert(!isPseudo());
@@ -193,7 +190,7 @@ public:
   }
 
   const IdentifierInfo *getName() const;
-  const MacroDefinition *getDefinition() const;
+  const MacroDefinitionRecord *getDefinition() const;
   SourceRange getSourceRange() const;
 };
 





More information about the cfe-commits mailing list