void HandleMicrosoftImportDirective(Token &Tok);
// Module inclusion testing.
- /// \brief Find the module for the source or header file that \p FilenameLoc
- /// points to.
- Module *getModuleForLocation(SourceLocation FilenameLoc);
+ /// \brief Find the module that owns the source or header file that
+ /// \p Loc points to. If the location is in a file that was included
+ /// into a module, or is outside any module, returns nullptr.
+ Module *getModuleForLocation(SourceLocation Loc);
+
+ /// \brief Find the module that contains the specified location, either
+ /// directly or indirectly.
+ Module *getModuleContainingLocation(SourceLocation Loc);
// Macro handling.
void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterTopLevelIfndef);
}
}
-Module *Preprocessor::getModuleForLocation(SourceLocation FilenameLoc) {
+Module *Preprocessor::getModuleForLocation(SourceLocation Loc) {
ModuleMap &ModMap = HeaderInfo.getModuleMap();
- if (SourceMgr.isInMainFile(FilenameLoc)) {
+ if (SourceMgr.isInMainFile(Loc)) {
if (Module *CurMod = getCurrentModule())
return CurMod; // Compiling a module.
return HeaderInfo.getModuleMap().SourceModule; // Compiling a source.
}
// Try to determine the module of the include directive.
// FIXME: Look into directly passing the FileEntry from LookupFile instead.
- FileID IDOfIncl = SourceMgr.getFileID(SourceMgr.getExpansionLoc(FilenameLoc));
+ FileID IDOfIncl = SourceMgr.getFileID(SourceMgr.getExpansionLoc(Loc));
if (const FileEntry *EntryOfIncl = SourceMgr.getFileEntryForID(IDOfIncl)) {
// The include comes from a file.
return ModMap.findModuleForHeader(EntryOfIncl).getModule();
}
}
+Module *Preprocessor::getModuleContainingLocation(SourceLocation Loc) {
+ return HeaderInfo.getModuleMap().inferModuleFromLocation(
+ FullSourceLoc(Loc, SourceMgr));
+}
+
const FileEntry *Preprocessor::LookupFile(
SourceLocation FilenameLoc,
StringRef Filename,
for (auto *MD = Macro.second.getLatest(); MD != State.getLatest();
MD = MD->getPrevious()) {
// Skip macros defined in other submodules we #included along the way.
- Module *Mod = getModuleForLocation(MD->getLocation());
+ Module *Mod = getModuleContainingLocation(MD->getLocation());
if (Mod != Info.M)
continue;
// Accumulate any overridden imported macros.
if (!MD->isImported() && getCurrentModule()) {
- Module *OwningMod = getModuleForLocation(MD->getLocation());
+ Module *OwningMod = getModuleContainingLocation(MD->getLocation());
if (!OwningMod)
return;
for (auto *PrevMD = OldMD; PrevMD; PrevMD = PrevMD->getPrevious()) {
- Module *DirectiveMod = getModuleForLocation(PrevMD->getLocation());
+ Module *DirectiveMod = getModuleContainingLocation(PrevMD->getLocation());
if (ModuleMacro *PrevMM = PrevMD->getOwningModuleMacro())
StoredMD.addOverriddenMacro(*this, PrevMM);
else if (ModuleMacro *PrevMM = getModuleMacro(DirectiveMod, II))
--- /dev/null
+#define INDIRECTLY_IN_MACROS 1
extern int __MODULE__;
#endif
+#include "macros-indirect.h"
# error MODULE macro should not be visible
#endif
+#ifndef INDIRECTLY_IN_MACROS
+# error INDIRECTLY_IN_MACROS should be visible
+#endif
+
// CHECK-PREPROCESSED: double d
double d;
DOUBLE *dp = &d;