blob: 6403cfb8683bc66543a0423c7ab3449b0d193653 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- HeaderSearch.cpp - Resolve Header File Locations ---===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the DirectoryLookup and HeaderSearch interfaces.
11//
12//===----------------------------------------------------------------------===//
13
Reid Spencer5f016e22007-07-11 17:01:13 +000014#include "clang/Lex/HeaderSearch.h"
Chris Lattner822da612007-12-17 06:36:45 +000015#include "clang/Lex/HeaderMap.h"
Douglas Gregora30cfe52011-11-11 19:10:28 +000016#include "clang/Basic/Diagnostic.h"
Chris Lattnerc7229c32007-10-07 08:58:51 +000017#include "clang/Basic/FileManager.h"
18#include "clang/Basic/IdentifierTable.h"
Michael J. Spencer32bef4e2011-01-10 02:34:13 +000019#include "llvm/Support/FileSystem.h"
Michael J. Spencer03013fa2010-11-29 18:12:39 +000020#include "llvm/Support/Path.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000021#include "llvm/ADT/SmallString.h"
Ted Kremenekeabea452011-07-27 18:41:18 +000022#include "llvm/Support/Capacity.h"
Chris Lattner3daed522009-03-02 22:20:04 +000023#include <cstdio>
Reid Spencer5f016e22007-07-11 17:01:13 +000024using namespace clang;
25
Douglas Gregor8c5a7602009-04-25 23:30:02 +000026const IdentifierInfo *
27HeaderFileInfo::getControllingMacro(ExternalIdentifierLookup *External) {
28 if (ControllingMacro)
29 return ControllingMacro;
30
31 if (!ControllingMacroID || !External)
32 return 0;
33
34 ControllingMacro = External->GetIdentifier(ControllingMacroID);
35 return ControllingMacro;
36}
37
Douglas Gregorcfbf1c72011-02-10 17:09:37 +000038ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource() {}
39
Douglas Gregor8e238062011-11-11 00:35:06 +000040HeaderSearch::HeaderSearch(FileManager &FM, DiagnosticsEngine &Diags)
Douglas Gregora30cfe52011-11-11 19:10:28 +000041 : FileMgr(FM), Diags(Diags), FrameworkMap(64),
42 ModMap(FileMgr, *Diags.getClient())
Douglas Gregor8e238062011-11-11 00:35:06 +000043{
Nico Weber74a5fd82011-05-24 04:31:14 +000044 AngledDirIdx = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +000045 SystemDirIdx = 0;
46 NoCurDirSearch = false;
Mike Stump1eb44332009-09-09 15:08:12 +000047
Douglas Gregor8c5a7602009-04-25 23:30:02 +000048 ExternalLookup = 0;
Douglas Gregorcfbf1c72011-02-10 17:09:37 +000049 ExternalSource = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +000050 NumIncluded = 0;
51 NumMultiIncludeFileOptzn = 0;
52 NumFrameworkLookups = NumSubFrameworkLookups = 0;
53}
54
Chris Lattner822da612007-12-17 06:36:45 +000055HeaderSearch::~HeaderSearch() {
56 // Delete headermaps.
57 for (unsigned i = 0, e = HeaderMaps.size(); i != e; ++i)
58 delete HeaderMaps[i].second;
59}
Mike Stump1eb44332009-09-09 15:08:12 +000060
Reid Spencer5f016e22007-07-11 17:01:13 +000061void HeaderSearch::PrintStats() {
62 fprintf(stderr, "\n*** HeaderSearch Stats:\n");
63 fprintf(stderr, "%d files tracked.\n", (int)FileInfo.size());
64 unsigned NumOnceOnlyFiles = 0, MaxNumIncludes = 0, NumSingleIncludedFiles = 0;
65 for (unsigned i = 0, e = FileInfo.size(); i != e; ++i) {
66 NumOnceOnlyFiles += FileInfo[i].isImport;
67 if (MaxNumIncludes < FileInfo[i].NumIncludes)
68 MaxNumIncludes = FileInfo[i].NumIncludes;
69 NumSingleIncludedFiles += FileInfo[i].NumIncludes == 1;
70 }
71 fprintf(stderr, " %d #import/#pragma once files.\n", NumOnceOnlyFiles);
72 fprintf(stderr, " %d included exactly once.\n", NumSingleIncludedFiles);
73 fprintf(stderr, " %d max times a file is included.\n", MaxNumIncludes);
Mike Stump1eb44332009-09-09 15:08:12 +000074
Reid Spencer5f016e22007-07-11 17:01:13 +000075 fprintf(stderr, " %d #include/#include_next/#import.\n", NumIncluded);
76 fprintf(stderr, " %d #includes skipped due to"
77 " the multi-include optimization.\n", NumMultiIncludeFileOptzn);
Mike Stump1eb44332009-09-09 15:08:12 +000078
Reid Spencer5f016e22007-07-11 17:01:13 +000079 fprintf(stderr, "%d framework lookups.\n", NumFrameworkLookups);
80 fprintf(stderr, "%d subframework lookups.\n", NumSubFrameworkLookups);
81}
82
Chris Lattner822da612007-12-17 06:36:45 +000083/// CreateHeaderMap - This method returns a HeaderMap for the specified
84/// FileEntry, uniquing them through the the 'HeaderMaps' datastructure.
Chris Lattner1bfd4a62007-12-17 18:34:53 +000085const HeaderMap *HeaderSearch::CreateHeaderMap(const FileEntry *FE) {
Chris Lattner822da612007-12-17 06:36:45 +000086 // We expect the number of headermaps to be small, and almost always empty.
Chris Lattnerdf772332007-12-17 07:52:39 +000087 // If it ever grows, use of a linear search should be re-evaluated.
Chris Lattner822da612007-12-17 06:36:45 +000088 if (!HeaderMaps.empty()) {
89 for (unsigned i = 0, e = HeaderMaps.size(); i != e; ++i)
Chris Lattnerdf772332007-12-17 07:52:39 +000090 // Pointer equality comparison of FileEntries works because they are
91 // already uniqued by inode.
Mike Stump1eb44332009-09-09 15:08:12 +000092 if (HeaderMaps[i].first == FE)
Chris Lattner822da612007-12-17 06:36:45 +000093 return HeaderMaps[i].second;
94 }
Mike Stump1eb44332009-09-09 15:08:12 +000095
Chris Lattner39b49bc2010-11-23 08:35:12 +000096 if (const HeaderMap *HM = HeaderMap::Create(FE, FileMgr)) {
Chris Lattner822da612007-12-17 06:36:45 +000097 HeaderMaps.push_back(std::make_pair(FE, HM));
98 return HM;
99 }
Mike Stump1eb44332009-09-09 15:08:12 +0000100
Chris Lattner822da612007-12-17 06:36:45 +0000101 return 0;
102}
103
Douglas Gregor21cae202011-09-12 23:31:24 +0000104const FileEntry *HeaderSearch::lookupModule(StringRef ModuleName,
Douglas Gregor6e975c42011-09-13 23:15:45 +0000105 std::string *ModuleFileName,
Douglas Gregor21cae202011-09-12 23:31:24 +0000106 std::string *UmbrellaHeader) {
Douglas Gregor9a6da692011-09-12 20:41:59 +0000107 // If we don't have a module cache path, we can't do anything.
Douglas Gregor6e975c42011-09-13 23:15:45 +0000108 if (ModuleCachePath.empty()) {
109 if (ModuleFileName)
110 ModuleFileName->clear();
Douglas Gregor9a6da692011-09-12 20:41:59 +0000111 return 0;
Douglas Gregor6e975c42011-09-13 23:15:45 +0000112 }
113
Douglas Gregor21cae202011-09-12 23:31:24 +0000114 // Try to find the module path.
Douglas Gregor9a6da692011-09-12 20:41:59 +0000115 llvm::SmallString<256> FileName(ModuleCachePath);
116 llvm::sys::path::append(FileName, ModuleName + ".pcm");
Douglas Gregor6e975c42011-09-13 23:15:45 +0000117 if (ModuleFileName)
118 *ModuleFileName = FileName.str();
119
120 if (const FileEntry *ModuleFile
121 = getFileMgr().getFile(FileName, /*OpenFile=*/false,
122 /*CacheFailure=*/false))
Douglas Gregor21cae202011-09-12 23:31:24 +0000123 return ModuleFile;
124
125 // We didn't find the module. If we're not supposed to look for an
126 // umbrella header, this is the end of the road.
127 if (!UmbrellaHeader)
128 return 0;
129
130 // Look in each of the framework directories for an umbrella header with
131 // the same name as the module.
132 // FIXME: We need a way for non-frameworks to provide umbrella headers.
133 llvm::SmallString<128> UmbrellaHeaderName;
134 UmbrellaHeaderName = ModuleName;
135 UmbrellaHeaderName += '/';
136 UmbrellaHeaderName += ModuleName;
137 UmbrellaHeaderName += ".h";
138 for (unsigned Idx = 0, N = SearchDirs.size(); Idx != N; ++Idx) {
139 // Skip non-framework include paths
140 if (!SearchDirs[Idx].isFramework())
141 continue;
142
143 // Look for the umbrella header in this directory.
144 if (const FileEntry *HeaderFile
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000145 = SearchDirs[Idx].LookupFile(UmbrellaHeaderName, *this, 0, 0,
146 StringRef(), 0)) {
Douglas Gregor21cae202011-09-12 23:31:24 +0000147 *UmbrellaHeader = HeaderFile->getName();
148 return 0;
149 }
150 }
151
152 // We did not find an umbrella header. Clear out the UmbrellaHeader pointee
153 // so our caller knows that we failed.
154 UmbrellaHeader->clear();
155 return 0;
Douglas Gregor9a6da692011-09-12 20:41:59 +0000156}
157
Chris Lattnerdf772332007-12-17 07:52:39 +0000158//===----------------------------------------------------------------------===//
159// File lookup within a DirectoryLookup scope
160//===----------------------------------------------------------------------===//
161
Chris Lattner3af66a92007-12-17 17:57:27 +0000162/// getName - Return the directory or filename corresponding to this lookup
163/// object.
164const char *DirectoryLookup::getName() const {
165 if (isNormalDir())
166 return getDir()->getName();
167 if (isFramework())
168 return getFrameworkDir()->getName();
169 assert(isHeaderMap() && "Unknown DirectoryLookup");
170 return getHeaderMap()->getFileName();
171}
172
173
Chris Lattnerdf772332007-12-17 07:52:39 +0000174/// LookupFile - Lookup the specified file in this search path, returning it
175/// if it exists or returning null if not.
Chandler Carruthb5142bb2011-03-16 18:34:36 +0000176const FileEntry *DirectoryLookup::LookupFile(
Chris Lattner5f9e2722011-07-23 10:55:15 +0000177 StringRef Filename,
Manuel Klimek74124942011-04-26 21:50:03 +0000178 HeaderSearch &HS,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000179 SmallVectorImpl<char> *SearchPath,
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000180 SmallVectorImpl<char> *RelativePath,
181 StringRef BuildingModule,
182 StringRef *SuggestedModule) const {
Chris Lattnerdf772332007-12-17 07:52:39 +0000183 llvm::SmallString<1024> TmpDir;
Chris Lattnerafded5b2007-12-17 08:13:48 +0000184 if (isNormalDir()) {
185 // Concatenate the requested file onto the directory.
Eli Friedmana6e023c2011-07-08 20:17:28 +0000186 TmpDir = getDir()->getName();
187 llvm::sys::path::append(TmpDir, Filename);
Manuel Klimek74124942011-04-26 21:50:03 +0000188 if (SearchPath != NULL) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000189 StringRef SearchPathRef(getDir()->getName());
Manuel Klimek74124942011-04-26 21:50:03 +0000190 SearchPath->clear();
191 SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
192 }
193 if (RelativePath != NULL) {
194 RelativePath->clear();
195 RelativePath->append(Filename.begin(), Filename.end());
196 }
Douglas Gregora30cfe52011-11-11 19:10:28 +0000197
198 // If we have a module map that might map this header, load it and
199 // check whether we'll have a suggestion for a module.
200 if (SuggestedModule && HS.hasModuleMap(TmpDir, getDir())) {
201 const FileEntry *File = HS.getFileMgr().getFile(TmpDir.str(),
202 /*openFile=*/false);
203 if (!File)
204 return File;
205
206 // If there is a module that corresponds to this header,
207 // suggest it.
208 StringRef Module = HS.getModuleForHeader(File);
209 if (!Module.empty() && Module != BuildingModule)
210 *SuggestedModule = Module;
211
212 return File;
213 }
214
Argyrios Kyrtzidis3cd01282011-03-16 19:17:25 +0000215 return HS.getFileMgr().getFile(TmpDir.str(), /*openFile=*/true);
Chris Lattnerafded5b2007-12-17 08:13:48 +0000216 }
Mike Stump1eb44332009-09-09 15:08:12 +0000217
Chris Lattnerafded5b2007-12-17 08:13:48 +0000218 if (isFramework())
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000219 return DoFrameworkLookup(Filename, HS, SearchPath, RelativePath,
220 BuildingModule, SuggestedModule);
Mike Stump1eb44332009-09-09 15:08:12 +0000221
Chris Lattnerb09e71f2007-12-17 08:17:39 +0000222 assert(isHeaderMap() && "Unknown directory lookup");
Manuel Klimek74124942011-04-26 21:50:03 +0000223 const FileEntry * const Result = getHeaderMap()->LookupFile(
224 Filename, HS.getFileMgr());
225 if (Result) {
226 if (SearchPath != NULL) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000227 StringRef SearchPathRef(getName());
Manuel Klimek74124942011-04-26 21:50:03 +0000228 SearchPath->clear();
229 SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
230 }
231 if (RelativePath != NULL) {
232 RelativePath->clear();
233 RelativePath->append(Filename.begin(), Filename.end());
234 }
235 }
236 return Result;
Chris Lattnerdf772332007-12-17 07:52:39 +0000237}
238
239
Chris Lattnerafded5b2007-12-17 08:13:48 +0000240/// DoFrameworkLookup - Do a lookup of the specified file in the current
241/// DirectoryLookup, which is a framework directory.
Chandler Carruthb5142bb2011-03-16 18:34:36 +0000242const FileEntry *DirectoryLookup::DoFrameworkLookup(
Chris Lattner5f9e2722011-07-23 10:55:15 +0000243 StringRef Filename,
Manuel Klimek74124942011-04-26 21:50:03 +0000244 HeaderSearch &HS,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000245 SmallVectorImpl<char> *SearchPath,
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000246 SmallVectorImpl<char> *RelativePath,
247 StringRef BuildingModule,
248 StringRef *SuggestedModule) const
249{
Chris Lattnerafded5b2007-12-17 08:13:48 +0000250 FileManager &FileMgr = HS.getFileMgr();
Mike Stump1eb44332009-09-09 15:08:12 +0000251
Reid Spencer5f016e22007-07-11 17:01:13 +0000252 // Framework names must have a '/' in the filename.
Chris Lattnera1394812010-01-10 01:35:12 +0000253 size_t SlashPos = Filename.find('/');
Chris Lattner5f9e2722011-07-23 10:55:15 +0000254 if (SlashPos == StringRef::npos) return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000255
Chris Lattnerafded5b2007-12-17 08:13:48 +0000256 // Find out if this is the home for the specified framework, by checking
257 // HeaderSearch. Possible answer are yes/no and unknown.
Mike Stump1eb44332009-09-09 15:08:12 +0000258 const DirectoryEntry *&FrameworkDirCache =
Chris Lattnera1394812010-01-10 01:35:12 +0000259 HS.LookupFrameworkCache(Filename.substr(0, SlashPos));
Mike Stump1eb44332009-09-09 15:08:12 +0000260
Chris Lattnerafded5b2007-12-17 08:13:48 +0000261 // If it is known and in some other directory, fail.
262 if (FrameworkDirCache && FrameworkDirCache != getFrameworkDir())
Reid Spencer5f016e22007-07-11 17:01:13 +0000263 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000264
Chris Lattnerafded5b2007-12-17 08:13:48 +0000265 // Otherwise, construct the path to this framework dir.
Mike Stump1eb44332009-09-09 15:08:12 +0000266
Reid Spencer5f016e22007-07-11 17:01:13 +0000267 // FrameworkName = "/System/Library/Frameworks/"
268 llvm::SmallString<1024> FrameworkName;
Chris Lattnerafded5b2007-12-17 08:13:48 +0000269 FrameworkName += getFrameworkDir()->getName();
Reid Spencer5f016e22007-07-11 17:01:13 +0000270 if (FrameworkName.empty() || FrameworkName.back() != '/')
271 FrameworkName.push_back('/');
Mike Stump1eb44332009-09-09 15:08:12 +0000272
Reid Spencer5f016e22007-07-11 17:01:13 +0000273 // FrameworkName = "/System/Library/Frameworks/Cocoa"
Chris Lattnera1394812010-01-10 01:35:12 +0000274 FrameworkName.append(Filename.begin(), Filename.begin()+SlashPos);
Mike Stump1eb44332009-09-09 15:08:12 +0000275
Reid Spencer5f016e22007-07-11 17:01:13 +0000276 // FrameworkName = "/System/Library/Frameworks/Cocoa.framework/"
277 FrameworkName += ".framework/";
Mike Stump1eb44332009-09-09 15:08:12 +0000278
Chris Lattnerafded5b2007-12-17 08:13:48 +0000279 // If the cache entry is still unresolved, query to see if the cache entry is
280 // still unresolved. If so, check its existence now.
281 if (FrameworkDirCache == 0) {
282 HS.IncrementFrameworkLookupCount();
Mike Stump1eb44332009-09-09 15:08:12 +0000283
Reid Spencer5f016e22007-07-11 17:01:13 +0000284 // If the framework dir doesn't exist, we fail.
Chris Lattnerafded5b2007-12-17 08:13:48 +0000285 // FIXME: It's probably more efficient to query this with FileMgr.getDir.
Michael J. Spencer32bef4e2011-01-10 02:34:13 +0000286 bool Exists;
287 if (llvm::sys::fs::exists(FrameworkName.str(), Exists) || !Exists)
Reid Spencer5f016e22007-07-11 17:01:13 +0000288 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000289
Reid Spencer5f016e22007-07-11 17:01:13 +0000290 // Otherwise, if it does, remember that this is the right direntry for this
291 // framework.
Chris Lattnerafded5b2007-12-17 08:13:48 +0000292 FrameworkDirCache = getFrameworkDir();
Reid Spencer5f016e22007-07-11 17:01:13 +0000293 }
Mike Stump1eb44332009-09-09 15:08:12 +0000294
Manuel Klimek74124942011-04-26 21:50:03 +0000295 if (RelativePath != NULL) {
296 RelativePath->clear();
297 RelativePath->append(Filename.begin()+SlashPos+1, Filename.end());
298 }
299
Reid Spencer5f016e22007-07-11 17:01:13 +0000300 // Check "/System/Library/Frameworks/Cocoa.framework/Headers/file.h"
301 unsigned OrigSize = FrameworkName.size();
Mike Stump1eb44332009-09-09 15:08:12 +0000302
Reid Spencer5f016e22007-07-11 17:01:13 +0000303 FrameworkName += "Headers/";
Manuel Klimek74124942011-04-26 21:50:03 +0000304
305 if (SearchPath != NULL) {
306 SearchPath->clear();
307 // Without trailing '/'.
308 SearchPath->append(FrameworkName.begin(), FrameworkName.end()-1);
309 }
310
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000311 /// Determine whether this is the module we're building or not.
312 bool AutomaticImport = SuggestedModule &&
Douglas Gregor0fd787b2011-09-16 00:22:46 +0000313 (BuildingModule != StringRef(Filename.begin(), SlashPos)) &&
314 !Filename.substr(SlashPos + 1).startswith("..");
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000315
Chris Lattnera1394812010-01-10 01:35:12 +0000316 FrameworkName.append(Filename.begin()+SlashPos+1, Filename.end());
Argyrios Kyrtzidis3cd01282011-03-16 19:17:25 +0000317 if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str(),
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000318 /*openFile=*/!AutomaticImport)) {
319 if (AutomaticImport)
320 *SuggestedModule = StringRef(Filename.begin(), SlashPos);
Reid Spencer5f016e22007-07-11 17:01:13 +0000321 return FE;
Chandler Carruthb5142bb2011-03-16 18:34:36 +0000322 }
Mike Stump1eb44332009-09-09 15:08:12 +0000323
Reid Spencer5f016e22007-07-11 17:01:13 +0000324 // Check "/System/Library/Frameworks/Cocoa.framework/PrivateHeaders/file.h"
325 const char *Private = "Private";
Mike Stump1eb44332009-09-09 15:08:12 +0000326 FrameworkName.insert(FrameworkName.begin()+OrigSize, Private,
Reid Spencer5f016e22007-07-11 17:01:13 +0000327 Private+strlen(Private));
Manuel Klimek74124942011-04-26 21:50:03 +0000328 if (SearchPath != NULL)
329 SearchPath->insert(SearchPath->begin()+OrigSize, Private,
330 Private+strlen(Private));
331
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000332 const FileEntry *FE = FileMgr.getFile(FrameworkName.str(),
333 /*openFile=*/!AutomaticImport);
334 if (FE && AutomaticImport)
335 *SuggestedModule = StringRef(Filename.begin(), SlashPos);
336 return FE;
Reid Spencer5f016e22007-07-11 17:01:13 +0000337}
338
Chris Lattnerdf772332007-12-17 07:52:39 +0000339
Chris Lattnerafded5b2007-12-17 08:13:48 +0000340//===----------------------------------------------------------------------===//
341// Header File Location.
342//===----------------------------------------------------------------------===//
343
344
Reid Spencer5f016e22007-07-11 17:01:13 +0000345/// LookupFile - Given a "foo" or <foo> reference, look up the indicated file,
346/// return null on failure. isAngled indicates whether the file reference is
Douglas Gregor10fe93d2010-08-08 07:49:23 +0000347/// for system #include's or not (i.e. using <> instead of ""). CurFileEnt, if
348/// non-null, indicates where the #including file is, in case a relative search
349/// is needed.
Chandler Carruthb5142bb2011-03-16 18:34:36 +0000350const FileEntry *HeaderSearch::LookupFile(
Chris Lattner5f9e2722011-07-23 10:55:15 +0000351 StringRef Filename,
Chandler Carruthb5142bb2011-03-16 18:34:36 +0000352 bool isAngled,
353 const DirectoryLookup *FromDir,
354 const DirectoryLookup *&CurDir,
355 const FileEntry *CurFileEnt,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000356 SmallVectorImpl<char> *SearchPath,
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000357 SmallVectorImpl<char> *RelativePath,
358 StringRef *SuggestedModule)
359{
360 if (SuggestedModule)
361 *SuggestedModule = StringRef();
362
Reid Spencer5f016e22007-07-11 17:01:13 +0000363 // If 'Filename' is absolute, check to see if it exists and no searching.
Michael J. Spencer256053b2010-12-17 21:22:22 +0000364 if (llvm::sys::path::is_absolute(Filename)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000365 CurDir = 0;
366
367 // If this was an #include_next "/absolute/file", fail.
368 if (FromDir) return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000369
Manuel Klimek74124942011-04-26 21:50:03 +0000370 if (SearchPath != NULL)
371 SearchPath->clear();
372 if (RelativePath != NULL) {
373 RelativePath->clear();
374 RelativePath->append(Filename.begin(), Filename.end());
375 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000376 // Otherwise, just return the file.
Argyrios Kyrtzidis3cd01282011-03-16 19:17:25 +0000377 return FileMgr.getFile(Filename, /*openFile=*/true);
Reid Spencer5f016e22007-07-11 17:01:13 +0000378 }
Mike Stump1eb44332009-09-09 15:08:12 +0000379
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000380 // Unless disabled, check to see if the file is in the #includer's
Douglas Gregor10fe93d2010-08-08 07:49:23 +0000381 // directory. This has to be based on CurFileEnt, not CurDir, because
382 // CurFileEnt could be a #include of a subdirectory (#include "foo/bar.h") and
Chris Lattnerdf772332007-12-17 07:52:39 +0000383 // a subsequent include of "baz.h" should resolve to "whatever/foo/baz.h".
384 // This search is not done for <> headers.
Douglas Gregor10fe93d2010-08-08 07:49:23 +0000385 if (CurFileEnt && !isAngled && !NoCurDirSearch) {
386 llvm::SmallString<1024> TmpDir;
387 // Concatenate the requested file onto the directory.
388 // FIXME: Portability. Filename concatenation should be in sys::Path.
389 TmpDir += CurFileEnt->getDir()->getName();
390 TmpDir.push_back('/');
391 TmpDir.append(Filename.begin(), Filename.end());
Argyrios Kyrtzidis3cd01282011-03-16 19:17:25 +0000392 if (const FileEntry *FE = FileMgr.getFile(TmpDir.str(),/*openFile=*/true)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000393 // Leave CurDir unset.
Douglas Gregor10fe93d2010-08-08 07:49:23 +0000394 // This file is a system header or C++ unfriendly if the old file is.
395 //
396 // Note that the temporary 'DirInfo' is required here, as either call to
397 // getFileInfo could resize the vector and we don't want to rely on order
398 // of evaluation.
399 unsigned DirInfo = getFileInfo(CurFileEnt).DirInfo;
Chris Lattnerc9dde4f2008-02-25 21:38:21 +0000400 getFileInfo(FE).DirInfo = DirInfo;
Manuel Klimek74124942011-04-26 21:50:03 +0000401 if (SearchPath != NULL) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000402 StringRef SearchPathRef(CurFileEnt->getDir()->getName());
Manuel Klimek74124942011-04-26 21:50:03 +0000403 SearchPath->clear();
404 SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
405 }
406 if (RelativePath != NULL) {
407 RelativePath->clear();
408 RelativePath->append(Filename.begin(), Filename.end());
409 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000410 return FE;
411 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000412 }
Mike Stump1eb44332009-09-09 15:08:12 +0000413
Reid Spencer5f016e22007-07-11 17:01:13 +0000414 CurDir = 0;
415
416 // If this is a system #include, ignore the user #include locs.
Nico Weber74a5fd82011-05-24 04:31:14 +0000417 unsigned i = isAngled ? AngledDirIdx : 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000418
Reid Spencer5f016e22007-07-11 17:01:13 +0000419 // If this is a #include_next request, start searching after the directory the
420 // file was found in.
421 if (FromDir)
422 i = FromDir-&SearchDirs[0];
Mike Stump1eb44332009-09-09 15:08:12 +0000423
Chris Lattner9960ae82007-07-22 07:28:00 +0000424 // Cache all of the lookups performed by this method. Many headers are
425 // multiply included, and the "pragma once" optimization prevents them from
426 // being relex/pp'd, but they would still have to search through a
427 // (potentially huge) series of SearchDirs to find it.
428 std::pair<unsigned, unsigned> &CacheLookup =
Chris Lattnera1394812010-01-10 01:35:12 +0000429 LookupFileCache.GetOrCreateValue(Filename).getValue();
Chris Lattner9960ae82007-07-22 07:28:00 +0000430
431 // If the entry has been previously looked up, the first value will be
432 // non-zero. If the value is equal to i (the start point of our search), then
433 // this is a matching hit.
434 if (CacheLookup.first == i+1) {
435 // Skip querying potentially lots of directories for this lookup.
436 i = CacheLookup.second;
437 } else {
438 // Otherwise, this is the first query, or the previous query didn't match
439 // our search start. We will fill in our found location below, so prime the
440 // start point value.
441 CacheLookup.first = i+1;
442 }
Mike Stump1eb44332009-09-09 15:08:12 +0000443
Reid Spencer5f016e22007-07-11 17:01:13 +0000444 // Check each directory in sequence to see if it contains this file.
445 for (; i != SearchDirs.size(); ++i) {
Mike Stump1eb44332009-09-09 15:08:12 +0000446 const FileEntry *FE =
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000447 SearchDirs[i].LookupFile(Filename, *this, SearchPath, RelativePath,
448 BuildingModule, SuggestedModule);
Chris Lattnerafded5b2007-12-17 08:13:48 +0000449 if (!FE) continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000450
Chris Lattnerafded5b2007-12-17 08:13:48 +0000451 CurDir = &SearchDirs[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000452
Chris Lattnerafded5b2007-12-17 08:13:48 +0000453 // This file is a system header or C++ unfriendly if the dir is.
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000454 HeaderFileInfo &HFI = getFileInfo(FE);
455 HFI.DirInfo = CurDir->getDirCharacteristic();
Mike Stump1eb44332009-09-09 15:08:12 +0000456
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000457 // If this file is found in a header map and uses the framework style of
458 // includes, then this header is part of a framework we're building.
459 if (CurDir->isIndexHeaderMap()) {
460 size_t SlashPos = Filename.find('/');
461 if (SlashPos != StringRef::npos) {
462 HFI.IndexHeaderMapHeader = 1;
463 HFI.Framework = getUniqueFrameworkName(StringRef(Filename.begin(),
464 SlashPos));
465 }
466 }
467
Chris Lattnerafded5b2007-12-17 08:13:48 +0000468 // Remember this location for the next lookup we do.
469 CacheLookup.second = i;
470 return FE;
Reid Spencer5f016e22007-07-11 17:01:13 +0000471 }
Mike Stump1eb44332009-09-09 15:08:12 +0000472
Douglas Gregor2c7b7802011-07-30 06:28:34 +0000473 // If we are including a file with a quoted include "foo.h" from inside
474 // a header in a framework that is currently being built, and we couldn't
475 // resolve "foo.h" any other way, change the include to <Foo/foo.h>, where
476 // "Foo" is the name of the framework in which the including header was found.
477 if (CurFileEnt && !isAngled && Filename.find('/') == StringRef::npos) {
478 HeaderFileInfo &IncludingHFI = getFileInfo(CurFileEnt);
479 if (IncludingHFI.IndexHeaderMapHeader) {
480 llvm::SmallString<128> ScratchFilename;
481 ScratchFilename += IncludingHFI.Framework;
482 ScratchFilename += '/';
483 ScratchFilename += Filename;
484
485 const FileEntry *Result = LookupFile(ScratchFilename, /*isAngled=*/true,
486 FromDir, CurDir, CurFileEnt,
Douglas Gregorfba18aa2011-09-15 22:00:41 +0000487 SearchPath, RelativePath,
488 SuggestedModule);
Douglas Gregor2c7b7802011-07-30 06:28:34 +0000489 std::pair<unsigned, unsigned> &CacheLookup
490 = LookupFileCache.GetOrCreateValue(Filename).getValue();
491 CacheLookup.second
492 = LookupFileCache.GetOrCreateValue(ScratchFilename).getValue().second;
493 return Result;
494 }
495 }
496
Chris Lattner9960ae82007-07-22 07:28:00 +0000497 // Otherwise, didn't find it. Remember we didn't find this.
498 CacheLookup.second = SearchDirs.size();
Reid Spencer5f016e22007-07-11 17:01:13 +0000499 return 0;
500}
501
502/// LookupSubframeworkHeader - Look up a subframework for the specified
503/// #include file. For example, if #include'ing <HIToolbox/HIToolbox.h> from
504/// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox
505/// is a subframework within Carbon.framework. If so, return the FileEntry
506/// for the designated file, otherwise return null.
507const FileEntry *HeaderSearch::
Chris Lattner5f9e2722011-07-23 10:55:15 +0000508LookupSubframeworkHeader(StringRef Filename,
Chandler Carruthb5142bb2011-03-16 18:34:36 +0000509 const FileEntry *ContextFileEnt,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000510 SmallVectorImpl<char> *SearchPath,
511 SmallVectorImpl<char> *RelativePath) {
Chris Lattner9415a0c2008-02-01 05:34:02 +0000512 assert(ContextFileEnt && "No context file?");
Mike Stump1eb44332009-09-09 15:08:12 +0000513
Reid Spencer5f016e22007-07-11 17:01:13 +0000514 // Framework names must have a '/' in the filename. Find it.
Chris Lattnera1394812010-01-10 01:35:12 +0000515 size_t SlashPos = Filename.find('/');
Chris Lattner5f9e2722011-07-23 10:55:15 +0000516 if (SlashPos == StringRef::npos) return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000517
Reid Spencer5f016e22007-07-11 17:01:13 +0000518 // Look up the base framework name of the ContextFileEnt.
519 const char *ContextName = ContextFileEnt->getName();
Mike Stump1eb44332009-09-09 15:08:12 +0000520
Reid Spencer5f016e22007-07-11 17:01:13 +0000521 // If the context info wasn't a framework, couldn't be a subframework.
522 const char *FrameworkPos = strstr(ContextName, ".framework/");
523 if (FrameworkPos == 0)
524 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000525
526 llvm::SmallString<1024> FrameworkName(ContextName,
Reid Spencer5f016e22007-07-11 17:01:13 +0000527 FrameworkPos+strlen(".framework/"));
528
529 // Append Frameworks/HIToolbox.framework/
530 FrameworkName += "Frameworks/";
Chris Lattnera1394812010-01-10 01:35:12 +0000531 FrameworkName.append(Filename.begin(), Filename.begin()+SlashPos);
Reid Spencer5f016e22007-07-11 17:01:13 +0000532 FrameworkName += ".framework/";
533
534 llvm::StringMapEntry<const DirectoryEntry *> &CacheLookup =
Chris Lattner65382272010-11-21 09:55:08 +0000535 FrameworkMap.GetOrCreateValue(Filename.substr(0, SlashPos));
Mike Stump1eb44332009-09-09 15:08:12 +0000536
Reid Spencer5f016e22007-07-11 17:01:13 +0000537 // Some other location?
538 if (CacheLookup.getValue() &&
539 CacheLookup.getKeyLength() == FrameworkName.size() &&
540 memcmp(CacheLookup.getKeyData(), &FrameworkName[0],
541 CacheLookup.getKeyLength()) != 0)
542 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000543
Reid Spencer5f016e22007-07-11 17:01:13 +0000544 // Cache subframework.
545 if (CacheLookup.getValue() == 0) {
546 ++NumSubFrameworkLookups;
Mike Stump1eb44332009-09-09 15:08:12 +0000547
Reid Spencer5f016e22007-07-11 17:01:13 +0000548 // If the framework dir doesn't exist, we fail.
Chris Lattner39b49bc2010-11-23 08:35:12 +0000549 const DirectoryEntry *Dir = FileMgr.getDirectory(FrameworkName.str());
Reid Spencer5f016e22007-07-11 17:01:13 +0000550 if (Dir == 0) return 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000551
Reid Spencer5f016e22007-07-11 17:01:13 +0000552 // Otherwise, if it does, remember that this is the right direntry for this
553 // framework.
554 CacheLookup.setValue(Dir);
555 }
Mike Stump1eb44332009-09-09 15:08:12 +0000556
Reid Spencer5f016e22007-07-11 17:01:13 +0000557 const FileEntry *FE = 0;
558
Manuel Klimek74124942011-04-26 21:50:03 +0000559 if (RelativePath != NULL) {
560 RelativePath->clear();
561 RelativePath->append(Filename.begin()+SlashPos+1, Filename.end());
562 }
563
Reid Spencer5f016e22007-07-11 17:01:13 +0000564 // Check ".../Frameworks/HIToolbox.framework/Headers/HIToolbox.h"
565 llvm::SmallString<1024> HeadersFilename(FrameworkName);
566 HeadersFilename += "Headers/";
Manuel Klimek74124942011-04-26 21:50:03 +0000567 if (SearchPath != NULL) {
568 SearchPath->clear();
569 // Without trailing '/'.
570 SearchPath->append(HeadersFilename.begin(), HeadersFilename.end()-1);
571 }
572
Chris Lattnera1394812010-01-10 01:35:12 +0000573 HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end());
Argyrios Kyrtzidis3cd01282011-03-16 19:17:25 +0000574 if (!(FE = FileMgr.getFile(HeadersFilename.str(), /*openFile=*/true))) {
Mike Stump1eb44332009-09-09 15:08:12 +0000575
Reid Spencer5f016e22007-07-11 17:01:13 +0000576 // Check ".../Frameworks/HIToolbox.framework/PrivateHeaders/HIToolbox.h"
577 HeadersFilename = FrameworkName;
578 HeadersFilename += "PrivateHeaders/";
Manuel Klimek74124942011-04-26 21:50:03 +0000579 if (SearchPath != NULL) {
580 SearchPath->clear();
581 // Without trailing '/'.
582 SearchPath->append(HeadersFilename.begin(), HeadersFilename.end()-1);
583 }
584
Chris Lattnera1394812010-01-10 01:35:12 +0000585 HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end());
Argyrios Kyrtzidis3cd01282011-03-16 19:17:25 +0000586 if (!(FE = FileMgr.getFile(HeadersFilename.str(), /*openFile=*/true)))
Reid Spencer5f016e22007-07-11 17:01:13 +0000587 return 0;
588 }
Mike Stump1eb44332009-09-09 15:08:12 +0000589
Reid Spencer5f016e22007-07-11 17:01:13 +0000590 // This file is a system header or C++ unfriendly if the old file is.
Ted Kremenekca63fa02008-02-24 03:55:14 +0000591 //
Chris Lattnerc9dde4f2008-02-25 21:38:21 +0000592 // Note that the temporary 'DirInfo' is required here, as either call to
593 // getFileInfo could resize the vector and we don't want to rely on order
594 // of evaluation.
595 unsigned DirInfo = getFileInfo(ContextFileEnt).DirInfo;
596 getFileInfo(FE).DirInfo = DirInfo;
Reid Spencer5f016e22007-07-11 17:01:13 +0000597 return FE;
598}
599
600//===----------------------------------------------------------------------===//
601// File Info Management.
602//===----------------------------------------------------------------------===//
603
Douglas Gregor8f8d5812011-09-17 05:35:18 +0000604/// \brief Merge the header file info provided by \p OtherHFI into the current
605/// header file info (\p HFI)
606static void mergeHeaderFileInfo(HeaderFileInfo &HFI,
607 const HeaderFileInfo &OtherHFI) {
608 HFI.isImport |= OtherHFI.isImport;
609 HFI.isPragmaOnce |= OtherHFI.isPragmaOnce;
610 HFI.NumIncludes += OtherHFI.NumIncludes;
611
612 if (!HFI.ControllingMacro && !HFI.ControllingMacroID) {
613 HFI.ControllingMacro = OtherHFI.ControllingMacro;
614 HFI.ControllingMacroID = OtherHFI.ControllingMacroID;
615 }
616
617 if (OtherHFI.External) {
618 HFI.DirInfo = OtherHFI.DirInfo;
619 HFI.External = OtherHFI.External;
620 HFI.IndexHeaderMapHeader = OtherHFI.IndexHeaderMapHeader;
621 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000622
Douglas Gregor8f8d5812011-09-17 05:35:18 +0000623 if (HFI.Framework.empty())
624 HFI.Framework = OtherHFI.Framework;
625
626 HFI.Resolved = true;
627}
628
Steve Naroff83d63c72009-04-24 20:03:17 +0000629/// getFileInfo - Return the HeaderFileInfo structure for the specified
Reid Spencer5f016e22007-07-11 17:01:13 +0000630/// FileEntry.
Steve Naroff83d63c72009-04-24 20:03:17 +0000631HeaderFileInfo &HeaderSearch::getFileInfo(const FileEntry *FE) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000632 if (FE->getUID() >= FileInfo.size())
633 FileInfo.resize(FE->getUID()+1);
Douglas Gregorcfbf1c72011-02-10 17:09:37 +0000634
635 HeaderFileInfo &HFI = FileInfo[FE->getUID()];
Douglas Gregor8f8d5812011-09-17 05:35:18 +0000636 if (ExternalSource && !HFI.Resolved)
637 mergeHeaderFileInfo(HFI, ExternalSource->GetHeaderFileInfo(FE));
Douglas Gregorcfbf1c72011-02-10 17:09:37 +0000638 return HFI;
Mike Stump1eb44332009-09-09 15:08:12 +0000639}
Reid Spencer5f016e22007-07-11 17:01:13 +0000640
Douglas Gregordd3e5542011-05-04 00:14:37 +0000641bool HeaderSearch::isFileMultipleIncludeGuarded(const FileEntry *File) {
642 // Check if we've ever seen this file as a header.
643 if (File->getUID() >= FileInfo.size())
644 return false;
645
646 // Resolve header file info from the external source, if needed.
647 HeaderFileInfo &HFI = FileInfo[File->getUID()];
Douglas Gregor8f8d5812011-09-17 05:35:18 +0000648 if (ExternalSource && !HFI.Resolved)
649 mergeHeaderFileInfo(HFI, ExternalSource->GetHeaderFileInfo(File));
Douglas Gregordd3e5542011-05-04 00:14:37 +0000650
651 return HFI.isPragmaOnce || HFI.ControllingMacro || HFI.ControllingMacroID;
652}
653
Steve Naroff83d63c72009-04-24 20:03:17 +0000654void HeaderSearch::setHeaderFileInfoForUID(HeaderFileInfo HFI, unsigned UID) {
655 if (UID >= FileInfo.size())
656 FileInfo.resize(UID+1);
Douglas Gregorcfbf1c72011-02-10 17:09:37 +0000657 HFI.Resolved = true;
Steve Naroff83d63c72009-04-24 20:03:17 +0000658 FileInfo[UID] = HFI;
659}
660
Reid Spencer5f016e22007-07-11 17:01:13 +0000661/// ShouldEnterIncludeFile - Mark the specified file as a target of of a
662/// #include, #include_next, or #import directive. Return false if #including
663/// the file will have no effect or true if we should include it.
664bool HeaderSearch::ShouldEnterIncludeFile(const FileEntry *File, bool isImport){
665 ++NumIncluded; // Count # of attempted #includes.
666
667 // Get information about this file.
Steve Naroff83d63c72009-04-24 20:03:17 +0000668 HeaderFileInfo &FileInfo = getFileInfo(File);
Mike Stump1eb44332009-09-09 15:08:12 +0000669
Reid Spencer5f016e22007-07-11 17:01:13 +0000670 // If this is a #import directive, check that we have not already imported
671 // this header.
672 if (isImport) {
673 // If this has already been imported, don't import it again.
674 FileInfo.isImport = true;
Mike Stump1eb44332009-09-09 15:08:12 +0000675
Reid Spencer5f016e22007-07-11 17:01:13 +0000676 // Has this already been #import'ed or #include'd?
677 if (FileInfo.NumIncludes) return false;
678 } else {
679 // Otherwise, if this is a #include of a file that was previously #import'd
680 // or if this is the second #include of a #pragma once file, ignore it.
681 if (FileInfo.isImport)
682 return false;
683 }
Mike Stump1eb44332009-09-09 15:08:12 +0000684
Reid Spencer5f016e22007-07-11 17:01:13 +0000685 // Next, check to see if the file is wrapped with #ifndef guards. If so, and
686 // if the macro that guards it is defined, we know the #include has no effect.
Mike Stump1eb44332009-09-09 15:08:12 +0000687 if (const IdentifierInfo *ControllingMacro
Douglas Gregor8c5a7602009-04-25 23:30:02 +0000688 = FileInfo.getControllingMacro(ExternalLookup))
689 if (ControllingMacro->hasMacroDefinition()) {
690 ++NumMultiIncludeFileOptzn;
691 return false;
692 }
Mike Stump1eb44332009-09-09 15:08:12 +0000693
Reid Spencer5f016e22007-07-11 17:01:13 +0000694 // Increment the number of times this file has been included.
695 ++FileInfo.NumIncludes;
Mike Stump1eb44332009-09-09 15:08:12 +0000696
Reid Spencer5f016e22007-07-11 17:01:13 +0000697 return true;
698}
699
Ted Kremenekd1194fb2011-07-26 23:46:11 +0000700size_t HeaderSearch::getTotalMemory() const {
701 return SearchDirs.capacity()
Ted Kremenekeabea452011-07-27 18:41:18 +0000702 + llvm::capacity_in_bytes(FileInfo)
703 + llvm::capacity_in_bytes(HeaderMaps)
Ted Kremenekd1194fb2011-07-26 23:46:11 +0000704 + LookupFileCache.getAllocator().getTotalMemory()
705 + FrameworkMap.getAllocator().getTotalMemory();
706}
Douglas Gregor65e02fa2011-07-28 04:45:53 +0000707
708StringRef HeaderSearch::getUniqueFrameworkName(StringRef Framework) {
709 return FrameworkNames.GetOrCreateValue(Framework).getKey();
710}
Douglas Gregora30cfe52011-11-11 19:10:28 +0000711
712bool HeaderSearch::hasModuleMap(StringRef FileName,
713 const DirectoryEntry *Root) {
714 llvm::SmallVector<const DirectoryEntry *, 2> FixUpDirectories;
715
716 StringRef DirName = FileName;
717 do {
718 // Get the parent directory name.
719 DirName = llvm::sys::path::parent_path(DirName);
720 if (DirName.empty())
721 return false;
722
723 // Determine whether this directory exists.
724 const DirectoryEntry *Dir = FileMgr.getDirectory(DirName);
725 if (!Dir)
726 return false;
727
728 llvm::DenseMap<const DirectoryEntry *, bool>::iterator
729 KnownDir = DirectoryHasModuleMap.find(Dir);
730 if (KnownDir != DirectoryHasModuleMap.end()) {
731 // We have seen this directory before. If it has no module map file,
732 // we're done.
733 if (!KnownDir->second)
734 return false;
735
736 // All of the directories we stepped through inherit this module map
737 // file.
738 for (unsigned I = 0, N = FixUpDirectories.size(); I != N; ++I)
739 DirectoryHasModuleMap[FixUpDirectories[I]] = true;
740
741 return true;
742 }
743
744 // We have not checked for a module map file in this directory yet;
745 // do so now.
746 llvm::SmallString<128> ModuleMapFileName;
747 ModuleMapFileName += Dir->getName();
748 llvm::sys::path::append(ModuleMapFileName, "module.map");
749 if (const FileEntry *ModuleMapFile = FileMgr.getFile(ModuleMapFileName)) {
750 // We have found a module map file. Try to parse it.
751 if (!ModMap.parseModuleMapFile(ModuleMapFile)) {
752 // This directory has a module map.
753 DirectoryHasModuleMap[Dir] = true;
754
755 // All of the directories we stepped through inherit this module map
756 // file.
757 for (unsigned I = 0, N = FixUpDirectories.size(); I != N; ++I)
758 DirectoryHasModuleMap[FixUpDirectories[I]] = true;
759
760 return true;
761 }
762 }
763
764 // This directory did not have a module map file.
765 DirectoryHasModuleMap[Dir] = false;
766
767 // Keep track of all of the directories we checked, so we can mark them as
768 // having module maps if we eventually do find a module map.
769 FixUpDirectories.push_back(Dir);
770 } while (true);
771
772 return false;
773}
774
775StringRef HeaderSearch::getModuleForHeader(const FileEntry *File) {
776 // FIXME: Actually look for the corresponding module for this header.
777 return StringRef();
778}
779
780