9
9
#include < libasr/assert.h>
10
10
#include < libasr/asr.h>
11
11
#include < libasr/string_utils.h>
12
+ #include < libasr/utils.h>
12
13
13
14
namespace LFortran {
14
15
15
16
namespace ASRUtils {
16
17
17
18
static inline double extract_real (const char *s) {
18
- return std::atof (s);
19
- }
19
+ // TODO: this is inefficient. We should
20
+ // convert this in the tokenizer where we know most information
21
+ std::string x = s;
22
+ x = replace (x, " d" , " e" );
23
+ x = replace (x, " D" , " E" );
24
+ return std::atof (x.c_str ());
25
+ }
20
26
21
27
static inline ASR::expr_t * EXPR (const ASR::asr_t *f)
22
28
{
@@ -664,16 +670,16 @@ static inline bool extract_value(ASR::expr_t* value_expr, T& value) {
664
670
value = (T) const_int->m_n ;
665
671
break ;
666
672
}
667
- case ASR::exprType::LogicalConstant: {
668
- ASR::LogicalConstant_t* const_logical = ASR::down_cast<ASR::LogicalConstant_t>(value_expr);
669
- value = (T) const_logical->m_value ;
670
- break ;
671
- }
672
673
case ASR::exprType::RealConstant: {
673
674
ASR::RealConstant_t* const_real = ASR::down_cast<ASR::RealConstant_t>(value_expr);
674
675
value = (T) const_real->m_r ;
675
676
break ;
676
677
}
678
+ case ASR::exprType::LogicalConstant: {
679
+ ASR::LogicalConstant_t* const_logical = ASR::down_cast<ASR::LogicalConstant_t>(value_expr);
680
+ value = (T) const_logical->m_value ;
681
+ break ;
682
+ }
677
683
default :
678
684
return false ;
679
685
}
@@ -768,7 +774,7 @@ static inline std::string get_type_code(const ASR::ttype_t *t, bool use_undersco
768
774
}
769
775
case ASR::ttypeType::Logical: {
770
776
ASR::Logical_t* bool_ = ASR::down_cast<ASR::Logical_t>(t);
771
- std::string res = " bool" ;
777
+ res = " bool" ;
772
778
if ( encode_dimensions_ ) {
773
779
encode_dimensions (bool_->n_dims , res, use_underscore_sep);
774
780
return res;
@@ -862,16 +868,20 @@ static inline std::string get_type_code(const ASR::ttype_t *t, bool use_undersco
862
868
case ASR::ttypeType::Pointer: {
863
869
ASR::Pointer_t* p = ASR::down_cast<ASR::Pointer_t>(t);
864
870
if ( use_underscore_sep ) {
865
- return " Pointer_" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_, set_dimensional_hint) + " _" ;
871
+ return " Pointer_" + get_type_code (p->m_type , use_underscore_sep,
872
+ encode_dimensions_, set_dimensional_hint) + " _" ;
866
873
}
867
- return " Pointer[" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_, set_dimensional_hint) + " ]" ;
874
+ return " Pointer[" + get_type_code (p->m_type , use_underscore_sep,
875
+ encode_dimensions_, set_dimensional_hint) + " ]" ;
868
876
}
869
877
case ASR::ttypeType::Const: {
870
878
ASR::Const_t* p = ASR::down_cast<ASR::Const_t>(t);
871
879
if ( use_underscore_sep ) {
872
- return " Const_" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_, set_dimensional_hint) + " _" ;
880
+ return " Const_" + get_type_code (p->m_type , use_underscore_sep,
881
+ encode_dimensions_, set_dimensional_hint) + " _" ;
873
882
}
874
- return " Const[" + get_type_code (p->m_type , use_underscore_sep, encode_dimensions_, set_dimensional_hint) + " ]" ;
883
+ return " Const[" + get_type_code (p->m_type , use_underscore_sep,
884
+ encode_dimensions_, set_dimensional_hint) + " ]" ;
875
885
}
876
886
default : {
877
887
throw LCompilersException (" Type encoding not implemented for "
@@ -1115,7 +1125,7 @@ std::vector<std::string> determine_module_dependencies(
1115
1125
const ASR::TranslationUnit_t &unit);
1116
1126
1117
1127
std::vector<std::string> determine_function_definition_order (
1118
- SymbolTable* symtab);
1128
+ SymbolTable* symtab);
1119
1129
1120
1130
void extract_module_python (const ASR::TranslationUnit_t &m,
1121
1131
std::vector<std::pair<std::string, ASR::Module_t*>>& children_modules,
@@ -1126,13 +1136,13 @@ ASR::Module_t* extract_module(const ASR::TranslationUnit_t &m);
1126
1136
ASR::Module_t* load_module (Allocator &al, SymbolTable *symtab,
1127
1137
const std::string &module_name,
1128
1138
const Location &loc, bool intrinsic,
1129
- const std::string &rl_path ,
1139
+ LCompilers::PassOptions& pass_options ,
1130
1140
bool run_verify,
1131
1141
const std::function<void (const std::string &, const Location &)> err);
1132
1142
1133
1143
ASR::TranslationUnit_t* find_and_load_module (Allocator &al, const std::string &msym,
1134
1144
SymbolTable &symtab, bool intrinsic,
1135
- const std::string &rl_path );
1145
+ LCompilers::PassOptions& pass_options );
1136
1146
1137
1147
void set_intrinsic (ASR::TranslationUnit_t* trans_unit);
1138
1148
@@ -1189,8 +1199,8 @@ static inline int extract_kind_from_ttype_t(const ASR::ttype_t* type) {
1189
1199
return extract_kind_from_ttype_t (ASR::down_cast<ASR::Pointer_t>(type)->m_type );
1190
1200
}
1191
1201
case ASR::ttypeType::Const: {
1192
- return extract_kind_from_ttype_t (ASR::down_cast<ASR::Const_t>(type)->m_type );
1193
- }
1202
+ return extract_kind_from_ttype_t (ASR::down_cast<ASR::Const_t>(type)->m_type );
1203
+ }
1194
1204
default : {
1195
1205
return -1 ;
1196
1206
}
@@ -1350,6 +1360,11 @@ inline int extract_dimensions_from_ttype(ASR::ttype_t *x,
1350
1360
return n_dims;
1351
1361
}
1352
1362
1363
+ inline int extract_n_dims_from_ttype (ASR::ttype_t *x) {
1364
+ ASR::dimension_t * m_dims_temp = nullptr ;
1365
+ return extract_dimensions_from_ttype (x, m_dims_temp);
1366
+ }
1367
+
1353
1368
// Sets the dimension member of `ttype_t`. Returns `true` if dimensions set.
1354
1369
// Returns `false` if the `ttype_t` does not have a dimension member.
1355
1370
inline bool ttype_set_dimensions (ASR::ttype_t *x,
0 commit comments