From ba71122a54163414096ada6c4e771a5cc5301829 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 19 May 2023 04:50:54 +0900 Subject: [PATCH] new ast layout for arguments --- Cargo.lock | 28 +-- Cargo.toml | 10 +- compiler/codegen/src/compile.rs | 28 +-- compiler/codegen/src/symboltable.rs | 60 ++++--- compiler/src/lib.rs | 10 +- vm/src/stdlib/ast.rs | 14 +- vm/src/stdlib/ast/gen.rs | 264 +--------------------------- 7 files changed, 83 insertions(+), 331 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c1365ecdd9..de0e02e2ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,9 +125,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.2.1" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24a6904aef64d73cf10ab17ebace7befb918b82164785cb89907993be7f83813" +checksum = "6776fc96284a0bb647b615056fc496d1fe1644a7ab01829818a6d91cae888b84" [[package]] name = "blake2" @@ -1795,7 +1795,7 @@ dependencies = [ [[package]] name = "ruff_source_location" version = "0.0.0" -source = "git+https://github.com/youknowone/RustPython-Parser.git?rev=fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec#fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" +source = "git+https://github.com/RustPython/Parser.git?rev=fdec727f8068c882f99a47f0439572a71fd98b28#fdec727f8068c882f99a47f0439572a71fd98b28" dependencies = [ "memchr", "once_cell", @@ -1805,7 +1805,7 @@ dependencies = [ [[package]] name = "ruff_text_size" version = "0.0.0" -source = "git+https://github.com/youknowone/RustPython-Parser.git?rev=fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec#fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" +source = "git+https://github.com/RustPython/Parser.git?rev=fdec727f8068c882f99a47f0439572a71fd98b28#fdec727f8068c882f99a47f0439572a71fd98b28" [[package]] name = "rustc-hash" @@ -1863,7 +1863,7 @@ dependencies = [ [[package]] name = "rustpython-ast" version = "0.2.0" -source = "git+https://github.com/youknowone/RustPython-Parser.git?rev=fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec#fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" +source = "git+https://github.com/RustPython/Parser.git?rev=fdec727f8068c882f99a47f0439572a71fd98b28#fdec727f8068c882f99a47f0439572a71fd98b28" dependencies = [ "is-macro", "num-bigint", @@ -1877,7 +1877,7 @@ name = "rustpython-codegen" version = "0.2.0" dependencies = [ "ahash", - "bitflags 2.2.1", + "bitflags 2.3.1", "indexmap", "insta", "itertools", @@ -1895,7 +1895,7 @@ name = "rustpython-common" version = "0.2.0" dependencies = [ "ascii", - "bitflags 2.2.1", + "bitflags 2.3.1", "bstr", "cfg-if", "itertools", @@ -1926,7 +1926,7 @@ dependencies = [ name = "rustpython-compiler-core" version = "0.2.0" dependencies = [ - "bitflags 2.2.1", + "bitflags 2.3.1", "itertools", "lz4_flex", "num-bigint", @@ -1972,9 +1972,9 @@ dependencies = [ [[package]] name = "rustpython-format" version = "0.2.0" -source = "git+https://github.com/youknowone/RustPython-Parser.git?rev=fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec#fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" +source = "git+https://github.com/RustPython/Parser.git?rev=fdec727f8068c882f99a47f0439572a71fd98b28#fdec727f8068c882f99a47f0439572a71fd98b28" dependencies = [ - "bitflags 2.2.1", + "bitflags 2.3.1", "itertools", "num-bigint", "num-traits", @@ -1999,7 +1999,7 @@ dependencies = [ [[package]] name = "rustpython-literal" version = "0.2.0" -source = "git+https://github.com/youknowone/RustPython-Parser.git?rev=fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec#fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" +source = "git+https://github.com/RustPython/Parser.git?rev=fdec727f8068c882f99a47f0439572a71fd98b28#fdec727f8068c882f99a47f0439572a71fd98b28" dependencies = [ "hexf-parse", "is-macro", @@ -2011,7 +2011,7 @@ dependencies = [ [[package]] name = "rustpython-parser" version = "0.2.0" -source = "git+https://github.com/youknowone/RustPython-Parser.git?rev=fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec#fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" +source = "git+https://github.com/RustPython/Parser.git?rev=fdec727f8068c882f99a47f0439572a71fd98b28#fdec727f8068c882f99a47f0439572a71fd98b28" dependencies = [ "anyhow", "is-macro", @@ -2034,7 +2034,7 @@ dependencies = [ [[package]] name = "rustpython-parser-core" version = "0.2.0" -source = "git+https://github.com/youknowone/RustPython-Parser.git?rev=fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec#fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" +source = "git+https://github.com/RustPython/Parser.git?rev=fdec727f8068c882f99a47f0439572a71fd98b28#fdec727f8068c882f99a47f0439572a71fd98b28" dependencies = [ "is-macro", "ruff_source_location", @@ -2129,7 +2129,7 @@ dependencies = [ "ahash", "ascii", "atty", - "bitflags 2.2.1", + "bitflags 2.3.1", "bstr", "caseless", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index 39f1103d5b..7b4b699e3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,11 +29,11 @@ rustpython-pylib = { path = "pylib" } rustpython-stdlib = { path = "stdlib" } rustpython-doc = { git = "https://github.com/RustPython/__doc__", branch = "main" } -rustpython-literal = { git = "https://github.com/youknowone/RustPython-Parser.git", rev = "fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" } -rustpython-parser-core = { git = "https://github.com/youknowone/RustPython-Parser.git", rev = "fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" } -rustpython-parser = { git = "https://github.com/youknowone/RustPython-Parser.git", rev = "fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" } -rustpython-ast = { git = "https://github.com/youknowone/RustPython-Parser.git", rev = "fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" } -rustpython-format = { git = "https://github.com/youknowone/RustPython-Parser.git", rev = "fc301ab1b0f5483f2b2d3e28d8d92a2845b99fec" } +rustpython-literal = { git = "https://github.com/RustPython/Parser.git", rev = "fdec727f8068c882f99a47f0439572a71fd98b28" } +rustpython-parser-core = { git = "https://github.com/RustPython/Parser.git", rev = "fdec727f8068c882f99a47f0439572a71fd98b28" } +rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "fdec727f8068c882f99a47f0439572a71fd98b28" } +rustpython-ast = { git = "https://github.com/RustPython/Parser.git", rev = "fdec727f8068c882f99a47f0439572a71fd98b28" } +rustpython-format = { git = "https://github.com/RustPython/Parser.git", rev = "fdec727f8068c882f99a47f0439572a71fd98b28" } # rustpython-literal = { path = "../RustPython-parser/literal" } # rustpython-parser-core = { path = "../RustPython-parser/core" } # rustpython-parser = { path = "../RustPython-parser/parser" } diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index 67f9003db3..bd51f6120d 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -927,31 +927,30 @@ impl Compiler { name: &str, args: &located_ast::Arguments, ) -> CompileResult { - let have_defaults = !args.defaults.is_empty(); + let defaults: Vec<_> = args.defaults().collect(); + let have_defaults = !defaults.is_empty(); if have_defaults { // Construct a tuple: - let size = args.defaults.len().to_u32(); - for element in &args.defaults { + let size = defaults.len().to_u32(); + for element in &defaults { self.compile_expression(element)?; } emit!(self, Instruction::BuildTuple { size }); } - if !args.kw_defaults.is_empty() { - let required_kw_count = args.kwonlyargs.len().saturating_sub(args.kw_defaults.len()); - for (kw, default) in args.kwonlyargs[required_kw_count..] - .iter() - .zip(&args.kw_defaults) - { + let (kw_without_defaults, kw_with_defaults) = args.split_kwonlyargs(); + if !kw_with_defaults.is_empty() { + let default_kw_count = kw_with_defaults.len(); + for (arg, default) in kw_with_defaults.iter() { self.emit_constant(ConstantData::Str { - value: kw.arg.to_string(), + value: arg.arg.to_string(), }); self.compile_expression(default)?; } emit!( self, Instruction::BuildMap { - size: args.kw_defaults.len().to_u32(), + size: default_kw_count.to_u32(), } ); } @@ -960,7 +959,7 @@ impl Compiler { if have_defaults { func_flags |= bytecode::MakeFunctionFlags::DEFAULTS; } - if !args.kw_defaults.is_empty() { + if !kw_with_defaults.is_empty() { func_flags |= bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS; } @@ -975,7 +974,9 @@ impl Compiler { let args_iter = std::iter::empty() .chain(&args.posonlyargs) .chain(&args.args) - .chain(&args.kwonlyargs); + .map(|arg| arg.as_arg()) + .chain(kw_without_defaults.into_iter()) + .chain(kw_with_defaults.into_iter().map(|(arg, _)| arg)); for name in args_iter { self.varname(name.arg.as_str())?; } @@ -1228,6 +1229,7 @@ impl Compiler { .chain(&args.posonlyargs) .chain(&args.args) .chain(&args.kwonlyargs) + .map(|arg| arg.as_arg()) .chain(args.vararg.as_deref()) .chain(args.kwarg.as_deref()); for arg in args_iter { diff --git a/compiler/codegen/src/symboltable.rs b/compiler/codegen/src/symboltable.rs index aeba6739a1..216d1af782 100644 --- a/compiler/codegen/src/symboltable.rs +++ b/compiler/codegen/src/symboltable.rs @@ -599,9 +599,17 @@ impl SymbolTableBuilder { Ok(()) } - fn scan_parameters(&mut self, parameters: &[ast::located::Arg]) -> SymbolTableResult { + fn scan_parameters( + &mut self, + parameters: &[ast::located::ArgWithDefault], + ) -> SymbolTableResult { for parameter in parameters { - self.scan_parameter(parameter)?; + let usage = if parameter.def.annotation.is_some() { + SymbolUsage::AnnotationParameter + } else { + SymbolUsage::Parameter + }; + self.register_name(parameter.def.arg.as_str(), usage, parameter.def.location())?; } Ok(()) } @@ -615,23 +623,6 @@ impl SymbolTableBuilder { self.register_name(parameter.arg.as_str(), usage, parameter.location()) } - fn scan_parameters_annotations( - &mut self, - parameters: &[ast::located::Arg], - ) -> SymbolTableResult { - for parameter in parameters { - self.scan_parameter_annotation(parameter)?; - } - Ok(()) - } - - fn scan_parameter_annotation(&mut self, parameter: &ast::located::Arg) -> SymbolTableResult { - if let Some(annotation) = ¶meter.annotation { - self.scan_annotation(annotation)?; - } - Ok(()) - } - fn scan_annotation(&mut self, annotation: &ast::located::Expr) -> SymbolTableResult { if self.future_annotations { Ok(()) @@ -1201,20 +1192,31 @@ impl SymbolTableBuilder { line_number: LineNumber, ) -> SymbolTableResult { // Evaluate eventual default parameters: - self.scan_expressions(&args.defaults, ExpressionContext::Load)?; - for expression in args.kw_defaults.iter() { - self.scan_expression(expression, ExpressionContext::Load)?; + for default in args + .posonlyargs + .iter() + .chain(args.args.iter()) + .chain(args.kwonlyargs.iter()) + .filter_map(|arg| arg.default.as_ref()) + { + self.scan_expression(default, ExpressionContext::Load)?; // not ExprContext? } // Annotations are scanned in outer scope: - self.scan_parameters_annotations(&args.posonlyargs)?; - self.scan_parameters_annotations(&args.args)?; - self.scan_parameters_annotations(&args.kwonlyargs)?; - if let Some(name) = &args.vararg { - self.scan_parameter_annotation(name)?; + for annotation in args + .posonlyargs + .iter() + .chain(args.args.iter()) + .chain(args.kwonlyargs.iter()) + .filter_map(|arg| arg.def.annotation.as_ref()) + { + self.scan_annotation(annotation)?; } - if let Some(name) = &args.kwarg { - self.scan_parameter_annotation(name)?; + if let Some(annotation) = args.vararg.as_ref().and_then(|arg| arg.annotation.as_ref()) { + self.scan_annotation(annotation)?; + } + if let Some(annotation) = args.kwarg.as_ref().and_then(|arg| arg.annotation.as_ref()) { + self.scan_annotation(annotation)?; } self.enter_scope(name, SymbolTableType::Function, line_number.get()); diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index ae79d0ae12..8094ce6e9f 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -1,9 +1,9 @@ use rustpython_codegen::{compile, symboltable}; -use rustpython_parser::ast::{fold::Fold, ConstantOptimizer}; +use rustpython_parser::ast::{self as ast, fold::Fold, ConstantOptimizer}; pub use rustpython_codegen::compile::CompileOpts; pub use rustpython_compiler_core::{bytecode::CodeObject, Mode}; -pub use rustpython_parser::source_code::SourceLocator; +pub use rustpython_parser::{source_code::SourceLocator, Parse}; // these modules are out of repository. re-exporting them here for convenience. pub use rustpython_codegen as codegen; @@ -75,13 +75,13 @@ pub fn compile_symtable( let res = match mode { Mode::Exec | Mode::Single | Mode::BlockExpr => { let ast = - parser::parse_program(source, source_path).map_err(|e| locator.locate_error(e))?; + ast::Suite::parse(source, source_path).map_err(|e| locator.locate_error(e))?; let ast = locator.fold(ast).unwrap(); symboltable::SymbolTable::scan_program(&ast) } Mode::Eval => { - let expr = parser::parse_expression(source, source_path) - .map_err(|e| locator.locate_error(e))?; + let expr = + ast::Expr::parse(source, source_path).map_err(|e| locator.locate_error(e))?; let expr = locator.fold(expr).unwrap(); symboltable::SymbolTable::scan_expr(&expr) } diff --git a/vm/src/stdlib/ast.rs b/vm/src/stdlib/ast.rs index ec2be4b7a4..1688f6d4d4 100644 --- a/vm/src/stdlib/ast.rs +++ b/vm/src/stdlib/ast.rs @@ -99,10 +99,6 @@ trait Node: Sized { fn ast_from_object(vm: &VirtualMachine, object: PyObjectRef) -> PyResult; } -trait NamedNode: Node { - const NAME: &'static str; -} - impl Node for Vec { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { vm.ctx @@ -317,6 +313,16 @@ impl Node for ast::ConversionFlag { } } +impl Node for ast::located::Arguments { + fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { + self.into_python_arguments().ast_to_object(vm) + } + fn ast_from_object(vm: &VirtualMachine, object: PyObjectRef) -> PyResult { + ast::located::PythonArguments::ast_from_object(vm, object) + .map(ast::located::PythonArguments::into_arguments) + } +} + #[cfg(feature = "rustpython-parser")] pub(crate) fn parse( vm: &VirtualMachine, diff --git a/vm/src/stdlib/ast/gen.rs b/vm/src/stdlib/ast/gen.rs index 3bb3d5008c..c189a78cce 100644 --- a/vm/src/stdlib/ast/gen.rs +++ b/vm/src/stdlib/ast/gen.rs @@ -2215,9 +2215,6 @@ impl NodeTypeIgnoreTypeIgnore { } } -impl NamedNode for ast::located::Mod { - const NAME: &'static str = "mod"; -} // sum impl Node for ast::located::Mod { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -2253,9 +2250,6 @@ impl Node for ast::located::Mod { } } // constructor -impl NamedNode for ast::located::ModModule { - const NAME: &'static str = "Module"; -} impl Node for ast::located::ModModule { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ModModule { @@ -2284,9 +2278,6 @@ impl Node for ast::located::ModModule { } } // constructor -impl NamedNode for ast::located::ModInteractive { - const NAME: &'static str = "Interactive"; -} impl Node for ast::located::ModInteractive { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ModInteractive { @@ -2311,9 +2302,6 @@ impl Node for ast::located::ModInteractive { } } // constructor -impl NamedNode for ast::located::ModExpression { - const NAME: &'static str = "Expression"; -} impl Node for ast::located::ModExpression { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ModExpression { @@ -2335,9 +2323,6 @@ impl Node for ast::located::ModExpression { } } // constructor -impl NamedNode for ast::located::ModFunctionType { - const NAME: &'static str = "FunctionType"; -} impl Node for ast::located::ModFunctionType { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ModFunctionType { @@ -2369,9 +2354,6 @@ impl Node for ast::located::ModFunctionType { }) } } -impl NamedNode for ast::located::Stmt { - const NAME: &'static str = "stmt"; -} // sum impl Node for ast::located::Stmt { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -2482,9 +2464,6 @@ impl Node for ast::located::Stmt { } } // constructor -impl NamedNode for ast::located::StmtFunctionDef { - const NAME: &'static str = "FunctionDef"; -} impl Node for ast::located::StmtFunctionDef { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtFunctionDef { @@ -2541,9 +2520,6 @@ impl Node for ast::located::StmtFunctionDef { } } // constructor -impl NamedNode for ast::located::StmtAsyncFunctionDef { - const NAME: &'static str = "AsyncFunctionDef"; -} impl Node for ast::located::StmtAsyncFunctionDef { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtAsyncFunctionDef { @@ -2600,9 +2576,6 @@ impl Node for ast::located::StmtAsyncFunctionDef { } } // constructor -impl NamedNode for ast::located::StmtClassDef { - const NAME: &'static str = "ClassDef"; -} impl Node for ast::located::StmtClassDef { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtClassDef { @@ -2646,9 +2619,6 @@ impl Node for ast::located::StmtClassDef { } } // constructor -impl NamedNode for ast::located::StmtReturn { - const NAME: &'static str = "Return"; -} impl Node for ast::located::StmtReturn { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtReturn { @@ -2674,9 +2644,6 @@ impl Node for ast::located::StmtReturn { } } // constructor -impl NamedNode for ast::located::StmtDelete { - const NAME: &'static str = "Delete"; -} impl Node for ast::located::StmtDelete { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtDelete { @@ -2703,9 +2670,6 @@ impl Node for ast::located::StmtDelete { } } // constructor -impl NamedNode for ast::located::StmtAssign { - const NAME: &'static str = "Assign"; -} impl Node for ast::located::StmtAssign { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtAssign { @@ -2742,9 +2706,6 @@ impl Node for ast::located::StmtAssign { } } // constructor -impl NamedNode for ast::located::StmtAugAssign { - const NAME: &'static str = "AugAssign"; -} impl Node for ast::located::StmtAugAssign { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtAugAssign { @@ -2781,9 +2742,6 @@ impl Node for ast::located::StmtAugAssign { } } // constructor -impl NamedNode for ast::located::StmtAnnAssign { - const NAME: &'static str = "AnnAssign"; -} impl Node for ast::located::StmtAnnAssign { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtAnnAssign { @@ -2830,9 +2788,6 @@ impl Node for ast::located::StmtAnnAssign { } } // constructor -impl NamedNode for ast::located::StmtFor { - const NAME: &'static str = "For"; -} impl Node for ast::located::StmtFor { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtFor { @@ -2872,9 +2827,6 @@ impl Node for ast::located::StmtFor { } } // constructor -impl NamedNode for ast::located::StmtAsyncFor { - const NAME: &'static str = "AsyncFor"; -} impl Node for ast::located::StmtAsyncFor { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtAsyncFor { @@ -2920,9 +2872,6 @@ impl Node for ast::located::StmtAsyncFor { } } // constructor -impl NamedNode for ast::located::StmtWhile { - const NAME: &'static str = "While"; -} impl Node for ast::located::StmtWhile { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtWhile { @@ -2952,9 +2901,6 @@ impl Node for ast::located::StmtWhile { } } // constructor -impl NamedNode for ast::located::StmtIf { - const NAME: &'static str = "If"; -} impl Node for ast::located::StmtIf { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtIf { @@ -2984,9 +2930,6 @@ impl Node for ast::located::StmtIf { } } // constructor -impl NamedNode for ast::located::StmtWith { - const NAME: &'static str = "With"; -} impl Node for ast::located::StmtWith { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtWith { @@ -3019,9 +2962,6 @@ impl Node for ast::located::StmtWith { } } // constructor -impl NamedNode for ast::located::StmtAsyncWith { - const NAME: &'static str = "AsyncWith"; -} impl Node for ast::located::StmtAsyncWith { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtAsyncWith { @@ -3057,9 +2997,6 @@ impl Node for ast::located::StmtAsyncWith { } } // constructor -impl NamedNode for ast::located::StmtMatch { - const NAME: &'static str = "Match"; -} impl Node for ast::located::StmtMatch { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtMatch { @@ -3090,9 +3027,6 @@ impl Node for ast::located::StmtMatch { } } // constructor -impl NamedNode for ast::located::StmtRaise { - const NAME: &'static str = "Raise"; -} impl Node for ast::located::StmtRaise { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtRaise { @@ -3123,9 +3057,6 @@ impl Node for ast::located::StmtRaise { } } // constructor -impl NamedNode for ast::located::StmtTry { - const NAME: &'static str = "Try"; -} impl Node for ast::located::StmtTry { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtTry { @@ -3166,9 +3097,6 @@ impl Node for ast::located::StmtTry { } } // constructor -impl NamedNode for ast::located::StmtTryStar { - const NAME: &'static str = "TryStar"; -} impl Node for ast::located::StmtTryStar { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtTryStar { @@ -3212,9 +3140,6 @@ impl Node for ast::located::StmtTryStar { } } // constructor -impl NamedNode for ast::located::StmtAssert { - const NAME: &'static str = "Assert"; -} impl Node for ast::located::StmtAssert { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtAssert { @@ -3242,9 +3167,6 @@ impl Node for ast::located::StmtAssert { } } // constructor -impl NamedNode for ast::located::StmtImport { - const NAME: &'static str = "Import"; -} impl Node for ast::located::StmtImport { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtImport { @@ -3268,9 +3190,6 @@ impl Node for ast::located::StmtImport { } } // constructor -impl NamedNode for ast::located::StmtImportFrom { - const NAME: &'static str = "ImportFrom"; -} impl Node for ast::located::StmtImportFrom { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtImportFrom { @@ -3309,9 +3228,6 @@ impl Node for ast::located::StmtImportFrom { } } // constructor -impl NamedNode for ast::located::StmtGlobal { - const NAME: &'static str = "Global"; -} impl Node for ast::located::StmtGlobal { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtGlobal { @@ -3335,9 +3251,6 @@ impl Node for ast::located::StmtGlobal { } } // constructor -impl NamedNode for ast::located::StmtNonlocal { - const NAME: &'static str = "Nonlocal"; -} impl Node for ast::located::StmtNonlocal { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtNonlocal { @@ -3361,9 +3274,6 @@ impl Node for ast::located::StmtNonlocal { } } // constructor -impl NamedNode for ast::located::StmtExpr { - const NAME: &'static str = "Expr"; -} impl Node for ast::located::StmtExpr { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtExpr { @@ -3387,9 +3297,6 @@ impl Node for ast::located::StmtExpr { } } // constructor -impl NamedNode for ast::located::StmtPass { - const NAME: &'static str = "Pass"; -} impl Node for ast::located::StmtPass { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtPass { range: _range } = self; @@ -3407,9 +3314,6 @@ impl Node for ast::located::StmtPass { } } // constructor -impl NamedNode for ast::located::StmtBreak { - const NAME: &'static str = "Break"; -} impl Node for ast::located::StmtBreak { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtBreak { range: _range } = self; @@ -3427,9 +3331,6 @@ impl Node for ast::located::StmtBreak { } } // constructor -impl NamedNode for ast::located::StmtContinue { - const NAME: &'static str = "Continue"; -} impl Node for ast::located::StmtContinue { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::StmtContinue { range: _range } = self; @@ -3446,9 +3347,6 @@ impl Node for ast::located::StmtContinue { }) } } -impl NamedNode for ast::located::Expr { - const NAME: &'static str = "expr"; -} // sum impl Node for ast::located::Expr { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -3561,9 +3459,6 @@ impl Node for ast::located::Expr { } } // constructor -impl NamedNode for ast::located::ExprBoolOp { - const NAME: &'static str = "BoolOp"; -} impl Node for ast::located::ExprBoolOp { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprBoolOp { @@ -3590,9 +3485,6 @@ impl Node for ast::located::ExprBoolOp { } } // constructor -impl NamedNode for ast::located::ExprNamedExpr { - const NAME: &'static str = "NamedExpr"; -} impl Node for ast::located::ExprNamedExpr { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprNamedExpr { @@ -3626,9 +3518,6 @@ impl Node for ast::located::ExprNamedExpr { } } // constructor -impl NamedNode for ast::located::ExprBinOp { - const NAME: &'static str = "BinOp"; -} impl Node for ast::located::ExprBinOp { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprBinOp { @@ -3658,9 +3547,6 @@ impl Node for ast::located::ExprBinOp { } } // constructor -impl NamedNode for ast::located::ExprUnaryOp { - const NAME: &'static str = "UnaryOp"; -} impl Node for ast::located::ExprUnaryOp { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprUnaryOp { @@ -3690,9 +3576,6 @@ impl Node for ast::located::ExprUnaryOp { } } // constructor -impl NamedNode for ast::located::ExprLambda { - const NAME: &'static str = "Lambda"; -} impl Node for ast::located::ExprLambda { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprLambda { @@ -3718,9 +3601,6 @@ impl Node for ast::located::ExprLambda { } } // constructor -impl NamedNode for ast::located::ExprIfExp { - const NAME: &'static str = "IfExp"; -} impl Node for ast::located::ExprIfExp { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprIfExp { @@ -3750,9 +3630,6 @@ impl Node for ast::located::ExprIfExp { } } // constructor -impl NamedNode for ast::located::ExprDict { - const NAME: &'static str = "Dict"; -} impl Node for ast::located::ExprDict { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprDict { @@ -3779,9 +3656,6 @@ impl Node for ast::located::ExprDict { } } // constructor -impl NamedNode for ast::located::ExprSet { - const NAME: &'static str = "Set"; -} impl Node for ast::located::ExprSet { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprSet { @@ -3804,9 +3678,6 @@ impl Node for ast::located::ExprSet { } } // constructor -impl NamedNode for ast::located::ExprListComp { - const NAME: &'static str = "ListComp"; -} impl Node for ast::located::ExprListComp { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprListComp { @@ -3836,9 +3707,6 @@ impl Node for ast::located::ExprListComp { } } // constructor -impl NamedNode for ast::located::ExprSetComp { - const NAME: &'static str = "SetComp"; -} impl Node for ast::located::ExprSetComp { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprSetComp { @@ -3868,9 +3736,6 @@ impl Node for ast::located::ExprSetComp { } } // constructor -impl NamedNode for ast::located::ExprDictComp { - const NAME: &'static str = "DictComp"; -} impl Node for ast::located::ExprDictComp { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprDictComp { @@ -3904,9 +3769,6 @@ impl Node for ast::located::ExprDictComp { } } // constructor -impl NamedNode for ast::located::ExprGeneratorExp { - const NAME: &'static str = "GeneratorExp"; -} impl Node for ast::located::ExprGeneratorExp { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprGeneratorExp { @@ -3936,9 +3798,6 @@ impl Node for ast::located::ExprGeneratorExp { } } // constructor -impl NamedNode for ast::located::ExprAwait { - const NAME: &'static str = "Await"; -} impl Node for ast::located::ExprAwait { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprAwait { @@ -3962,9 +3821,6 @@ impl Node for ast::located::ExprAwait { } } // constructor -impl NamedNode for ast::located::ExprYield { - const NAME: &'static str = "Yield"; -} impl Node for ast::located::ExprYield { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprYield { @@ -3990,9 +3846,6 @@ impl Node for ast::located::ExprYield { } } // constructor -impl NamedNode for ast::located::ExprYieldFrom { - const NAME: &'static str = "YieldFrom"; -} impl Node for ast::located::ExprYieldFrom { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprYieldFrom { @@ -4019,9 +3872,6 @@ impl Node for ast::located::ExprYieldFrom { } } // constructor -impl NamedNode for ast::located::ExprCompare { - const NAME: &'static str = "Compare"; -} impl Node for ast::located::ExprCompare { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprCompare { @@ -4054,9 +3904,6 @@ impl Node for ast::located::ExprCompare { } } // constructor -impl NamedNode for ast::located::ExprCall { - const NAME: &'static str = "Call"; -} impl Node for ast::located::ExprCall { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprCall { @@ -4089,9 +3936,6 @@ impl Node for ast::located::ExprCall { } } // constructor -impl NamedNode for ast::located::ExprFormattedValue { - const NAME: &'static str = "FormattedValue"; -} impl Node for ast::located::ExprFormattedValue { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprFormattedValue { @@ -4131,9 +3975,6 @@ impl Node for ast::located::ExprFormattedValue { } } // constructor -impl NamedNode for ast::located::ExprJoinedStr { - const NAME: &'static str = "JoinedStr"; -} impl Node for ast::located::ExprJoinedStr { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprJoinedStr { @@ -4160,9 +4001,6 @@ impl Node for ast::located::ExprJoinedStr { } } // constructor -impl NamedNode for ast::located::ExprConstant { - const NAME: &'static str = "Constant"; -} impl Node for ast::located::ExprConstant { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprConstant { @@ -4191,9 +4029,6 @@ impl Node for ast::located::ExprConstant { } } // constructor -impl NamedNode for ast::located::ExprAttribute { - const NAME: &'static str = "Attribute"; -} impl Node for ast::located::ExprAttribute { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprAttribute { @@ -4226,9 +4061,6 @@ impl Node for ast::located::ExprAttribute { } } // constructor -impl NamedNode for ast::located::ExprSubscript { - const NAME: &'static str = "Subscript"; -} impl Node for ast::located::ExprSubscript { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprSubscript { @@ -4265,9 +4097,6 @@ impl Node for ast::located::ExprSubscript { } } // constructor -impl NamedNode for ast::located::ExprStarred { - const NAME: &'static str = "Starred"; -} impl Node for ast::located::ExprStarred { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprStarred { @@ -4294,9 +4123,6 @@ impl Node for ast::located::ExprStarred { } } // constructor -impl NamedNode for ast::located::ExprName { - const NAME: &'static str = "Name"; -} impl Node for ast::located::ExprName { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprName { @@ -4322,9 +4148,6 @@ impl Node for ast::located::ExprName { } } // constructor -impl NamedNode for ast::located::ExprList { - const NAME: &'static str = "List"; -} impl Node for ast::located::ExprList { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprList { @@ -4350,9 +4173,6 @@ impl Node for ast::located::ExprList { } } // constructor -impl NamedNode for ast::located::ExprTuple { - const NAME: &'static str = "Tuple"; -} impl Node for ast::located::ExprTuple { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprTuple { @@ -4378,9 +4198,6 @@ impl Node for ast::located::ExprTuple { } } // constructor -impl NamedNode for ast::located::ExprSlice { - const NAME: &'static str = "Slice"; -} impl Node for ast::located::ExprSlice { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExprSlice { @@ -4416,9 +4233,6 @@ impl Node for ast::located::ExprSlice { }) } } -impl NamedNode for ast::located::ExprContext { - const NAME: &'static str = "expr_context"; -} // sum impl Node for ast::located::ExprContext { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -4448,9 +4262,6 @@ impl Node for ast::located::ExprContext { }) } } -impl NamedNode for ast::located::Boolop { - const NAME: &'static str = "boolop"; -} // sum impl Node for ast::located::Boolop { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -4477,9 +4288,6 @@ impl Node for ast::located::Boolop { }) } } -impl NamedNode for ast::located::Operator { - const NAME: &'static str = "operator"; -} // sum impl Node for ast::located::Operator { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -4539,9 +4347,6 @@ impl Node for ast::located::Operator { }) } } -impl NamedNode for ast::located::Unaryop { - const NAME: &'static str = "unaryop"; -} // sum impl Node for ast::located::Unaryop { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -4574,9 +4379,6 @@ impl Node for ast::located::Unaryop { }) } } -impl NamedNode for ast::located::Cmpop { - const NAME: &'static str = "cmpop"; -} // sum impl Node for ast::located::Cmpop { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -4628,9 +4430,6 @@ impl Node for ast::located::Cmpop { } } // product -impl NamedNode for ast::located::Comprehension { - const NAME: &'static str = "comprehension"; -} impl Node for ast::located::Comprehension { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::Comprehension { @@ -4674,9 +4473,6 @@ impl Node for ast::located::Comprehension { }) } } -impl NamedNode for ast::located::Excepthandler { - const NAME: &'static str = "excepthandler"; -} // sum impl Node for ast::located::Excepthandler { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -4699,9 +4495,6 @@ impl Node for ast::located::Excepthandler { } } // constructor -impl NamedNode for ast::located::ExcepthandlerExceptHandler { - const NAME: &'static str = "ExceptHandler"; -} impl Node for ast::located::ExcepthandlerExceptHandler { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::ExcepthandlerExceptHandler { @@ -4741,12 +4534,9 @@ impl Node for ast::located::ExcepthandlerExceptHandler { } } // product -impl NamedNode for ast::located::Arguments { - const NAME: &'static str = "arguments"; -} -impl Node for ast::located::Arguments { +impl Node for ast::located::PythonArguments { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { - let ast::located::Arguments { + let ast::located::PythonArguments { posonlyargs, args, vararg, @@ -4776,7 +4566,7 @@ impl Node for ast::located::Arguments { node.into() } fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult { - Ok(ast::located::Arguments { + Ok(ast::located::PythonArguments { posonlyargs: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "posonlyargs", "arguments")?, @@ -4805,9 +4595,6 @@ impl Node for ast::located::Arguments { } } // product -impl NamedNode for ast::located::Arg { - const NAME: &'static str = "arg"; -} impl Node for ast::located::Arg { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::Arg { @@ -4842,9 +4629,6 @@ impl Node for ast::located::Arg { } } // product -impl NamedNode for ast::located::Keyword { - const NAME: &'static str = "keyword"; -} impl Node for ast::located::Keyword { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::Keyword { @@ -4873,9 +4657,6 @@ impl Node for ast::located::Keyword { } } // product -impl NamedNode for ast::located::Alias { - const NAME: &'static str = "alias"; -} impl Node for ast::located::Alias { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::Alias { @@ -4904,9 +4685,6 @@ impl Node for ast::located::Alias { } } // product -impl NamedNode for ast::located::Withitem { - const NAME: &'static str = "withitem"; -} impl Node for ast::located::Withitem { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::Withitem { @@ -4938,9 +4716,6 @@ impl Node for ast::located::Withitem { } } // product -impl NamedNode for ast::located::MatchCase { - const NAME: &'static str = "match_case"; -} impl Node for ast::located::MatchCase { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::MatchCase { @@ -4974,9 +4749,6 @@ impl Node for ast::located::MatchCase { }) } } -impl NamedNode for ast::located::Pattern { - const NAME: &'static str = "pattern"; -} // sum impl Node for ast::located::Pattern { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -5034,9 +4806,6 @@ impl Node for ast::located::Pattern { } } // constructor -impl NamedNode for ast::located::PatternMatchValue { - const NAME: &'static str = "MatchValue"; -} impl Node for ast::located::PatternMatchValue { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::PatternMatchValue { @@ -5063,9 +4832,6 @@ impl Node for ast::located::PatternMatchValue { } } // constructor -impl NamedNode for ast::located::PatternMatchSingleton { - const NAME: &'static str = "MatchSingleton"; -} impl Node for ast::located::PatternMatchSingleton { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::PatternMatchSingleton { @@ -5092,9 +4858,6 @@ impl Node for ast::located::PatternMatchSingleton { } } // constructor -impl NamedNode for ast::located::PatternMatchSequence { - const NAME: &'static str = "MatchSequence"; -} impl Node for ast::located::PatternMatchSequence { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::PatternMatchSequence { @@ -5121,9 +4884,6 @@ impl Node for ast::located::PatternMatchSequence { } } // constructor -impl NamedNode for ast::located::PatternMatchMapping { - const NAME: &'static str = "MatchMapping"; -} impl Node for ast::located::PatternMatchMapping { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::PatternMatchMapping { @@ -5161,9 +4921,6 @@ impl Node for ast::located::PatternMatchMapping { } } // constructor -impl NamedNode for ast::located::PatternMatchClass { - const NAME: &'static str = "MatchClass"; -} impl Node for ast::located::PatternMatchClass { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::PatternMatchClass { @@ -5207,9 +4964,6 @@ impl Node for ast::located::PatternMatchClass { } } // constructor -impl NamedNode for ast::located::PatternMatchStar { - const NAME: &'static str = "MatchStar"; -} impl Node for ast::located::PatternMatchStar { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::PatternMatchStar { @@ -5234,9 +4988,6 @@ impl Node for ast::located::PatternMatchStar { } } // constructor -impl NamedNode for ast::located::PatternMatchAs { - const NAME: &'static str = "MatchAs"; -} impl Node for ast::located::PatternMatchAs { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::PatternMatchAs { @@ -5267,9 +5018,6 @@ impl Node for ast::located::PatternMatchAs { } } // constructor -impl NamedNode for ast::located::PatternMatchOr { - const NAME: &'static str = "MatchOr"; -} impl Node for ast::located::PatternMatchOr { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::PatternMatchOr { @@ -5295,9 +5043,6 @@ impl Node for ast::located::PatternMatchOr { }) } } -impl NamedNode for ast::located::TypeIgnore { - const NAME: &'static str = "type_ignore"; -} // sum impl Node for ast::located::TypeIgnore { fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef { @@ -5320,9 +5065,6 @@ impl Node for ast::located::TypeIgnore { } } // constructor -impl NamedNode for ast::located::TypeIgnoreTypeIgnore { - const NAME: &'static str = "TypeIgnore"; -} impl Node for ast::located::TypeIgnoreTypeIgnore { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { let ast::located::TypeIgnoreTypeIgnore {