@@ -20,6 +20,7 @@ struct AttributeHandler {
2020 AttributeHandler () {
2121 attribute_map = {
2222 {" int@bit_length" , &eval_int_bit_length},
23+ {" array@size" , &eval_array_size},
2324 {" list@append" , &eval_list_append},
2425 {" list@remove" , &eval_list_remove},
2526 {" list@count" , &eval_list_count},
@@ -42,6 +43,8 @@ struct AttributeHandler {
4243 return " set" ;
4344 } else if (ASR ::is_a<ASR ::Dict_t>(*t)) {
4445 return " dict" ;
46+ } else if (ASRUtils::is_array (t)) {
47+ return " array" ;
4548 } else if (ASR ::is_a<ASR ::Integer_t>(*t)) {
4649 return " int" ;
4750 }
@@ -55,7 +58,7 @@ struct AttributeHandler {
5558 if (class_name == " " ) {
5659 throw SemanticError (" Type name is not implemented yet." , loc);
5760 }
58- std::string key = get_type_name (type) + " @" + attr_name;
61+ std::string key = class_name + " @" + attr_name;
5962 auto search = attribute_map.find (key);
6063 if (search != attribute_map.end ()) {
6164 attribute_eval_callback cb = search->second ;
@@ -77,6 +80,15 @@ struct AttributeHandler {
7780 return ASR::make_IntegerBitLen_t (al, loc, s, int_type, nullptr );
7881 }
7982
83+ static ASR ::asr_t * eval_array_size (ASR ::expr_t *s, Allocator &al, const Location &loc,
84+ Vec<ASR ::expr_t *> &args, diag::Diagnostics &/* diag*/ ) {
85+ if (args.size () != 0 ) {
86+ throw SemanticError (" array.size() takes no arguments" , loc);
87+ }
88+ ASR ::ttype_t *int_type = ASRUtils::TYPE (ASR::make_Integer_t (al, loc, 4 , nullptr , 0 ));
89+ return ASR::make_ArraySize_t (al, loc, s, nullptr , int_type, nullptr );
90+ }
91+
8092 static ASR ::asr_t * eval_list_append (ASR ::expr_t *s, Allocator &al, const Location &loc,
8193 Vec<ASR ::expr_t *> &args, diag::Diagnostics &diag) {
8294 if (args.size () != 1 ) {
0 commit comments