@@ -116,28 +116,9 @@ namespace CUtils {
116
116
return type_src;
117
117
}
118
118
119
- static inline std::string deepcopy (std::string target, std::string value, ASR::ttype_t * m_type) {
120
- switch (m_type->type ) {
121
- case ASR::ttypeType::Character: {
122
- return " strcpy(" + target + " , " + value + " );" ;
123
- }
124
- default : {
125
- return target + " = " + value + " ;" ;
126
- }
127
- }
128
- }
129
-
130
119
} // namespace CUtils
131
120
132
121
133
- namespace CPPUtils {
134
- static inline std::string deepcopy (std::string target, std::string value, ASR::ttype_t * /* m_type*/ ) {
135
- return target + " = " + value + " ;" ;
136
- }
137
- } // namespace CPPUtils
138
-
139
- typedef std::string (*DeepCopyFunction)(std::string, std::string, ASR::ttype_t *);
140
-
141
122
class CCPPDSUtils {
142
123
private:
143
124
@@ -151,19 +132,15 @@ class CCPPDSUtils {
151
132
std::string func_decls;
152
133
153
134
SymbolTable* global_scope;
154
- DeepCopyFunction deepcopy_function ;
135
+ bool is_c ;
155
136
156
137
public:
157
138
158
- CCPPDSUtils () {
139
+ CCPPDSUtils (bool is_c): is_c{is_c} {
159
140
generated_code.clear ();
160
141
func_decls.clear ();
161
142
}
162
143
163
- void set_deepcopy_function (DeepCopyFunction func) {
164
- deepcopy_function = func;
165
- }
166
-
167
144
void set_indentation (int indendation_level_, int indendation_space_) {
168
145
indentation_level = indendation_level_;
169
146
indentation_spaces = indendation_space_;
@@ -174,21 +151,35 @@ class CCPPDSUtils {
174
151
}
175
152
176
153
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::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 + " );" ;
187
- } else if (ASR::is_a<ASR::Character_t>(*t)) {
188
- return " strcpy(" + target + " , " + value + " );" ;
189
- } else {
190
- return target + " = " + value + " ;" ;
154
+ std::string result;
155
+ switch (t->type ) {
156
+ case ASR::ttypeType::List : {
157
+ ASR::List_t* list_type = ASR::down_cast<ASR::List_t>(t);
158
+ std::string list_type_code = ASRUtils::get_type_code (list_type->m_type , true );
159
+ std::string func = typecodeToDSfuncs[list_type_code][" list_deepcopy" ];
160
+ result = func + " (&" + value + " , &" + target + " );" ;
161
+ break ;
162
+ }
163
+ case ASR::ttypeType::Tuple : {
164
+ ASR::Tuple_t* tup_type = ASR::down_cast<ASR::Tuple_t>(t);
165
+ std::string tup_type_code = CUtils::get_tuple_type_code (tup_type);
166
+ std::string func = typecodeToDSfuncs[tup_type_code][" tuple_deepcopy" ];
167
+ result = func + " (" + value + " , &" + target + " );" ;
168
+ break ;
169
+ }
170
+ case ASR::ttypeType::Character : {
171
+ if (is_c) {
172
+ result = " strcpy(" + target + " , " + value + " );" ;
173
+ } else {
174
+ result = target + " = " + value + " ;" ;
175
+ }
176
+ break ;
177
+ }
178
+ default : {
179
+ result = target + " = " + value + " ;" ;
180
+ }
191
181
}
182
+ return result;
192
183
}
193
184
194
185
bool is_non_primitive_DT (ASR::ttype_t *t) {
@@ -522,7 +513,7 @@ class CCPPDSUtils {
522
513
if ( ASR::is_a<ASR::Character_t>(*m_type) ) {
523
514
generated_code += indent + tab + " x->data[pos] = (char*) malloc(40 * sizeof(char));\n " ;
524
515
}
525
- generated_code += indent + tab + deepcopy_function ( " x->data[pos]" , " element " , m_type ) + " \n " ;
516
+ generated_code += indent + tab + get_deepcopy (m_type, " element " , " x->data[pos]" ) + " \n " ;
526
517
generated_code += indent + tab + " x->current_end_point += 1;\n " ;
527
518
generated_code += indent + " }\n\n " ;
528
519
}
0 commit comments