@@ -1041,9 +1041,9 @@ bool Converter::VisitWhileStmt(clang::WhileStmt *stmt) {
10411041 ConvertCondition (stmt->getCond ());
10421042 {
10431043 PushBrace brace (*this );
1044- curr_for_inc_.emplace (nullptr );
1044+ curr_for_inc_.emplace_back (nullptr );
10451045 Convert (stmt->getBody ());
1046- curr_for_inc_.pop ();
1046+ curr_for_inc_.pop_back ();
10471047 }
10481048 return false ;
10491049}
@@ -1054,9 +1054,9 @@ bool Converter::VisitDoStmt(clang::DoStmt *stmt) {
10541054 StrCat (keyword::kLoop );
10551055 {
10561056 PushBrace loop_brace (*this );
1057- curr_for_inc_.emplace (nullptr );
1057+ curr_for_inc_.emplace_back (nullptr );
10581058 Convert (stmt->getBody ());
1059- curr_for_inc_.pop ();
1059+ curr_for_inc_.pop_back ();
10601060 StrCat (keyword::kIf , token::kNot );
10611061 {
10621062 PushParen paren (*this );
@@ -1082,9 +1082,9 @@ bool Converter::VisitForStmt(clang::ForStmt *stmt) {
10821082 }
10831083 {
10841084 PushBrace brace (*this );
1085- curr_for_inc_.emplace (stmt->getInc ());
1085+ curr_for_inc_.emplace_back (stmt->getInc ());
10861086 Convert (stmt->getBody ());
1087- curr_for_inc_.pop ();
1087+ curr_for_inc_.pop_back ();
10881088 Convert (stmt->getInc ());
10891089 StrCat (token::kSemiColon );
10901090 }
@@ -1120,9 +1120,9 @@ void Converter::ConvertForRangeBody(clang::CXXForRangeStmt *stmt,
11201120 std::optional<ScopedMapIterDecl> skip;
11211121 if (map_iter_decl)
11221122 skip.emplace (*this , map_iter_decl);
1123- curr_for_inc_.emplace (nullptr );
1123+ curr_for_inc_.emplace_back (nullptr );
11241124 Convert (stmt->getBody ());
1125- curr_for_inc_.pop ();
1125+ curr_for_inc_.pop_back ();
11261126}
11271127
11281128bool Converter::VisitCXXForRangeStmt (clang::CXXForRangeStmt *stmt) {
@@ -1213,7 +1213,7 @@ bool Converter::VisitBreakStmt([[maybe_unused]] clang::BreakStmt *stmt) {
12131213
12141214bool Converter::VisitContinueStmt ([[maybe_unused]] clang::ContinueStmt *stmt) {
12151215 if (!curr_for_inc_.empty ()) {
1216- Convert (curr_for_inc_.top ());
1216+ Convert (curr_for_inc_.back ());
12171217 StrCat (token::kSemiColon );
12181218 }
12191219 StrCat (keyword::kContinue );
@@ -1256,27 +1256,26 @@ bool Converter::IsSubExprOf(const clang::Expr *sub_expr,
12561256}
12571257
12581258bool Converter::GetFmtArg (clang::Expr *arg, std::string &fmt,
1259- std::string &fmt_args, std::string &fmt_trait,
1259+ std::string &fmt_args, const char * &fmt_trait,
12601260 std::string &fmt_width) {
12611261 std::string arg_str = Mapper::ToString (arg);
12621262 if (clang::isa<clang::StringLiteral>(arg->IgnoreImplicit ())) {
12631263 auto str = GetEscapedStringLiteral (arg);
1264+ std::string_view trim (str);
12641265 // Delete " from string
1265- str.erase (std::remove (str.begin (), str.end (), ' "' ), str.end ());
1266- fmt += std::move (str);
1266+ trim.remove_prefix (1 );
1267+ trim.remove_suffix (1 );
1268+ fmt += trim;
12671269 } else if (auto ch = GetEscapedUTF8CharLiteral (arg); !ch.empty ()) {
12681270 fmt += std::move (ch);
12691271 } else if (arg_str.contains (" std::endl" )) {
12701272 fmt += " \\ n" ;
12711273 } else if (arg_str.contains (" std::hex" )) {
1272- fmt_trait = ' x ' ;
1274+ fmt_trait = " x " ;
12731275 } else if (arg_str.contains (" std::dec" )) {
12741276 fmt_trait = " " ;
12751277 } else if (arg_str.contains (" Setw" )) {
1276- fmt_width = ToString (arg);
1277- // Delete leading and trailing whitespaces
1278- fmt_width.erase (0 , fmt_width.find_first_not_of (' ' ));
1279- fmt_width.erase (fmt_width.find_last_not_of (' ' ) + 1 );
1278+ fmt_width = Trim (ToString (arg));
12801279 } else if (!arg->getType ()->isCharType () &&
12811280 Mapper::Map (arg->getType ()) != " Vec<u8>" ) {
12821281 fmt += (" {:" + fmt_width + fmt_trait + " }" );
@@ -1343,7 +1342,7 @@ void Converter::ConvertCallToOstream(clang::CallExpr *expr) {
13431342 }
13441343
13451344 std::string fmt;
1346- std::string fmt_trait;
1345+ const char * fmt_trait = " " ;
13471346 std::string fmt_width;
13481347 std::string fmt_args;
13491348 std::string raw_args;
@@ -1379,7 +1378,7 @@ void Converter::ConvertCallToOstream(clang::CallExpr *expr) {
13791378 write_raw_args ();
13801379 }
13811380
1382- assert (fmt_trait == " " && " Stream state was not restored after call" );
1381+ assert (* fmt_trait == ' \0 ' && " Stream state was not restored after call" );
13831382}
13841383
13851384void Converter::ConvertPrintf (clang::CallExpr *expr) {
@@ -1766,8 +1765,8 @@ std::string Converter::GetEscapedStringLiteral(clang::Expr *expr,
17661765}
17671766
17681767bool Converter::VisitStringLiteral (clang::StringLiteral *expr) {
1769- if (!curr_init_type_.empty () && curr_init_type_.top ()->isArrayType ()) {
1770- if (auto *arr_ty = ctx_.getAsConstantArrayType (curr_init_type_.top ())) {
1768+ if (!curr_init_type_.empty () && curr_init_type_.back ()->isArrayType ()) {
1769+ if (auto *arr_ty = ctx_.getAsConstantArrayType (curr_init_type_.back ())) {
17711770 uint64_t arr_size = arr_ty->getSize ().getZExtValue ();
17721771 if (expr->getString ().empty ()) {
17731772 StrCat (std::format (" [0u8; {}]" , arr_size));
@@ -2077,8 +2076,8 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) {
20772076 Convert (lhs);
20782077 ConvertCast (computation_result_type);
20792078 }
2080- std::string op ( opcode_as_string) ;
2081- op.erase ( std::remove (op. begin (), op. end (), ' =' ), op. end ());
2079+ auto op = opcode_as_string;
2080+ op.remove_suffix ( 1 ); // remove '=' from operator
20822081 StrCat (op);
20832082 Convert (rhs);
20842083 }
@@ -2778,7 +2777,7 @@ bool Converter::VisitCXXNewExpr(clang::CXXNewExpr *expr) {
27782777 alloc_type_as_string);
27792778 StrCat (new_array_as_string);
27802779 }
2781- if (!curr_init_type_.empty () && curr_init_type_.top ()->isPointerType ()) {
2780+ if (!curr_init_type_.empty () && curr_init_type_.back ()->isPointerType ()) {
27822781 StrCat (" .as_mut_ptr()" );
27832782 }
27842783 } else {
0 commit comments