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
8 changes: 4 additions & 4 deletions cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2136,7 +2136,7 @@ std::string Converter::ConvertDeclRefExpr(clang::DeclRefExpr *expr) {
return std::format("{}::{}",
GetRecordName(clang::dyn_cast<clang::EnumDecl>(
enum_constant->getDeclContext())),
enum_constant->getName().str());
std::string_view(enum_constant->getName()));
} else if (IsGlobalVar(expr)) {
return ReplaceAll(Mapper::ToString(expr->getDecl()), "::", "_");
}
Expand Down Expand Up @@ -2612,12 +2612,12 @@ bool Converter::VisitEnumDecl(clang::EnumDecl *decl) {
for (auto e : decl->enumerators()) {
llvm::SmallVector<char, 32> init;
e->getInitVal().toString(init, 10);
std::string init_str(init.begin(), init.end());
if (first_enumerator) {
StrCat("#[default]");
first_enumerator = false;
}
StrCat(std::format("{} = {},", e->getNameAsString(), init_str));
StrCat(std::format("{} = {},", std::string_view(e->getName()),
std::string_view(init.data(), init.size())));
}
StrCat("}");
return false;
Expand Down Expand Up @@ -2854,7 +2854,7 @@ std::string Converter::ConvertVarDefaultInit(clang::QualType qual_type) {

std::string
Converter::GetOverloadedFunctionName(const clang::FunctionDecl *decl) {
std::string name(decl->getNameAsString());
auto name = decl->getNameAsString();

if (decl->getNumParams() != 0U) {
name += '_';
Expand Down
11 changes: 6 additions & 5 deletions cpp2rust/converter/mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void addBuiltinTypes(Model model) {
auto build_rust_type = [&](clang::QualType qt) {
unsigned bits = ctx_->getTypeSize(qt);
char sign = qt->isSignedIntegerType() ? 'i' : 'u';
return std::string(1, sign) + std::to_string(bits);
return std::format("{}{}", sign, bits);
};

// Misc
Expand Down Expand Up @@ -858,10 +858,11 @@ std::string ToString(const clang::Expr *expr) {
}

if (const auto *uop = llvm::dyn_cast<clang::UnaryOperator>(expr)) {
std::string opcode =
clang::UnaryOperator::getOpcodeStr(uop->getOpcode()).str();
return uop->isPostfix() ? ToString(uop->getSubExpr()) + std::move(opcode)
: std::move(opcode) + ToString(uop->getSubExpr());
auto sub = ToString(uop->getSubExpr());
std::string_view opcode =
clang::UnaryOperator::getOpcodeStr(uop->getOpcode());
return uop->isPostfix() ? std::format("{}{}", sub, opcode)
: std::format("{}{}", opcode, sub);
}

return "Unhandled case in ToString";
Expand Down
2 changes: 1 addition & 1 deletion cpp2rust/converter/models/converter_refcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ void ConverterRefCount::ConvertGenericBinaryOperator(
clang::BinaryOperator *expr) {
auto lhs = expr->getLHS();
auto rhs = expr->getRHS();
auto opcode = expr->getOpcodeStr().str();
std::string_view opcode = expr->getOpcodeStr();

auto lhs_vars = GetAllVars(lhs);
auto rhs_vars = GetAllVars(rhs);
Expand Down
Loading