diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-02-20 00:54:57 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-02-20 00:54:57 +0000 |
commit | 9818a1d443e97677dd3422305de9cc2b1fb2a8c1 (patch) | |
tree | f6b547c4fcc33ff4bae563473287cddfeff4e21c /lib/Serialization/ASTWriter.cpp | |
parent | 206f49966f66ad7cbfe3d37c14fa7e6e7410f3be (diff) |
[preprocessor] Split the MacroInfo class into two separate concepts, MacroInfo class
for the data specific to a macro definition (e.g. what the tokens are), and
MacroDirective class which encapsulates the changes to the "macro namespace"
(e.g. the location where the macro name became active, the location where it was undefined, etc.)
(A MacroDirective always points to a MacroInfo object.)
Usually a macro definition (MacroInfo) is where a macro name becomes active (MacroDirective) but
splitting the concepts allows us to better model the effect of modules to the macro namespace
(also as a bonus it allows better modeling of push_macro/pop_macro #pragmas).
Modules can have their own macro history, separate from the local (current translation unit)
macro history; MacroDirectives will be used to model the macro history (changes to macro namespace).
For example, if "@import A;" imports macro FOO, there will be a new local MacroDirective created
to indicate that "FOO" became active at the import location. Module "A" itself will contain another
MacroDirective in its macro history (at the point of the definition of FOO) and both MacroDirectives
will point to the same MacroInfo object.
Introducing the separation of macro concepts is the first part towards better modeling of module macros.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175585 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTWriter.cpp')
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 8747bc8512..f33fbc23d8 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1746,7 +1746,7 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { // emitting each to the PP section. // Construct the list of macro definitions that need to be serialized. - SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2> + SmallVector<std::pair<const IdentifierInfo *, MacroDirective *>, 2> MacrosToEmit; llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen; for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0), @@ -1774,19 +1774,19 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) { const IdentifierInfo *Name = MacrosToEmit[I].first; - for (MacroInfo *MI = MacrosToEmit[I].second; MI; - MI = MI->getPreviousDefinition()) { - MacroID ID = getMacroRef(MI); + for (MacroDirective *MD = MacrosToEmit[I].second; MD; + MD = MD->getPrevious()) { + MacroID ID = getMacroRef(MD); if (!ID) continue; // Skip macros from a AST file if we're chaining. - if (Chain && MI->isFromAST() && !MI->hasChangedAfterLoad()) + if (Chain && MD->isImported() && !MD->hasChangedAfterLoad()) continue; if (ID < FirstMacroID) { // This will have been dealt with via an update record. - assert(MacroUpdates.count(MI) > 0 && "Missing macro update"); + assert(MacroUpdates.count(MD) > 0 && "Missing macro update"); continue; } @@ -1802,14 +1802,15 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { } AddIdentifierRef(Name, Record); - addMacroRef(MI, Record); + addMacroRef(MD, Record); + const MacroInfo *MI = MD->getInfo(); Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc())); AddSourceLocation(MI->getDefinitionLoc(), Record); AddSourceLocation(MI->getDefinitionEndLoc(), Record); - AddSourceLocation(MI->getUndefLoc(), Record); + AddSourceLocation(MD->getUndefLoc(), Record); Record.push_back(MI->isUsed()); - Record.push_back(MI->isPublic()); - AddSourceLocation(MI->getVisibilityLocation(), Record); + Record.push_back(MD->isPublic()); + AddSourceLocation(MD->getVisibilityLocation(), Record); unsigned Code; if (MI->isObjectLike()) { Code = PP_MACRO_OBJECT_LIKE; @@ -2643,7 +2644,7 @@ class ASTIdentifierTableTrait { /// \brief Determines whether this is an "interesting" identifier /// that needs a full IdentifierInfo structure written into the hash /// table. - bool isInterestingIdentifier(IdentifierInfo *II, MacroInfo *&Macro) { + bool isInterestingIdentifier(IdentifierInfo *II, MacroDirective *&Macro) { if (II->isPoisoned() || II->isExtensionToken() || II->getObjCOrBuiltinID() || @@ -2654,12 +2655,13 @@ class ASTIdentifierTableTrait { return hadMacroDefinition(II, Macro); } - bool hadMacroDefinition(IdentifierInfo *II, MacroInfo *&Macro) { + bool hadMacroDefinition(IdentifierInfo *II, MacroDirective *&Macro) { if (!II->hadMacroDefinition()) return false; - if (Macro || (Macro = PP.getMacroInfoHistory(II))) - return !Macro->isBuiltinMacro() && (!IsModule || Macro->isPublic()); + if (Macro || (Macro = PP.getMacroDirectiveHistory(II))) + return !Macro->getInfo()->isBuiltinMacro() && + (!IsModule || Macro->isPublic()); return false; } @@ -2683,12 +2685,12 @@ public: EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { unsigned KeyLen = II->getLength() + 1; unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 - MacroInfo *Macro = 0; + MacroDirective *Macro = 0; if (isInterestingIdentifier(II, Macro)) { DataLen += 2; // 2 bytes for builtin ID DataLen += 2; // 2 bytes for flags if (hadMacroDefinition(II, Macro)) { - for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) { + for (MacroDirective *M = Macro; M; M = M->getPrevious()) { if (Writer.getMacroRef(M) != 0) DataLen += 4; } @@ -2719,7 +2721,7 @@ public: void EmitData(raw_ostream& Out, IdentifierInfo* II, IdentID ID, unsigned) { - MacroInfo *Macro = 0; + MacroDirective *Macro = 0; if (!isInterestingIdentifier(II, Macro)) { clang::io::Emit32(Out, ID << 1); return; @@ -2740,7 +2742,7 @@ public: if (HadMacroDefinition) { // Write all of the macro IDs associated with this identifier. - for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) { + for (MacroDirective *M = Macro; M; M = M->getPrevious()) { if (MacroID ID = Writer.getMacroRef(M)) clang::io::Emit32(Out, ID); } @@ -3943,8 +3945,8 @@ void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Recor Record.push_back(getIdentifierRef(II)); } -void ASTWriter::addMacroRef(MacroInfo *MI, RecordDataImpl &Record) { - Record.push_back(getMacroRef(MI)); +void ASTWriter::addMacroRef(MacroDirective *MD, RecordDataImpl &Record) { + Record.push_back(getMacroRef(MD)); } IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { @@ -3957,14 +3959,14 @@ IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { return ID; } -MacroID ASTWriter::getMacroRef(MacroInfo *MI) { +MacroID ASTWriter::getMacroRef(MacroDirective *MD) { // Don't emit builtin macros like __LINE__ to the AST file unless they // have been redefined by the header (in which case they are not // isBuiltinMacro). - if (MI == 0 || MI->isBuiltinMacro()) + if (MD == 0 || MD->getInfo()->isBuiltinMacro()) return 0; - MacroID &ID = MacroIDs[MI]; + MacroID &ID = MacroIDs[MD]; if (ID == 0) ID = NextMacroID++; return ID; @@ -4709,9 +4711,9 @@ void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { StoredID = ID; } -void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { +void ASTWriter::MacroRead(serialization::MacroID ID, MacroDirective *MD) { // Always keep the highest ID. See \p TypeRead() for more information. - MacroID &StoredID = MacroIDs[MI]; + MacroID &StoredID = MacroIDs[MD]; if (ID > StoredID) StoredID = ID; } @@ -4745,8 +4747,8 @@ void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { SubmoduleIDs[Mod] = ID; } -void ASTWriter::UndefinedMacro(MacroInfo *MI) { - MacroUpdates[MI].UndefLoc = MI->getUndefLoc(); +void ASTWriter::UndefinedMacro(MacroDirective *MD) { + MacroUpdates[MD].UndefLoc = MD->getUndefLoc(); } void ASTWriter::CompletedTagDefinition(const TagDecl *D) { |