Skip to content

Commit 3638fee

Browse files
committed
edits
1 parent 4c1beff commit 3638fee

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ bool Converter::VisitBinaryOperator(clang::BinaryOperator *expr) {
18761876
auto *rhs = expr->getRHS();
18771877
auto lhs_type = lhs->getType();
18781878
auto rhs_type = rhs->getType();
1879-
std::string opcode_as_string = expr->getOpcodeStr().str();
1879+
std::string_view opcode_as_string = expr->getOpcodeStr();
18801880

18811881
if (auto *cmpd_assign_op =
18821882
llvm::dyn_cast<clang::CompoundAssignOperator>(expr);
@@ -1902,7 +1902,9 @@ bool Converter::VisitBinaryOperator(clang::BinaryOperator *expr) {
19021902
Convert(lhs);
19031903
ConvertCast(computation_result_type);
19041904
}
1905-
StrCat(std::regex_replace(opcode_as_string, std::regex("="), ""));
1905+
std::string op(opcode_as_string);
1906+
op.erase(std::remove(op.begin(), op.end(), '='), op.end());
1907+
StrCat(op);
19061908
Convert(rhs);
19071909
}
19081910
if (lhs_type->isBooleanType()) {
@@ -2207,7 +2209,7 @@ bool Converter::VisitParenExpr(clang::ParenExpr *expr) {
22072209
bool Converter::ConvertCXXOperatorCallExpr(clang::CXXOperatorCallExpr *expr) {
22082210
switch (expr->getOperator()) {
22092211
case clang::OverloadedOperatorKind::OO_Equal:
2210-
ConvertAssignment(expr->getArg(0), expr->getArg(1), token::kAssign);
2212+
ConvertAssignment(expr->getArg(0), expr->getArg(1), "=");
22112213
break;
22122214
case clang::OverloadedOperatorKind::OO_Star:
22132215
case clang::OverloadedOperatorKind::OO_Arrow:

cpp2rust/converter/lex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ inline constexpr const char *kDiff = "!=";
2222
inline constexpr char kZero = '0';
2323
inline constexpr char kOne = '1';
2424
inline constexpr char kRef = '&';
25-
inline constexpr char kStar = '*';
25+
inline constexpr const char *kStar = "*";
2626
inline constexpr const char *kArrow = "->";
2727
inline constexpr char kHash = '#';
2828
inline constexpr char kMinus = '-';

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ bool ConverterRefCount::VisitBinaryOperator(clang::BinaryOperator *expr) {
11441144
auto *rhs = expr->getRHS();
11451145
auto lhs_type = lhs->getType();
11461146
auto rhs_type = rhs->getType();
1147-
std::string opcode_as_string = expr->getOpcodeStr().str();
1147+
std::string_view opcode_as_string = expr->getOpcodeStr();
11481148

11491149
if (auto *assign = llvm::dyn_cast<clang::CompoundAssignOperator>(expr);
11501150
assign && lhs_type != assign->getComputationResultType()) {
@@ -1165,7 +1165,9 @@ bool ConverterRefCount::VisitBinaryOperator(clang::BinaryOperator *expr) {
11651165
StrCat(ConvertRValue(lhs));
11661166
ConvertCast(computation_result_type);
11671167
}
1168-
StrCat(std::regex_replace(opcode_as_string, std::regex("="), ""));
1168+
std::string op(opcode_as_string);
1169+
op.erase(std::remove(op.begin(), op.end(), '='), op.end());
1170+
StrCat(op);
11691171
Convert(rhs);
11701172
}
11711173
if (lhs_type->isBooleanType()) {
@@ -1805,7 +1807,7 @@ bool ConverterRefCount::ConvertCXXOperatorCallExpr(
18051807
clang::CXXOperatorCallExpr *expr) {
18061808
switch (expr->getOperator()) {
18071809
case clang::OverloadedOperatorKind::OO_Equal:
1808-
ConvertAssignment(expr->getArg(0), expr->getArg(1), token::kAssign);
1810+
ConvertAssignment(expr->getArg(0), expr->getArg(1), "=");
18091811
break;
18101812

18111813
case clang::OverloadedOperatorKind::OO_Arrow:

0 commit comments

Comments
 (0)