@@ -726,40 +726,50 @@ static inline void encode_dimensions(size_t n_dims, std::string& res,
726
726
}
727
727
728
728
static inline std::string get_type_code (const ASR::ttype_t *t, bool use_underscore_sep=false ,
729
- bool encode_dimensions_=true )
729
+ bool encode_dimensions_=true , bool set_dimensional_hint= true )
730
730
{
731
+ bool is_dimensional = false ;
732
+ std::string res = " " ;
731
733
switch (t->type ) {
732
734
case ASR::ttypeType::Integer: {
733
735
ASR::Integer_t *integer = ASR::down_cast<ASR::Integer_t>(t);
734
- std::string res = " i" + std::to_string (integer->m_kind * 8 );
736
+ res = " i" + std::to_string (integer->m_kind * 8 );
735
737
if ( encode_dimensions_ ) {
736
738
encode_dimensions (integer->n_dims , res, use_underscore_sep);
739
+ return res;
737
740
}
738
- return res;
741
+ is_dimensional = integer->n_dims > 0 ;
742
+ break ;
739
743
}
740
744
case ASR::ttypeType::Real: {
741
745
ASR::Real_t *real = ASR::down_cast<ASR::Real_t>(t);
742
- std::string res = " r" + std::to_string (real->m_kind * 8 );
746
+ res = " r" + std::to_string (real->m_kind * 8 );
743
747
if ( encode_dimensions_ ) {
744
748
encode_dimensions (real->n_dims , res, use_underscore_sep);
749
+ return res;
745
750
}
746
- return res;
751
+ is_dimensional = real->n_dims > 0 ;
752
+ break ;
747
753
}
748
754
case ASR::ttypeType::Complex: {
749
755
ASR::Complex_t *complx = ASR::down_cast<ASR::Complex_t>(t);
750
- std::string res = " c" + std::to_string (complx->m_kind * 8 );
756
+ res = " c" + std::to_string (complx->m_kind * 8 );
751
757
if ( encode_dimensions_ ) {
752
758
encode_dimensions (complx->n_dims , res, use_underscore_sep);
759
+ return res;
753
760
}
754
- return res;
761
+ is_dimensional = complx->n_dims > 0 ;
762
+ break ;
755
763
}
756
764
case ASR::ttypeType::Logical: {
757
765
ASR::Logical_t* bool_ = ASR::down_cast<ASR::Logical_t>(t);
758
766
std::string res = " bool" ;
759
767
if ( encode_dimensions_ ) {
760
768
encode_dimensions (bool_->n_dims , res, use_underscore_sep);
769
+ return res;
761
770
}
762
- return res;
771
+ is_dimensional = bool_->n_dims > 0 ;
772
+ break ;
763
773
}
764
774
case ASR::ttypeType::Character: {
765
775
return " str" ;
@@ -773,7 +783,8 @@ static inline std::string get_type_code(const ASR::ttype_t *t, bool use_undersco
773
783
result += " [" ;
774
784
}
775
785
for (size_t i = 0 ; i < tup->n_type ; i++) {
776
- result += get_type_code (tup->m_type [i], use_underscore_sep, encode_dimensions_);
786
+ result += get_type_code (tup->m_type [i], use_underscore_sep,
787
+ encode_dimensions_, set_dimensional_hint);
777
788
if (i + 1 != tup->n_type ) {
778
789
if ( use_underscore_sep ) {
779
790
result += " _" ;
@@ -792,64 +803,80 @@ static inline std::string get_type_code(const ASR::ttype_t *t, bool use_undersco
792
803
case ASR::ttypeType::Set: {
793
804
ASR::Set_t *s = ASR::down_cast<ASR::Set_t>(t);
794
805
if ( use_underscore_sep ) {
795
- return " set_" + get_type_code (s->m_type , use_underscore_sep, encode_dimensions_) + " _" ;
806
+ return " set_" + get_type_code (s->m_type , use_underscore_sep,
807
+ encode_dimensions_, set_dimensional_hint) + " _" ;
796
808
}
797
- return " set[" + get_type_code (s->m_type , use_underscore_sep, encode_dimensions_) + " ]" ;
809
+ return " set[" + get_type_code (s->m_type , use_underscore_sep,
810
+ encode_dimensions_, set_dimensional_hint) + " ]" ;
798
811
}
799
812
case ASR::ttypeType::Dict: {
800
813
ASR::Dict_t *d = ASR::down_cast<ASR::Dict_t>(t);
801
814
if ( use_underscore_sep ) {
802
- return " dict_" + get_type_code (d->m_key_type , use_underscore_sep, encode_dimensions_) +
803
- " _" + get_type_code (d->m_value_type , use_underscore_sep, encode_dimensions_) + " _" ;
815
+ return " dict_" + get_type_code (d->m_key_type , use_underscore_sep,
816
+ encode_dimensions_, set_dimensional_hint) +
817
+ " _" + get_type_code (d->m_value_type , use_underscore_sep,
818
+ encode_dimensions_, set_dimensional_hint) + " _" ;
804
819
}
805
- return " dict[" + get_type_code (d->m_key_type , use_underscore_sep, encode_dimensions_) +
806
- " , " + get_type_code (d->m_value_type , use_underscore_sep, encode_dimensions_) + " ]" ;
820
+ return " dict[" + get_type_code (d->m_key_type , use_underscore_sep,
821
+ encode_dimensions_, set_dimensional_hint) +
822
+ " , " + get_type_code (d->m_value_type , use_underscore_sep,
823
+ encode_dimensions_, set_dimensional_hint) + " ]" ;
807
824
}
808
825
case ASR::ttypeType::List: {
809
826
ASR::List_t *l = ASR::down_cast<ASR::List_t>(t);
810
827
if ( use_underscore_sep ) {
811
- return " list_" + get_type_code (l->m_type , use_underscore_sep, encode_dimensions_) + " _" ;
828
+ return " list_" + get_type_code (l->m_type , use_underscore_sep,
829
+ encode_dimensions_, set_dimensional_hint) + " _" ;
812
830
}
813
- return " list[" + get_type_code (l->m_type , use_underscore_sep, encode_dimensions_) + " ]" ;
831
+ return " list[" + get_type_code (l->m_type , use_underscore_sep,
832
+ encode_dimensions_, set_dimensional_hint) + " ]" ;
814
833
}
815
834
case ASR::ttypeType::CPtr: {
816
835
return " CPtr" ;
817
836
}
818
837
case ASR::ttypeType::Struct: {
819
838
ASR::Struct_t* d = ASR::down_cast<ASR::Struct_t>(t);
820
- std::string res = symbol_name (d->m_derived_type );
839
+ res = symbol_name (d->m_derived_type );
821
840
if ( encode_dimensions_ ) {
822
841
encode_dimensions (d->n_dims , res, use_underscore_sep);
842
+ return res;
823
843
}
824
- return res;
844
+ is_dimensional = d->n_dims > 0 ;
845
+ break ;
825
846
}
826
847
case ASR::ttypeType::Union: {
827
848
ASR::Union_t* d = ASR::down_cast<ASR::Union_t>(t);
828
- std::string res = symbol_name (d->m_union_type );
849
+ res = symbol_name (d->m_union_type );
829
850
if ( encode_dimensions_ ) {
830
851
encode_dimensions (d->n_dims , res, use_underscore_sep);
852
+ return res;
831
853
}
832
- return res;
854
+ is_dimensional = d->n_dims > 0 ;
855
+ break ;
833
856
}
834
857
case ASR::ttypeType::Pointer: {
835
858
ASR::Pointer_t* p = ASR::down_cast<ASR::Pointer_t>(t);
836
859
if ( use_underscore_sep ) {
837
- return " Pointer_" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_) + " _" ;
860
+ return " Pointer_" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_, set_dimensional_hint ) + " _" ;
838
861
}
839
- return " Pointer[" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_) + " ]" ;
862
+ return " Pointer[" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_, set_dimensional_hint ) + " ]" ;
840
863
}
841
864
case ASR::ttypeType::Const: {
842
865
ASR::Const_t* p = ASR::down_cast<ASR::Const_t>(t);
843
866
if ( use_underscore_sep ) {
844
- return " Const_" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_) + " _" ;
867
+ return " Const_" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_, set_dimensional_hint ) + " _" ;
845
868
}
846
- return " Const[" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_) + " ]" ;
869
+ return " Const[" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_, set_dimensional_hint ) + " ]" ;
847
870
}
848
871
default : {
849
872
throw LCompilersException (" Type encoding not implemented for "
850
873
+ std::to_string (t->type ));
851
874
}
852
875
}
876
+ if ( is_dimensional && set_dimensional_hint ) {
877
+ res += " dim" ;
878
+ }
879
+ return res;
853
880
}
854
881
855
882
static inline std::string get_type_code (ASR::ttype_t ** types, size_t n_types,
0 commit comments