From 9e5bb85ac899eeab7c21b5ff9030c3da6ff4837b Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Thu, 14 Jul 2011 08:20:46 +0000 Subject: [PATCH] Move the rest of the preprocessor terminology from 'instantiate' and variants to 'expand'. This changed a couple of public APIs, including one public type "MacroInstantiation" which is now "MacroExpansion". The rest of the codebase was updated to reflect this, especially the libclang code. Two of the C++ (and thus easily changed) libclang APIs were updated as well because they pertained directly to the old MacroInstantiation class. No functionality changed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135139 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/PreprocessingRecord.h | 34 ++++++++++++------------- include/clang/Lex/Preprocessor.h | 26 +++++++++---------- lib/Lex/PPMacroExpansion.cpp | 26 +++++++++---------- lib/Lex/PreprocessingRecord.cpp | 11 ++++---- lib/Lex/Preprocessor.cpp | 12 ++++----- lib/Parse/ParseStmt.cpp | 2 +- lib/Serialization/ASTReader.cpp | 10 ++++---- lib/Serialization/ASTWriter.cpp | 10 ++++---- tools/libclang/CIndex.cpp | 12 ++++----- tools/libclang/CXCursor.cpp | 8 +++--- tools/libclang/CXCursor.h | 12 ++++----- 11 files changed, 81 insertions(+), 82 deletions(-) diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index e498e9d0a0..b38303a2f4 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -38,13 +38,13 @@ namespace clang { class FileEntry; /// \brief Base class that describes a preprocessed entity, which may be a - /// preprocessor directive or macro instantiation. + /// preprocessor directive or macro expansion. class PreprocessedEntity { public: /// \brief The kind of preprocessed entity an object describes. enum EntityKind { - /// \brief A macro instantiation. - MacroInstantiationKind, + /// \brief A macro expansion. + MacroExpansionKind, /// \brief A preprocessing directive whose kind is not specified. /// @@ -110,31 +110,31 @@ namespace clang { void operator delete(void* data) throw(); }; - /// \brief Records the location of a macro instantiation. - class MacroInstantiation : public PreprocessedEntity { - /// \brief The name of the macro being instantiation. + /// \brief Records the location of a macro expansion. + class MacroExpansion : public PreprocessedEntity { + /// \brief The name of the macro being expanded. IdentifierInfo *Name; /// \brief The definition of this macro. MacroDefinition *Definition; public: - MacroInstantiation(IdentifierInfo *Name, SourceRange Range, - MacroDefinition *Definition) - : PreprocessedEntity(MacroInstantiationKind, Range), Name(Name), + MacroExpansion(IdentifierInfo *Name, SourceRange Range, + MacroDefinition *Definition) + : PreprocessedEntity(MacroExpansionKind, Range), Name(Name), Definition(Definition) { } - /// \brief The name of the macro being instantiated. + /// \brief The name of the macro being expanded. IdentifierInfo *getName() const { return Name; } - /// \brief The definition of the macro being instantiated. + /// \brief The definition of the macro being expanded. MacroDefinition *getDefinition() const { return Definition; } // Implement isa/cast/dyncast/etc. static bool classof(const PreprocessedEntity *PE) { - return PE->getKind() == MacroInstantiationKind; + return PE->getKind() == MacroExpansionKind; } - static bool classof(const MacroInstantiation *) { return true; } + static bool classof(const MacroExpansion *) { return true; } }; @@ -256,11 +256,11 @@ namespace clang { /// \brief A record of the steps taken while preprocessing a source file, /// including the various preprocessing directives processed, macros - /// instantiated, etc. + /// expanded, etc. class PreprocessingRecord : public PPCallbacks { - /// \brief Whether we should include nested macro instantiations in + /// \brief Whether we should include nested macro expansions in /// the preprocessing record. - bool IncludeNestedMacroInstantiations; + bool IncludeNestedMacroExpansions; /// \brief Allocator used to store preprocessing objects. llvm::BumpPtrAllocator BumpAlloc; @@ -286,7 +286,7 @@ namespace clang { public: /// \brief Construct - explicit PreprocessingRecord(bool IncludeNestedMacroInstantiations); + explicit PreprocessingRecord(bool IncludeNestedMacroExpansions); /// \brief Allocate memory in the preprocessing record. void *Allocate(unsigned Size, unsigned Align = 8) { diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index a2d495a9a7..f6f3205099 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -121,7 +121,7 @@ class Preprocessor : public llvm::RefCountedBase { /// Selectors - This table contains all the selectors in the program. Unlike /// IdentifierTable above, this table *isn't* populated by the preprocessor. - /// It is declared/instantiated here because it's role/lifetime is + /// It is declared/expanded here because it's role/lifetime is /// conceptually similar the IdentifierTable. In addition, the current control /// flow (in clang::ParseAST()), make it convenient to put here. /// FIXME: Make sure the lifetime of Identifiers/Selectors *isn't* tied to @@ -220,9 +220,9 @@ class Preprocessor : public llvm::RefCountedBase { /// previous macro value. llvm::DenseMap > PragmaPushMacroInfo; - /// \brief Instantiation source location for the last macro that expanded + /// \brief Expansion source location for the last macro that expanded /// to no tokens. - SourceLocation LastEmptyMacroInstantiationLoc; + SourceLocation LastEmptyMacroExpansionLoc; // Various statistics we track for performance analysis. unsigned NumDirectives, NumIncluded, NumDefined, NumUndefined, NumPragma; @@ -249,7 +249,7 @@ class Preprocessor : public llvm::RefCountedBase { llvm::SmallVector MacroExpandedTokens; std::vector > MacroExpandingLexersStack; - /// \brief A record of the macro definitions and instantiations that + /// \brief A record of the macro definitions and expansions that /// occurred during preprocessing. /// /// This is an optional side structure that can be enabled with @@ -380,10 +380,10 @@ public: macro_iterator macro_begin(bool IncludeExternalMacros = true) const; macro_iterator macro_end(bool IncludeExternalMacros = true) const; - /// \brief Instantiation source location for the last macro that expanded + /// \brief Expansion source location for the last macro that expanded /// to no tokens. - SourceLocation getLastEmptyMacroInstantiationLoc() const { - return LastEmptyMacroInstantiationLoc; + SourceLocation getLastEmptyMacroExpansionLoc() const { + return LastEmptyMacroExpansionLoc; } const std::string &getPredefines() const { return Predefines; } @@ -451,7 +451,7 @@ public: /// \brief Create a new preprocessing record, which will keep track of /// all macro expansions, macro definitions, etc. - void createPreprocessingRecord(bool IncludeNestedMacroInstantiations); + void createPreprocessingRecord(bool IncludeNestedMacroExpansions); /// EnterMainSourceFile - Enter the specified FileID as the main source file, /// which implicitly adds the builtin defines etc. @@ -667,7 +667,7 @@ public: /// getSpelling() - Return the 'spelling' of the token at the given /// location; does not go up to the spelling location or down to the - /// instantiation location. + /// expansion location. /// /// \param buffer A buffer which will be used only if the token requires /// "cleaning", e.g. if it contains trigraphs or escaped newlines @@ -730,7 +730,7 @@ public: /// CreateString - Plop the specified string into a scratch buffer and set the /// specified token's location and length to it. If specified, the source - /// location provides a location of the instantiation point of the token. + /// location provides a location of the expansion point of the token. void CreateString(const char *Buf, unsigned Len, Token &Tok, SourceLocation SourceLoc = SourceLocation()); @@ -754,13 +754,13 @@ public: } /// \brief Returns true if the given MacroID location points at the first - /// token of the macro instantiation. + /// token of the macro expansion. bool isAtStartOfMacroExpansion(SourceLocation loc) const { return Lexer::isAtStartOfMacroExpansion(loc, SourceMgr, Features); } /// \brief Returns true if the given MacroID location points at the last - /// token of the macro instantiation. + /// token of the macro expansion. bool isAtEndOfMacroExpansion(SourceLocation loc) const { return Lexer::isAtEndOfMacroExpansion(loc, SourceMgr, Features); } @@ -1019,7 +1019,7 @@ private: /// invoked to read all of the formal arguments specified for the macro /// invocation. This returns null on error. MacroArgs *ReadFunctionLikeMacroArgs(Token &MacroName, MacroInfo *MI, - SourceLocation &InstantiationEnd); + SourceLocation &ExpansionEnd); /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded /// as a builtin macro, handle it and return the next token as 'Tok'. diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index f1d03713a9..ecd4d4cfc6 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -195,9 +195,9 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, /// invocation. MacroArgs *Args = 0; - // Remember where the end of the instantiation occurred. For an object-like + // Remember where the end of the expansion occurred. For an object-like // macro, this is the identifier. For a function-like macro, this is the ')'. - SourceLocation InstantiationEnd = Identifier.getLocation(); + SourceLocation ExpansionEnd = Identifier.getLocation(); // If this is a function-like macro, read the arguments. if (MI->isFunctionLike()) { @@ -210,7 +210,7 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, // Preprocessor directives used inside macro arguments are not portable, and // this enables the warning. InMacroArgs = true; - Args = ReadFunctionLikeMacroArgs(Identifier, MI, InstantiationEnd); + Args = ReadFunctionLikeMacroArgs(Identifier, MI, ExpansionEnd); // Finished parsing args. InMacroArgs = false; @@ -230,8 +230,8 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, // If we started lexing a macro, enter the macro expansion body. - // Remember where the token is instantiated. - SourceLocation InstantiateLoc = Identifier.getLocation(); + // Remember where the token is expanded. + SourceLocation ExpandLoc = Identifier.getLocation(); // If this macro expands to no tokens, don't bother to push it onto the // expansion stack, only to take it right back off. @@ -255,7 +255,7 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, if (HadLeadingSpace) Identifier.setFlag(Token::LeadingSpace); } Identifier.setFlag(Token::LeadingEmptyMacro); - LastEmptyMacroInstantiationLoc = InstantiateLoc; + LastEmptyMacroExpansionLoc = ExpandLoc; ++NumFastMacroExpanded; return false; @@ -281,11 +281,11 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, Identifier.setFlagValue(Token::StartOfLine , isAtStartOfLine); Identifier.setFlagValue(Token::LeadingSpace, hasLeadingSpace); - // Update the tokens location to include both its instantiation and physical + // Update the tokens location to include both its expansion and physical // locations. SourceLocation Loc = - SourceMgr.createInstantiationLoc(Identifier.getLocation(), InstantiateLoc, - InstantiationEnd,Identifier.getLength()); + SourceMgr.createInstantiationLoc(Identifier.getLocation(), ExpandLoc, + ExpansionEnd,Identifier.getLength()); Identifier.setLocation(Loc); // If this is a disabled macro or #define X X, we must mark the result as @@ -303,7 +303,7 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, } // Start expanding the macro. - EnterMacro(Identifier, InstantiationEnd, Args); + EnterMacro(Identifier, ExpansionEnd, Args); // Now that the macro is at the top of the include stack, ask the // preprocessor to read the next token from it. @@ -833,10 +833,10 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { Loc = AdvanceToTokenCharacter(Loc, 0); // One wrinkle here is that GCC expands __LINE__ to location of the *end* of - // a macro instantiation. This doesn't matter for object-like macros, but + // a macro expansion. This doesn't matter for object-like macros, but // can matter for a function-like macro that expands to contain __LINE__. - // Skip down through instantiation points until we find a file loc for the - // end of the instantiation history. + // Skip down through expansion points until we find a file loc for the + // end of the expansion history. Loc = SourceMgr.getInstantiationRange(Loc).second; PresumedLoc PLoc = SourceMgr.getPresumedLoc(Loc); diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp index 0c8d948ce0..9f93ab0450 100644 --- a/lib/Lex/PreprocessingRecord.cpp +++ b/lib/Lex/PreprocessingRecord.cpp @@ -45,8 +45,8 @@ void PreprocessingRecord::MaybeLoadPreallocatedEntities() const { ExternalSource->ReadPreprocessedEntities(); } -PreprocessingRecord::PreprocessingRecord(bool IncludeNestedMacroInstantiations) - : IncludeNestedMacroInstantiations(IncludeNestedMacroInstantiations), +PreprocessingRecord::PreprocessingRecord(bool IncludeNestedMacroExpansions) + : IncludeNestedMacroExpansions(IncludeNestedMacroExpansions), ExternalSource(0), NumPreallocatedEntities(0), LoadedPreallocatedEntities(false) { @@ -121,14 +121,13 @@ MacroDefinition *PreprocessingRecord::findMacroDefinition(const MacroInfo *MI) { } void PreprocessingRecord::MacroExpands(const Token &Id, const MacroInfo* MI) { - if (!IncludeNestedMacroInstantiations && Id.getLocation().isMacroID()) + if (!IncludeNestedMacroExpansions && Id.getLocation().isMacroID()) return; if (MacroDefinition *Def = findMacroDefinition(MI)) PreprocessedEntities.push_back( - new (*this) MacroInstantiation(Id.getIdentifierInfo(), - Id.getLocation(), - Def)); + new (*this) MacroExpansion(Id.getIdentifierInfo(), + Id.getLocation(), Def)); } void PreprocessingRecord::MacroDefined(const Token &Id, diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 2f43c8e30b..e7aa286a16 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -328,15 +328,15 @@ llvm::StringRef Preprocessor::getSpelling(const Token &Tok, /// location for it. If specified, the source location provides a source /// location for the token. void Preprocessor::CreateString(const char *Buf, unsigned Len, Token &Tok, - SourceLocation InstantiationLoc) { + SourceLocation ExpansionLoc) { Tok.setLength(Len); const char *DestPtr; SourceLocation Loc = ScratchBuf->getToken(Buf, Len, DestPtr); - if (InstantiationLoc.isValid()) - Loc = SourceMgr.createInstantiationLoc(Loc, InstantiationLoc, - InstantiationLoc, Len); + if (ExpansionLoc.isValid()) + Loc = SourceMgr.createInstantiationLoc(Loc, ExpansionLoc, + ExpansionLoc, Len); Tok.setLocation(Loc); // If this is a raw identifier or a literal token, set the pointer data. @@ -534,10 +534,10 @@ CommentHandler::~CommentHandler() { } CodeCompletionHandler::~CodeCompletionHandler() { } void Preprocessor::createPreprocessingRecord( - bool IncludeNestedMacroInstantiations) { + bool IncludeNestedMacroExpansions) { if (Record) return; - Record = new PreprocessingRecord(IncludeNestedMacroInstantiations); + Record = new PreprocessingRecord(IncludeNestedMacroExpansions); addPPCallbacks(Record); } diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 47a9ecc604..b91bca55a9 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -226,7 +226,7 @@ Retry: case tok::semi: { // C99 6.8.3p3: expression[opt] ';' SourceLocation LeadingEmptyMacroLoc; if (Tok.hasLeadingEmptyMacro()) - LeadingEmptyMacroLoc = PP.getLastEmptyMacroInstantiationLoc(); + LeadingEmptyMacroLoc = PP.getLastEmptyMacroExpansionLoc(); return Actions.ActOnNullStmt(ConsumeToken(), LeadingEmptyMacroLoc); } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index e8a5c41804..e37083ab03 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1560,13 +1560,13 @@ PreprocessedEntity *ASTReader::LoadPreprocessedEntity(PerFileData &F) { if (PreprocessedEntity *PE = PPRec.getPreprocessedEntity(Record[0])) return PE; - MacroInstantiation *MI - = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), + MacroExpansion *ME = + new (PPRec) MacroExpansion(DecodeIdentifierInfo(Record[3]), SourceRange(ReadSourceLocation(F, Record[1]), ReadSourceLocation(F, Record[2])), - getMacroDefinition(Record[4])); - PPRec.SetPreallocatedEntity(Record[0], MI); - return MI; + getMacroDefinition(Record[4])); + PPRec.SetPreallocatedEntity(Record[0], ME); + return ME; } case PPD_MACRO_DEFINITION: { diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index fb1795e6a4..2df14937e3 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1800,12 +1800,12 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { SerializationListener->SerializedPreprocessedEntity(*E, Stream.GetCurrentBitNo()); - if (MacroInstantiation *MI = dyn_cast(*E)) { + if (MacroExpansion *ME = dyn_cast(*E)) { Record.push_back(IndexBase + NumPreprocessingRecords++); - AddSourceLocation(MI->getSourceRange().getBegin(), Record); - AddSourceLocation(MI->getSourceRange().getEnd(), Record); - AddIdentifierRef(MI->getName(), Record); - Record.push_back(getMacroDefinitionID(MI->getDefinition())); + AddSourceLocation(ME->getSourceRange().getBegin(), Record); + AddSourceLocation(ME->getSourceRange().getEnd(), Record); + AddIdentifierRef(ME->getName(), Record); + Record.push_back(getMacroDefinitionID(ME->getDefinition())); Stream.EmitRecord(PPD_MACRO_INSTANTIATION, Record); continue; } diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index b75850dd25..e85b94f4f7 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -544,8 +544,8 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) { // do so. PreprocessingRecord::iterator E, EEnd; for (llvm::tie(E, EEnd) = getPreprocessedEntities(); E != EEnd; ++E) { - if (MacroInstantiation *MI = dyn_cast(*E)) { - if (Visit(MakeMacroInstantiationCursor(MI, tu))) + if (MacroExpansion *ME = dyn_cast(*E)) { + if (Visit(MakeMacroExpansionCursor(ME, tu))) return true; continue; @@ -3152,7 +3152,7 @@ CXString clang_getCursorSpelling(CXCursor C) { } if (C.kind == CXCursor_MacroInstantiation) - return createCXString(getCursorMacroInstantiation(C)->getName() + return createCXString(getCursorMacroExpansion(C)->getName() ->getNameStart()); if (C.kind == CXCursor_MacroDefinition) @@ -3674,7 +3674,7 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) { if (C.kind == CXCursor_MacroInstantiation) { SourceLocation L - = cxcursor::getCursorMacroInstantiation(C)->getSourceRange().getBegin(); + = cxcursor::getCursorMacroExpansion(C)->getSourceRange().getBegin(); return cxloc::translateSourceLocation(getCursorContext(C), L); } @@ -3760,7 +3760,7 @@ static SourceRange getRawCursorExtent(CXCursor C) { return cxcursor::getCursorPreprocessingDirective(C); if (C.kind == CXCursor_MacroInstantiation) - return cxcursor::getCursorMacroInstantiation(C)->getSourceRange(); + return cxcursor::getCursorMacroExpansion(C)->getSourceRange(); if (C.kind == CXCursor_MacroDefinition) return cxcursor::getCursorMacroDefinition(C)->getSourceRange(); @@ -3877,7 +3877,7 @@ CXCursor clang_getCursorReferenced(CXCursor C) { } if (C.kind == CXCursor_MacroInstantiation) { - if (MacroDefinition *Def = getCursorMacroInstantiation(C)->getDefinition()) + if (MacroDefinition *Def = getCursorMacroExpansion(C)->getDefinition()) return MakeMacroDefinitionCursor(Def, tu); } diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index b9842b6df0..b48ad91098 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -378,15 +378,15 @@ MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) { return static_cast(C.data[0]); } -CXCursor cxcursor::MakeMacroInstantiationCursor(MacroInstantiation *MI, - CXTranslationUnit TU) { +CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI, + CXTranslationUnit TU) { CXCursor C = { CXCursor_MacroInstantiation, { MI, 0, TU } }; return C; } -MacroInstantiation *cxcursor::getCursorMacroInstantiation(CXCursor C) { +MacroExpansion *cxcursor::getCursorMacroExpansion(CXCursor C) { assert(C.kind == CXCursor_MacroInstantiation); - return static_cast(C.data[0]); + return static_cast(C.data[0]); } CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID, diff --git a/tools/libclang/CXCursor.h b/tools/libclang/CXCursor.h index 545ea8751b..68d09e76c1 100644 --- a/tools/libclang/CXCursor.h +++ b/tools/libclang/CXCursor.h @@ -31,7 +31,7 @@ class FieldDecl; class InclusionDirective; class LabelStmt; class MacroDefinition; -class MacroInstantiation; +class MacroExpansion; class NamedDecl; class ObjCInterfaceDecl; class ObjCProtocolDecl; @@ -134,13 +134,13 @@ CXCursor MakeMacroDefinitionCursor(MacroDefinition *, CXTranslationUnit TU); /// source range. MacroDefinition *getCursorMacroDefinition(CXCursor C); -/// \brief Create a macro instantiation cursor. -CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, - CXTranslationUnit TU); +/// \brief Create a macro expansion cursor. +CXCursor MakeMacroExpansionCursor(MacroExpansion *, + CXTranslationUnit TU); -/// \brief Unpack a given macro instantiation cursor to retrieve its +/// \brief Unpack a given macro expansion cursor to retrieve its /// source range. -MacroInstantiation *getCursorMacroInstantiation(CXCursor C); +MacroExpansion *getCursorMacroExpansion(CXCursor C); /// \brief Create an inclusion directive cursor. CXCursor MakeInclusionDirectiveCursor(InclusionDirective *, -- 2.40.0