(
clause: ast::ElifElseClause,
mut rest: alloc::vec::IntoIter<ast::ElifElseClause>,
vm: &VirtualMachine,
source_file: &SourceFile,
)
| 2 | use rustpython_compiler_core::SourceFile; |
| 3 | |
| 4 | pub(super) fn ast_to_object( |
| 5 | clause: ast::ElifElseClause, |
| 6 | mut rest: alloc::vec::IntoIter<ast::ElifElseClause>, |
| 7 | vm: &VirtualMachine, |
| 8 | source_file: &SourceFile, |
| 9 | ) -> PyObjectRef { |
| 10 | let ast::ElifElseClause { |
| 11 | node_index: _, |
| 12 | range, |
| 13 | test, |
| 14 | body, |
| 15 | } = clause; |
| 16 | let Some(test) = test else { |
| 17 | assert!(rest.len() == 0); |
| 18 | return body.ast_to_object(vm, source_file); |
| 19 | }; |
| 20 | let node = NodeAst |
| 21 | .into_ref_with_type(vm, pyast::NodeStmtIf::static_type().to_owned()) |
| 22 | .unwrap(); |
| 23 | let dict = node.as_object().dict().unwrap(); |
| 24 | |
| 25 | dict.set_item("test", test.ast_to_object(vm, source_file), vm) |
| 26 | .unwrap(); |
| 27 | dict.set_item("body", body.ast_to_object(vm, source_file), vm) |
| 28 | .unwrap(); |
| 29 | |
| 30 | let orelse = if let Some(next) = rest.next() { |
| 31 | if next.test.is_some() { |
| 32 | let next = ast::ElifElseClause { |
| 33 | range: TextRange::new(next.range.start(), range.end()), |
| 34 | ..next |
| 35 | }; |
| 36 | vm.ctx |
| 37 | .new_list(vec![ast_to_object(next, rest, vm, source_file)]) |
| 38 | .into() |
| 39 | } else { |
| 40 | next.body.ast_to_object(vm, source_file) |
| 41 | } |
| 42 | } else { |
| 43 | vm.ctx.new_list(vec![]).into() |
| 44 | }; |
| 45 | dict.set_item("orelse", orelse, vm).unwrap(); |
| 46 | |
| 47 | node_add_location(&dict, range, vm, source_file); |
| 48 | node.into() |
| 49 | } |
| 50 | |
| 51 | pub(super) fn ast_from_object( |
| 52 | vm: &VirtualMachine, |
no test coverage detected