Skip to content

Commit 446cd7b

Browse files
Merge pull request #6472 from adrian-prantl/log-expr
Fix logging of typechecked AST.
2 parents 1462210 + 2dbbf94 commit 446cd7b

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ static void AddNodesToBeginningFunction(
972972
body->getRBraceLoc());
973973

974974
function->setBody(new_function_body, function->getBodyKind());
975+
function->setHasSingleExpressionBody(false);
975976
}
976977

977978
bool SwiftASTManipulator::AddExternalVariables(
@@ -1081,9 +1082,10 @@ bool SwiftASTManipulator::AddExternalVariables(
10811082
variable.m_decl->dump(ss);
10821083
ss.flush();
10831084

1084-
log->Printf("[SwiftASTManipulator::AddExternalVariables] Injected "
1085-
"variable %s",
1086-
s.c_str());
1085+
LLDB_LOG(log,
1086+
"[SwiftASTManipulator::AddExternalVariables] Injected "
1087+
"variable {0} into {1}",
1088+
s, containing_function->getName().getBaseIdentifier().str());
10871089
}
10881090

10891091
m_variables.push_back(variable);

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,36 +1710,30 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
17101710
return ParseResult::unrecoverable_error;
17111711
}
17121712

1713-
if (log) {
1713+
auto dumpModule = [&](const char *msg) {
17141714
std::string s;
17151715
llvm::raw_string_ostream ss(s);
17161716
parsed_expr->source_file.dump(ss);
17171717
ss.flush();
1718+
LLDB_LOG(log, "\n{0}\n\n{1}\n", msg, s);
1719+
};
17181720

1719-
log->Printf("Source file before type checking:");
1720-
log->PutCString(s.c_str());
1721-
}
1721+
if (log)
1722+
dumpModule("Module before type checking:");
17221723

17231724
swift::bindExtensions(parsed_expr->module);
17241725
swift::performTypeChecking(parsed_expr->source_file);
17251726

1727+
if (log)
1728+
dumpModule("Module after type checking:");
1729+
17261730
if (m_swift_ast_ctx.HasErrors()) {
17271731
DiagnoseSwiftASTContextError();
17281732
return ParseResult::unrecoverable_error;
17291733
}
1730-
if (log) {
1731-
std::string s;
1732-
llvm::raw_string_ostream ss(s);
1733-
parsed_expr->source_file.dump(ss);
1734-
ss.flush();
17351734

1736-
log->Printf("Source file after type checking:");
1737-
log->PutCString(s.c_str());
1738-
}
1739-
1740-
if (repl) {
1735+
if (repl)
17411736
parsed_expr->code_manipulator->MakeDeclarationsPublic();
1742-
}
17431737

17441738
Status error;
17451739
if (!playground) {

0 commit comments

Comments
 (0)