forked from OSchip/llvm-project
When making a suggestion regarding which module to load rather than
preprocess/parse a header, report back with an actual module (which may be a submodule) rather than just the name of the module. llvm-svn: 144925
This commit is contained in:
parent
ee95ed5055
commit
c04f644311
|
@ -14,6 +14,7 @@
|
||||||
#ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
|
#ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
|
||||||
#define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
|
#define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
|
||||||
|
|
||||||
|
#include "clang/Lex/ModuleMap.h"
|
||||||
#include "clang/Basic/LLVM.h"
|
#include "clang/Basic/LLVM.h"
|
||||||
#include "clang/Basic/SourceManager.h"
|
#include "clang/Basic/SourceManager.h"
|
||||||
|
|
||||||
|
@ -144,13 +145,13 @@ public:
|
||||||
/// \param BuildingModule The name of the module we're currently building.
|
/// \param BuildingModule The name of the module we're currently building.
|
||||||
///
|
///
|
||||||
/// \param SuggestedModule If non-null, and the file found is semantically
|
/// \param SuggestedModule If non-null, and the file found is semantically
|
||||||
/// part of a known module, this will be set to the name of the module that
|
/// part of a known module, this will be set to the module that should
|
||||||
/// could be imported instead of preprocessing/parsing the file found.
|
/// be imported instead of preprocessing/parsing the file found.
|
||||||
const FileEntry *LookupFile(StringRef Filename, HeaderSearch &HS,
|
const FileEntry *LookupFile(StringRef Filename, HeaderSearch &HS,
|
||||||
SmallVectorImpl<char> *SearchPath,
|
SmallVectorImpl<char> *SearchPath,
|
||||||
SmallVectorImpl<char> *RelativePath,
|
SmallVectorImpl<char> *RelativePath,
|
||||||
StringRef BuildingModule,
|
StringRef BuildingModule,
|
||||||
StringRef *SuggestedModule) const;
|
ModuleMap::Module **SuggestedModule) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const FileEntry *DoFrameworkLookup(
|
const FileEntry *DoFrameworkLookup(
|
||||||
|
@ -158,7 +159,7 @@ private:
|
||||||
SmallVectorImpl<char> *SearchPath,
|
SmallVectorImpl<char> *SearchPath,
|
||||||
SmallVectorImpl<char> *RelativePath,
|
SmallVectorImpl<char> *RelativePath,
|
||||||
StringRef BuildingModule,
|
StringRef BuildingModule,
|
||||||
StringRef *SuggestedModule) const;
|
ModuleMap::Module **SuggestedModule) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -258,15 +258,15 @@ public:
|
||||||
/// Filename for framework includes.
|
/// Filename for framework includes.
|
||||||
///
|
///
|
||||||
/// \param SuggestedModule If non-null, and the file found is semantically
|
/// \param SuggestedModule If non-null, and the file found is semantically
|
||||||
/// part of a known module, this will be set to the name of the module that
|
/// part of a known module, this will be set to the module that should
|
||||||
/// could be imported instead of preprocessing/parsing the file found.
|
/// be imported instead of preprocessing/parsing the file found.
|
||||||
const FileEntry *LookupFile(StringRef Filename, bool isAngled,
|
const FileEntry *LookupFile(StringRef Filename, bool isAngled,
|
||||||
const DirectoryLookup *FromDir,
|
const DirectoryLookup *FromDir,
|
||||||
const DirectoryLookup *&CurDir,
|
const DirectoryLookup *&CurDir,
|
||||||
const FileEntry *CurFileEnt,
|
const FileEntry *CurFileEnt,
|
||||||
SmallVectorImpl<char> *SearchPath,
|
SmallVectorImpl<char> *SearchPath,
|
||||||
SmallVectorImpl<char> *RelativePath,
|
SmallVectorImpl<char> *RelativePath,
|
||||||
StringRef *SuggestedModule);
|
ModuleMap::Module **SuggestedModule);
|
||||||
|
|
||||||
/// LookupSubframeworkHeader - Look up a subframework for the specified
|
/// LookupSubframeworkHeader - Look up a subframework for the specified
|
||||||
/// #include file. For example, if #include'ing <HIToolbox/HIToolbox.h> from
|
/// #include file. For example, if #include'ing <HIToolbox/HIToolbox.h> from
|
||||||
|
@ -366,9 +366,7 @@ public:
|
||||||
bool hasModuleMap(StringRef Filename, const DirectoryEntry *Root);
|
bool hasModuleMap(StringRef Filename, const DirectoryEntry *Root);
|
||||||
|
|
||||||
/// \brief Retrieve the module that corresponds to the given file, if any.
|
/// \brief Retrieve the module that corresponds to the given file, if any.
|
||||||
///
|
ModuleMap::Module *findModuleForHeader(const FileEntry *File);
|
||||||
/// FIXME: This will need to be generalized for submodules.
|
|
||||||
StringRef findModuleForHeader(const FileEntry *File);
|
|
||||||
|
|
||||||
|
|
||||||
/// \brief Read the contents of the given module map file.
|
/// \brief Read the contents of the given module map file.
|
||||||
|
|
|
@ -1008,7 +1008,7 @@ public:
|
||||||
const DirectoryLookup *&CurDir,
|
const DirectoryLookup *&CurDir,
|
||||||
SmallVectorImpl<char> *SearchPath,
|
SmallVectorImpl<char> *SearchPath,
|
||||||
SmallVectorImpl<char> *RelativePath,
|
SmallVectorImpl<char> *RelativePath,
|
||||||
StringRef *SuggestedModule);
|
ModuleMap::Module **SuggestedModule);
|
||||||
|
|
||||||
/// GetCurLookup - The DirectoryLookup structure used to find the current
|
/// GetCurLookup - The DirectoryLookup structure used to find the current
|
||||||
/// FileEntry, if CurLexer is non-null and if applicable. This allows us to
|
/// FileEntry, if CurLexer is non-null and if applicable. This allows us to
|
||||||
|
|
|
@ -219,7 +219,7 @@ const FileEntry *DirectoryLookup::LookupFile(
|
||||||
SmallVectorImpl<char> *SearchPath,
|
SmallVectorImpl<char> *SearchPath,
|
||||||
SmallVectorImpl<char> *RelativePath,
|
SmallVectorImpl<char> *RelativePath,
|
||||||
StringRef BuildingModule,
|
StringRef BuildingModule,
|
||||||
StringRef *SuggestedModule) const {
|
ModuleMap::Module **SuggestedModule) const {
|
||||||
llvm::SmallString<1024> TmpDir;
|
llvm::SmallString<1024> TmpDir;
|
||||||
if (isNormalDir()) {
|
if (isNormalDir()) {
|
||||||
// Concatenate the requested file onto the directory.
|
// Concatenate the requested file onto the directory.
|
||||||
|
@ -245,8 +245,8 @@ const FileEntry *DirectoryLookup::LookupFile(
|
||||||
|
|
||||||
// If there is a module that corresponds to this header,
|
// If there is a module that corresponds to this header,
|
||||||
// suggest it.
|
// suggest it.
|
||||||
StringRef Module = HS.findModuleForHeader(File);
|
ModuleMap::Module *Module = HS.findModuleForHeader(File);
|
||||||
if (!Module.empty() && Module != BuildingModule)
|
if (Module && Module->getTopLevelModuleName() != BuildingModule)
|
||||||
*SuggestedModule = Module;
|
*SuggestedModule = Module;
|
||||||
|
|
||||||
return File;
|
return File;
|
||||||
|
@ -285,7 +285,7 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(
|
||||||
SmallVectorImpl<char> *SearchPath,
|
SmallVectorImpl<char> *SearchPath,
|
||||||
SmallVectorImpl<char> *RelativePath,
|
SmallVectorImpl<char> *RelativePath,
|
||||||
StringRef BuildingModule,
|
StringRef BuildingModule,
|
||||||
StringRef *SuggestedModule) const
|
ModuleMap::Module **SuggestedModule) const
|
||||||
{
|
{
|
||||||
FileManager &FileMgr = HS.getFileMgr();
|
FileManager &FileMgr = HS.getFileMgr();
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(
|
||||||
if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str(),
|
if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str(),
|
||||||
/*openFile=*/!AutomaticImport)) {
|
/*openFile=*/!AutomaticImport)) {
|
||||||
if (AutomaticImport)
|
if (AutomaticImport)
|
||||||
*SuggestedModule = Module->Name;
|
*SuggestedModule = Module;
|
||||||
return FE;
|
return FE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(
|
||||||
const FileEntry *FE = FileMgr.getFile(FrameworkName.str(),
|
const FileEntry *FE = FileMgr.getFile(FrameworkName.str(),
|
||||||
/*openFile=*/!AutomaticImport);
|
/*openFile=*/!AutomaticImport);
|
||||||
if (FE && AutomaticImport)
|
if (FE && AutomaticImport)
|
||||||
*SuggestedModule = Module->Name;
|
*SuggestedModule = Module;
|
||||||
return FE;
|
return FE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,10 +408,10 @@ const FileEntry *HeaderSearch::LookupFile(
|
||||||
const FileEntry *CurFileEnt,
|
const FileEntry *CurFileEnt,
|
||||||
SmallVectorImpl<char> *SearchPath,
|
SmallVectorImpl<char> *SearchPath,
|
||||||
SmallVectorImpl<char> *RelativePath,
|
SmallVectorImpl<char> *RelativePath,
|
||||||
StringRef *SuggestedModule)
|
ModuleMap::Module **SuggestedModule)
|
||||||
{
|
{
|
||||||
if (SuggestedModule)
|
if (SuggestedModule)
|
||||||
*SuggestedModule = StringRef();
|
*SuggestedModule = 0;
|
||||||
|
|
||||||
// If 'Filename' is absolute, check to see if it exists and no searching.
|
// If 'Filename' is absolute, check to see if it exists and no searching.
|
||||||
if (llvm::sys::path::is_absolute(Filename)) {
|
if (llvm::sys::path::is_absolute(Filename)) {
|
||||||
|
@ -806,11 +806,11 @@ bool HeaderSearch::hasModuleMap(StringRef FileName,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringRef HeaderSearch::findModuleForHeader(const FileEntry *File) {
|
ModuleMap::Module *HeaderSearch::findModuleForHeader(const FileEntry *File) {
|
||||||
if (ModuleMap::Module *Module = ModMap.findModuleForHeader(File))
|
if (ModuleMap::Module *Module = ModMap.findModuleForHeader(File))
|
||||||
return Module->getTopLevelModuleName();
|
return Module;
|
||||||
|
|
||||||
return StringRef();
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HeaderSearch::loadModuleMapFile(const FileEntry *File) {
|
bool HeaderSearch::loadModuleMapFile(const FileEntry *File) {
|
||||||
|
|
|
@ -486,7 +486,7 @@ const FileEntry *Preprocessor::LookupFile(
|
||||||
const DirectoryLookup *&CurDir,
|
const DirectoryLookup *&CurDir,
|
||||||
SmallVectorImpl<char> *SearchPath,
|
SmallVectorImpl<char> *SearchPath,
|
||||||
SmallVectorImpl<char> *RelativePath,
|
SmallVectorImpl<char> *RelativePath,
|
||||||
StringRef *SuggestedModule) {
|
ModuleMap::Module **SuggestedModule) {
|
||||||
// If the header lookup mechanism may be relative to the current file, pass in
|
// If the header lookup mechanism may be relative to the current file, pass in
|
||||||
// info about where the current file is.
|
// info about where the current file is.
|
||||||
const FileEntry *CurFileEnt = 0;
|
const FileEntry *CurFileEnt = 0;
|
||||||
|
@ -1269,7 +1269,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
|
||||||
llvm::SmallString<1024> RelativePath;
|
llvm::SmallString<1024> RelativePath;
|
||||||
// We get the raw path only if we have 'Callbacks' to which we later pass
|
// We get the raw path only if we have 'Callbacks' to which we later pass
|
||||||
// the path.
|
// the path.
|
||||||
StringRef SuggestedModule;
|
ModuleMap::Module *SuggestedModule = 0;
|
||||||
const FileEntry *File = LookupFile(
|
const FileEntry *File = LookupFile(
|
||||||
Filename, isAngled, LookupFrom, CurDir,
|
Filename, isAngled, LookupFrom, CurDir,
|
||||||
Callbacks ? &SearchPath : NULL, Callbacks ? &RelativePath : NULL,
|
Callbacks ? &SearchPath : NULL, Callbacks ? &RelativePath : NULL,
|
||||||
|
@ -1277,9 +1277,13 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
|
||||||
|
|
||||||
// If we are supposed to import a module rather than including the header,
|
// If we are supposed to import a module rather than including the header,
|
||||||
// do so now.
|
// do so now.
|
||||||
if (!SuggestedModule.empty()) {
|
if (SuggestedModule) {
|
||||||
|
// FIXME: Actually load the submodule that we were given.
|
||||||
|
while (SuggestedModule->Parent)
|
||||||
|
SuggestedModule = SuggestedModule->Parent;
|
||||||
|
|
||||||
TheModuleLoader.loadModule(IncludeTok.getLocation(),
|
TheModuleLoader.loadModule(IncludeTok.getLocation(),
|
||||||
Identifiers.get(SuggestedModule),
|
Identifiers.get(SuggestedModule->Name),
|
||||||
FilenameTok.getLocation());
|
FilenameTok.getLocation());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue