@@ -173,6 +173,18 @@ class CCPPDSUtils {
173
173
global_scope = global_scope_;
174
174
}
175
175
176
+ std::string get_deepcopy (ASR::ttype_t *t, std::string value, std::string target) {
177
+ if (ASR::is_a<ASR::List_t>(*t)) {
178
+ ASR::List_t* list_type = ASR::down_cast<ASR::List_t>(t);
179
+ std::string list_type_code = ASRUtils::get_type_code (list_type->m_type , true );
180
+ std::string func = typecodeToDSfuncs[list_type_code][" list_deepcopy" ];
181
+ return func + " (&" + value + " , &" + target + " );" ;
182
+ } else if (ASR::is_a<ASR::Character_t>(*t)) {
183
+ return " strcpy(" + target + " , " + value + " );" ;
184
+ }
185
+ LFORTRAN_ASSERT (false );
186
+ }
187
+
176
188
bool is_non_primitive_DT (ASR::ttype_t *t) {
177
189
return ASR::is_a<ASR::List_t>(*t) || ASR::is_a<ASR::Tuple_t>(*t);
178
190
}
@@ -469,14 +481,8 @@ class CCPPDSUtils {
469
481
if ( ASR::is_a<ASR::Character_t>(*m_type) ) {
470
482
generated_code += indent + tab + " x->data[x->current_end_point] = (char*) malloc(40 * sizeof(char));\n " ;
471
483
}
472
- if (ASR::is_a<ASR::List_t>(*m_type)) {
473
- ASR::ttype_t *tt = ASR::down_cast<ASR::List_t>(m_type)->m_type ;
474
- std::string deep_copy_func = typecodeToDSfuncs[ASRUtils::get_type_code (tt, true )][" list_deepcopy" ];
475
- LFORTRAN_ASSERT (deep_copy_func.size () > 0 );
476
- generated_code += indent + tab + deep_copy_func + " (&element, &x->data[x->current_end_point]);\n " ;
477
- } else {
478
- generated_code += indent + tab + deepcopy_function (" x->data[x->current_end_point]" , " element" , m_type) + " \n " ;
479
- }
484
+ generated_code += indent + generated_code += indent + tab + \
485
+ get_deepcopy (m_type, " element" , " x->data[x->current_end_point]" ) + " \n " ;
480
486
generated_code += indent + tab + " x->current_end_point += 1;\n " ;
481
487
generated_code += indent + " }\n\n " ;
482
488
}
0 commit comments