@@ -617,6 +617,90 @@ static inline std::string type_python_1dim_helper(const std::string & res,
617
617
return res;
618
618
}
619
619
620
+ static inline void encode_dimensions (size_t n_dims, std::string& res) {
621
+ if ( n_dims > 0 ) {
622
+ res += " [" ;
623
+ }
624
+ for ( size_t i = 0 ; i < n_dims; i++ ) {
625
+ res += " :" ;
626
+ if ( i == n_dims - 1 ) {
627
+ res += " ]" ;
628
+ } else {
629
+ res += " , " ;
630
+ }
631
+ }
632
+ }
633
+
634
+ static inline std::string get_type_code (const ASR::ttype_t *t)
635
+ {
636
+ switch (t->type ) {
637
+ case ASR::ttypeType::Integer: {
638
+ ASR::Integer_t *integer = ASR::down_cast<ASR::Integer_t>(t);
639
+ std::string res = " i" + std::to_string (integer->m_kind * 8 );
640
+ encode_dimensions (integer->n_dims , res);
641
+ return res;
642
+ }
643
+ case ASR::ttypeType::Real: {
644
+ ASR::Real_t *real = ASR::down_cast<ASR::Real_t>(t);
645
+ std::string res = " r" + std::to_string (real->m_kind * 8 );
646
+ encode_dimensions (real->n_dims , res);
647
+ return res;
648
+ }
649
+ case ASR::ttypeType::Complex: {
650
+ ASR::Complex_t *complx = ASR::down_cast<ASR::Complex_t>(t);
651
+ std::string res = " r" + std::to_string (complx->m_kind * 8 );
652
+ encode_dimensions (complx->n_dims , res);
653
+ return res;
654
+ }
655
+ case ASR::ttypeType::Logical: {
656
+ return " bool" ;
657
+ }
658
+ case ASR::ttypeType::Character: {
659
+ return " str" ;
660
+ }
661
+ case ASR::ttypeType::Tuple: {
662
+ ASR::Tuple_t *tup = ASR::down_cast<ASR::Tuple_t>(t);
663
+ std::string result = " tuple[" ;
664
+ for (size_t i = 0 ; i < tup->n_type ; i++) {
665
+ result += get_type_code (tup->m_type [i]);
666
+ if (i + 1 != tup->n_type ) {
667
+ result += " , " ;
668
+ }
669
+ }
670
+ result += " ]" ;
671
+ return result;
672
+ }
673
+ case ASR::ttypeType::Set: {
674
+ ASR::Set_t *s = ASR::down_cast<ASR::Set_t>(t);
675
+ return " set[" + get_type_code (s->m_type ) + " ]" ;
676
+ }
677
+ case ASR::ttypeType::Dict: {
678
+ ASR::Dict_t *d = ASR::down_cast<ASR::Dict_t>(t);
679
+ return " dict[" + get_type_code (d->m_key_type ) +
680
+ " , " + get_type_code (d->m_value_type ) + " ]" ;
681
+ }
682
+ case ASR::ttypeType::List: {
683
+ ASR::List_t *l = ASR::down_cast<ASR::List_t>(t);
684
+ return " list[" + get_type_code (l->m_type ) + " ]" ;
685
+ }
686
+ case ASR::ttypeType::CPtr: {
687
+ return " CPtr" ;
688
+ }
689
+ case ASR::ttypeType::Derived: {
690
+ ASR::Derived_t* d = ASR::down_cast<ASR::Derived_t>(t);
691
+ return symbol_name (d->m_derived_type );
692
+ }
693
+ case ASR::ttypeType::Pointer: {
694
+ ASR::Pointer_t* p = ASR::down_cast<ASR::Pointer_t>(t);
695
+ return " Pointer[" + get_type_code (p->m_type ) + " ]" ;
696
+ }
697
+ default : {
698
+ throw LCompilersException (" Type encoding not implemented for "
699
+ + std::to_string (t->type ));
700
+ }
701
+ }
702
+ }
703
+
620
704
static inline std::string type_to_str_python (const ASR::ttype_t *t,
621
705
bool for_error_message=true )
622
706
{
0 commit comments