Skip to content

Commit a3fdbdc

Browse files
committed
[clang][include-tree] Extract error handling
1 parent a6ad865 commit a3fdbdc

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

clang/lib/Lex/PPDirectives.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,18 +2020,23 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
20202020
}
20212021
};
20222022

2023+
auto CheckLoadResult = [&](ModuleLoadResult Result) {
2024+
if (Result)
2025+
return true;
2026+
assert(hadModuleLoaderFatalFailure() && "unexpected failure kind");
2027+
if (hadModuleLoaderFatalFailure()) {
2028+
IncludeTok.setKind(tok::eof);
2029+
CurLexer->cutOffLexing();
2030+
}
2031+
return false;
2032+
};
2033+
20232034
auto LoadModule = [&](const PPCachedActions::IncludeModule *Import) {
20242035
auto Imported = TheModuleLoader.loadModule(
20252036
IncludeTok.getLocation(), ArrayRef(Import->ImportPath).take_front(),
20262037
Module::Hidden, /*IsInclusionDirective=*/true);
2027-
if (!Imported) {
2028-
assert(hadModuleLoaderFatalFailure() && "unexpected failure kind");
2029-
if (hadModuleLoaderFatalFailure()) {
2030-
IncludeTok.setKind(tok::eof);
2031-
CurLexer->cutOffLexing();
2032-
}
2038+
if (!CheckLoadResult(Imported))
20332039
return;
2034-
}
20352040

20362041
auto Path = Import->ImportPath;
20372042
std::string PathStr = Path.front().first->getName().str();
@@ -2064,14 +2069,8 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
20642069
Imported = TheModuleLoader.loadModule(
20652070
IncludeTok.getLocation(), Import->ImportPath, Module::Hidden,
20662071
/*IsIncludeDirective=*/true);
2067-
if (!Imported) {
2068-
assert(hadModuleLoaderFatalFailure() && "unexpected failure kind");
2069-
if (hadModuleLoaderFatalFailure()) {
2070-
IncludeTok.setKind(tok::eof);
2071-
CurLexer->cutOffLexing();
2072-
}
2072+
if (!CheckLoadResult(Imported))
20732073
return;
2074-
}
20752074
}
20762075

20772076
makeModuleVisible(Imported, EndLoc);

0 commit comments

Comments
 (0)