diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index b4016158..f18eb783 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -165,7 +165,7 @@ bool Converter::VisitRecordType(clang::RecordType *type) { ->getAs(), FnProtoType::LambdaCallOperator)); } else { - StrCat("_"); + StrCat('_'); } return false; } @@ -1660,9 +1660,9 @@ void Converter::ConvertGenericCallExpr(clang::CallExpr *expr) { temp_refs[i] = std::move(ref); } else if (!clang::isa(arg)) { StrCat("let", std::format("_{}: {}", param_name, ToString(param_type)), - "="); + '='); convert_param_ty(param_type, arg); - StrCat(";"); + StrCat(';'); } } @@ -3018,7 +3018,7 @@ bool Converter::VisitEnumDecl(clang::EnumDecl *decl) { Mapper::AddRuleForUserDefinedType(decl); StrCat("#[derive(Clone, Copy, PartialEq, Debug, Default)]"); StrCat(std::format("enum {}", GetRecordName(decl))); - StrCat("{"); + StrCat('{'); bool first_enumerator = true; for (auto e : decl->enumerators()) { llvm::SmallVector init; @@ -3030,7 +3030,7 @@ bool Converter::VisitEnumDecl(clang::EnumDecl *decl) { StrCat(std::format("{} = {},", std::string_view(e->getName()), std::string_view(init.data(), init.size()))); } - StrCat("}"); + StrCat('}'); AddFromImpl(decl); AddIncDecImpls(decl); @@ -3071,7 +3071,7 @@ bool Converter::VisitLambdaExpr(clang::LambdaExpr *expr) { StrCat("Some"); } PushParen paren(*this); - StrCat("|"); + StrCat('|'); for (auto p : expr->getLambdaClass()->getLambdaCallOperator()->parameters()) { StrCat(GetNamedDeclAsString(p), token::kColon, ToString(p->getType()), token::kComma); @@ -3083,7 +3083,7 @@ bool Converter::VisitLambdaExpr(clang::LambdaExpr *expr) { curr_function_ = expr->getLambdaClass()->getLambdaCallOperator(); ConvertFunctionBody(curr_function_); curr_function_ = old_function; - StrCat("}"); + StrCat('}'); return false; } @@ -3659,21 +3659,21 @@ void Converter::ConvertOrdAndPartialOrdTraitsBase( std::string_view first_branch, std::string_view second_branch, std::string_view first_return, std::string_view second_return, std::string_view record_name) { - StrCat(keyword::kImpl, "Ord for ", record_name, "{"); + StrCat(keyword::kImpl, "Ord for ", record_name, '{'); StrCat("fn cmp(&self, other: &Self) -> std::cmp::Ordering {"); StrCat(std::format("{} {{", keyword_unsafe_)); - StrCat("if", first_branch, "{", first_return, "} else if", second_branch, "{", + StrCat("if", first_branch, '{', first_return, "} else if", second_branch, '{', second_return, "} else { std::cmp::Ordering::Equal }"); StrCat("}}}"); - StrCat(keyword::kImpl, "PartialOrd for", record_name, "{"); + StrCat(keyword::kImpl, "PartialOrd for", record_name, '{'); StrCat(R"( fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } })"); - StrCat(keyword::kImpl, "PartialEq for", record_name, "{"); + StrCat(keyword::kImpl, "PartialEq for", record_name, '{'); StrCat("fn eq(&self, other: &Self) -> bool {"); StrCat(std::format("{} {{", keyword_unsafe_)); StrCat("!(", first_branch, ") && !(", second_branch, ')'); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 4dff7a28..9801bc6a 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -274,7 +274,7 @@ bool ConverterRefCount::VisitConstantArrayType(clang::ConstantArrayType *type) { switch (conv) { case ConversionKind::Unboxed: - StrCat("["); + StrCat('['); Convert(type->getElementType()); StrCat(std::format("; {}]", GetNumAsString(type->getSize()).c_str())); break; @@ -445,7 +445,7 @@ void ConverterRefCount::AddCloneTrait(const clang::CXXRecordDecl *decl) { auto record_name = GetRecordName(decl); - StrCat(keyword::kImpl, "Clone for", record_name, "{"); + StrCat(keyword::kImpl, "Clone for", record_name, '{'); StrCat("fn clone(&self) -> Self {"); for (auto ctor : decl->ctors()) { @@ -456,8 +456,8 @@ void ConverterRefCount::AddCloneTrait(const clang::CXXRecordDecl *decl) { } } - StrCat("}"); - StrCat("}"); + StrCat('}'); + StrCat('}'); } void ConverterRefCount::AddDefaultTrait(const clang::RecordDecl *decl) { @@ -491,11 +491,11 @@ void ConverterRefCount::AddDropTrait(const clang::CXXRecordDecl *decl) { auto record_name = GetRecordName(decl); - StrCat(keyword::kImpl, "Drop for", record_name, "{"); + StrCat(keyword::kImpl, "Drop for", record_name, '{'); StrCat("fn drop(&mut self) {"); Convert(body); - StrCat("}"); - StrCat("}"); + StrCat('}'); + StrCat('}'); } static bool recordImplementsByteRepr(const clang::RecordDecl *decl) { @@ -687,7 +687,7 @@ bool ConverterRefCount::ConvertIncAndDec(clang::UnaryOperator *expr) { if (!pending_deref_.empty()) { StrCat(pending_deref_.take(), ".with_mut(|__v| __v.", method, "())"); } else { - StrCat(str, ".", method, "()"); + StrCat(str, '.', method, "()"); } return true; } @@ -946,7 +946,7 @@ void ConverterRefCount::ConvertPrintf(clang::CallExpr *expr) { if (types[j]) StrCat(keyword::kAs, types[j++]); } - StrCat(")"); + StrCat(')'); } bool ConverterRefCount::VisitCallExpr(clang::CallExpr *expr) { @@ -1144,7 +1144,7 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { void ConverterRefCount::EmitFnPtrCall(clang::Expr *callee) { StrCat("(*"); Convert(callee); - StrCat(")"); + StrCat(')'); } void ConverterRefCount::ConvertFunctionToFunctionPointer( @@ -1156,7 +1156,7 @@ void ConverterRefCount::ConvertFunctionToFunctionPointer( } void ConverterRefCount::ConvertEqualsNullPtr(clang::Expr *expr) { - StrCat("("); + StrCat('('); Convert(expr); StrCat(").is_null()"); } @@ -1485,7 +1485,7 @@ bool ConverterRefCount::VisitCXXNewExpr(clang::CXXNewExpr *expr) { expr->getInitializer())) { StrCat("Ptr::alloc_array("); Convert(init); - StrCat(")"); + StrCat(')'); } else { auto array_size_as_string = ToString(*expr->getArraySize()); auto alloc_type = expr->getAllocatedType(); @@ -1505,7 +1505,7 @@ bool ConverterRefCount::VisitCXXNewExpr(clang::CXXNewExpr *expr) { } else { Convert(expr->getInitializer()); } - StrCat(")"); + StrCat(')'); } computed_expr_type_ = ComputedExprType::FreshPointer; return false; @@ -1540,7 +1540,7 @@ bool ConverterRefCount::VisitCXXForRangeStmtMap(clang::CXXForRangeStmt *stmt) { StrCat("'loop_:"); StrCat(keyword::kFor, loop_var_name, keyword::kIn, "RefcountMapIter::begin(", - ConvertObject(stmt->getRangeInit()), ")"); + ConvertObject(stmt->getRangeInit()), ')'); PushBrace brace(*this); EmitByValueShadow( @@ -1603,7 +1603,7 @@ bool ConverterRefCount::VisitCXXForRangeStmtString( stmt->getLoopVariable()->getType().isConstQualified() ? "" : "mut", loop_var_name, keyword::kIn, ConvertObject(stmt->getRangeInit())); StrCat(".to_string_iterator() as StringIterator<", - ToString(loop_var->getType().getNonReferenceType()), ">"); + ToString(loop_var->getType().getNonReferenceType()), '>'); PushBrace brace(*this); @@ -1688,7 +1688,7 @@ bool ConverterRefCount::VisitImplicitValueInitExpr( if (clang::isa(arr_ty)) { StrCat("Box::new("); Converter::VisitImplicitValueInitExpr(expr); - StrCat(")"); + StrCat(')'); return false; } } @@ -1798,7 +1798,7 @@ void ConverterRefCount::ConvertVarInit(clang::QualType qual_type, if (qual_type->isFunctionPointerType() && lambda->capture_size() == 0) { StrCat("FnPtr::new("); VisitLambdaExpr(lambda); - StrCat(")"); + StrCat(')'); } else { VisitLambdaExpr(lambda); } @@ -1866,7 +1866,7 @@ void ConverterRefCount::EmitSetOrAssign(clang::Expr *lhs, auto lhs_str = ConvertLValue(lhs); if (!pending_deref_.empty()) { auto ptr = pending_deref_.take(); - StrCat(ptr, ".write(", rhs, ")"); + StrCat(ptr, ".write(", rhs, ')'); } else { StrCat(lhs_str, token::kAssign, rhs); } @@ -2039,7 +2039,7 @@ bool ConverterRefCount::ConvertCXXOperatorCallExpr( } if (is_inner_boxed && !isObject()) { - StrCat("("); + StrCat('('); } PushConversionKind push(*this, ConversionKind::Unboxed); diff --git a/cpp2rust/converter/plugins/emplace_back.cpp b/cpp2rust/converter/plugins/emplace_back.cpp index 306e3c73..0c5924d5 100644 --- a/cpp2rust/converter/plugins/emplace_back.cpp +++ b/cpp2rust/converter/plugins/emplace_back.cpp @@ -139,11 +139,11 @@ void Converter::emplace_back_emit_push_open(clang::CXXMemberCallExpr *call) { PushExprKind push(*this, ExprKind::LValue); StrCat(ReplaceAll(ToString(call->getCallee()), "emplace_back", "push")); } - StrCat("("); + StrCat('('); } void Converter::emplace_back_emit_push_close(clang::CXXMemberCallExpr *call) { - StrCat(")"); + StrCat(')'); } bool Converter::emplace_back_plugin_convert(clang::CallExpr *call) { @@ -169,7 +169,7 @@ bool Converter::emplace_back_plugin_convert(clang::CallExpr *call) { emplace_back_plugin_construct_arg( elem_ty, buildConstructExpr(member_call, GetSema())); if (is_argument_moved) { - StrCat(")"); + StrCat(')'); } } else if (elem_ty.isPODType(ctx_)) { if (call->getNumArgs() == 0) {