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