[modules] Refactor creation of ModuleMacros and create them when importing from local submodules.
llvm-svn: 235669
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 847f1ff..39aac12 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1735,9 +1735,7 @@
}
MacroDirective *import(Preprocessor &PP, SourceLocation ImportLoc) const {
- if (auto *MI = MM->getMacroInfo())
- return PP.AllocateDefMacroDirective(MI, ImportLoc, MM);
- return PP.AllocateUndefMacroDirective(ImportLoc, MM);
+ return PP.AllocateImportedMacroDirective(MM, ImportLoc);
}
};
@@ -1843,16 +1841,17 @@
ModuleMacro *MM = nullptr;
if (SubmoduleID ImportedFrom = getGlobalSubmoduleID(M, Record[Idx++]))
MM = PP.getModuleMacro(getSubmodule(ImportedFrom), II);
- DefMacroDirective *DefMD = PP.AllocateDefMacroDirective(MI, Loc, MM);
- DefMD->setAmbiguous(IsAmbiguous);
- MD = DefMD;
+ MD = MM ? PP.AllocateImportedMacroDirective(MM, Loc)
+ : PP.AllocateDefMacroDirective(MI, Loc);
+ cast<DefMacroDirective>(MD)->setAmbiguous(IsAmbiguous);
break;
}
case MacroDirective::MD_Undefine: {
ModuleMacro *MM = nullptr;
if (SubmoduleID ImportedFrom = getGlobalSubmoduleID(M, Record[Idx++]))
MM = PP.getModuleMacro(getSubmodule(ImportedFrom), II);
- MD = PP.AllocateUndefMacroDirective(Loc, MM);
+ MD = MM ? PP.AllocateImportedMacroDirective(MM, Loc)
+ : PP.AllocateUndefMacroDirective(Loc);
break;
}
case MacroDirective::MD_Visibility: