@@ -183,13 +183,6 @@ const Decl *getRefContainer(const Decl *Enclosing,
183
183
// including filename normalization, URI conversion etc.
184
184
// Expensive checks are cached internally.
185
185
class SymbolCollector ::HeaderFileURICache {
186
- struct FrameworkUmbrellaSpelling {
187
- // Spelling for the public umbrella header, e.g. <Foundation/Foundation.h>
188
- llvm::Optional<std::string> PublicHeader;
189
- // Spelling for the private umbrella header, e.g.
190
- // <Foundation/Foundation_Private.h>
191
- llvm::Optional<std::string> PrivateHeader;
192
- };
193
186
// Weird double-indirect access to PP, which might not be ready yet when
194
187
// HeaderFiles is created but will be by the time it's used.
195
188
// (IndexDataConsumer::setPreprocessor can happen before or after initialize)
@@ -200,9 +193,6 @@ class SymbolCollector::HeaderFileURICache {
200
193
llvm::DenseMap<const FileEntry *, const std::string *> CacheFEToURI;
201
194
llvm::StringMap<std::string> CachePathToURI;
202
195
llvm::DenseMap<FileID, llvm::StringRef> CacheFIDToInclude;
203
- llvm::StringMap<std::string> CachePathToFrameworkSpelling;
204
- llvm::StringMap<FrameworkUmbrellaSpelling>
205
- CacheFrameworkToUmbrellaHeaderSpelling;
206
196
207
197
public:
208
198
HeaderFileURICache (Preprocessor *&PP, const SourceManager &SM,
@@ -259,125 +249,6 @@ class SymbolCollector::HeaderFileURICache {
259
249
return R.first ->second ;
260
250
}
261
251
262
- struct FrameworkHeaderPath {
263
- // Path to the framework directory containing the Headers/PrivateHeaders
264
- // directories e.g. /Frameworks/Foundation.framework/
265
- llvm::StringRef HeadersParentDir;
266
- // Subpath relative to the Headers or PrivateHeaders dir, e.g. NSObject.h
267
- // Note: This is NOT relative to the `HeadersParentDir`.
268
- llvm::StringRef HeaderSubpath;
269
- // Whether this header is under the PrivateHeaders dir
270
- bool IsPrivateHeader;
271
- };
272
-
273
- llvm::Optional<FrameworkHeaderPath>
274
- splitFrameworkHeaderPath (llvm::StringRef Path) {
275
- using namespace llvm ::sys;
276
- path::reverse_iterator I = path::rbegin (Path);
277
- path::reverse_iterator Prev = I;
278
- path::reverse_iterator E = path::rend (Path);
279
- while (I != E) {
280
- if (*I == " Headers" ) {
281
- FrameworkHeaderPath HeaderPath;
282
- HeaderPath.HeadersParentDir = Path.substr (0 , I - E);
283
- HeaderPath.HeaderSubpath = Path.substr (Prev - E);
284
- return HeaderPath;
285
- }
286
- if (*I == " PrivateHeaders" ) {
287
- FrameworkHeaderPath HeaderPath;
288
- HeaderPath.HeadersParentDir = Path.substr (0 , I - E);
289
- HeaderPath.HeaderSubpath = Path.substr (Prev - E);
290
- HeaderPath.IsPrivateHeader = true ;
291
- return HeaderPath;
292
- }
293
- Prev = I;
294
- ++I;
295
- }
296
- // Unexpected, must not be a framework header.
297
- return llvm::None;
298
- }
299
-
300
- // Frameworks typically have an umbrella header of the same name, e.g.
301
- // <Foundation/Foundation.h> instead of <Foundation/NSObject.h> or
302
- // <Foundation/Foundation_Private.h> instead of
303
- // <Foundation/NSObject_Private.h> which should be used instead of directly
304
- // importing the header.
305
- llvm::Optional<std::string> getFrameworkUmbrellaSpelling (
306
- llvm::StringRef Framework, SrcMgr::CharacteristicKind HeadersDirKind,
307
- HeaderSearch &HS, FrameworkHeaderPath &HeaderPath) {
308
- auto Res = CacheFrameworkToUmbrellaHeaderSpelling.try_emplace (Framework);
309
- auto *CachedSpelling = &Res.first ->second ;
310
- if (!Res.second ) {
311
- return HeaderPath.IsPrivateHeader ? CachedSpelling->PrivateHeader
312
- : CachedSpelling->PublicHeader ;
313
- }
314
- bool IsSystem = isSystem (HeadersDirKind);
315
- SmallString<256 > UmbrellaPath (HeaderPath.HeadersParentDir );
316
- llvm::sys::path::append (UmbrellaPath, " Headers" , Framework + " .h" );
317
-
318
- llvm::vfs::Status Status;
319
- auto StatErr = HS.getFileMgr ().getNoncachedStatValue (UmbrellaPath, Status);
320
- if (!StatErr) {
321
- if (IsSystem)
322
- CachedSpelling->PublicHeader = llvm::formatv (" <{0}/{0}.h>" , Framework);
323
- else
324
- CachedSpelling->PublicHeader =
325
- llvm::formatv (" \" {0}/{0}.h\" " , Framework);
326
- }
327
-
328
- UmbrellaPath = HeaderPath.HeadersParentDir ;
329
- llvm::sys::path::append (UmbrellaPath, " PrivateHeaders" ,
330
- Framework + " _Private.h" );
331
-
332
- StatErr = HS.getFileMgr ().getNoncachedStatValue (UmbrellaPath, Status);
333
- if (!StatErr) {
334
- if (IsSystem)
335
- CachedSpelling->PrivateHeader =
336
- llvm::formatv (" <{0}/{0}_Private.h>" , Framework);
337
- else
338
- CachedSpelling->PrivateHeader =
339
- llvm::formatv (" \" {0}/{0}_Private.h\" " , Framework);
340
- }
341
- return HeaderPath.IsPrivateHeader ? CachedSpelling->PrivateHeader
342
- : CachedSpelling->PublicHeader ;
343
- }
344
-
345
- // Compute the framework include spelling for `FE` which is in a framework
346
- // named `Framework`, e.g. `NSObject.h` in framework `Foundation` would
347
- // give <Foundation/Foundation.h> if the umbrella header exists, otherwise
348
- // <Foundation/NSObject.h>.
349
- llvm::Optional<llvm::StringRef> getFrameworkHeaderIncludeSpelling (
350
- const FileEntry *FE, llvm::StringRef Framework, HeaderSearch &HS) {
351
- auto Res = CachePathToFrameworkSpelling.try_emplace (FE->getName ());
352
- auto *CachedHeaderSpelling = &Res.first ->second ;
353
- if (!Res.second )
354
- return llvm::StringRef (*CachedHeaderSpelling);
355
-
356
- auto HeaderPath = splitFrameworkHeaderPath (FE->getName ());
357
- if (!HeaderPath) {
358
- // Unexpected: must not be a proper framework header, don't cache the
359
- // failure.
360
- CachePathToFrameworkSpelling.erase (Res.first );
361
- return llvm::None;
362
- }
363
- auto DirKind = HS.getFileDirFlavor (FE);
364
- if (auto UmbrellaSpelling =
365
- getFrameworkUmbrellaSpelling (Framework, DirKind, HS, *HeaderPath)) {
366
- *CachedHeaderSpelling = *UmbrellaSpelling;
367
- return llvm::StringRef (*CachedHeaderSpelling);
368
- }
369
-
370
- if (isSystem (DirKind))
371
- *CachedHeaderSpelling =
372
- llvm::formatv (" <{0}/{1}>" , Framework, HeaderPath->HeaderSubpath )
373
- .str ();
374
- else
375
- *CachedHeaderSpelling =
376
- llvm::formatv (" \" {0}/{1}\" " , Framework, HeaderPath->HeaderSubpath )
377
- .str ();
378
- return llvm::StringRef (*CachedHeaderSpelling);
379
- }
380
-
381
252
llvm::StringRef getIncludeHeaderUncached (FileID FID) {
382
253
const FileEntry *FE = SM.getFileEntryForID (FID);
383
254
if (!FE || FE->getName ().empty ())
@@ -394,15 +265,6 @@ class SymbolCollector::HeaderFileURICache {
394
265
return toURI (Canonical);
395
266
}
396
267
}
397
- // Framework headers are spelled as <FrameworkName/Foo.h>, not
398
- // "path/FrameworkName.framework/Headers/Foo.h".
399
- auto &HS = PP->getHeaderSearchInfo ();
400
- if (const auto *HFI = HS.getExistingFileInfo (FE, /* WantExternal*/ false ))
401
- if (!HFI->Framework .empty ())
402
- if (auto Spelling =
403
- getFrameworkHeaderIncludeSpelling (FE, HFI->Framework , HS))
404
- return *Spelling;
405
-
406
268
if (!isSelfContainedHeader (FE, FID, PP->getSourceManager (),
407
269
PP->getHeaderSearchInfo ())) {
408
270
// A .inc or .def file is often included into a real header to define
0 commit comments