@@ -1720,7 +1720,6 @@ const clang::Expr *Converter::GetParentExpr(const clang::Expr *expr) {
17201720bool Converter::GetFmtArg (clang::Expr *arg, std::string &fmt,
17211721 std::string &fmt_args, const char *&fmt_trait,
17221722 std::string &fmt_width) {
1723- std::string arg_str = Printer::ToString (ctx_, arg);
17241723 if (auto *str_lit =
17251724 clang::dyn_cast<clang::StringLiteral>(arg->IgnoreImplicit ())) {
17261725 if (!IsAsciiStringLiteral (str_lit)) {
@@ -1734,20 +1733,20 @@ bool Converter::GetFmtArg(clang::Expr *arg, std::string &fmt,
17341733 fmt += trim;
17351734 } else if (auto ch = GetEscapedUTF8CharLiteral (arg); !ch.empty ()) {
17361735 fmt += std::move (ch);
1737- } else if (arg_str. contains ( " std:: endl" )) {
1736+ } else if (IsStdFunction (arg, " endl" )) {
17381737 fmt += " \\ n" ;
1739- } else if (arg_str. contains ( " std:: hex" )) {
1738+ } else if (IsStdFunction (arg, " hex" )) {
17401739 fmt_trait = " x" ;
1741- } else if (arg_str. contains ( " std:: dec" )) {
1740+ } else if (IsStdFunction (arg, " dec" )) {
17421741 fmt_trait = " " ;
1743- } else if (arg_str. contains ( " Setw " )) {
1742+ } else if (IsStdFunction (arg, " setw " )) {
17441743 fmt_width = Trim (ToString (arg));
17451744 } else if (!arg->getType ()->isCharType () &&
17461745 Mapper::Map (*this , arg->getType ()) !=
17471746 std::format (" Vec<{}>" , CharRustType ())) {
17481747 fmt += (" {:" + fmt_width + fmt_trait + " }" );
17491748 fmt_width.clear (); // Reset setw after first usage
1750- arg_str = ToString (arg);
1749+ auto arg_str = ToString (arg);
17511750 if (arg->getType ()->isBooleanType ()) {
17521751 arg_str = std::format (" ({} as u8)" , std::move (arg_str));
17531752 }
@@ -1767,7 +1766,7 @@ bool Converter::GetRawArg(clang::Expr *arg, std::string &raw_args) {
17671766 std::string str = ToString (arg);
17681767 raw_args += " (&(" + str + " ).iter().take((" + str +
17691768 " ).len() - 1).map(|&c| c as u8).collect::<Vec<u8>>()[..]" ;
1770- } else if (Printer::ToString (ctx_, arg). contains ( " std:: endl" )) {
1769+ } else if (IsStdFunction (arg, " endl" )) {
17711770 raw_args += " (&[b'\\ n']" ;
17721771 } else if (clang::isa<clang::StringLiteral>(arg->IgnoreImplicit ())) {
17731772 raw_args += " (b" + GetEscapedStringLiteral (arg);
@@ -1853,8 +1852,7 @@ void Converter::ConvertCallToOstream(clang::CallExpr *expr) {
18531852}
18541853
18551854void Converter::ConvertPrintf (clang::CallExpr *expr) {
1856- bool is_fprintf =
1857- Printer::ToString (ctx_, expr->getCallee ()).starts_with (" int fprintf" );
1855+ bool is_fprintf = IsCDecl (expr->getDirectCallee (), " fprintf" );
18581856
18591857 StrCat (" printf(" );
18601858 for (unsigned i = is_fprintf; i < expr->getNumArgs (); ++i) {
@@ -2338,9 +2336,8 @@ std::optional<Converter::TempMaterializationCtx>
23382336Converter::ConvertCallExpr (clang::CallExpr *expr) {
23392337 auto *callee = expr->getCallee ();
23402338
2341- auto fn = Printer::ToString (ctx_, callee);
2342- bool is_printf = fn.starts_with (" int printf" );
2343- bool is_fprintf = fn.starts_with (" int fprintf" );
2339+ bool is_printf = IsCDecl (expr->getDirectCallee (), " printf" );
2340+ bool is_fprintf = IsCDecl (expr->getDirectCallee (), " fprintf" );
23442341 unsigned format_arg = is_fprintf ? 1 : 0 ;
23452342 if ((is_printf || is_fprintf) &&
23462343 clang::isa<clang::StringLiteral>(
@@ -4289,7 +4286,7 @@ std::string Converter::GetArrayDefaultAsString(clang::QualType qual_type) {
42894286 if (clang::isa<clang::IncompleteArrayType>(qual_type)) {
42904287 return " []" ;
42914288 }
4292- if (Printer::ToString (ctx_, qual_type). contains ( " std:: array" )) {
4289+ if (IsStdDecl ( qual_type-> getAsCXXRecordDecl (), " array" )) {
42934290 assert (GetTemplateArgs (qual_type).has_value ());
42944291 auto template_args = *GetTemplateArgs (qual_type);
42954292 assert (template_args.size () == 2 );
@@ -4499,24 +4496,7 @@ void Converter::ConvertVarInit(clang::QualType qual_type, clang::Expr *expr) {
44994496 StrCat (keyword_mut_);
45004497 }
45014498 }
4502- auto *ignore_casts = expr->IgnoreCasts ();
4503- // FIXME: this looks very complicated
4504- if (auto *ctor = clang::dyn_cast<clang::CXXConstructExpr>(ignore_casts);
4505- ctor && ctor->getNumArgs () != 0 && IsReferenceType (ctor->getArg (0 )) &&
4506- clang::isa<clang::CallExpr>(ctor->getArg (0 )->IgnoreCasts ()) &&
4507- !Mapper::Contains (
4508- ctx_, clang::cast<clang::CallExpr>(ctor->getArg (0 )->IgnoreCasts ())
4509- ->getCallee ()) &&
4510- Printer::ToString (ctx_, ctor->getConstructor ()->getThisType ()) ==
4511- " std::string" ) {
4512- {
4513- PushParen paren (*this );
4514- StrCat (token::kStar );
4515- PushInitType init_type (*this , qual_type);
4516- Convert (expr);
4517- }
4518- StrCat (" .clone()" );
4519- } else if (IsReferenceType (expr) || qual_type->isFunctionPointerType ()) {
4499+ if (IsReferenceType (expr) || qual_type->isFunctionPointerType ()) {
45204500 PushExprKind push (*this , ExprKind::AddrOf);
45214501 PushInitType init_type (*this , qual_type);
45224502 Convert (expr, qual_type);
0 commit comments