Skip to content

Commit fb15513

Browse files
committed
[Sema][NFC] Refactor the logic matching paths in the SDK
1 parent d78d1eb commit fb15513

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/AST/Module.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,17 +2629,24 @@ LibraryLevel
26292629
ModuleLibraryLevelRequest::evaluate(Evaluator &evaluator,
26302630
const ModuleDecl *module) const {
26312631
auto &ctx = module->getASTContext();
2632+
namespace path = llvm::sys::path;
2633+
SmallString<128> scratch;
2634+
2635+
/// Is \p path under the folder SDK/a/b/c/d/e?
2636+
auto hasSDKPrefix =
2637+
[&](StringRef path, const Twine &a, const Twine &b = "",
2638+
const Twine &c = "", const Twine &d = "", const Twine &e = "") {
2639+
scratch = ctx.SearchPathOpts.getSDKPath();
2640+
path::append(scratch, a, b, c, d);
2641+
path::append(scratch, e);
2642+
return path.startswith(scratch);
2643+
};
26322644

26332645
/// Is \p modulePath from System/Library/PrivateFrameworks/?
26342646
auto fromPrivateFrameworks = [&](StringRef modulePath) -> bool {
26352647
if (!ctx.LangOpts.Target.isOSDarwin()) return false;
26362648

2637-
namespace path = llvm::sys::path;
2638-
SmallString<128> scratch;
2639-
scratch = ctx.SearchPathOpts.getSDKPath();
2640-
path::append(scratch, "System", "Library", "PrivateFrameworks");
2641-
return hasPrefix(path::begin(modulePath), path::end(modulePath),
2642-
path::begin(scratch), path::end(scratch));
2649+
return hasSDKPrefix(modulePath, "System", "Library", "PrivateFrameworks");
26432650
};
26442651

26452652
if (module->isNonSwiftModule()) {

0 commit comments

Comments
 (0)