Skip to content

Commit 2afbf1f

Browse files
committed
Added support for list.clear in ASR
1 parent 1534a3d commit 2afbf1f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/lpython/semantics/python_attribute_eval.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct AttributeHandler {
2121
{"int@bit_length", &eval_int_bit_length},
2222
{"list@append", &eval_list_append},
2323
{"list@remove", &eval_list_remove},
24+
{"list@clear", &eval_list_clear},
2425
{"list@insert", &eval_list_insert},
2526
{"list@pop", &eval_list_pop},
2627
{"set@pop", &eval_set_pop},
@@ -187,6 +188,23 @@ struct AttributeHandler {
187188
return make_ListPop_t(al, loc, s, idx, list_type, nullptr);
188189
}
189190

191+
static ASR::asr_t* eval_list_clear(ASR::expr_t *s, Allocator &al,
192+
const Location &loc, Vec<ASR::expr_t*> &args, diag::Diagnostics & diag) {
193+
if (args.size() != 0) {
194+
diag.add(diag::Diagnostic(
195+
"Incorrect number of arguments in 'clear', it accepts no argument",
196+
diag::Level::Error, diag::Stage::Semantic, {
197+
diag::Label("incorrect number of arguments in clear (found: " +
198+
std::to_string(args.size()) + ", expected: 0)",
199+
{loc})
200+
})
201+
);
202+
throw SemanticAbort();
203+
}
204+
205+
return make_ListClear_t(al, loc, s);
206+
}
207+
190208
static ASR::asr_t* eval_set_pop(ASR::expr_t *s, Allocator &al, const Location &loc,
191209
Vec<ASR::expr_t*> &args, diag::Diagnostics &/*diag*/) {
192210
if (args.size() != 0) {

0 commit comments

Comments
 (0)