@@ -205,13 +205,14 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>
205
205
ASR::ttype_t * element_type, bool & is_fixed_size,
206
206
bool convert_to_1d=false )
207
207
{
208
- std::string dims;
208
+ std::string dims = " " ;
209
209
size_t size = 1 ;
210
210
std::string array_size = " " ;
211
211
for (size_t i=0 ; i<n_dims; i++) {
212
212
ASR::expr_t *length = m_dims[i].m_length ;
213
213
if (!length) {
214
- dims += " *" ;
214
+ is_fixed_size = false ;
215
+ return dims;
215
216
} else {
216
217
visit_expr (*length);
217
218
array_size += " *" + src;
@@ -285,7 +286,11 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>
285
286
if ( !is_fixed_size ) {
286
287
sub += indent + format_type_c (" *" , type_name_copy, std::string (v_m_name) + " _data" ,
287
288
use_ref, dummy);
288
- sub += " = " + dims + " ;\n " ;
289
+ if ( dims.size () > 0 ) {
290
+ sub += " = " + dims + " ;\n " ;
291
+ } else {
292
+ sub += " ;\n " ;
293
+ }
289
294
} else {
290
295
sub += indent + format_type_c (dims, type_name_copy, std::string (v_m_name) + " _data" ,
291
296
use_ref, dummy) + " ;\n " ;
@@ -360,14 +365,25 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>
360
365
} else if (ASR::is_a<ASR::Struct_t>(*t2)) {
361
366
ASR::Struct_t *t = ASR::down_cast<ASR::Struct_t>(t2);
362
367
std::string der_type_name = ASRUtils::symbol_name (t->m_derived_type );
363
- bool is_fixed_size = true ;
364
- std::string dims = convert_dims_c (t->n_dims , t->m_dims , v_m_type, is_fixed_size);
365
- std::string ptr_char = " *" ;
366
- if ( !use_ptr_for_derived_type ) {
367
- ptr_char.clear ();
368
+ if ( is_array ) {
369
+ bool is_fixed_size = true ;
370
+ std::string dims = convert_dims_c (t->n_dims , t->m_dims , v_m_type, is_fixed_size, true );
371
+ std::string encoded_type_name = " x" + der_type_name;
372
+ std::string type_name = std::string (" struct " ) + der_type_name;
373
+ generate_array_decl (sub, std::string (v.m_name ), type_name, dims,
374
+ encoded_type_name, t->m_dims , t->n_dims ,
375
+ use_ref, dummy,
376
+ v.m_intent != ASRUtils::intent_in &&
377
+ v.m_intent != ASRUtils::intent_inout,
378
+ is_fixed_size);
379
+ } else {
380
+ std::string ptr_char = " *" ;
381
+ if ( !use_ptr_for_derived_type ) {
382
+ ptr_char.clear ();
383
+ }
384
+ sub = format_type_c (" " , " struct " + der_type_name + ptr_char,
385
+ v.m_name , use_ref, dummy);
368
386
}
369
- sub = format_type_c (dims, " struct " + der_type_name + ptr_char,
370
- v.m_name , use_ref, dummy);
371
387
} else if (ASR::is_a<ASR::CPtr_t>(*t2)) {
372
388
sub = format_type_c (" " , " void**" , v.m_name , false , false );
373
389
} else {
0 commit comments