Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bool Converter::VisitRecordType(clang::RecordType *type) {
->getAs<clang::FunctionProtoType>(),
FnProtoType::LambdaCallOperator));
} else {
StrCat("_");
StrCat('_');
}
return false;
}
Expand Down Expand Up @@ -1660,9 +1660,9 @@ void Converter::ConvertGenericCallExpr(clang::CallExpr *expr) {
temp_refs[i] = std::move(ref);
} else if (!clang::isa<clang::MaterializeTemporaryExpr>(arg)) {
StrCat("let", std::format("_{}: {}", param_name, ToString(param_type)),
"=");
'=');
convert_param_ty(param_type, arg);
StrCat(";");
StrCat(';');
}
}

Expand Down Expand Up @@ -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<char, 32> init;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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<std::cmp::Ordering> {
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, ')');
Expand Down
38 changes: 19 additions & 19 deletions cpp2rust/converter/models/converter_refcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -456,8 +456,8 @@ void ConverterRefCount::AddCloneTrait(const clang::CXXRecordDecl *decl) {
}
}

StrCat("}");
StrCat("}");
StrCat('}');
StrCat('}');
}

void ConverterRefCount::AddDefaultTrait(const clang::RecordDecl *decl) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1144,7 +1144,7 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
void ConverterRefCount::EmitFnPtrCall(clang::Expr *callee) {
StrCat("(*");
Convert(callee);
StrCat(")");
StrCat(')');
}

void ConverterRefCount::ConvertFunctionToFunctionPointer(
Expand All @@ -1156,7 +1156,7 @@ void ConverterRefCount::ConvertFunctionToFunctionPointer(
}

void ConverterRefCount::ConvertEqualsNullPtr(clang::Expr *expr) {
StrCat("(");
StrCat('(');
Convert(expr);
StrCat(").is_null()");
}
Expand Down Expand Up @@ -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();
Expand All @@ -1505,7 +1505,7 @@ bool ConverterRefCount::VisitCXXNewExpr(clang::CXXNewExpr *expr) {
} else {
Convert(expr->getInitializer());
}
StrCat(")");
StrCat(')');
}
computed_expr_type_ = ComputedExprType::FreshPointer;
return false;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1688,7 +1688,7 @@ bool ConverterRefCount::VisitImplicitValueInitExpr(
if (clang::isa<clang::ConstantArrayType>(arr_ty)) {
StrCat("Box::new(");
Converter::VisitImplicitValueInitExpr(expr);
StrCat(")");
StrCat(')');
return false;
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -2039,7 +2039,7 @@ bool ConverterRefCount::ConvertCXXOperatorCallExpr(
}

if (is_inner_boxed && !isObject()) {
StrCat("(");
StrCat('(');
}

PushConversionKind push(*this, ConversionKind::Unboxed);
Expand Down
6 changes: 3 additions & 3 deletions cpp2rust/converter/plugins/emplace_back.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Loading