@@ -139,6 +139,9 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>
139
139
void allocate_array_members_of_struct (ASR::StructType_t* der_type_t , std::string& sub,
140
140
std::string indent, std::string name) {
141
141
for ( auto itr: der_type_t ->m_symtab ->get_scope () ) {
142
+ if ( ASR::is_a<ASR::UnionType_t>(*itr.second ) ) {
143
+ continue ;
144
+ }
142
145
ASR::ttype_t * mem_type = ASRUtils::symbol_type (itr.second );
143
146
if ( ASRUtils::is_character (*mem_type) ) {
144
147
sub += indent + name + " ->" + itr.first + " = (char*) malloc(40 * sizeof(char));\n " ;
@@ -394,7 +397,8 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>
394
397
} else if (ASR::is_a<ASR::Union_t>(*v_m_type)) {
395
398
std::string indent (indentation_level*indentation_spaces, ' ' );
396
399
ASR::Union_t *t = ASR::down_cast<ASR::Union_t>(v_m_type);
397
- std::string der_type_name = ASRUtils::symbol_name (t->m_union_type );
400
+ std::string der_type_name = ASRUtils::symbol_name (
401
+ ASRUtils::symbol_get_past_external (t->m_union_type ));
398
402
if ( is_array ) {
399
403
bool is_fixed_size = true ;
400
404
dims = convert_dims_c (t->n_dims , t->m_dims , v_m_type, is_fixed_size, true );
@@ -682,11 +686,20 @@ R"(
682
686
}
683
687
684
688
template <typename T>
685
- void visit_AggregateTypeUtil (const T& x, std::string c_type_name) {
689
+ void visit_AggregateTypeUtil (const T& x, std::string c_type_name,
690
+ std::string& src_dest) {
691
+ std::string body = " " ;
692
+ int indendation_level_copy = indentation_level;
693
+ for ( auto itr: x.m_symtab ->get_scope () ) {
694
+ if (ASR::is_a<ASR::UnionType_t>(*itr.second )) {
695
+ visit_AggregateTypeUtil (*ASR::down_cast<ASR::UnionType_t>(itr.second ),
696
+ " union" , src_dest);
697
+ }
698
+ }
699
+ indentation_level = indendation_level_copy;
686
700
std::string indent (indentation_level*indentation_spaces, ' ' );
687
701
indentation_level += 1 ;
688
702
std::string open_struct = indent + c_type_name + " " + std::string (x.m_name ) + " {\n " ;
689
- std::string body = " " ;
690
703
indent.push_back (' ' );
691
704
for ( size_t i = 0 ; i < x.n_members ; i++ ) {
692
705
ASR::symbol_t * member = x.m_symtab ->get_symbol (x.m_members [i]);
701
714
}
702
715
indentation_level -= 1 ;
703
716
std::string end_struct = " };\n\n " ;
704
- array_types_decls += open_struct + body + end_struct;
717
+ src_dest += open_struct + body + end_struct;
705
718
}
706
719
707
720
void visit_StructType (const ASR::StructType_t& x) {
@@ -721,12 +734,12 @@ R"(
721
734
attr_args += " )" ;
722
735
c_type_name += " __attribute__(" + attr_args + " )" ;
723
736
}
724
- visit_AggregateTypeUtil (x, c_type_name);
737
+ visit_AggregateTypeUtil (x, c_type_name, array_types_decls );
725
738
src = " " ;
726
739
}
727
740
728
741
void visit_UnionType (const ASR::UnionType_t& x) {
729
- visit_AggregateTypeUtil (x, " union" );
742
+ visit_AggregateTypeUtil (x, " union" , array_types_decls );
730
743
}
731
744
732
745
void visit_EnumType (const ASR::EnumType_t& x) {
0 commit comments