@@ -179,6 +179,11 @@ class CCPPDSUtils {
179
179
std::string list_type_code = ASRUtils::get_type_code (list_type->m_type , true );
180
180
std::string func = typecodeToDSfuncs[list_type_code][" list_deepcopy" ];
181
181
return func + " (&" + value + " , &" + target + " );" ;
182
+ } else if (ASR::is_a<ASR::Tuple_t>(*t)) {
183
+ ASR::Tuple_t* tup_type = ASR::down_cast<ASR::Tuple_t>(t);
184
+ std::string tup_type_code = CUtils::get_tuple_type_code (tup_type);
185
+ std::string func = typecodeToDSfuncs[tup_type_code][" tuple_deepcopy" ];
186
+ return func + " (" + value + " , &" + target + " );" ;
182
187
} else if (ASR::is_a<ASR::Character_t>(*t)) {
183
188
return " strcpy(" + target + " , " + value + " );" ;
184
189
}
@@ -567,6 +572,12 @@ class CCPPDSUtils {
567
572
generated_code += indent + " }\n\n " ;
568
573
}
569
574
575
+ std::string get_tuple_deepcopy_func (ASR::Tuple_t* tup_type) {
576
+ std::string tuple_type_code = CUtils::get_tuple_type_code (tup_type);
577
+ return typecodeToDSfuncs[tuple_type_code][" tuple_deepcopy" ];
578
+ }
579
+
580
+
570
581
std::string get_tuple_type (ASR::Tuple_t* tuple_type) {
571
582
std::string tuple_type_code = CUtils::get_tuple_type_code (tuple_type);
572
583
if (typecodeToDStype.find (tuple_type_code) != typecodeToDStype.end ()) {
@@ -590,9 +601,35 @@ class CCPPDSUtils {
590
601
tmp_gen += indent + " };\n\n " ;
591
602
func_decls += tmp_gen;
592
603
generate_compare_funcs ((ASR::ttype_t *)tuple_type);
604
+ tuple_deepcopy (tuple_type, tuple_type_code);
593
605
return tuple_struct_type;
594
606
}
595
607
608
+ void tuple_deepcopy (ASR::Tuple_t *t, std::string tuple_type_code) {
609
+ std::string indent (indentation_level * indentation_spaces, ' ' );
610
+ std::string tab (indentation_spaces, ' ' );
611
+ std::string tup_dc_func = global_scope->get_unique_name (" tuple_deepcopy_" + tuple_type_code);
612
+ typecodeToDSfuncs[tuple_type_code][" tuple_deepcopy" ] = tup_dc_func;
613
+ std::string tuple_struct_type = typecodeToDStype[tuple_type_code];
614
+ std::string signature = " void " + tup_dc_func + " ("
615
+ + tuple_struct_type + " src, "
616
+ + tuple_struct_type + " * dest)" ;
617
+ std::string tmp_def = " " , tmp_gen = " " ;
618
+ tmp_def += " inline " + signature + " ;\n " ;
619
+ tmp_gen += indent + signature + " {\n " ;
620
+ for (size_t i=0 ; i<t->n_type ; i++) {
621
+ std::string n = std::to_string (i);
622
+ if (ASR::is_a<ASR::Character_t>(*t->m_type [i])) {
623
+ tmp_gen += indent + tab + " data->element_" + n + " = " + \
624
+ " (char *) malloc(40*sizeof(char));\n " ;
625
+ }
626
+ tmp_gen += indent + tab + get_deepcopy (t->m_type [i], " src.element_" + n,
627
+ " data->element_" + n) + " \n " ;
628
+ }
629
+ tmp_gen += indent + " }\n\n " ;
630
+ func_decls += tmp_def;
631
+ generated_code += tmp_gen;
632
+ }
596
633
597
634
~CCPPDSUtils () {
598
635
typecodeToDStype.clear ();
0 commit comments