Skip to content

Commit e0f2254

Browse files
authored
Convert single-char StrCat string arguments to char literals
1 parent dabd690 commit e0f2254

3 files changed

Lines changed: 33 additions & 33 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ bool Converter::VisitRecordType(clang::RecordType *type) {
165165
->getAs<clang::FunctionProtoType>(),
166166
FnProtoType::LambdaCallOperator));
167167
} else {
168-
StrCat("_");
168+
StrCat('_');
169169
}
170170
return false;
171171
}
@@ -1660,9 +1660,9 @@ void Converter::ConvertGenericCallExpr(clang::CallExpr *expr) {
16601660
temp_refs[i] = std::move(ref);
16611661
} else if (!clang::isa<clang::MaterializeTemporaryExpr>(arg)) {
16621662
StrCat("let", std::format("_{}: {}", param_name, ToString(param_type)),
1663-
"=");
1663+
'=');
16641664
convert_param_ty(param_type, arg);
1665-
StrCat(";");
1665+
StrCat(';');
16661666
}
16671667
}
16681668

@@ -3018,7 +3018,7 @@ bool Converter::VisitEnumDecl(clang::EnumDecl *decl) {
30183018
Mapper::AddRuleForUserDefinedType(decl);
30193019
StrCat("#[derive(Clone, Copy, PartialEq, Debug, Default)]");
30203020
StrCat(std::format("enum {}", GetRecordName(decl)));
3021-
StrCat("{");
3021+
StrCat('{');
30223022
bool first_enumerator = true;
30233023
for (auto e : decl->enumerators()) {
30243024
llvm::SmallVector<char, 32> init;
@@ -3030,7 +3030,7 @@ bool Converter::VisitEnumDecl(clang::EnumDecl *decl) {
30303030
StrCat(std::format("{} = {},", std::string_view(e->getName()),
30313031
std::string_view(init.data(), init.size())));
30323032
}
3033-
StrCat("}");
3033+
StrCat('}');
30343034

30353035
AddFromImpl(decl);
30363036
AddIncDecImpls(decl);
@@ -3071,7 +3071,7 @@ bool Converter::VisitLambdaExpr(clang::LambdaExpr *expr) {
30713071
StrCat("Some");
30723072
}
30733073
PushParen paren(*this);
3074-
StrCat("|");
3074+
StrCat('|');
30753075
for (auto p : expr->getLambdaClass()->getLambdaCallOperator()->parameters()) {
30763076
StrCat(GetNamedDeclAsString(p), token::kColon, ToString(p->getType()),
30773077
token::kComma);
@@ -3083,7 +3083,7 @@ bool Converter::VisitLambdaExpr(clang::LambdaExpr *expr) {
30833083
curr_function_ = expr->getLambdaClass()->getLambdaCallOperator();
30843084
ConvertFunctionBody(curr_function_);
30853085
curr_function_ = old_function;
3086-
StrCat("}");
3086+
StrCat('}');
30873087
return false;
30883088
}
30893089

@@ -3659,21 +3659,21 @@ void Converter::ConvertOrdAndPartialOrdTraitsBase(
36593659
std::string_view first_branch, std::string_view second_branch,
36603660
std::string_view first_return, std::string_view second_return,
36613661
std::string_view record_name) {
3662-
StrCat(keyword::kImpl, "Ord for ", record_name, "{");
3662+
StrCat(keyword::kImpl, "Ord for ", record_name, '{');
36633663
StrCat("fn cmp(&self, other: &Self) -> std::cmp::Ordering {");
36643664
StrCat(std::format("{} {{", keyword_unsafe_));
3665-
StrCat("if", first_branch, "{", first_return, "} else if", second_branch, "{",
3665+
StrCat("if", first_branch, '{', first_return, "} else if", second_branch, '{',
36663666
second_return, "} else { std::cmp::Ordering::Equal }");
36673667
StrCat("}}}");
36683668

3669-
StrCat(keyword::kImpl, "PartialOrd for", record_name, "{");
3669+
StrCat(keyword::kImpl, "PartialOrd for", record_name, '{');
36703670
StrCat(R"(
36713671
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
36723672
Some(self.cmp(other))
36733673
}
36743674
})");
36753675

3676-
StrCat(keyword::kImpl, "PartialEq for", record_name, "{");
3676+
StrCat(keyword::kImpl, "PartialEq for", record_name, '{');
36773677
StrCat("fn eq(&self, other: &Self) -> bool {");
36783678
StrCat(std::format("{} {{", keyword_unsafe_));
36793679
StrCat("!(", first_branch, ") && !(", second_branch, ')');

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ bool ConverterRefCount::VisitConstantArrayType(clang::ConstantArrayType *type) {
274274

275275
switch (conv) {
276276
case ConversionKind::Unboxed:
277-
StrCat("[");
277+
StrCat('[');
278278
Convert(type->getElementType());
279279
StrCat(std::format("; {}]", GetNumAsString(type->getSize()).c_str()));
280280
break;
@@ -445,7 +445,7 @@ void ConverterRefCount::AddCloneTrait(const clang::CXXRecordDecl *decl) {
445445

446446
auto record_name = GetRecordName(decl);
447447

448-
StrCat(keyword::kImpl, "Clone for", record_name, "{");
448+
StrCat(keyword::kImpl, "Clone for", record_name, '{');
449449
StrCat("fn clone(&self) -> Self {");
450450

451451
for (auto ctor : decl->ctors()) {
@@ -456,8 +456,8 @@ void ConverterRefCount::AddCloneTrait(const clang::CXXRecordDecl *decl) {
456456
}
457457
}
458458

459-
StrCat("}");
460-
StrCat("}");
459+
StrCat('}');
460+
StrCat('}');
461461
}
462462

463463
void ConverterRefCount::AddDefaultTrait(const clang::RecordDecl *decl) {
@@ -491,11 +491,11 @@ void ConverterRefCount::AddDropTrait(const clang::CXXRecordDecl *decl) {
491491

492492
auto record_name = GetRecordName(decl);
493493

494-
StrCat(keyword::kImpl, "Drop for", record_name, "{");
494+
StrCat(keyword::kImpl, "Drop for", record_name, '{');
495495
StrCat("fn drop(&mut self) {");
496496
Convert(body);
497-
StrCat("}");
498-
StrCat("}");
497+
StrCat('}');
498+
StrCat('}');
499499
}
500500

501501
static bool recordImplementsByteRepr(const clang::RecordDecl *decl) {
@@ -687,7 +687,7 @@ bool ConverterRefCount::ConvertIncAndDec(clang::UnaryOperator *expr) {
687687
if (!pending_deref_.empty()) {
688688
StrCat(pending_deref_.take(), ".with_mut(|__v| __v.", method, "())");
689689
} else {
690-
StrCat(str, ".", method, "()");
690+
StrCat(str, '.', method, "()");
691691
}
692692
return true;
693693
}
@@ -946,7 +946,7 @@ void ConverterRefCount::ConvertPrintf(clang::CallExpr *expr) {
946946
if (types[j])
947947
StrCat(keyword::kAs, types[j++]);
948948
}
949-
StrCat(")");
949+
StrCat(')');
950950
}
951951

952952
bool ConverterRefCount::VisitCallExpr(clang::CallExpr *expr) {
@@ -1144,7 +1144,7 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
11441144
void ConverterRefCount::EmitFnPtrCall(clang::Expr *callee) {
11451145
StrCat("(*");
11461146
Convert(callee);
1147-
StrCat(")");
1147+
StrCat(')');
11481148
}
11491149

11501150
void ConverterRefCount::ConvertFunctionToFunctionPointer(
@@ -1156,7 +1156,7 @@ void ConverterRefCount::ConvertFunctionToFunctionPointer(
11561156
}
11571157

11581158
void ConverterRefCount::ConvertEqualsNullPtr(clang::Expr *expr) {
1159-
StrCat("(");
1159+
StrCat('(');
11601160
Convert(expr);
11611161
StrCat(").is_null()");
11621162
}
@@ -1485,7 +1485,7 @@ bool ConverterRefCount::VisitCXXNewExpr(clang::CXXNewExpr *expr) {
14851485
expr->getInitializer())) {
14861486
StrCat("Ptr::alloc_array(");
14871487
Convert(init);
1488-
StrCat(")");
1488+
StrCat(')');
14891489
} else {
14901490
auto array_size_as_string = ToString(*expr->getArraySize());
14911491
auto alloc_type = expr->getAllocatedType();
@@ -1505,7 +1505,7 @@ bool ConverterRefCount::VisitCXXNewExpr(clang::CXXNewExpr *expr) {
15051505
} else {
15061506
Convert(expr->getInitializer());
15071507
}
1508-
StrCat(")");
1508+
StrCat(')');
15091509
}
15101510
computed_expr_type_ = ComputedExprType::FreshPointer;
15111511
return false;
@@ -1540,7 +1540,7 @@ bool ConverterRefCount::VisitCXXForRangeStmtMap(clang::CXXForRangeStmt *stmt) {
15401540

15411541
StrCat("'loop_:");
15421542
StrCat(keyword::kFor, loop_var_name, keyword::kIn, "RefcountMapIter::begin(",
1543-
ConvertObject(stmt->getRangeInit()), ")");
1543+
ConvertObject(stmt->getRangeInit()), ')');
15441544
PushBrace brace(*this);
15451545

15461546
EmitByValueShadow(
@@ -1603,7 +1603,7 @@ bool ConverterRefCount::VisitCXXForRangeStmtString(
16031603
stmt->getLoopVariable()->getType().isConstQualified() ? "" : "mut",
16041604
loop_var_name, keyword::kIn, ConvertObject(stmt->getRangeInit()));
16051605
StrCat(".to_string_iterator() as StringIterator<",
1606-
ToString(loop_var->getType().getNonReferenceType()), ">");
1606+
ToString(loop_var->getType().getNonReferenceType()), '>');
16071607

16081608
PushBrace brace(*this);
16091609

@@ -1688,7 +1688,7 @@ bool ConverterRefCount::VisitImplicitValueInitExpr(
16881688
if (clang::isa<clang::ConstantArrayType>(arr_ty)) {
16891689
StrCat("Box::new(");
16901690
Converter::VisitImplicitValueInitExpr(expr);
1691-
StrCat(")");
1691+
StrCat(')');
16921692
return false;
16931693
}
16941694
}
@@ -1798,7 +1798,7 @@ void ConverterRefCount::ConvertVarInit(clang::QualType qual_type,
17981798
if (qual_type->isFunctionPointerType() && lambda->capture_size() == 0) {
17991799
StrCat("FnPtr::new(");
18001800
VisitLambdaExpr(lambda);
1801-
StrCat(")");
1801+
StrCat(')');
18021802
} else {
18031803
VisitLambdaExpr(lambda);
18041804
}
@@ -1866,7 +1866,7 @@ void ConverterRefCount::EmitSetOrAssign(clang::Expr *lhs,
18661866
auto lhs_str = ConvertLValue(lhs);
18671867
if (!pending_deref_.empty()) {
18681868
auto ptr = pending_deref_.take();
1869-
StrCat(ptr, ".write(", rhs, ")");
1869+
StrCat(ptr, ".write(", rhs, ')');
18701870
} else {
18711871
StrCat(lhs_str, token::kAssign, rhs);
18721872
}
@@ -2039,7 +2039,7 @@ bool ConverterRefCount::ConvertCXXOperatorCallExpr(
20392039
}
20402040

20412041
if (is_inner_boxed && !isObject()) {
2042-
StrCat("(");
2042+
StrCat('(');
20432043
}
20442044

20452045
PushConversionKind push(*this, ConversionKind::Unboxed);

cpp2rust/converter/plugins/emplace_back.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ void Converter::emplace_back_emit_push_open(clang::CXXMemberCallExpr *call) {
139139
PushExprKind push(*this, ExprKind::LValue);
140140
StrCat(ReplaceAll(ToString(call->getCallee()), "emplace_back", "push"));
141141
}
142-
StrCat("(");
142+
StrCat('(');
143143
}
144144

145145
void Converter::emplace_back_emit_push_close(clang::CXXMemberCallExpr *call) {
146-
StrCat(")");
146+
StrCat(')');
147147
}
148148

149149
bool Converter::emplace_back_plugin_convert(clang::CallExpr *call) {
@@ -169,7 +169,7 @@ bool Converter::emplace_back_plugin_convert(clang::CallExpr *call) {
169169
emplace_back_plugin_construct_arg(
170170
elem_ty, buildConstructExpr(member_call, GetSema()));
171171
if (is_argument_moved) {
172-
StrCat(")");
172+
StrCat(')');
173173
}
174174
} else if (elem_ty.isPODType(ctx_)) {
175175
if (call->getNumArgs() == 0) {

0 commit comments

Comments
 (0)