MCPcopy Index your code
hub / github.com/RustPython/RustPython / ast_from_object

Function ast_from_object

crates/vm/src/stdlib/_ast/elif_else_clause.rs:51–104  ·  view source on GitHub ↗
(
    vm: &VirtualMachine,
    source_file: &SourceFile,
    object: PyObjectRef,
)

Source from the content-addressed store, hash-verified

49}
50
51pub(super) fn ast_from_object(
52 vm: &VirtualMachine,
53 source_file: &SourceFile,
54 object: PyObjectRef,
55) -> PyResult<ast::StmtIf> {
56 let test = Node::ast_from_object(vm, source_file, get_node_field(vm, &object, "test", "If")?)?;
57 let body = Node::ast_from_object(vm, source_file, get_node_field(vm, &object, "body", "If")?)?;
58 let orelse: Vec<ast::Stmt> = Node::ast_from_object(
59 vm,
60 source_file,
61 get_node_field(vm, &object, "orelse", "If")?,
62 )?;
63 let range = range_from_object(vm, source_file, object, "If")?;
64
65 let elif_else_clauses = if orelse.is_empty() {
66 vec![]
67 } else if let [ast::Stmt::If(_)] = &*orelse {
68 let Some(ast::Stmt::If(ast::StmtIf {
69 node_index: _,
70 range,
71 test,
72 body,
73 mut elif_else_clauses,
74 })) = orelse.into_iter().next()
75 else {
76 unreachable!()
77 };
78 elif_else_clauses.insert(
79 0,
80 ast::ElifElseClause {
81 node_index: Default::default(),
82 range,
83 test: Some(*test),
84 body,
85 },
86 );
87 elif_else_clauses
88 } else {
89 vec![ast::ElifElseClause {
90 node_index: Default::default(),
91 range,
92 test: None,
93 body: orelse,
94 }]
95 };
96
97 Ok(ast::StmtIf {
98 node_index: Default::default(),
99 test,
100 body,
101 elif_else_clauses,
102 range,
103 })
104}

Callers 15

compileFunction · 0.85
validate_ast_objectFunction · 0.85
ast_from_objectMethod · 0.85
ast_from_objectMethod · 0.85
ast_from_objectMethod · 0.85
ast_from_objectMethod · 0.85
ast_from_objectMethod · 0.85
ast_from_objectMethod · 0.85
ast_from_objectMethod · 0.85
ast_from_objectMethod · 0.85
ast_from_objectMethod · 0.85
ast_from_objectMethod · 0.85

Calls 7

get_node_fieldFunction · 0.85
range_from_objectFunction · 0.85
SomeClass · 0.50
is_emptyMethod · 0.45
nextMethod · 0.45
into_iterMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected