@@ -605,39 +605,59 @@ static inline std::string type_python_1dim_helper(const std::string & res,
605
605
return res;
606
606
}
607
607
608
- static inline void encode_dimensions (size_t n_dims, std::string& res) {
609
- if ( n_dims > 0 ) {
608
+ static inline void encode_dimensions (size_t n_dims, std::string& res,
609
+ bool use_underscore_sep=false ) {
610
+ if ( n_dims == 0 ) {
611
+ return ;
612
+ }
613
+
614
+ if ( use_underscore_sep ) {
615
+ res += " _" ;
616
+ } else {
610
617
res += " [" ;
611
618
}
619
+
612
620
for ( size_t i = 0 ; i < n_dims; i++ ) {
613
- res += " :" ;
621
+ if ( use_underscore_sep ) {
622
+ res += " _" ;
623
+ } else {
624
+ res += " :" ;
625
+ }
614
626
if ( i == n_dims - 1 ) {
615
- res += " ]" ;
627
+ if ( use_underscore_sep ) {
628
+ res += " _" ;
629
+ } else {
630
+ res += " ]" ;
631
+ }
616
632
} else {
617
- res += " , " ;
633
+ if ( use_underscore_sep ) {
634
+ res += " _" ;
635
+ } else {
636
+ res += " , " ;
637
+ }
618
638
}
619
639
}
620
640
}
621
641
622
- static inline std::string get_type_code (const ASR::ttype_t *t)
642
+ static inline std::string get_type_code (const ASR::ttype_t *t, bool use_underscore_sep= false )
623
643
{
624
644
switch (t->type ) {
625
645
case ASR::ttypeType::Integer: {
626
646
ASR::Integer_t *integer = ASR::down_cast<ASR::Integer_t>(t);
627
647
std::string res = " i" + std::to_string (integer->m_kind * 8 );
628
- encode_dimensions (integer->n_dims , res);
648
+ encode_dimensions (integer->n_dims , res, use_underscore_sep );
629
649
return res;
630
650
}
631
651
case ASR::ttypeType::Real: {
632
652
ASR::Real_t *real = ASR::down_cast<ASR::Real_t>(t);
633
653
std::string res = " r" + std::to_string (real->m_kind * 8 );
634
- encode_dimensions (real->n_dims , res);
654
+ encode_dimensions (real->n_dims , res, use_underscore_sep );
635
655
return res;
636
656
}
637
657
case ASR::ttypeType::Complex: {
638
658
ASR::Complex_t *complx = ASR::down_cast<ASR::Complex_t>(t);
639
659
std::string res = " r" + std::to_string (complx->m_kind * 8 );
640
- encode_dimensions (complx->n_dims , res);
660
+ encode_dimensions (complx->n_dims , res, use_underscore_sep );
641
661
return res;
642
662
}
643
663
case ASR::ttypeType::Logical: {
@@ -648,28 +668,51 @@ static inline std::string get_type_code(const ASR::ttype_t *t)
648
668
}
649
669
case ASR::ttypeType::Tuple: {
650
670
ASR::Tuple_t *tup = ASR::down_cast<ASR::Tuple_t>(t);
651
- std::string result = " tuple[" ;
671
+ std::string result = " tuple" ;
672
+ if ( use_underscore_sep ) {
673
+ result += " _" ;
674
+ } else {
675
+ result += " [" ;
676
+ }
652
677
for (size_t i = 0 ; i < tup->n_type ; i++) {
653
- result += get_type_code (tup->m_type [i]);
678
+ result += get_type_code (tup->m_type [i], use_underscore_sep );
654
679
if (i + 1 != tup->n_type ) {
655
- result += " , " ;
680
+ if ( use_underscore_sep ) {
681
+ result += " _" ;
682
+ } else {
683
+ result += " , " ;
684
+ }
656
685
}
657
686
}
658
- result += " ]" ;
687
+ if ( use_underscore_sep ) {
688
+ result += " _" ;
689
+ } else {
690
+ result += " ]" ;
691
+ }
659
692
return result;
660
693
}
661
694
case ASR::ttypeType::Set: {
662
695
ASR::Set_t *s = ASR::down_cast<ASR::Set_t>(t);
663
- return " set[" + get_type_code (s->m_type ) + " ]" ;
696
+ if ( use_underscore_sep ) {
697
+ return " set_" + get_type_code (s->m_type , use_underscore_sep) + " _" ;
698
+ }
699
+ return " set[" + get_type_code (s->m_type , use_underscore_sep) + " ]" ;
664
700
}
665
701
case ASR::ttypeType::Dict: {
666
702
ASR::Dict_t *d = ASR::down_cast<ASR::Dict_t>(t);
667
- return " dict[" + get_type_code (d->m_key_type ) +
668
- " , " + get_type_code (d->m_value_type ) + " ]" ;
703
+ if ( use_underscore_sep ) {
704
+ return " dict_" + get_type_code (d->m_key_type , use_underscore_sep) +
705
+ " _" + get_type_code (d->m_value_type , use_underscore_sep) + " _" ;
706
+ }
707
+ return " dict[" + get_type_code (d->m_key_type , use_underscore_sep) +
708
+ " , " + get_type_code (d->m_value_type , use_underscore_sep) + " ]" ;
669
709
}
670
710
case ASR::ttypeType::List: {
671
711
ASR::List_t *l = ASR::down_cast<ASR::List_t>(t);
672
- return " list[" + get_type_code (l->m_type ) + " ]" ;
712
+ if ( use_underscore_sep ) {
713
+ return " list_" + get_type_code (l->m_type , use_underscore_sep) + " _" ;
714
+ }
715
+ return " list[" + get_type_code (l->m_type , use_underscore_sep) + " ]" ;
673
716
}
674
717
case ASR::ttypeType::CPtr: {
675
718
return " CPtr" ;
@@ -680,7 +723,10 @@ static inline std::string get_type_code(const ASR::ttype_t *t)
680
723
}
681
724
case ASR::ttypeType::Pointer: {
682
725
ASR::Pointer_t* p = ASR::down_cast<ASR::Pointer_t>(t);
683
- return " Pointer[" + get_type_code (p->m_type ) + " ]" ;
726
+ if ( use_underscore_sep ) {
727
+ return " Pointer_" + get_type_code (p->m_type , use_underscore_sep) + " _" ;
728
+ }
729
+ return " Pointer[" + get_type_code (p->m_type , use_underscore_sep) + " ]" ;
684
730
}
685
731
default : {
686
732
throw LCompilersException (" Type encoding not implemented for "
@@ -689,10 +735,11 @@ static inline std::string get_type_code(const ASR::ttype_t *t)
689
735
}
690
736
}
691
737
692
- static inline std::string get_type_code (ASR::ttype_t ** types, size_t n_types) {
738
+ static inline std::string get_type_code (ASR::ttype_t ** types, size_t n_types,
739
+ bool use_underscore_sep=false ) {
693
740
std::string code = " " ;
694
741
for ( size_t i = 0 ; i < n_types; i++ ) {
695
- code += get_type_code (types[i]) + " _" ;
742
+ code += get_type_code (types[i], use_underscore_sep ) + " _" ;
696
743
}
697
744
return code;
698
745
}
0 commit comments