Skip to content

Commit 9222e5b

Browse files
committed
Remove vouts and keep errs for hard errors
1 parent 6dc3f47 commit 9222e5b

11 files changed

Lines changed: 83 additions & 86 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ use std::rc::Rc;
5353
}
5454

5555
bool Converter::VisitRecoveryExpr(clang::RecoveryExpr *expr) {
56-
verrs() << "RecoveryExpr: ";
57-
expr->dump(verrs(), ctx_);
56+
llvm::errs() << "RecoveryExpr: ";
57+
expr->dump(llvm::errs(), ctx_);
5858
exit(1);
5959
return false;
6060
}
@@ -123,7 +123,7 @@ bool Converter::VisitBuiltinType(clang::BuiltinType *type) {
123123
break;
124124
default:
125125
// FIXME: improve error handling
126-
verrs() << "unsupported builtin type\n";
126+
log() << "unsupported builtin type\n";
127127
break;
128128
}
129129
return false;
@@ -152,7 +152,7 @@ bool Converter::VisitRecordType(clang::RecordType *type) {
152152
}
153153

154154
std::string Converter::ConvertPointer(clang::Expr *expr, int line) {
155-
verrs() << "ConvertPointer called from line " << line << "\n";
155+
log() << "ConvertPointer called from line " << line << "\n";
156156
PushExprKind push(*this, ExprKind::AddrOf);
157157
return ToString(expr);
158158
}
@@ -176,7 +176,7 @@ std::string Converter::ConvertLValue(clang::Expr *expr) {
176176
}
177177

178178
std::string Converter::ConvertRValue(clang::Expr *expr, int line) {
179-
verrs() << "ConvertRValue called from line " << line << "\n";
179+
log() << "ConvertRValue called from line " << line << "\n";
180180
PushExprKind push(*this, ExprKind::RValue);
181181
return ToString(expr);
182182
}
@@ -296,7 +296,7 @@ bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) {
296296
if (!IsInMainFile(decl) && !decl_ids_.insert(GetID(decl)).second) {
297297
return false;
298298
}
299-
decl->dump(verrs());
299+
decl->dump(log());
300300
curr_function_ = decl;
301301
std::string function_name;
302302
if (decl->isMain()) {
@@ -583,7 +583,7 @@ static bool recordDerivesCopy(const clang::RecordDecl *decl) {
583583
}
584584

585585
bool Converter::VisitRecordDecl(clang::RecordDecl *decl) {
586-
decl->dump(verrs());
586+
decl->dump(log());
587587

588588
// VisitCXXRecordDecl already visited the record
589589
if (clang::isa<clang::CXXRecordDecl>(decl)) {
@@ -695,7 +695,7 @@ bool Converter::VisitCXXRecordDecl(clang::CXXRecordDecl *decl) {
695695
materializeTemplateSpecialization(decl);
696696
}
697697

698-
decl->dump(verrs());
698+
decl->dump(log());
699699

700700
Mapper::AddRuleForUserDefinedType(decl);
701701
if (!IsConvertibleCXXRecordDecl(decl)) {
@@ -742,7 +742,7 @@ bool Converter::VisitCXXRecordDecl(clang::CXXRecordDecl *decl) {
742742
}
743743

744744
bool Converter::VisitCXXMethodDecl(clang::CXXMethodDecl *decl) {
745-
decl->dump(verrs());
745+
decl->dump(log());
746746
if (!IsConvertibleCXXMethodDecl(decl)) {
747747
return false;
748748
}
@@ -1086,10 +1086,10 @@ bool Converter::VisitCXXForRangeStmt(clang::CXXForRangeStmt *stmt) {
10861086

10871087
if (!Mapper::Contains(range_init_type.getUnqualifiedType())) {
10881088
// FIXME: improve error handling
1089-
verrs() << "for range stmts only for types in std namespace\n";
1089+
log() << "for range stmts only for types in std namespace\n";
10901090
}
10911091

1092-
verrs() << "GetClassName: " << GetClassName(range_init_type) << "\n";
1092+
log() << "GetClassName: " << GetClassName(range_init_type) << "\n";
10931093

10941094
if (GetClassName(range_init_type) == "std::map") {
10951095
return VisitCXXForRangeStmtMap(stmt);
@@ -2364,8 +2364,8 @@ bool Converter::ConvertCXXOperatorCallExpr(clang::CXXOperatorCallExpr *expr) {
23642364
break;
23652365
default:
23662366
// FIXME: improve error handling
2367-
verrs() << "unsupported CXXOperatorCallExpr: "
2368-
<< clang::getOperatorSpelling(expr->getOperator()) << '\n';
2367+
llvm::errs() << "unsupported CXXOperatorCallExpr: "
2368+
<< clang::getOperatorSpelling(expr->getOperator()) << '\n';
23692369
assert(0);
23702370
}
23712371
return false;
@@ -2693,7 +2693,7 @@ bool Converter::VisitUnaryExprOrTypeTraitExpr(
26932693
break;
26942694
default:
26952695
// FIXME: improve error handling
2696-
verrs() << "unsupported unary expr or type trait expr\n";
2696+
log() << "unsupported unary expr or type trait expr\n";
26972697
}
26982698
return false;
26992699
}
@@ -3345,7 +3345,8 @@ void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) {
33453345
}
33463346

33473347
if (methods.size() > 1) {
3348-
verrs() << "Currently supporting only one overloaded comparison operator\n";
3348+
llvm::errs()
3349+
<< "Currently supporting only one overloaded comparison operator\n";
33493350
abort();
33503351
}
33513352

@@ -3436,8 +3437,8 @@ void Converter::ConvertUnsignedArithBinaryOperator(clang::BinaryOperator *op,
34363437
break;
34373438
default:
34383439
// FIXME: improve error handling
3439-
verrs() << "unsupported unsigned binary operator: " << opcode << '\n';
3440-
op->dump(verrs(), ctx_);
3440+
llvm::errs() << "unsupported unsigned binary operator: " << opcode << '\n';
3441+
op->dump(llvm::errs(), ctx_);
34413442
assert(0);
34423443
}
34433444
PushParen paren(*this);
@@ -3747,9 +3748,9 @@ void Converter::SetFreshType(clang::QualType type) {
37473748
}
37483749

37493750
void Converter::dump_expr_kinds() {
3750-
verrs() << "isRValue: " << isRValue() << ", isXValue: " << isXValue()
3751-
<< ", isAddrOf: " << isAddrOf() << ", isObject: " << isObject()
3752-
<< ", isVoid: " << isVoid() << "\n";
3751+
log() << "isRValue: " << isRValue() << ", isXValue: " << isXValue()
3752+
<< ", isAddrOf: " << isAddrOf() << ", isObject: " << isObject()
3753+
<< ", isVoid: " << isVoid() << "\n";
37533754
}
37543755

37553756
void Converter::emplace_back_plugin_construct_arg(

cpp2rust/converter/converter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
330330

331331
template <typename... Ts>
332332
inline void _StrCat(const char *func, int line, const Ts &...vals) {
333-
verrs() << '[' << func << ':' << line << "] ";
334-
((verrs() << vals << '\n', *rs_code_ += vals, *rs_code_ += ' '), ...);
333+
log() << '[' << func << ':' << line << "] ";
334+
((log() << vals << '\n', *rs_code_ += vals, *rs_code_ += ' '), ...);
335335
}
336336

337337
class Buffer {
@@ -610,13 +610,13 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
610610
int line = __builtin_LINE())
611611
: c(c) {
612612
c.curr_expr_kind_.push_back(k);
613-
verrs() << "PushExprKind " << file << ':' << line << ' ';
613+
log() << "PushExprKind " << file << ':' << line << ' ';
614614
c.dump_expr_kinds();
615-
verrs() << '[';
615+
log() << '[';
616616
for (const auto k : c.curr_expr_kind_) {
617-
verrs() << c.expr_kind_to_string(k) << ", ";
617+
log() << c.expr_kind_to_string(k) << ", ";
618618
}
619-
verrs() << "]\n";
619+
log() << "]\n";
620620
}
621621
~PushExprKind() { c.curr_expr_kind_.pop_back(); }
622622
};

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-
verrs() << "unsupported overloaded operator\n";
421+
log() << "unsupported overloaded operator\n";
422422
return "";
423423
}
424424
}

cpp2rust/converter/converter_lib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void ForEachTemplateArgument(
118118
break;
119119
default:
120120
// FIXME: improve logging
121-
verrs() << "unsupported template argument kind\n";
121+
log() << "unsupported template argument kind\n";
122122
}
123123
}
124124
}

cpp2rust/converter/mapper.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,20 +384,20 @@ 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-
verrs() << "search expr " << qualified_name << ", result:\n";
387+
log() << "search expr " << qualified_name << ", result:\n";
388388
if (rule) {
389389
rule->dump();
390390
} else {
391-
verrs() << "None\n";
391+
log() << "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-
verrs() << "search type " << type
400-
<< ", result: " << (rule ? rule->type_info.type : "None") << '\n';
399+
log() << "search type " << type
400+
<< ", result: " << (rule ? rule->type_info.type : "None") << '\n';
401401
return rule;
402402
}
403403

@@ -407,7 +407,7 @@ void addRulesFromDirectory(const std::filesystem::path &dir, Model model) {
407407
if (entry.is_regular_file() && path.extension() == ".cpp") {
408408
auto [expr_rules, type_rules] = TranslationRule::Load(path, model);
409409
if (expr_rules.empty() && type_rules.empty()) {
410-
verrs() << "No rules found in " << path << '\n';
410+
log() << "No rules found in " << path << '\n';
411411
continue;
412412
}
413413
for (auto &[_, rule] : expr_rules) {
@@ -534,7 +534,7 @@ clang::QualType normalizeQualType(clang::QualType qual_type) {
534534
std::string mapTypeStringRecursive(const std::string &cpp_type) {
535535
auto [rule, subs] = search(types_, cpp_type, GetTypeMapKey(cpp_type));
536536
if (!rule) {
537-
verrs() << "cpp_type: " << cpp_type << '\n';
537+
llvm::errs() << "cpp_type: " << cpp_type << '\n';
538538
assert(0 && "Type is not present in types_");
539539
}
540540
for (auto &ty : subs) {
@@ -884,11 +884,11 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx,
884884

885885
#if 0
886886
for (auto &[src, rule] : exprs_) {
887-
verrs() << "Expr key: " << src << '\n';
887+
log() << "Expr key: " << src << '\n';
888888
rule.dump();
889889
}
890890
for (auto &[src, rule] : types_) {
891-
verrs() << "Type key: " << src << '\n';
891+
log() << "Type key: " << src << '\n';
892892
rule.dump();
893893
}
894894
#endif

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ static std::vector<const char *> printf2fmt(std::string &format) {
824824
}
825825
}
826826
}
827-
verrs() << "Unknown printf format: " << format << "\n";
827+
llvm::errs() << "Unknown printf format: " << format << "\n";
828828
assert(0);
829829
}
830830
return types;
@@ -838,9 +838,9 @@ void ConverterRefCount::ConvertPrintf(clang::CallExpr *expr) {
838838
expr->getArg(is_fprintf)->IgnoreImplicit())) {
839839
format = GetEscapedStringLiteral(str);
840840
} else {
841-
verrs() << "Uknown fprintf format: ";
842-
expr->getArg(1)->dump(verrs(), ctx_);
843-
verrs() << "\n";
841+
llvm::errs() << "Uknown fprintf format: ";
842+
expr->getArg(1)->dump(llvm::errs(), ctx_);
843+
llvm::errs() << "\n";
844844
exit(1);
845845
}
846846
bool ends_newline = format.ends_with("\\n\"");
@@ -851,7 +851,7 @@ void ConverterRefCount::ConvertPrintf(clang::CallExpr *expr) {
851851
} else if (fd == "stderr" || fd == "__stderrp") {
852852
StrCat(ends_newline ? "eprintln!(" : "eprint!(");
853853
} else {
854-
verrs() << "Uknown fprintf fd: " << fd << "\n";
854+
llvm::errs() << "Uknown fprintf fd: " << fd << "\n";
855855
exit(1);
856856
}
857857
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-
verrs() << "[PushConversionKind:" << line << "] ";
248+
log() << "[PushConversionKind:" << line << "] ";
249249
for (auto ck : c.conversion_kind_) {
250-
verrs() << c.ConversionKindToString(ck) << ", ";
250+
log() << c.ConversionKindToString(ck) << ", ";
251251
}
252-
verrs() << "\n";
252+
log() << "\n";
253253
}
254254
~PushConversionKind() {
255255
if (pushed) {
256256
c.conversion_kind_.pop_back();
257257
}
258-
verrs() << "[PopConversionKind] ";
258+
log() << "[PopConversionKind] ";
259259
for (auto ck : c.conversion_kind_) {
260-
verrs() << c.ConversionKindToString(ck) << ", ";
260+
log() << c.ConversionKindToString(ck) << ", ";
261261
}
262-
verrs() << "\n";
262+
log() << "\n";
263263
}
264264
};
265265

cpp2rust/converter/plugins/emplace_back.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ bool Converter::emplace_back_plugin_convert(clang::CallExpr *call) {
183183
StrCat(GetUnsafeTypeAsString(elem_ty));
184184
}
185185
} else {
186-
call->dump(verrs(), ctx_);
186+
call->dump(llvm::errs(), ctx_);
187187
assert(0 && "no ctor and no pod type");
188188
return false;
189189
}

0 commit comments

Comments
 (0)