From 0a6028ee4116b33c2d9c34e0e409af6c2a3cffe8 Mon Sep 17 00:00:00 2001 From: Richard Smith <richard-llvm@metafoo.co.uk> Date: Mon, 4 May 2015 02:25:31 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236400 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Index/USRGeneration.h | 6 +-- include/clang/Lex/MacroInfo.h | 50 ++++++++++++++++- include/clang/Lex/PreprocessingRecord.h | 53 ++++++++++--------- include/clang/Lex/Preprocessor.h | 46 ---------------- .../ASTDeserializationListener.h | 13 +++-- include/clang/Serialization/ASTWriter.h | 8 +-- lib/Frontend/FrontendAction.cpp | 2 +- lib/Frontend/MultiplexConsumer.cpp | 7 +-- lib/Index/USRGeneration.cpp | 2 +- lib/Lex/PPExpressions.cpp | 4 +- lib/Lex/PreprocessingRecord.cpp | 29 +++++----- lib/Serialization/ASTReader.cpp | 20 +++---- lib/Serialization/ASTWriter.cpp | 10 ++-- tools/libclang/CIndex.cpp | 38 ++++++------- tools/libclang/CIndexer.h | 39 +++++++------- tools/libclang/CXCursor.cpp | 32 ++++++----- tools/libclang/CXCursor.h | 21 ++++---- 17 files changed, 190 insertions(+), 190 deletions(-) diff --git a/include/clang/Index/USRGeneration.h b/include/clang/Index/USRGeneration.h index 3195dee7506..55e35cc6d9b 100644 --- a/include/clang/Index/USRGeneration.h +++ b/include/clang/Index/USRGeneration.h @@ -15,7 +15,7 @@ namespace clang { class Decl; -class MacroDefinition; +class MacroDefinitionRecord; class SourceManager; namespace index { @@ -52,8 +52,8 @@ void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS); /// \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 diff --git a/include/clang/Lex/MacroInfo.h b/include/clang/Lex/MacroInfo.h index 7de995589b9..fdd422f160c 100644 --- a/include/clang/Lex/MacroInfo.h +++ b/include/clang/Lex/MacroInfo.h @@ -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 diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index e379dbdbcea..5cf74f64380 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -36,11 +36,11 @@ void* operator new(size_t bytes, clang::PreprocessingRecord& PR, 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 { diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index e3cbd79c3d7..07e1beb677d 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -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)); } diff --git a/include/clang/Serialization/ASTDeserializationListener.h b/include/clang/Serialization/ASTDeserializationListener.h index c24ccdcd4f5..4b10c39d8fb 100644 --- a/include/clang/Serialization/ASTDeserializationListener.h +++ b/include/clang/Serialization/ASTDeserializationListener.h @@ -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 diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index bb2e55469a4..649dbd8b857 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -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. diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index 83906241317..d42ca718c39 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -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); } diff --git a/lib/Frontend/MultiplexConsumer.cpp b/lib/Frontend/MultiplexConsumer.cpp index 007ddc21f57..1512b5e6ba9 100644 --- a/lib/Frontend/MultiplexConsumer.cpp +++ b/lib/Frontend/MultiplexConsumer.cpp @@ -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::SelectorRead( } 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); } diff --git a/lib/Index/USRGeneration.cpp b/lib/Index/USRGeneration.cpp index baa166ee280..8cdd283ba5c 100644 --- a/lib/Index/USRGeneration.cpp +++ b/lib/Index/USRGeneration.cpp @@ -847,7 +847,7 @@ bool clang::index::generateUSRForDecl(const Decl *D, 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. diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp index d05ec672c8b..411a5012241 100644 --- a/lib/Lex/PPExpressions.cpp +++ b/lib/Lex/PPExpressions.cpp @@ -108,9 +108,9 @@ static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT, // 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) diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp index dafcbbe58c9..fd4bed17797 100644 --- a/lib/Lex/PreprocessingRecord.cpp +++ b/lib/Lex/PreprocessingRecord.cpp @@ -246,10 +246,11 @@ PreprocessingRecord::addPreprocessedEntity(PreprocessedEntity *Entity) { 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::allocateLoadedEntities(unsigned NumEntities) { } void PreprocessingRecord::RegisterMacroDefinition(MacroInfo *Macro, - MacroDefinition *Def) { + MacroDefinitionRecord *Def) { MacroDefinitions[Macro] = Def; } @@ -355,9 +356,10 @@ PreprocessingRecord::getLoadedPreprocessedEntity(unsigned Index) { 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::addMacroExpansion(const Token &Id, 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(const Token &Id, 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; } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index e6f35e16c4b..0dd9d2e460e 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1432,10 +1432,10 @@ MacroInfo *ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { 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::ReadPreprocessedEntity(unsigned Index) { 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::ReadPreprocessedEntity(unsigned Index) { // 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); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 377820db131..0e6e5588390 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -2217,13 +2217,13 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { (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 ID, Selector S) { } void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, - MacroDefinition *MD) { + MacroDefinitionRecord *MD) { assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); MacroDefinitions[MD] = ID; } diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index aa5b8b0318c..04344254942 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -454,14 +454,14 @@ bool CursorVisitor::visitPreprocessedEntities(InputIterator First, 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(CXCursor Cursor) { 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(CXCursor C) { 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(CXTranslationUnit TU, 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 IdentifierInfo &II, 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(const MacroDefinition *MacroDef, 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::checkForMacroInMacroDefinition(const MacroInfo *MI, 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; diff --git a/tools/libclang/CIndexer.h b/tools/libclang/CIndexer.h index 7a8dbd37d02..cb7c62e4b56 100644 --- a/tools/libclang/CIndexer.h +++ b/tools/libclang/CIndexer.h @@ -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 diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index 7834181d478..b0446fd0da9 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -750,28 +750,28 @@ SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) { 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::MacroExpansionCursor::getName() const { 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_getCursorCompletionString(CXCursor cursor) { 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; diff --git a/tools/libclang/CXCursor.h b/tools/libclang/CXCursor.h index 931d112766e..083b86934d1 100644 --- a/tools/libclang/CXCursor.h +++ b/tools/libclang/CXCursor.h @@ -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 MakePreprocessingDirectiveCursor(SourceRange Range, 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(MacroDefinition *, SourceLocation Loc, 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; }; -- GitLab