@@ -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>(
@@ -4295,7 +4292,7 @@ std::string Converter::GetArrayDefaultAsString(clang::QualType qual_type) {
42954292 if (clang::isa<clang::IncompleteArrayType>(qual_type)) {
42964293 return " []" ;
42974294 }
4298- if (Printer::ToString (ctx_, qual_type). contains ( " std:: array" )) {
4295+ if (IsStdDecl ( qual_type-> getAsCXXRecordDecl (), " array" )) {
42994296 assert (GetTemplateArgs (qual_type).has_value ());
43004297 auto template_args = *GetTemplateArgs (qual_type);
43014298 assert (template_args.size () == 2 );
@@ -4505,24 +4502,7 @@ void Converter::ConvertVarInit(clang::QualType qual_type, clang::Expr *expr) {
45054502 StrCat (keyword_mut_);
45064503 }
45074504 }
4508- auto *ignore_casts = expr->IgnoreCasts ();
4509- // FIXME: this looks very complicated
4510- if (auto *ctor = clang::dyn_cast<clang::CXXConstructExpr>(ignore_casts);
4511- ctor && ctor->getNumArgs () != 0 && IsReferenceType (ctor->getArg (0 )) &&
4512- clang::isa<clang::CallExpr>(ctor->getArg (0 )->IgnoreCasts ()) &&
4513- !Mapper::Contains (
4514- ctx_, clang::cast<clang::CallExpr>(ctor->getArg (0 )->IgnoreCasts ())
4515- ->getCallee ()) &&
4516- Printer::ToString (ctx_, ctor->getConstructor ()->getThisType ()) ==
4517- " std::string" ) {
4518- {
4519- PushParen paren (*this );
4520- StrCat (token::kStar );
4521- PushInitType init_type (*this , qual_type);
4522- Convert (expr);
4523- }
4524- StrCat (" .clone()" );
4525- } else if (IsReferenceType (expr) || qual_type->isFunctionPointerType ()) {
4505+ if (IsReferenceType (expr) || qual_type->isFunctionPointerType ()) {
45264506 PushExprKind push (*this , ExprKind::AddrOf);
45274507 PushInitType init_type (*this , qual_type);
45284508 Convert (expr, qual_type);
0 commit comments