Skip to content

Commit e753578

Browse files
committed
Disable verbose logging by default
1 parent eddc30e commit e753578

10 files changed

Lines changed: 103 additions & 94 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "converter/converter_lib.h"
1515
#include "converter/lex.h"
1616
#include "converter/mapper.h"
17+
#include "logging.h"
1718

1819
namespace cpp2rust {
1920
std::unordered_map<std::string, std::string> Converter::inner_structs_;
@@ -52,8 +53,8 @@ use std::rc::Rc;
5253
}
5354

5455
bool Converter::VisitRecoveryExpr(clang::RecoveryExpr *expr) {
55-
llvm::errs() << "RecoveryExpr: ";
56-
expr->dump();
56+
verrs() << "RecoveryExpr: ";
57+
expr->dump(verrs(), ctx_);
5758
exit(1);
5859
return false;
5960
}
@@ -122,7 +123,7 @@ bool Converter::VisitBuiltinType(clang::BuiltinType *type) {
122123
break;
123124
default:
124125
// FIXME: improve error handling
125-
llvm::errs() << "unsupported builtin type\n";
126+
verrs() << "unsupported builtin type\n";
126127
break;
127128
}
128129
return false;
@@ -151,7 +152,7 @@ bool Converter::VisitRecordType(clang::RecordType *type) {
151152
}
152153

153154
std::string Converter::ConvertPointer(clang::Expr *expr, int line) {
154-
llvm::errs() << "ConvertPointer called from line " << line << "\n";
155+
verrs() << "ConvertPointer called from line " << line << "\n";
155156
PushExprKind push(*this, ExprKind::AddrOf);
156157
return ToString(expr);
157158
}
@@ -175,7 +176,7 @@ std::string Converter::ConvertLValue(clang::Expr *expr) {
175176
}
176177

177178
std::string Converter::ConvertRValue(clang::Expr *expr, int line) {
178-
llvm::errs() << "ConvertRValue called from line " << line << "\n";
179+
verrs() << "ConvertRValue called from line " << line << "\n";
179180
PushExprKind push(*this, ExprKind::RValue);
180181
return ToString(expr);
181182
}
@@ -295,7 +296,7 @@ bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) {
295296
if (!IsInMainFile(decl) && !decl_ids_.insert(GetID(decl)).second) {
296297
return false;
297298
}
298-
decl->dump();
299+
decl->dump(verrs());
299300
curr_function_ = decl;
300301
std::string function_name;
301302
if (decl->isMain()) {
@@ -582,7 +583,7 @@ static bool recordDerivesCopy(const clang::RecordDecl *decl) {
582583
}
583584

584585
bool Converter::VisitRecordDecl(clang::RecordDecl *decl) {
585-
decl->dumpColor();
586+
decl->dump(verrs());
586587

587588
// VisitCXXRecordDecl already visited the record
588589
if (clang::isa<clang::CXXRecordDecl>(decl)) {
@@ -694,7 +695,7 @@ bool Converter::VisitCXXRecordDecl(clang::CXXRecordDecl *decl) {
694695
materializeTemplateSpecialization(decl);
695696
}
696697

697-
decl->dump();
698+
decl->dump(verrs());
698699

699700
Mapper::AddRuleForUserDefinedType(decl);
700701
if (!IsConvertibleCXXRecordDecl(decl)) {
@@ -741,7 +742,7 @@ bool Converter::VisitCXXRecordDecl(clang::CXXRecordDecl *decl) {
741742
}
742743

743744
bool Converter::VisitCXXMethodDecl(clang::CXXMethodDecl *decl) {
744-
decl->dump();
745+
decl->dump(verrs());
745746
if (!IsConvertibleCXXMethodDecl(decl)) {
746747
return false;
747748
}
@@ -1085,10 +1086,10 @@ bool Converter::VisitCXXForRangeStmt(clang::CXXForRangeStmt *stmt) {
10851086

10861087
if (!Mapper::Contains(range_init_type.getUnqualifiedType())) {
10871088
// FIXME: improve error handling
1088-
llvm::errs() << "for range stmts only for types in std namespace\n";
1089+
verrs() << "for range stmts only for types in std namespace\n";
10891090
}
10901091

1091-
llvm::errs() << "GetClassName: " << GetClassName(range_init_type) << "\n";
1092+
verrs() << "GetClassName: " << GetClassName(range_init_type) << "\n";
10921093

10931094
if (GetClassName(range_init_type) == "std::map") {
10941095
return VisitCXXForRangeStmtMap(stmt);
@@ -2341,8 +2342,8 @@ bool Converter::ConvertCXXOperatorCallExpr(clang::CXXOperatorCallExpr *expr) {
23412342
break;
23422343
default:
23432344
// FIXME: improve error handling
2344-
llvm::errs() << "unsupported CXXOperatorCallExpr: "
2345-
<< clang::getOperatorSpelling(expr->getOperator()) << '\n';
2345+
verrs() << "unsupported CXXOperatorCallExpr: "
2346+
<< clang::getOperatorSpelling(expr->getOperator()) << '\n';
23462347
assert(0);
23472348
}
23482349
return false;
@@ -2670,7 +2671,7 @@ bool Converter::VisitUnaryExprOrTypeTraitExpr(
26702671
break;
26712672
default:
26722673
// FIXME: improve error handling
2673-
llvm::errs() << "unsupported unary expr or type trait expr\n";
2674+
verrs() << "unsupported unary expr or type trait expr\n";
26742675
}
26752676
return false;
26762677
}
@@ -3302,8 +3303,7 @@ void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) {
33023303
}
33033304

33043305
if (methods.size() > 1) {
3305-
llvm::errs()
3306-
<< "Currently supporting only one overloaded comparison operator\n";
3306+
verrs() << "Currently supporting only one overloaded comparison operator\n";
33073307
abort();
33083308
}
33093309

@@ -3394,8 +3394,8 @@ void Converter::ConvertUnsignedArithBinaryOperator(clang::BinaryOperator *op,
33943394
break;
33953395
default:
33963396
// FIXME: improve error handling
3397-
llvm::errs() << "unsupported unsigned binary operator: " << opcode << '\n';
3398-
op->dumpColor();
3397+
verrs() << "unsupported unsigned binary operator: " << opcode << '\n';
3398+
op->dump(verrs(), ctx_);
33993399
assert(0);
34003400
}
34013401
PushParen paren(*this);
@@ -3705,9 +3705,9 @@ void Converter::SetFreshType(clang::QualType type) {
37053705
}
37063706

37073707
void Converter::dump_expr_kinds() {
3708-
llvm::errs() << "isRValue: " << isRValue() << ", isXValue: " << isXValue()
3709-
<< ", isAddrOf: " << isAddrOf() << ", isObject: " << isObject()
3710-
<< ", isVoid: " << isVoid() << "\n";
3708+
verrs() << "isRValue: " << isRValue() << ", isXValue: " << isXValue()
3709+
<< ", isAddrOf: " << isAddrOf() << ", isObject: " << isObject()
3710+
<< ", isVoid: " << isVoid() << "\n";
37113711
}
37123712

37133713
void Converter::emplace_back_plugin_construct_arg(

cpp2rust/converter/converter.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "converter/lex.h"
1919
#include "converter/translation_rule.h"
20+
#include "logging.h"
2021

2122
namespace cpp2rust {
2223
class Converter : public clang::RecursiveASTVisitor<Converter> {
@@ -325,8 +326,8 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
325326

326327
template <typename... Ts>
327328
inline void _StrCat(const char *func, int line, const Ts &...vals) {
328-
llvm::errs() << '[' << func << ':' << line << "] ";
329-
((llvm::errs() << vals << '\n', *rs_code_ += vals, *rs_code_ += ' '), ...);
329+
verrs() << '[' << func << ':' << line << "] ";
330+
((verrs() << vals << '\n', *rs_code_ += vals, *rs_code_ += ' '), ...);
330331
}
331332

332333
class Buffer {
@@ -605,13 +606,13 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
605606
int line = __builtin_LINE())
606607
: c(c) {
607608
c.curr_expr_kind_.push_back(k);
608-
llvm::errs() << "PushExprKind " << file << ':' << line << ' ';
609+
verrs() << "PushExprKind " << file << ':' << line << ' ';
609610
c.dump_expr_kinds();
610-
llvm::errs() << '[';
611+
verrs() << '[';
611612
for (const auto k : c.curr_expr_kind_) {
612-
llvm::errs() << c.expr_kind_to_string(k) << ", ";
613+
verrs() << c.expr_kind_to_string(k) << ", ";
613614
}
614-
llvm::errs() << "]\n";
615+
verrs() << "]\n";
615616
}
616617
~PushExprKind() { c.curr_expr_kind_.pop_back(); }
617618
};

cpp2rust/converter/converter_lib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ const char *GetOverloadedOperator(const clang::FunctionDecl *decl) {
418418
return "lt";
419419
default:
420420
// FIXME: improve error handling
421-
llvm::errs() << "unsupported overloaded operator\n";
421+
verrs() << "unsupported overloaded operator\n";
422422
return "";
423423
}
424424
}

cpp2rust/converter/converter_lib.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <string_view>
1515
#include <vector>
1616

17+
#include "logging.h"
18+
1719
namespace cpp2rust {
1820

1921
// Order matters: each category is a superset of the previous one.
@@ -116,7 +118,7 @@ void ForEachTemplateArgument(
116118
break;
117119
default:
118120
// FIXME: improve logging
119-
llvm::errs() << "unsupported template argument kind\n";
121+
verrs() << "unsupported template argument kind\n";
120122
}
121123
}
122124
}

cpp2rust/converter/mapper.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "converter/converter_lib.h"
1818
#include "converter/translation_rule.h"
19+
#include "logging.h"
1920

2021
namespace cpp2rust::Mapper {
2122

@@ -368,11 +369,11 @@ decltype(exprs_)::const_iterator search(const clang::Expr *expr) {
368369
auto result = parallel_search(exprs_, [&](const std::string &tpl) {
369370
return matchTemplate(tpl, qualified_name);
370371
});
371-
llvm::errs() << "search expr " << qualified_name << ", result:\n";
372+
verrs() << "search expr " << qualified_name << ", result:\n";
372373
if (result != exprs_.end()) {
373374
result->second.dump();
374375
} else {
375-
llvm::errs() << "None\n";
376+
verrs() << "None\n";
376377
}
377378
return result;
378379
}
@@ -381,10 +382,9 @@ decltype(types_)::const_iterator search(clang::QualType qual_type) {
381382
auto type = ToString(qual_type);
382383
auto result = parallel_search(
383384
types_, [&](const std::string &tpl) { return matchTemplate(tpl, type); });
384-
llvm::errs() << "search type " << type << ", result: "
385-
<< ((result == types_.end()) ? "None"
386-
: result->second.type_info.type)
387-
<< '\n';
385+
verrs() << "search type " << type << ", result: "
386+
<< ((result == types_.end()) ? "None" : result->second.type_info.type)
387+
<< '\n';
388388
return result;
389389
}
390390

@@ -394,21 +394,21 @@ void addRulesFromDirectory(const std::filesystem::path &dir, Model model) {
394394
if (entry.is_regular_file() && path.extension() == ".cpp") {
395395
auto rules = TranslationRule::Load(path, model);
396396
if (rules.empty()) {
397-
llvm::errs() << "No rules found in " << path << '\n';
397+
verrs() << "No rules found in " << path << '\n';
398398
continue;
399399
}
400400
for (auto &rule : rules) {
401401
if (auto *expr = std::get_if<TranslationRule::ExprTgt>(&rule.tgt)) {
402402
if (!exprs_.try_emplace(std::move(rule.src), std::move(*expr))
403403
.second) {
404-
llvm::errs() << "Key: " << rule.src << " already exists in exprs\n";
404+
verrs() << "Key: " << rule.src << " already exists in exprs\n";
405405
assert(0);
406406
}
407407
} else if (auto *type =
408408
std::get_if<TranslationRule::TypeTgt>(&rule.tgt)) {
409409
if (!types_.try_emplace(std::move(rule.src), std::move(*type))
410410
.second) {
411-
llvm::errs() << "Key: " << rule.src << " already exists in types\n";
411+
verrs() << "Key: " << rule.src << " already exists in types\n";
412412
assert(0);
413413
}
414414
}
@@ -532,7 +532,7 @@ std::string mapTypeStringRecursive(const std::string &cpp_type) {
532532
return matchTemplate(tpl, cpp_type);
533533
});
534534
if (rule == types_.end()) {
535-
llvm::errs() << "cpp_type: " << cpp_type << '\n';
535+
verrs() << "cpp_type: " << cpp_type << '\n';
536536
assert(0 && "Type is not present in types_");
537537
}
538538
auto subs = matchTemplate(rule->first, cpp_type).value();
@@ -897,11 +897,11 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx,
897897

898898
#if 0
899899
for (auto &[src, expr] : exprs_) {
900-
llvm::errs() << "Expr: " << src << '\n';
900+
verrs() << "Expr: " << src << '\n';
901901
expr.dump();
902902
}
903903
for (auto &[src, type_tgt] : types_) {
904-
llvm::errs() << "Type: " << src << '\n';
904+
verrs() << "Type: " << src << '\n';
905905
type_tgt.dump();
906906
}
907907
#endif

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "converter/converter_lib.h"
1212
#include "converter/lex.h"
1313
#include "converter/mapper.h"
14+
#include "logging.h"
1415

1516
namespace cpp2rust {
1617
ConverterRefCount::ConverterRefCount(std::string &rs_code,
@@ -823,7 +824,7 @@ static std::vector<const char *> printf2fmt(std::string &format) {
823824
}
824825
}
825826
}
826-
llvm::errs() << "Unknown printf format: " << format << "\n";
827+
cpp2rust::verrs() << "Unknown printf format: " << format << "\n";
827828
assert(0);
828829
}
829830
return types;
@@ -837,9 +838,9 @@ void ConverterRefCount::ConvertPrintf(clang::CallExpr *expr) {
837838
expr->getArg(is_fprintf)->IgnoreImplicit())) {
838839
format = GetEscapedStringLiteral(str);
839840
} else {
840-
llvm::errs() << "Uknown fprintf format: ";
841-
expr->getArg(1)->dump();
842-
llvm::errs() << "\n";
841+
cpp2rust::verrs() << "Uknown fprintf format: ";
842+
expr->getArg(1)->dump(cpp2rust::verrs(), ctx_);
843+
cpp2rust::verrs() << "\n";
843844
exit(1);
844845
}
845846
bool ends_newline = format.ends_with("\\n\"");
@@ -850,7 +851,7 @@ void ConverterRefCount::ConvertPrintf(clang::CallExpr *expr) {
850851
} else if (fd == "stderr" || fd == "__stderrp") {
851852
StrCat(ends_newline ? "eprintln!(" : "eprint!(");
852853
} else {
853-
llvm::errs() << "Uknown fprintf fd: " << fd << "\n";
854+
cpp2rust::verrs() << "Uknown fprintf fd: " << fd << "\n";
854855
exit(1);
855856
}
856857
if (ends_newline) {

cpp2rust/converter/models/converter_refcount.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,21 @@ class ConverterRefCount final : public Converter {
245245
if (pushed) {
246246
c.conversion_kind_.push_back(k);
247247
}
248-
llvm::errs() << "[PushConversionKind:" << line << "] ";
248+
verrs() << "[PushConversionKind:" << line << "] ";
249249
for (auto ck : c.conversion_kind_) {
250-
llvm::errs() << c.ConversionKindToString(ck) << ", ";
250+
verrs() << c.ConversionKindToString(ck) << ", ";
251251
}
252-
llvm::errs() << "\n";
252+
verrs() << "\n";
253253
}
254254
~PushConversionKind() {
255255
if (pushed) {
256256
c.conversion_kind_.pop_back();
257257
}
258-
llvm::errs() << "[PopConversionKind] ";
258+
verrs() << "[PopConversionKind] ";
259259
for (auto ck : c.conversion_kind_) {
260-
llvm::errs() << c.ConversionKindToString(ck) << ", ";
260+
verrs() << c.ConversionKindToString(ck) << ", ";
261261
}
262-
llvm::errs() << "\n";
262+
verrs() << "\n";
263263
}
264264
};
265265

cpp2rust/converter/plugins/emplace_back.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "converter/converter_lib.h"
77
#include "converter/mapper.h"
88
#include "converter/models/converter_refcount.h"
9+
#include "logging.h"
910

1011
namespace cpp2rust {
1112

@@ -182,7 +183,7 @@ bool Converter::emplace_back_plugin_convert(clang::CallExpr *call) {
182183
StrCat(GetUnsafeTypeAsString(elem_ty));
183184
}
184185
} else {
185-
call->dumpColor();
186+
call->dump(cpp2rust::verrs(), ctx_);
186187
assert(0 && "no ctor and no pod type");
187188
return false;
188189
}

0 commit comments

Comments
 (0)