88#include < clang/Basic/LangOptions.h>
99#include < clang/Basic/SourceManager.h>
1010#include < clang/Basic/Version.h>
11+ #include < clang/Sema/Template.h>
1112#include < llvm/ADT/DenseMap.h>
1213#include < llvm/Support/ConvertUTF.h>
1314#include < llvm/Support/ErrorHandling.h>
@@ -1766,15 +1767,6 @@ void Converter::ConvertPrintf(clang::CallExpr *expr) {
17661767 StrCat (' )' );
17671768}
17681769
1769- std::optional<std::string> Converter::TryPluginConvert (clang::CallExpr *call) {
1770- if (emplace_back_plugin_match (call)) {
1771- Buffer buf (*this );
1772- emplace_back_plugin_convert (call);
1773- return std::move (buf).str ();
1774- }
1775- return std::nullopt ;
1776- }
1777-
17781770void Converter::ConvertVariadicArg (clang::Expr *arg) {
17791771 if (arg->getType ()->isFunctionPointerType ()) {
17801772 Convert (arg);
@@ -1829,12 +1821,6 @@ bool Converter::VisitCallExpr(clang::CallExpr *expr) {
18291821 return false ;
18301822 }
18311823
1832- if (auto plugin_str = TryPluginConvert (expr)) {
1833- StrCat (*plugin_str);
1834- SetFreshType (expr->getType ());
1835- return false ;
1836- }
1837-
18381824 if (Mapper::Contains (expr->getCallee ())) {
18391825 if (Mapper::IsLibcPassthrough (GetCalleeOrExpr (expr))) {
18401826 ConvertGenericCallExpr (expr);
@@ -3625,6 +3611,7 @@ void Converter::ConvertArrayCXXConstructExpr(clang::CXXConstructExpr *expr) {
36253611}
36263612
36273613void Converter::ConvertCXXConstructExprArgs (clang::CXXConstructExpr *expr) {
3614+ HoistMaterializedTempBindings hoist_temps (*this , /* as_block=*/ true );
36283615 auto ctor = expr->getConstructor ();
36293616 StrCat (GetRecordName (ctor->getParent ()), token::kDoubleColon ,
36303617 GetCtorName (ctor));
@@ -3647,7 +3634,6 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) {
36473634 if (arg_idx < expr->getNumArgs ()) {
36483635 clang::Expr *arg = expr->getArg (arg_idx++);
36493636 PushBrace brace (*this );
3650- HoistMaterializedTempBindings hoist_temps (*this );
36513637
36523638 if (has_default) {
36533639 StrCat (" Some(" );
@@ -5044,6 +5030,8 @@ std::string Converter::ConvertIRFragment(
50445030 result += ConvertPlaceholder (expr, arg, ph_ctx);
50455031 } else if (std::get_if<TranslationRule::VaArgsFragment>(&frag)) {
50465032 result += ConvertVariadicTail (expr, all_args);
5033+ } else if (std::get_if<TranslationRule::InitFragment>(&frag)) {
5034+ result += ConvertInitFragment (expr, all_args);
50475035 } else if (auto *mc =
50485036 std::get_if<std::unique_ptr<MethodCallFragment>>(&frag)) {
50495037 result += ConvertMappedMethodCall (expr, **mc, args, num_args, ctx);
@@ -5072,6 +5060,43 @@ Converter::ConvertVariadicTail(clang::Expr *expr,
50725060 return std::move (buf).str ();
50735061}
50745062
5063+ std::string
5064+ Converter::ConvertInitFragment (clang::Expr *expr,
5065+ const std::vector<clang::Expr *> &all_args) {
5066+ const auto *tgt_ir = Mapper::GetExprRule (GetCalleeOrExpr (expr));
5067+ assert (tgt_ir && tgt_ir->init_type .valid ());
5068+ auto *callee = clang::cast<clang::CallExpr>(expr)->getDirectCallee ();
5069+ assert (callee);
5070+ auto type = GetSema ()
5071+ .getTemplateInstantiationArgs (callee)(tgt_ir->init_type .depth ,
5072+ tgt_ir->init_type .index )
5073+ .getAsType ();
5074+
5075+ Buffer buf (*this );
5076+ ConvertConstructFromArgs (
5077+ type, llvm::ArrayRef (all_args).drop_front (tgt_ir->params .size ()),
5078+ expr->getExprLoc ());
5079+ return std::move (buf).str ();
5080+ }
5081+
5082+ void Converter::ConvertConstructFromArgs (clang::QualType type,
5083+ llvm::ArrayRef<clang::Expr *> args,
5084+ clang::SourceLocation loc) {
5085+ auto *init = BuildInitExpr (GetSema (), type, args, loc);
5086+ assert (init && " type cannot be initialized from the arguments" );
5087+ if (auto *ctor =
5088+ clang::dyn_cast<clang::CXXConstructExpr>(init->IgnoreImplicit ())) {
5089+ ConvertConstructedValue (type, ctor);
5090+ return ;
5091+ }
5092+
5093+ if (args.empty ()) {
5094+ StrCat (GetDefaultAsString (type));
5095+ return ;
5096+ }
5097+ Convert (init);
5098+ }
5099+
50755100std::string Converter::AccessLValueObject (clang::MemberExpr *member) {
50765101 auto *object = member->getBase ();
50775102 auto type = object->getType ();
@@ -5170,9 +5195,9 @@ void Converter::dump_expr_kinds() {
51705195 << " , isVoid: " << isVoid () << ' \n ' ;
51715196}
51725197
5173- void Converter::emplace_back_plugin_construct_arg (
5174- clang::QualType elem_type, clang::CXXConstructExpr *ctor) {
5175- ConvertVarInit (elem_type , ctor);
5198+ void Converter::ConvertConstructedValue (clang::QualType type,
5199+ clang::CXXConstructExpr *ctor) {
5200+ ConvertVarInit (type , ctor);
51765201}
51775202
51785203const char *Converter::GetPointerDerefPrefix (clang::QualType pointee_type) {
0 commit comments