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