@@ -114,11 +114,23 @@ class PrintListTupleVisitor
114114 list_iter_var_name, al, current_scope, int_type);
115115 }
116116
117+ std::string list_var_name;
118+ ASR::expr_t *list_var;
119+ {
120+ list_var_name =
121+ current_scope->get_unique_name (" __list_var" , false );
122+ list_var = PassUtils::create_auxiliary_variable (loc,
123+ list_var_name, al, current_scope, ASRUtils::expr_type (list_expr));
124+ }
125+
126+ ASR::stmt_t *assign_stmt = ASRUtils::STMT (
127+ ASR::make_Assignment_t (al, loc, list_var, list_expr, nullptr ));
128+
117129 ASR::expr_t *list_item = ASRUtils::EXPR (
118- ASR::make_ListItem_t (al, loc, list_expr ,
130+ ASR::make_ListItem_t (al, loc, list_var ,
119131 list_iter_var, listC->m_type , nullptr ));
120132 ASR::expr_t *list_len = ASRUtils::EXPR (ASR::make_ListLen_t (
121- al, loc, list_expr , int_type, nullptr ));
133+ al, loc, list_var , int_type, nullptr ));
122134 ASR::expr_t *constant_one = ASRUtils::EXPR (
123135 ASR::make_IntegerConstant_t (al, loc, 1 , int_type));
124136 ASR::expr_t *list_len_minus_one =
@@ -199,6 +211,7 @@ class PrintListTupleVisitor
199211 al, loc, nullptr , loop_head, loop_body.p , loop_body.size (), nullptr , 0 ));
200212
201213 {
214+ print_pass_result_tmp.push_back (al, assign_stmt);
202215 print_pass_result_tmp.push_back (al, print_open_bracket);
203216 print_pass_result_tmp.push_back (al, loop);
204217 print_pass_result_tmp.push_back (al, print_close_bracket);
0 commit comments