Teach subframework header lookup to suggest modules <rdar://problem/13176200>.

llvm-svn: 174683
This commit is contained in:
Douglas Gregor 2013-02-08 00:10:48 +00:00
parent cff2b27bf4
commit f5f9452808
10 changed files with 45 additions and 5 deletions

View File

@ -363,7 +363,8 @@ public:
StringRef Filename, StringRef Filename,
const FileEntry *RelativeFileEnt, const FileEntry *RelativeFileEnt,
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *SearchPath,
SmallVectorImpl<char> *RelativePath); SmallVectorImpl<char> *RelativePath,
Module **SuggestedModule);
/// \brief Look up the specified framework name in our framework cache. /// \brief Look up the specified framework name in our framework cache.
/// \returns The DirectoryEntry it is in if we know, null otherwise. /// \returns The DirectoryEntry it is in if we know, null otherwise.

View File

@ -665,7 +665,8 @@ const FileEntry *HeaderSearch::
LookupSubframeworkHeader(StringRef Filename, LookupSubframeworkHeader(StringRef Filename,
const FileEntry *ContextFileEnt, const FileEntry *ContextFileEnt,
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *SearchPath,
SmallVectorImpl<char> *RelativePath) { SmallVectorImpl<char> *RelativePath,
Module **SuggestedModule) {
assert(ContextFileEnt && "No context file?"); assert(ContextFileEnt && "No context file?");
// Framework names must have a '/' in the filename. Find it. // Framework names must have a '/' in the filename. Find it.
@ -754,6 +755,26 @@ LookupSubframeworkHeader(StringRef Filename,
// of evaluation. // of evaluation.
unsigned DirInfo = getFileInfo(ContextFileEnt).DirInfo; unsigned DirInfo = getFileInfo(ContextFileEnt).DirInfo;
getFileInfo(FE).DirInfo = DirInfo; getFileInfo(FE).DirInfo = DirInfo;
// If we're supposed to suggest a module, look for one now.
if (SuggestedModule) {
// Find the top-level framework based on this framework.
FrameworkName.pop_back(); // remove the trailing '/'
SmallVector<std::string, 4> SubmodulePath;
const DirectoryEntry *TopFrameworkDir
= ::getTopFrameworkDir(FileMgr, FrameworkName, SubmodulePath);
// Determine the name of the top-level framework.
StringRef ModuleName = llvm::sys::path::stem(TopFrameworkDir->getName());
// Load this framework module. If that succeeds, find the suggested module
// for this header, if any.
bool IsSystem = false;
if (loadFrameworkModule(ModuleName, TopFrameworkDir, IsSystem)) {
*SuggestedModule = findModuleForHeader(FE);
}
}
return FE; return FE;
} }

View File

@ -537,11 +537,11 @@ const FileEntry *Preprocessor::LookupFile(
// Otherwise, see if this is a subframework header. If so, this is relative // Otherwise, see if this is a subframework header. If so, this is relative
// to one of the headers on the #include stack. Walk the list of the current // to one of the headers on the #include stack. Walk the list of the current
// headers on the #include stack and pass them to HeaderInfo. // headers on the #include stack and pass them to HeaderInfo.
// FIXME: SuggestedModule!
if (IsFileLexer()) { if (IsFileLexer()) {
if ((CurFileEnt = SourceMgr.getFileEntryForID(CurPPLexer->getFileID()))) if ((CurFileEnt = SourceMgr.getFileEntryForID(CurPPLexer->getFileID())))
if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt, if ((FE = HeaderInfo.LookupSubframeworkHeader(Filename, CurFileEnt,
SearchPath, RelativePath))) SearchPath, RelativePath,
SuggestedModule)))
return FE; return FE;
} }
@ -551,7 +551,8 @@ const FileEntry *Preprocessor::LookupFile(
if ((CurFileEnt = if ((CurFileEnt =
SourceMgr.getFileEntryForID(ISEntry.ThePPLexer->getFileID()))) SourceMgr.getFileEntryForID(ISEntry.ThePPLexer->getFileID())))
if ((FE = HeaderInfo.LookupSubframeworkHeader( if ((FE = HeaderInfo.LookupSubframeworkHeader(
Filename, CurFileEnt, SearchPath, RelativePath))) Filename, CurFileEnt, SearchPath, RelativePath,
SuggestedModule)))
return FE; return FE;
} }
} }

View File

@ -26,6 +26,7 @@ int glob;
// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_PRIVATE_H:.*/Modules/Inputs/DependsOnModule.framework[/\\]PrivateHeaders[/\\]DependsOnModulePrivate.h]] | {{.*}} | hash loc: <invalid> // CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_PRIVATE_H:.*/Modules/Inputs/DependsOnModule.framework[/\\]PrivateHeaders[/\\]DependsOnModulePrivate.h]] | {{.*}} | hash loc: <invalid>
// CHECK-DMOD-NEXT: [importedASTFile]: {{.*}}.cache{{[/\\]}}Module.pcm | loc: [[DMOD_MODULE_H]]:1:2 | name: "Module" | isImplicit: 1 // CHECK-DMOD-NEXT: [importedASTFile]: {{.*}}.cache{{[/\\]}}Module.pcm | loc: [[DMOD_MODULE_H]]:1:2 | name: "Module" | isImplicit: 1
// CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: depends_on_module_other | {{.*}} | loc: [[DMOD_OTHER_H]]:1:5 // CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: depends_on_module_other | {{.*}} | loc: [[DMOD_OTHER_H]]:1:5
// CHECK-DMOD-NEXT: [importedASTFile]: {{.*}}.cache/DependsOnModule.pcm | loc: {{.*}}SubFramework.h:1:2 | name: "DependsOnModule.SubFramework.Other" | isImplicit: 1
// CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: sub_framework | {{.*}} | loc: [[DMOD_SUB_H]]:2:8 // CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: sub_framework | {{.*}} | loc: [[DMOD_SUB_H]]:2:8
// CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: sub_framework_other | {{.*}} | loc: [[DMOD_SUB_OTHER_H]]:1:9 // CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: sub_framework_other | {{.*}} | loc: [[DMOD_SUB_OTHER_H]]:1:9
// CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: depends_on_module_private | {{.*}} | loc: [[DMOD_PRIVATE_H]]:1:5 // CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: depends_on_module_private | {{.*}} | loc: [[DMOD_PRIVATE_H]]:1:5

View File

@ -0,0 +1 @@
#include <Sub/Types.h>

View File

@ -0,0 +1,4 @@
struct FrameworkSubStruct {
const char * name;
unsigned version;
};

View File

@ -0,0 +1 @@
#import <Sub/Sub.h>

View File

@ -0,0 +1,2 @@
#import <Sub/SubPriv.h>

View File

@ -20,3 +20,10 @@ void testSubFrameworkAgain() {
CXXOnly cxxonly; CXXOnly cxxonly;
#endif #endif
@import HasSubModules;
// expected-warning@1{{treating #include as an import of module 'HasSubModules.Sub.Types'}}
#import <HasSubModules/HasSubModulesPriv.h>
struct FrameworkSubStruct ss;