Skip to content

Commit 3a41c5c

Browse files
committed
Add len nodes for all iterables
1 parent 62a73d6 commit 3a41c5c

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/libasr/ASR.asdl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,22 @@ expr
227227
| LogicalConstant(bool value, ttype type)
228228

229229
| ListConstant(expr* args, ttype type)
230+
| ListLen(expr arg, ttype type)
230231
| ListConcat(expr left, expr right, ttype type, expr? value)
231232

232233
| ArrayConstant(expr* args, ttype type)
234+
233235
| SetConstant(expr* elements, ttype type)
236+
| SetLen(expr arg, ttype type)
237+
234238
| TupleConstant(expr* elements, ttype type)
239+
| TupleLen(expr arg, ttype type)
235240

236241
| StringConstant(string s, ttype type)
237-
| StringLen(expr arg)
242+
| StringLen(expr arg, ttype type)
238243

239244
| DictConstant(expr* keys, expr* values, ttype type)
245+
| DictLen(expr arg, ttype type)
240246
| Var(symbol v)
241247
| ArrayRef(symbol v, array_index* args, ttype type, expr? value)
242248
| DerivedRef(expr v, symbol m, ttype type, expr? value)

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,8 +2685,10 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
26852685
const Location &loc) {
26862686
ASR::expr_t *arg = args[0].m_value;
26872687
ASR::ttype_t *type = ASRUtils::expr_type(arg);
2688+
ASR::ttype_t *to_type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc,
2689+
4, nullptr, 0));
26882690
if (ASRUtils::is_character(*type)) {
2689-
return (ASR::asr_t *)ASR::down_cast<ASR::expr_t>(ASR::make_StringLen_t(al, loc, arg));
2691+
return (ASR::asr_t *)ASR::down_cast<ASR::expr_t>(ASR::make_StringLen_t(al, loc, arg, to_type));
26902692
}
26912693
return nullptr;
26922694
}

0 commit comments

Comments
 (0)