diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-04-23 20:40:50 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-04-23 20:40:50 +0000 |
commit | 713369b057bc6401e88abbc65cab1fc0a8f688e0 (patch) | |
tree | 1ff1bc32fe2a74cf60a317285bddb4407c2f57ba /clang/lib/Lex | |
parent | 07e2d283a39a3b2a25dd642643e74e62686b5720 (diff) | |
download | bcm5719-llvm-713369b057bc6401e88abbc65cab1fc0a8f688e0.tar.gz bcm5719-llvm-713369b057bc6401e88abbc65cab1fc0a8f688e0.zip |
[modules] Store a ModuleMacro* on an imported macro directive rather than duplicating the info within it.
llvm-svn: 235644
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r-- | clang/lib/Lex/MacroInfo.cpp | 19 | ||||
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 20 | ||||
-rw-r--r-- | clang/lib/Lex/PPMacroExpansion.cpp | 19 | ||||
-rw-r--r-- | clang/lib/Lex/Pragma.cpp | 6 |
4 files changed, 35 insertions, 29 deletions
diff --git a/clang/lib/Lex/MacroInfo.cpp b/clang/lib/Lex/MacroInfo.cpp index d7f483192f1..dbc804490b2 100644 --- a/clang/lib/Lex/MacroInfo.cpp +++ b/clang/lib/Lex/MacroInfo.cpp @@ -235,6 +235,25 @@ void MacroDirective::dump() const { Out << "\n"; } +DefMacroDirective * +DefMacroDirective::createImported(Preprocessor &PP, MacroInfo *MI, + SourceLocation Loc, + ModuleMacro *ImportedFrom) { + void *Mem = PP.getPreprocessorAllocator().Allocate( + sizeof(DefMacroDirective) + sizeof(MacroDirective::ImportData), + llvm::alignOf<DefMacroDirective>()); + return new (Mem) DefMacroDirective(MI, Loc, ImportedFrom); +} + +UndefMacroDirective * +UndefMacroDirective::createImported(Preprocessor &PP, SourceLocation Loc, + ModuleMacro *ImportedFrom) { + void *Mem = PP.getPreprocessorAllocator().Allocate( + sizeof(UndefMacroDirective) + sizeof(MacroDirective::ImportData), + llvm::alignOf<UndefMacroDirective>()); + return new (Mem) UndefMacroDirective(Loc, ImportedFrom); +} + ModuleMacro *ModuleMacro::create(Preprocessor &PP, Module *OwningModule, IdentifierInfo *II, MacroInfo *Macro, ArrayRef<ModuleMacro *> Overrides) { diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index c22b0592218..4f3efa526c4 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -64,24 +64,16 @@ MacroInfo *Preprocessor::AllocateDeserializedMacroInfo(SourceLocation L, DefMacroDirective * Preprocessor::AllocateDefMacroDirective(MacroInfo *MI, SourceLocation Loc, - unsigned ImportedFromModuleID, - ArrayRef<unsigned> Overrides) { - unsigned NumExtra = (ImportedFromModuleID ? 1 : 0) + Overrides.size(); - return new (BP.Allocate(sizeof(DefMacroDirective) + - sizeof(unsigned) * NumExtra, - llvm::alignOf<DefMacroDirective>())) - DefMacroDirective(MI, Loc, ImportedFromModuleID, Overrides); + ModuleMacro *MM) { + if (MM) return DefMacroDirective::createImported(*this, MI, Loc, MM); + return new (BP) DefMacroDirective(MI, Loc); } UndefMacroDirective * Preprocessor::AllocateUndefMacroDirective(SourceLocation UndefLoc, - unsigned ImportedFromModuleID, - ArrayRef<unsigned> Overrides) { - unsigned NumExtra = (ImportedFromModuleID ? 1 : 0) + Overrides.size(); - return new (BP.Allocate(sizeof(UndefMacroDirective) + - sizeof(unsigned) * NumExtra, - llvm::alignOf<UndefMacroDirective>())) - UndefMacroDirective(UndefLoc, ImportedFromModuleID, Overrides); + ModuleMacro *MM) { + if (MM) return UndefMacroDirective::createImported(*this, UndefLoc, MM); + return new (BP) UndefMacroDirective(UndefLoc); } VisibilityMacroDirective * diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 883f2d5ff3b..54f72f64628 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -65,21 +65,18 @@ void Preprocessor::appendMacroDirective(IdentifierInfo *II, MacroDirective *MD){ return; for (auto *PrevMD = OldMD; PrevMD; PrevMD = PrevMD->getPrevious()) { - // FIXME: Store a ModuleMacro * on an imported directive. Module *DirectiveMod = getModuleForLocation(PrevMD->getLocation()); - Module *PrevOwningMod = - PrevMD->isImported() - ? getExternalSource()->getModule(PrevMD->getOwningModuleID()) - : DirectiveMod; - auto *MM = getModuleMacro(PrevOwningMod, II); - if (!MM) { + if (ModuleMacro *PrevMM = PrevMD->getOwningModuleMacro()) + StoredMD.addOverriddenMacro(*this, PrevMM); + else if (ModuleMacro *PrevMM = getModuleMacro(DirectiveMod, II)) + // The previous macro was from another submodule that we #included. + // FIXME: Create an import directive when importing a macro from a local + // submodule. + StoredMD.addOverriddenMacro(*this, PrevMM); + else // We're still within the module defining the previous macro. We don't // override it. - assert(!PrevMD->isImported() && - "imported macro with no corresponding ModuleMacro"); break; - } - StoredMD.addOverriddenMacro(*this, MM); // Stop once we leave the original macro's submodule. // diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index bfac3fda297..5625842145a 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -600,11 +600,9 @@ void Preprocessor::HandlePragmaPopMacro(Token &PopMacroTok) { // Get the MacroInfo we want to reinstall. MacroInfo *MacroToReInstall = iter->second.back(); - if (MacroToReInstall) { + if (MacroToReInstall) // Reinstall the previously pushed macro. - appendDefMacroDirective(IdentInfo, MacroToReInstall, MessageLoc, - /*isImported=*/false, /*Overrides*/None); - } + appendDefMacroDirective(IdentInfo, MacroToReInstall, MessageLoc); // Pop PragmaPushMacroInfo stack. iter->second.pop_back(); |