@@ -1581,6 +1581,29 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
1581
1581
}
1582
1582
}
1583
1583
1584
+ AST::expr_t * get_var_intent_and_annotation (AST::expr_t *annotation, ASR::intentType &intent) {
1585
+ if (AST::is_a<AST::Subscript_t>(*annotation)) {
1586
+ AST::Subscript_t *s = AST::down_cast<AST::Subscript_t>(annotation);
1587
+ if (AST::is_a<AST::Name_t>(*s->m_value )) {
1588
+ std::string ann_name = AST::down_cast<AST::Name_t>(s->m_value )->m_id ;
1589
+ if (ann_name == " In" ) {
1590
+ intent = ASRUtils::intent_in;
1591
+ return s->m_slice ;
1592
+ } else if (ann_name == " InOut" ) {
1593
+ intent = ASRUtils::intent_inout;
1594
+ return s->m_slice ;
1595
+ } else if (ann_name == " Out" ) {
1596
+ intent = ASRUtils::intent_out;
1597
+ return s->m_slice ;
1598
+ }
1599
+ return annotation;
1600
+ } else {
1601
+ throw SemanticError (" Only Name in Subscript supported for now in annotation" , annotation->base .loc );
1602
+ }
1603
+ }
1604
+ return annotation;
1605
+ }
1606
+
1584
1607
// Convert Python AST type annotation to an ASR type
1585
1608
// Examples:
1586
1609
// i32, i64, f32, f64
@@ -3741,7 +3764,9 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
3741
3764
if (x.m_args .m_args [i].m_annotation == nullptr ) {
3742
3765
throw SemanticError (" Argument does not have a type" , loc);
3743
3766
}
3744
- ASR::ttype_t *arg_type = ast_expr_to_asr_type (x.base .base .loc , *x.m_args .m_args [i].m_annotation );
3767
+ ASR::intentType s_intent = ASRUtils::intent_unspecified;
3768
+ AST::expr_t * arg_annotation_type = get_var_intent_and_annotation (x.m_args .m_args [i].m_annotation , s_intent);
3769
+ ASR::ttype_t *arg_type = ast_expr_to_asr_type (x.base .base .loc , *arg_annotation_type);
3745
3770
// Set the function as generic if an argument is typed with a type parameter
3746
3771
if (ASRUtils::is_generic (*arg_type)) {
3747
3772
ASR::ttype_t * arg_type_type = ASRUtils::get_type_parameter (arg_type);
@@ -3766,12 +3791,13 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
3766
3791
}
3767
3792
3768
3793
std::string arg_s = arg;
3769
-
3770
3794
ASR::expr_t *value = nullptr ;
3771
3795
ASR::expr_t *init_expr = nullptr ;
3772
- ASR::intentType s_intent = ASRUtils::intent_in;
3773
- if (ASRUtils::is_array (arg_type)) {
3774
- s_intent = ASRUtils::intent_inout;
3796
+ if (s_intent == ASRUtils::intent_unspecified) {
3797
+ s_intent = ASRUtils::intent_in;
3798
+ if (ASRUtils::is_array (arg_type)) {
3799
+ s_intent = ASRUtils::intent_inout;
3800
+ }
3775
3801
}
3776
3802
ASR::storage_typeType storage_type =
3777
3803
ASR::storage_typeType::Default;
0 commit comments