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

Method ast_to_object

crates/vm/src/stdlib/_ast/constant.rs:101–119  ·  view source on GitHub ↗
(self, vm: &VirtualMachine, source_file: &SourceFile)

Source from the content-addressed store, hash-verified

99// constructor
100impl Node for Constant {
101 fn ast_to_object(self, vm: &VirtualMachine, source_file: &SourceFile) -> PyObjectRef {
102 let Self { range, value } = self;
103 let node = NodeAst
104 .into_ref_with_type(vm, pyast::NodeExprConstant::static_type().to_owned())
105 .unwrap();
106 let kind = match &value {
107 ConstantLiteral::Str {
108 prefix: StringLiteralPrefix::Unicode,
109 ..
110 } => vm.ctx.new_str("u").into(),
111 _ => vm.ctx.none(),
112 };
113 let value = value.ast_to_object(vm, source_file);
114 let dict = node.as_object().dict().unwrap();
115 dict.set_item("value", value, vm).unwrap();
116 dict.set_item("kind", kind, vm).unwrap();
117 node_add_location(&dict, range, vm, source_file);
118 node.into()
119 }
120
121 fn ast_from_object(
122 vm: &VirtualMachine,

Callers 6

number_literal_to_objectFunction · 0.45
string_literal_to_objectFunction · 0.45
bytes_literal_to_objectFunction · 0.45
none_literal_to_objectFunction · 0.45

Calls 15

node_add_locationFunction · 0.85
newFunction · 0.85
into_ref_with_typeMethod · 0.80
noneMethod · 0.80
collectMethod · 0.80
unwrapMethod · 0.45
to_ownedMethod · 0.45
new_strMethod · 0.45
dictMethod · 0.45
as_objectMethod · 0.45
set_itemMethod · 0.45
to_pyobjectMethod · 0.45

Tested by

no test coverage detected