diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-03-26 17:17:01 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-03-26 17:17:01 +0000 |
commit | c56fff7fd231aebf4b152f60f8f11ef91835c48a (patch) | |
tree | 22119f54c12ae692e50e7ed4930160f950e37f2f /lib/Frontend | |
parent | 1232e279b4a0d98885b9672d3bb5905488360e49 (diff) |
[Preprocessor/Modules] Separate the macro directives kinds into their own MacroDirective's subclasses.
For each macro directive (define, undefine, visibility) have a separate object that gets chained
to the macro directive history. This has several benefits:
-No need to mutate a MacroDirective when there is a undefine/visibility directive. Stuff like
PPMutationListener become unnecessary.
-No need to keep extra source locations for the undef/visibility locations for the define directive object
(which is the majority of the directives)
-Much easier to hide/unhide a section in the macro directive history.
-Easier to track the effects of the directives across different submodules.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178037 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend')
-rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 39 | ||||
-rw-r--r-- | lib/Frontend/PrintPreprocessedOutput.cpp | 4 |
2 files changed, 23 insertions, 20 deletions
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 4c4d603716..c6c850b0d6 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -923,10 +923,11 @@ static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro, // If this identifier does not currently have a macro definition, // check whether it had one on the command line. if (!Id->hasMacroDefinition()) { - MacroDirective *UndefMD = PP.getMacroDirectiveHistory(Id); - for (MacroDirective *MD = UndefMD; MD; MD = MD->getPrevious()) { - - FileID FID = SourceMgr.getFileID(MD->getLocation()); + MacroDirective::DefInfo LatestDef = + PP.getMacroDirectiveHistory(Id)->getDefinition(); + for (MacroDirective::DefInfo Def = LatestDef; Def; + Def = Def.getPreviousDefinition()) { + FileID FID = SourceMgr.getFileID(Def.getLocation()); if (FID.isInvalid()) continue; @@ -942,8 +943,8 @@ static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro, // Complain. PP.Diag(ImportLoc, diag::warn_module_config_macro_undef) << true << ConfigMacro << Mod->getFullModuleName(); - if (UndefMD->getUndefLoc().isValid()) - PP.Diag(UndefMD->getUndefLoc(), diag::note_module_def_undef_here) + if (LatestDef.isUndefined()) + PP.Diag(LatestDef.getUndefLocation(), diag::note_module_def_undef_here) << true; return; } @@ -954,10 +955,12 @@ static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro, // This identifier has a macro definition. Check whether we had a definition // on the command line. - MacroDirective *DefMD = PP.getMacroDirective(Id); - MacroDirective *PredefinedMD = 0; - for (MacroDirective *MD = DefMD; MD; MD = MD->getPrevious()) { - FileID FID = SourceMgr.getFileID(MD->getLocation()); + MacroDirective::DefInfo LatestDef = + PP.getMacroDirectiveHistory(Id)->getDefinition(); + MacroDirective::DefInfo PredefinedDef; + for (MacroDirective::DefInfo Def = LatestDef; Def; + Def = Def.getPreviousDefinition()) { + FileID FID = SourceMgr.getFileID(Def.getLocation()); if (FID.isInvalid()) continue; @@ -969,32 +972,32 @@ static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro, if (!StringRef(Buffer->getBufferIdentifier()).equals("<built-in>")) continue; - PredefinedMD = MD; + PredefinedDef = Def; break; } // If there was no definition for this macro in the predefines buffer, // complain. - if (!PredefinedMD || - (!PredefinedMD->getLocation().isValid() && - PredefinedMD->getUndefLoc().isValid())) { + if (!PredefinedDef || + (!PredefinedDef.getLocation().isValid() && + PredefinedDef.getUndefLocation().isValid())) { PP.Diag(ImportLoc, diag::warn_module_config_macro_undef) << false << ConfigMacro << Mod->getFullModuleName(); - PP.Diag(DefMD->getLocation(), diag::note_module_def_undef_here) + PP.Diag(LatestDef.getLocation(), diag::note_module_def_undef_here) << false; return; } // If the current macro definition is the same as the predefined macro // definition, it's okay. - if (DefMD == PredefinedMD || - DefMD->getInfo()->isIdenticalTo(*PredefinedMD->getInfo(), PP)) + if (LatestDef.getMacroInfo() == PredefinedDef.getMacroInfo() || + LatestDef.getMacroInfo()->isIdenticalTo(*PredefinedDef.getMacroInfo(),PP)) return; // The macro definitions differ. PP.Diag(ImportLoc, diag::warn_module_config_macro_undef) << false << ConfigMacro << Mod->getFullModuleName(); - PP.Diag(DefMD->getLocation(), diag::note_module_def_undef_here) + PP.Diag(LatestDef.getLocation(), diag::note_module_def_undef_here) << false; } diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index d894939b4b..f70bd7c93e 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -318,7 +318,7 @@ void PrintPPOutputPPCallbacks::Ident(SourceLocation Loc, const std::string &S) { /// MacroDefined - This hook is called whenever a macro definition is seen. void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) { - const MacroInfo *MI = MD->getInfo(); + const MacroInfo *MI = MD->getMacroInfo(); // Only print out macro definitions in -dD mode. if (!DumpDefines || // Ignore __FILE__ etc. @@ -602,7 +602,7 @@ static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) { for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end(); I != E; ++I) { if (I->first->hasMacroDefinition()) - MacrosByID.push_back(id_macro_pair(I->first, I->second->getInfo())); + MacrosByID.push_back(id_macro_pair(I->first, I->second->getMacroInfo())); } llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(), MacroIDCompare); |