@@ -3761,7 +3761,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
37613761
37623762 bool visit_SubscriptIndices (AST::expr_t * m_slice, Vec<ASR::array_index_t >& args,
37633763 ASR::expr_t * value, ASR::ttype_t * type, bool & is_item,
3764- const Location& loc) {
3764+ const Location& loc, size_t idx= 0 ) {
37653765 ASR::array_index_t ai;
37663766 ai.loc = loc;
37673767 ai.m_left = nullptr ;
@@ -3823,7 +3823,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
38233823 AST::Tuple_t* indices = AST::down_cast<AST::Tuple_t>(m_slice);
38243824 for ( size_t i = 0 ; i < indices->n_elts ; i++ ) {
38253825 final_result &= visit_SubscriptIndices (indices->m_elts [i], args,
3826- value, type, is_item, loc);
3826+ value, type, is_item, loc, i );
38273827 }
38283828 return final_result;
38293829 } else {
@@ -3899,6 +3899,25 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
38993899 tmp = make_TupleItem_t (al, loc, value, index,
39003900 ASR::down_cast<ASR::Tuple_t>(type)->m_type [i], nullptr );
39013901 return false ;
3902+ } else if (ASR::is_a<ASR::Array_t>(*type)) {
3903+ index = ASRUtils::EXPR (tmp);
3904+ ASR::expr_t * val = ASRUtils::expr_value (index);
3905+ if (val && ASR::is_a<ASR::IntegerConstant_t>(*val)) {
3906+ if (ASR::down_cast<ASR::IntegerConstant_t>(val)->m_n < 0 ) {
3907+ ASR::ttype_t *int_type = ASRUtils::TYPE (ASR::make_Integer_t (
3908+ al, loc, 4 ));
3909+ ASR::expr_t *neg_idx = ASRUtils::expr_value (index);
3910+ ASR::expr_t *dim_size;
3911+ if (ASRUtils::extract_physical_type (type) != ASR::array_physical_typeType::DescriptorArray)
3912+ dim_size = ASR::down_cast<ASR::Array_t>(type)->m_dims [idx].m_length ;
3913+ else {
3914+ ASR::expr_t *idx_expr = ASRUtils::EXPR (ASR::make_IntegerConstant_t (al, loc, idx + 1 , int_type));
3915+ dim_size = ASRUtils::EXPR (ASRUtils::make_ArraySize_t_util (al, loc, value, idx_expr, int_type, nullptr , false ));
3916+ }
3917+ index = ASRUtils::EXPR (ASR::make_IntegerBinOp_t (al, loc,
3918+ dim_size, ASR::binopType::Add, neg_idx, int_type, nullptr ));
3919+ }
3920+ }
39023921 } else {
39033922 index = ASRUtils::EXPR (tmp);
39043923 }
0 commit comments