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>
@@ -1787,15 +1788,6 @@ void Converter::ConvertPrintf(clang::CallExpr *expr) {
17871788 StrCat (' )' );
17881789}
17891790
1790- std::optional<std::string> Converter::TryPluginConvert (clang::CallExpr *call) {
1791- if (emplace_back_plugin_match (call)) {
1792- Buffer buf (*this );
1793- emplace_back_plugin_convert (call);
1794- return std::move (buf).str ();
1795- }
1796- return std::nullopt ;
1797- }
1798-
17991791void Converter::ConvertVariadicArg (clang::Expr *arg) {
18001792 if (arg->getType ()->isFunctionPointerType ()) {
18011793 Convert (arg);
@@ -1850,12 +1842,6 @@ bool Converter::VisitCallExpr(clang::CallExpr *expr) {
18501842 return false ;
18511843 }
18521844
1853- if (auto plugin_str = TryPluginConvert (expr)) {
1854- StrCat (*plugin_str);
1855- SetFreshType (expr->getType ());
1856- return false ;
1857- }
1858-
18591845 if (Mapper::Contains (expr->getCallee ())) {
18601846 if (Mapper::IsLibcPassthrough (GetCalleeOrExpr (expr))) {
18611847 ConvertGenericCallExpr (expr);
@@ -1986,8 +1972,10 @@ Converter::CallInfo Converter::CollectCallInfo(clang::CallExpr *expr) {
19861972 proto = ptr_ty->getPointeeType ()->getAs <clang::FunctionProtoType>();
19871973 }
19881974 }
1989- assert ((function || proto) &&
1990- " Either function decl or function prototype should be known" );
1975+ if (!function && !proto) {
1976+ llvm::report_fatal_error (
1977+ " Either function decl or function prototype should be known" );
1978+ }
19911979
19921980 unsigned num_args = expr->getNumArgs () - arg_begin;
19931981 unsigned num_named_params =
@@ -3620,6 +3608,7 @@ void Converter::ConvertArrayCXXConstructExpr(clang::CXXConstructExpr *expr) {
36203608}
36213609
36223610void Converter::ConvertCXXConstructExprArgs (clang::CXXConstructExpr *expr) {
3611+ HoistMaterializedTempBindings hoist_temps (*this , /* as_block=*/ true );
36233612 auto ctor = expr->getConstructor ();
36243613 StrCat (GetRecordName (ctor->getParent ()), token::kDoubleColon ,
36253614 GetCtorName (ctor));
@@ -3642,7 +3631,6 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) {
36423631 if (arg_idx < expr->getNumArgs ()) {
36433632 clang::Expr *arg = expr->getArg (arg_idx++);
36443633 PushBrace brace (*this );
3645- HoistMaterializedTempBindings hoist_temps (*this );
36463634
36473635 if (has_default) {
36483636 StrCat (" Some(" );
@@ -5054,6 +5042,8 @@ std::string Converter::ConvertIRFragment(
50545042 result += ConvertPlaceholder (expr, arg, ph_ctx);
50555043 } else if (std::get_if<TranslationRule::VaArgsFragment>(&frag)) {
50565044 result += ConvertVariadicTail (expr, all_args);
5045+ } else if (std::get_if<TranslationRule::InitFragment>(&frag)) {
5046+ result += ConvertInitFragment (expr, all_args);
50575047 } else if (auto *mc =
50585048 std::get_if<std::unique_ptr<MethodCallFragment>>(&frag)) {
50595049 result += ConvertMappedMethodCall (expr, **mc, args, num_args, ctx);
@@ -5082,6 +5072,43 @@ Converter::ConvertVariadicTail(clang::Expr *expr,
50825072 return std::move (buf).str ();
50835073}
50845074
5075+ std::string
5076+ Converter::ConvertInitFragment (clang::Expr *expr,
5077+ const std::vector<clang::Expr *> &all_args) {
5078+ const auto *tgt_ir = Mapper::GetExprRule (GetCalleeOrExpr (expr));
5079+ assert (tgt_ir && tgt_ir->init_type .valid ());
5080+ auto *callee = clang::cast<clang::CallExpr>(expr)->getDirectCallee ();
5081+ assert (callee);
5082+ auto type = GetSema ()
5083+ .getTemplateInstantiationArgs (callee)(tgt_ir->init_type .depth ,
5084+ tgt_ir->init_type .index )
5085+ .getAsType ();
5086+
5087+ Buffer buf (*this );
5088+ ConvertConstructFromArgs (
5089+ type, llvm::ArrayRef (all_args).drop_front (tgt_ir->params .size ()),
5090+ expr->getExprLoc ());
5091+ return std::move (buf).str ();
5092+ }
5093+
5094+ void Converter::ConvertConstructFromArgs (clang::QualType type,
5095+ llvm::ArrayRef<clang::Expr *> args,
5096+ clang::SourceLocation loc) {
5097+ auto *init = BuildInitExpr (GetSema (), type, args, loc);
5098+ assert (init && " type cannot be initialized from the arguments" );
5099+ if (auto *ctor =
5100+ clang::dyn_cast<clang::CXXConstructExpr>(init->IgnoreImplicit ())) {
5101+ ConvertConstructedValue (type, ctor);
5102+ return ;
5103+ }
5104+
5105+ if (args.empty ()) {
5106+ StrCat (GetDefaultAsString (type));
5107+ return ;
5108+ }
5109+ Convert (init);
5110+ }
5111+
50855112std::string Converter::AccessLValueObject (clang::MemberExpr *member) {
50865113 auto *object = member->getBase ();
50875114 auto type = object->getType ();
@@ -5180,9 +5207,9 @@ void Converter::dump_expr_kinds() {
51805207 << " , isVoid: " << isVoid () << ' \n ' ;
51815208}
51825209
5183- void Converter::emplace_back_plugin_construct_arg (
5184- clang::QualType elem_type, clang::CXXConstructExpr *ctor) {
5185- ConvertVarInit (elem_type , ctor);
5210+ void Converter::ConvertConstructedValue (clang::QualType type,
5211+ clang::CXXConstructExpr *ctor) {
5212+ ConvertVarInit (type , ctor);
51865213}
51875214
51885215const char *Converter::GetPointerDerefPrefix (clang::QualType pointee_type) {
0 commit comments