@@ -1012,6 +1012,33 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
10121012 this ->visit_expr (*x.m_arg );
10131013 }
10141014
1015+ std::string construct_call_args (size_t n_args, ASR::call_arg_t * m_args) {
1016+ bracket_open++;
1017+ std::string args = " " ;
1018+ for (size_t i=0 ; i<n_args; i++) {
1019+ if (ASR::is_a<ASR::Var_t>(*m_args[i].m_value )) {
1020+ ASR::Variable_t *arg = ASRUtils::EXPR2VAR (m_args[i].m_value );
1021+ std::string arg_name = arg->m_name ;
1022+ if ( ASRUtils::is_array (arg->m_type ) &&
1023+ ASRUtils::is_pointer (arg->m_type ) ) {
1024+ args += " &" + arg_name;
1025+ } else {
1026+ args += arg_name;
1027+ }
1028+ } else {
1029+ self ().visit_expr (*m_args[i].m_value );
1030+ if ( ASR::is_a<ASR::Struct_t>(*ASRUtils::expr_type (m_args[i].m_value )) ) {
1031+ args += " &" + src;
1032+ } else {
1033+ args += src;
1034+ }
1035+ }
1036+ if (i < n_args-1 ) args += " , " ;
1037+ }
1038+ bracket_open--;
1039+ return args;
1040+ }
1041+
10151042 void visit_FunctionCall (const ASR::FunctionCall_t &x) {
10161043 CHECK_FAST_C_CPP (compiler_options, x)
10171044 ASR::Function_t *fn = ASR::down_cast<ASR::Function_t>(
@@ -1052,15 +1079,7 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
10521079 + " ' not implemented" );
10531080 }
10541081 } else {
1055- std::string args;
1056- bracket_open++;
1057- for (size_t i=0 ; i<x.n_args ; i++) {
1058- self ().visit_expr (*x.m_args [i].m_value );
1059- args += src;
1060- if (i < x.n_args -1 ) args += " , " ;
1061- }
1062- bracket_open--;
1063- src = fn_name + " (" + args + " )" ;
1082+ src = fn_name + " (" + construct_call_args (x.n_args , x.m_args ) + " )" ;
10641083 }
10651084 last_expr_precedence = 2 ;
10661085 if ( ASR::is_a<ASR::List_t>(*x.m_type ) ) {
@@ -2739,30 +2758,7 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
27392758 if (sym_name == " main" ) {
27402759 sym_name = " _xx_lcompilers_changed_main_xx" ;
27412760 }
2742- std::string out = indent + sym_name + " (" ;
2743- for (size_t i=0 ; i<x.n_args ; i++) {
2744- if (ASR::is_a<ASR::Var_t>(*x.m_args [i].m_value )) {
2745- ASR::Variable_t *arg = ASRUtils::EXPR2VAR (x.m_args [i].m_value );
2746- std::string arg_name = arg->m_name ;
2747- if ( ASRUtils::is_array (arg->m_type ) &&
2748- ASRUtils::is_pointer (arg->m_type ) ) {
2749- out += " &" + arg_name;
2750- } else {
2751- out += arg_name;
2752- }
2753- } else {
2754- self ().visit_expr (*x.m_args [i].m_value );
2755- if ( ASR::is_a<ASR::ArrayItem_t>(*x.m_args [i].m_value ) ||
2756- ASR::is_a<ASR::Struct_t>(*ASRUtils::expr_type (x.m_args [i].m_value )) ) {
2757- out += " &" + src;
2758- } else {
2759- out += src;
2760- }
2761- }
2762- if (i < x.n_args -1 ) out += " , " ;
2763- }
2764- out += " );\n " ;
2765- src = out;
2761+ src = indent + sym_name + " (" + construct_call_args (x.n_args , x.m_args ) + " );\n " ;
27662762 }
27672763
27682764 #define SET_INTRINSIC_NAME (X, func_name ) \
0 commit comments