@@ -237,6 +237,9 @@ static inline ASR::abiType symbol_abi(const ASR::symbol_t *f)
237
237
case ASR::symbolType::ExternalSymbol: {
238
238
return symbol_abi (ASR::down_cast<ASR::ExternalSymbol_t>(f)->m_external );
239
239
}
240
+ case ASR::symbolType::Function: {
241
+ return ASRUtils::get_FunctionType (*ASR::down_cast<ASR::Function_t>(f))->m_abi ;
242
+ }
240
243
default : {
241
244
throw LCompilersException (" Cannot return ABI of, " +
242
245
std::to_string (f->type ) + " symbol." );
@@ -1982,6 +1985,74 @@ static inline bool is_only_upper_bound_empty(ASR::dimension_t& dim) {
1982
1985
return (dim.m_start != nullptr && dim.m_length == nullptr );
1983
1986
}
1984
1987
1988
+ class ExprDependentOnlyOnArguments : public ASR ::BaseWalkVisitor<ExprDependentOnlyOnArguments> {
1989
+
1990
+ public:
1991
+
1992
+ bool is_dependent_only_on_argument;
1993
+
1994
+ ExprDependentOnlyOnArguments (): is_dependent_only_on_argument(false )
1995
+ {}
1996
+
1997
+ void visit_Var (const ASR::Var_t& x) {
1998
+ if ( ASR::is_a<ASR::Variable_t>(*x.m_v ) ) {
1999
+ ASR::Variable_t* x_m_v = ASR::down_cast<ASR::Variable_t>(x.m_v );
2000
+ is_dependent_only_on_argument = is_dependent_only_on_argument && ASRUtils::is_arg_dummy (x_m_v->m_intent );
2001
+ } else {
2002
+ is_dependent_only_on_argument = false ;
2003
+ }
2004
+ }
2005
+ };
2006
+
2007
+ static inline bool is_dimension_dependent_only_on_arguments (ASR::dimension_t * m_dims, size_t n_dims) {
2008
+ ExprDependentOnlyOnArguments visitor;
2009
+ for ( size_t i = 0 ; i < n_dims; i++ ) {
2010
+ visitor.is_dependent_only_on_argument = true ;
2011
+ if ( m_dims[i].m_length == nullptr ) {
2012
+ return false ;
2013
+ }
2014
+ visitor.visit_expr (*m_dims[i].m_length );
2015
+ if ( !visitor.is_dependent_only_on_argument ) {
2016
+ return false ;
2017
+ }
2018
+ }
2019
+ return true ;
2020
+ }
2021
+
2022
+ static inline ASR::asr_t * make_ArraySize_t_util (
2023
+ Allocator &al, const Location &a_loc, ASR::expr_t * a_v,
2024
+ ASR::expr_t * a_dim, ASR::ttype_t * a_type, ASR::expr_t * a_value,
2025
+ bool for_type=true ) {
2026
+ if ( ASR::is_a<ASR::ArrayPhysicalCast_t>(*a_v) ) {
2027
+ a_v = ASR::down_cast<ASR::ArrayPhysicalCast_t>(a_v)->m_arg ;
2028
+ }
2029
+
2030
+ ASR::dimension_t * m_dims = nullptr ;
2031
+ size_t n_dims = ASRUtils::extract_dimensions_from_ttype (ASRUtils::expr_type (a_v), m_dims);
2032
+ bool is_dimension_dependent_only_on_arguments_ = is_dimension_dependent_only_on_arguments (m_dims, n_dims);
2033
+ int dim = -1 ;
2034
+ bool is_dimension_constant = (a_dim != nullptr ) && ASRUtils::extract_value (ASRUtils::expr_value (a_dim), dim);
2035
+
2036
+ bool compute_size = (is_dimension_dependent_only_on_arguments_ &&
2037
+ (is_dimension_constant || a_dim == nullptr ));
2038
+ if ( compute_size && for_type ) {
2039
+ ASR::dimension_t * m_dims = nullptr ;
2040
+ size_t n_dims = ASRUtils::extract_dimensions_from_ttype (ASRUtils::expr_type (a_v), m_dims);
2041
+ if ( a_dim == nullptr ) {
2042
+ ASR::asr_t * size = ASR::make_IntegerConstant_t (al, a_loc, 1 , a_type);
2043
+ for ( size_t i = 0 ; i < n_dims; i++ ) {
2044
+ size = ASR::make_IntegerBinOp_t (al, a_loc, ASRUtils::EXPR (size),
2045
+ ASR::binopType::Mul, m_dims[i].m_length , a_type, nullptr );
2046
+ }
2047
+ return size;
2048
+ } else if ( is_dimension_constant ) {
2049
+ return (ASR::asr_t *) m_dims[dim - 1 ].m_length ;
2050
+ }
2051
+ }
2052
+
2053
+ return ASR::make_ArraySize_t (al, a_loc, a_v, a_dim, a_type, a_value);
2054
+ }
2055
+
1985
2056
inline ASR::ttype_t * make_Array_t_util (Allocator& al, const Location& loc,
1986
2057
ASR::ttype_t * type, ASR::dimension_t * m_dims, size_t n_dims,
1987
2058
ASR::abiType abi=ASR::abiType::Source, bool is_argument=false ,
@@ -1991,6 +2062,14 @@ inline ASR::ttype_t* make_Array_t_util(Allocator& al, const Location& loc,
1991
2062
return type;
1992
2063
}
1993
2064
2065
+ for ( size_t i = 0 ; i < n_dims; i++ ) {
2066
+ if ( m_dims[i].m_length && ASR::is_a<ASR::ArraySize_t>(*m_dims[i].m_length ) ) {
2067
+ ASR::ArraySize_t* as = ASR::down_cast<ASR::ArraySize_t>(m_dims[i].m_length );
2068
+ m_dims[i].m_length = ASRUtils::EXPR (ASRUtils::make_ArraySize_t_util (
2069
+ al, as->base .base .loc , as->m_v , as->m_dim , as->m_type , nullptr ));
2070
+ }
2071
+ }
2072
+
1994
2073
if ( !override_physical_type ) {
1995
2074
if ( abi == ASR::abiType::BindC ) {
1996
2075
physical_type = ASR::array_physical_typeType::PointerToDataArray;
@@ -3228,40 +3307,6 @@ class ReplaceFunctionParamVisitor: public ASR::BaseExprReplacer<ReplaceFunctionP
3228
3307
3229
3308
};
3230
3309
3231
- class ExprDependentOnlyOnArguments : public ASR ::BaseWalkVisitor<ExprDependentOnlyOnArguments> {
3232
-
3233
- public:
3234
-
3235
- bool is_dependent_only_on_argument;
3236
-
3237
- ExprDependentOnlyOnArguments (): is_dependent_only_on_argument(false )
3238
- {}
3239
-
3240
- void visit_Var (const ASR::Var_t& x) {
3241
- if ( ASR::is_a<ASR::Variable_t>(*x.m_v ) ) {
3242
- ASR::Variable_t* x_m_v = ASR::down_cast<ASR::Variable_t>(x.m_v );
3243
- is_dependent_only_on_argument = is_dependent_only_on_argument && ASRUtils::is_arg_dummy (x_m_v->m_intent );
3244
- } else {
3245
- is_dependent_only_on_argument = false ;
3246
- }
3247
- }
3248
- };
3249
-
3250
- static inline bool is_dimension_dependent_only_on_arguments (ASR::dimension_t * m_dims, size_t n_dims) {
3251
- ExprDependentOnlyOnArguments visitor;
3252
- for ( size_t i = 0 ; i < n_dims; i++ ) {
3253
- visitor.is_dependent_only_on_argument = true ;
3254
- if ( m_dims[i].m_length == nullptr ) {
3255
- return false ;
3256
- }
3257
- visitor.visit_expr (*m_dims[i].m_length );
3258
- if ( !visitor.is_dependent_only_on_argument ) {
3259
- return false ;
3260
- }
3261
- }
3262
- return true ;
3263
- }
3264
-
3265
3310
inline ASR::asr_t * make_FunctionType_t_util (Allocator &al,
3266
3311
const Location &a_loc, ASR::expr_t ** a_args, size_t n_args,
3267
3312
ASR::expr_t * a_return_var, ASR::abiType a_abi, ASR::deftypeType a_deftype,
@@ -3881,16 +3926,6 @@ static inline ASR::expr_t* get_bound(ASR::expr_t* arr_expr, int dim,
3881
3926
int32_type, bound_type, bound_value));
3882
3927
}
3883
3928
3884
- static inline ASR::asr_t * make_ArraySize_t_util (
3885
- Allocator &al, const Location &a_loc, ASR::expr_t * a_v,
3886
- ASR::expr_t * a_dim, ASR::ttype_t * a_type, ASR::expr_t * a_value) {
3887
- if ( ASR::is_a<ASR::ArrayPhysicalCast_t>(*a_v) ) {
3888
- a_v = ASR::down_cast<ASR::ArrayPhysicalCast_t>(a_v)->m_arg ;
3889
- }
3890
-
3891
- return ASR::make_ArraySize_t (al, a_loc, a_v, a_dim, a_type, a_value);
3892
- }
3893
-
3894
3929
static inline ASR::expr_t * get_size (ASR::expr_t * arr_expr, int dim,
3895
3930
Allocator& al) {
3896
3931
ASR::ttype_t * int32_type = ASRUtils::TYPE (ASR::make_Integer_t (al, arr_expr->base .loc , 4 ));
0 commit comments