Skip to content

Commit dcb753a

Browse files
Skip verbose AST dumps when logging is disabled
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
1 parent 8f2e062 commit dcb753a

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ bool Converter::VisitTranslationUnitDecl(clang::TranslationUnitDecl *decl) {
412412
return false;
413413
}
414414

415+
static void DumpVerbose(const clang::Decl *decl) {
416+
if (auto &out = log(); &out != &llvm::nulls()) {
417+
decl->dump(out);
418+
}
419+
}
420+
415421
bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) {
416422
if (auto method = clang::dyn_cast<clang::CXXMethodDecl>(decl)) {
417423
return VisitCXXMethodDecl(method);
@@ -422,7 +428,7 @@ bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) {
422428
if (!IsInMainFile(decl) && !decl_ids_.insert(GetID(decl)).second) {
423429
return false;
424430
}
425-
decl->dump(log());
431+
DumpVerbose(decl);
426432
ScopedValue push_fn(curr_function_, decl);
427433
std::string function_name;
428434
if (decl->isMain()) {
@@ -861,7 +867,7 @@ bool Converter::RecordHasCopyableFields(const clang::RecordDecl *decl) {
861867
}
862868

863869
bool Converter::VisitRecordDecl(clang::RecordDecl *decl) {
864-
decl->dump(log());
870+
DumpVerbose(decl);
865871

866872
// VisitCXXRecordDecl already visited the record
867873
if (clang::isa<clang::CXXRecordDecl>(decl)) {
@@ -1094,7 +1100,7 @@ void Converter::EmitRustUnion(clang::RecordDecl *decl) {
10941100
}
10951101

10961102
bool Converter::VisitCXXRecordDecl(clang::CXXRecordDecl *decl) {
1097-
decl->dump(log());
1103+
DumpVerbose(decl);
10981104

10991105
if (!IsConvertibleCXXRecordDecl(decl)) {
11001106
return false;
@@ -1137,7 +1143,7 @@ bool Converter::VisitCXXRecordDecl(clang::CXXRecordDecl *decl) {
11371143
}
11381144

11391145
bool Converter::VisitCXXMethodDecl(clang::CXXMethodDecl *decl) {
1140-
decl->dump(log());
1146+
DumpVerbose(decl);
11411147
if (!ShouldConvertMethod(decl)) {
11421148
return false;
11431149
}

0 commit comments

Comments
 (0)