@@ -116,27 +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
-
140
122
class CCPPDSUtils {
141
123
private:
142
124
@@ -150,10 +132,11 @@ class CCPPDSUtils {
150
132
std::string func_decls;
151
133
152
134
SymbolTable* global_scope;
135
+ bool is_c;
153
136
154
137
public:
155
138
156
- CCPPDSUtils () {
139
+ CCPPDSUtils (bool is_c): is_c{is_c} {
157
140
generated_code.clear ();
158
141
func_decls.clear ();
159
142
}
@@ -168,21 +151,35 @@ class CCPPDSUtils {
168
151
}
169
152
170
153
std::string get_deepcopy (ASR::ttype_t *t, std::string value, std::string target) {
171
- if (ASR::is_a<ASR::List_t>(*t)) {
172
- ASR::List_t* list_type = ASR::down_cast<ASR::List_t>(t);
173
- std::string list_type_code = ASRUtils::get_type_code (list_type->m_type , true );
174
- std::string func = typecodeToDSfuncs[list_type_code][" list_deepcopy" ];
175
- return func + " (&" + value + " , &" + target + " );" ;
176
- } else if (ASR::is_a<ASR::Tuple_t>(*t)) {
177
- ASR::Tuple_t* tup_type = ASR::down_cast<ASR::Tuple_t>(t);
178
- std::string tup_type_code = CUtils::get_tuple_type_code (tup_type);
179
- std::string func = typecodeToDSfuncs[tup_type_code][" tuple_deepcopy" ];
180
- return func + " (" + value + " , &" + target + " );" ;
181
- } else if (ASR::is_a<ASR::Character_t>(*t)) {
182
- return " strcpy(" + target + " , " + value + " );" ;
183
- } else {
184
- 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
+ }
185
181
}
182
+ return result;
186
183
}
187
184
188
185
bool is_non_primitive_DT (ASR::ttype_t *t) {
0 commit comments