@@ -594,6 +594,7 @@ class CCPPDSUtils {
594594 list_remove (list_struct_type, list_type_code, list_element_type, list_type->m_type );
595595 list_clear (list_struct_type, list_type_code, list_element_type);
596596 list_concat (list_struct_type, list_type_code, list_element_type, list_type->m_type );
597+ list_repeat (list_struct_type, list_type_code, list_element_type, list_type->m_type );
597598 list_section (list_struct_type, list_type_code);
598599 return list_struct_type;
599600 }
@@ -652,6 +653,11 @@ class CCPPDSUtils {
652653 return typecodeToDSfuncs[list_type_code][" list_concat" ];
653654 }
654655
656+ std::string get_list_repeat_func (ASR::List_t* list_type) {
657+ std::string list_type_code = ASRUtils::get_type_code (list_type->m_type , true );
658+ return typecodeToDSfuncs[list_type_code][" list_repeat" ];
659+ }
660+
655661 std::string get_list_find_item_position_function (std::string list_type_code) {
656662 return typecodeToDSfuncs[list_type_code][" list_find_item" ];
657663 }
@@ -934,6 +940,40 @@ class CCPPDSUtils {
934940 generated_code += indent + " }\n\n " ;
935941 }
936942
943+ void list_repeat (std::string list_struct_type,
944+ std::string list_type_code,
945+ std::string list_element_type, ASR::ttype_t *m_type) {
946+ std::string indent (indentation_level * indentation_spaces, ' ' );
947+ std::string tab (indentation_spaces, ' ' );
948+ std::string list_con_func = global_scope->get_unique_name (" list_repeat_" + list_type_code);
949+ typecodeToDSfuncs[list_type_code][" list_repeat" ] = list_con_func;
950+ std::string init_func = typecodeToDSfuncs[list_type_code][" list_init" ];
951+ std::string signature = list_struct_type + " * " + list_con_func + " ("
952+ + list_struct_type + " * x, "
953+ + " int32_t freq)" ;
954+ func_decls += " inline " + signature + " ;\n " ;
955+ generated_code += indent + signature + " {\n " ;
956+ generated_code += indent + tab + list_struct_type + " *result = (" + list_struct_type + " *)malloc(sizeof(" +
957+ list_struct_type + " ));\n " ;
958+ generated_code += indent + tab + init_func + " (result, x->current_end_point * freq);\n " ;
959+ generated_code += indent + tab + " for (int i=0; i<freq; i++) {\n " ;
960+
961+ if (ASR::is_a<ASR::List_t>(*m_type)) {
962+ ASR::ttype_t *tt = ASR::down_cast<ASR::List_t>(m_type)->m_type ;
963+ std::string deep_copy_func = typecodeToDSfuncs[ASRUtils::get_type_code (tt, true )][" list_deepcopy" ];
964+ LCOMPILERS_ASSERT (deep_copy_func.size () > 0 );
965+ generated_code += indent + tab + tab + " for(int j=0; j<x->current_end_point; j++)\n " ;
966+ generated_code += indent + tab + tab + tab + deep_copy_func + " (&x->data[j], &result->data[i*x->current_end_point+j]);\n " ;
967+ } else {
968+ generated_code += indent + tab + tab + " memcpy(&result->data[i*x->current_end_point], x->data, x->current_end_point * sizeof(" + list_element_type + " ));\n " ;
969+ }
970+
971+ generated_code += indent + tab + " }\n " ;
972+ generated_code += indent + tab + " result->current_end_point = x->current_end_point * freq;\n " ;
973+ generated_code += indent + tab + " return result;\n " ;
974+ generated_code += indent + " }\n\n " ;
975+ }
976+
937977 void resize_if_needed (std::string list_struct_type,
938978 std::string list_type_code,
939979 std::string list_element_type) {
0 commit comments