Skip to content

Commit 916052b

Browse files
committed
Disable verbose logging by default
1 parent a7de658 commit 916052b

10 files changed

Lines changed: 89 additions & 77 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);
@@ -2363,8 +2364,8 @@ bool Converter::ConvertCXXOperatorCallExpr(clang::CXXOperatorCallExpr *expr) {
23632364
break;
23642365
default:
23652366
// FIXME: improve error handling
2366-
llvm::errs() << "unsupported CXXOperatorCallExpr: "
2367-
<< clang::getOperatorSpelling(expr->getOperator()) << '\n';
2367+
verrs() << "unsupported CXXOperatorCallExpr: "
2368+
<< clang::getOperatorSpelling(expr->getOperator()) << '\n';
23682369
assert(0);
23692370
}
23702371
return false;
@@ -2692,7 +2693,7 @@ bool Converter::VisitUnaryExprOrTypeTraitExpr(
26922693
break;
26932694
default:
26942695
// FIXME: improve error handling
2695-
llvm::errs() << "unsupported unary expr or type trait expr\n";
2696+
verrs() << "unsupported unary expr or type trait expr\n";
26962697
}
26972698
return false;
26982699
}
@@ -3344,8 +3345,7 @@ void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) {
33443345
}
33453346

33463347
if (methods.size() > 1) {
3347-
llvm::errs()
3348-
<< "Currently supporting only one overloaded comparison operator\n";
3348+
verrs() << "Currently supporting only one overloaded comparison operator\n";
33493349
abort();
33503350
}
33513351

@@ -3436,8 +3436,8 @@ void Converter::ConvertUnsignedArithBinaryOperator(clang::BinaryOperator *op,
34363436
break;
34373437
default:
34383438
// FIXME: improve error handling
3439-
llvm::errs() << "unsupported unsigned binary operator: " << opcode << '\n';
3440-
op->dumpColor();
3439+
verrs() << "unsupported unsigned binary operator: " << opcode << '\n';
3440+
op->dump(verrs(), ctx_);
34413441
assert(0);
34423442
}
34433443
PushParen paren(*this);
@@ -3747,9 +3747,9 @@ void Converter::SetFreshType(clang::QualType type) {
37473747
}
37483748

37493749
void Converter::dump_expr_kinds() {
3750-
llvm::errs() << "isRValue: " << isRValue() << ", isXValue: " << isXValue()
3751-
<< ", isAddrOf: " << isAddrOf() << ", isObject: " << isObject()
3752-
<< ", isVoid: " << isVoid() << "\n";
3750+
verrs() << "isRValue: " << isRValue() << ", isXValue: " << isXValue()
3751+
<< ", isAddrOf: " << isAddrOf() << ", isObject: " << isObject()
3752+
<< ", isVoid: " << isVoid() << "\n";
37533753
}
37543754

37553755
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> {
@@ -329,8 +330,8 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
329330

330331
template <typename... Ts>
331332
inline void _StrCat(const char *func, int line, const Ts &...vals) {
332-
llvm::errs() << '[' << func << ':' << line << "] ";
333-
((llvm::errs() << vals << '\n', *rs_code_ += vals, *rs_code_ += ' '), ...);
333+
verrs() << '[' << func << ':' << line << "] ";
334+
((verrs() << vals << '\n', *rs_code_ += vals, *rs_code_ += ' '), ...);
334335
}
335336

336337
class Buffer {
@@ -609,13 +610,13 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
609610
int line = __builtin_LINE())
610611
: c(c) {
611612
c.curr_expr_kind_.push_back(k);
612-
llvm::errs() << "PushExprKind " << file << ':' << line << ' ';
613+
verrs() << "PushExprKind " << file << ':' << line << ' ';
613614
c.dump_expr_kinds();
614-
llvm::errs() << '[';
615+
verrs() << '[';
615616
for (const auto k : c.curr_expr_kind_) {
616-
llvm::errs() << c.expr_kind_to_string(k) << ", ";
617+
verrs() << c.expr_kind_to_string(k) << ", ";
617618
}
618-
llvm::errs() << "]\n";
619+
verrs() << "]\n";
619620
}
620621
~PushExprKind() { c.curr_expr_kind_.pop_back(); }
621622
};

‎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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,19 @@ TranslationRule::ExprRule *search(const clang::Expr *expr) {
384384
auto qualified_name = ToString(expr);
385385
auto [rule, subs] =
386386
search(exprs_, qualified_name, GetExprMapKey(qualified_name));
387-
llvm::errs() << "search expr " << qualified_name << ", result:\n";
387+
verrs() << "search expr " << qualified_name << ", result:\n";
388388
if (rule) {
389389
rule->dump();
390390
} else {
391-
llvm::errs() << "None\n";
391+
verrs() << "None\n";
392392
}
393393
return rule;
394394
}
395395

396396
TranslationRule::TypeRule *search(clang::QualType qual_type) {
397397
auto type = ToString(qual_type);
398398
auto [rule, subs] = search(types_, type, GetTypeMapKey(type));
399-
llvm::errs() << "search type " << type
399+
verrs() << "search type " << type
400400
<< ", result: " << (rule ? rule->type_info.type : "None")
401401
<< '\n';
402402
return rule;
@@ -408,7 +408,7 @@ void addRulesFromDirectory(const std::filesystem::path &dir, Model model) {
408408
if (entry.is_regular_file() && path.extension() == ".cpp") {
409409
auto [expr_rules, type_rules] = TranslationRule::Load(path, model);
410410
if (expr_rules.empty() && type_rules.empty()) {
411-
llvm::errs() << "No rules found in " << path << '\n';
411+
verrs() << "No rules found in " << path << '\n';
412412
continue;
413413
}
414414
for (auto &[_, rule] : expr_rules) {
@@ -535,7 +535,7 @@ clang::QualType normalizeQualType(clang::QualType qual_type) {
535535
std::string mapTypeStringRecursive(const std::string &cpp_type) {
536536
auto [rule, subs] = search(types_, cpp_type, GetTypeMapKey(cpp_type));
537537
if (!rule) {
538-
llvm::errs() << "cpp_type: " << cpp_type << '\n';
538+
verrs() << "cpp_type: " << cpp_type << '\n';
539539
assert(0 && "Type is not present in types_");
540540
}
541541
for (auto &ty : subs) {
@@ -885,11 +885,11 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx,
885885

886886
#if 0
887887
for (auto &[src, rule] : exprs_) {
888-
llvm::errs() << "Expr key: " << src << '\n';
888+
verrs() << "Expr key: " << src << '\n';
889889
rule.dump();
890890
}
891891
for (auto &[src, rule] : types_) {
892-
llvm::errs() << "Type key: " << src << '\n';
892+
verrs() << "Type key: " << src << '\n';
893893
rule.dump();
894894
}
895895
#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)