@@ -179,6 +179,11 @@ class CCPPDSUtils {
179179                std::string list_type_code = ASRUtils::get_type_code (list_type->m_type , true );
180180                std::string func = typecodeToDSfuncs[list_type_code][" list_deepcopy" 
181181                return  func + " (&" " , &" " );" 
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 + " (" " , &" " );" 
182187            } else  if  (ASR::is_a<ASR::Character_t>(*t)) {
183188                return  " strcpy(" " , " " );" 
184189            }
@@ -567,6 +572,12 @@ class CCPPDSUtils {
567572            generated_code += indent + " }\n\n " 
568573        }
569574
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+ 
570581        std::string get_tuple_type (ASR::Tuple_t* tuple_type) {
571582            std::string tuple_type_code = CUtils::get_tuple_type_code (tuple_type);
572583            if  (typecodeToDStype.find (tuple_type_code) != typecodeToDStype.end ()) {
@@ -590,9 +601,35 @@ class CCPPDSUtils {
590601            tmp_gen += indent + " };\n\n " 
591602            func_decls += tmp_gen;
592603            generate_compare_funcs ((ASR::ttype_t  *)tuple_type);
604+             tuple_deepcopy (tuple_type, tuple_type_code);
593605            return  tuple_struct_type;
594606        }
595607
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_" 
612+             typecodeToDSfuncs[tuple_type_code][" tuple_deepcopy" 
613+             std::string tuple_struct_type = typecodeToDStype[tuple_type_code];
614+             std::string signature = " void " " (" 
615+                                 + tuple_struct_type + "  src, " 
616+                                 + tuple_struct_type + " * dest)" 
617+             std::string tmp_def = " " " " 
618+             tmp_def += " inline " " ;\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_" "  = " 
624+                                 " (char *) malloc(40*sizeof(char));\n " 
625+                 }
626+                 tmp_gen += indent + tab + get_deepcopy (t->m_type [i], " src.element_" 
627+                                 " data->element_" " \n " 
628+             }
629+             tmp_gen += indent + " }\n\n " 
630+             func_decls += tmp_def;
631+             generated_code += tmp_gen;
632+         }
596633
597634        ~CCPPDSUtils () {
598635            typecodeToDStype.clear ();
0 commit comments