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/Lex/Pragma.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/Lex/Pragma.cpp')
-rw-r--r-- | lib/Lex/Pragma.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp index 092216aef5..23d088a9fb 100644 --- a/lib/Lex/Pragma.cpp +++ b/lib/Lex/Pragma.cpp @@ -650,17 +650,13 @@ void Preprocessor::HandlePragmaPushMacro(Token &PushMacroTok) { // Get the MacroInfo associated with IdentInfo. MacroInfo *MI = getMacroInfo(IdentInfo); - MacroInfo *MacroCopyToPush = 0; if (MI) { - // Make a clone of MI. - MacroCopyToPush = CloneMacroInfo(*MI); - // Allow the original MacroInfo to be redefined later. MI->setIsAllowRedefinitionsWithoutWarning(true); } // Push the cloned MacroInfo so we can retrieve it later. - PragmaPushMacroInfo[IdentInfo].push_back(MacroCopyToPush); + PragmaPushMacroInfo[IdentInfo].push_back(MI); } /// \brief Handle \#pragma pop_macro. @@ -681,10 +677,10 @@ void Preprocessor::HandlePragmaPopMacro(Token &PopMacroTok) { PragmaPushMacroInfo.find(IdentInfo); if (iter != PragmaPushMacroInfo.end()) { // Forget the MacroInfo currently associated with IdentInfo. - if (MacroInfo *CurrentMI = getMacroInfo(IdentInfo)) { - if (CurrentMI->isWarnIfUnused()) - WarnUnusedMacroLocs.erase(CurrentMI->getDefinitionLoc()); - UndefineMacro(IdentInfo, CurrentMI, MessageLoc); + if (MacroDirective *CurrentMD = getMacroDirective(IdentInfo)) { + if (CurrentMD->getInfo()->isWarnIfUnused()) + WarnUnusedMacroLocs.erase(CurrentMD->getInfo()->getDefinitionLoc()); + UndefineMacro(IdentInfo, CurrentMD, MessageLoc); } // Get the MacroInfo we want to reinstall. @@ -692,7 +688,8 @@ void Preprocessor::HandlePragmaPopMacro(Token &PopMacroTok) { if (MacroToReInstall) { // Reinstall the previously pushed macro. - setMacroInfo(IdentInfo, MacroToReInstall); + setMacroDirective(IdentInfo, MacroToReInstall, MessageLoc, + /*isImported=*/false); } else if (IdentInfo->hasMacroDefinition()) { clearMacroInfo(IdentInfo); } |