Hoist ASTDumpMemberLoading choice up to the frontend call sites.

This commit is contained in:
Tony Allevato
2025-02-03 11:37:47 -05:00
parent 237e79a467
commit 0d9467e688
3 changed files with 15 additions and 11 deletions

View File

@@ -464,20 +464,21 @@ getPrimaryOrMainSourceFile(const CompilerInstance &Instance) {
/// Dumps the AST of all available primary source files. If corresponding output
/// files were specified, use them; otherwise, dump the AST to stdout.
static bool dumpAST(CompilerInstance &Instance) {
static bool dumpAST(CompilerInstance &Instance,
ASTDumpMemberLoading memberLoading) {
const FrontendOptions &opts = Instance.getInvocation().getFrontendOptions();
auto dumpAST = [&](SourceFile *SF, raw_ostream &out) {
switch (opts.DumpASTFormat) {
case FrontendOptions::ASTFormat::Default:
SF->dump(out, ASTDumpMemberLoading::Parsed);
SF->dump(out, memberLoading);
break;
case FrontendOptions::ASTFormat::JSON:
SF->dumpJSON(out);
SF->dumpJSON(out, memberLoading);
break;
case FrontendOptions::ASTFormat::JSONZlib:
std::string jsonText;
llvm::raw_string_ostream jsonTextStream(jsonText);
SF->dumpJSON(jsonTextStream);
SF->dumpJSON(jsonTextStream, memberLoading);
SmallVector<uint8_t, 0> compressed;
llvm::compression::zlib::compress(llvm::arrayRefFromStringRef(jsonText),
@@ -1233,12 +1234,14 @@ static bool performAction(CompilerInstance &Instance,
// MARK: Actions that Dump
case FrontendOptions::ActionType::DumpParse:
return dumpAST(Instance);
return dumpAST(Instance, ASTDumpMemberLoading::Parsed);
case FrontendOptions::ActionType::DumpAST:
return withSemanticAnalysis(
Instance, observer, [](CompilerInstance &Instance) {
return dumpAST(Instance);
}, /*runDespiteErrors=*/true);
Instance, observer,
[](CompilerInstance &Instance) {
return dumpAST(Instance, ASTDumpMemberLoading::TypeChecked);
},
/*runDespiteErrors=*/true);
case FrontendOptions::ActionType::PrintAST:
return withSemanticAnalysis(
Instance, observer, [](CompilerInstance &Instance) {