@@ -967,6 +967,19 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
967
967
tmp = ASR::make_Assert_t (al, x.base .base .loc , test, msg);
968
968
}
969
969
970
+ ASR::expr_t *index_add_one (const Location &loc, ASR::expr_t *idx) {
971
+ // Add 1 to the index `idx`, assumes `idx` is of type Integer 4
972
+ ASR::expr_t *overloaded = nullptr ;
973
+ ASR::expr_t *comptime_value = nullptr ;
974
+ ASR::ttype_t *a_type = ASRUtils::TYPE (ASR::make_Integer_t (al, loc,
975
+ 4 , nullptr , 0 ));
976
+ ASR::expr_t *constant_one = ASR::down_cast<ASR::expr_t >(ASR::make_ConstantInteger_t (
977
+ al, loc, 1 , a_type));
978
+ return ASRUtils::EXPR (ASR::make_BinOp_t (al, loc, idx,
979
+ ASR::binopType::Add, constant_one, a_type,
980
+ comptime_value, overloaded));
981
+ }
982
+
970
983
void visit_Subscript (const AST::Subscript_t &x) {
971
984
this ->visit_expr (*x.m_value );
972
985
ASR::expr_t *value = ASRUtils::EXPR (tmp);
@@ -981,19 +994,19 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
981
994
AST::Slice_t *s = AST::down_cast<AST::Slice_t>(x.m_slice );
982
995
if (s->m_lower != nullptr ) {
983
996
this ->visit_expr (*s->m_lower );
984
- ai.m_left = ASRUtils::EXPR (tmp);
997
+ ai.m_left = index_add_one (x. base . base . loc , ASRUtils::EXPR (tmp) );
985
998
}
986
999
if (s->m_upper != nullptr ) {
987
1000
this ->visit_expr (*s->m_upper );
988
- ai.m_right = ASRUtils::EXPR (tmp);
1001
+ ai.m_right = index_add_one (x. base . base . loc , ASRUtils::EXPR (tmp) );
989
1002
}
990
1003
if (s->m_step != nullptr ) {
991
1004
this ->visit_expr (*s->m_step );
992
- ai.m_step = ASRUtils::EXPR (tmp);
1005
+ ai.m_step = index_add_one (x. base . base . loc , ASRUtils::EXPR (tmp) );
993
1006
}
994
1007
} else {
995
1008
this ->visit_expr (*x.m_slice );
996
- ASR::expr_t *index = ASRUtils::EXPR (tmp);
1009
+ ASR::expr_t *index = index_add_one (x. base . base . loc , ASRUtils::EXPR (tmp) );
997
1010
ai.m_right = index;
998
1011
}
999
1012
ASR::symbol_t *s = ASR::down_cast<ASR::Var_t>(value)->m_v ;
0 commit comments