@@ -1081,6 +1081,49 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
1081
1081
}
1082
1082
}
1083
1083
1084
+ void visit_Attribute (const AST::Attribute_t &x) {
1085
+ if (AST::is_a<AST::Name_t>(*x.m_value )) {
1086
+ std::string value = AST::down_cast<AST::Name_t>(x.m_value )->m_id ;
1087
+ ASR::symbol_t *t = current_scope->scope [value];
1088
+ if (!t) {
1089
+ throw SemanticError (" '" + value + " ' is not defined in the scope" ,
1090
+ x.base .base .loc );
1091
+ }
1092
+ if (ASR::is_a<ASR::Variable_t>(*t)) {
1093
+ ASR::Variable_t *var = ASR::down_cast<ASR::Variable_t>(t);
1094
+ LFORTRAN_ASSERT (var->m_value );
1095
+ if (ASR::is_a<ASR::ConstantComplex_t>(*var->m_value )) {
1096
+ std::string attr = x.m_attr ;
1097
+ if (attr == " imag" ) {
1098
+ double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value )->m_im ;
1099
+ ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Real_t (al, x.base .base .loc ,
1100
+ 8 , nullptr , 0 ));
1101
+ tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , val, type);
1102
+ } else if (attr == " real" ) {
1103
+ double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value )->m_im ;
1104
+ ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Real_t (al, x.base .base .loc ,
1105
+ 8 , nullptr , 0 ));
1106
+ tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , val, type);
1107
+ } else {
1108
+ throw SemanticError (" '" + attr + " ' is not implemented for Complex type" ,
1109
+ x.base .base .loc );
1110
+ }
1111
+
1112
+ } else {
1113
+ throw SemanticError (" Only Complex type supported for now in Attribute" ,
1114
+ x.base .base .loc );
1115
+ }
1116
+ } else {
1117
+ throw SemanticError (" Only Variable type is supported for now in Attribute" ,
1118
+ x.base .base .loc );
1119
+ }
1120
+
1121
+ } else {
1122
+ throw SemanticError (" Only Name is supported for now in Attribute" ,
1123
+ x.base .base .loc );
1124
+ }
1125
+ }
1126
+
1084
1127
void visit_Assert (const AST::Assert_t &x) {
1085
1128
this ->visit_expr (*x.m_test );
1086
1129
ASR::expr_t *test = ASRUtils::EXPR (tmp);
0 commit comments