diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 392f84a263e77..3c627ddba2546 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,7 +40,7 @@ jobs: - name: run tests with num-bigint run: cargo test --all --no-default-features --features num-bigint - name: run tests with malachite-bigint and all features - run: cargo test --all --features location,malachite-bigint,constant-optimization,fold,unparse,visitor,all-nodes-with-ranges,full-lexer,serde --exclude rustpython-ast-pyo3 + run: cargo test --all --features malachite-bigint,all-nodes-with-ranges,full-lexer,serde lint: name: Check Rust code with rustfmt and clippy @@ -55,7 +55,7 @@ jobs: - name: run clippy run: cargo clippy --all --no-default-features --features num-bigint - name: run clippy - run: cargo clippy --all --features location,malachite-bigint,constant-optimization,fold,unparse,visitor,all-nodes-with-ranges,full-lexer,serde --exclude rustpython-ast-pyo3 -- -Dwarnings + run: cargo clippy --all --features malachite-bigint,all-nodes-with-ranges,full-lexer,serde -- -Dwarnings - uses: actions/setup-python@v4 with: diff --git a/Cargo.toml b/Cargo.toml index 2342f7f12c5b4..219221e609782 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,9 +11,7 @@ include = ["LICENSE", "Cargo.toml", "src/**/*.rs"] [workspace] resolver = "2" members = [ - "ast", "core", "format", "literal", "parser", - "ast-pyo3", - "ruff_text_size", "ruff_source_location", + "ast", "core", "format", "literal", "parser", "ruff_text_size", ] [workspace.dependencies] diff --git a/ast-pyo3/.gitignore b/ast-pyo3/.gitignore deleted file mode 100644 index af3ca5ef1ca84..0000000000000 --- a/ast-pyo3/.gitignore +++ /dev/null @@ -1,72 +0,0 @@ -/target - -# Byte-compiled / optimized / DLL files -__pycache__/ -.pytest_cache/ -*.py[cod] - -# C extensions -*.so - -# Distribution / packaging -.Python -.venv/ -env/ -bin/ -build/ -develop-eggs/ -dist/ -eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -include/ -man/ -venv/ -*.egg-info/ -.installed.cfg -*.egg - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt -pip-selfcheck.json - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.cache -nosetests.xml -coverage.xml - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Rope -.ropeproject - -# Django stuff: -*.log -*.pot - -.DS_Store - -# Sphinx documentation -docs/_build/ - -# PyCharm -.idea/ - -# VSCode -.vscode/ - -# Pyenv -.python-version \ No newline at end of file diff --git a/ast-pyo3/Cargo.toml b/ast-pyo3/Cargo.toml deleted file mode 100644 index bf145ab4183da..0000000000000 --- a/ast-pyo3/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "rustpython-ast-pyo3" -version = "0.0.1" -edition = "2021" - -[features] -# abi3 = ["pyo3/abi3-py37"] # will be supported from next pyo3 version -# This feature is experimental -# It reimplements AST types, but currently both slower than python AST types and limited to use in other API -wrapper = [] - -[lib] -name = "rustpython_ast" -crate-type = ["cdylib"] - -[dependencies] -rustpython-ast = { workspace = true, features = ["location"] } -rustpython-parser = { workspace = true, features = ["num-bigint"] } -num-complex = { workspace = true } -num-traits = { workspace = true } -once_cell = { workspace = true } - -pyo3 = { workspace = true, features = ["num-bigint", "num-complex"] } diff --git a/ast-pyo3/pyproject.toml b/ast-pyo3/pyproject.toml deleted file mode 100644 index f6e6dbcdc8f33..0000000000000 --- a/ast-pyo3/pyproject.toml +++ /dev/null @@ -1,15 +0,0 @@ -[build-system] -requires = ["maturin>=0.15,<0.16"] -build-backend = "maturin" - -[project] -name = "rustpython_ast" -requires-python = ">=3.7" -classifiers = [ - "Programming Language :: Rust", - "Programming Language :: Python :: Implementation :: CPython", -] - -[tool.maturin] -# module-name = "_rustpython_ast" -features = ["pyo3/extension-module"] diff --git a/ast-pyo3/rustpython_ast/__init__.py b/ast-pyo3/rustpython_ast/__init__.py deleted file mode 100644 index a013bb1bda8d0..0000000000000 --- a/ast-pyo3/rustpython_ast/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from rustpython_ast.rustpython_ast import parse - -__all__ = ["parse"] diff --git a/ast-pyo3/src/gen/to_py_ast.rs b/ast-pyo3/src/gen/to_py_ast.rs deleted file mode 100644 index 93ffac3aba86b..0000000000000 --- a/ast-pyo3/src/gen/to_py_ast.rs +++ /dev/null @@ -1,4882 +0,0 @@ -// File automatically generated by ast/asdl_rs.py. - -impl PyNode for ast::Mod { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ModModule { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ModInteractive { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ModExpression { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ModFunctionType { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::Stmt { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtFunctionDef { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtAsyncFunctionDef { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtClassDef { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtReturn { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtDelete { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtAssign { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtAugAssign { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtAnnAssign { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtFor { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtAsyncFor { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtWhile { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtIf { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtWith { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtAsyncWith { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtMatch { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtRaise { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtTry { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtTryStar { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtAssert { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtImport { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtImportFrom { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtGlobal { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtNonlocal { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtExpr { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtPass { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtBreak { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::StmtContinue { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::Expr { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprBoolOp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprNamedExpr { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprBinOp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprUnaryOp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprLambda { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprIfExp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprDict { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprSet { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprListComp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprSetComp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprDictComp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprGeneratorExp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprAwait { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprYield { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprYieldFrom { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprCompare { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprCall { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprFormattedValue { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprJoinedStr { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprConstant { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprAttribute { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprSubscript { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprStarred { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprName { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprList { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprTuple { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprSlice { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprContext { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprContextLoad { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprContextStore { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExprContextDel { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::BoolOp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::BoolOpAnd { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::BoolOpOr { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::Operator { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorAdd { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorSub { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorMult { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorMatMult { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorDiv { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorMod { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorPow { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorLShift { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorRShift { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorBitOr { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorBitXor { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorBitAnd { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::OperatorFloorDiv { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::UnaryOp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::UnaryOpInvert { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::UnaryOpNot { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::UnaryOpUAdd { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::UnaryOpUSub { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOp { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOpEq { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOpNotEq { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOpLt { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOpLtE { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOpGt { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOpGtE { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOpIs { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOpIsNot { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOpIn { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::CmpOpNotIn { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::Comprehension { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExceptHandler { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::ExceptHandlerExceptHandler { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::PythonArguments { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::Arg { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::Keyword { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::Alias { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::WithItem { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::MatchCase { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::Pattern { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::PatternMatchValue { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::PatternMatchSingleton { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::PatternMatchSequence { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::PatternMatchMapping { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::PatternMatchClass { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::PatternMatchStar { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::PatternMatchAs { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::PatternMatchOr { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::TypeIgnore { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::TypeIgnoreTypeIgnore { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl PyNode for ast::Decorator { - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } -} - -impl ToPyAst for ast::ExprContext { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cell = match &self { - ast::ExprContext::Load => ast::ExprContextLoad::py_type_cache(), - ast::ExprContext::Store => ast::ExprContextStore::py_type_cache(), - ast::ExprContext::Del => ast::ExprContextDel::py_type_cache(), - }; - Ok(Py::::as_ref(&cell.get().unwrap().1, py)) - } -} - -impl ToPyAst for ast::BoolOp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cell = match &self { - ast::BoolOp::And => ast::BoolOpAnd::py_type_cache(), - ast::BoolOp::Or => ast::BoolOpOr::py_type_cache(), - }; - Ok(Py::::as_ref(&cell.get().unwrap().1, py)) - } -} - -impl ToPyAst for ast::Operator { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cell = match &self { - ast::Operator::Add => ast::OperatorAdd::py_type_cache(), - ast::Operator::Sub => ast::OperatorSub::py_type_cache(), - ast::Operator::Mult => ast::OperatorMult::py_type_cache(), - ast::Operator::MatMult => ast::OperatorMatMult::py_type_cache(), - ast::Operator::Div => ast::OperatorDiv::py_type_cache(), - ast::Operator::Mod => ast::OperatorMod::py_type_cache(), - ast::Operator::Pow => ast::OperatorPow::py_type_cache(), - ast::Operator::LShift => ast::OperatorLShift::py_type_cache(), - ast::Operator::RShift => ast::OperatorRShift::py_type_cache(), - ast::Operator::BitOr => ast::OperatorBitOr::py_type_cache(), - ast::Operator::BitXor => ast::OperatorBitXor::py_type_cache(), - ast::Operator::BitAnd => ast::OperatorBitAnd::py_type_cache(), - ast::Operator::FloorDiv => ast::OperatorFloorDiv::py_type_cache(), - }; - Ok(Py::::as_ref(&cell.get().unwrap().1, py)) - } -} - -impl ToPyAst for ast::UnaryOp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cell = match &self { - ast::UnaryOp::Invert => ast::UnaryOpInvert::py_type_cache(), - ast::UnaryOp::Not => ast::UnaryOpNot::py_type_cache(), - ast::UnaryOp::UAdd => ast::UnaryOpUAdd::py_type_cache(), - ast::UnaryOp::USub => ast::UnaryOpUSub::py_type_cache(), - }; - Ok(Py::::as_ref(&cell.get().unwrap().1, py)) - } -} - -impl ToPyAst for ast::CmpOp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cell = match &self { - ast::CmpOp::Eq => ast::CmpOpEq::py_type_cache(), - ast::CmpOp::NotEq => ast::CmpOpNotEq::py_type_cache(), - ast::CmpOp::Lt => ast::CmpOpLt::py_type_cache(), - ast::CmpOp::LtE => ast::CmpOpLtE::py_type_cache(), - ast::CmpOp::Gt => ast::CmpOpGt::py_type_cache(), - ast::CmpOp::GtE => ast::CmpOpGtE::py_type_cache(), - ast::CmpOp::Is => ast::CmpOpIs::py_type_cache(), - ast::CmpOp::IsNot => ast::CmpOpIsNot::py_type_cache(), - ast::CmpOp::In => ast::CmpOpIn::py_type_cache(), - ast::CmpOp::NotIn => ast::CmpOpNotIn::py_type_cache(), - }; - Ok(Py::::as_ref(&cell.get().unwrap().1, py)) - } -} - -impl ToPyAst for ast::Mod { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::Mod::Module(cons) => cons.to_py_ast(py)?, - ast::Mod::Interactive(cons) => cons.to_py_ast(py)?, - ast::Mod::Expression(cons) => cons.to_py_ast(py)?, - ast::Mod::FunctionType(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::ModModule { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - body, - type_ignores, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((body.to_py_ast(py)?, type_ignores.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ModInteractive { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - body, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((body.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ModExpression { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - body, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((body.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ModFunctionType { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - argtypes, - returns, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((argtypes.to_py_ast(py)?, returns.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Stmt { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::Stmt::FunctionDef(cons) => cons.to_py_ast(py)?, - ast::Stmt::AsyncFunctionDef(cons) => cons.to_py_ast(py)?, - ast::Stmt::ClassDef(cons) => cons.to_py_ast(py)?, - ast::Stmt::Return(cons) => cons.to_py_ast(py)?, - ast::Stmt::Delete(cons) => cons.to_py_ast(py)?, - ast::Stmt::Assign(cons) => cons.to_py_ast(py)?, - ast::Stmt::AugAssign(cons) => cons.to_py_ast(py)?, - ast::Stmt::AnnAssign(cons) => cons.to_py_ast(py)?, - ast::Stmt::For(cons) => cons.to_py_ast(py)?, - ast::Stmt::AsyncFor(cons) => cons.to_py_ast(py)?, - ast::Stmt::While(cons) => cons.to_py_ast(py)?, - ast::Stmt::If(cons) => cons.to_py_ast(py)?, - ast::Stmt::With(cons) => cons.to_py_ast(py)?, - ast::Stmt::AsyncWith(cons) => cons.to_py_ast(py)?, - ast::Stmt::Match(cons) => cons.to_py_ast(py)?, - ast::Stmt::Raise(cons) => cons.to_py_ast(py)?, - ast::Stmt::Try(cons) => cons.to_py_ast(py)?, - ast::Stmt::TryStar(cons) => cons.to_py_ast(py)?, - ast::Stmt::Assert(cons) => cons.to_py_ast(py)?, - ast::Stmt::Import(cons) => cons.to_py_ast(py)?, - ast::Stmt::ImportFrom(cons) => cons.to_py_ast(py)?, - ast::Stmt::Global(cons) => cons.to_py_ast(py)?, - ast::Stmt::Nonlocal(cons) => cons.to_py_ast(py)?, - ast::Stmt::Expr(cons) => cons.to_py_ast(py)?, - ast::Stmt::Pass(cons) => cons.to_py_ast(py)?, - ast::Stmt::Break(cons) => cons.to_py_ast(py)?, - ast::Stmt::Continue(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::StmtFunctionDef { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - name, - args, - body, - decorator_list, - returns, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - name.to_py_ast(py)?, - args.to_py_ast(py)?, - body.to_py_ast(py)?, - decorator_list.to_py_ast(py)?, - returns.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAsyncFunctionDef { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - name, - args, - body, - decorator_list, - returns, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - name.to_py_ast(py)?, - args.to_py_ast(py)?, - body.to_py_ast(py)?, - decorator_list.to_py_ast(py)?, - returns.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtClassDef { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - name, - bases, - keywords, - body, - decorator_list, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - name.to_py_ast(py)?, - bases.to_py_ast(py)?, - keywords.to_py_ast(py)?, - body.to_py_ast(py)?, - decorator_list.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtReturn { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtDelete { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - targets, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((targets.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAssign { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - targets, - value, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - targets.to_py_ast(py)?, - value.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAugAssign { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - op, - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - target.to_py_ast(py)?, - op.to_py_ast(py)?, - value.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAnnAssign { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - annotation, - value, - simple, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - target.to_py_ast(py)?, - annotation.to_py_ast(py)?, - value.to_py_ast(py)?, - simple.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtFor { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - iter, - body, - orelse, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - target.to_py_ast(py)?, - iter.to_py_ast(py)?, - body.to_py_ast(py)?, - orelse.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAsyncFor { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - iter, - body, - orelse, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - target.to_py_ast(py)?, - iter.to_py_ast(py)?, - body.to_py_ast(py)?, - orelse.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtWhile { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - test, - body, - orelse, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - test.to_py_ast(py)?, - body.to_py_ast(py)?, - orelse.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtIf { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - test, - body, - orelse, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - test.to_py_ast(py)?, - body.to_py_ast(py)?, - orelse.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtWith { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - items, - body, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - items.to_py_ast(py)?, - body.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAsyncWith { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - items, - body, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - items.to_py_ast(py)?, - body.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtMatch { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - subject, - cases, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((subject.to_py_ast(py)?, cases.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtRaise { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - exc, - cause, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((exc.to_py_ast(py)?, cause.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtTry { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - body, - handlers, - orelse, - finalbody, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - body.to_py_ast(py)?, - handlers.to_py_ast(py)?, - orelse.to_py_ast(py)?, - finalbody.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtTryStar { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - body, - handlers, - orelse, - finalbody, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - body.to_py_ast(py)?, - handlers.to_py_ast(py)?, - orelse.to_py_ast(py)?, - finalbody.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAssert { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - test, - msg, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((test.to_py_ast(py)?, msg.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtImport { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - names, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((names.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtImportFrom { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - module, - names, - level, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - module.to_py_ast(py)?, - names.to_py_ast(py)?, - level.map_or_else(|| py.None(), |level| level.to_u32().to_object(py)), - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtGlobal { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - names, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((names.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtNonlocal { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - names, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((names.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtExpr { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtPass { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { range: _range } = self; - let instance = Py::::as_ref(&cache.0, py).call0()?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtBreak { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { range: _range } = self; - let instance = Py::::as_ref(&cache.0, py).call0()?; - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtContinue { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { range: _range } = self; - let instance = Py::::as_ref(&cache.0, py).call0()?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Expr { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::Expr::BoolOp(cons) => cons.to_py_ast(py)?, - ast::Expr::NamedExpr(cons) => cons.to_py_ast(py)?, - ast::Expr::BinOp(cons) => cons.to_py_ast(py)?, - ast::Expr::UnaryOp(cons) => cons.to_py_ast(py)?, - ast::Expr::Lambda(cons) => cons.to_py_ast(py)?, - ast::Expr::IfExp(cons) => cons.to_py_ast(py)?, - ast::Expr::Dict(cons) => cons.to_py_ast(py)?, - ast::Expr::Set(cons) => cons.to_py_ast(py)?, - ast::Expr::ListComp(cons) => cons.to_py_ast(py)?, - ast::Expr::SetComp(cons) => cons.to_py_ast(py)?, - ast::Expr::DictComp(cons) => cons.to_py_ast(py)?, - ast::Expr::GeneratorExp(cons) => cons.to_py_ast(py)?, - ast::Expr::Await(cons) => cons.to_py_ast(py)?, - ast::Expr::Yield(cons) => cons.to_py_ast(py)?, - ast::Expr::YieldFrom(cons) => cons.to_py_ast(py)?, - ast::Expr::Compare(cons) => cons.to_py_ast(py)?, - ast::Expr::Call(cons) => cons.to_py_ast(py)?, - ast::Expr::FormattedValue(cons) => cons.to_py_ast(py)?, - ast::Expr::JoinedStr(cons) => cons.to_py_ast(py)?, - ast::Expr::Constant(cons) => cons.to_py_ast(py)?, - ast::Expr::Attribute(cons) => cons.to_py_ast(py)?, - ast::Expr::Subscript(cons) => cons.to_py_ast(py)?, - ast::Expr::Starred(cons) => cons.to_py_ast(py)?, - ast::Expr::Name(cons) => cons.to_py_ast(py)?, - ast::Expr::List(cons) => cons.to_py_ast(py)?, - ast::Expr::Tuple(cons) => cons.to_py_ast(py)?, - ast::Expr::Slice(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::ExprBoolOp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - op, - values, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((op.to_py_ast(py)?, values.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprNamedExpr { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((target.to_py_ast(py)?, value.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprBinOp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - left, - op, - right, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - left.to_py_ast(py)?, - op.to_py_ast(py)?, - right.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprUnaryOp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - op, - operand, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((op.to_py_ast(py)?, operand.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprLambda { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - args, - body, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((args.to_py_ast(py)?, body.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprIfExp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - test, - body, - orelse, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - test.to_py_ast(py)?, - body.to_py_ast(py)?, - orelse.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprDict { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - keys, - values, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((keys.to_py_ast(py)?, values.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprSet { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elts, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((elts.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprListComp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elt, - generators, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((elt.to_py_ast(py)?, generators.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprSetComp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elt, - generators, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((elt.to_py_ast(py)?, generators.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprDictComp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - key, - value, - generators, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - key.to_py_ast(py)?, - value.to_py_ast(py)?, - generators.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprGeneratorExp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elt, - generators, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((elt.to_py_ast(py)?, generators.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprAwait { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprYield { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprYieldFrom { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprCompare { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - left, - ops, - comparators, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - left.to_py_ast(py)?, - ops.to_py_ast(py)?, - comparators.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprCall { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - func, - args, - keywords, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - func.to_py_ast(py)?, - args.to_py_ast(py)?, - keywords.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprFormattedValue { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - conversion, - format_spec, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - value.to_py_ast(py)?, - conversion.to_py_ast(py)?, - format_spec.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprJoinedStr { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - values, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((values.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprConstant { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - kind, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((constant_to_object(value, py), kind.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprAttribute { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - attr, - ctx, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - value.to_py_ast(py)?, - attr.to_py_ast(py)?, - ctx.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprSubscript { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - slice, - ctx, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - value.to_py_ast(py)?, - slice.to_py_ast(py)?, - ctx.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprStarred { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - ctx, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?, ctx.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprName { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - id, - ctx, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((id.to_py_ast(py)?, ctx.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprList { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elts, - ctx, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((elts.to_py_ast(py)?, ctx.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprTuple { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elts, - ctx, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((elts.to_py_ast(py)?, ctx.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprSlice { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - lower, - upper, - step, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - lower.to_py_ast(py)?, - upper.to_py_ast(py)?, - step.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Comprehension { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - iter, - ifs, - is_async, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - target.to_py_ast(py)?, - iter.to_py_ast(py)?, - ifs.to_py_ast(py)?, - is_async.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExceptHandler { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::ExceptHandler::ExceptHandler(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::ExceptHandlerExceptHandler { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - type_, - name, - body, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - type_.to_py_ast(py)?, - name.to_py_ast(py)?, - body.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::PythonArguments { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - posonlyargs, - args, - vararg, - kwonlyargs, - kw_defaults, - kwarg, - defaults, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - posonlyargs.to_py_ast(py)?, - args.to_py_ast(py)?, - vararg.to_py_ast(py)?, - kwonlyargs.to_py_ast(py)?, - kw_defaults.to_py_ast(py)?, - kwarg.to_py_ast(py)?, - defaults.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Arg { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - arg, - annotation, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - arg.to_py_ast(py)?, - annotation.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Keyword { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - arg, - value, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((arg.to_py_ast(py)?, value.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Alias { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - name, - asname, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((name.to_py_ast(py)?, asname.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::WithItem { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - context_expr, - optional_vars, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((context_expr.to_py_ast(py)?, optional_vars.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::MatchCase { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - pattern, - guard, - body, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - pattern.to_py_ast(py)?, - guard.to_py_ast(py)?, - body.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Pattern { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::Pattern::MatchValue(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchSingleton(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchSequence(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchMapping(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchClass(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchStar(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchAs(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchOr(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchValue { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchSingleton { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((constant_to_object(value, py),))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchSequence { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - patterns, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((patterns.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchMapping { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - keys, - patterns, - rest, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - keys.to_py_ast(py)?, - patterns.to_py_ast(py)?, - rest.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchClass { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - cls, - patterns, - kwd_attrs, - kwd_patterns, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - cls.to_py_ast(py)?, - patterns.to_py_ast(py)?, - kwd_attrs.to_py_ast(py)?, - kwd_patterns.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchStar { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - name, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((name.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchAs { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - pattern, - name, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((pattern.to_py_ast(py)?, name.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchOr { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - patterns, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((patterns.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::TypeIgnore { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::TypeIgnore::TypeIgnore(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::TypeIgnoreTypeIgnore { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - lineno, - tag, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((lineno.to_u32().to_object(py), tag.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Decorator { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - expression, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((expression.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Mod { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::Mod::Module(cons) => cons.to_py_ast(py)?, - ast::Mod::Interactive(cons) => cons.to_py_ast(py)?, - ast::Mod::Expression(cons) => cons.to_py_ast(py)?, - ast::Mod::FunctionType(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::ModModule { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - body, - type_ignores, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((body.to_py_ast(py)?, type_ignores.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ModInteractive { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - body, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((body.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ModExpression { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - body, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((body.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ModFunctionType { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - argtypes, - returns, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((argtypes.to_py_ast(py)?, returns.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Stmt { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::Stmt::FunctionDef(cons) => cons.to_py_ast(py)?, - ast::Stmt::AsyncFunctionDef(cons) => cons.to_py_ast(py)?, - ast::Stmt::ClassDef(cons) => cons.to_py_ast(py)?, - ast::Stmt::Return(cons) => cons.to_py_ast(py)?, - ast::Stmt::Delete(cons) => cons.to_py_ast(py)?, - ast::Stmt::Assign(cons) => cons.to_py_ast(py)?, - ast::Stmt::AugAssign(cons) => cons.to_py_ast(py)?, - ast::Stmt::AnnAssign(cons) => cons.to_py_ast(py)?, - ast::Stmt::For(cons) => cons.to_py_ast(py)?, - ast::Stmt::AsyncFor(cons) => cons.to_py_ast(py)?, - ast::Stmt::While(cons) => cons.to_py_ast(py)?, - ast::Stmt::If(cons) => cons.to_py_ast(py)?, - ast::Stmt::With(cons) => cons.to_py_ast(py)?, - ast::Stmt::AsyncWith(cons) => cons.to_py_ast(py)?, - ast::Stmt::Match(cons) => cons.to_py_ast(py)?, - ast::Stmt::Raise(cons) => cons.to_py_ast(py)?, - ast::Stmt::Try(cons) => cons.to_py_ast(py)?, - ast::Stmt::TryStar(cons) => cons.to_py_ast(py)?, - ast::Stmt::Assert(cons) => cons.to_py_ast(py)?, - ast::Stmt::Import(cons) => cons.to_py_ast(py)?, - ast::Stmt::ImportFrom(cons) => cons.to_py_ast(py)?, - ast::Stmt::Global(cons) => cons.to_py_ast(py)?, - ast::Stmt::Nonlocal(cons) => cons.to_py_ast(py)?, - ast::Stmt::Expr(cons) => cons.to_py_ast(py)?, - ast::Stmt::Pass(cons) => cons.to_py_ast(py)?, - ast::Stmt::Break(cons) => cons.to_py_ast(py)?, - ast::Stmt::Continue(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::StmtFunctionDef { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - name, - args, - body, - decorator_list, - returns, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - name.to_py_ast(py)?, - args.to_py_ast(py)?, - body.to_py_ast(py)?, - decorator_list.to_py_ast(py)?, - returns.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAsyncFunctionDef { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - name, - args, - body, - decorator_list, - returns, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - name.to_py_ast(py)?, - args.to_py_ast(py)?, - body.to_py_ast(py)?, - decorator_list.to_py_ast(py)?, - returns.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtClassDef { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - name, - bases, - keywords, - body, - decorator_list, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - name.to_py_ast(py)?, - bases.to_py_ast(py)?, - keywords.to_py_ast(py)?, - body.to_py_ast(py)?, - decorator_list.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtReturn { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtDelete { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - targets, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((targets.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAssign { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - targets, - value, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - targets.to_py_ast(py)?, - value.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAugAssign { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - op, - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - target.to_py_ast(py)?, - op.to_py_ast(py)?, - value.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAnnAssign { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - annotation, - value, - simple, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - target.to_py_ast(py)?, - annotation.to_py_ast(py)?, - value.to_py_ast(py)?, - simple.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtFor { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - iter, - body, - orelse, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - target.to_py_ast(py)?, - iter.to_py_ast(py)?, - body.to_py_ast(py)?, - orelse.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAsyncFor { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - iter, - body, - orelse, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - target.to_py_ast(py)?, - iter.to_py_ast(py)?, - body.to_py_ast(py)?, - orelse.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtWhile { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - test, - body, - orelse, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - test.to_py_ast(py)?, - body.to_py_ast(py)?, - orelse.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtIf { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - test, - body, - orelse, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - test.to_py_ast(py)?, - body.to_py_ast(py)?, - orelse.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtWith { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - items, - body, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - items.to_py_ast(py)?, - body.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAsyncWith { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - items, - body, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - items.to_py_ast(py)?, - body.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtMatch { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - subject, - cases, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((subject.to_py_ast(py)?, cases.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtRaise { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - exc, - cause, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((exc.to_py_ast(py)?, cause.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtTry { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - body, - handlers, - orelse, - finalbody, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - body.to_py_ast(py)?, - handlers.to_py_ast(py)?, - orelse.to_py_ast(py)?, - finalbody.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtTryStar { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - body, - handlers, - orelse, - finalbody, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - body.to_py_ast(py)?, - handlers.to_py_ast(py)?, - orelse.to_py_ast(py)?, - finalbody.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtAssert { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - test, - msg, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((test.to_py_ast(py)?, msg.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtImport { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - names, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((names.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtImportFrom { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - module, - names, - level, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - module.to_py_ast(py)?, - names.to_py_ast(py)?, - level.map_or_else(|| py.None(), |level| level.to_u32().to_object(py)), - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtGlobal { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - names, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((names.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtNonlocal { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - names, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((names.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtExpr { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtPass { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { range: _range } = self; - let instance = Py::::as_ref(&cache.0, py).call0()?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtBreak { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { range: _range } = self; - let instance = Py::::as_ref(&cache.0, py).call0()?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::StmtContinue { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { range: _range } = self; - let instance = Py::::as_ref(&cache.0, py).call0()?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::Expr { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::Expr::BoolOp(cons) => cons.to_py_ast(py)?, - ast::Expr::NamedExpr(cons) => cons.to_py_ast(py)?, - ast::Expr::BinOp(cons) => cons.to_py_ast(py)?, - ast::Expr::UnaryOp(cons) => cons.to_py_ast(py)?, - ast::Expr::Lambda(cons) => cons.to_py_ast(py)?, - ast::Expr::IfExp(cons) => cons.to_py_ast(py)?, - ast::Expr::Dict(cons) => cons.to_py_ast(py)?, - ast::Expr::Set(cons) => cons.to_py_ast(py)?, - ast::Expr::ListComp(cons) => cons.to_py_ast(py)?, - ast::Expr::SetComp(cons) => cons.to_py_ast(py)?, - ast::Expr::DictComp(cons) => cons.to_py_ast(py)?, - ast::Expr::GeneratorExp(cons) => cons.to_py_ast(py)?, - ast::Expr::Await(cons) => cons.to_py_ast(py)?, - ast::Expr::Yield(cons) => cons.to_py_ast(py)?, - ast::Expr::YieldFrom(cons) => cons.to_py_ast(py)?, - ast::Expr::Compare(cons) => cons.to_py_ast(py)?, - ast::Expr::Call(cons) => cons.to_py_ast(py)?, - ast::Expr::FormattedValue(cons) => cons.to_py_ast(py)?, - ast::Expr::JoinedStr(cons) => cons.to_py_ast(py)?, - ast::Expr::Constant(cons) => cons.to_py_ast(py)?, - ast::Expr::Attribute(cons) => cons.to_py_ast(py)?, - ast::Expr::Subscript(cons) => cons.to_py_ast(py)?, - ast::Expr::Starred(cons) => cons.to_py_ast(py)?, - ast::Expr::Name(cons) => cons.to_py_ast(py)?, - ast::Expr::List(cons) => cons.to_py_ast(py)?, - ast::Expr::Tuple(cons) => cons.to_py_ast(py)?, - ast::Expr::Slice(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::ExprBoolOp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - op, - values, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((op.to_py_ast(py)?, values.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprNamedExpr { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((target.to_py_ast(py)?, value.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprBinOp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - left, - op, - right, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - left.to_py_ast(py)?, - op.to_py_ast(py)?, - right.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprUnaryOp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - op, - operand, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((op.to_py_ast(py)?, operand.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprLambda { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - args, - body, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((args.to_py_ast(py)?, body.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprIfExp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - test, - body, - orelse, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - test.to_py_ast(py)?, - body.to_py_ast(py)?, - orelse.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprDict { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - keys, - values, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((keys.to_py_ast(py)?, values.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprSet { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elts, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((elts.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprListComp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elt, - generators, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((elt.to_py_ast(py)?, generators.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprSetComp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elt, - generators, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((elt.to_py_ast(py)?, generators.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprDictComp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - key, - value, - generators, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - key.to_py_ast(py)?, - value.to_py_ast(py)?, - generators.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprGeneratorExp { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elt, - generators, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((elt.to_py_ast(py)?, generators.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprAwait { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprYield { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprYieldFrom { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprCompare { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - left, - ops, - comparators, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - left.to_py_ast(py)?, - ops.to_py_ast(py)?, - comparators.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprCall { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - func, - args, - keywords, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - func.to_py_ast(py)?, - args.to_py_ast(py)?, - keywords.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprFormattedValue { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - conversion, - format_spec, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - value.to_py_ast(py)?, - conversion.to_py_ast(py)?, - format_spec.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprJoinedStr { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - values, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((values.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprConstant { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - kind, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((constant_to_object(value, py), kind.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprAttribute { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - attr, - ctx, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - value.to_py_ast(py)?, - attr.to_py_ast(py)?, - ctx.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprSubscript { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - slice, - ctx, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - value.to_py_ast(py)?, - slice.to_py_ast(py)?, - ctx.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprStarred { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - ctx, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?, ctx.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprName { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - id, - ctx, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((id.to_py_ast(py)?, ctx.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprList { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elts, - ctx, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((elts.to_py_ast(py)?, ctx.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprTuple { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - elts, - ctx, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((elts.to_py_ast(py)?, ctx.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::ExprSlice { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - lower, - upper, - step, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - lower.to_py_ast(py)?, - upper.to_py_ast(py)?, - step.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::Comprehension { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - target, - iter, - ifs, - is_async, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - target.to_py_ast(py)?, - iter.to_py_ast(py)?, - ifs.to_py_ast(py)?, - is_async.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::ExceptHandler { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::ExceptHandler::ExceptHandler(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::ExceptHandlerExceptHandler { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - type_, - name, - body, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - type_.to_py_ast(py)?, - name.to_py_ast(py)?, - body.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::PythonArguments { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - posonlyargs, - args, - vararg, - kwonlyargs, - kw_defaults, - kwarg, - defaults, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - posonlyargs.to_py_ast(py)?, - args.to_py_ast(py)?, - vararg.to_py_ast(py)?, - kwonlyargs.to_py_ast(py)?, - kw_defaults.to_py_ast(py)?, - kwarg.to_py_ast(py)?, - defaults.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Arg { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - arg, - annotation, - type_comment, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - arg.to_py_ast(py)?, - annotation.to_py_ast(py)?, - type_comment.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::Keyword { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - arg, - value, - range: _range, - } = self; - - let instance = - Py::::as_ref(&cache.0, py).call1((arg.to_py_ast(py)?, value.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::Alias { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - name, - asname, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((name.to_py_ast(py)?, asname.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::WithItem { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - context_expr, - optional_vars, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((context_expr.to_py_ast(py)?, optional_vars.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::MatchCase { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - pattern, - guard, - body, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - pattern.to_py_ast(py)?, - guard.to_py_ast(py)?, - body.to_py_ast(py)?, - ))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Pattern { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::Pattern::MatchValue(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchSingleton(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchSequence(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchMapping(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchClass(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchStar(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchAs(cons) => cons.to_py_ast(py)?, - ast::Pattern::MatchOr(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchValue { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((value.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchSingleton { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - value, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((constant_to_object(value, py),))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchSequence { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - patterns, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((patterns.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchMapping { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - keys, - patterns, - rest, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - keys.to_py_ast(py)?, - patterns.to_py_ast(py)?, - rest.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchClass { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - cls, - patterns, - kwd_attrs, - kwd_patterns, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1(( - cls.to_py_ast(py)?, - patterns.to_py_ast(py)?, - kwd_attrs.to_py_ast(py)?, - kwd_patterns.to_py_ast(py)?, - ))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchStar { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - name, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((name.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchAs { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - pattern, - name, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((pattern.to_py_ast(py)?, name.to_py_ast(py)?))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::PatternMatchOr { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - patterns, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((patterns.to_py_ast(py)?,))?; - - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - - Ok(instance) - } -} - -impl ToPyAst for ast::TypeIgnore { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let instance = match &self { - ast::TypeIgnore::TypeIgnore(cons) => cons.to_py_ast(py)?, - }; - Ok(instance) - } -} - -impl ToPyAst for ast::TypeIgnoreTypeIgnore { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - lineno, - tag, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py) - .call1((lineno.to_u32().to_object(py), tag.to_py_ast(py)?))?; - - Ok(instance) - } -} - -impl ToPyAst for ast::Decorator { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let cache = Self::py_type_cache().get().unwrap(); - - let Self { - expression, - range: _range, - } = self; - - let instance = Py::::as_ref(&cache.0, py).call1((expression.to_py_ast(py)?,))?; - - Ok(instance) - } -} - -fn init_types(py: Python) -> PyResult<()> { - let ast_module = PyModule::import(py, "_ast")?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - cache_py_type::(ast_module)?; - Ok(()) -} diff --git a/ast-pyo3/src/gen/wrapper_located.rs b/ast-pyo3/src/gen/wrapper_located.rs deleted file mode 100644 index 9890414f5d921..0000000000000 --- a/ast-pyo3/src/gen/wrapper_located.rs +++ /dev/null @@ -1,4447 +0,0 @@ -// File automatically generated by ast/asdl_rs.py. - -#[pyclass(module="rustpython_ast.located", name="_mod", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct Mod; - -impl From<&'static ast::Mod> for Mod { - fn from(_node: &'static ast::Mod) -> Self { - Mod - } -} - -#[pymethods] -impl Mod { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for Mod { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Mod { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::Module(cons) => cons.to_py_wrapper(py), - Self::Interactive(cons) => cons.to_py_wrapper(py), - Self::Expression(cons) => cons.to_py_wrapper(py), - Self::FunctionType(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.located", name="_Module", extends=Mod, frozen)] -#[derive(Clone, Debug)] -pub struct ModModule(pub &'static ast::ModModule); - -impl From<&'static ast::ModModule> for ModModule { - fn from(node: &'static ast::ModModule) -> Self { - ModModule(node) - } -} - -impl ToPyObject for ModModule { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Mod) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ModModule { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ModModule(self).to_object(py)) - } -} - -#[pymethods] -impl ModModule { - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_ignores(&self, py: Python) -> PyResult { - self.0.type_ignores.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Interactive", extends=Mod, frozen)] -#[derive(Clone, Debug)] -pub struct ModInteractive(pub &'static ast::ModInteractive); - -impl From<&'static ast::ModInteractive> for ModInteractive { - fn from(node: &'static ast::ModInteractive) -> Self { - ModInteractive(node) - } -} - -impl ToPyObject for ModInteractive { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Mod) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ModInteractive { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ModInteractive(self).to_object(py)) - } -} - -#[pymethods] -impl ModInteractive { - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Expression", extends=Mod, frozen)] -#[derive(Clone, Debug)] -pub struct ModExpression(pub &'static ast::ModExpression); - -impl From<&'static ast::ModExpression> for ModExpression { - fn from(node: &'static ast::ModExpression) -> Self { - ModExpression(node) - } -} - -impl ToPyObject for ModExpression { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Mod) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ModExpression { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ModExpression(self).to_object(py)) - } -} - -#[pymethods] -impl ModExpression { - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_FunctionType", extends=Mod, frozen)] -#[derive(Clone, Debug)] -pub struct ModFunctionType(pub &'static ast::ModFunctionType); - -impl From<&'static ast::ModFunctionType> for ModFunctionType { - fn from(node: &'static ast::ModFunctionType) -> Self { - ModFunctionType(node) - } -} - -impl ToPyObject for ModFunctionType { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Mod) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ModFunctionType { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ModFunctionType(self).to_object(py)) - } -} - -#[pymethods] -impl ModFunctionType { - #[getter] - #[inline] - fn get_argtypes(&self, py: Python) -> PyResult { - self.0.argtypes.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_returns(&self, py: Python) -> PyResult { - self.0.returns.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_stmt", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct Stmt; - -impl From<&'static ast::Stmt> for Stmt { - fn from(_node: &'static ast::Stmt) -> Self { - Stmt - } -} - -#[pymethods] -impl Stmt { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for Stmt { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Stmt { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::FunctionDef(cons) => cons.to_py_wrapper(py), - Self::AsyncFunctionDef(cons) => cons.to_py_wrapper(py), - Self::ClassDef(cons) => cons.to_py_wrapper(py), - Self::Return(cons) => cons.to_py_wrapper(py), - Self::Delete(cons) => cons.to_py_wrapper(py), - Self::Assign(cons) => cons.to_py_wrapper(py), - Self::AugAssign(cons) => cons.to_py_wrapper(py), - Self::AnnAssign(cons) => cons.to_py_wrapper(py), - Self::For(cons) => cons.to_py_wrapper(py), - Self::AsyncFor(cons) => cons.to_py_wrapper(py), - Self::While(cons) => cons.to_py_wrapper(py), - Self::If(cons) => cons.to_py_wrapper(py), - Self::With(cons) => cons.to_py_wrapper(py), - Self::AsyncWith(cons) => cons.to_py_wrapper(py), - Self::Match(cons) => cons.to_py_wrapper(py), - Self::Raise(cons) => cons.to_py_wrapper(py), - Self::Try(cons) => cons.to_py_wrapper(py), - Self::TryStar(cons) => cons.to_py_wrapper(py), - Self::Assert(cons) => cons.to_py_wrapper(py), - Self::Import(cons) => cons.to_py_wrapper(py), - Self::ImportFrom(cons) => cons.to_py_wrapper(py), - Self::Global(cons) => cons.to_py_wrapper(py), - Self::Nonlocal(cons) => cons.to_py_wrapper(py), - Self::Expr(cons) => cons.to_py_wrapper(py), - Self::Pass(cons) => cons.to_py_wrapper(py), - Self::Break(cons) => cons.to_py_wrapper(py), - Self::Continue(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.located", name="_FunctionDef", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtFunctionDef(pub &'static ast::StmtFunctionDef); - -impl From<&'static ast::StmtFunctionDef> for StmtFunctionDef { - fn from(node: &'static ast::StmtFunctionDef) -> Self { - StmtFunctionDef(node) - } -} - -impl ToPyObject for StmtFunctionDef { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtFunctionDef { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtFunctionDef(self).to_object(py)) - } -} - -#[pymethods] -impl StmtFunctionDef { - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_args(&self, py: Python) -> PyResult { - self.0.args.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_decorator_list(&self, py: Python) -> PyResult { - self.0.decorator_list.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_returns(&self, py: Python) -> PyResult { - self.0.returns.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_AsyncFunctionDef", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAsyncFunctionDef(pub &'static ast::StmtAsyncFunctionDef); - -impl From<&'static ast::StmtAsyncFunctionDef> for StmtAsyncFunctionDef { - fn from(node: &'static ast::StmtAsyncFunctionDef) -> Self { - StmtAsyncFunctionDef(node) - } -} - -impl ToPyObject for StmtAsyncFunctionDef { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAsyncFunctionDef { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAsyncFunctionDef(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAsyncFunctionDef { - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_args(&self, py: Python) -> PyResult { - self.0.args.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_decorator_list(&self, py: Python) -> PyResult { - self.0.decorator_list.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_returns(&self, py: Python) -> PyResult { - self.0.returns.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_ClassDef", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtClassDef(pub &'static ast::StmtClassDef); - -impl From<&'static ast::StmtClassDef> for StmtClassDef { - fn from(node: &'static ast::StmtClassDef) -> Self { - StmtClassDef(node) - } -} - -impl ToPyObject for StmtClassDef { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtClassDef { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtClassDef(self).to_object(py)) - } -} - -#[pymethods] -impl StmtClassDef { - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_bases(&self, py: Python) -> PyResult { - self.0.bases.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_keywords(&self, py: Python) -> PyResult { - self.0.keywords.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_decorator_list(&self, py: Python) -> PyResult { - self.0.decorator_list.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Return", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtReturn(pub &'static ast::StmtReturn); - -impl From<&'static ast::StmtReturn> for StmtReturn { - fn from(node: &'static ast::StmtReturn) -> Self { - StmtReturn(node) - } -} - -impl ToPyObject for StmtReturn { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtReturn { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtReturn(self).to_object(py)) - } -} - -#[pymethods] -impl StmtReturn { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Delete", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtDelete(pub &'static ast::StmtDelete); - -impl From<&'static ast::StmtDelete> for StmtDelete { - fn from(node: &'static ast::StmtDelete) -> Self { - StmtDelete(node) - } -} - -impl ToPyObject for StmtDelete { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtDelete { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtDelete(self).to_object(py)) - } -} - -#[pymethods] -impl StmtDelete { - #[getter] - #[inline] - fn get_targets(&self, py: Python) -> PyResult { - self.0.targets.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Assign", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAssign(pub &'static ast::StmtAssign); - -impl From<&'static ast::StmtAssign> for StmtAssign { - fn from(node: &'static ast::StmtAssign) -> Self { - StmtAssign(node) - } -} - -impl ToPyObject for StmtAssign { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAssign { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAssign(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAssign { - #[getter] - #[inline] - fn get_targets(&self, py: Python) -> PyResult { - self.0.targets.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_AugAssign", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAugAssign(pub &'static ast::StmtAugAssign); - -impl From<&'static ast::StmtAugAssign> for StmtAugAssign { - fn from(node: &'static ast::StmtAugAssign) -> Self { - StmtAugAssign(node) - } -} - -impl ToPyObject for StmtAugAssign { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAugAssign { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAugAssign(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAugAssign { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_op(&self, py: Python) -> PyResult { - self.0.op.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_AnnAssign", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAnnAssign(pub &'static ast::StmtAnnAssign); - -impl From<&'static ast::StmtAnnAssign> for StmtAnnAssign { - fn from(node: &'static ast::StmtAnnAssign) -> Self { - StmtAnnAssign(node) - } -} - -impl ToPyObject for StmtAnnAssign { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAnnAssign { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAnnAssign(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAnnAssign { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_annotation(&self, py: Python) -> PyResult { - self.0.annotation.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_simple(&self, py: Python) -> PyResult { - self.0.simple.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_For", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtFor(pub &'static ast::StmtFor); - -impl From<&'static ast::StmtFor> for StmtFor { - fn from(node: &'static ast::StmtFor) -> Self { - StmtFor(node) - } -} - -impl ToPyObject for StmtFor { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtFor { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtFor(self).to_object(py)) - } -} - -#[pymethods] -impl StmtFor { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_iter(&self, py: Python) -> PyResult { - self.0.iter.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_AsyncFor", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAsyncFor(pub &'static ast::StmtAsyncFor); - -impl From<&'static ast::StmtAsyncFor> for StmtAsyncFor { - fn from(node: &'static ast::StmtAsyncFor) -> Self { - StmtAsyncFor(node) - } -} - -impl ToPyObject for StmtAsyncFor { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAsyncFor { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAsyncFor(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAsyncFor { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_iter(&self, py: Python) -> PyResult { - self.0.iter.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_While", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtWhile(pub &'static ast::StmtWhile); - -impl From<&'static ast::StmtWhile> for StmtWhile { - fn from(node: &'static ast::StmtWhile) -> Self { - StmtWhile(node) - } -} - -impl ToPyObject for StmtWhile { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtWhile { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtWhile(self).to_object(py)) - } -} - -#[pymethods] -impl StmtWhile { - #[getter] - #[inline] - fn get_test(&self, py: Python) -> PyResult { - self.0.test.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_If", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtIf(pub &'static ast::StmtIf); - -impl From<&'static ast::StmtIf> for StmtIf { - fn from(node: &'static ast::StmtIf) -> Self { - StmtIf(node) - } -} - -impl ToPyObject for StmtIf { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtIf { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtIf(self).to_object(py)) - } -} - -#[pymethods] -impl StmtIf { - #[getter] - #[inline] - fn get_test(&self, py: Python) -> PyResult { - self.0.test.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_With", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtWith(pub &'static ast::StmtWith); - -impl From<&'static ast::StmtWith> for StmtWith { - fn from(node: &'static ast::StmtWith) -> Self { - StmtWith(node) - } -} - -impl ToPyObject for StmtWith { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtWith { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtWith(self).to_object(py)) - } -} - -#[pymethods] -impl StmtWith { - #[getter] - #[inline] - fn get_items(&self, py: Python) -> PyResult { - self.0.items.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_AsyncWith", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAsyncWith(pub &'static ast::StmtAsyncWith); - -impl From<&'static ast::StmtAsyncWith> for StmtAsyncWith { - fn from(node: &'static ast::StmtAsyncWith) -> Self { - StmtAsyncWith(node) - } -} - -impl ToPyObject for StmtAsyncWith { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAsyncWith { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAsyncWith(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAsyncWith { - #[getter] - #[inline] - fn get_items(&self, py: Python) -> PyResult { - self.0.items.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Match", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtMatch(pub &'static ast::StmtMatch); - -impl From<&'static ast::StmtMatch> for StmtMatch { - fn from(node: &'static ast::StmtMatch) -> Self { - StmtMatch(node) - } -} - -impl ToPyObject for StmtMatch { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtMatch { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtMatch(self).to_object(py)) - } -} - -#[pymethods] -impl StmtMatch { - #[getter] - #[inline] - fn get_subject(&self, py: Python) -> PyResult { - self.0.subject.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_cases(&self, py: Python) -> PyResult { - self.0.cases.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Raise", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtRaise(pub &'static ast::StmtRaise); - -impl From<&'static ast::StmtRaise> for StmtRaise { - fn from(node: &'static ast::StmtRaise) -> Self { - StmtRaise(node) - } -} - -impl ToPyObject for StmtRaise { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtRaise { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtRaise(self).to_object(py)) - } -} - -#[pymethods] -impl StmtRaise { - #[getter] - #[inline] - fn get_exc(&self, py: Python) -> PyResult { - self.0.exc.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_cause(&self, py: Python) -> PyResult { - self.0.cause.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Try", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtTry(pub &'static ast::StmtTry); - -impl From<&'static ast::StmtTry> for StmtTry { - fn from(node: &'static ast::StmtTry) -> Self { - StmtTry(node) - } -} - -impl ToPyObject for StmtTry { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtTry { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtTry(self).to_object(py)) - } -} - -#[pymethods] -impl StmtTry { - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_handlers(&self, py: Python) -> PyResult { - self.0.handlers.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_finalbody(&self, py: Python) -> PyResult { - self.0.finalbody.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_TryStar", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtTryStar(pub &'static ast::StmtTryStar); - -impl From<&'static ast::StmtTryStar> for StmtTryStar { - fn from(node: &'static ast::StmtTryStar) -> Self { - StmtTryStar(node) - } -} - -impl ToPyObject for StmtTryStar { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtTryStar { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtTryStar(self).to_object(py)) - } -} - -#[pymethods] -impl StmtTryStar { - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_handlers(&self, py: Python) -> PyResult { - self.0.handlers.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_finalbody(&self, py: Python) -> PyResult { - self.0.finalbody.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Assert", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAssert(pub &'static ast::StmtAssert); - -impl From<&'static ast::StmtAssert> for StmtAssert { - fn from(node: &'static ast::StmtAssert) -> Self { - StmtAssert(node) - } -} - -impl ToPyObject for StmtAssert { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAssert { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAssert(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAssert { - #[getter] - #[inline] - fn get_test(&self, py: Python) -> PyResult { - self.0.test.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_msg(&self, py: Python) -> PyResult { - self.0.msg.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Import", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtImport(pub &'static ast::StmtImport); - -impl From<&'static ast::StmtImport> for StmtImport { - fn from(node: &'static ast::StmtImport) -> Self { - StmtImport(node) - } -} - -impl ToPyObject for StmtImport { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtImport { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtImport(self).to_object(py)) - } -} - -#[pymethods] -impl StmtImport { - #[getter] - #[inline] - fn get_names(&self, py: Python) -> PyResult { - self.0.names.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_ImportFrom", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtImportFrom(pub &'static ast::StmtImportFrom); - -impl From<&'static ast::StmtImportFrom> for StmtImportFrom { - fn from(node: &'static ast::StmtImportFrom) -> Self { - StmtImportFrom(node) - } -} - -impl ToPyObject for StmtImportFrom { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtImportFrom { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtImportFrom(self).to_object(py)) - } -} - -#[pymethods] -impl StmtImportFrom { - #[getter] - #[inline] - fn get_module(&self, py: Python) -> PyResult { - self.0.module.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_names(&self, py: Python) -> PyResult { - self.0.names.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_level(&self, py: Python) -> PyResult { - self.0.level.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Global", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtGlobal(pub &'static ast::StmtGlobal); - -impl From<&'static ast::StmtGlobal> for StmtGlobal { - fn from(node: &'static ast::StmtGlobal) -> Self { - StmtGlobal(node) - } -} - -impl ToPyObject for StmtGlobal { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtGlobal { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtGlobal(self).to_object(py)) - } -} - -#[pymethods] -impl StmtGlobal { - #[getter] - #[inline] - fn get_names(&self, py: Python) -> PyResult { - self.0.names.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Nonlocal", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtNonlocal(pub &'static ast::StmtNonlocal); - -impl From<&'static ast::StmtNonlocal> for StmtNonlocal { - fn from(node: &'static ast::StmtNonlocal) -> Self { - StmtNonlocal(node) - } -} - -impl ToPyObject for StmtNonlocal { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtNonlocal { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtNonlocal(self).to_object(py)) - } -} - -#[pymethods] -impl StmtNonlocal { - #[getter] - #[inline] - fn get_names(&self, py: Python) -> PyResult { - self.0.names.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Expr", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtExpr(pub &'static ast::StmtExpr); - -impl From<&'static ast::StmtExpr> for StmtExpr { - fn from(node: &'static ast::StmtExpr) -> Self { - StmtExpr(node) - } -} - -impl ToPyObject for StmtExpr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtExpr { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtExpr(self).to_object(py)) - } -} - -#[pymethods] -impl StmtExpr { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Pass", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtPass(pub &'static ast::StmtPass); - -impl From<&'static ast::StmtPass> for StmtPass { - fn from(node: &'static ast::StmtPass) -> Self { - StmtPass(node) - } -} - -impl ToPyObject for StmtPass { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtPass { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtPass(self).to_object(py)) - } -} - -#[pymethods] -impl StmtPass {} - -#[pyclass(module="rustpython_ast.located", name="_Break", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtBreak(pub &'static ast::StmtBreak); - -impl From<&'static ast::StmtBreak> for StmtBreak { - fn from(node: &'static ast::StmtBreak) -> Self { - StmtBreak(node) - } -} - -impl ToPyObject for StmtBreak { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtBreak { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtBreak(self).to_object(py)) - } -} - -#[pymethods] -impl StmtBreak {} - -#[pyclass(module="rustpython_ast.located", name="_Continue", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtContinue(pub &'static ast::StmtContinue); - -impl From<&'static ast::StmtContinue> for StmtContinue { - fn from(node: &'static ast::StmtContinue) -> Self { - StmtContinue(node) - } -} - -impl ToPyObject for StmtContinue { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtContinue { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtContinue(self).to_object(py)) - } -} - -#[pymethods] -impl StmtContinue {} - -#[pyclass(module="rustpython_ast.located", name="_expr", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct Expr; - -impl From<&'static ast::Expr> for Expr { - fn from(_node: &'static ast::Expr) -> Self { - Expr - } -} - -#[pymethods] -impl Expr { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for Expr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Expr { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::BoolOp(cons) => cons.to_py_wrapper(py), - Self::NamedExpr(cons) => cons.to_py_wrapper(py), - Self::BinOp(cons) => cons.to_py_wrapper(py), - Self::UnaryOp(cons) => cons.to_py_wrapper(py), - Self::Lambda(cons) => cons.to_py_wrapper(py), - Self::IfExp(cons) => cons.to_py_wrapper(py), - Self::Dict(cons) => cons.to_py_wrapper(py), - Self::Set(cons) => cons.to_py_wrapper(py), - Self::ListComp(cons) => cons.to_py_wrapper(py), - Self::SetComp(cons) => cons.to_py_wrapper(py), - Self::DictComp(cons) => cons.to_py_wrapper(py), - Self::GeneratorExp(cons) => cons.to_py_wrapper(py), - Self::Await(cons) => cons.to_py_wrapper(py), - Self::Yield(cons) => cons.to_py_wrapper(py), - Self::YieldFrom(cons) => cons.to_py_wrapper(py), - Self::Compare(cons) => cons.to_py_wrapper(py), - Self::Call(cons) => cons.to_py_wrapper(py), - Self::FormattedValue(cons) => cons.to_py_wrapper(py), - Self::JoinedStr(cons) => cons.to_py_wrapper(py), - Self::Constant(cons) => cons.to_py_wrapper(py), - Self::Attribute(cons) => cons.to_py_wrapper(py), - Self::Subscript(cons) => cons.to_py_wrapper(py), - Self::Starred(cons) => cons.to_py_wrapper(py), - Self::Name(cons) => cons.to_py_wrapper(py), - Self::List(cons) => cons.to_py_wrapper(py), - Self::Tuple(cons) => cons.to_py_wrapper(py), - Self::Slice(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.located", name="_BoolOp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprBoolOp(pub &'static ast::ExprBoolOp); - -impl From<&'static ast::ExprBoolOp> for ExprBoolOp { - fn from(node: &'static ast::ExprBoolOp) -> Self { - ExprBoolOp(node) - } -} - -impl ToPyObject for ExprBoolOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprBoolOp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprBoolOp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprBoolOp { - #[getter] - #[inline] - fn get_op(&self, py: Python) -> PyResult { - self.0.op.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_values(&self, py: Python) -> PyResult { - self.0.values.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_NamedExpr", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprNamedExpr(pub &'static ast::ExprNamedExpr); - -impl From<&'static ast::ExprNamedExpr> for ExprNamedExpr { - fn from(node: &'static ast::ExprNamedExpr) -> Self { - ExprNamedExpr(node) - } -} - -impl ToPyObject for ExprNamedExpr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprNamedExpr { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprNamedExpr(self).to_object(py)) - } -} - -#[pymethods] -impl ExprNamedExpr { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_BinOp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprBinOp(pub &'static ast::ExprBinOp); - -impl From<&'static ast::ExprBinOp> for ExprBinOp { - fn from(node: &'static ast::ExprBinOp) -> Self { - ExprBinOp(node) - } -} - -impl ToPyObject for ExprBinOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprBinOp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprBinOp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprBinOp { - #[getter] - #[inline] - fn get_left(&self, py: Python) -> PyResult { - self.0.left.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_op(&self, py: Python) -> PyResult { - self.0.op.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_right(&self, py: Python) -> PyResult { - self.0.right.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_UnaryOp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprUnaryOp(pub &'static ast::ExprUnaryOp); - -impl From<&'static ast::ExprUnaryOp> for ExprUnaryOp { - fn from(node: &'static ast::ExprUnaryOp) -> Self { - ExprUnaryOp(node) - } -} - -impl ToPyObject for ExprUnaryOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprUnaryOp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprUnaryOp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprUnaryOp { - #[getter] - #[inline] - fn get_op(&self, py: Python) -> PyResult { - self.0.op.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_operand(&self, py: Python) -> PyResult { - self.0.operand.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Lambda", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprLambda(pub &'static ast::ExprLambda); - -impl From<&'static ast::ExprLambda> for ExprLambda { - fn from(node: &'static ast::ExprLambda) -> Self { - ExprLambda(node) - } -} - -impl ToPyObject for ExprLambda { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprLambda { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprLambda(self).to_object(py)) - } -} - -#[pymethods] -impl ExprLambda { - #[getter] - #[inline] - fn get_args(&self, py: Python) -> PyResult { - self.0.args.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_IfExp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprIfExp(pub &'static ast::ExprIfExp); - -impl From<&'static ast::ExprIfExp> for ExprIfExp { - fn from(node: &'static ast::ExprIfExp) -> Self { - ExprIfExp(node) - } -} - -impl ToPyObject for ExprIfExp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprIfExp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprIfExp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprIfExp { - #[getter] - #[inline] - fn get_test(&self, py: Python) -> PyResult { - self.0.test.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Dict", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprDict(pub &'static ast::ExprDict); - -impl From<&'static ast::ExprDict> for ExprDict { - fn from(node: &'static ast::ExprDict) -> Self { - ExprDict(node) - } -} - -impl ToPyObject for ExprDict { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprDict { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprDict(self).to_object(py)) - } -} - -#[pymethods] -impl ExprDict { - #[getter] - #[inline] - fn get_keys(&self, py: Python) -> PyResult { - self.0.keys.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_values(&self, py: Python) -> PyResult { - self.0.values.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Set", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprSet(pub &'static ast::ExprSet); - -impl From<&'static ast::ExprSet> for ExprSet { - fn from(node: &'static ast::ExprSet) -> Self { - ExprSet(node) - } -} - -impl ToPyObject for ExprSet { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprSet { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprSet(self).to_object(py)) - } -} - -#[pymethods] -impl ExprSet { - #[getter] - #[inline] - fn get_elts(&self, py: Python) -> PyResult { - self.0.elts.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_ListComp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprListComp(pub &'static ast::ExprListComp); - -impl From<&'static ast::ExprListComp> for ExprListComp { - fn from(node: &'static ast::ExprListComp) -> Self { - ExprListComp(node) - } -} - -impl ToPyObject for ExprListComp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprListComp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprListComp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprListComp { - #[getter] - #[inline] - fn get_elt(&self, py: Python) -> PyResult { - self.0.elt.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_generators(&self, py: Python) -> PyResult { - self.0.generators.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_SetComp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprSetComp(pub &'static ast::ExprSetComp); - -impl From<&'static ast::ExprSetComp> for ExprSetComp { - fn from(node: &'static ast::ExprSetComp) -> Self { - ExprSetComp(node) - } -} - -impl ToPyObject for ExprSetComp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprSetComp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprSetComp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprSetComp { - #[getter] - #[inline] - fn get_elt(&self, py: Python) -> PyResult { - self.0.elt.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_generators(&self, py: Python) -> PyResult { - self.0.generators.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_DictComp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprDictComp(pub &'static ast::ExprDictComp); - -impl From<&'static ast::ExprDictComp> for ExprDictComp { - fn from(node: &'static ast::ExprDictComp) -> Self { - ExprDictComp(node) - } -} - -impl ToPyObject for ExprDictComp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprDictComp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprDictComp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprDictComp { - #[getter] - #[inline] - fn get_key(&self, py: Python) -> PyResult { - self.0.key.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_generators(&self, py: Python) -> PyResult { - self.0.generators.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_GeneratorExp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprGeneratorExp(pub &'static ast::ExprGeneratorExp); - -impl From<&'static ast::ExprGeneratorExp> for ExprGeneratorExp { - fn from(node: &'static ast::ExprGeneratorExp) -> Self { - ExprGeneratorExp(node) - } -} - -impl ToPyObject for ExprGeneratorExp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprGeneratorExp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprGeneratorExp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprGeneratorExp { - #[getter] - #[inline] - fn get_elt(&self, py: Python) -> PyResult { - self.0.elt.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_generators(&self, py: Python) -> PyResult { - self.0.generators.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Await", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprAwait(pub &'static ast::ExprAwait); - -impl From<&'static ast::ExprAwait> for ExprAwait { - fn from(node: &'static ast::ExprAwait) -> Self { - ExprAwait(node) - } -} - -impl ToPyObject for ExprAwait { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprAwait { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprAwait(self).to_object(py)) - } -} - -#[pymethods] -impl ExprAwait { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Yield", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprYield(pub &'static ast::ExprYield); - -impl From<&'static ast::ExprYield> for ExprYield { - fn from(node: &'static ast::ExprYield) -> Self { - ExprYield(node) - } -} - -impl ToPyObject for ExprYield { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprYield { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprYield(self).to_object(py)) - } -} - -#[pymethods] -impl ExprYield { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_YieldFrom", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprYieldFrom(pub &'static ast::ExprYieldFrom); - -impl From<&'static ast::ExprYieldFrom> for ExprYieldFrom { - fn from(node: &'static ast::ExprYieldFrom) -> Self { - ExprYieldFrom(node) - } -} - -impl ToPyObject for ExprYieldFrom { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprYieldFrom { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprYieldFrom(self).to_object(py)) - } -} - -#[pymethods] -impl ExprYieldFrom { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Compare", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprCompare(pub &'static ast::ExprCompare); - -impl From<&'static ast::ExprCompare> for ExprCompare { - fn from(node: &'static ast::ExprCompare) -> Self { - ExprCompare(node) - } -} - -impl ToPyObject for ExprCompare { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprCompare { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprCompare(self).to_object(py)) - } -} - -#[pymethods] -impl ExprCompare { - #[getter] - #[inline] - fn get_left(&self, py: Python) -> PyResult { - self.0.left.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ops(&self, py: Python) -> PyResult { - self.0.ops.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_comparators(&self, py: Python) -> PyResult { - self.0.comparators.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Call", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprCall(pub &'static ast::ExprCall); - -impl From<&'static ast::ExprCall> for ExprCall { - fn from(node: &'static ast::ExprCall) -> Self { - ExprCall(node) - } -} - -impl ToPyObject for ExprCall { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprCall { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprCall(self).to_object(py)) - } -} - -#[pymethods] -impl ExprCall { - #[getter] - #[inline] - fn get_func(&self, py: Python) -> PyResult { - self.0.func.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_args(&self, py: Python) -> PyResult { - self.0.args.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_keywords(&self, py: Python) -> PyResult { - self.0.keywords.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_FormattedValue", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprFormattedValue(pub &'static ast::ExprFormattedValue); - -impl From<&'static ast::ExprFormattedValue> for ExprFormattedValue { - fn from(node: &'static ast::ExprFormattedValue) -> Self { - ExprFormattedValue(node) - } -} - -impl ToPyObject for ExprFormattedValue { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprFormattedValue { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprFormattedValue(self).to_object(py)) - } -} - -#[pymethods] -impl ExprFormattedValue { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_conversion(&self, py: Python) -> PyResult { - self.0.conversion.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_format_spec(&self, py: Python) -> PyResult { - self.0.format_spec.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_JoinedStr", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprJoinedStr(pub &'static ast::ExprJoinedStr); - -impl From<&'static ast::ExprJoinedStr> for ExprJoinedStr { - fn from(node: &'static ast::ExprJoinedStr) -> Self { - ExprJoinedStr(node) - } -} - -impl ToPyObject for ExprJoinedStr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprJoinedStr { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprJoinedStr(self).to_object(py)) - } -} - -#[pymethods] -impl ExprJoinedStr { - #[getter] - #[inline] - fn get_values(&self, py: Python) -> PyResult { - self.0.values.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Constant", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprConstant(pub &'static ast::ExprConstant); - -impl From<&'static ast::ExprConstant> for ExprConstant { - fn from(node: &'static ast::ExprConstant) -> Self { - ExprConstant(node) - } -} - -impl ToPyObject for ExprConstant { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprConstant { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprConstant(self).to_object(py)) - } -} - -#[pymethods] -impl ExprConstant { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kind(&self, py: Python) -> PyResult { - self.0.kind.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Attribute", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprAttribute(pub &'static ast::ExprAttribute); - -impl From<&'static ast::ExprAttribute> for ExprAttribute { - fn from(node: &'static ast::ExprAttribute) -> Self { - ExprAttribute(node) - } -} - -impl ToPyObject for ExprAttribute { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprAttribute { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprAttribute(self).to_object(py)) - } -} - -#[pymethods] -impl ExprAttribute { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_attr(&self, py: Python) -> PyResult { - self.0.attr.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Subscript", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprSubscript(pub &'static ast::ExprSubscript); - -impl From<&'static ast::ExprSubscript> for ExprSubscript { - fn from(node: &'static ast::ExprSubscript) -> Self { - ExprSubscript(node) - } -} - -impl ToPyObject for ExprSubscript { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprSubscript { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprSubscript(self).to_object(py)) - } -} - -#[pymethods] -impl ExprSubscript { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_slice(&self, py: Python) -> PyResult { - self.0.slice.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Starred", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprStarred(pub &'static ast::ExprStarred); - -impl From<&'static ast::ExprStarred> for ExprStarred { - fn from(node: &'static ast::ExprStarred) -> Self { - ExprStarred(node) - } -} - -impl ToPyObject for ExprStarred { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprStarred { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprStarred(self).to_object(py)) - } -} - -#[pymethods] -impl ExprStarred { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Name", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprName(pub &'static ast::ExprName); - -impl From<&'static ast::ExprName> for ExprName { - fn from(node: &'static ast::ExprName) -> Self { - ExprName(node) - } -} - -impl ToPyObject for ExprName { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprName { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprName(self).to_object(py)) - } -} - -#[pymethods] -impl ExprName { - #[getter] - #[inline] - fn get_id(&self, py: Python) -> PyResult { - self.0.id.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_List", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprList(pub &'static ast::ExprList); - -impl From<&'static ast::ExprList> for ExprList { - fn from(node: &'static ast::ExprList) -> Self { - ExprList(node) - } -} - -impl ToPyObject for ExprList { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprList { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprList(self).to_object(py)) - } -} - -#[pymethods] -impl ExprList { - #[getter] - #[inline] - fn get_elts(&self, py: Python) -> PyResult { - self.0.elts.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Tuple", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprTuple(pub &'static ast::ExprTuple); - -impl From<&'static ast::ExprTuple> for ExprTuple { - fn from(node: &'static ast::ExprTuple) -> Self { - ExprTuple(node) - } -} - -impl ToPyObject for ExprTuple { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprTuple { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprTuple(self).to_object(py)) - } -} - -#[pymethods] -impl ExprTuple { - #[getter] - #[inline] - fn get_elts(&self, py: Python) -> PyResult { - self.0.elts.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Slice", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprSlice(pub &'static ast::ExprSlice); - -impl From<&'static ast::ExprSlice> for ExprSlice { - fn from(node: &'static ast::ExprSlice) -> Self { - ExprSlice(node) - } -} - -impl ToPyObject for ExprSlice { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprSlice { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprSlice(self).to_object(py)) - } -} - -#[pymethods] -impl ExprSlice { - #[getter] - #[inline] - fn get_lower(&self, py: Python) -> PyResult { - self.0.lower.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_upper(&self, py: Python) -> PyResult { - self.0.upper.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_step(&self, py: Python) -> PyResult { - self.0.step.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_expr_context", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct ExprContext; - -impl From<&'static ast::ExprContext> for ExprContext { - fn from(_node: &'static ast::ExprContext) -> Self { - ExprContext - } -} - -#[pymethods] -impl ExprContext { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for ExprContext { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Load", extends=ExprContext)] -pub struct ExprContextLoad; - -impl ToPyObject for ExprContextLoad { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(ExprContext) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Store", extends=ExprContext)] -pub struct ExprContextStore; - -impl ToPyObject for ExprContextStore { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(ExprContext) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Del", extends=ExprContext)] -pub struct ExprContextDel; - -impl ToPyObject for ExprContextDel { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(ExprContext) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_boolop", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct BoolOp; - -impl From<&'static ast::BoolOp> for BoolOp { - fn from(_node: &'static ast::BoolOp) -> Self { - BoolOp - } -} - -#[pymethods] -impl BoolOp { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for BoolOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_And", extends=BoolOp)] -pub struct BoolOpAnd; - -impl ToPyObject for BoolOpAnd { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(BoolOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Or", extends=BoolOp)] -pub struct BoolOpOr; - -impl ToPyObject for BoolOpOr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(BoolOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_operator", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct Operator; - -impl From<&'static ast::Operator> for Operator { - fn from(_node: &'static ast::Operator) -> Self { - Operator - } -} - -#[pymethods] -impl Operator { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for Operator { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Add", extends=Operator)] -pub struct OperatorAdd; - -impl ToPyObject for OperatorAdd { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Sub", extends=Operator)] -pub struct OperatorSub; - -impl ToPyObject for OperatorSub { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Mult", extends=Operator)] -pub struct OperatorMult; - -impl ToPyObject for OperatorMult { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_MatMult", extends=Operator)] -pub struct OperatorMatMult; - -impl ToPyObject for OperatorMatMult { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Div", extends=Operator)] -pub struct OperatorDiv; - -impl ToPyObject for OperatorDiv { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Mod", extends=Operator)] -pub struct OperatorMod; - -impl ToPyObject for OperatorMod { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Pow", extends=Operator)] -pub struct OperatorPow; - -impl ToPyObject for OperatorPow { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_LShift", extends=Operator)] -pub struct OperatorLShift; - -impl ToPyObject for OperatorLShift { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_RShift", extends=Operator)] -pub struct OperatorRShift; - -impl ToPyObject for OperatorRShift { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_BitOr", extends=Operator)] -pub struct OperatorBitOr; - -impl ToPyObject for OperatorBitOr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_BitXor", extends=Operator)] -pub struct OperatorBitXor; - -impl ToPyObject for OperatorBitXor { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_BitAnd", extends=Operator)] -pub struct OperatorBitAnd; - -impl ToPyObject for OperatorBitAnd { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_FloorDiv", extends=Operator)] -pub struct OperatorFloorDiv; - -impl ToPyObject for OperatorFloorDiv { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_unaryop", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct UnaryOp; - -impl From<&'static ast::UnaryOp> for UnaryOp { - fn from(_node: &'static ast::UnaryOp) -> Self { - UnaryOp - } -} - -#[pymethods] -impl UnaryOp { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for UnaryOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Invert", extends=UnaryOp)] -pub struct UnaryOpInvert; - -impl ToPyObject for UnaryOpInvert { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(UnaryOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Not", extends=UnaryOp)] -pub struct UnaryOpNot; - -impl ToPyObject for UnaryOpNot { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(UnaryOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_UAdd", extends=UnaryOp)] -pub struct UnaryOpUAdd; - -impl ToPyObject for UnaryOpUAdd { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(UnaryOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_USub", extends=UnaryOp)] -pub struct UnaryOpUSub; - -impl ToPyObject for UnaryOpUSub { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(UnaryOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_cmpop", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct CmpOp; - -impl From<&'static ast::CmpOp> for CmpOp { - fn from(_node: &'static ast::CmpOp) -> Self { - CmpOp - } -} - -#[pymethods] -impl CmpOp { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for CmpOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Eq", extends=CmpOp)] -pub struct CmpOpEq; - -impl ToPyObject for CmpOpEq { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_NotEq", extends=CmpOp)] -pub struct CmpOpNotEq; - -impl ToPyObject for CmpOpNotEq { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Lt", extends=CmpOp)] -pub struct CmpOpLt; - -impl ToPyObject for CmpOpLt { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_LtE", extends=CmpOp)] -pub struct CmpOpLtE; - -impl ToPyObject for CmpOpLtE { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Gt", extends=CmpOp)] -pub struct CmpOpGt; - -impl ToPyObject for CmpOpGt { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_GtE", extends=CmpOp)] -pub struct CmpOpGtE; - -impl ToPyObject for CmpOpGtE { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_Is", extends=CmpOp)] -pub struct CmpOpIs; - -impl ToPyObject for CmpOpIs { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_IsNot", extends=CmpOp)] -pub struct CmpOpIsNot; - -impl ToPyObject for CmpOpIsNot { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_In", extends=CmpOp)] -pub struct CmpOpIn; - -impl ToPyObject for CmpOpIn { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_NotIn", extends=CmpOp)] -pub struct CmpOpNotIn; - -impl ToPyObject for CmpOpNotIn { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_comprehension", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Comprehension(pub &'static ast::Comprehension); - -impl From<&'static ast::Comprehension> for Comprehension { - fn from(node: &'static ast::Comprehension) -> Self { - Comprehension(node) - } -} - -impl ToPyObject for Comprehension { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Comprehension { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Comprehension(self).to_object(py)) - } -} - -#[pymethods] -impl Comprehension { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_iter(&self, py: Python) -> PyResult { - self.0.iter.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ifs(&self, py: Python) -> PyResult { - self.0.ifs.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_is_async(&self, py: Python) -> PyResult { - self.0.is_async.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_excepthandler", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct ExceptHandler; - -impl From<&'static ast::ExceptHandler> for ExceptHandler { - fn from(_node: &'static ast::ExceptHandler) -> Self { - ExceptHandler - } -} - -#[pymethods] -impl ExceptHandler { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for ExceptHandler { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExceptHandler { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::ExceptHandler(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.located", name="_ExceptHandler", extends=ExceptHandler, frozen)] -#[derive(Clone, Debug)] -pub struct ExceptHandlerExceptHandler(pub &'static ast::ExceptHandlerExceptHandler); - -impl From<&'static ast::ExceptHandlerExceptHandler> for ExceptHandlerExceptHandler { - fn from(node: &'static ast::ExceptHandlerExceptHandler) -> Self { - ExceptHandlerExceptHandler(node) - } -} - -impl ToPyObject for ExceptHandlerExceptHandler { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(ExceptHandler) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExceptHandlerExceptHandler { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExceptHandlerExceptHandler(self).to_object(py)) - } -} - -#[pymethods] -impl ExceptHandlerExceptHandler { - #[getter] - #[inline] - fn get_type(&self, py: Python) -> PyResult { - self.0.type_.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_arguments", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Arguments(pub &'static ast::PythonArguments); - -impl From<&'static ast::PythonArguments> for Arguments { - fn from(node: &'static ast::PythonArguments) -> Self { - Arguments(node) - } -} - -impl ToPyObject for Arguments { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PythonArguments { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Arguments(self).to_object(py)) - } -} - -#[pymethods] -impl Arguments { - #[getter] - #[inline] - fn get_posonlyargs(&self, py: Python) -> PyResult { - self.0.posonlyargs.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_args(&self, py: Python) -> PyResult { - self.0.args.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_vararg(&self, py: Python) -> PyResult { - self.0.vararg.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kwonlyargs(&self, py: Python) -> PyResult { - self.0.kwonlyargs.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kw_defaults(&self, py: Python) -> PyResult { - self.0.kw_defaults.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kwarg(&self, py: Python) -> PyResult { - self.0.kwarg.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_defaults(&self, py: Python) -> PyResult { - self.0.defaults.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_arg", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Arg(pub &'static ast::Arg); - -impl From<&'static ast::Arg> for Arg { - fn from(node: &'static ast::Arg) -> Self { - Arg(node) - } -} - -impl ToPyObject for Arg { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Arg { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Arg(self).to_object(py)) - } -} - -#[pymethods] -impl Arg { - #[getter] - #[inline] - fn get_arg(&self, py: Python) -> PyResult { - self.0.arg.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_annotation(&self, py: Python) -> PyResult { - self.0.annotation.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_keyword", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Keyword(pub &'static ast::Keyword); - -impl From<&'static ast::Keyword> for Keyword { - fn from(node: &'static ast::Keyword) -> Self { - Keyword(node) - } -} - -impl ToPyObject for Keyword { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Keyword { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Keyword(self).to_object(py)) - } -} - -#[pymethods] -impl Keyword { - #[getter] - #[inline] - fn get_arg(&self, py: Python) -> PyResult { - self.0.arg.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_alias", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Alias(pub &'static ast::Alias); - -impl From<&'static ast::Alias> for Alias { - fn from(node: &'static ast::Alias) -> Self { - Alias(node) - } -} - -impl ToPyObject for Alias { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Alias { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Alias(self).to_object(py)) - } -} - -#[pymethods] -impl Alias { - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_asname(&self, py: Python) -> PyResult { - self.0.asname.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_withitem", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct WithItem(pub &'static ast::WithItem); - -impl From<&'static ast::WithItem> for WithItem { - fn from(node: &'static ast::WithItem) -> Self { - WithItem(node) - } -} - -impl ToPyObject for WithItem { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::WithItem { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(WithItem(self).to_object(py)) - } -} - -#[pymethods] -impl WithItem { - #[getter] - #[inline] - fn get_context_expr(&self, py: Python) -> PyResult { - self.0.context_expr.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_optional_vars(&self, py: Python) -> PyResult { - self.0.optional_vars.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_match_case", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct MatchCase(pub &'static ast::MatchCase); - -impl From<&'static ast::MatchCase> for MatchCase { - fn from(node: &'static ast::MatchCase) -> Self { - MatchCase(node) - } -} - -impl ToPyObject for MatchCase { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::MatchCase { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(MatchCase(self).to_object(py)) - } -} - -#[pymethods] -impl MatchCase { - #[getter] - #[inline] - fn get_pattern(&self, py: Python) -> PyResult { - self.0.pattern.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_guard(&self, py: Python) -> PyResult { - self.0.guard.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_pattern", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct Pattern; - -impl From<&'static ast::Pattern> for Pattern { - fn from(_node: &'static ast::Pattern) -> Self { - Pattern - } -} - -#[pymethods] -impl Pattern { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for Pattern { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Pattern { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::MatchValue(cons) => cons.to_py_wrapper(py), - Self::MatchSingleton(cons) => cons.to_py_wrapper(py), - Self::MatchSequence(cons) => cons.to_py_wrapper(py), - Self::MatchMapping(cons) => cons.to_py_wrapper(py), - Self::MatchClass(cons) => cons.to_py_wrapper(py), - Self::MatchStar(cons) => cons.to_py_wrapper(py), - Self::MatchAs(cons) => cons.to_py_wrapper(py), - Self::MatchOr(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.located", name="_MatchValue", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchValue(pub &'static ast::PatternMatchValue); - -impl From<&'static ast::PatternMatchValue> for PatternMatchValue { - fn from(node: &'static ast::PatternMatchValue) -> Self { - PatternMatchValue(node) - } -} - -impl ToPyObject for PatternMatchValue { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchValue { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchValue(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchValue { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_MatchSingleton", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchSingleton(pub &'static ast::PatternMatchSingleton); - -impl From<&'static ast::PatternMatchSingleton> for PatternMatchSingleton { - fn from(node: &'static ast::PatternMatchSingleton) -> Self { - PatternMatchSingleton(node) - } -} - -impl ToPyObject for PatternMatchSingleton { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchSingleton { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchSingleton(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchSingleton { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_MatchSequence", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchSequence(pub &'static ast::PatternMatchSequence); - -impl From<&'static ast::PatternMatchSequence> for PatternMatchSequence { - fn from(node: &'static ast::PatternMatchSequence) -> Self { - PatternMatchSequence(node) - } -} - -impl ToPyObject for PatternMatchSequence { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchSequence { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchSequence(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchSequence { - #[getter] - #[inline] - fn get_patterns(&self, py: Python) -> PyResult { - self.0.patterns.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_MatchMapping", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchMapping(pub &'static ast::PatternMatchMapping); - -impl From<&'static ast::PatternMatchMapping> for PatternMatchMapping { - fn from(node: &'static ast::PatternMatchMapping) -> Self { - PatternMatchMapping(node) - } -} - -impl ToPyObject for PatternMatchMapping { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchMapping { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchMapping(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchMapping { - #[getter] - #[inline] - fn get_keys(&self, py: Python) -> PyResult { - self.0.keys.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_patterns(&self, py: Python) -> PyResult { - self.0.patterns.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_rest(&self, py: Python) -> PyResult { - self.0.rest.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_MatchClass", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchClass(pub &'static ast::PatternMatchClass); - -impl From<&'static ast::PatternMatchClass> for PatternMatchClass { - fn from(node: &'static ast::PatternMatchClass) -> Self { - PatternMatchClass(node) - } -} - -impl ToPyObject for PatternMatchClass { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchClass { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchClass(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchClass { - #[getter] - #[inline] - fn get_cls(&self, py: Python) -> PyResult { - self.0.cls.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_patterns(&self, py: Python) -> PyResult { - self.0.patterns.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kwd_attrs(&self, py: Python) -> PyResult { - self.0.kwd_attrs.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kwd_patterns(&self, py: Python) -> PyResult { - self.0.kwd_patterns.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_MatchStar", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchStar(pub &'static ast::PatternMatchStar); - -impl From<&'static ast::PatternMatchStar> for PatternMatchStar { - fn from(node: &'static ast::PatternMatchStar) -> Self { - PatternMatchStar(node) - } -} - -impl ToPyObject for PatternMatchStar { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchStar { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchStar(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchStar { - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_MatchAs", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchAs(pub &'static ast::PatternMatchAs); - -impl From<&'static ast::PatternMatchAs> for PatternMatchAs { - fn from(node: &'static ast::PatternMatchAs) -> Self { - PatternMatchAs(node) - } -} - -impl ToPyObject for PatternMatchAs { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchAs { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchAs(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchAs { - #[getter] - #[inline] - fn get_pattern(&self, py: Python) -> PyResult { - self.0.pattern.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_MatchOr", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchOr(pub &'static ast::PatternMatchOr); - -impl From<&'static ast::PatternMatchOr> for PatternMatchOr { - fn from(node: &'static ast::PatternMatchOr) -> Self { - PatternMatchOr(node) - } -} - -impl ToPyObject for PatternMatchOr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchOr { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchOr(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchOr { - #[getter] - #[inline] - fn get_patterns(&self, py: Python) -> PyResult { - self.0.patterns.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_type_ignore", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct TypeIgnore; - -impl From<&'static ast::TypeIgnore> for TypeIgnore { - fn from(_node: &'static ast::TypeIgnore) -> Self { - TypeIgnore - } -} - -#[pymethods] -impl TypeIgnore { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for TypeIgnore { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::TypeIgnore { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::TypeIgnore(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.located", name="_TypeIgnore", extends=TypeIgnore, frozen)] -#[derive(Clone, Debug)] -pub struct TypeIgnoreTypeIgnore(pub &'static ast::TypeIgnoreTypeIgnore); - -impl From<&'static ast::TypeIgnoreTypeIgnore> for TypeIgnoreTypeIgnore { - fn from(node: &'static ast::TypeIgnoreTypeIgnore) -> Self { - TypeIgnoreTypeIgnore(node) - } -} - -impl ToPyObject for TypeIgnoreTypeIgnore { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(TypeIgnore) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::TypeIgnoreTypeIgnore { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(TypeIgnoreTypeIgnore(self).to_object(py)) - } -} - -#[pymethods] -impl TypeIgnoreTypeIgnore { - #[getter] - #[inline] - fn get_lineno(&self, py: Python) -> PyResult { - self.0.lineno.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_tag(&self, py: Python) -> PyResult { - self.0.tag.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.located", name="_decorator", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Decorator(pub &'static ast::Decorator); - -impl From<&'static ast::Decorator> for Decorator { - fn from(node: &'static ast::Decorator) -> Self { - Decorator(node) - } -} - -impl ToPyObject for Decorator { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Decorator { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Decorator(self).to_object(py)) - } -} - -#[pymethods] -impl Decorator { - #[getter] - #[inline] - fn get_expression(&self, py: Python) -> PyResult { - self.0.expression.to_py_wrapper(py) - } -} - -impl ToPyWrapper for ast::ExprContext { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - match &self { - Self::Load => Ok(ExprContextLoad.to_object(py)), - Self::Store => Ok(ExprContextStore.to_object(py)), - Self::Del => Ok(ExprContextDel.to_object(py)), - } - } -} - -impl ToPyWrapper for ast::ExprContextLoad { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(ExprContextLoad.to_object(py)) - } -} - -impl ToPyWrapper for ast::ExprContextStore { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(ExprContextStore.to_object(py)) - } -} - -impl ToPyWrapper for ast::ExprContextDel { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(ExprContextDel.to_object(py)) - } -} - -impl ToPyWrapper for ast::BoolOp { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - match &self { - Self::And => Ok(BoolOpAnd.to_object(py)), - Self::Or => Ok(BoolOpOr.to_object(py)), - } - } -} - -impl ToPyWrapper for ast::BoolOpAnd { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(BoolOpAnd.to_object(py)) - } -} - -impl ToPyWrapper for ast::BoolOpOr { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(BoolOpOr.to_object(py)) - } -} - -impl ToPyWrapper for ast::Operator { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - match &self { - Self::Add => Ok(OperatorAdd.to_object(py)), - Self::Sub => Ok(OperatorSub.to_object(py)), - Self::Mult => Ok(OperatorMult.to_object(py)), - Self::MatMult => Ok(OperatorMatMult.to_object(py)), - Self::Div => Ok(OperatorDiv.to_object(py)), - Self::Mod => Ok(OperatorMod.to_object(py)), - Self::Pow => Ok(OperatorPow.to_object(py)), - Self::LShift => Ok(OperatorLShift.to_object(py)), - Self::RShift => Ok(OperatorRShift.to_object(py)), - Self::BitOr => Ok(OperatorBitOr.to_object(py)), - Self::BitXor => Ok(OperatorBitXor.to_object(py)), - Self::BitAnd => Ok(OperatorBitAnd.to_object(py)), - Self::FloorDiv => Ok(OperatorFloorDiv.to_object(py)), - } - } -} - -impl ToPyWrapper for ast::OperatorAdd { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorAdd.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorSub { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorSub.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorMult { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorMult.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorMatMult { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorMatMult.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorDiv { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorDiv.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorMod { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorMod.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorPow { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorPow.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorLShift { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorLShift.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorRShift { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorRShift.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorBitOr { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorBitOr.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorBitXor { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorBitXor.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorBitAnd { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorBitAnd.to_object(py)) - } -} - -impl ToPyWrapper for ast::OperatorFloorDiv { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(OperatorFloorDiv.to_object(py)) - } -} - -impl ToPyWrapper for ast::UnaryOp { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - match &self { - Self::Invert => Ok(UnaryOpInvert.to_object(py)), - Self::Not => Ok(UnaryOpNot.to_object(py)), - Self::UAdd => Ok(UnaryOpUAdd.to_object(py)), - Self::USub => Ok(UnaryOpUSub.to_object(py)), - } - } -} - -impl ToPyWrapper for ast::UnaryOpInvert { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(UnaryOpInvert.to_object(py)) - } -} - -impl ToPyWrapper for ast::UnaryOpNot { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(UnaryOpNot.to_object(py)) - } -} - -impl ToPyWrapper for ast::UnaryOpUAdd { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(UnaryOpUAdd.to_object(py)) - } -} - -impl ToPyWrapper for ast::UnaryOpUSub { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(UnaryOpUSub.to_object(py)) - } -} - -impl ToPyWrapper for ast::CmpOp { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - match &self { - Self::Eq => Ok(CmpOpEq.to_object(py)), - Self::NotEq => Ok(CmpOpNotEq.to_object(py)), - Self::Lt => Ok(CmpOpLt.to_object(py)), - Self::LtE => Ok(CmpOpLtE.to_object(py)), - Self::Gt => Ok(CmpOpGt.to_object(py)), - Self::GtE => Ok(CmpOpGtE.to_object(py)), - Self::Is => Ok(CmpOpIs.to_object(py)), - Self::IsNot => Ok(CmpOpIsNot.to_object(py)), - Self::In => Ok(CmpOpIn.to_object(py)), - Self::NotIn => Ok(CmpOpNotIn.to_object(py)), - } - } -} - -impl ToPyWrapper for ast::CmpOpEq { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(CmpOpEq.to_object(py)) - } -} - -impl ToPyWrapper for ast::CmpOpNotEq { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(CmpOpNotEq.to_object(py)) - } -} - -impl ToPyWrapper for ast::CmpOpLt { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(CmpOpLt.to_object(py)) - } -} - -impl ToPyWrapper for ast::CmpOpLtE { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(CmpOpLtE.to_object(py)) - } -} - -impl ToPyWrapper for ast::CmpOpGt { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(CmpOpGt.to_object(py)) - } -} - -impl ToPyWrapper for ast::CmpOpGtE { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(CmpOpGtE.to_object(py)) - } -} - -impl ToPyWrapper for ast::CmpOpIs { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(CmpOpIs.to_object(py)) - } -} - -impl ToPyWrapper for ast::CmpOpIsNot { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(CmpOpIsNot.to_object(py)) - } -} - -impl ToPyWrapper for ast::CmpOpIn { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(CmpOpIn.to_object(py)) - } -} - -impl ToPyWrapper for ast::CmpOpNotIn { - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> { - Ok(CmpOpNotIn.to_object(py)) - } -} - -pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> { - super::init_module(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - Ok(()) -} diff --git a/ast-pyo3/src/gen/wrapper_ranged.rs b/ast-pyo3/src/gen/wrapper_ranged.rs deleted file mode 100644 index 4348d509cd1fd..0000000000000 --- a/ast-pyo3/src/gen/wrapper_ranged.rs +++ /dev/null @@ -1,4151 +0,0 @@ -// File automatically generated by ast/asdl_rs.py. - -#[pyclass(module="rustpython_ast.ranged", name="_mod", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct Mod; - -impl From<&'static ast::Mod> for Mod { - fn from(_node: &'static ast::Mod) -> Self { - Mod - } -} - -#[pymethods] -impl Mod { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for Mod { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Mod { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::Module(cons) => cons.to_py_wrapper(py), - Self::Interactive(cons) => cons.to_py_wrapper(py), - Self::Expression(cons) => cons.to_py_wrapper(py), - Self::FunctionType(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Module", extends=Mod, frozen)] -#[derive(Clone, Debug)] -pub struct ModModule(pub &'static ast::ModModule); - -impl From<&'static ast::ModModule> for ModModule { - fn from(node: &'static ast::ModModule) -> Self { - ModModule(node) - } -} - -impl ToPyObject for ModModule { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Mod) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ModModule { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ModModule(self).to_object(py)) - } -} - -#[pymethods] -impl ModModule { - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_ignores(&self, py: Python) -> PyResult { - self.0.type_ignores.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Interactive", extends=Mod, frozen)] -#[derive(Clone, Debug)] -pub struct ModInteractive(pub &'static ast::ModInteractive); - -impl From<&'static ast::ModInteractive> for ModInteractive { - fn from(node: &'static ast::ModInteractive) -> Self { - ModInteractive(node) - } -} - -impl ToPyObject for ModInteractive { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Mod) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ModInteractive { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ModInteractive(self).to_object(py)) - } -} - -#[pymethods] -impl ModInteractive { - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Expression", extends=Mod, frozen)] -#[derive(Clone, Debug)] -pub struct ModExpression(pub &'static ast::ModExpression); - -impl From<&'static ast::ModExpression> for ModExpression { - fn from(node: &'static ast::ModExpression) -> Self { - ModExpression(node) - } -} - -impl ToPyObject for ModExpression { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Mod) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ModExpression { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ModExpression(self).to_object(py)) - } -} - -#[pymethods] -impl ModExpression { - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_FunctionType", extends=Mod, frozen)] -#[derive(Clone, Debug)] -pub struct ModFunctionType(pub &'static ast::ModFunctionType); - -impl From<&'static ast::ModFunctionType> for ModFunctionType { - fn from(node: &'static ast::ModFunctionType) -> Self { - ModFunctionType(node) - } -} - -impl ToPyObject for ModFunctionType { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Mod) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ModFunctionType { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ModFunctionType(self).to_object(py)) - } -} - -#[pymethods] -impl ModFunctionType { - #[getter] - #[inline] - fn get_argtypes(&self, py: Python) -> PyResult { - self.0.argtypes.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_returns(&self, py: Python) -> PyResult { - self.0.returns.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_stmt", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct Stmt; - -impl From<&'static ast::Stmt> for Stmt { - fn from(_node: &'static ast::Stmt) -> Self { - Stmt - } -} - -#[pymethods] -impl Stmt { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for Stmt { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Stmt { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::FunctionDef(cons) => cons.to_py_wrapper(py), - Self::AsyncFunctionDef(cons) => cons.to_py_wrapper(py), - Self::ClassDef(cons) => cons.to_py_wrapper(py), - Self::Return(cons) => cons.to_py_wrapper(py), - Self::Delete(cons) => cons.to_py_wrapper(py), - Self::Assign(cons) => cons.to_py_wrapper(py), - Self::AugAssign(cons) => cons.to_py_wrapper(py), - Self::AnnAssign(cons) => cons.to_py_wrapper(py), - Self::For(cons) => cons.to_py_wrapper(py), - Self::AsyncFor(cons) => cons.to_py_wrapper(py), - Self::While(cons) => cons.to_py_wrapper(py), - Self::If(cons) => cons.to_py_wrapper(py), - Self::With(cons) => cons.to_py_wrapper(py), - Self::AsyncWith(cons) => cons.to_py_wrapper(py), - Self::Match(cons) => cons.to_py_wrapper(py), - Self::Raise(cons) => cons.to_py_wrapper(py), - Self::Try(cons) => cons.to_py_wrapper(py), - Self::TryStar(cons) => cons.to_py_wrapper(py), - Self::Assert(cons) => cons.to_py_wrapper(py), - Self::Import(cons) => cons.to_py_wrapper(py), - Self::ImportFrom(cons) => cons.to_py_wrapper(py), - Self::Global(cons) => cons.to_py_wrapper(py), - Self::Nonlocal(cons) => cons.to_py_wrapper(py), - Self::Expr(cons) => cons.to_py_wrapper(py), - Self::Pass(cons) => cons.to_py_wrapper(py), - Self::Break(cons) => cons.to_py_wrapper(py), - Self::Continue(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_FunctionDef", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtFunctionDef(pub &'static ast::StmtFunctionDef); - -impl From<&'static ast::StmtFunctionDef> for StmtFunctionDef { - fn from(node: &'static ast::StmtFunctionDef) -> Self { - StmtFunctionDef(node) - } -} - -impl ToPyObject for StmtFunctionDef { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtFunctionDef { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtFunctionDef(self).to_object(py)) - } -} - -#[pymethods] -impl StmtFunctionDef { - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_args(&self, py: Python) -> PyResult { - self.0.args.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_decorator_list(&self, py: Python) -> PyResult { - self.0.decorator_list.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_returns(&self, py: Python) -> PyResult { - self.0.returns.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_AsyncFunctionDef", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAsyncFunctionDef(pub &'static ast::StmtAsyncFunctionDef); - -impl From<&'static ast::StmtAsyncFunctionDef> for StmtAsyncFunctionDef { - fn from(node: &'static ast::StmtAsyncFunctionDef) -> Self { - StmtAsyncFunctionDef(node) - } -} - -impl ToPyObject for StmtAsyncFunctionDef { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAsyncFunctionDef { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAsyncFunctionDef(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAsyncFunctionDef { - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_args(&self, py: Python) -> PyResult { - self.0.args.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_decorator_list(&self, py: Python) -> PyResult { - self.0.decorator_list.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_returns(&self, py: Python) -> PyResult { - self.0.returns.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_ClassDef", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtClassDef(pub &'static ast::StmtClassDef); - -impl From<&'static ast::StmtClassDef> for StmtClassDef { - fn from(node: &'static ast::StmtClassDef) -> Self { - StmtClassDef(node) - } -} - -impl ToPyObject for StmtClassDef { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtClassDef { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtClassDef(self).to_object(py)) - } -} - -#[pymethods] -impl StmtClassDef { - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_bases(&self, py: Python) -> PyResult { - self.0.bases.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_keywords(&self, py: Python) -> PyResult { - self.0.keywords.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_decorator_list(&self, py: Python) -> PyResult { - self.0.decorator_list.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Return", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtReturn(pub &'static ast::StmtReturn); - -impl From<&'static ast::StmtReturn> for StmtReturn { - fn from(node: &'static ast::StmtReturn) -> Self { - StmtReturn(node) - } -} - -impl ToPyObject for StmtReturn { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtReturn { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtReturn(self).to_object(py)) - } -} - -#[pymethods] -impl StmtReturn { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Delete", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtDelete(pub &'static ast::StmtDelete); - -impl From<&'static ast::StmtDelete> for StmtDelete { - fn from(node: &'static ast::StmtDelete) -> Self { - StmtDelete(node) - } -} - -impl ToPyObject for StmtDelete { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtDelete { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtDelete(self).to_object(py)) - } -} - -#[pymethods] -impl StmtDelete { - #[getter] - #[inline] - fn get_targets(&self, py: Python) -> PyResult { - self.0.targets.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Assign", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAssign(pub &'static ast::StmtAssign); - -impl From<&'static ast::StmtAssign> for StmtAssign { - fn from(node: &'static ast::StmtAssign) -> Self { - StmtAssign(node) - } -} - -impl ToPyObject for StmtAssign { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAssign { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAssign(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAssign { - #[getter] - #[inline] - fn get_targets(&self, py: Python) -> PyResult { - self.0.targets.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_AugAssign", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAugAssign(pub &'static ast::StmtAugAssign); - -impl From<&'static ast::StmtAugAssign> for StmtAugAssign { - fn from(node: &'static ast::StmtAugAssign) -> Self { - StmtAugAssign(node) - } -} - -impl ToPyObject for StmtAugAssign { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAugAssign { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAugAssign(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAugAssign { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_op(&self, py: Python) -> PyResult { - self.0.op.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_AnnAssign", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAnnAssign(pub &'static ast::StmtAnnAssign); - -impl From<&'static ast::StmtAnnAssign> for StmtAnnAssign { - fn from(node: &'static ast::StmtAnnAssign) -> Self { - StmtAnnAssign(node) - } -} - -impl ToPyObject for StmtAnnAssign { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAnnAssign { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAnnAssign(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAnnAssign { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_annotation(&self, py: Python) -> PyResult { - self.0.annotation.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_simple(&self, py: Python) -> PyResult { - self.0.simple.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_For", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtFor(pub &'static ast::StmtFor); - -impl From<&'static ast::StmtFor> for StmtFor { - fn from(node: &'static ast::StmtFor) -> Self { - StmtFor(node) - } -} - -impl ToPyObject for StmtFor { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtFor { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtFor(self).to_object(py)) - } -} - -#[pymethods] -impl StmtFor { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_iter(&self, py: Python) -> PyResult { - self.0.iter.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_AsyncFor", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAsyncFor(pub &'static ast::StmtAsyncFor); - -impl From<&'static ast::StmtAsyncFor> for StmtAsyncFor { - fn from(node: &'static ast::StmtAsyncFor) -> Self { - StmtAsyncFor(node) - } -} - -impl ToPyObject for StmtAsyncFor { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAsyncFor { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAsyncFor(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAsyncFor { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_iter(&self, py: Python) -> PyResult { - self.0.iter.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_While", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtWhile(pub &'static ast::StmtWhile); - -impl From<&'static ast::StmtWhile> for StmtWhile { - fn from(node: &'static ast::StmtWhile) -> Self { - StmtWhile(node) - } -} - -impl ToPyObject for StmtWhile { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtWhile { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtWhile(self).to_object(py)) - } -} - -#[pymethods] -impl StmtWhile { - #[getter] - #[inline] - fn get_test(&self, py: Python) -> PyResult { - self.0.test.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_If", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtIf(pub &'static ast::StmtIf); - -impl From<&'static ast::StmtIf> for StmtIf { - fn from(node: &'static ast::StmtIf) -> Self { - StmtIf(node) - } -} - -impl ToPyObject for StmtIf { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtIf { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtIf(self).to_object(py)) - } -} - -#[pymethods] -impl StmtIf { - #[getter] - #[inline] - fn get_test(&self, py: Python) -> PyResult { - self.0.test.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_With", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtWith(pub &'static ast::StmtWith); - -impl From<&'static ast::StmtWith> for StmtWith { - fn from(node: &'static ast::StmtWith) -> Self { - StmtWith(node) - } -} - -impl ToPyObject for StmtWith { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtWith { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtWith(self).to_object(py)) - } -} - -#[pymethods] -impl StmtWith { - #[getter] - #[inline] - fn get_items(&self, py: Python) -> PyResult { - self.0.items.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_AsyncWith", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAsyncWith(pub &'static ast::StmtAsyncWith); - -impl From<&'static ast::StmtAsyncWith> for StmtAsyncWith { - fn from(node: &'static ast::StmtAsyncWith) -> Self { - StmtAsyncWith(node) - } -} - -impl ToPyObject for StmtAsyncWith { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAsyncWith { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAsyncWith(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAsyncWith { - #[getter] - #[inline] - fn get_items(&self, py: Python) -> PyResult { - self.0.items.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Match", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtMatch(pub &'static ast::StmtMatch); - -impl From<&'static ast::StmtMatch> for StmtMatch { - fn from(node: &'static ast::StmtMatch) -> Self { - StmtMatch(node) - } -} - -impl ToPyObject for StmtMatch { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtMatch { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtMatch(self).to_object(py)) - } -} - -#[pymethods] -impl StmtMatch { - #[getter] - #[inline] - fn get_subject(&self, py: Python) -> PyResult { - self.0.subject.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_cases(&self, py: Python) -> PyResult { - self.0.cases.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Raise", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtRaise(pub &'static ast::StmtRaise); - -impl From<&'static ast::StmtRaise> for StmtRaise { - fn from(node: &'static ast::StmtRaise) -> Self { - StmtRaise(node) - } -} - -impl ToPyObject for StmtRaise { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtRaise { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtRaise(self).to_object(py)) - } -} - -#[pymethods] -impl StmtRaise { - #[getter] - #[inline] - fn get_exc(&self, py: Python) -> PyResult { - self.0.exc.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_cause(&self, py: Python) -> PyResult { - self.0.cause.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Try", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtTry(pub &'static ast::StmtTry); - -impl From<&'static ast::StmtTry> for StmtTry { - fn from(node: &'static ast::StmtTry) -> Self { - StmtTry(node) - } -} - -impl ToPyObject for StmtTry { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtTry { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtTry(self).to_object(py)) - } -} - -#[pymethods] -impl StmtTry { - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_handlers(&self, py: Python) -> PyResult { - self.0.handlers.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_finalbody(&self, py: Python) -> PyResult { - self.0.finalbody.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_TryStar", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtTryStar(pub &'static ast::StmtTryStar); - -impl From<&'static ast::StmtTryStar> for StmtTryStar { - fn from(node: &'static ast::StmtTryStar) -> Self { - StmtTryStar(node) - } -} - -impl ToPyObject for StmtTryStar { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtTryStar { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtTryStar(self).to_object(py)) - } -} - -#[pymethods] -impl StmtTryStar { - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_handlers(&self, py: Python) -> PyResult { - self.0.handlers.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_finalbody(&self, py: Python) -> PyResult { - self.0.finalbody.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Assert", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtAssert(pub &'static ast::StmtAssert); - -impl From<&'static ast::StmtAssert> for StmtAssert { - fn from(node: &'static ast::StmtAssert) -> Self { - StmtAssert(node) - } -} - -impl ToPyObject for StmtAssert { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtAssert { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtAssert(self).to_object(py)) - } -} - -#[pymethods] -impl StmtAssert { - #[getter] - #[inline] - fn get_test(&self, py: Python) -> PyResult { - self.0.test.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_msg(&self, py: Python) -> PyResult { - self.0.msg.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Import", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtImport(pub &'static ast::StmtImport); - -impl From<&'static ast::StmtImport> for StmtImport { - fn from(node: &'static ast::StmtImport) -> Self { - StmtImport(node) - } -} - -impl ToPyObject for StmtImport { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtImport { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtImport(self).to_object(py)) - } -} - -#[pymethods] -impl StmtImport { - #[getter] - #[inline] - fn get_names(&self, py: Python) -> PyResult { - self.0.names.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_ImportFrom", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtImportFrom(pub &'static ast::StmtImportFrom); - -impl From<&'static ast::StmtImportFrom> for StmtImportFrom { - fn from(node: &'static ast::StmtImportFrom) -> Self { - StmtImportFrom(node) - } -} - -impl ToPyObject for StmtImportFrom { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtImportFrom { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtImportFrom(self).to_object(py)) - } -} - -#[pymethods] -impl StmtImportFrom { - #[getter] - #[inline] - fn get_module(&self, py: Python) -> PyResult { - self.0.module.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_names(&self, py: Python) -> PyResult { - self.0.names.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_level(&self, py: Python) -> PyResult { - self.0.level.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Global", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtGlobal(pub &'static ast::StmtGlobal); - -impl From<&'static ast::StmtGlobal> for StmtGlobal { - fn from(node: &'static ast::StmtGlobal) -> Self { - StmtGlobal(node) - } -} - -impl ToPyObject for StmtGlobal { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtGlobal { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtGlobal(self).to_object(py)) - } -} - -#[pymethods] -impl StmtGlobal { - #[getter] - #[inline] - fn get_names(&self, py: Python) -> PyResult { - self.0.names.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Nonlocal", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtNonlocal(pub &'static ast::StmtNonlocal); - -impl From<&'static ast::StmtNonlocal> for StmtNonlocal { - fn from(node: &'static ast::StmtNonlocal) -> Self { - StmtNonlocal(node) - } -} - -impl ToPyObject for StmtNonlocal { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtNonlocal { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtNonlocal(self).to_object(py)) - } -} - -#[pymethods] -impl StmtNonlocal { - #[getter] - #[inline] - fn get_names(&self, py: Python) -> PyResult { - self.0.names.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Expr", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtExpr(pub &'static ast::StmtExpr); - -impl From<&'static ast::StmtExpr> for StmtExpr { - fn from(node: &'static ast::StmtExpr) -> Self { - StmtExpr(node) - } -} - -impl ToPyObject for StmtExpr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtExpr { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtExpr(self).to_object(py)) - } -} - -#[pymethods] -impl StmtExpr { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Pass", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtPass(pub &'static ast::StmtPass); - -impl From<&'static ast::StmtPass> for StmtPass { - fn from(node: &'static ast::StmtPass) -> Self { - StmtPass(node) - } -} - -impl ToPyObject for StmtPass { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtPass { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtPass(self).to_object(py)) - } -} - -#[pymethods] -impl StmtPass {} - -#[pyclass(module="rustpython_ast.ranged", name="_Break", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtBreak(pub &'static ast::StmtBreak); - -impl From<&'static ast::StmtBreak> for StmtBreak { - fn from(node: &'static ast::StmtBreak) -> Self { - StmtBreak(node) - } -} - -impl ToPyObject for StmtBreak { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtBreak { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtBreak(self).to_object(py)) - } -} - -#[pymethods] -impl StmtBreak {} - -#[pyclass(module="rustpython_ast.ranged", name="_Continue", extends=Stmt, frozen)] -#[derive(Clone, Debug)] -pub struct StmtContinue(pub &'static ast::StmtContinue); - -impl From<&'static ast::StmtContinue> for StmtContinue { - fn from(node: &'static ast::StmtContinue) -> Self { - StmtContinue(node) - } -} - -impl ToPyObject for StmtContinue { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Stmt) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::StmtContinue { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(StmtContinue(self).to_object(py)) - } -} - -#[pymethods] -impl StmtContinue {} - -#[pyclass(module="rustpython_ast.ranged", name="_expr", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct Expr; - -impl From<&'static ast::Expr> for Expr { - fn from(_node: &'static ast::Expr) -> Self { - Expr - } -} - -#[pymethods] -impl Expr { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for Expr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Expr { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::BoolOp(cons) => cons.to_py_wrapper(py), - Self::NamedExpr(cons) => cons.to_py_wrapper(py), - Self::BinOp(cons) => cons.to_py_wrapper(py), - Self::UnaryOp(cons) => cons.to_py_wrapper(py), - Self::Lambda(cons) => cons.to_py_wrapper(py), - Self::IfExp(cons) => cons.to_py_wrapper(py), - Self::Dict(cons) => cons.to_py_wrapper(py), - Self::Set(cons) => cons.to_py_wrapper(py), - Self::ListComp(cons) => cons.to_py_wrapper(py), - Self::SetComp(cons) => cons.to_py_wrapper(py), - Self::DictComp(cons) => cons.to_py_wrapper(py), - Self::GeneratorExp(cons) => cons.to_py_wrapper(py), - Self::Await(cons) => cons.to_py_wrapper(py), - Self::Yield(cons) => cons.to_py_wrapper(py), - Self::YieldFrom(cons) => cons.to_py_wrapper(py), - Self::Compare(cons) => cons.to_py_wrapper(py), - Self::Call(cons) => cons.to_py_wrapper(py), - Self::FormattedValue(cons) => cons.to_py_wrapper(py), - Self::JoinedStr(cons) => cons.to_py_wrapper(py), - Self::Constant(cons) => cons.to_py_wrapper(py), - Self::Attribute(cons) => cons.to_py_wrapper(py), - Self::Subscript(cons) => cons.to_py_wrapper(py), - Self::Starred(cons) => cons.to_py_wrapper(py), - Self::Name(cons) => cons.to_py_wrapper(py), - Self::List(cons) => cons.to_py_wrapper(py), - Self::Tuple(cons) => cons.to_py_wrapper(py), - Self::Slice(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_BoolOp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprBoolOp(pub &'static ast::ExprBoolOp); - -impl From<&'static ast::ExprBoolOp> for ExprBoolOp { - fn from(node: &'static ast::ExprBoolOp) -> Self { - ExprBoolOp(node) - } -} - -impl ToPyObject for ExprBoolOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprBoolOp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprBoolOp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprBoolOp { - #[getter] - #[inline] - fn get_op(&self, py: Python) -> PyResult { - self.0.op.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_values(&self, py: Python) -> PyResult { - self.0.values.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_NamedExpr", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprNamedExpr(pub &'static ast::ExprNamedExpr); - -impl From<&'static ast::ExprNamedExpr> for ExprNamedExpr { - fn from(node: &'static ast::ExprNamedExpr) -> Self { - ExprNamedExpr(node) - } -} - -impl ToPyObject for ExprNamedExpr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprNamedExpr { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprNamedExpr(self).to_object(py)) - } -} - -#[pymethods] -impl ExprNamedExpr { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_BinOp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprBinOp(pub &'static ast::ExprBinOp); - -impl From<&'static ast::ExprBinOp> for ExprBinOp { - fn from(node: &'static ast::ExprBinOp) -> Self { - ExprBinOp(node) - } -} - -impl ToPyObject for ExprBinOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprBinOp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprBinOp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprBinOp { - #[getter] - #[inline] - fn get_left(&self, py: Python) -> PyResult { - self.0.left.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_op(&self, py: Python) -> PyResult { - self.0.op.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_right(&self, py: Python) -> PyResult { - self.0.right.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_UnaryOp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprUnaryOp(pub &'static ast::ExprUnaryOp); - -impl From<&'static ast::ExprUnaryOp> for ExprUnaryOp { - fn from(node: &'static ast::ExprUnaryOp) -> Self { - ExprUnaryOp(node) - } -} - -impl ToPyObject for ExprUnaryOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprUnaryOp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprUnaryOp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprUnaryOp { - #[getter] - #[inline] - fn get_op(&self, py: Python) -> PyResult { - self.0.op.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_operand(&self, py: Python) -> PyResult { - self.0.operand.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Lambda", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprLambda(pub &'static ast::ExprLambda); - -impl From<&'static ast::ExprLambda> for ExprLambda { - fn from(node: &'static ast::ExprLambda) -> Self { - ExprLambda(node) - } -} - -impl ToPyObject for ExprLambda { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprLambda { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprLambda(self).to_object(py)) - } -} - -#[pymethods] -impl ExprLambda { - #[getter] - #[inline] - fn get_args(&self, py: Python) -> PyResult { - self.0.args.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_IfExp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprIfExp(pub &'static ast::ExprIfExp); - -impl From<&'static ast::ExprIfExp> for ExprIfExp { - fn from(node: &'static ast::ExprIfExp) -> Self { - ExprIfExp(node) - } -} - -impl ToPyObject for ExprIfExp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprIfExp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprIfExp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprIfExp { - #[getter] - #[inline] - fn get_test(&self, py: Python) -> PyResult { - self.0.test.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_orelse(&self, py: Python) -> PyResult { - self.0.orelse.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Dict", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprDict(pub &'static ast::ExprDict); - -impl From<&'static ast::ExprDict> for ExprDict { - fn from(node: &'static ast::ExprDict) -> Self { - ExprDict(node) - } -} - -impl ToPyObject for ExprDict { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprDict { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprDict(self).to_object(py)) - } -} - -#[pymethods] -impl ExprDict { - #[getter] - #[inline] - fn get_keys(&self, py: Python) -> PyResult { - self.0.keys.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_values(&self, py: Python) -> PyResult { - self.0.values.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Set", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprSet(pub &'static ast::ExprSet); - -impl From<&'static ast::ExprSet> for ExprSet { - fn from(node: &'static ast::ExprSet) -> Self { - ExprSet(node) - } -} - -impl ToPyObject for ExprSet { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprSet { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprSet(self).to_object(py)) - } -} - -#[pymethods] -impl ExprSet { - #[getter] - #[inline] - fn get_elts(&self, py: Python) -> PyResult { - self.0.elts.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_ListComp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprListComp(pub &'static ast::ExprListComp); - -impl From<&'static ast::ExprListComp> for ExprListComp { - fn from(node: &'static ast::ExprListComp) -> Self { - ExprListComp(node) - } -} - -impl ToPyObject for ExprListComp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprListComp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprListComp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprListComp { - #[getter] - #[inline] - fn get_elt(&self, py: Python) -> PyResult { - self.0.elt.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_generators(&self, py: Python) -> PyResult { - self.0.generators.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_SetComp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprSetComp(pub &'static ast::ExprSetComp); - -impl From<&'static ast::ExprSetComp> for ExprSetComp { - fn from(node: &'static ast::ExprSetComp) -> Self { - ExprSetComp(node) - } -} - -impl ToPyObject for ExprSetComp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprSetComp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprSetComp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprSetComp { - #[getter] - #[inline] - fn get_elt(&self, py: Python) -> PyResult { - self.0.elt.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_generators(&self, py: Python) -> PyResult { - self.0.generators.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_DictComp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprDictComp(pub &'static ast::ExprDictComp); - -impl From<&'static ast::ExprDictComp> for ExprDictComp { - fn from(node: &'static ast::ExprDictComp) -> Self { - ExprDictComp(node) - } -} - -impl ToPyObject for ExprDictComp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprDictComp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprDictComp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprDictComp { - #[getter] - #[inline] - fn get_key(&self, py: Python) -> PyResult { - self.0.key.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_generators(&self, py: Python) -> PyResult { - self.0.generators.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_GeneratorExp", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprGeneratorExp(pub &'static ast::ExprGeneratorExp); - -impl From<&'static ast::ExprGeneratorExp> for ExprGeneratorExp { - fn from(node: &'static ast::ExprGeneratorExp) -> Self { - ExprGeneratorExp(node) - } -} - -impl ToPyObject for ExprGeneratorExp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprGeneratorExp { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprGeneratorExp(self).to_object(py)) - } -} - -#[pymethods] -impl ExprGeneratorExp { - #[getter] - #[inline] - fn get_elt(&self, py: Python) -> PyResult { - self.0.elt.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_generators(&self, py: Python) -> PyResult { - self.0.generators.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Await", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprAwait(pub &'static ast::ExprAwait); - -impl From<&'static ast::ExprAwait> for ExprAwait { - fn from(node: &'static ast::ExprAwait) -> Self { - ExprAwait(node) - } -} - -impl ToPyObject for ExprAwait { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprAwait { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprAwait(self).to_object(py)) - } -} - -#[pymethods] -impl ExprAwait { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Yield", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprYield(pub &'static ast::ExprYield); - -impl From<&'static ast::ExprYield> for ExprYield { - fn from(node: &'static ast::ExprYield) -> Self { - ExprYield(node) - } -} - -impl ToPyObject for ExprYield { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprYield { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprYield(self).to_object(py)) - } -} - -#[pymethods] -impl ExprYield { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_YieldFrom", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprYieldFrom(pub &'static ast::ExprYieldFrom); - -impl From<&'static ast::ExprYieldFrom> for ExprYieldFrom { - fn from(node: &'static ast::ExprYieldFrom) -> Self { - ExprYieldFrom(node) - } -} - -impl ToPyObject for ExprYieldFrom { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprYieldFrom { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprYieldFrom(self).to_object(py)) - } -} - -#[pymethods] -impl ExprYieldFrom { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Compare", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprCompare(pub &'static ast::ExprCompare); - -impl From<&'static ast::ExprCompare> for ExprCompare { - fn from(node: &'static ast::ExprCompare) -> Self { - ExprCompare(node) - } -} - -impl ToPyObject for ExprCompare { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprCompare { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprCompare(self).to_object(py)) - } -} - -#[pymethods] -impl ExprCompare { - #[getter] - #[inline] - fn get_left(&self, py: Python) -> PyResult { - self.0.left.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ops(&self, py: Python) -> PyResult { - self.0.ops.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_comparators(&self, py: Python) -> PyResult { - self.0.comparators.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Call", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprCall(pub &'static ast::ExprCall); - -impl From<&'static ast::ExprCall> for ExprCall { - fn from(node: &'static ast::ExprCall) -> Self { - ExprCall(node) - } -} - -impl ToPyObject for ExprCall { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprCall { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprCall(self).to_object(py)) - } -} - -#[pymethods] -impl ExprCall { - #[getter] - #[inline] - fn get_func(&self, py: Python) -> PyResult { - self.0.func.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_args(&self, py: Python) -> PyResult { - self.0.args.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_keywords(&self, py: Python) -> PyResult { - self.0.keywords.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_FormattedValue", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprFormattedValue(pub &'static ast::ExprFormattedValue); - -impl From<&'static ast::ExprFormattedValue> for ExprFormattedValue { - fn from(node: &'static ast::ExprFormattedValue) -> Self { - ExprFormattedValue(node) - } -} - -impl ToPyObject for ExprFormattedValue { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprFormattedValue { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprFormattedValue(self).to_object(py)) - } -} - -#[pymethods] -impl ExprFormattedValue { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_conversion(&self, py: Python) -> PyResult { - self.0.conversion.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_format_spec(&self, py: Python) -> PyResult { - self.0.format_spec.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_JoinedStr", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprJoinedStr(pub &'static ast::ExprJoinedStr); - -impl From<&'static ast::ExprJoinedStr> for ExprJoinedStr { - fn from(node: &'static ast::ExprJoinedStr) -> Self { - ExprJoinedStr(node) - } -} - -impl ToPyObject for ExprJoinedStr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprJoinedStr { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprJoinedStr(self).to_object(py)) - } -} - -#[pymethods] -impl ExprJoinedStr { - #[getter] - #[inline] - fn get_values(&self, py: Python) -> PyResult { - self.0.values.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Constant", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprConstant(pub &'static ast::ExprConstant); - -impl From<&'static ast::ExprConstant> for ExprConstant { - fn from(node: &'static ast::ExprConstant) -> Self { - ExprConstant(node) - } -} - -impl ToPyObject for ExprConstant { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprConstant { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprConstant(self).to_object(py)) - } -} - -#[pymethods] -impl ExprConstant { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kind(&self, py: Python) -> PyResult { - self.0.kind.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Attribute", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprAttribute(pub &'static ast::ExprAttribute); - -impl From<&'static ast::ExprAttribute> for ExprAttribute { - fn from(node: &'static ast::ExprAttribute) -> Self { - ExprAttribute(node) - } -} - -impl ToPyObject for ExprAttribute { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprAttribute { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprAttribute(self).to_object(py)) - } -} - -#[pymethods] -impl ExprAttribute { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_attr(&self, py: Python) -> PyResult { - self.0.attr.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Subscript", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprSubscript(pub &'static ast::ExprSubscript); - -impl From<&'static ast::ExprSubscript> for ExprSubscript { - fn from(node: &'static ast::ExprSubscript) -> Self { - ExprSubscript(node) - } -} - -impl ToPyObject for ExprSubscript { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprSubscript { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprSubscript(self).to_object(py)) - } -} - -#[pymethods] -impl ExprSubscript { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_slice(&self, py: Python) -> PyResult { - self.0.slice.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Starred", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprStarred(pub &'static ast::ExprStarred); - -impl From<&'static ast::ExprStarred> for ExprStarred { - fn from(node: &'static ast::ExprStarred) -> Self { - ExprStarred(node) - } -} - -impl ToPyObject for ExprStarred { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprStarred { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprStarred(self).to_object(py)) - } -} - -#[pymethods] -impl ExprStarred { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Name", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprName(pub &'static ast::ExprName); - -impl From<&'static ast::ExprName> for ExprName { - fn from(node: &'static ast::ExprName) -> Self { - ExprName(node) - } -} - -impl ToPyObject for ExprName { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprName { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprName(self).to_object(py)) - } -} - -#[pymethods] -impl ExprName { - #[getter] - #[inline] - fn get_id(&self, py: Python) -> PyResult { - self.0.id.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_List", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprList(pub &'static ast::ExprList); - -impl From<&'static ast::ExprList> for ExprList { - fn from(node: &'static ast::ExprList) -> Self { - ExprList(node) - } -} - -impl ToPyObject for ExprList { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprList { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprList(self).to_object(py)) - } -} - -#[pymethods] -impl ExprList { - #[getter] - #[inline] - fn get_elts(&self, py: Python) -> PyResult { - self.0.elts.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Tuple", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprTuple(pub &'static ast::ExprTuple); - -impl From<&'static ast::ExprTuple> for ExprTuple { - fn from(node: &'static ast::ExprTuple) -> Self { - ExprTuple(node) - } -} - -impl ToPyObject for ExprTuple { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprTuple { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprTuple(self).to_object(py)) - } -} - -#[pymethods] -impl ExprTuple { - #[getter] - #[inline] - fn get_elts(&self, py: Python) -> PyResult { - self.0.elts.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ctx(&self, py: Python) -> PyResult { - self.0.ctx.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Slice", extends=Expr, frozen)] -#[derive(Clone, Debug)] -pub struct ExprSlice(pub &'static ast::ExprSlice); - -impl From<&'static ast::ExprSlice> for ExprSlice { - fn from(node: &'static ast::ExprSlice) -> Self { - ExprSlice(node) - } -} - -impl ToPyObject for ExprSlice { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Expr) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExprSlice { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExprSlice(self).to_object(py)) - } -} - -#[pymethods] -impl ExprSlice { - #[getter] - #[inline] - fn get_lower(&self, py: Python) -> PyResult { - self.0.lower.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_upper(&self, py: Python) -> PyResult { - self.0.upper.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_step(&self, py: Python) -> PyResult { - self.0.step.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_expr_context", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct ExprContext; - -impl From<&'static ast::ExprContext> for ExprContext { - fn from(_node: &'static ast::ExprContext) -> Self { - ExprContext - } -} - -#[pymethods] -impl ExprContext { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for ExprContext { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Load", extends=ExprContext)] -pub struct ExprContextLoad; - -impl ToPyObject for ExprContextLoad { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(ExprContext) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Store", extends=ExprContext)] -pub struct ExprContextStore; - -impl ToPyObject for ExprContextStore { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(ExprContext) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Del", extends=ExprContext)] -pub struct ExprContextDel; - -impl ToPyObject for ExprContextDel { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(ExprContext) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_boolop", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct BoolOp; - -impl From<&'static ast::BoolOp> for BoolOp { - fn from(_node: &'static ast::BoolOp) -> Self { - BoolOp - } -} - -#[pymethods] -impl BoolOp { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for BoolOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_And", extends=BoolOp)] -pub struct BoolOpAnd; - -impl ToPyObject for BoolOpAnd { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(BoolOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Or", extends=BoolOp)] -pub struct BoolOpOr; - -impl ToPyObject for BoolOpOr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(BoolOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_operator", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct Operator; - -impl From<&'static ast::Operator> for Operator { - fn from(_node: &'static ast::Operator) -> Self { - Operator - } -} - -#[pymethods] -impl Operator { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for Operator { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Add", extends=Operator)] -pub struct OperatorAdd; - -impl ToPyObject for OperatorAdd { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Sub", extends=Operator)] -pub struct OperatorSub; - -impl ToPyObject for OperatorSub { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Mult", extends=Operator)] -pub struct OperatorMult; - -impl ToPyObject for OperatorMult { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_MatMult", extends=Operator)] -pub struct OperatorMatMult; - -impl ToPyObject for OperatorMatMult { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Div", extends=Operator)] -pub struct OperatorDiv; - -impl ToPyObject for OperatorDiv { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Mod", extends=Operator)] -pub struct OperatorMod; - -impl ToPyObject for OperatorMod { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Pow", extends=Operator)] -pub struct OperatorPow; - -impl ToPyObject for OperatorPow { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_LShift", extends=Operator)] -pub struct OperatorLShift; - -impl ToPyObject for OperatorLShift { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_RShift", extends=Operator)] -pub struct OperatorRShift; - -impl ToPyObject for OperatorRShift { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_BitOr", extends=Operator)] -pub struct OperatorBitOr; - -impl ToPyObject for OperatorBitOr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_BitXor", extends=Operator)] -pub struct OperatorBitXor; - -impl ToPyObject for OperatorBitXor { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_BitAnd", extends=Operator)] -pub struct OperatorBitAnd; - -impl ToPyObject for OperatorBitAnd { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_FloorDiv", extends=Operator)] -pub struct OperatorFloorDiv; - -impl ToPyObject for OperatorFloorDiv { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Operator) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_unaryop", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct UnaryOp; - -impl From<&'static ast::UnaryOp> for UnaryOp { - fn from(_node: &'static ast::UnaryOp) -> Self { - UnaryOp - } -} - -#[pymethods] -impl UnaryOp { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for UnaryOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Invert", extends=UnaryOp)] -pub struct UnaryOpInvert; - -impl ToPyObject for UnaryOpInvert { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(UnaryOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Not", extends=UnaryOp)] -pub struct UnaryOpNot; - -impl ToPyObject for UnaryOpNot { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(UnaryOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_UAdd", extends=UnaryOp)] -pub struct UnaryOpUAdd; - -impl ToPyObject for UnaryOpUAdd { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(UnaryOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_USub", extends=UnaryOp)] -pub struct UnaryOpUSub; - -impl ToPyObject for UnaryOpUSub { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(UnaryOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_cmpop", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct CmpOp; - -impl From<&'static ast::CmpOp> for CmpOp { - fn from(_node: &'static ast::CmpOp) -> Self { - CmpOp - } -} - -#[pymethods] -impl CmpOp { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for CmpOp { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Eq", extends=CmpOp)] -pub struct CmpOpEq; - -impl ToPyObject for CmpOpEq { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_NotEq", extends=CmpOp)] -pub struct CmpOpNotEq; - -impl ToPyObject for CmpOpNotEq { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Lt", extends=CmpOp)] -pub struct CmpOpLt; - -impl ToPyObject for CmpOpLt { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_LtE", extends=CmpOp)] -pub struct CmpOpLtE; - -impl ToPyObject for CmpOpLtE { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Gt", extends=CmpOp)] -pub struct CmpOpGt; - -impl ToPyObject for CmpOpGt { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_GtE", extends=CmpOp)] -pub struct CmpOpGtE; - -impl ToPyObject for CmpOpGtE { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_Is", extends=CmpOp)] -pub struct CmpOpIs; - -impl ToPyObject for CmpOpIs { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_IsNot", extends=CmpOp)] -pub struct CmpOpIsNot; - -impl ToPyObject for CmpOpIsNot { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_In", extends=CmpOp)] -pub struct CmpOpIn; - -impl ToPyObject for CmpOpIn { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_NotIn", extends=CmpOp)] -pub struct CmpOpNotIn; - -impl ToPyObject for CmpOpNotIn { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(CmpOp) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_comprehension", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Comprehension(pub &'static ast::Comprehension); - -impl From<&'static ast::Comprehension> for Comprehension { - fn from(node: &'static ast::Comprehension) -> Self { - Comprehension(node) - } -} - -impl ToPyObject for Comprehension { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Comprehension { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Comprehension(self).to_object(py)) - } -} - -#[pymethods] -impl Comprehension { - #[getter] - #[inline] - fn get_target(&self, py: Python) -> PyResult { - self.0.target.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_iter(&self, py: Python) -> PyResult { - self.0.iter.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_ifs(&self, py: Python) -> PyResult { - self.0.ifs.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_is_async(&self, py: Python) -> PyResult { - self.0.is_async.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_excepthandler", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct ExceptHandler; - -impl From<&'static ast::ExceptHandler> for ExceptHandler { - fn from(_node: &'static ast::ExceptHandler) -> Self { - ExceptHandler - } -} - -#[pymethods] -impl ExceptHandler { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for ExceptHandler { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExceptHandler { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::ExceptHandler(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_ExceptHandler", extends=ExceptHandler, frozen)] -#[derive(Clone, Debug)] -pub struct ExceptHandlerExceptHandler(pub &'static ast::ExceptHandlerExceptHandler); - -impl From<&'static ast::ExceptHandlerExceptHandler> for ExceptHandlerExceptHandler { - fn from(node: &'static ast::ExceptHandlerExceptHandler) -> Self { - ExceptHandlerExceptHandler(node) - } -} - -impl ToPyObject for ExceptHandlerExceptHandler { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(ExceptHandler) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::ExceptHandlerExceptHandler { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(ExceptHandlerExceptHandler(self).to_object(py)) - } -} - -#[pymethods] -impl ExceptHandlerExceptHandler { - #[getter] - #[inline] - fn get_type(&self, py: Python) -> PyResult { - self.0.type_.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_arguments", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Arguments(pub &'static ast::PythonArguments); - -impl From<&'static ast::PythonArguments> for Arguments { - fn from(node: &'static ast::PythonArguments) -> Self { - Arguments(node) - } -} - -impl ToPyObject for Arguments { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PythonArguments { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Arguments(self).to_object(py)) - } -} - -#[pymethods] -impl Arguments { - #[getter] - #[inline] - fn get_posonlyargs(&self, py: Python) -> PyResult { - self.0.posonlyargs.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_args(&self, py: Python) -> PyResult { - self.0.args.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_vararg(&self, py: Python) -> PyResult { - self.0.vararg.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kwonlyargs(&self, py: Python) -> PyResult { - self.0.kwonlyargs.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kw_defaults(&self, py: Python) -> PyResult { - self.0.kw_defaults.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kwarg(&self, py: Python) -> PyResult { - self.0.kwarg.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_defaults(&self, py: Python) -> PyResult { - self.0.defaults.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_arg", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Arg(pub &'static ast::Arg); - -impl From<&'static ast::Arg> for Arg { - fn from(node: &'static ast::Arg) -> Self { - Arg(node) - } -} - -impl ToPyObject for Arg { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Arg { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Arg(self).to_object(py)) - } -} - -#[pymethods] -impl Arg { - #[getter] - #[inline] - fn get_arg(&self, py: Python) -> PyResult { - self.0.arg.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_annotation(&self, py: Python) -> PyResult { - self.0.annotation.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_type_comment(&self, py: Python) -> PyResult { - self.0.type_comment.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_keyword", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Keyword(pub &'static ast::Keyword); - -impl From<&'static ast::Keyword> for Keyword { - fn from(node: &'static ast::Keyword) -> Self { - Keyword(node) - } -} - -impl ToPyObject for Keyword { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Keyword { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Keyword(self).to_object(py)) - } -} - -#[pymethods] -impl Keyword { - #[getter] - #[inline] - fn get_arg(&self, py: Python) -> PyResult { - self.0.arg.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_alias", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Alias(pub &'static ast::Alias); - -impl From<&'static ast::Alias> for Alias { - fn from(node: &'static ast::Alias) -> Self { - Alias(node) - } -} - -impl ToPyObject for Alias { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Alias { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Alias(self).to_object(py)) - } -} - -#[pymethods] -impl Alias { - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_asname(&self, py: Python) -> PyResult { - self.0.asname.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_withitem", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct WithItem(pub &'static ast::WithItem); - -impl From<&'static ast::WithItem> for WithItem { - fn from(node: &'static ast::WithItem) -> Self { - WithItem(node) - } -} - -impl ToPyObject for WithItem { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::WithItem { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(WithItem(self).to_object(py)) - } -} - -#[pymethods] -impl WithItem { - #[getter] - #[inline] - fn get_context_expr(&self, py: Python) -> PyResult { - self.0.context_expr.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_optional_vars(&self, py: Python) -> PyResult { - self.0.optional_vars.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_match_case", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct MatchCase(pub &'static ast::MatchCase); - -impl From<&'static ast::MatchCase> for MatchCase { - fn from(node: &'static ast::MatchCase) -> Self { - MatchCase(node) - } -} - -impl ToPyObject for MatchCase { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::MatchCase { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(MatchCase(self).to_object(py)) - } -} - -#[pymethods] -impl MatchCase { - #[getter] - #[inline] - fn get_pattern(&self, py: Python) -> PyResult { - self.0.pattern.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_guard(&self, py: Python) -> PyResult { - self.0.guard.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_body(&self, py: Python) -> PyResult { - self.0.body.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_pattern", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct Pattern; - -impl From<&'static ast::Pattern> for Pattern { - fn from(_node: &'static ast::Pattern) -> Self { - Pattern - } -} - -#[pymethods] -impl Pattern { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for Pattern { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Pattern { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::MatchValue(cons) => cons.to_py_wrapper(py), - Self::MatchSingleton(cons) => cons.to_py_wrapper(py), - Self::MatchSequence(cons) => cons.to_py_wrapper(py), - Self::MatchMapping(cons) => cons.to_py_wrapper(py), - Self::MatchClass(cons) => cons.to_py_wrapper(py), - Self::MatchStar(cons) => cons.to_py_wrapper(py), - Self::MatchAs(cons) => cons.to_py_wrapper(py), - Self::MatchOr(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_MatchValue", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchValue(pub &'static ast::PatternMatchValue); - -impl From<&'static ast::PatternMatchValue> for PatternMatchValue { - fn from(node: &'static ast::PatternMatchValue) -> Self { - PatternMatchValue(node) - } -} - -impl ToPyObject for PatternMatchValue { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchValue { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchValue(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchValue { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_MatchSingleton", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchSingleton(pub &'static ast::PatternMatchSingleton); - -impl From<&'static ast::PatternMatchSingleton> for PatternMatchSingleton { - fn from(node: &'static ast::PatternMatchSingleton) -> Self { - PatternMatchSingleton(node) - } -} - -impl ToPyObject for PatternMatchSingleton { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchSingleton { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchSingleton(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchSingleton { - #[getter] - #[inline] - fn get_value(&self, py: Python) -> PyResult { - self.0.value.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_MatchSequence", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchSequence(pub &'static ast::PatternMatchSequence); - -impl From<&'static ast::PatternMatchSequence> for PatternMatchSequence { - fn from(node: &'static ast::PatternMatchSequence) -> Self { - PatternMatchSequence(node) - } -} - -impl ToPyObject for PatternMatchSequence { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchSequence { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchSequence(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchSequence { - #[getter] - #[inline] - fn get_patterns(&self, py: Python) -> PyResult { - self.0.patterns.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_MatchMapping", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchMapping(pub &'static ast::PatternMatchMapping); - -impl From<&'static ast::PatternMatchMapping> for PatternMatchMapping { - fn from(node: &'static ast::PatternMatchMapping) -> Self { - PatternMatchMapping(node) - } -} - -impl ToPyObject for PatternMatchMapping { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchMapping { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchMapping(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchMapping { - #[getter] - #[inline] - fn get_keys(&self, py: Python) -> PyResult { - self.0.keys.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_patterns(&self, py: Python) -> PyResult { - self.0.patterns.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_rest(&self, py: Python) -> PyResult { - self.0.rest.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_MatchClass", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchClass(pub &'static ast::PatternMatchClass); - -impl From<&'static ast::PatternMatchClass> for PatternMatchClass { - fn from(node: &'static ast::PatternMatchClass) -> Self { - PatternMatchClass(node) - } -} - -impl ToPyObject for PatternMatchClass { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchClass { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchClass(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchClass { - #[getter] - #[inline] - fn get_cls(&self, py: Python) -> PyResult { - self.0.cls.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_patterns(&self, py: Python) -> PyResult { - self.0.patterns.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kwd_attrs(&self, py: Python) -> PyResult { - self.0.kwd_attrs.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_kwd_patterns(&self, py: Python) -> PyResult { - self.0.kwd_patterns.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_MatchStar", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchStar(pub &'static ast::PatternMatchStar); - -impl From<&'static ast::PatternMatchStar> for PatternMatchStar { - fn from(node: &'static ast::PatternMatchStar) -> Self { - PatternMatchStar(node) - } -} - -impl ToPyObject for PatternMatchStar { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchStar { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchStar(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchStar { - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_MatchAs", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchAs(pub &'static ast::PatternMatchAs); - -impl From<&'static ast::PatternMatchAs> for PatternMatchAs { - fn from(node: &'static ast::PatternMatchAs) -> Self { - PatternMatchAs(node) - } -} - -impl ToPyObject for PatternMatchAs { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchAs { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchAs(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchAs { - #[getter] - #[inline] - fn get_pattern(&self, py: Python) -> PyResult { - self.0.pattern.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_name(&self, py: Python) -> PyResult { - self.0.name.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_MatchOr", extends=Pattern, frozen)] -#[derive(Clone, Debug)] -pub struct PatternMatchOr(pub &'static ast::PatternMatchOr); - -impl From<&'static ast::PatternMatchOr> for PatternMatchOr { - fn from(node: &'static ast::PatternMatchOr) -> Self { - PatternMatchOr(node) - } -} - -impl ToPyObject for PatternMatchOr { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(Pattern) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::PatternMatchOr { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(PatternMatchOr(self).to_object(py)) - } -} - -#[pymethods] -impl PatternMatchOr { - #[getter] - #[inline] - fn get_patterns(&self, py: Python) -> PyResult { - self.0.patterns.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_type_ignore", extends=super::Ast, frozen, subclass)] -#[derive(Clone, Debug)] -pub struct TypeIgnore; - -impl From<&'static ast::TypeIgnore> for TypeIgnore { - fn from(_node: &'static ast::TypeIgnore) -> Self { - TypeIgnore - } -} - -#[pymethods] -impl TypeIgnore { - #[new] - fn new() -> PyClassInitializer { - PyClassInitializer::from(Ast).add_subclass(Self) - } -} -impl ToPyObject for TypeIgnore { - fn to_object(&self, py: Python) -> PyObject { - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::TypeIgnore { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match &self { - Self::TypeIgnore(cons) => cons.to_py_wrapper(py), - } - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_TypeIgnore", extends=TypeIgnore, frozen)] -#[derive(Clone, Debug)] -pub struct TypeIgnoreTypeIgnore(pub &'static ast::TypeIgnoreTypeIgnore); - -impl From<&'static ast::TypeIgnoreTypeIgnore> for TypeIgnoreTypeIgnore { - fn from(node: &'static ast::TypeIgnoreTypeIgnore) -> Self { - TypeIgnoreTypeIgnore(node) - } -} - -impl ToPyObject for TypeIgnoreTypeIgnore { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast) - .add_subclass(TypeIgnore) - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::TypeIgnoreTypeIgnore { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(TypeIgnoreTypeIgnore(self).to_object(py)) - } -} - -#[pymethods] -impl TypeIgnoreTypeIgnore { - #[getter] - #[inline] - fn get_lineno(&self, py: Python) -> PyResult { - self.0.lineno.to_py_wrapper(py) - } - - #[getter] - #[inline] - fn get_tag(&self, py: Python) -> PyResult { - self.0.tag.to_py_wrapper(py) - } -} - -#[pyclass(module="rustpython_ast.ranged", name="_decorator", extends=super::Ast, frozen)] -#[derive(Clone, Debug)] -pub struct Decorator(pub &'static ast::Decorator); - -impl From<&'static ast::Decorator> for Decorator { - fn from(node: &'static ast::Decorator) -> Self { - Decorator(node) - } -} - -impl ToPyObject for Decorator { - fn to_object(&self, py: Python) -> PyObject { - let initializer = PyClassInitializer::from(Ast).add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - } -} - -impl ToPyWrapper for ast::Decorator { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(Decorator(self).to_object(py)) - } -} - -#[pymethods] -impl Decorator { - #[getter] - #[inline] - fn get_expression(&self, py: Python) -> PyResult { - self.0.expression.to_py_wrapper(py) - } -} - -pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> { - super::init_module(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - super::init_type::(py, m)?; - Ok(()) -} diff --git a/ast-pyo3/src/lib.rs b/ast-pyo3/src/lib.rs deleted file mode 100644 index 65a336b074f9f..0000000000000 --- a/ast-pyo3/src/lib.rs +++ /dev/null @@ -1,49 +0,0 @@ -mod py_ast; -#[cfg(feature = "wrapper")] -pub mod wrapper; - -pub use py_ast::{init, PyNode, ToPyAst}; -use pyo3::prelude::*; -use rustpython_parser::ast::{source_code::LinearLocator, Fold}; - -#[pyfunction] -#[pyo3(signature = (source, filename="", *, type_comments=false, locate=true))] -pub fn parse<'py>( - source: &str, - filename: &str, - type_comments: bool, - locate: bool, - py: Python<'py>, -) -> PyResult<&'py PyAny> { - if type_comments { - todo!("'type_comments' is not implemented yet"); - } - let parsed = rustpython_parser::parse(source, rustpython_parser::Mode::Module, filename) - .map_err(|e| PyErr::new::(e.to_string()))?; - if locate { - let parsed = LinearLocator::new(source).fold(parsed).unwrap(); - parsed.module().unwrap().to_py_ast(py) - } else { - parsed.module().unwrap().to_py_ast(py) - } -} - -#[pymodule] -fn rustpython_ast(py: Python, m: &PyModule) -> PyResult<()> { - py_ast::init(py)?; - - #[cfg(feature = "wrapper")] - { - let ast = PyModule::new(py, "ast")?; - wrapper::located::add_to_module(py, ast)?; - m.add_submodule(ast)?; - - let ast = PyModule::new(py, "unlocated_ast")?; - wrapper::ranged::add_to_module(py, ast)?; - m.add_submodule(ast)?; - } - - m.add_function(wrap_pyfunction!(parse, m)?)?; - - Ok(()) -} diff --git a/ast-pyo3/src/py_ast.rs b/ast-pyo3/src/py_ast.rs deleted file mode 100644 index 6d2bb4179dda1..0000000000000 --- a/ast-pyo3/src/py_ast.rs +++ /dev/null @@ -1,219 +0,0 @@ -use num_complex::Complex64; -use num_traits::cast::ToPrimitive; -use once_cell::sync::OnceCell; -use pyo3::{ - prelude::*, - types::{PyBool, PyBytes, PyList, PyString, PyTuple}, - ToPyObject, -}; -use rustpython_ast::{ - self as ast, source_code::SourceRange, text_size::TextRange, ConversionFlag, Node, -}; - -pub trait PyNode { - fn py_type_cache() -> &'static OnceCell<(Py, Py)> { - { - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - } - } -} - -pub trait ToPyAst { - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny>; -} - -impl ToPyAst for Box { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - (**self).to_py_ast(py) - } -} - -impl ToPyAst for Option { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - match self { - Some(ast) => ast.to_py_ast(py), - None => Ok(ast_cache().none_ref(py)), - } - } -} - -impl ToPyAst for Vec { - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let elts = self - .iter() - .map(|item| item.to_py_ast(py)) - .collect::, _>>()?; - let list = PyList::new(py, elts); - Ok(list.into()) - } -} - -impl ToPyAst for ast::Identifier { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - Ok(PyString::new(py, self.as_str()).into()) - } -} - -impl ToPyAst for ast::String { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - Ok(PyString::new(py, self.as_str()).into()) - } -} - -impl ToPyAst for bool { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - Ok(ast_cache().bool_int(py, *self)) - } -} - -impl ToPyAst for ConversionFlag { - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - Ok(ast_cache().conversion_flag(py, *self)) - } -} - -impl ToPyAst for ast::Arguments -where - R: Clone, - ast::PythonArguments: ToPyAst, -{ - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> { - let arguments = self.to_python_arguments(); - arguments.to_py_ast(py) - } -} - -fn constant_to_object(constant: &ast::Constant, py: Python) -> PyObject { - let cache = ast_cache(); - match constant { - ast::Constant::None => cache.none.clone_ref(py), - ast::Constant::Bool(bool) => cache.bool(py, *bool).into(), - ast::Constant::Str(string) => string.to_object(py), - ast::Constant::Bytes(bytes) => PyBytes::new(py, bytes).into(), - ast::Constant::Int(int) => match int.to_i64() { - Some(small_int) => small_int.to_object(py), - None => int.to_object(py), - }, - ast::Constant::Tuple(elts) => { - let elts: Vec<_> = elts.iter().map(|c| constant_to_object(c, py)).collect(); - PyTuple::new(py, elts).into() - } - ast::Constant::Float(f64) => f64.to_object(py), - ast::Constant::Complex { real, imag } => Complex64::new(*real, *imag).to_object(py), - ast::Constant::Ellipsis => py.Ellipsis(), - } -} - -#[pyclass(module = "rustpython_ast", subclass)] -pub struct Ast; - -#[pymethods] -impl Ast { - #[new] - fn new() -> Self { - Self - } -} - -fn cache_py_type(ast_module: &PyAny) -> PyResult<()> { - let class = ast_module.getattr(N::NAME)?; - let base = if std::mem::size_of::() == 0 { - class.call0()? - } else { - class.getattr("__new__")? - }; - N::py_type_cache().get_or_init(|| (class.into(), base.into())); - Ok(()) -} - -// TODO: This cache must be bound to 'py -struct AstCache { - lineno: Py, - col_offset: Py, - end_lineno: Py, - end_col_offset: Py, - none: Py, - bool_values: (Py, Py), - bool_int_values: (Py, Py), - conversion_flags: (Py, Py, Py, Py), -} - -impl AstCache { - // fn location_vec<'py>(&'static self, py: Python<'py>, range: &SourceRange) -> &'py PyDict { - // let attributes = PyDict::new(py); - // attributes.set_item(self.lineno.as_ref(py), range.start.row.get()).unwrap(); - // attributes.set_item(self.col_offset.as_ref(py), range.start.column.to_zero_indexed()).unwrap(); - // if let Some(end) = range.end { - // attributes.set_item(self.end_lineno.as_ref(py), end.row.get()).unwrap(); - // attributes.set_item( - // self.end_col_offset.as_ref(py), - // end.column.to_zero_indexed(), - // ).unwrap(); - // } - // attributes - // } - #[inline] - fn none_ref<'py>(&'static self, py: Python<'py>) -> &'py PyAny { - Py::::as_ref(&self.none, py) - } - #[inline] - fn bool_int<'py>(&'static self, py: Python<'py>, value: bool) -> &'py PyAny { - let v = &self.bool_int_values; - Py::::as_ref(if value { &v.1 } else { &v.0 }, py) - } - #[inline] - fn bool(&'static self, py: Python, value: bool) -> Py { - let v = &self.bool_values; - (if value { &v.1 } else { &v.0 }).clone_ref(py) - } - fn conversion_flag<'py>(&'static self, py: Python<'py>, value: ConversionFlag) -> &'py PyAny { - let v = &self.conversion_flags; - match value { - ConversionFlag::None => v.0.as_ref(py), - ConversionFlag::Str => v.1.as_ref(py), - ConversionFlag::Ascii => v.2.as_ref(py), - ConversionFlag::Repr => v.3.as_ref(py), - } - } -} - -fn ast_cache_cell() -> &'static OnceCell { - { - static PY_TYPE: OnceCell = OnceCell::new(); - &PY_TYPE - } -} - -fn ast_cache() -> &'static AstCache { - ast_cache_cell().get().unwrap() -} - -pub fn init(py: Python) -> PyResult<()> { - ast_cache_cell().get_or_init(|| AstCache { - lineno: pyo3::intern!(py, "lineno").into_py(py), - col_offset: pyo3::intern!(py, "col_offset").into_py(py), - end_lineno: pyo3::intern!(py, "end_lineno").into_py(py), - end_col_offset: pyo3::intern!(py, "end_col_offset").into_py(py), - none: py.None(), - bool_values: (PyBool::new(py, false).into(), PyBool::new(py, true).into()), - bool_int_values: ((0).to_object(py), (1).to_object(py)), - conversion_flags: ( - (-1).to_object(py), - (b's').to_object(py), - (b'a').to_object(py), - (b'r').to_object(py), - ), - }); - - init_types(py) -} - -include!("gen/to_py_ast.rs"); diff --git a/ast-pyo3/src/wrapper.rs b/ast-pyo3/src/wrapper.rs deleted file mode 100644 index 1ac8f1c10fed3..0000000000000 --- a/ast-pyo3/src/wrapper.rs +++ /dev/null @@ -1,153 +0,0 @@ -use crate::PyNode; -use num_complex::Complex64; -use pyo3::prelude::*; -use pyo3::types::{PyBytes, PyList, PyTuple}; -use rustpython_ast::{ - self as ast, source_code::SourceRange, text_size::TextRange, ConversionFlag, Node, -}; - -pub trait ToPyWrapper { - fn to_py_wrapper(&'static self, py: Python) -> PyResult>; -} - -impl ToPyWrapper for Box { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - (**self).to_py_wrapper(py) - } -} - -impl ToPyWrapper for Option { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - match self { - Some(ast) => ast.to_py_wrapper(py), - None => Ok(py.None()), - } - } -} - -impl ToPyWrapper for ast::Identifier { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(self.as_str().to_object(py)) - } -} - -impl ToPyWrapper for ast::String { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok(self.as_str().to_object(py)) - } -} - -impl ToPyWrapper for ast::Int { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok((self.to_u32()).to_object(py)) - } -} - -impl ToPyWrapper for bool { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok((*self as u32).to_object(py)) - } -} - -impl ToPyWrapper for ConversionFlag { - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - Ok((*self as i8).to_object(py)) - } -} - -impl ToPyWrapper for ast::Constant { - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - let value = match self { - ast::Constant::None => py.None(), - ast::Constant::Bool(bool) => bool.to_object(py), - ast::Constant::Str(string) => string.to_object(py), - ast::Constant::Bytes(bytes) => PyBytes::new(py, bytes).into(), - ast::Constant::Int(int) => int.to_object(py), - ast::Constant::Tuple(elts) => { - let elts: PyResult> = elts.iter().map(|c| c.to_py_wrapper(py)).collect(); - PyTuple::new(py, elts?).into() - } - ast::Constant::Float(f64) => f64.to_object(py), - ast::Constant::Complex { real, imag } => Complex64::new(*real, *imag).to_object(py), - ast::Constant::Ellipsis => py.Ellipsis(), - }; - Ok(value) - } -} - -impl ToPyWrapper for Vec { - fn to_py_wrapper(&'static self, py: Python) -> PyResult> { - let list = PyList::empty(py); - for item in self { - let py_item = item.to_py_wrapper(py)?; - list.append(py_item)?; - } - Ok(list.into()) - } -} - -impl ToPyWrapper for ast::Arguments -where - Self: Clone, - ast::PythonArguments: ToPyWrapper, -{ - #[inline] - fn to_py_wrapper(&'static self, _py: Python) -> PyResult> { - todo!() - // Ok(FunctionArguments(self).to_object(py)) - } -} - -#[pyclass(module = "rustpython_ast", name = "AST", subclass)] -pub struct Ast; - -#[pymethods] -impl Ast { - #[new] - fn new() -> Self { - Self - } -} - -pub mod located { - pub use super::Ast; - use super::*; - include!("gen/wrapper_located.rs"); -} - -pub mod ranged { - pub use super::Ast; - use super::*; - include!("gen/wrapper_ranged.rs"); -} - -fn init_type(py: Python, m: &PyModule) -> PyResult<()> { - m.add_class::

()?; - let node = m.getattr(P::NAME)?; - if P::NAME != N::NAME { - // TODO: no idea how to escape rust keyword on #[pyclass] - m.setattr(P::NAME, node)?; - } - let names: Vec<&'static str> = N::FIELD_NAMES.to_vec(); - let fields = PyTuple::new(py, names); - node.setattr("_fields", fields)?; - Ok(()) -} - -/// A Python module implemented in Rust. -fn init_module(py: Python, m: &PyModule) -> PyResult<()> { - m.add_class::()?; - - let ast = m.getattr("AST")?; - let fields = PyTuple::empty(py); - ast.setattr("_fields", fields)?; - - Ok(()) -} diff --git a/ast-pyo3/test_ast.py b/ast-pyo3/test_ast.py deleted file mode 100644 index e09d189291e13..0000000000000 --- a/ast-pyo3/test_ast.py +++ /dev/null @@ -1,56 +0,0 @@ -import re -import difflib -import pytest - -import ast as py_ast -import rustpython_ast as rust_ast - - -from glob import glob - -files = {} -for path in glob("../../cpython/Lib/**/*.py"): - try: - txt = open(path, "r").read() - except UnicodeDecodeError: - continue - - # try: - # if py_ast.dump(py_ast.parse(txt)) != py_ast.dump(rust_ast.parse(txt)): - # continue - # except SyntaxError: - # continue - files[path] = txt - - -@pytest.mark.parametrize("path", files.keys()) -def test_roundtrip(path): - txt = files[path] - module_p = py_ast.parse(txt) - dump_p = py_ast.dump(module_p, indent=True) - module_r = rust_ast.parse(txt) - dump_r = py_ast.dump(module_r, indent=True) - p = re.compile("object at 0x[0-9a-f]+") - dump_p2 = re.sub(p, "object at 0x????????", dump_p) - dump_r2 = re.sub(p, "object at 0x????????", dump_r) - try: - assert dump_p2 == dump_r2 - except AssertionError: - last_sign = ' ' - for s in difflib.ndiff(dump_p2, dump_r2): - if s[0]==' ': continue - if s[0] == last_sign: - print(s[2:], end='') - else: - print() - print(s, end='') - last_sign = s[0] - # with open("dump_code.py", "w") as f: - # f.write(path) - # f.write('\n') - # f.write(txt) - # with open("dump_p.txt", "w") as f: - # f.write(dump_p2) - # with open("dump_r.txt", "w") as f: - # f.write(dump_r2) - raise diff --git a/ast/Cargo.toml b/ast/Cargo.toml index d3229bcc645af..967b0e634fdaf 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -8,12 +8,7 @@ repository = "https://github.com/RustPython/Parser/" license = "MIT" [features] -default = ["location", "malachite-bigint"] -constant-optimization = ["fold"] -location = ["fold", "rustpython-parser-core/location"] -fold = [] -unparse = ["rustpython-literal"] -visitor = [] +default = ["malachite-bigint"] all-nodes-with-ranges = [] [dependencies] diff --git a/ast/asdl_rs.py b/ast/asdl_rs.py index 517a4b47a9101..39bfdf3643e60 100755 --- a/ast/asdl_rs.py +++ b/ast/asdl_rs.py @@ -3,14 +3,12 @@ # ! /usr/bin/env python """Generate Rust code from an ASDL description.""" +import re import sys -import json import textwrap -import re - from argparse import ArgumentParser from pathlib import Path -from typing import Optional, Dict, Any +from typing import Any, Dict, Optional import asdl @@ -554,9 +552,11 @@ def sum_with_constructors(self, sum, type, depth): for t in sum.types: self.sum_subtype_struct(type_info, t, rust_name, depth) - def sum_subtype_struct(self, sum_type_info, t, rust_name, depth): - self.emit(f"""/// See also [{t.name}](https://docs.python.org/3/library/ast.html#ast.{t.name})""", depth) + self.emit( + f"""/// See also [{t.name}](https://docs.python.org/3/library/ast.html#ast.{t.name})""", + depth, + ) self.emit_attrs(depth) payload_name = f"{rust_name}{t.name}" self.emit(f"pub struct {payload_name} {{", depth) @@ -657,379 +657,6 @@ def visitProduct(self, product, type, depth): ) -class FoldTraitDefVisitor(EmitVisitor): - def visitModule(self, mod, depth): - self.emit("pub trait Fold {", depth) - self.emit("type TargetU;", depth + 1) - self.emit("type Error;", depth + 1) - self.emit("type UserContext;", depth + 1) - self.emit( - """ - fn will_map_user(&mut self, user: &U) -> Self::UserContext; - #[cfg(feature = "all-nodes-with-ranges")] - fn will_map_user_cfg(&mut self, user: &U) -> Self::UserContext { - self.will_map_user(user) - } - #[cfg(not(feature = "all-nodes-with-ranges"))] - fn will_map_user_cfg(&mut self, _user: &crate::EmptyRange) -> crate::EmptyRange { - crate::EmptyRange::default() - } - fn map_user(&mut self, user: U, context: Self::UserContext) -> Result; - #[cfg(feature = "all-nodes-with-ranges")] - fn map_user_cfg(&mut self, user: U, context: Self::UserContext) -> Result { - self.map_user(user, context) - } - #[cfg(not(feature = "all-nodes-with-ranges"))] - fn map_user_cfg( - &mut self, - _user: crate::EmptyRange, - _context: crate::EmptyRange, - ) -> Result, Self::Error> { - Ok(crate::EmptyRange::default()) - } - """, - depth + 1, - ) - self.emit( - """ - fn fold>(&mut self, node: X) -> Result { - node.fold(self) - }""", - depth + 1, - ) - for dfn in mod.dfns + [arg_with_default]: - dfn = maybe_custom(dfn) - self.visit(dfn, depth + 2) - self.emit("}", depth) - - def visitType(self, type, depth): - info = self.type_info[type.name] - apply_u, apply_target_u = self.apply_generics(info.name, "U", "Self::TargetU") - enum_name = info.full_type_name - self.emit( - f"fn fold_{info.full_field_name}(&mut self, node: {enum_name}{apply_u}) -> Result<{enum_name}{apply_target_u}, Self::Error> {{", - depth, - ) - self.emit(f"fold_{info.full_field_name}(self, node)", depth + 1) - self.emit("}", depth) - - if isinstance(type.value, asdl.Sum) and not is_simple(type.value): - for cons in type.value.types: - self.visit(cons, type, depth) - - def visitConstructor(self, cons, type, depth): - info = self.type_info[type.name] - apply_u, apply_target_u = self.apply_generics(type.name, "U", "Self::TargetU") - enum_name = rust_type_name(type.name) - func_name = f"fold_{info.full_field_name}_{rust_field_name(cons.name)}" - self.emit( - f"fn {func_name}(&mut self, node: {enum_name}{cons.name}{apply_u}) -> Result<{enum_name}{cons.name}{apply_target_u}, Self::Error> {{", - depth, - ) - self.emit(f"{func_name}(self, node)", depth + 1) - self.emit("}", depth) - - -class FoldImplVisitor(EmitVisitor): - def visitModule(self, mod, depth): - for dfn in mod.dfns + [arg_with_default]: - dfn = maybe_custom(dfn) - self.visit(dfn, depth) - - def visitType(self, type, depth=0): - self.visit(type.value, type, depth) - - def visitSum(self, sum, type, depth): - name = type.name - apply_t, apply_u, apply_target_u = self.apply_generics( - name, "T", "U", "F::TargetU" - ) - enum_name = rust_type_name(name) - simple = is_simple(sum) - - self.emit(f"impl Foldable for {enum_name}{apply_t} {{", depth) - self.emit(f"type Mapped = {enum_name}{apply_u};", depth + 1) - self.emit( - "fn fold + ?Sized>(self, folder: &mut F) -> Result {", - depth + 1, - ) - self.emit(f"folder.fold_{name}(self)", depth + 2) - self.emit("}", depth + 1) - self.emit("}", depth) - - self.emit( - f"pub fn fold_{name} + ?Sized>(#[allow(unused)] folder: &mut F, node: {enum_name}{apply_u}) -> Result<{enum_name}{apply_target_u}, F::Error> {{", - depth, - ) - - if simple: - self.emit("Ok(node) }", depth + 1) - return - - self.emit("let folded = match node {", depth + 1) - for cons in sum.types: - self.emit( - f"{enum_name}::{cons.name}(cons) => {enum_name}::{cons.name}(Foldable::fold(cons, folder)?),", - depth + 1, - ) - - self.emit("};", depth + 1) - self.emit("Ok(folded)", depth + 1) - self.emit("}", depth) - - for cons in sum.types: - self.visit(cons, type, depth) - - def visitConstructor(self, cons, type, depth): - apply_t, apply_u, apply_target_u = self.apply_generics( - type.name, "T", "U", "F::TargetU" - ) - info = self.type_info[type.name] - enum_name = info.full_type_name - - cons_type_name = f"{enum_name}{cons.name}" - - self.emit(f"impl Foldable for {cons_type_name}{apply_t} {{", depth) - self.emit(f"type Mapped = {cons_type_name}{apply_u};", depth + 1) - self.emit( - "fn fold + ?Sized>(self, folder: &mut F) -> Result {", - depth + 1, - ) - self.emit( - f"folder.fold_{info.full_field_name}_{rust_field_name(cons.name)}(self)", - depth + 2, - ) - self.emit("}", depth + 1) - self.emit("}", depth) - - self.emit( - f"pub fn fold_{info.full_field_name}_{rust_field_name(cons.name)} + ?Sized>(#[allow(unused)] folder: &mut F, node: {cons_type_name}{apply_u}) -> Result<{enum_name}{cons.name}{apply_target_u}, F::Error> {{", - depth, - ) - - fields_pattern = self.make_pattern(cons.fields) - - map_user_suffix = "" if info.has_attributes else "_cfg" - self.emit( - f""" - let {cons_type_name} {{ {fields_pattern} }} = node; - let context = folder.will_map_user{map_user_suffix}(&range); - """, - depth + 3, - ) - self.fold_fields(cons.fields, depth + 3) - self.emit( - f"let range = folder.map_user{map_user_suffix}(range, context)?;", - depth + 3, - ) - self.composite_fields(f"{cons_type_name}", cons.fields, depth + 3) - self.emit("}", depth + 2) - - def visitProduct(self, product, type, depth): - info = self.type_info[type.name] - name = type.name - apply_t, apply_u, apply_target_u = self.apply_generics( - name, "T", "U", "F::TargetU" - ) - struct_name = info.full_type_name - has_attributes = bool(product.attributes) - - self.emit(f"impl Foldable for {struct_name}{apply_t} {{", depth) - self.emit(f"type Mapped = {struct_name}{apply_u};", depth + 1) - self.emit( - "fn fold + ?Sized>(self, folder: &mut F) -> Result {", - depth + 1, - ) - self.emit(f"folder.fold_{info.full_field_name}(self)", depth + 2) - self.emit("}", depth + 1) - self.emit("}", depth) - - self.emit( - f"pub fn fold_{info.full_field_name} + ?Sized>(#[allow(unused)] folder: &mut F, node: {struct_name}{apply_u}) -> Result<{struct_name}{apply_target_u}, F::Error> {{", - depth, - ) - - fields_pattern = self.make_pattern(product.fields) - self.emit(f"let {struct_name} {{ {fields_pattern} }} = node;", depth + 1) - - map_user_suffix = "" if has_attributes else "_cfg" - - self.emit( - f"let context = folder.will_map_user{map_user_suffix}(&range);", depth + 3 - ) - self.fold_fields(product.fields, depth + 1) - self.emit( - f"let range = folder.map_user{map_user_suffix}(range, context)?;", depth + 3 - ) - self.composite_fields(struct_name, product.fields, depth + 1) - - self.emit("}", depth) - - def make_pattern(self, fields): - body = ",".join(rust_field(f.name) for f in fields) - if body: - body += "," - body += "range" - - return body - - def fold_fields(self, fields, depth): - for field in fields: - name = rust_field(field.name) - self.emit(f"let {name} = Foldable::fold({name}, folder)?;", depth + 1) - - def composite_fields(self, header, fields, depth): - self.emit(f"Ok({header} {{", depth) - for field in fields: - name = rust_field(field.name) - self.emit(f"{name},", depth + 1) - self.emit("range,", depth + 1) - self.emit("})", depth) - - -class FoldModuleVisitor(EmitVisitor): - def visitModule(self, mod): - depth = 0 - FoldTraitDefVisitor(self.file, self.type_info).visit(mod, depth) - FoldImplVisitor(self.file, self.type_info).visit(mod, depth) - - -class VisitorModuleVisitor(StructVisitor): - def full_name(self, name): - type_info = self.type_info[name] - if type_info.enum_name: - return f"{type_info.enum_name}_{name}" - else: - return name - - def node_type_name(self, name): - type_info = self.type_info[name] - if type_info.enum_name: - return f"{rust_type_name(type_info.enum_name)}{rust_type_name(name)}" - else: - return rust_type_name(name) - - def visitModule(self, mod, depth=0): - self.emit("#[allow(unused_variables)]", depth) - self.emit("pub trait Visitor {", depth) - - for dfn in mod.dfns: - dfn = self.customized_type_info(dfn.name).type - self.visit(dfn, depth + 1) - self.emit("}", depth) - - def visitType(self, type, depth=0): - self.visit(type.value, type.name, depth) - - def visitSum(self, sum, name, depth): - if is_simple(sum): - self.simple_sum(sum, name, depth) - else: - self.sum_with_constructors(sum, name, depth) - - def emit_visitor(self, nodename, depth, has_node=True): - type_info = self.type_info[nodename] - node_type = type_info.full_type_name - (generic,) = self.apply_generics(nodename, "R") - self.emit( - f"fn visit_{type_info.full_field_name}(&mut self, node: {node_type}{generic}) {{", - depth, - ) - if has_node: - self.emit( - f"self.generic_visit_{type_info.full_field_name}(node)", depth + 1 - ) - - self.emit("}", depth) - - def emit_generic_visitor_signature(self, nodename, depth, has_node=True): - type_info = self.type_info[nodename] - if has_node: - node_type = type_info.full_type_name - else: - node_type = "()" - (generic,) = self.apply_generics(nodename, "R") - self.emit( - f"fn generic_visit_{type_info.full_field_name}(&mut self, node: {node_type}{generic}) {{", - depth, - ) - - def emit_empty_generic_visitor(self, nodename, depth): - self.emit_generic_visitor_signature(nodename, depth) - self.emit("}", depth) - - def simple_sum(self, sum, name, depth): - self.emit_visitor(name, depth) - self.emit_empty_generic_visitor(name, depth) - - def visit_match_for_type(self, nodename, rust_name, type_, depth): - self.emit(f"{rust_name}::{type_.name}", depth) - self.emit("(data)", depth) - self.emit( - f"=> self.visit_{nodename}_{rust_field_name(type_.name)}(data),", depth - ) - - def visit_sum_type(self, name, type_, depth): - self.emit_visitor(type_.name, depth, has_node=type_.fields) - if not type_.fields: - return - - self.emit_generic_visitor_signature(type_.name, depth, has_node=True) - for field in type_.fields: - if field.type in CUSTOM_REPLACEMENTS: - type_name = CUSTOM_REPLACEMENTS[field.type].name - else: - type_name = field.type - field_name = rust_field(field.name) - field_type = self.type_info.get(type_name) - if not (field_type and field_type.has_user_data): - continue - - if field.opt: - self.emit(f"if let Some(value) = node.{field_name} {{", depth + 1) - elif field.seq: - iterable = f"node.{field_name}" - if type_.name == "Dict" and field.name == "keys": - iterable = f"{iterable}.into_iter().flatten()" - self.emit(f"for value in {iterable} {{", depth + 1) - else: - self.emit("{", depth + 1) - self.emit(f"let value = node.{field_name};", depth + 2) - - variable = "value" - if field_type.boxed and (not field.seq or field.opt): - variable = "*" + variable - type_info = self.type_info[field_type.name] - self.emit(f"self.visit_{type_info.full_field_name}({variable});", depth + 2) - - self.emit("}", depth + 1) - - self.emit("}", depth) - - def sum_with_constructors(self, sum, name, depth): - if not sum.attributes: - return - - enum_name = rust_type_name(name) - self.emit_visitor(name, depth) - self.emit_generic_visitor_signature(name, depth) - depth += 1 - self.emit("match node {", depth) - for t in sum.types: - self.visit_match_for_type(name, enum_name, t, depth + 1) - self.emit("}", depth) - depth -= 1 - self.emit("}", depth) - - # Now for the visitors for the types - for t in sum.types: - self.visit_sum_type(name, t, depth) - - def visitProduct(self, product, name, depth): - self.emit_visitor(name, depth) - self.emit_empty_generic_visitor(name, depth) - - class RangedDefVisitor(EmitVisitor): def visitModule(self, mod): for dfn in mod.dfns + CUSTOM_TYPES: @@ -1106,1083 +733,73 @@ def emit_ranged_impl(self, info): ) -class LocatedDefVisitor(EmitVisitor): - def visitModule(self, mod): - for dfn in mod.dfns + CUSTOM_TYPES: - self.visit(dfn) - - def visitType(self, type, depth=0): - self.visit(type.value, type.name, depth) - - def visitSum(self, sum, name, depth): - info = self.type_info[name] +def write_ast_def(mod, type_info, f): + f.write("use crate::text_size::TextRange;") + StructVisitor(f, type_info).visit(mod) - self.emit_type_alias(info) - if info.is_simple: - for ty in sum.types: - variant_info = self.type_info[ty.name] - self.emit_type_alias(variant_info) - return +def write_ranged_def(mod, type_info, f): + RangedDefVisitor(f, type_info).visit(mod) - sum_match_arms = "" - for ty in sum.types: - variant_info = self.type_info[ty.name] - sum_match_arms += ( - f" Self::{variant_info.rust_name}(node) => node.range()," - ) - self.emit_type_alias(variant_info) - self.emit_located_impl(variant_info) +def write_parse_def(mod, type_info, f): + for info in type_info.values(): + if info.enum_name not in ["expr", "stmt"]: + continue - if not info.no_cfg(self.type_info): - cfg = '#[cfg(feature = "all-nodes-with-ranges")]' - else: - cfg = '' + type_name = rust_type_name(info.enum_name) + cons_name = rust_type_name(info.name) - self.emit( + f.write( f""" - {cfg} - impl Located for {info.full_type_name} {{ - fn range(&self) -> SourceRange {{ - match self {{ - {sum_match_arms} - }} - }} + impl Parse for ast::{info.full_type_name} {{ + fn lex_starts_at( + source: &str, + offset: TextSize, + ) -> SoftKeywordTransformer> {{ + ast::{type_name}::lex_starts_at(source, offset) }} - {cfg} - impl LocatedMut for {info.full_type_name} {{ - fn range_mut(&mut self) -> &mut SourceRange {{ - match self {{ - {sum_match_arms.replace('range()', 'range_mut()')} - }} + fn parse_tokens( + lxr: impl IntoIterator, + source_path: &str, + ) -> Result {{ + let node = ast::{type_name}::parse_tokens(lxr, source_path)?; + match node {{ + ast::{type_name}::{cons_name}(node) => Ok(node), + node => Err(ParseError {{ + error: ParseErrorType::InvalidToken, + offset: node.range().start(), + source_path: source_path.to_owned(), + }}), }} }} - """.lstrip(), - 0, + }} + """ ) - def visitProduct(self, product, name, depth): - info = self.type_info[name] - - self.emit_type_alias(info) - self.emit_located_impl(info) - def emit_type_alias(self, info): - generics = "" if info.is_simple else "::" +def main( + input_filename, + ast_dir, + parser_dir, + dump_module=False, +): + auto_gen_msg = AUTO_GEN_MESSAGE.format("/".join(Path(__file__).parts[-2:])) + mod = asdl.parse(input_filename) + if dump_module: + print("Parsed Module:") + print(mod) + if not asdl.check(mod): + sys.exit(1) - self.emit( - f"pub type {info.full_type_name} = crate::generic::{info.full_type_name}{generics};", - 0, - ) - self.emit("", 0) + type_info = {} + FindUserDataTypesVisitor(type_info).visit(mod) - def emit_located_impl(self, info): - if not info.no_cfg(self.type_info): - cfg = '#[cfg(feature = "all-nodes-with-ranges")]' - else: - cfg = '' - - self.emit( - f""" - {cfg} - impl Located for {info.full_type_name} {{ - fn range(&self) -> SourceRange {{ - self.range - }} - }} - {cfg} - impl LocatedMut for {info.full_type_name} {{ - fn range_mut(&mut self) -> &mut SourceRange {{ - &mut self.range - }} - }} - """, - 0, - ) - - -class ToPyo3AstVisitor(EmitVisitor): - """Visitor to generate type-defs for AST.""" - - def __init__(self, namespace, *args, **kw): - super().__init__(*args, **kw) - self.namespace = namespace - - @property - def generics(self): - if self.namespace == "ranged": - return "" - elif self.namespace == "located": - return "" - else: - assert False, self.namespace - - def visitModule(self, mod): - for dfn in mod.dfns: - self.visit(dfn) - - def visitType(self, type): - self.visit(type.value, type) - - def visitProduct(self, product, type): - info = self.type_info[type.name] - rust_name = info.full_type_name - self.emit_to_pyo3_with_fields(product, type, rust_name) - - def visitSum(self, sum, type): - info = self.type_info[type.name] - rust_name = info.full_type_name - simple = is_simple(sum) - if is_simple(sum): - return - - self.emit( - f""" - impl ToPyAst for ast::{rust_name}{self.generics} {{ - #[inline] - fn to_py_ast<'py>(&self, {"_" if simple else ""}py: Python<'py>) -> PyResult<&'py PyAny> {{ - let instance = match &self {{ - """, - 0, - ) - for cons in sum.types: - self.emit( - f"ast::{rust_name}::{cons.name}(cons) => cons.to_py_ast(py)?,", - 1, - ) - self.emit( - """ - }; - Ok(instance) - } - } - """, - 0, - ) - - for cons in sum.types: - self.visit(cons, type) - - def visitConstructor(self, cons, type): - parent = rust_type_name(type.name) - self.emit_to_pyo3_with_fields(cons, type, f"{parent}{cons.name}") - - def emit_to_pyo3_with_fields(self, cons, type, name): - type_info = self.type_info[type.name] - - self.emit( - f""" - impl ToPyAst for ast::{name}{self.generics} {{ - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {{ - let cache = Self::py_type_cache().get().unwrap(); - """, - 0, - ) - if cons.fields: - field_names = ", ".join(rust_field(f.name) for f in cons.fields) - if not type_info.is_simple: - field_names += ", range: _range" - self.emit( - f"let Self {{ {field_names} }} = self;", - 1, - ) - self.emit( - """ - let instance = Py::::as_ref(&cache.0, py).call1(( - """, - 1, - ) - for field in cons.fields: - if field.type == "constant": - self.emit( - f"constant_to_object({rust_field(field.name)}, py),", - 3, - ) - continue - if field.type == "int": - if field.name == "level": - assert field.opt - self.emit( - f"{rust_field(field.name)}.map_or_else(|| py.None(), |level| level.to_u32().to_object(py)),", - 3, - ) - continue - if field.name == "lineno": - self.emit( - f"{rust_field(field.name)}.to_u32().to_object(py),", - 3, - ) - continue - self.emit( - f"{rust_field(field.name)}.to_py_ast(py)?,", - 3, - ) - self.emit( - "))?;", - 0, - ) - else: - self.emit( - "let Self { range: _range } = self;", - 1, - ) - self.emit( - """let instance = Py::::as_ref(&cache.0, py).call0()?;""", - 1, - ) - if type.value.attributes and self.namespace == "located": - self.emit( - """ - let cache = ast_cache(); - instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?; - instance.setattr(cache.col_offset.as_ref(py), _range.start.column.get())?; - if let Some(end) = _range.end { - instance.setattr(cache.end_lineno.as_ref(py), end.row.get())?; - instance.setattr(cache.end_col_offset.as_ref(py), end.column.get())?; - } - """, - 0, - ) - self.emit( - """ - Ok(instance) - } - } - """, - 0, - ) - - -class Pyo3StructVisitor(EmitVisitor): - """Visitor to generate type-defs for AST.""" - - def __init__(self, namespace, *args, **kw): - self.namespace = namespace - self.borrow = True - super().__init__(*args, **kw) - - @property - def generics(self): - if self.namespace == "ranged": - return "" - elif self.namespace == "located": - return "" - else: - assert False, self.namespace - - @property - def module_name(self): - name = f"rustpython_ast.{self.namespace}" - return name - - @property - def ref_def(self): - return "&'static " if self.borrow else "" - - @property - def ref(self): - return "&" if self.borrow else "" - - def emit_class(self, info, simple, base="super::Ast"): - inner_name = info.full_type_name - rust_name = self.type_info[info.custom.name].full_type_name - if simple: - generics = "" - else: - generics = self.generics - if info.is_sum: - subclass = ", subclass" - body = "" - into = f"{rust_name}" - else: - subclass = "" - body = f"(pub {self.ref_def} ast::{inner_name}{generics})" - into = f"{rust_name}(node)" - - self.emit( - f""" - #[pyclass(module="{self.module_name}", name="_{info.name}", extends={base}, frozen{subclass})] - #[derive(Clone, Debug)] - pub struct {rust_name} {body}; - - impl From<{self.ref_def} ast::{inner_name}{generics}> for {rust_name} {{ - fn from({"" if body else "_"}node: {self.ref_def} ast::{inner_name}{generics}) -> Self {{ - {into} - }} - }} - """, - 0, - ) - - if subclass: - self.emit( - f""" - #[pymethods] - impl {rust_name} {{ - #[new] - fn new() -> PyClassInitializer {{ - PyClassInitializer::from(Ast) - .add_subclass(Self) - }} - - }} - impl ToPyObject for {rust_name} {{ - fn to_object(&self, py: Python) -> PyObject {{ - let initializer = Self::new(); - Py::new(py, initializer).unwrap().into_py(py) - }} - }} - """, - 0, - ) - else: - if base != "super::Ast": - add_subclass = f".add_subclass({base})" - else: - add_subclass = "" - self.emit( - f""" - impl ToPyObject for {rust_name} {{ - fn to_object(&self, py: Python) -> PyObject {{ - let initializer = PyClassInitializer::from(Ast) - {add_subclass} - .add_subclass(self.clone()); - Py::new(py, initializer).unwrap().into_py(py) - }} - }} - """, - 0, - ) - - if not subclass: - self.emit_wrapper(info) - - def emit_getter(self, owner, type_name): - self.emit( - f""" - #[pymethods] - impl {type_name} {{ - """, - 0, - ) - - for field in owner.fields: - self.emit( - f""" - #[getter] - #[inline] - fn get_{field.name}(&self, py: Python) -> PyResult {{ - self.0.{rust_field(field.name)}.to_py_wrapper(py) - }} - """, - 3, - ) - - self.emit( - """ - } - """, - 0, - ) - - def emit_getattr(self, owner, type_name): - self.emit( - f""" - #[pymethods] - impl {type_name} {{ - fn __getattr__(&self, py: Python, key: &str) -> PyResult {{ - let object: Py = match key {{ - """, - 0, - ) - - for field in owner.fields: - self.emit( - f'"{field.name}" => self.0.{rust_field(field.name)}.to_py_wrapper(py)?,', - 3, - ) - - self.emit( - """ - _ => todo!(), - }; - Ok(object) - } - } - """, - 0, - ) - - def emit_wrapper(self, info): - inner_name = info.full_type_name - rust_name = self.type_info[info.custom.name].full_type_name - self.emit( - f""" - impl ToPyWrapper for ast::{inner_name}{self.generics} {{ - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> {{ - Ok({rust_name}(self).to_object(py)) - }} - }} - """, - 0, - ) - - def visitModule(self, mod): - for dfn in mod.dfns: - self.visit(dfn) - - def visitType(self, type, depth=0): - self.visit(type.value, type, depth) - - def visitSum(self, sum, type, depth=0): - info = self.type_info[type.name] - rust_name = rust_type_name(type.name) - - simple = is_simple(sum) - self.emit_class(info, simple) - - if not simple: - self.emit( - f""" - impl ToPyWrapper for ast::{rust_name}{self.generics} {{ - #[inline] - fn to_py_wrapper(&'static self, py: Python) -> PyResult> {{ - match &self {{ - """, - 0, - ) - - for cons in sum.types: - self.emit(f"Self::{cons.name}(cons) => cons.to_py_wrapper(py),", 3) - - self.emit( - """ - } - } - } - """, - 0, - ) - - for cons in sum.types: - self.visit(cons, rust_name, simple, depth + 1) - - def visitProduct(self, product, type, depth=0): - info = self.type_info[type.name] - rust_name = rust_type_name(type.name) - self.emit_class(info, False) - if self.borrow: - self.emit_getter(product, rust_name) - - def visitConstructor(self, cons, parent, simple, depth): - if simple: - self.emit( - f""" - #[pyclass(module="{self.module_name}", name="_{cons.name}", extends={parent})] - pub struct {parent}{cons.name}; - - impl ToPyObject for {parent}{cons.name} {{ - fn to_object(&self, py: Python) -> PyObject {{ - let initializer = PyClassInitializer::from(Ast) - .add_subclass({parent}) - .add_subclass(Self); - Py::new(py, initializer).unwrap().into_py(py) - }} - }} - """, - depth, - ) - else: - info = self.type_info[cons.name] - self.emit_class( - info, - simple=False, - base=parent, - ) - if self.borrow: - self.emit_getter(cons, f"{parent}{cons.name}") - - -class Pyo3PymoduleVisitor(EmitVisitor): - def __init__(self, namespace, *args, **kw): - self.namespace = namespace - super().__init__(*args, **kw) - - def visitModule(self, mod): - for dfn in mod.dfns: - self.visit(dfn) - - def visitType(self, type, depth=0): - self.visit(type.value, type.name, depth) - - def visitProduct(self, product, name, depth=0): - info = self.type_info[name] - self.emit_fields(info, False) - - def visitSum(self, sum, name, depth): - info = self.type_info[name] - simple = is_simple(sum) - self.emit_fields(info, True) - - for cons in sum.types: - self.visit(cons, name, simple, depth) - - def visitConstructor(self, cons, parent, simple, depth): - info = self.type_info[cons.name] - self.emit_fields(info, simple) - - def emit_fields(self, info, simple): - inner_name = info.full_type_name - rust_name = self.type_info[info.custom.name].full_type_name - self.emit(f"super::init_type::<{rust_name}, ast::{inner_name}>(py, m)?;", 1) - - -class StdlibClassDefVisitor(EmitVisitor): - def visitModule(self, mod): - for dfn in mod.dfns: - self.visit(dfn) - - def visitType(self, type, depth=0): - self.visit(type.value, type.name, depth) - - def visitSum(self, sum, name, depth): - # info = self.type_info[self.type_info[name].custom.name] - info = self.type_info[name] - struct_name = "Node" + info.full_type_name - self.emit( - f'#[pyclass(module = "_ast", name = {json.dumps(name)}, base = "NodeAst")]', - depth, - ) - self.emit(f"struct {struct_name};", depth) - self.emit("#[pyclass(flags(HAS_DICT, BASETYPE))]", depth) - self.emit(f"impl {struct_name} {{}}", depth) - for cons in sum.types: - self.visit(cons, sum.attributes, struct_name, depth) - - def visitConstructor(self, cons, attrs, base, depth): - self.gen_class_def(cons.name, cons.fields, attrs, depth, base) - - def visitProduct(self, product, name, depth): - self.gen_class_def(name, product.fields, product.attributes, depth) - - def gen_class_def(self, name, fields, attrs, depth, base=None): - - info = self.type_info[self.type_info[name].custom.name] - if base is None: - base = "NodeAst" - struct_name = "Node" + info.full_type_name - else: - struct_name = "Node" + info.full_type_name - self.emit( - f'#[pyclass(module = "_ast", name = {json.dumps(name)}, base = {json.dumps(base)})]', - depth, - ) - self.emit(f"struct {struct_name};", depth) - self.emit("#[pyclass(flags(HAS_DICT, BASETYPE))]", depth) - self.emit(f"impl {struct_name} {{", depth) - self.emit("#[extend_class]", depth + 1) - self.emit( - "fn extend_class_with_fields(ctx: &Context, class: &'static Py) {", - depth + 1, - ) - fields = ",".join( - f"ctx.new_str(ascii!({json.dumps(f.name)})).into()" for f in fields - ) - self.emit( - f"class.set_attr(identifier!(ctx, _fields), ctx.new_tuple(vec![{fields}]).into());", - depth + 2, - ) - attrs = ",".join( - f"ctx.new_str(ascii!({json.dumps(attr.name)})).into()" for attr in attrs - ) - self.emit( - f"class.set_attr(identifier!(ctx, _attributes), ctx.new_list(vec![{attrs}]).into());", - depth + 2, - ) - self.emit("}", depth + 1) - self.emit("}", depth) - - -class StdlibExtendModuleVisitor(EmitVisitor): - def visitModule(self, mod): - depth = 0 - self.emit( - "pub fn extend_module_nodes(vm: &VirtualMachine, module: &Py) {", - depth, - ) - self.emit("extend_module!(vm, module, {", depth + 1) - for dfn in mod.dfns: - self.visit(dfn, depth + 2) - self.emit("})", depth + 1) - self.emit("}", depth) - - def visitType(self, type, depth): - self.visit(type.value, type.name, depth) - - def visitSum(self, sum, name, depth): - rust_name = rust_type_name(name) - self.emit(f"{json.dumps(name)} => Node{rust_name}::make_class(&vm.ctx),", depth) - for cons in sum.types: - self.visit(cons, depth, rust_name) - - def visitConstructor(self, cons, depth, rust_name): - self.gen_extension(cons.name, depth, rust_name) - - def visitProduct(self, product, name, depth): - self.gen_extension(name, depth) - - def gen_extension(self, name, depth, base=""): - rust_name = rust_type_name(name) - self.emit( - f"{json.dumps(name)} => Node{base}{rust_name}::make_class(&vm.ctx),", depth - ) - - -class StdlibTraitImplVisitor(EmitVisitor): - def visitModule(self, mod): - for dfn in mod.dfns: - self.visit(dfn) - - def visitType(self, type, depth=0): - self.visit(type.value, type.name, depth) - - def visitSum(self, sum, name, depth): - info = self.type_info[name] - rust_name = info.full_type_name - - self.emit("// sum", depth) - self.emit(f"impl Node for ast::located::{rust_name} {{", depth) - self.emit( - "fn ast_to_object(self, vm: &VirtualMachine) -> PyObjectRef {", depth + 1 - ) - simple = is_simple(sum) - if simple: - self.emit("let node_type = match self {", depth + 2) - for cons in sum.types: - self.emit( - f"ast::located::{rust_name}::{cons.name} => Node{rust_name}{cons.name}::static_type(),", - depth, - ) - self.emit("};", depth + 3) - self.emit( - "NodeAst.into_ref_with_type(vm, node_type.to_owned()).unwrap().into()", - depth + 2, - ) - else: - self.emit("match self {", depth + 2) - for cons in sum.types: - self.emit( - f"ast::located::{rust_name}::{cons.name}(cons) => cons.ast_to_object(vm),", - depth + 3, - ) - self.emit("}", depth + 2) - - self.emit("}", depth + 1) - self.emit( - "fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult {", - depth + 1, - ) - self.gen_sum_from_object(sum, name, rust_name, depth + 2) - self.emit("}", depth + 1) - self.emit("}", depth) - - if not is_simple(sum): - for cons in sum.types: - self.visit(cons, sum, rust_name, depth) - - def visitConstructor(self, cons, sum, sum_rust_name, depth): - rust_name = rust_type_name(cons.name) - self.emit("// constructor", depth) - self.emit(f"impl Node for ast::located::{sum_rust_name}{rust_name} {{", depth) - - fields_pattern = self.make_pattern(cons.fields) - - self.emit( - "fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef {", depth + 1 - ) - self.emit( - f"let ast::located::{sum_rust_name}{rust_name} {{ {fields_pattern} }} = self;", - depth, - ) - self.make_node(cons.name, sum, cons.fields, depth + 2, sum_rust_name) - - self.emit("}", depth + 1) - - self.emit( - "fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult {", - depth + 1, - ) - - self.gen_product_from_object( - cons, cons.name, f"{sum_rust_name}{rust_name}", sum.attributes, depth + 2 - ) - self.emit("}", depth + 1) - - self.emit("}", depth + 1) - - def visitProduct(self, product, name, depth): - info = self.type_info[name] - struct_name = info.full_type_name - - self.emit("// product", depth) - self.emit(f"impl Node for ast::located::{struct_name} {{", depth) - self.emit( - "fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef {", depth + 1 - ) - fields_pattern = self.make_pattern(product.fields) - self.emit( - f"let ast::located::{struct_name} {{ {fields_pattern} }} = self;", - depth + 2, - ) - self.make_node(name, product, product.fields, depth + 2) - self.emit("}", depth + 1) - self.emit( - "fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult {", - depth + 1, - ) - self.gen_product_from_object( - product, name, struct_name, product.attributes, depth + 2 - ) - self.emit("}", depth + 1) - self.emit("}", depth) - - def make_node(self, variant, owner, fields, depth, base=""): - rust_variant = rust_type_name(variant) - self.emit( - f"let node = NodeAst.into_ref_with_type(_vm, Node{base}{rust_variant}::static_type().to_owned()).unwrap();", - depth, - ) - if fields or owner.attributes: - self.emit("let dict = node.as_object().dict().unwrap();", depth) - for f in fields: - self.emit( - f"dict.set_item({json.dumps(f.name)}, {rust_field(f.name)}.ast_to_object(_vm), _vm).unwrap();", - depth, - ) - if owner.attributes: - self.emit("node_add_location(&dict, _range, _vm);", depth) - self.emit("node.into()", depth) - - def make_pattern(self, fields): - return "".join(f"{rust_field(f.name)}," for f in fields) + "range: _range" - - def gen_sum_from_object(self, sum, sum_name, rust_name, depth): - # if sum.attributes: - # self.extract_location(sum_name, depth) - - self.emit("let _cls = _object.class();", depth) - self.emit("Ok(", depth) - for cons in sum.types: - self.emit( - f"if _cls.is(Node{rust_name}{cons.name}::static_type()) {{", depth - ) - self.emit(f"ast::located::{rust_name}::{cons.name}", depth + 1) - if not is_simple(sum): - self.emit( - f"(ast::located::{rust_name}{cons.name}::ast_from_object(_vm, _object)?)", - depth + 1, - ) - self.emit("} else", depth) - - self.emit("{", depth) - msg = f'format!("expected some sort of {sum_name}, but got {{}}",_object.repr(_vm)?)' - self.emit(f"return Err(_vm.new_type_error({msg}));", depth + 1) - self.emit("})", depth) - - def gen_product_from_object( - self, product, product_name, struct_name, has_attributes, depth - ): - self.emit("Ok(", depth) - self.gen_construction( - struct_name, product, product_name, has_attributes, depth + 1 - ) - self.emit(")", depth) - - def gen_construction_fields(self, cons, name, depth): - for field in cons.fields: - self.emit( - f"{rust_field(field.name)}: {self.decode_field(field, name)},", - depth + 1, - ) - - def gen_construction(self, cons_path, cons, name, attributes, depth): - self.emit(f"ast::located::{cons_path} {{", depth) - self.gen_construction_fields(cons, name, depth + 1) - if attributes: - self.emit(f'range: range_from_object(_vm, _object, "{name}")?,', depth + 1) - else: - self.emit("range: Default::default(),", depth + 1) - self.emit("}", depth) - - def extract_location(self, typename, depth): - row = self.decode_field(asdl.Field("int", "lineno"), typename) - column = self.decode_field(asdl.Field("int", "col_offset"), typename) - self.emit( - f""" - let _location = {{ - let row = {row}; - let column = {column}; - try_location(row, column) - }}; - """, - depth, - ) - - def decode_field(self, field, typename): - name = json.dumps(field.name) - if field.opt and not field.seq: - return f"get_node_field_opt(_vm, &_object, {name})?.map(|obj| Node::ast_from_object(_vm, obj)).transpose()?" - else: - return f"Node::ast_from_object(_vm, get_node_field(_vm, &_object, {name}, {json.dumps(typename)})?)?" - - -class ChainOfVisitors: - def __init__(self, *visitors): - self.visitors = visitors - - def visit(self, object): - for v in self.visitors: - v.visit(object) - v.emit("", 0) - - -def write_ast_def(mod, type_info, f): - f.write("use crate::text_size::TextRange;") - StructVisitor(f, type_info).visit(mod) - - -def write_fold_def(mod, type_info, f): - FoldModuleVisitor(f, type_info).visit(mod) - - -def write_visitor_def(mod, type_info, f): - VisitorModuleVisitor(f, type_info).visit(mod) - - -def write_ranged_def(mod, type_info, f): - RangedDefVisitor(f, type_info).visit(mod) - - -def write_located_def(mod, type_info, f): - LocatedDefVisitor(f, type_info).visit(mod) - - -def write_pyo3_node(type_info, f): - def write(info: TypeInfo, rust_name: str): - if info.is_simple: - generics = "" - else: - generics = "" - - f.write( - f""" - impl{generics} PyNode for ast::{rust_name}{generics} {{ - #[inline] - fn py_type_cache() -> &'static OnceCell<(Py, Py)> {{ - static PY_TYPE: OnceCell<(Py, Py)> = OnceCell::new(); - &PY_TYPE - }} - }} - """, - ) - - for type_name, info in type_info.items(): - rust_name = info.full_type_name - if info.is_custom: - if type_name != info.type.name: - rust_name = "Python" + rust_name - else: - continue - write(info, rust_name) - - -def write_to_pyo3(mod, type_info, f): - write_pyo3_node(type_info, f) - write_to_pyo3_simple(type_info, f) - - for namespace in ("ranged", "located"): - ToPyo3AstVisitor(namespace, f, type_info).visit(mod) - - f.write( - """ - fn init_types(py: Python) -> PyResult<()> { - let ast_module = PyModule::import(py, "_ast")?; - """ - ) - - for info in type_info.values(): - if info.is_custom: - continue - rust_name = info.full_type_name - f.write(f"cache_py_type::(ast_module)?;\n") - f.write("Ok(())\n}") - - -def write_to_pyo3_simple(type_info, f): - for type_info in type_info.values(): - if not type_info.is_sum: - continue - if not type_info.is_simple: - continue - - rust_name = type_info.full_type_name - f.write( - f""" - impl ToPyAst for ast::{rust_name} {{ - #[inline] - fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {{ - let cell = match &self {{ - """, - ) - for cons in type_info.type.value.types: - f.write( - f"""ast::{rust_name}::{cons.name} => ast::{rust_name}{cons.name}::py_type_cache(),""", - ) - f.write( - """ - }; - Ok(Py::::as_ref(&cell.get().unwrap().1, py)) - } - } - """, - ) - - -def write_pyo3_wrapper(mod, type_info, namespace, f): - Pyo3StructVisitor(namespace, f, type_info).visit(mod) - - if namespace == "located": - for info in type_info.values(): - if not info.is_simple or not info.is_sum: - continue - - rust_name = info.full_type_name - inner_name = type_info[info.custom.name].full_type_name - f.write( - f""" - impl ToPyWrapper for ast::{inner_name} {{ - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> {{ - match &self {{ - """, - ) - for cons in info.type.value.types: - f.write( - f"Self::{cons.name} => Ok({rust_name}{cons.name}.to_object(py)),", - ) - f.write( - """ - } - } - } - """, - ) - - for cons in info.type.value.types: - f.write( - f""" - impl ToPyWrapper for ast::{rust_name}{cons.name} {{ - #[inline] - fn to_py_wrapper(&self, py: Python) -> PyResult> {{ - Ok({rust_name}{cons.name}.to_object(py)) - }} - }} - """ - ) - - f.write( - """ - pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> { - super::init_module(py, m)?; - """ - ) - - Pyo3PymoduleVisitor(namespace, f, type_info).visit(mod) - f.write("Ok(())\n}") - - -def write_parse_def(mod, type_info, f): - for info in type_info.values(): - if info.enum_name not in ["expr", "stmt"]: - continue - - type_name = rust_type_name(info.enum_name) - cons_name = rust_type_name(info.name) - - f.write(f""" - impl Parse for ast::{info.full_type_name} {{ - fn lex_starts_at( - source: &str, - offset: TextSize, - ) -> SoftKeywordTransformer> {{ - ast::{type_name}::lex_starts_at(source, offset) - }} - fn parse_tokens( - lxr: impl IntoIterator, - source_path: &str, - ) -> Result {{ - let node = ast::{type_name}::parse_tokens(lxr, source_path)?; - match node {{ - ast::{type_name}::{cons_name}(node) => Ok(node), - node => Err(ParseError {{ - error: ParseErrorType::InvalidToken, - offset: node.range().start(), - source_path: source_path.to_owned(), - }}), - }} - }} - }} - """) - - -def write_ast_mod(mod, type_info, f): - f.write( - """ - #![allow(clippy::all)] - - use super::*; - use crate::common::ascii; - """ - ) - - c = ChainOfVisitors( - StdlibClassDefVisitor(f, type_info), - StdlibTraitImplVisitor(f, type_info), - StdlibExtendModuleVisitor(f, type_info), - ) - c.visit(mod) - - -def main( - input_filename, - ast_dir, - parser_dir, - ast_pyo3_dir, - module_filename, - dump_module=False, -): - auto_gen_msg = AUTO_GEN_MESSAGE.format("/".join(Path(__file__).parts[-2:])) - mod = asdl.parse(input_filename) - if dump_module: - print("Parsed Module:") - print(mod) - if not asdl.check(mod): - sys.exit(1) - - type_info = {} - FindUserDataTypesVisitor(type_info).visit(mod) - - from functools import partial as p + from functools import partial as p for filename, write in [ ("generic", p(write_ast_def, mod, type_info)), - ("fold", p(write_fold_def, mod, type_info)), ("ranged", p(write_ranged_def, mod, type_info)), - ("located", p(write_located_def, mod, type_info)), - ("visitor", p(write_visitor_def, mod, type_info)), ]: with (ast_dir / f"{filename}.rs").open("w") as f: f.write(auto_gen_msg) @@ -2195,21 +812,7 @@ def main( f.write(auto_gen_msg) write(f) - - for filename, write in [ - ("to_py_ast", p(write_to_pyo3, mod, type_info)), - ("wrapper_located", p(write_pyo3_wrapper, mod, type_info, "located")), - ("wrapper_ranged", p(write_pyo3_wrapper, mod, type_info, "ranged")), - ]: - with (ast_pyo3_dir / f"{filename}.rs").open("w") as f: - f.write(auto_gen_msg) - write(f) - - with module_filename.open("w") as module_file: - module_file.write(auto_gen_msg) - write_ast_mod(mod, type_info, module_file) - - print(f"{ast_dir}, {module_filename} regenerated.") + print(f"{ast_dir} regenerated.") if __name__ == "__main__": @@ -2217,8 +820,6 @@ def main( parser.add_argument("input_file", type=Path) parser.add_argument("-A", "--ast-dir", type=Path, required=True) parser.add_argument("-P", "--parser-dir", type=Path, required=True) - parser.add_argument("-O", "--ast-pyo3-dir", type=Path, required=True) - parser.add_argument("-M", "--module-file", type=Path, required=True) parser.add_argument("-d", "--dump-module", action="store_true") args = parser.parse_args() @@ -2226,7 +827,5 @@ def main( args.input_file, args.ast_dir, args.parser_dir, - args.ast_pyo3_dir, - args.module_file, args.dump_module, ) diff --git a/ast/src/fold.rs b/ast/src/fold.rs deleted file mode 100644 index ccbcc7bcc741d..0000000000000 --- a/ast/src/fold.rs +++ /dev/null @@ -1,76 +0,0 @@ -use super::generic::*; - -use crate::{builtin, ConversionFlag}; - -pub trait Foldable { - type Mapped; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result; -} - -impl Foldable for Vec -where - X: Foldable, -{ - type Mapped = Vec; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - self.into_iter().map(|x| x.fold(folder)).collect() - } -} - -impl Foldable for Option -where - X: Foldable, -{ - type Mapped = Option; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - self.map(|x| x.fold(folder)).transpose() - } -} - -impl Foldable for Box -where - X: Foldable, -{ - type Mapped = Box; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - (*self).fold(folder).map(Box::new) - } -} - -macro_rules! simple_fold { - ($($t:ty),+$(,)?) => { - $(impl $crate::fold::Foldable for $t { - type Mapped = Self; - #[inline] - fn fold + ?Sized>( - self, - _folder: &mut F, - ) -> Result { - Ok(self) - } - })+ - }; -} - -simple_fold!( - builtin::Int, - builtin::String, - builtin::Identifier, - bool, - ConversionFlag, - builtin::Constant -); - -include!("gen/fold.rs"); diff --git a/ast/src/gen/fold.rs b/ast/src/gen/fold.rs deleted file mode 100644 index 08e64594736d7..0000000000000 --- a/ast/src/gen/fold.rs +++ /dev/null @@ -1,2846 +0,0 @@ -// File automatically generated by ast/asdl_rs.py. - -pub trait Fold { - type TargetU; - type Error; - type UserContext; - - fn will_map_user(&mut self, user: &U) -> Self::UserContext; - #[cfg(feature = "all-nodes-with-ranges")] - fn will_map_user_cfg(&mut self, user: &U) -> Self::UserContext { - self.will_map_user(user) - } - #[cfg(not(feature = "all-nodes-with-ranges"))] - fn will_map_user_cfg( - &mut self, - _user: &crate::EmptyRange, - ) -> crate::EmptyRange { - crate::EmptyRange::default() - } - fn map_user( - &mut self, - user: U, - context: Self::UserContext, - ) -> Result; - #[cfg(feature = "all-nodes-with-ranges")] - fn map_user_cfg( - &mut self, - user: U, - context: Self::UserContext, - ) -> Result { - self.map_user(user, context) - } - #[cfg(not(feature = "all-nodes-with-ranges"))] - fn map_user_cfg( - &mut self, - _user: crate::EmptyRange, - _context: crate::EmptyRange, - ) -> Result, Self::Error> { - Ok(crate::EmptyRange::default()) - } - - fn fold>(&mut self, node: X) -> Result { - node.fold(self) - } - fn fold_mod(&mut self, node: Mod) -> Result, Self::Error> { - fold_mod(self, node) - } - fn fold_mod_module( - &mut self, - node: ModModule, - ) -> Result, Self::Error> { - fold_mod_module(self, node) - } - fn fold_mod_interactive( - &mut self, - node: ModInteractive, - ) -> Result, Self::Error> { - fold_mod_interactive(self, node) - } - fn fold_mod_expression( - &mut self, - node: ModExpression, - ) -> Result, Self::Error> { - fold_mod_expression(self, node) - } - fn fold_mod_function_type( - &mut self, - node: ModFunctionType, - ) -> Result, Self::Error> { - fold_mod_function_type(self, node) - } - fn fold_stmt(&mut self, node: Stmt) -> Result, Self::Error> { - fold_stmt(self, node) - } - fn fold_stmt_function_def( - &mut self, - node: StmtFunctionDef, - ) -> Result, Self::Error> { - fold_stmt_function_def(self, node) - } - fn fold_stmt_async_function_def( - &mut self, - node: StmtAsyncFunctionDef, - ) -> Result, Self::Error> { - fold_stmt_async_function_def(self, node) - } - fn fold_stmt_class_def( - &mut self, - node: StmtClassDef, - ) -> Result, Self::Error> { - fold_stmt_class_def(self, node) - } - fn fold_stmt_return( - &mut self, - node: StmtReturn, - ) -> Result, Self::Error> { - fold_stmt_return(self, node) - } - fn fold_stmt_delete( - &mut self, - node: StmtDelete, - ) -> Result, Self::Error> { - fold_stmt_delete(self, node) - } - fn fold_stmt_assign( - &mut self, - node: StmtAssign, - ) -> Result, Self::Error> { - fold_stmt_assign(self, node) - } - fn fold_stmt_aug_assign( - &mut self, - node: StmtAugAssign, - ) -> Result, Self::Error> { - fold_stmt_aug_assign(self, node) - } - fn fold_stmt_ann_assign( - &mut self, - node: StmtAnnAssign, - ) -> Result, Self::Error> { - fold_stmt_ann_assign(self, node) - } - fn fold_stmt_for(&mut self, node: StmtFor) -> Result, Self::Error> { - fold_stmt_for(self, node) - } - fn fold_stmt_async_for( - &mut self, - node: StmtAsyncFor, - ) -> Result, Self::Error> { - fold_stmt_async_for(self, node) - } - fn fold_stmt_while( - &mut self, - node: StmtWhile, - ) -> Result, Self::Error> { - fold_stmt_while(self, node) - } - fn fold_stmt_if(&mut self, node: StmtIf) -> Result, Self::Error> { - fold_stmt_if(self, node) - } - fn fold_stmt_with( - &mut self, - node: StmtWith, - ) -> Result, Self::Error> { - fold_stmt_with(self, node) - } - fn fold_stmt_async_with( - &mut self, - node: StmtAsyncWith, - ) -> Result, Self::Error> { - fold_stmt_async_with(self, node) - } - fn fold_stmt_match( - &mut self, - node: StmtMatch, - ) -> Result, Self::Error> { - fold_stmt_match(self, node) - } - fn fold_stmt_raise( - &mut self, - node: StmtRaise, - ) -> Result, Self::Error> { - fold_stmt_raise(self, node) - } - fn fold_stmt_try(&mut self, node: StmtTry) -> Result, Self::Error> { - fold_stmt_try(self, node) - } - fn fold_stmt_try_star( - &mut self, - node: StmtTryStar, - ) -> Result, Self::Error> { - fold_stmt_try_star(self, node) - } - fn fold_stmt_assert( - &mut self, - node: StmtAssert, - ) -> Result, Self::Error> { - fold_stmt_assert(self, node) - } - fn fold_stmt_import( - &mut self, - node: StmtImport, - ) -> Result, Self::Error> { - fold_stmt_import(self, node) - } - fn fold_stmt_import_from( - &mut self, - node: StmtImportFrom, - ) -> Result, Self::Error> { - fold_stmt_import_from(self, node) - } - fn fold_stmt_global( - &mut self, - node: StmtGlobal, - ) -> Result, Self::Error> { - fold_stmt_global(self, node) - } - fn fold_stmt_nonlocal( - &mut self, - node: StmtNonlocal, - ) -> Result, Self::Error> { - fold_stmt_nonlocal(self, node) - } - fn fold_stmt_expr( - &mut self, - node: StmtExpr, - ) -> Result, Self::Error> { - fold_stmt_expr(self, node) - } - fn fold_stmt_pass( - &mut self, - node: StmtPass, - ) -> Result, Self::Error> { - fold_stmt_pass(self, node) - } - fn fold_stmt_break( - &mut self, - node: StmtBreak, - ) -> Result, Self::Error> { - fold_stmt_break(self, node) - } - fn fold_stmt_continue( - &mut self, - node: StmtContinue, - ) -> Result, Self::Error> { - fold_stmt_continue(self, node) - } - fn fold_expr(&mut self, node: Expr) -> Result, Self::Error> { - fold_expr(self, node) - } - fn fold_expr_bool_op( - &mut self, - node: ExprBoolOp, - ) -> Result, Self::Error> { - fold_expr_bool_op(self, node) - } - fn fold_expr_named_expr( - &mut self, - node: ExprNamedExpr, - ) -> Result, Self::Error> { - fold_expr_named_expr(self, node) - } - fn fold_expr_bin_op( - &mut self, - node: ExprBinOp, - ) -> Result, Self::Error> { - fold_expr_bin_op(self, node) - } - fn fold_expr_unary_op( - &mut self, - node: ExprUnaryOp, - ) -> Result, Self::Error> { - fold_expr_unary_op(self, node) - } - fn fold_expr_lambda( - &mut self, - node: ExprLambda, - ) -> Result, Self::Error> { - fold_expr_lambda(self, node) - } - fn fold_expr_if_exp( - &mut self, - node: ExprIfExp, - ) -> Result, Self::Error> { - fold_expr_if_exp(self, node) - } - fn fold_expr_dict( - &mut self, - node: ExprDict, - ) -> Result, Self::Error> { - fold_expr_dict(self, node) - } - fn fold_expr_set(&mut self, node: ExprSet) -> Result, Self::Error> { - fold_expr_set(self, node) - } - fn fold_expr_list_comp( - &mut self, - node: ExprListComp, - ) -> Result, Self::Error> { - fold_expr_list_comp(self, node) - } - fn fold_expr_set_comp( - &mut self, - node: ExprSetComp, - ) -> Result, Self::Error> { - fold_expr_set_comp(self, node) - } - fn fold_expr_dict_comp( - &mut self, - node: ExprDictComp, - ) -> Result, Self::Error> { - fold_expr_dict_comp(self, node) - } - fn fold_expr_generator_exp( - &mut self, - node: ExprGeneratorExp, - ) -> Result, Self::Error> { - fold_expr_generator_exp(self, node) - } - fn fold_expr_await( - &mut self, - node: ExprAwait, - ) -> Result, Self::Error> { - fold_expr_await(self, node) - } - fn fold_expr_yield( - &mut self, - node: ExprYield, - ) -> Result, Self::Error> { - fold_expr_yield(self, node) - } - fn fold_expr_yield_from( - &mut self, - node: ExprYieldFrom, - ) -> Result, Self::Error> { - fold_expr_yield_from(self, node) - } - fn fold_expr_compare( - &mut self, - node: ExprCompare, - ) -> Result, Self::Error> { - fold_expr_compare(self, node) - } - fn fold_expr_call( - &mut self, - node: ExprCall, - ) -> Result, Self::Error> { - fold_expr_call(self, node) - } - fn fold_expr_formatted_value( - &mut self, - node: ExprFormattedValue, - ) -> Result, Self::Error> { - fold_expr_formatted_value(self, node) - } - fn fold_expr_joined_str( - &mut self, - node: ExprJoinedStr, - ) -> Result, Self::Error> { - fold_expr_joined_str(self, node) - } - fn fold_expr_constant( - &mut self, - node: ExprConstant, - ) -> Result, Self::Error> { - fold_expr_constant(self, node) - } - fn fold_expr_attribute( - &mut self, - node: ExprAttribute, - ) -> Result, Self::Error> { - fold_expr_attribute(self, node) - } - fn fold_expr_subscript( - &mut self, - node: ExprSubscript, - ) -> Result, Self::Error> { - fold_expr_subscript(self, node) - } - fn fold_expr_starred( - &mut self, - node: ExprStarred, - ) -> Result, Self::Error> { - fold_expr_starred(self, node) - } - fn fold_expr_name( - &mut self, - node: ExprName, - ) -> Result, Self::Error> { - fold_expr_name(self, node) - } - fn fold_expr_list( - &mut self, - node: ExprList, - ) -> Result, Self::Error> { - fold_expr_list(self, node) - } - fn fold_expr_tuple( - &mut self, - node: ExprTuple, - ) -> Result, Self::Error> { - fold_expr_tuple(self, node) - } - fn fold_expr_slice( - &mut self, - node: ExprSlice, - ) -> Result, Self::Error> { - fold_expr_slice(self, node) - } - fn fold_expr_context(&mut self, node: ExprContext) -> Result { - fold_expr_context(self, node) - } - fn fold_boolop(&mut self, node: BoolOp) -> Result { - fold_boolop(self, node) - } - fn fold_operator(&mut self, node: Operator) -> Result { - fold_operator(self, node) - } - fn fold_unaryop(&mut self, node: UnaryOp) -> Result { - fold_unaryop(self, node) - } - fn fold_cmpop(&mut self, node: CmpOp) -> Result { - fold_cmpop(self, node) - } - fn fold_comprehension( - &mut self, - node: Comprehension, - ) -> Result, Self::Error> { - fold_comprehension(self, node) - } - fn fold_excepthandler( - &mut self, - node: ExceptHandler, - ) -> Result, Self::Error> { - fold_excepthandler(self, node) - } - fn fold_excepthandler_except_handler( - &mut self, - node: ExceptHandlerExceptHandler, - ) -> Result, Self::Error> { - fold_excepthandler_except_handler(self, node) - } - fn fold_arguments( - &mut self, - node: Arguments, - ) -> Result, Self::Error> { - fold_arguments(self, node) - } - fn fold_arg(&mut self, node: Arg) -> Result, Self::Error> { - fold_arg(self, node) - } - fn fold_keyword(&mut self, node: Keyword) -> Result, Self::Error> { - fold_keyword(self, node) - } - fn fold_alias(&mut self, node: Alias) -> Result, Self::Error> { - fold_alias(self, node) - } - fn fold_withitem(&mut self, node: WithItem) -> Result, Self::Error> { - fold_withitem(self, node) - } - fn fold_match_case( - &mut self, - node: MatchCase, - ) -> Result, Self::Error> { - fold_match_case(self, node) - } - fn fold_pattern(&mut self, node: Pattern) -> Result, Self::Error> { - fold_pattern(self, node) - } - fn fold_pattern_match_value( - &mut self, - node: PatternMatchValue, - ) -> Result, Self::Error> { - fold_pattern_match_value(self, node) - } - fn fold_pattern_match_singleton( - &mut self, - node: PatternMatchSingleton, - ) -> Result, Self::Error> { - fold_pattern_match_singleton(self, node) - } - fn fold_pattern_match_sequence( - &mut self, - node: PatternMatchSequence, - ) -> Result, Self::Error> { - fold_pattern_match_sequence(self, node) - } - fn fold_pattern_match_mapping( - &mut self, - node: PatternMatchMapping, - ) -> Result, Self::Error> { - fold_pattern_match_mapping(self, node) - } - fn fold_pattern_match_class( - &mut self, - node: PatternMatchClass, - ) -> Result, Self::Error> { - fold_pattern_match_class(self, node) - } - fn fold_pattern_match_star( - &mut self, - node: PatternMatchStar, - ) -> Result, Self::Error> { - fold_pattern_match_star(self, node) - } - fn fold_pattern_match_as( - &mut self, - node: PatternMatchAs, - ) -> Result, Self::Error> { - fold_pattern_match_as(self, node) - } - fn fold_pattern_match_or( - &mut self, - node: PatternMatchOr, - ) -> Result, Self::Error> { - fold_pattern_match_or(self, node) - } - fn fold_type_ignore( - &mut self, - node: TypeIgnore, - ) -> Result, Self::Error> { - fold_type_ignore(self, node) - } - fn fold_type_ignore_type_ignore( - &mut self, - node: TypeIgnoreTypeIgnore, - ) -> Result, Self::Error> { - fold_type_ignore_type_ignore(self, node) - } - fn fold_decorator( - &mut self, - node: Decorator, - ) -> Result, Self::Error> { - fold_decorator(self, node) - } - fn fold_arg_with_default( - &mut self, - node: ArgWithDefault, - ) -> Result, Self::Error> { - fold_arg_with_default(self, node) - } -} -impl Foldable for Mod { - type Mapped = Mod; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_mod(self) - } -} -pub fn fold_mod + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Mod, -) -> Result, F::Error> { - let folded = match node { - Mod::Module(cons) => Mod::Module(Foldable::fold(cons, folder)?), - Mod::Interactive(cons) => Mod::Interactive(Foldable::fold(cons, folder)?), - Mod::Expression(cons) => Mod::Expression(Foldable::fold(cons, folder)?), - Mod::FunctionType(cons) => Mod::FunctionType(Foldable::fold(cons, folder)?), - }; - Ok(folded) -} -impl Foldable for ModModule { - type Mapped = ModModule; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_mod_module(self) - } -} -pub fn fold_mod_module + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ModModule, -) -> Result, F::Error> { - let ModModule { - body, - type_ignores, - range, - } = node; - let context = folder.will_map_user_cfg(&range); - - let body = Foldable::fold(body, folder)?; - let type_ignores = Foldable::fold(type_ignores, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(ModModule { - body, - type_ignores, - range, - }) -} -impl Foldable for ModInteractive { - type Mapped = ModInteractive; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_mod_interactive(self) - } -} -pub fn fold_mod_interactive + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ModInteractive, -) -> Result, F::Error> { - let ModInteractive { body, range } = node; - let context = folder.will_map_user_cfg(&range); - - let body = Foldable::fold(body, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(ModInteractive { body, range }) -} -impl Foldable for ModExpression { - type Mapped = ModExpression; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_mod_expression(self) - } -} -pub fn fold_mod_expression + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ModExpression, -) -> Result, F::Error> { - let ModExpression { body, range } = node; - let context = folder.will_map_user_cfg(&range); - - let body = Foldable::fold(body, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(ModExpression { body, range }) -} -impl Foldable for ModFunctionType { - type Mapped = ModFunctionType; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_mod_function_type(self) - } -} -pub fn fold_mod_function_type + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ModFunctionType, -) -> Result, F::Error> { - let ModFunctionType { - argtypes, - returns, - range, - } = node; - let context = folder.will_map_user_cfg(&range); - - let argtypes = Foldable::fold(argtypes, folder)?; - let returns = Foldable::fold(returns, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(ModFunctionType { - argtypes, - returns, - range, - }) -} -impl Foldable for Stmt { - type Mapped = Stmt; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt(self) - } -} -pub fn fold_stmt + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Stmt, -) -> Result, F::Error> { - let folded = match node { - Stmt::FunctionDef(cons) => Stmt::FunctionDef(Foldable::fold(cons, folder)?), - Stmt::AsyncFunctionDef(cons) => Stmt::AsyncFunctionDef(Foldable::fold(cons, folder)?), - Stmt::ClassDef(cons) => Stmt::ClassDef(Foldable::fold(cons, folder)?), - Stmt::Return(cons) => Stmt::Return(Foldable::fold(cons, folder)?), - Stmt::Delete(cons) => Stmt::Delete(Foldable::fold(cons, folder)?), - Stmt::Assign(cons) => Stmt::Assign(Foldable::fold(cons, folder)?), - Stmt::AugAssign(cons) => Stmt::AugAssign(Foldable::fold(cons, folder)?), - Stmt::AnnAssign(cons) => Stmt::AnnAssign(Foldable::fold(cons, folder)?), - Stmt::For(cons) => Stmt::For(Foldable::fold(cons, folder)?), - Stmt::AsyncFor(cons) => Stmt::AsyncFor(Foldable::fold(cons, folder)?), - Stmt::While(cons) => Stmt::While(Foldable::fold(cons, folder)?), - Stmt::If(cons) => Stmt::If(Foldable::fold(cons, folder)?), - Stmt::With(cons) => Stmt::With(Foldable::fold(cons, folder)?), - Stmt::AsyncWith(cons) => Stmt::AsyncWith(Foldable::fold(cons, folder)?), - Stmt::Match(cons) => Stmt::Match(Foldable::fold(cons, folder)?), - Stmt::Raise(cons) => Stmt::Raise(Foldable::fold(cons, folder)?), - Stmt::Try(cons) => Stmt::Try(Foldable::fold(cons, folder)?), - Stmt::TryStar(cons) => Stmt::TryStar(Foldable::fold(cons, folder)?), - Stmt::Assert(cons) => Stmt::Assert(Foldable::fold(cons, folder)?), - Stmt::Import(cons) => Stmt::Import(Foldable::fold(cons, folder)?), - Stmt::ImportFrom(cons) => Stmt::ImportFrom(Foldable::fold(cons, folder)?), - Stmt::Global(cons) => Stmt::Global(Foldable::fold(cons, folder)?), - Stmt::Nonlocal(cons) => Stmt::Nonlocal(Foldable::fold(cons, folder)?), - Stmt::Expr(cons) => Stmt::Expr(Foldable::fold(cons, folder)?), - Stmt::Pass(cons) => Stmt::Pass(Foldable::fold(cons, folder)?), - Stmt::Break(cons) => Stmt::Break(Foldable::fold(cons, folder)?), - Stmt::Continue(cons) => Stmt::Continue(Foldable::fold(cons, folder)?), - }; - Ok(folded) -} -impl Foldable for StmtFunctionDef { - type Mapped = StmtFunctionDef; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_function_def(self) - } -} -pub fn fold_stmt_function_def + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtFunctionDef, -) -> Result, F::Error> { - let StmtFunctionDef { - name, - args, - body, - decorator_list, - returns, - type_comment, - range, - } = node; - let context = folder.will_map_user(&range); - - let name = Foldable::fold(name, folder)?; - let args = Foldable::fold(args, folder)?; - let body = Foldable::fold(body, folder)?; - let decorator_list = Foldable::fold(decorator_list, folder)?; - let returns = Foldable::fold(returns, folder)?; - let type_comment = Foldable::fold(type_comment, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtFunctionDef { - name, - args, - body, - decorator_list, - returns, - type_comment, - range, - }) -} -impl Foldable for StmtAsyncFunctionDef { - type Mapped = StmtAsyncFunctionDef; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_async_function_def(self) - } -} -pub fn fold_stmt_async_function_def + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtAsyncFunctionDef, -) -> Result, F::Error> { - let StmtAsyncFunctionDef { - name, - args, - body, - decorator_list, - returns, - type_comment, - range, - } = node; - let context = folder.will_map_user(&range); - - let name = Foldable::fold(name, folder)?; - let args = Foldable::fold(args, folder)?; - let body = Foldable::fold(body, folder)?; - let decorator_list = Foldable::fold(decorator_list, folder)?; - let returns = Foldable::fold(returns, folder)?; - let type_comment = Foldable::fold(type_comment, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtAsyncFunctionDef { - name, - args, - body, - decorator_list, - returns, - type_comment, - range, - }) -} -impl Foldable for StmtClassDef { - type Mapped = StmtClassDef; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_class_def(self) - } -} -pub fn fold_stmt_class_def + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtClassDef, -) -> Result, F::Error> { - let StmtClassDef { - name, - bases, - keywords, - body, - decorator_list, - range, - } = node; - let context = folder.will_map_user(&range); - - let name = Foldable::fold(name, folder)?; - let bases = Foldable::fold(bases, folder)?; - let keywords = Foldable::fold(keywords, folder)?; - let body = Foldable::fold(body, folder)?; - let decorator_list = Foldable::fold(decorator_list, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtClassDef { - name, - bases, - keywords, - body, - decorator_list, - range, - }) -} -impl Foldable for StmtReturn { - type Mapped = StmtReturn; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_return(self) - } -} -pub fn fold_stmt_return + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtReturn, -) -> Result, F::Error> { - let StmtReturn { value, range } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtReturn { value, range }) -} -impl Foldable for StmtDelete { - type Mapped = StmtDelete; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_delete(self) - } -} -pub fn fold_stmt_delete + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtDelete, -) -> Result, F::Error> { - let StmtDelete { targets, range } = node; - let context = folder.will_map_user(&range); - - let targets = Foldable::fold(targets, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtDelete { targets, range }) -} -impl Foldable for StmtAssign { - type Mapped = StmtAssign; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_assign(self) - } -} -pub fn fold_stmt_assign + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtAssign, -) -> Result, F::Error> { - let StmtAssign { - targets, - value, - type_comment, - range, - } = node; - let context = folder.will_map_user(&range); - - let targets = Foldable::fold(targets, folder)?; - let value = Foldable::fold(value, folder)?; - let type_comment = Foldable::fold(type_comment, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtAssign { - targets, - value, - type_comment, - range, - }) -} -impl Foldable for StmtAugAssign { - type Mapped = StmtAugAssign; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_aug_assign(self) - } -} -pub fn fold_stmt_aug_assign + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtAugAssign, -) -> Result, F::Error> { - let StmtAugAssign { - target, - op, - value, - range, - } = node; - let context = folder.will_map_user(&range); - - let target = Foldable::fold(target, folder)?; - let op = Foldable::fold(op, folder)?; - let value = Foldable::fold(value, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtAugAssign { - target, - op, - value, - range, - }) -} -impl Foldable for StmtAnnAssign { - type Mapped = StmtAnnAssign; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_ann_assign(self) - } -} -pub fn fold_stmt_ann_assign + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtAnnAssign, -) -> Result, F::Error> { - let StmtAnnAssign { - target, - annotation, - value, - simple, - range, - } = node; - let context = folder.will_map_user(&range); - - let target = Foldable::fold(target, folder)?; - let annotation = Foldable::fold(annotation, folder)?; - let value = Foldable::fold(value, folder)?; - let simple = Foldable::fold(simple, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtAnnAssign { - target, - annotation, - value, - simple, - range, - }) -} -impl Foldable for StmtFor { - type Mapped = StmtFor; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_for(self) - } -} -pub fn fold_stmt_for + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtFor, -) -> Result, F::Error> { - let StmtFor { - target, - iter, - body, - orelse, - type_comment, - range, - } = node; - let context = folder.will_map_user(&range); - - let target = Foldable::fold(target, folder)?; - let iter = Foldable::fold(iter, folder)?; - let body = Foldable::fold(body, folder)?; - let orelse = Foldable::fold(orelse, folder)?; - let type_comment = Foldable::fold(type_comment, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtFor { - target, - iter, - body, - orelse, - type_comment, - range, - }) -} -impl Foldable for StmtAsyncFor { - type Mapped = StmtAsyncFor; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_async_for(self) - } -} -pub fn fold_stmt_async_for + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtAsyncFor, -) -> Result, F::Error> { - let StmtAsyncFor { - target, - iter, - body, - orelse, - type_comment, - range, - } = node; - let context = folder.will_map_user(&range); - - let target = Foldable::fold(target, folder)?; - let iter = Foldable::fold(iter, folder)?; - let body = Foldable::fold(body, folder)?; - let orelse = Foldable::fold(orelse, folder)?; - let type_comment = Foldable::fold(type_comment, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtAsyncFor { - target, - iter, - body, - orelse, - type_comment, - range, - }) -} -impl Foldable for StmtWhile { - type Mapped = StmtWhile; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_while(self) - } -} -pub fn fold_stmt_while + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtWhile, -) -> Result, F::Error> { - let StmtWhile { - test, - body, - orelse, - range, - } = node; - let context = folder.will_map_user(&range); - - let test = Foldable::fold(test, folder)?; - let body = Foldable::fold(body, folder)?; - let orelse = Foldable::fold(orelse, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtWhile { - test, - body, - orelse, - range, - }) -} -impl Foldable for StmtIf { - type Mapped = StmtIf; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_if(self) - } -} -pub fn fold_stmt_if + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtIf, -) -> Result, F::Error> { - let StmtIf { - test, - body, - orelse, - range, - } = node; - let context = folder.will_map_user(&range); - - let test = Foldable::fold(test, folder)?; - let body = Foldable::fold(body, folder)?; - let orelse = Foldable::fold(orelse, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtIf { - test, - body, - orelse, - range, - }) -} -impl Foldable for StmtWith { - type Mapped = StmtWith; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_with(self) - } -} -pub fn fold_stmt_with + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtWith, -) -> Result, F::Error> { - let StmtWith { - items, - body, - type_comment, - range, - } = node; - let context = folder.will_map_user(&range); - - let items = Foldable::fold(items, folder)?; - let body = Foldable::fold(body, folder)?; - let type_comment = Foldable::fold(type_comment, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtWith { - items, - body, - type_comment, - range, - }) -} -impl Foldable for StmtAsyncWith { - type Mapped = StmtAsyncWith; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_async_with(self) - } -} -pub fn fold_stmt_async_with + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtAsyncWith, -) -> Result, F::Error> { - let StmtAsyncWith { - items, - body, - type_comment, - range, - } = node; - let context = folder.will_map_user(&range); - - let items = Foldable::fold(items, folder)?; - let body = Foldable::fold(body, folder)?; - let type_comment = Foldable::fold(type_comment, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtAsyncWith { - items, - body, - type_comment, - range, - }) -} -impl Foldable for StmtMatch { - type Mapped = StmtMatch; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_match(self) - } -} -pub fn fold_stmt_match + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtMatch, -) -> Result, F::Error> { - let StmtMatch { - subject, - cases, - range, - } = node; - let context = folder.will_map_user(&range); - - let subject = Foldable::fold(subject, folder)?; - let cases = Foldable::fold(cases, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtMatch { - subject, - cases, - range, - }) -} -impl Foldable for StmtRaise { - type Mapped = StmtRaise; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_raise(self) - } -} -pub fn fold_stmt_raise + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtRaise, -) -> Result, F::Error> { - let StmtRaise { exc, cause, range } = node; - let context = folder.will_map_user(&range); - - let exc = Foldable::fold(exc, folder)?; - let cause = Foldable::fold(cause, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtRaise { exc, cause, range }) -} -impl Foldable for StmtTry { - type Mapped = StmtTry; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_try(self) - } -} -pub fn fold_stmt_try + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtTry, -) -> Result, F::Error> { - let StmtTry { - body, - handlers, - orelse, - finalbody, - range, - } = node; - let context = folder.will_map_user(&range); - - let body = Foldable::fold(body, folder)?; - let handlers = Foldable::fold(handlers, folder)?; - let orelse = Foldable::fold(orelse, folder)?; - let finalbody = Foldable::fold(finalbody, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtTry { - body, - handlers, - orelse, - finalbody, - range, - }) -} -impl Foldable for StmtTryStar { - type Mapped = StmtTryStar; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_try_star(self) - } -} -pub fn fold_stmt_try_star + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtTryStar, -) -> Result, F::Error> { - let StmtTryStar { - body, - handlers, - orelse, - finalbody, - range, - } = node; - let context = folder.will_map_user(&range); - - let body = Foldable::fold(body, folder)?; - let handlers = Foldable::fold(handlers, folder)?; - let orelse = Foldable::fold(orelse, folder)?; - let finalbody = Foldable::fold(finalbody, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtTryStar { - body, - handlers, - orelse, - finalbody, - range, - }) -} -impl Foldable for StmtAssert { - type Mapped = StmtAssert; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_assert(self) - } -} -pub fn fold_stmt_assert + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtAssert, -) -> Result, F::Error> { - let StmtAssert { test, msg, range } = node; - let context = folder.will_map_user(&range); - - let test = Foldable::fold(test, folder)?; - let msg = Foldable::fold(msg, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtAssert { test, msg, range }) -} -impl Foldable for StmtImport { - type Mapped = StmtImport; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_import(self) - } -} -pub fn fold_stmt_import + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtImport, -) -> Result, F::Error> { - let StmtImport { names, range } = node; - let context = folder.will_map_user(&range); - - let names = Foldable::fold(names, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtImport { names, range }) -} -impl Foldable for StmtImportFrom { - type Mapped = StmtImportFrom; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_import_from(self) - } -} -pub fn fold_stmt_import_from + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtImportFrom, -) -> Result, F::Error> { - let StmtImportFrom { - module, - names, - level, - range, - } = node; - let context = folder.will_map_user(&range); - - let module = Foldable::fold(module, folder)?; - let names = Foldable::fold(names, folder)?; - let level = Foldable::fold(level, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtImportFrom { - module, - names, - level, - range, - }) -} -impl Foldable for StmtGlobal { - type Mapped = StmtGlobal; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_global(self) - } -} -pub fn fold_stmt_global + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtGlobal, -) -> Result, F::Error> { - let StmtGlobal { names, range } = node; - let context = folder.will_map_user(&range); - - let names = Foldable::fold(names, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtGlobal { names, range }) -} -impl Foldable for StmtNonlocal { - type Mapped = StmtNonlocal; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_nonlocal(self) - } -} -pub fn fold_stmt_nonlocal + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtNonlocal, -) -> Result, F::Error> { - let StmtNonlocal { names, range } = node; - let context = folder.will_map_user(&range); - - let names = Foldable::fold(names, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtNonlocal { names, range }) -} -impl Foldable for StmtExpr { - type Mapped = StmtExpr; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_expr(self) - } -} -pub fn fold_stmt_expr + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtExpr, -) -> Result, F::Error> { - let StmtExpr { value, range } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let range = folder.map_user(range, context)?; - Ok(StmtExpr { value, range }) -} -impl Foldable for StmtPass { - type Mapped = StmtPass; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_pass(self) - } -} -pub fn fold_stmt_pass + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtPass, -) -> Result, F::Error> { - let StmtPass { range } = node; - let context = folder.will_map_user(&range); - - let range = folder.map_user(range, context)?; - Ok(StmtPass { range }) -} -impl Foldable for StmtBreak { - type Mapped = StmtBreak; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_break(self) - } -} -pub fn fold_stmt_break + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtBreak, -) -> Result, F::Error> { - let StmtBreak { range } = node; - let context = folder.will_map_user(&range); - - let range = folder.map_user(range, context)?; - Ok(StmtBreak { range }) -} -impl Foldable for StmtContinue { - type Mapped = StmtContinue; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_stmt_continue(self) - } -} -pub fn fold_stmt_continue + ?Sized>( - #[allow(unused)] folder: &mut F, - node: StmtContinue, -) -> Result, F::Error> { - let StmtContinue { range } = node; - let context = folder.will_map_user(&range); - - let range = folder.map_user(range, context)?; - Ok(StmtContinue { range }) -} -impl Foldable for Expr { - type Mapped = Expr; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr(self) - } -} -pub fn fold_expr + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Expr, -) -> Result, F::Error> { - let folded = match node { - Expr::BoolOp(cons) => Expr::BoolOp(Foldable::fold(cons, folder)?), - Expr::NamedExpr(cons) => Expr::NamedExpr(Foldable::fold(cons, folder)?), - Expr::BinOp(cons) => Expr::BinOp(Foldable::fold(cons, folder)?), - Expr::UnaryOp(cons) => Expr::UnaryOp(Foldable::fold(cons, folder)?), - Expr::Lambda(cons) => Expr::Lambda(Foldable::fold(cons, folder)?), - Expr::IfExp(cons) => Expr::IfExp(Foldable::fold(cons, folder)?), - Expr::Dict(cons) => Expr::Dict(Foldable::fold(cons, folder)?), - Expr::Set(cons) => Expr::Set(Foldable::fold(cons, folder)?), - Expr::ListComp(cons) => Expr::ListComp(Foldable::fold(cons, folder)?), - Expr::SetComp(cons) => Expr::SetComp(Foldable::fold(cons, folder)?), - Expr::DictComp(cons) => Expr::DictComp(Foldable::fold(cons, folder)?), - Expr::GeneratorExp(cons) => Expr::GeneratorExp(Foldable::fold(cons, folder)?), - Expr::Await(cons) => Expr::Await(Foldable::fold(cons, folder)?), - Expr::Yield(cons) => Expr::Yield(Foldable::fold(cons, folder)?), - Expr::YieldFrom(cons) => Expr::YieldFrom(Foldable::fold(cons, folder)?), - Expr::Compare(cons) => Expr::Compare(Foldable::fold(cons, folder)?), - Expr::Call(cons) => Expr::Call(Foldable::fold(cons, folder)?), - Expr::FormattedValue(cons) => Expr::FormattedValue(Foldable::fold(cons, folder)?), - Expr::JoinedStr(cons) => Expr::JoinedStr(Foldable::fold(cons, folder)?), - Expr::Constant(cons) => Expr::Constant(Foldable::fold(cons, folder)?), - Expr::Attribute(cons) => Expr::Attribute(Foldable::fold(cons, folder)?), - Expr::Subscript(cons) => Expr::Subscript(Foldable::fold(cons, folder)?), - Expr::Starred(cons) => Expr::Starred(Foldable::fold(cons, folder)?), - Expr::Name(cons) => Expr::Name(Foldable::fold(cons, folder)?), - Expr::List(cons) => Expr::List(Foldable::fold(cons, folder)?), - Expr::Tuple(cons) => Expr::Tuple(Foldable::fold(cons, folder)?), - Expr::Slice(cons) => Expr::Slice(Foldable::fold(cons, folder)?), - }; - Ok(folded) -} -impl Foldable for ExprBoolOp { - type Mapped = ExprBoolOp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_bool_op(self) - } -} -pub fn fold_expr_bool_op + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprBoolOp, -) -> Result, F::Error> { - let ExprBoolOp { op, values, range } = node; - let context = folder.will_map_user(&range); - - let op = Foldable::fold(op, folder)?; - let values = Foldable::fold(values, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprBoolOp { op, values, range }) -} -impl Foldable for ExprNamedExpr { - type Mapped = ExprNamedExpr; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_named_expr(self) - } -} -pub fn fold_expr_named_expr + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprNamedExpr, -) -> Result, F::Error> { - let ExprNamedExpr { - target, - value, - range, - } = node; - let context = folder.will_map_user(&range); - - let target = Foldable::fold(target, folder)?; - let value = Foldable::fold(value, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprNamedExpr { - target, - value, - range, - }) -} -impl Foldable for ExprBinOp { - type Mapped = ExprBinOp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_bin_op(self) - } -} -pub fn fold_expr_bin_op + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprBinOp, -) -> Result, F::Error> { - let ExprBinOp { - left, - op, - right, - range, - } = node; - let context = folder.will_map_user(&range); - - let left = Foldable::fold(left, folder)?; - let op = Foldable::fold(op, folder)?; - let right = Foldable::fold(right, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprBinOp { - left, - op, - right, - range, - }) -} -impl Foldable for ExprUnaryOp { - type Mapped = ExprUnaryOp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_unary_op(self) - } -} -pub fn fold_expr_unary_op + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprUnaryOp, -) -> Result, F::Error> { - let ExprUnaryOp { op, operand, range } = node; - let context = folder.will_map_user(&range); - - let op = Foldable::fold(op, folder)?; - let operand = Foldable::fold(operand, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprUnaryOp { op, operand, range }) -} -impl Foldable for ExprLambda { - type Mapped = ExprLambda; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_lambda(self) - } -} -pub fn fold_expr_lambda + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprLambda, -) -> Result, F::Error> { - let ExprLambda { args, body, range } = node; - let context = folder.will_map_user(&range); - - let args = Foldable::fold(args, folder)?; - let body = Foldable::fold(body, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprLambda { args, body, range }) -} -impl Foldable for ExprIfExp { - type Mapped = ExprIfExp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_if_exp(self) - } -} -pub fn fold_expr_if_exp + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprIfExp, -) -> Result, F::Error> { - let ExprIfExp { - test, - body, - orelse, - range, - } = node; - let context = folder.will_map_user(&range); - - let test = Foldable::fold(test, folder)?; - let body = Foldable::fold(body, folder)?; - let orelse = Foldable::fold(orelse, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprIfExp { - test, - body, - orelse, - range, - }) -} -impl Foldable for ExprDict { - type Mapped = ExprDict; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_dict(self) - } -} -pub fn fold_expr_dict + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprDict, -) -> Result, F::Error> { - let ExprDict { - keys, - values, - range, - } = node; - let context = folder.will_map_user(&range); - - let keys = Foldable::fold(keys, folder)?; - let values = Foldable::fold(values, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprDict { - keys, - values, - range, - }) -} -impl Foldable for ExprSet { - type Mapped = ExprSet; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_set(self) - } -} -pub fn fold_expr_set + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprSet, -) -> Result, F::Error> { - let ExprSet { elts, range } = node; - let context = folder.will_map_user(&range); - - let elts = Foldable::fold(elts, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprSet { elts, range }) -} -impl Foldable for ExprListComp { - type Mapped = ExprListComp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_list_comp(self) - } -} -pub fn fold_expr_list_comp + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprListComp, -) -> Result, F::Error> { - let ExprListComp { - elt, - generators, - range, - } = node; - let context = folder.will_map_user(&range); - - let elt = Foldable::fold(elt, folder)?; - let generators = Foldable::fold(generators, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprListComp { - elt, - generators, - range, - }) -} -impl Foldable for ExprSetComp { - type Mapped = ExprSetComp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_set_comp(self) - } -} -pub fn fold_expr_set_comp + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprSetComp, -) -> Result, F::Error> { - let ExprSetComp { - elt, - generators, - range, - } = node; - let context = folder.will_map_user(&range); - - let elt = Foldable::fold(elt, folder)?; - let generators = Foldable::fold(generators, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprSetComp { - elt, - generators, - range, - }) -} -impl Foldable for ExprDictComp { - type Mapped = ExprDictComp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_dict_comp(self) - } -} -pub fn fold_expr_dict_comp + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprDictComp, -) -> Result, F::Error> { - let ExprDictComp { - key, - value, - generators, - range, - } = node; - let context = folder.will_map_user(&range); - - let key = Foldable::fold(key, folder)?; - let value = Foldable::fold(value, folder)?; - let generators = Foldable::fold(generators, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprDictComp { - key, - value, - generators, - range, - }) -} -impl Foldable for ExprGeneratorExp { - type Mapped = ExprGeneratorExp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_generator_exp(self) - } -} -pub fn fold_expr_generator_exp + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprGeneratorExp, -) -> Result, F::Error> { - let ExprGeneratorExp { - elt, - generators, - range, - } = node; - let context = folder.will_map_user(&range); - - let elt = Foldable::fold(elt, folder)?; - let generators = Foldable::fold(generators, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprGeneratorExp { - elt, - generators, - range, - }) -} -impl Foldable for ExprAwait { - type Mapped = ExprAwait; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_await(self) - } -} -pub fn fold_expr_await + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprAwait, -) -> Result, F::Error> { - let ExprAwait { value, range } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprAwait { value, range }) -} -impl Foldable for ExprYield { - type Mapped = ExprYield; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_yield(self) - } -} -pub fn fold_expr_yield + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprYield, -) -> Result, F::Error> { - let ExprYield { value, range } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprYield { value, range }) -} -impl Foldable for ExprYieldFrom { - type Mapped = ExprYieldFrom; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_yield_from(self) - } -} -pub fn fold_expr_yield_from + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprYieldFrom, -) -> Result, F::Error> { - let ExprYieldFrom { value, range } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprYieldFrom { value, range }) -} -impl Foldable for ExprCompare { - type Mapped = ExprCompare; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_compare(self) - } -} -pub fn fold_expr_compare + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprCompare, -) -> Result, F::Error> { - let ExprCompare { - left, - ops, - comparators, - range, - } = node; - let context = folder.will_map_user(&range); - - let left = Foldable::fold(left, folder)?; - let ops = Foldable::fold(ops, folder)?; - let comparators = Foldable::fold(comparators, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprCompare { - left, - ops, - comparators, - range, - }) -} -impl Foldable for ExprCall { - type Mapped = ExprCall; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_call(self) - } -} -pub fn fold_expr_call + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprCall, -) -> Result, F::Error> { - let ExprCall { - func, - args, - keywords, - range, - } = node; - let context = folder.will_map_user(&range); - - let func = Foldable::fold(func, folder)?; - let args = Foldable::fold(args, folder)?; - let keywords = Foldable::fold(keywords, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprCall { - func, - args, - keywords, - range, - }) -} -impl Foldable for ExprFormattedValue { - type Mapped = ExprFormattedValue; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_formatted_value(self) - } -} -pub fn fold_expr_formatted_value + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprFormattedValue, -) -> Result, F::Error> { - let ExprFormattedValue { - value, - conversion, - format_spec, - range, - } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let conversion = Foldable::fold(conversion, folder)?; - let format_spec = Foldable::fold(format_spec, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprFormattedValue { - value, - conversion, - format_spec, - range, - }) -} -impl Foldable for ExprJoinedStr { - type Mapped = ExprJoinedStr; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_joined_str(self) - } -} -pub fn fold_expr_joined_str + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprJoinedStr, -) -> Result, F::Error> { - let ExprJoinedStr { values, range } = node; - let context = folder.will_map_user(&range); - - let values = Foldable::fold(values, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprJoinedStr { values, range }) -} -impl Foldable for ExprConstant { - type Mapped = ExprConstant; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_constant(self) - } -} -pub fn fold_expr_constant + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprConstant, -) -> Result, F::Error> { - let ExprConstant { value, kind, range } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let kind = Foldable::fold(kind, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprConstant { value, kind, range }) -} -impl Foldable for ExprAttribute { - type Mapped = ExprAttribute; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_attribute(self) - } -} -pub fn fold_expr_attribute + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprAttribute, -) -> Result, F::Error> { - let ExprAttribute { - value, - attr, - ctx, - range, - } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let attr = Foldable::fold(attr, folder)?; - let ctx = Foldable::fold(ctx, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprAttribute { - value, - attr, - ctx, - range, - }) -} -impl Foldable for ExprSubscript { - type Mapped = ExprSubscript; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_subscript(self) - } -} -pub fn fold_expr_subscript + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprSubscript, -) -> Result, F::Error> { - let ExprSubscript { - value, - slice, - ctx, - range, - } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let slice = Foldable::fold(slice, folder)?; - let ctx = Foldable::fold(ctx, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprSubscript { - value, - slice, - ctx, - range, - }) -} -impl Foldable for ExprStarred { - type Mapped = ExprStarred; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_starred(self) - } -} -pub fn fold_expr_starred + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprStarred, -) -> Result, F::Error> { - let ExprStarred { value, ctx, range } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let ctx = Foldable::fold(ctx, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprStarred { value, ctx, range }) -} -impl Foldable for ExprName { - type Mapped = ExprName; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_name(self) - } -} -pub fn fold_expr_name + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprName, -) -> Result, F::Error> { - let ExprName { id, ctx, range } = node; - let context = folder.will_map_user(&range); - - let id = Foldable::fold(id, folder)?; - let ctx = Foldable::fold(ctx, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprName { id, ctx, range }) -} -impl Foldable for ExprList { - type Mapped = ExprList; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_list(self) - } -} -pub fn fold_expr_list + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprList, -) -> Result, F::Error> { - let ExprList { elts, ctx, range } = node; - let context = folder.will_map_user(&range); - - let elts = Foldable::fold(elts, folder)?; - let ctx = Foldable::fold(ctx, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprList { elts, ctx, range }) -} -impl Foldable for ExprTuple { - type Mapped = ExprTuple; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_tuple(self) - } -} -pub fn fold_expr_tuple + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprTuple, -) -> Result, F::Error> { - let ExprTuple { elts, ctx, range } = node; - let context = folder.will_map_user(&range); - - let elts = Foldable::fold(elts, folder)?; - let ctx = Foldable::fold(ctx, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprTuple { elts, ctx, range }) -} -impl Foldable for ExprSlice { - type Mapped = ExprSlice; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_slice(self) - } -} -pub fn fold_expr_slice + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprSlice, -) -> Result, F::Error> { - let ExprSlice { - lower, - upper, - step, - range, - } = node; - let context = folder.will_map_user(&range); - - let lower = Foldable::fold(lower, folder)?; - let upper = Foldable::fold(upper, folder)?; - let step = Foldable::fold(step, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExprSlice { - lower, - upper, - step, - range, - }) -} -impl Foldable for ExprContext { - type Mapped = ExprContext; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_expr_context(self) - } -} -pub fn fold_expr_context + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExprContext, -) -> Result { - Ok(node) -} -impl Foldable for BoolOp { - type Mapped = BoolOp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_boolop(self) - } -} -pub fn fold_boolop + ?Sized>( - #[allow(unused)] folder: &mut F, - node: BoolOp, -) -> Result { - Ok(node) -} -impl Foldable for Operator { - type Mapped = Operator; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_operator(self) - } -} -pub fn fold_operator + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Operator, -) -> Result { - Ok(node) -} -impl Foldable for UnaryOp { - type Mapped = UnaryOp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_unaryop(self) - } -} -pub fn fold_unaryop + ?Sized>( - #[allow(unused)] folder: &mut F, - node: UnaryOp, -) -> Result { - Ok(node) -} -impl Foldable for CmpOp { - type Mapped = CmpOp; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_cmpop(self) - } -} -pub fn fold_cmpop + ?Sized>( - #[allow(unused)] folder: &mut F, - node: CmpOp, -) -> Result { - Ok(node) -} -impl Foldable for Comprehension { - type Mapped = Comprehension; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_comprehension(self) - } -} -pub fn fold_comprehension + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Comprehension, -) -> Result, F::Error> { - let Comprehension { - target, - iter, - ifs, - is_async, - range, - } = node; - let context = folder.will_map_user_cfg(&range); - let target = Foldable::fold(target, folder)?; - let iter = Foldable::fold(iter, folder)?; - let ifs = Foldable::fold(ifs, folder)?; - let is_async = Foldable::fold(is_async, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(Comprehension { - target, - iter, - ifs, - is_async, - range, - }) -} -impl Foldable for ExceptHandler { - type Mapped = ExceptHandler; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_excepthandler(self) - } -} -pub fn fold_excepthandler + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExceptHandler, -) -> Result, F::Error> { - let folded = match node { - ExceptHandler::ExceptHandler(cons) => { - ExceptHandler::ExceptHandler(Foldable::fold(cons, folder)?) - } - }; - Ok(folded) -} -impl Foldable for ExceptHandlerExceptHandler { - type Mapped = ExceptHandlerExceptHandler; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_excepthandler_except_handler(self) - } -} -pub fn fold_excepthandler_except_handler + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ExceptHandlerExceptHandler, -) -> Result, F::Error> { - let ExceptHandlerExceptHandler { - type_, - name, - body, - range, - } = node; - let context = folder.will_map_user(&range); - - let type_ = Foldable::fold(type_, folder)?; - let name = Foldable::fold(name, folder)?; - let body = Foldable::fold(body, folder)?; - let range = folder.map_user(range, context)?; - Ok(ExceptHandlerExceptHandler { - type_, - name, - body, - range, - }) -} -impl Foldable for Arguments { - type Mapped = Arguments; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_arguments(self) - } -} -pub fn fold_arguments + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Arguments, -) -> Result, F::Error> { - let Arguments { - posonlyargs, - args, - vararg, - kwonlyargs, - kwarg, - range, - } = node; - let context = folder.will_map_user_cfg(&range); - let posonlyargs = Foldable::fold(posonlyargs, folder)?; - let args = Foldable::fold(args, folder)?; - let vararg = Foldable::fold(vararg, folder)?; - let kwonlyargs = Foldable::fold(kwonlyargs, folder)?; - let kwarg = Foldable::fold(kwarg, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(Arguments { - posonlyargs, - args, - vararg, - kwonlyargs, - kwarg, - range, - }) -} -impl Foldable for Arg { - type Mapped = Arg; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_arg(self) - } -} -pub fn fold_arg + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Arg, -) -> Result, F::Error> { - let Arg { - arg, - annotation, - type_comment, - range, - } = node; - let context = folder.will_map_user(&range); - let arg = Foldable::fold(arg, folder)?; - let annotation = Foldable::fold(annotation, folder)?; - let type_comment = Foldable::fold(type_comment, folder)?; - let range = folder.map_user(range, context)?; - Ok(Arg { - arg, - annotation, - type_comment, - range, - }) -} -impl Foldable for Keyword { - type Mapped = Keyword; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_keyword(self) - } -} -pub fn fold_keyword + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Keyword, -) -> Result, F::Error> { - let Keyword { arg, value, range } = node; - let context = folder.will_map_user(&range); - let arg = Foldable::fold(arg, folder)?; - let value = Foldable::fold(value, folder)?; - let range = folder.map_user(range, context)?; - Ok(Keyword { arg, value, range }) -} -impl Foldable for Alias { - type Mapped = Alias; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_alias(self) - } -} -pub fn fold_alias + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Alias, -) -> Result, F::Error> { - let Alias { - name, - asname, - range, - } = node; - let context = folder.will_map_user(&range); - let name = Foldable::fold(name, folder)?; - let asname = Foldable::fold(asname, folder)?; - let range = folder.map_user(range, context)?; - Ok(Alias { - name, - asname, - range, - }) -} -impl Foldable for WithItem { - type Mapped = WithItem; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_withitem(self) - } -} -pub fn fold_withitem + ?Sized>( - #[allow(unused)] folder: &mut F, - node: WithItem, -) -> Result, F::Error> { - let WithItem { - context_expr, - optional_vars, - range, - } = node; - let context = folder.will_map_user_cfg(&range); - let context_expr = Foldable::fold(context_expr, folder)?; - let optional_vars = Foldable::fold(optional_vars, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(WithItem { - context_expr, - optional_vars, - range, - }) -} -impl Foldable for MatchCase { - type Mapped = MatchCase; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_match_case(self) - } -} -pub fn fold_match_case + ?Sized>( - #[allow(unused)] folder: &mut F, - node: MatchCase, -) -> Result, F::Error> { - let MatchCase { - pattern, - guard, - body, - range, - } = node; - let context = folder.will_map_user_cfg(&range); - let pattern = Foldable::fold(pattern, folder)?; - let guard = Foldable::fold(guard, folder)?; - let body = Foldable::fold(body, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(MatchCase { - pattern, - guard, - body, - range, - }) -} -impl Foldable for Pattern { - type Mapped = Pattern; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_pattern(self) - } -} -pub fn fold_pattern + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Pattern, -) -> Result, F::Error> { - let folded = match node { - Pattern::MatchValue(cons) => Pattern::MatchValue(Foldable::fold(cons, folder)?), - Pattern::MatchSingleton(cons) => Pattern::MatchSingleton(Foldable::fold(cons, folder)?), - Pattern::MatchSequence(cons) => Pattern::MatchSequence(Foldable::fold(cons, folder)?), - Pattern::MatchMapping(cons) => Pattern::MatchMapping(Foldable::fold(cons, folder)?), - Pattern::MatchClass(cons) => Pattern::MatchClass(Foldable::fold(cons, folder)?), - Pattern::MatchStar(cons) => Pattern::MatchStar(Foldable::fold(cons, folder)?), - Pattern::MatchAs(cons) => Pattern::MatchAs(Foldable::fold(cons, folder)?), - Pattern::MatchOr(cons) => Pattern::MatchOr(Foldable::fold(cons, folder)?), - }; - Ok(folded) -} -impl Foldable for PatternMatchValue { - type Mapped = PatternMatchValue; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_pattern_match_value(self) - } -} -pub fn fold_pattern_match_value + ?Sized>( - #[allow(unused)] folder: &mut F, - node: PatternMatchValue, -) -> Result, F::Error> { - let PatternMatchValue { value, range } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let range = folder.map_user(range, context)?; - Ok(PatternMatchValue { value, range }) -} -impl Foldable for PatternMatchSingleton { - type Mapped = PatternMatchSingleton; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_pattern_match_singleton(self) - } -} -pub fn fold_pattern_match_singleton + ?Sized>( - #[allow(unused)] folder: &mut F, - node: PatternMatchSingleton, -) -> Result, F::Error> { - let PatternMatchSingleton { value, range } = node; - let context = folder.will_map_user(&range); - - let value = Foldable::fold(value, folder)?; - let range = folder.map_user(range, context)?; - Ok(PatternMatchSingleton { value, range }) -} -impl Foldable for PatternMatchSequence { - type Mapped = PatternMatchSequence; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_pattern_match_sequence(self) - } -} -pub fn fold_pattern_match_sequence + ?Sized>( - #[allow(unused)] folder: &mut F, - node: PatternMatchSequence, -) -> Result, F::Error> { - let PatternMatchSequence { patterns, range } = node; - let context = folder.will_map_user(&range); - - let patterns = Foldable::fold(patterns, folder)?; - let range = folder.map_user(range, context)?; - Ok(PatternMatchSequence { patterns, range }) -} -impl Foldable for PatternMatchMapping { - type Mapped = PatternMatchMapping; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_pattern_match_mapping(self) - } -} -pub fn fold_pattern_match_mapping + ?Sized>( - #[allow(unused)] folder: &mut F, - node: PatternMatchMapping, -) -> Result, F::Error> { - let PatternMatchMapping { - keys, - patterns, - rest, - range, - } = node; - let context = folder.will_map_user(&range); - - let keys = Foldable::fold(keys, folder)?; - let patterns = Foldable::fold(patterns, folder)?; - let rest = Foldable::fold(rest, folder)?; - let range = folder.map_user(range, context)?; - Ok(PatternMatchMapping { - keys, - patterns, - rest, - range, - }) -} -impl Foldable for PatternMatchClass { - type Mapped = PatternMatchClass; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_pattern_match_class(self) - } -} -pub fn fold_pattern_match_class + ?Sized>( - #[allow(unused)] folder: &mut F, - node: PatternMatchClass, -) -> Result, F::Error> { - let PatternMatchClass { - cls, - patterns, - kwd_attrs, - kwd_patterns, - range, - } = node; - let context = folder.will_map_user(&range); - - let cls = Foldable::fold(cls, folder)?; - let patterns = Foldable::fold(patterns, folder)?; - let kwd_attrs = Foldable::fold(kwd_attrs, folder)?; - let kwd_patterns = Foldable::fold(kwd_patterns, folder)?; - let range = folder.map_user(range, context)?; - Ok(PatternMatchClass { - cls, - patterns, - kwd_attrs, - kwd_patterns, - range, - }) -} -impl Foldable for PatternMatchStar { - type Mapped = PatternMatchStar; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_pattern_match_star(self) - } -} -pub fn fold_pattern_match_star + ?Sized>( - #[allow(unused)] folder: &mut F, - node: PatternMatchStar, -) -> Result, F::Error> { - let PatternMatchStar { name, range } = node; - let context = folder.will_map_user(&range); - - let name = Foldable::fold(name, folder)?; - let range = folder.map_user(range, context)?; - Ok(PatternMatchStar { name, range }) -} -impl Foldable for PatternMatchAs { - type Mapped = PatternMatchAs; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_pattern_match_as(self) - } -} -pub fn fold_pattern_match_as + ?Sized>( - #[allow(unused)] folder: &mut F, - node: PatternMatchAs, -) -> Result, F::Error> { - let PatternMatchAs { - pattern, - name, - range, - } = node; - let context = folder.will_map_user(&range); - - let pattern = Foldable::fold(pattern, folder)?; - let name = Foldable::fold(name, folder)?; - let range = folder.map_user(range, context)?; - Ok(PatternMatchAs { - pattern, - name, - range, - }) -} -impl Foldable for PatternMatchOr { - type Mapped = PatternMatchOr; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_pattern_match_or(self) - } -} -pub fn fold_pattern_match_or + ?Sized>( - #[allow(unused)] folder: &mut F, - node: PatternMatchOr, -) -> Result, F::Error> { - let PatternMatchOr { patterns, range } = node; - let context = folder.will_map_user(&range); - - let patterns = Foldable::fold(patterns, folder)?; - let range = folder.map_user(range, context)?; - Ok(PatternMatchOr { patterns, range }) -} -impl Foldable for TypeIgnore { - type Mapped = TypeIgnore; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_type_ignore(self) - } -} -pub fn fold_type_ignore + ?Sized>( - #[allow(unused)] folder: &mut F, - node: TypeIgnore, -) -> Result, F::Error> { - let folded = match node { - TypeIgnore::TypeIgnore(cons) => TypeIgnore::TypeIgnore(Foldable::fold(cons, folder)?), - }; - Ok(folded) -} -impl Foldable for TypeIgnoreTypeIgnore { - type Mapped = TypeIgnoreTypeIgnore; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_type_ignore_type_ignore(self) - } -} -pub fn fold_type_ignore_type_ignore + ?Sized>( - #[allow(unused)] folder: &mut F, - node: TypeIgnoreTypeIgnore, -) -> Result, F::Error> { - let TypeIgnoreTypeIgnore { lineno, tag, range } = node; - let context = folder.will_map_user_cfg(&range); - - let lineno = Foldable::fold(lineno, folder)?; - let tag = Foldable::fold(tag, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(TypeIgnoreTypeIgnore { lineno, tag, range }) -} -impl Foldable for Decorator { - type Mapped = Decorator; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_decorator(self) - } -} -pub fn fold_decorator + ?Sized>( - #[allow(unused)] folder: &mut F, - node: Decorator, -) -> Result, F::Error> { - let Decorator { expression, range } = node; - let context = folder.will_map_user_cfg(&range); - let expression = Foldable::fold(expression, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(Decorator { expression, range }) -} -impl Foldable for ArgWithDefault { - type Mapped = ArgWithDefault; - fn fold + ?Sized>( - self, - folder: &mut F, - ) -> Result { - folder.fold_arg_with_default(self) - } -} -pub fn fold_arg_with_default + ?Sized>( - #[allow(unused)] folder: &mut F, - node: ArgWithDefault, -) -> Result, F::Error> { - let ArgWithDefault { - def, - default, - range, - } = node; - let context = folder.will_map_user_cfg(&range); - let def = Foldable::fold(def, folder)?; - let default = Foldable::fold(default, folder)?; - let range = folder.map_user_cfg(range, context)?; - Ok(ArgWithDefault { - def, - default, - range, - }) -} diff --git a/ast/src/gen/located.rs b/ast/src/gen/located.rs deleted file mode 100644 index b80b7163cd9f6..0000000000000 --- a/ast/src/gen/located.rs +++ /dev/null @@ -1,1413 +0,0 @@ -// File automatically generated by ast/asdl_rs.py. - -pub type Mod = crate::generic::Mod; - -pub type ModModule = crate::generic::ModModule; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for ModModule { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for ModModule { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ModInteractive = crate::generic::ModInteractive; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for ModInteractive { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for ModInteractive { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ModExpression = crate::generic::ModExpression; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for ModExpression { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for ModExpression { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ModFunctionType = crate::generic::ModFunctionType; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for ModFunctionType { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for ModFunctionType { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for Mod { - fn range(&self) -> SourceRange { - match self { - Self::Module(node) => node.range(), - Self::Interactive(node) => node.range(), - Self::Expression(node) => node.range(), - Self::FunctionType(node) => node.range(), - } - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for Mod { - fn range_mut(&mut self) -> &mut SourceRange { - match self { - Self::Module(node) => node.range_mut(), - Self::Interactive(node) => node.range_mut(), - Self::Expression(node) => node.range_mut(), - Self::FunctionType(node) => node.range_mut(), - } - } -} - -pub type Stmt = crate::generic::Stmt; - -pub type StmtFunctionDef = crate::generic::StmtFunctionDef; - -impl Located for StmtFunctionDef { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtFunctionDef { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtAsyncFunctionDef = crate::generic::StmtAsyncFunctionDef; - -impl Located for StmtAsyncFunctionDef { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtAsyncFunctionDef { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtClassDef = crate::generic::StmtClassDef; - -impl Located for StmtClassDef { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtClassDef { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtReturn = crate::generic::StmtReturn; - -impl Located for StmtReturn { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtReturn { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtDelete = crate::generic::StmtDelete; - -impl Located for StmtDelete { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtDelete { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtAssign = crate::generic::StmtAssign; - -impl Located for StmtAssign { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtAssign { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtAugAssign = crate::generic::StmtAugAssign; - -impl Located for StmtAugAssign { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtAugAssign { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtAnnAssign = crate::generic::StmtAnnAssign; - -impl Located for StmtAnnAssign { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtAnnAssign { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtFor = crate::generic::StmtFor; - -impl Located for StmtFor { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtFor { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtAsyncFor = crate::generic::StmtAsyncFor; - -impl Located for StmtAsyncFor { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtAsyncFor { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtWhile = crate::generic::StmtWhile; - -impl Located for StmtWhile { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtWhile { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtIf = crate::generic::StmtIf; - -impl Located for StmtIf { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtIf { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtWith = crate::generic::StmtWith; - -impl Located for StmtWith { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtWith { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtAsyncWith = crate::generic::StmtAsyncWith; - -impl Located for StmtAsyncWith { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtAsyncWith { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtMatch = crate::generic::StmtMatch; - -impl Located for StmtMatch { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtMatch { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtRaise = crate::generic::StmtRaise; - -impl Located for StmtRaise { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtRaise { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtTry = crate::generic::StmtTry; - -impl Located for StmtTry { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtTry { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtTryStar = crate::generic::StmtTryStar; - -impl Located for StmtTryStar { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtTryStar { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtAssert = crate::generic::StmtAssert; - -impl Located for StmtAssert { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtAssert { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtImport = crate::generic::StmtImport; - -impl Located for StmtImport { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtImport { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtImportFrom = crate::generic::StmtImportFrom; - -impl Located for StmtImportFrom { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtImportFrom { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtGlobal = crate::generic::StmtGlobal; - -impl Located for StmtGlobal { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtGlobal { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtNonlocal = crate::generic::StmtNonlocal; - -impl Located for StmtNonlocal { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtNonlocal { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtExpr = crate::generic::StmtExpr; - -impl Located for StmtExpr { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtExpr { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtPass = crate::generic::StmtPass; - -impl Located for StmtPass { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtPass { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtBreak = crate::generic::StmtBreak; - -impl Located for StmtBreak { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtBreak { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type StmtContinue = crate::generic::StmtContinue; - -impl Located for StmtContinue { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for StmtContinue { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -impl Located for Stmt { - fn range(&self) -> SourceRange { - match self { - Self::FunctionDef(node) => node.range(), - Self::AsyncFunctionDef(node) => node.range(), - Self::ClassDef(node) => node.range(), - Self::Return(node) => node.range(), - Self::Delete(node) => node.range(), - Self::Assign(node) => node.range(), - Self::AugAssign(node) => node.range(), - Self::AnnAssign(node) => node.range(), - Self::For(node) => node.range(), - Self::AsyncFor(node) => node.range(), - Self::While(node) => node.range(), - Self::If(node) => node.range(), - Self::With(node) => node.range(), - Self::AsyncWith(node) => node.range(), - Self::Match(node) => node.range(), - Self::Raise(node) => node.range(), - Self::Try(node) => node.range(), - Self::TryStar(node) => node.range(), - Self::Assert(node) => node.range(), - Self::Import(node) => node.range(), - Self::ImportFrom(node) => node.range(), - Self::Global(node) => node.range(), - Self::Nonlocal(node) => node.range(), - Self::Expr(node) => node.range(), - Self::Pass(node) => node.range(), - Self::Break(node) => node.range(), - Self::Continue(node) => node.range(), - } - } -} - -impl LocatedMut for Stmt { - fn range_mut(&mut self) -> &mut SourceRange { - match self { - Self::FunctionDef(node) => node.range_mut(), - Self::AsyncFunctionDef(node) => node.range_mut(), - Self::ClassDef(node) => node.range_mut(), - Self::Return(node) => node.range_mut(), - Self::Delete(node) => node.range_mut(), - Self::Assign(node) => node.range_mut(), - Self::AugAssign(node) => node.range_mut(), - Self::AnnAssign(node) => node.range_mut(), - Self::For(node) => node.range_mut(), - Self::AsyncFor(node) => node.range_mut(), - Self::While(node) => node.range_mut(), - Self::If(node) => node.range_mut(), - Self::With(node) => node.range_mut(), - Self::AsyncWith(node) => node.range_mut(), - Self::Match(node) => node.range_mut(), - Self::Raise(node) => node.range_mut(), - Self::Try(node) => node.range_mut(), - Self::TryStar(node) => node.range_mut(), - Self::Assert(node) => node.range_mut(), - Self::Import(node) => node.range_mut(), - Self::ImportFrom(node) => node.range_mut(), - Self::Global(node) => node.range_mut(), - Self::Nonlocal(node) => node.range_mut(), - Self::Expr(node) => node.range_mut(), - Self::Pass(node) => node.range_mut(), - Self::Break(node) => node.range_mut(), - Self::Continue(node) => node.range_mut(), - } - } -} - -pub type Expr = crate::generic::Expr; - -pub type ExprBoolOp = crate::generic::ExprBoolOp; - -impl Located for ExprBoolOp { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprBoolOp { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprNamedExpr = crate::generic::ExprNamedExpr; - -impl Located for ExprNamedExpr { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprNamedExpr { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprBinOp = crate::generic::ExprBinOp; - -impl Located for ExprBinOp { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprBinOp { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprUnaryOp = crate::generic::ExprUnaryOp; - -impl Located for ExprUnaryOp { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprUnaryOp { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprLambda = crate::generic::ExprLambda; - -impl Located for ExprLambda { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprLambda { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprIfExp = crate::generic::ExprIfExp; - -impl Located for ExprIfExp { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprIfExp { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprDict = crate::generic::ExprDict; - -impl Located for ExprDict { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprDict { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprSet = crate::generic::ExprSet; - -impl Located for ExprSet { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprSet { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprListComp = crate::generic::ExprListComp; - -impl Located for ExprListComp { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprListComp { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprSetComp = crate::generic::ExprSetComp; - -impl Located for ExprSetComp { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprSetComp { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprDictComp = crate::generic::ExprDictComp; - -impl Located for ExprDictComp { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprDictComp { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprGeneratorExp = crate::generic::ExprGeneratorExp; - -impl Located for ExprGeneratorExp { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprGeneratorExp { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprAwait = crate::generic::ExprAwait; - -impl Located for ExprAwait { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprAwait { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprYield = crate::generic::ExprYield; - -impl Located for ExprYield { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprYield { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprYieldFrom = crate::generic::ExprYieldFrom; - -impl Located for ExprYieldFrom { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprYieldFrom { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprCompare = crate::generic::ExprCompare; - -impl Located for ExprCompare { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprCompare { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprCall = crate::generic::ExprCall; - -impl Located for ExprCall { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprCall { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprFormattedValue = crate::generic::ExprFormattedValue; - -impl Located for ExprFormattedValue { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprFormattedValue { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprJoinedStr = crate::generic::ExprJoinedStr; - -impl Located for ExprJoinedStr { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprJoinedStr { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprConstant = crate::generic::ExprConstant; - -impl Located for ExprConstant { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprConstant { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprAttribute = crate::generic::ExprAttribute; - -impl Located for ExprAttribute { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprAttribute { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprSubscript = crate::generic::ExprSubscript; - -impl Located for ExprSubscript { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprSubscript { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprStarred = crate::generic::ExprStarred; - -impl Located for ExprStarred { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprStarred { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprName = crate::generic::ExprName; - -impl Located for ExprName { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprName { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprList = crate::generic::ExprList; - -impl Located for ExprList { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprList { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprTuple = crate::generic::ExprTuple; - -impl Located for ExprTuple { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprTuple { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExprSlice = crate::generic::ExprSlice; - -impl Located for ExprSlice { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExprSlice { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -impl Located for Expr { - fn range(&self) -> SourceRange { - match self { - Self::BoolOp(node) => node.range(), - Self::NamedExpr(node) => node.range(), - Self::BinOp(node) => node.range(), - Self::UnaryOp(node) => node.range(), - Self::Lambda(node) => node.range(), - Self::IfExp(node) => node.range(), - Self::Dict(node) => node.range(), - Self::Set(node) => node.range(), - Self::ListComp(node) => node.range(), - Self::SetComp(node) => node.range(), - Self::DictComp(node) => node.range(), - Self::GeneratorExp(node) => node.range(), - Self::Await(node) => node.range(), - Self::Yield(node) => node.range(), - Self::YieldFrom(node) => node.range(), - Self::Compare(node) => node.range(), - Self::Call(node) => node.range(), - Self::FormattedValue(node) => node.range(), - Self::JoinedStr(node) => node.range(), - Self::Constant(node) => node.range(), - Self::Attribute(node) => node.range(), - Self::Subscript(node) => node.range(), - Self::Starred(node) => node.range(), - Self::Name(node) => node.range(), - Self::List(node) => node.range(), - Self::Tuple(node) => node.range(), - Self::Slice(node) => node.range(), - } - } -} - -impl LocatedMut for Expr { - fn range_mut(&mut self) -> &mut SourceRange { - match self { - Self::BoolOp(node) => node.range_mut(), - Self::NamedExpr(node) => node.range_mut(), - Self::BinOp(node) => node.range_mut(), - Self::UnaryOp(node) => node.range_mut(), - Self::Lambda(node) => node.range_mut(), - Self::IfExp(node) => node.range_mut(), - Self::Dict(node) => node.range_mut(), - Self::Set(node) => node.range_mut(), - Self::ListComp(node) => node.range_mut(), - Self::SetComp(node) => node.range_mut(), - Self::DictComp(node) => node.range_mut(), - Self::GeneratorExp(node) => node.range_mut(), - Self::Await(node) => node.range_mut(), - Self::Yield(node) => node.range_mut(), - Self::YieldFrom(node) => node.range_mut(), - Self::Compare(node) => node.range_mut(), - Self::Call(node) => node.range_mut(), - Self::FormattedValue(node) => node.range_mut(), - Self::JoinedStr(node) => node.range_mut(), - Self::Constant(node) => node.range_mut(), - Self::Attribute(node) => node.range_mut(), - Self::Subscript(node) => node.range_mut(), - Self::Starred(node) => node.range_mut(), - Self::Name(node) => node.range_mut(), - Self::List(node) => node.range_mut(), - Self::Tuple(node) => node.range_mut(), - Self::Slice(node) => node.range_mut(), - } - } -} - -pub type ExprContext = crate::generic::ExprContext; - -pub type ExprContextLoad = crate::generic::ExprContextLoad; - -pub type ExprContextStore = crate::generic::ExprContextStore; - -pub type ExprContextDel = crate::generic::ExprContextDel; - -pub type BoolOp = crate::generic::BoolOp; - -pub type BoolOpAnd = crate::generic::BoolOpAnd; - -pub type BoolOpOr = crate::generic::BoolOpOr; - -pub type Operator = crate::generic::Operator; - -pub type OperatorAdd = crate::generic::OperatorAdd; - -pub type OperatorSub = crate::generic::OperatorSub; - -pub type OperatorMult = crate::generic::OperatorMult; - -pub type OperatorMatMult = crate::generic::OperatorMatMult; - -pub type OperatorDiv = crate::generic::OperatorDiv; - -pub type OperatorMod = crate::generic::OperatorMod; - -pub type OperatorPow = crate::generic::OperatorPow; - -pub type OperatorLShift = crate::generic::OperatorLShift; - -pub type OperatorRShift = crate::generic::OperatorRShift; - -pub type OperatorBitOr = crate::generic::OperatorBitOr; - -pub type OperatorBitXor = crate::generic::OperatorBitXor; - -pub type OperatorBitAnd = crate::generic::OperatorBitAnd; - -pub type OperatorFloorDiv = crate::generic::OperatorFloorDiv; - -pub type UnaryOp = crate::generic::UnaryOp; - -pub type UnaryOpInvert = crate::generic::UnaryOpInvert; - -pub type UnaryOpNot = crate::generic::UnaryOpNot; - -pub type UnaryOpUAdd = crate::generic::UnaryOpUAdd; - -pub type UnaryOpUSub = crate::generic::UnaryOpUSub; - -pub type CmpOp = crate::generic::CmpOp; - -pub type CmpOpEq = crate::generic::CmpOpEq; - -pub type CmpOpNotEq = crate::generic::CmpOpNotEq; - -pub type CmpOpLt = crate::generic::CmpOpLt; - -pub type CmpOpLtE = crate::generic::CmpOpLtE; - -pub type CmpOpGt = crate::generic::CmpOpGt; - -pub type CmpOpGtE = crate::generic::CmpOpGtE; - -pub type CmpOpIs = crate::generic::CmpOpIs; - -pub type CmpOpIsNot = crate::generic::CmpOpIsNot; - -pub type CmpOpIn = crate::generic::CmpOpIn; - -pub type CmpOpNotIn = crate::generic::CmpOpNotIn; - -pub type Comprehension = crate::generic::Comprehension; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for Comprehension { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for Comprehension { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ExceptHandler = crate::generic::ExceptHandler; - -pub type ExceptHandlerExceptHandler = crate::generic::ExceptHandlerExceptHandler; - -impl Located for ExceptHandlerExceptHandler { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for ExceptHandlerExceptHandler { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -impl Located for ExceptHandler { - fn range(&self) -> SourceRange { - match self { - Self::ExceptHandler(node) => node.range(), - } - } -} - -impl LocatedMut for ExceptHandler { - fn range_mut(&mut self) -> &mut SourceRange { - match self { - Self::ExceptHandler(node) => node.range_mut(), - } - } -} - -pub type PythonArguments = crate::generic::PythonArguments; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for PythonArguments { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for PythonArguments { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type Arg = crate::generic::Arg; - -impl Located for Arg { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for Arg { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type Keyword = crate::generic::Keyword; - -impl Located for Keyword { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for Keyword { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type Alias = crate::generic::Alias; - -impl Located for Alias { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for Alias { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type WithItem = crate::generic::WithItem; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for WithItem { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for WithItem { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type MatchCase = crate::generic::MatchCase; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for MatchCase { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for MatchCase { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type Pattern = crate::generic::Pattern; - -pub type PatternMatchValue = crate::generic::PatternMatchValue; - -impl Located for PatternMatchValue { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for PatternMatchValue { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type PatternMatchSingleton = crate::generic::PatternMatchSingleton; - -impl Located for PatternMatchSingleton { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for PatternMatchSingleton { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type PatternMatchSequence = crate::generic::PatternMatchSequence; - -impl Located for PatternMatchSequence { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for PatternMatchSequence { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type PatternMatchMapping = crate::generic::PatternMatchMapping; - -impl Located for PatternMatchMapping { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for PatternMatchMapping { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type PatternMatchClass = crate::generic::PatternMatchClass; - -impl Located for PatternMatchClass { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for PatternMatchClass { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type PatternMatchStar = crate::generic::PatternMatchStar; - -impl Located for PatternMatchStar { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for PatternMatchStar { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type PatternMatchAs = crate::generic::PatternMatchAs; - -impl Located for PatternMatchAs { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for PatternMatchAs { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type PatternMatchOr = crate::generic::PatternMatchOr; - -impl Located for PatternMatchOr { - fn range(&self) -> SourceRange { - self.range - } -} - -impl LocatedMut for PatternMatchOr { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -impl Located for Pattern { - fn range(&self) -> SourceRange { - match self { - Self::MatchValue(node) => node.range(), - Self::MatchSingleton(node) => node.range(), - Self::MatchSequence(node) => node.range(), - Self::MatchMapping(node) => node.range(), - Self::MatchClass(node) => node.range(), - Self::MatchStar(node) => node.range(), - Self::MatchAs(node) => node.range(), - Self::MatchOr(node) => node.range(), - } - } -} - -impl LocatedMut for Pattern { - fn range_mut(&mut self) -> &mut SourceRange { - match self { - Self::MatchValue(node) => node.range_mut(), - Self::MatchSingleton(node) => node.range_mut(), - Self::MatchSequence(node) => node.range_mut(), - Self::MatchMapping(node) => node.range_mut(), - Self::MatchClass(node) => node.range_mut(), - Self::MatchStar(node) => node.range_mut(), - Self::MatchAs(node) => node.range_mut(), - Self::MatchOr(node) => node.range_mut(), - } - } -} - -pub type TypeIgnore = crate::generic::TypeIgnore; - -pub type TypeIgnoreTypeIgnore = crate::generic::TypeIgnoreTypeIgnore; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for TypeIgnoreTypeIgnore { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for TypeIgnoreTypeIgnore { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for TypeIgnore { - fn range(&self) -> SourceRange { - match self { - Self::TypeIgnore(node) => node.range(), - } - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for TypeIgnore { - fn range_mut(&mut self) -> &mut SourceRange { - match self { - Self::TypeIgnore(node) => node.range_mut(), - } - } -} - -pub type Decorator = crate::generic::Decorator; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for Decorator { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for Decorator { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type Arguments = crate::generic::Arguments; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for Arguments { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for Arguments { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} - -pub type ArgWithDefault = crate::generic::ArgWithDefault; - -#[cfg(feature = "all-nodes-with-ranges")] -impl Located for ArgWithDefault { - fn range(&self) -> SourceRange { - self.range - } -} -#[cfg(feature = "all-nodes-with-ranges")] -impl LocatedMut for ArgWithDefault { - fn range_mut(&mut self) -> &mut SourceRange { - &mut self.range - } -} diff --git a/ast/src/gen/visitor.rs b/ast/src/gen/visitor.rs deleted file mode 100644 index b7be112272264..0000000000000 --- a/ast/src/gen/visitor.rs +++ /dev/null @@ -1,817 +0,0 @@ -// File automatically generated by ast/asdl_rs.py. - -#[allow(unused_variables)] -pub trait Visitor { - fn visit_stmt(&mut self, node: Stmt) { - self.generic_visit_stmt(node) - } - fn generic_visit_stmt(&mut self, node: Stmt) { - match node { - Stmt::FunctionDef(data) => self.visit_stmt_function_def(data), - Stmt::AsyncFunctionDef(data) => self.visit_stmt_async_function_def(data), - Stmt::ClassDef(data) => self.visit_stmt_class_def(data), - Stmt::Return(data) => self.visit_stmt_return(data), - Stmt::Delete(data) => self.visit_stmt_delete(data), - Stmt::Assign(data) => self.visit_stmt_assign(data), - Stmt::AugAssign(data) => self.visit_stmt_aug_assign(data), - Stmt::AnnAssign(data) => self.visit_stmt_ann_assign(data), - Stmt::For(data) => self.visit_stmt_for(data), - Stmt::AsyncFor(data) => self.visit_stmt_async_for(data), - Stmt::While(data) => self.visit_stmt_while(data), - Stmt::If(data) => self.visit_stmt_if(data), - Stmt::With(data) => self.visit_stmt_with(data), - Stmt::AsyncWith(data) => self.visit_stmt_async_with(data), - Stmt::Match(data) => self.visit_stmt_match(data), - Stmt::Raise(data) => self.visit_stmt_raise(data), - Stmt::Try(data) => self.visit_stmt_try(data), - Stmt::TryStar(data) => self.visit_stmt_try_star(data), - Stmt::Assert(data) => self.visit_stmt_assert(data), - Stmt::Import(data) => self.visit_stmt_import(data), - Stmt::ImportFrom(data) => self.visit_stmt_import_from(data), - Stmt::Global(data) => self.visit_stmt_global(data), - Stmt::Nonlocal(data) => self.visit_stmt_nonlocal(data), - Stmt::Expr(data) => self.visit_stmt_expr(data), - Stmt::Pass(data) => self.visit_stmt_pass(data), - Stmt::Break(data) => self.visit_stmt_break(data), - Stmt::Continue(data) => self.visit_stmt_continue(data), - } - } - fn visit_stmt_function_def(&mut self, node: StmtFunctionDef) { - self.generic_visit_stmt_function_def(node) - } - fn generic_visit_stmt_function_def(&mut self, node: StmtFunctionDef) { - { - let value = node.args; - self.visit_arguments(*value); - } - for value in node.body { - self.visit_stmt(value); - } - for value in node.decorator_list { - self.visit_decorator(value); - } - if let Some(value) = node.returns { - self.visit_expr(*value); - } - } - fn visit_stmt_async_function_def(&mut self, node: StmtAsyncFunctionDef) { - self.generic_visit_stmt_async_function_def(node) - } - fn generic_visit_stmt_async_function_def(&mut self, node: StmtAsyncFunctionDef) { - { - let value = node.args; - self.visit_arguments(*value); - } - for value in node.body { - self.visit_stmt(value); - } - for value in node.decorator_list { - self.visit_decorator(value); - } - if let Some(value) = node.returns { - self.visit_expr(*value); - } - } - fn visit_stmt_class_def(&mut self, node: StmtClassDef) { - self.generic_visit_stmt_class_def(node) - } - fn generic_visit_stmt_class_def(&mut self, node: StmtClassDef) { - for value in node.bases { - self.visit_expr(value); - } - for value in node.keywords { - self.visit_keyword(value); - } - for value in node.body { - self.visit_stmt(value); - } - for value in node.decorator_list { - self.visit_decorator(value); - } - } - fn visit_stmt_return(&mut self, node: StmtReturn) { - self.generic_visit_stmt_return(node) - } - fn generic_visit_stmt_return(&mut self, node: StmtReturn) { - if let Some(value) = node.value { - self.visit_expr(*value); - } - } - fn visit_stmt_delete(&mut self, node: StmtDelete) { - self.generic_visit_stmt_delete(node) - } - fn generic_visit_stmt_delete(&mut self, node: StmtDelete) { - for value in node.targets { - self.visit_expr(value); - } - } - fn visit_stmt_assign(&mut self, node: StmtAssign) { - self.generic_visit_stmt_assign(node) - } - fn generic_visit_stmt_assign(&mut self, node: StmtAssign) { - for value in node.targets { - self.visit_expr(value); - } - { - let value = node.value; - self.visit_expr(*value); - } - } - fn visit_stmt_aug_assign(&mut self, node: StmtAugAssign) { - self.generic_visit_stmt_aug_assign(node) - } - fn generic_visit_stmt_aug_assign(&mut self, node: StmtAugAssign) { - { - let value = node.target; - self.visit_expr(*value); - } - { - let value = node.value; - self.visit_expr(*value); - } - } - fn visit_stmt_ann_assign(&mut self, node: StmtAnnAssign) { - self.generic_visit_stmt_ann_assign(node) - } - fn generic_visit_stmt_ann_assign(&mut self, node: StmtAnnAssign) { - { - let value = node.target; - self.visit_expr(*value); - } - { - let value = node.annotation; - self.visit_expr(*value); - } - if let Some(value) = node.value { - self.visit_expr(*value); - } - } - fn visit_stmt_for(&mut self, node: StmtFor) { - self.generic_visit_stmt_for(node) - } - fn generic_visit_stmt_for(&mut self, node: StmtFor) { - { - let value = node.target; - self.visit_expr(*value); - } - { - let value = node.iter; - self.visit_expr(*value); - } - for value in node.body { - self.visit_stmt(value); - } - for value in node.orelse { - self.visit_stmt(value); - } - } - fn visit_stmt_async_for(&mut self, node: StmtAsyncFor) { - self.generic_visit_stmt_async_for(node) - } - fn generic_visit_stmt_async_for(&mut self, node: StmtAsyncFor) { - { - let value = node.target; - self.visit_expr(*value); - } - { - let value = node.iter; - self.visit_expr(*value); - } - for value in node.body { - self.visit_stmt(value); - } - for value in node.orelse { - self.visit_stmt(value); - } - } - fn visit_stmt_while(&mut self, node: StmtWhile) { - self.generic_visit_stmt_while(node) - } - fn generic_visit_stmt_while(&mut self, node: StmtWhile) { - { - let value = node.test; - self.visit_expr(*value); - } - for value in node.body { - self.visit_stmt(value); - } - for value in node.orelse { - self.visit_stmt(value); - } - } - fn visit_stmt_if(&mut self, node: StmtIf) { - self.generic_visit_stmt_if(node) - } - fn generic_visit_stmt_if(&mut self, node: StmtIf) { - { - let value = node.test; - self.visit_expr(*value); - } - for value in node.body { - self.visit_stmt(value); - } - for value in node.orelse { - self.visit_stmt(value); - } - } - fn visit_stmt_with(&mut self, node: StmtWith) { - self.generic_visit_stmt_with(node) - } - fn generic_visit_stmt_with(&mut self, node: StmtWith) { - for value in node.items { - self.visit_withitem(value); - } - for value in node.body { - self.visit_stmt(value); - } - } - fn visit_stmt_async_with(&mut self, node: StmtAsyncWith) { - self.generic_visit_stmt_async_with(node) - } - fn generic_visit_stmt_async_with(&mut self, node: StmtAsyncWith) { - for value in node.items { - self.visit_withitem(value); - } - for value in node.body { - self.visit_stmt(value); - } - } - fn visit_stmt_match(&mut self, node: StmtMatch) { - self.generic_visit_stmt_match(node) - } - fn generic_visit_stmt_match(&mut self, node: StmtMatch) { - { - let value = node.subject; - self.visit_expr(*value); - } - for value in node.cases { - self.visit_match_case(value); - } - } - fn visit_stmt_raise(&mut self, node: StmtRaise) { - self.generic_visit_stmt_raise(node) - } - fn generic_visit_stmt_raise(&mut self, node: StmtRaise) { - if let Some(value) = node.exc { - self.visit_expr(*value); - } - if let Some(value) = node.cause { - self.visit_expr(*value); - } - } - fn visit_stmt_try(&mut self, node: StmtTry) { - self.generic_visit_stmt_try(node) - } - fn generic_visit_stmt_try(&mut self, node: StmtTry) { - for value in node.body { - self.visit_stmt(value); - } - for value in node.handlers { - self.visit_excepthandler(value); - } - for value in node.orelse { - self.visit_stmt(value); - } - for value in node.finalbody { - self.visit_stmt(value); - } - } - fn visit_stmt_try_star(&mut self, node: StmtTryStar) { - self.generic_visit_stmt_try_star(node) - } - fn generic_visit_stmt_try_star(&mut self, node: StmtTryStar) { - for value in node.body { - self.visit_stmt(value); - } - for value in node.handlers { - self.visit_excepthandler(value); - } - for value in node.orelse { - self.visit_stmt(value); - } - for value in node.finalbody { - self.visit_stmt(value); - } - } - fn visit_stmt_assert(&mut self, node: StmtAssert) { - self.generic_visit_stmt_assert(node) - } - fn generic_visit_stmt_assert(&mut self, node: StmtAssert) { - { - let value = node.test; - self.visit_expr(*value); - } - if let Some(value) = node.msg { - self.visit_expr(*value); - } - } - fn visit_stmt_import(&mut self, node: StmtImport) { - self.generic_visit_stmt_import(node) - } - fn generic_visit_stmt_import(&mut self, node: StmtImport) { - for value in node.names { - self.visit_alias(value); - } - } - fn visit_stmt_import_from(&mut self, node: StmtImportFrom) { - self.generic_visit_stmt_import_from(node) - } - fn generic_visit_stmt_import_from(&mut self, node: StmtImportFrom) { - for value in node.names { - self.visit_alias(value); - } - } - fn visit_stmt_global(&mut self, node: StmtGlobal) { - self.generic_visit_stmt_global(node) - } - fn generic_visit_stmt_global(&mut self, node: StmtGlobal) {} - fn visit_stmt_nonlocal(&mut self, node: StmtNonlocal) { - self.generic_visit_stmt_nonlocal(node) - } - fn generic_visit_stmt_nonlocal(&mut self, node: StmtNonlocal) {} - fn visit_stmt_expr(&mut self, node: StmtExpr) { - self.generic_visit_stmt_expr(node) - } - fn generic_visit_stmt_expr(&mut self, node: StmtExpr) { - { - let value = node.value; - self.visit_expr(*value); - } - } - fn visit_stmt_pass(&mut self, node: StmtPass) {} - fn visit_stmt_break(&mut self, node: StmtBreak) {} - fn visit_stmt_continue(&mut self, node: StmtContinue) {} - fn visit_expr(&mut self, node: Expr) { - self.generic_visit_expr(node) - } - fn generic_visit_expr(&mut self, node: Expr) { - match node { - Expr::BoolOp(data) => self.visit_expr_bool_op(data), - Expr::NamedExpr(data) => self.visit_expr_named_expr(data), - Expr::BinOp(data) => self.visit_expr_bin_op(data), - Expr::UnaryOp(data) => self.visit_expr_unary_op(data), - Expr::Lambda(data) => self.visit_expr_lambda(data), - Expr::IfExp(data) => self.visit_expr_if_exp(data), - Expr::Dict(data) => self.visit_expr_dict(data), - Expr::Set(data) => self.visit_expr_set(data), - Expr::ListComp(data) => self.visit_expr_list_comp(data), - Expr::SetComp(data) => self.visit_expr_set_comp(data), - Expr::DictComp(data) => self.visit_expr_dict_comp(data), - Expr::GeneratorExp(data) => self.visit_expr_generator_exp(data), - Expr::Await(data) => self.visit_expr_await(data), - Expr::Yield(data) => self.visit_expr_yield(data), - Expr::YieldFrom(data) => self.visit_expr_yield_from(data), - Expr::Compare(data) => self.visit_expr_compare(data), - Expr::Call(data) => self.visit_expr_call(data), - Expr::FormattedValue(data) => self.visit_expr_formatted_value(data), - Expr::JoinedStr(data) => self.visit_expr_joined_str(data), - Expr::Constant(data) => self.visit_expr_constant(data), - Expr::Attribute(data) => self.visit_expr_attribute(data), - Expr::Subscript(data) => self.visit_expr_subscript(data), - Expr::Starred(data) => self.visit_expr_starred(data), - Expr::Name(data) => self.visit_expr_name(data), - Expr::List(data) => self.visit_expr_list(data), - Expr::Tuple(data) => self.visit_expr_tuple(data), - Expr::Slice(data) => self.visit_expr_slice(data), - } - } - fn visit_expr_bool_op(&mut self, node: ExprBoolOp) { - self.generic_visit_expr_bool_op(node) - } - fn generic_visit_expr_bool_op(&mut self, node: ExprBoolOp) { - for value in node.values { - self.visit_expr(value); - } - } - fn visit_expr_named_expr(&mut self, node: ExprNamedExpr) { - self.generic_visit_expr_named_expr(node) - } - fn generic_visit_expr_named_expr(&mut self, node: ExprNamedExpr) { - { - let value = node.target; - self.visit_expr(*value); - } - { - let value = node.value; - self.visit_expr(*value); - } - } - fn visit_expr_bin_op(&mut self, node: ExprBinOp) { - self.generic_visit_expr_bin_op(node) - } - fn generic_visit_expr_bin_op(&mut self, node: ExprBinOp) { - { - let value = node.left; - self.visit_expr(*value); - } - { - let value = node.right; - self.visit_expr(*value); - } - } - fn visit_expr_unary_op(&mut self, node: ExprUnaryOp) { - self.generic_visit_expr_unary_op(node) - } - fn generic_visit_expr_unary_op(&mut self, node: ExprUnaryOp) { - { - let value = node.operand; - self.visit_expr(*value); - } - } - fn visit_expr_lambda(&mut self, node: ExprLambda) { - self.generic_visit_expr_lambda(node) - } - fn generic_visit_expr_lambda(&mut self, node: ExprLambda) { - { - let value = node.args; - self.visit_arguments(*value); - } - { - let value = node.body; - self.visit_expr(*value); - } - } - fn visit_expr_if_exp(&mut self, node: ExprIfExp) { - self.generic_visit_expr_if_exp(node) - } - fn generic_visit_expr_if_exp(&mut self, node: ExprIfExp) { - { - let value = node.test; - self.visit_expr(*value); - } - { - let value = node.body; - self.visit_expr(*value); - } - { - let value = node.orelse; - self.visit_expr(*value); - } - } - fn visit_expr_dict(&mut self, node: ExprDict) { - self.generic_visit_expr_dict(node) - } - fn generic_visit_expr_dict(&mut self, node: ExprDict) { - for value in node.keys.into_iter().flatten() { - self.visit_expr(value); - } - for value in node.values { - self.visit_expr(value); - } - } - fn visit_expr_set(&mut self, node: ExprSet) { - self.generic_visit_expr_set(node) - } - fn generic_visit_expr_set(&mut self, node: ExprSet) { - for value in node.elts { - self.visit_expr(value); - } - } - fn visit_expr_list_comp(&mut self, node: ExprListComp) { - self.generic_visit_expr_list_comp(node) - } - fn generic_visit_expr_list_comp(&mut self, node: ExprListComp) { - { - let value = node.elt; - self.visit_expr(*value); - } - for value in node.generators { - self.visit_comprehension(value); - } - } - fn visit_expr_set_comp(&mut self, node: ExprSetComp) { - self.generic_visit_expr_set_comp(node) - } - fn generic_visit_expr_set_comp(&mut self, node: ExprSetComp) { - { - let value = node.elt; - self.visit_expr(*value); - } - for value in node.generators { - self.visit_comprehension(value); - } - } - fn visit_expr_dict_comp(&mut self, node: ExprDictComp) { - self.generic_visit_expr_dict_comp(node) - } - fn generic_visit_expr_dict_comp(&mut self, node: ExprDictComp) { - { - let value = node.key; - self.visit_expr(*value); - } - { - let value = node.value; - self.visit_expr(*value); - } - for value in node.generators { - self.visit_comprehension(value); - } - } - fn visit_expr_generator_exp(&mut self, node: ExprGeneratorExp) { - self.generic_visit_expr_generator_exp(node) - } - fn generic_visit_expr_generator_exp(&mut self, node: ExprGeneratorExp) { - { - let value = node.elt; - self.visit_expr(*value); - } - for value in node.generators { - self.visit_comprehension(value); - } - } - fn visit_expr_await(&mut self, node: ExprAwait) { - self.generic_visit_expr_await(node) - } - fn generic_visit_expr_await(&mut self, node: ExprAwait) { - { - let value = node.value; - self.visit_expr(*value); - } - } - fn visit_expr_yield(&mut self, node: ExprYield) { - self.generic_visit_expr_yield(node) - } - fn generic_visit_expr_yield(&mut self, node: ExprYield) { - if let Some(value) = node.value { - self.visit_expr(*value); - } - } - fn visit_expr_yield_from(&mut self, node: ExprYieldFrom) { - self.generic_visit_expr_yield_from(node) - } - fn generic_visit_expr_yield_from(&mut self, node: ExprYieldFrom) { - { - let value = node.value; - self.visit_expr(*value); - } - } - fn visit_expr_compare(&mut self, node: ExprCompare) { - self.generic_visit_expr_compare(node) - } - fn generic_visit_expr_compare(&mut self, node: ExprCompare) { - { - let value = node.left; - self.visit_expr(*value); - } - for value in node.comparators { - self.visit_expr(value); - } - } - fn visit_expr_call(&mut self, node: ExprCall) { - self.generic_visit_expr_call(node) - } - fn generic_visit_expr_call(&mut self, node: ExprCall) { - { - let value = node.func; - self.visit_expr(*value); - } - for value in node.args { - self.visit_expr(value); - } - for value in node.keywords { - self.visit_keyword(value); - } - } - fn visit_expr_formatted_value(&mut self, node: ExprFormattedValue) { - self.generic_visit_expr_formatted_value(node) - } - fn generic_visit_expr_formatted_value(&mut self, node: ExprFormattedValue) { - { - let value = node.value; - self.visit_expr(*value); - } - if let Some(value) = node.format_spec { - self.visit_expr(*value); - } - } - fn visit_expr_joined_str(&mut self, node: ExprJoinedStr) { - self.generic_visit_expr_joined_str(node) - } - fn generic_visit_expr_joined_str(&mut self, node: ExprJoinedStr) { - for value in node.values { - self.visit_expr(value); - } - } - fn visit_expr_constant(&mut self, node: ExprConstant) { - self.generic_visit_expr_constant(node) - } - fn generic_visit_expr_constant(&mut self, node: ExprConstant) {} - fn visit_expr_attribute(&mut self, node: ExprAttribute) { - self.generic_visit_expr_attribute(node) - } - fn generic_visit_expr_attribute(&mut self, node: ExprAttribute) { - { - let value = node.value; - self.visit_expr(*value); - } - } - fn visit_expr_subscript(&mut self, node: ExprSubscript) { - self.generic_visit_expr_subscript(node) - } - fn generic_visit_expr_subscript(&mut self, node: ExprSubscript) { - { - let value = node.value; - self.visit_expr(*value); - } - { - let value = node.slice; - self.visit_expr(*value); - } - } - fn visit_expr_starred(&mut self, node: ExprStarred) { - self.generic_visit_expr_starred(node) - } - fn generic_visit_expr_starred(&mut self, node: ExprStarred) { - { - let value = node.value; - self.visit_expr(*value); - } - } - fn visit_expr_name(&mut self, node: ExprName) { - self.generic_visit_expr_name(node) - } - fn generic_visit_expr_name(&mut self, node: ExprName) {} - fn visit_expr_list(&mut self, node: ExprList) { - self.generic_visit_expr_list(node) - } - fn generic_visit_expr_list(&mut self, node: ExprList) { - for value in node.elts { - self.visit_expr(value); - } - } - fn visit_expr_tuple(&mut self, node: ExprTuple) { - self.generic_visit_expr_tuple(node) - } - fn generic_visit_expr_tuple(&mut self, node: ExprTuple) { - for value in node.elts { - self.visit_expr(value); - } - } - fn visit_expr_slice(&mut self, node: ExprSlice) { - self.generic_visit_expr_slice(node) - } - fn generic_visit_expr_slice(&mut self, node: ExprSlice) { - if let Some(value) = node.lower { - self.visit_expr(*value); - } - if let Some(value) = node.upper { - self.visit_expr(*value); - } - if let Some(value) = node.step { - self.visit_expr(*value); - } - } - fn visit_expr_context(&mut self, node: ExprContext) { - self.generic_visit_expr_context(node) - } - fn generic_visit_expr_context(&mut self, node: ExprContext) {} - fn visit_boolop(&mut self, node: BoolOp) { - self.generic_visit_boolop(node) - } - fn generic_visit_boolop(&mut self, node: BoolOp) {} - fn visit_operator(&mut self, node: Operator) { - self.generic_visit_operator(node) - } - fn generic_visit_operator(&mut self, node: Operator) {} - fn visit_unaryop(&mut self, node: UnaryOp) { - self.generic_visit_unaryop(node) - } - fn generic_visit_unaryop(&mut self, node: UnaryOp) {} - fn visit_cmpop(&mut self, node: CmpOp) { - self.generic_visit_cmpop(node) - } - fn generic_visit_cmpop(&mut self, node: CmpOp) {} - fn visit_comprehension(&mut self, node: Comprehension) { - self.generic_visit_comprehension(node) - } - fn generic_visit_comprehension(&mut self, node: Comprehension) {} - fn visit_excepthandler(&mut self, node: ExceptHandler) { - self.generic_visit_excepthandler(node) - } - fn generic_visit_excepthandler(&mut self, node: ExceptHandler) { - match node { - ExceptHandler::ExceptHandler(data) => self.visit_excepthandler_except_handler(data), - } - } - fn visit_excepthandler_except_handler(&mut self, node: ExceptHandlerExceptHandler) { - self.generic_visit_excepthandler_except_handler(node) - } - fn generic_visit_excepthandler_except_handler(&mut self, node: ExceptHandlerExceptHandler) { - if let Some(value) = node.type_ { - self.visit_expr(*value); - } - for value in node.body { - self.visit_stmt(value); - } - } - fn visit_arguments(&mut self, node: Arguments) { - self.generic_visit_arguments(node) - } - fn generic_visit_arguments(&mut self, node: Arguments) {} - fn visit_arg(&mut self, node: Arg) { - self.generic_visit_arg(node) - } - fn generic_visit_arg(&mut self, node: Arg) {} - fn visit_keyword(&mut self, node: Keyword) { - self.generic_visit_keyword(node) - } - fn generic_visit_keyword(&mut self, node: Keyword) {} - fn visit_alias(&mut self, node: Alias) { - self.generic_visit_alias(node) - } - fn generic_visit_alias(&mut self, node: Alias) {} - fn visit_withitem(&mut self, node: WithItem) { - self.generic_visit_withitem(node) - } - fn generic_visit_withitem(&mut self, node: WithItem) {} - fn visit_match_case(&mut self, node: MatchCase) { - self.generic_visit_match_case(node) - } - fn generic_visit_match_case(&mut self, node: MatchCase) {} - fn visit_pattern(&mut self, node: Pattern) { - self.generic_visit_pattern(node) - } - fn generic_visit_pattern(&mut self, node: Pattern) { - match node { - Pattern::MatchValue(data) => self.visit_pattern_match_value(data), - Pattern::MatchSingleton(data) => self.visit_pattern_match_singleton(data), - Pattern::MatchSequence(data) => self.visit_pattern_match_sequence(data), - Pattern::MatchMapping(data) => self.visit_pattern_match_mapping(data), - Pattern::MatchClass(data) => self.visit_pattern_match_class(data), - Pattern::MatchStar(data) => self.visit_pattern_match_star(data), - Pattern::MatchAs(data) => self.visit_pattern_match_as(data), - Pattern::MatchOr(data) => self.visit_pattern_match_or(data), - } - } - fn visit_pattern_match_value(&mut self, node: PatternMatchValue) { - self.generic_visit_pattern_match_value(node) - } - fn generic_visit_pattern_match_value(&mut self, node: PatternMatchValue) { - { - let value = node.value; - self.visit_expr(*value); - } - } - fn visit_pattern_match_singleton(&mut self, node: PatternMatchSingleton) { - self.generic_visit_pattern_match_singleton(node) - } - fn generic_visit_pattern_match_singleton(&mut self, node: PatternMatchSingleton) {} - fn visit_pattern_match_sequence(&mut self, node: PatternMatchSequence) { - self.generic_visit_pattern_match_sequence(node) - } - fn generic_visit_pattern_match_sequence(&mut self, node: PatternMatchSequence) { - for value in node.patterns { - self.visit_pattern(value); - } - } - fn visit_pattern_match_mapping(&mut self, node: PatternMatchMapping) { - self.generic_visit_pattern_match_mapping(node) - } - fn generic_visit_pattern_match_mapping(&mut self, node: PatternMatchMapping) { - for value in node.keys { - self.visit_expr(value); - } - for value in node.patterns { - self.visit_pattern(value); - } - } - fn visit_pattern_match_class(&mut self, node: PatternMatchClass) { - self.generic_visit_pattern_match_class(node) - } - fn generic_visit_pattern_match_class(&mut self, node: PatternMatchClass) { - { - let value = node.cls; - self.visit_expr(*value); - } - for value in node.patterns { - self.visit_pattern(value); - } - for value in node.kwd_patterns { - self.visit_pattern(value); - } - } - fn visit_pattern_match_star(&mut self, node: PatternMatchStar) { - self.generic_visit_pattern_match_star(node) - } - fn generic_visit_pattern_match_star(&mut self, node: PatternMatchStar) {} - fn visit_pattern_match_as(&mut self, node: PatternMatchAs) { - self.generic_visit_pattern_match_as(node) - } - fn generic_visit_pattern_match_as(&mut self, node: PatternMatchAs) { - if let Some(value) = node.pattern { - self.visit_pattern(*value); - } - } - fn visit_pattern_match_or(&mut self, node: PatternMatchOr) { - self.generic_visit_pattern_match_or(node) - } - fn generic_visit_pattern_match_or(&mut self, node: PatternMatchOr) { - for value in node.patterns { - self.visit_pattern(value); - } - } - fn visit_decorator(&mut self, node: Decorator) { - self.generic_visit_decorator(node) - } - fn generic_visit_decorator(&mut self, node: Decorator) {} -} diff --git a/ast/src/lib.rs b/ast/src/lib.rs index 4e5d37152a79d..9aa6da1de2066 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -19,8 +19,6 @@ mod builtin; mod generic; mod impls; mod ranged; -#[cfg(feature = "unparse")] -mod unparse; #[cfg(feature = "malachite-bigint")] pub use malachite_bigint as bigint; @@ -36,30 +34,3 @@ pub trait Node { const NAME: &'static str; const FIELD_NAMES: &'static [&'static str]; } - -#[cfg(feature = "fold")] -pub mod fold; -#[cfg(feature = "fold")] -pub use fold::Fold; - -#[cfg(feature = "visitor")] -mod visitor { - use super::generic::*; - - include!("gen/visitor.rs"); -} - -#[cfg(feature = "location")] -pub mod located; -#[cfg(feature = "location")] -mod source_locator; -#[cfg(feature = "location")] -pub use rustpython_parser_core::source_code; - -#[cfg(feature = "visitor")] -pub use visitor::Visitor; - -#[cfg(feature = "constant-optimization")] -mod optimizer; -#[cfg(feature = "constant-optimization")] -pub use optimizer::ConstantOptimizer; diff --git a/ast/src/located.rs b/ast/src/located.rs deleted file mode 100644 index bf252617cb969..0000000000000 --- a/ast/src/located.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![allow(clippy::derive_partial_eq_without_eq)] -use crate::source_code::{SourceLocation, SourceRange}; - -pub trait Located { - fn range(&self) -> SourceRange; - - fn location(&self) -> SourceLocation { - self.range().start - } - - fn end_location(&self) -> Option { - self.range().end - } -} - -pub trait LocatedMut: Located { - fn range_mut(&mut self) -> &mut SourceRange; -} - -pub type Suite = Vec; - -pub use crate::builtin::*; -include!("gen/located.rs"); diff --git a/ast/src/optimizer.rs b/ast/src/optimizer.rs deleted file mode 100644 index 42a6dddc7366e..0000000000000 --- a/ast/src/optimizer.rs +++ /dev/null @@ -1,131 +0,0 @@ -use crate::builtin::Constant; - -#[non_exhaustive] -#[derive(Default)] -pub struct ConstantOptimizer {} - -impl ConstantOptimizer { - #[inline] - pub fn new() -> Self { - Self {} - } -} - -#[cfg(feature = "constant-optimization")] -impl crate::fold::Fold for ConstantOptimizer { - type TargetU = U; - type Error = std::convert::Infallible; - type UserContext = (); - - #[inline(always)] - fn will_map_user(&mut self, _user: &U) -> Self::UserContext {} - #[inline] - fn map_user(&mut self, user: U, _context: ()) -> Result { - Ok(user) - } - fn fold_expr(&mut self, node: crate::Expr) -> Result, Self::Error> { - match node { - crate::Expr::Tuple(crate::ExprTuple { elts, ctx, range }) => { - let elts = elts - .into_iter() - .map(|x| self.fold_expr(x)) - .collect::, _>>()?; - let expr = if elts.iter().all(|e| e.is_constant_expr()) { - let tuple = elts - .into_iter() - .map(|e| match e { - crate::Expr::Constant(crate::ExprConstant { value, .. }) => value, - _ => unreachable!(), - }) - .collect(); - crate::Expr::Constant(crate::ExprConstant { - value: Constant::Tuple(tuple), - kind: None, - range, - }) - } else { - crate::Expr::Tuple(crate::ExprTuple { elts, ctx, range }) - }; - Ok(expr) - } - _ => crate::fold::fold_expr(self, node), - } - } -} - -#[cfg(test)] -mod tests { - use crate::bigint::BigInt; - use rustpython_parser_core::text_size::TextRange; - - #[cfg(feature = "constant-optimization")] - #[test] - fn test_constant_opt() { - use crate::{fold::Fold, *}; - - let range = TextRange::default(); - let ast = ExprTuple { - ctx: ExprContext::Load, - elts: vec![ - ExprConstant { - value: BigInt::from(1).into(), - kind: None, - range, - } - .into(), - ExprConstant { - value: BigInt::from(2).into(), - kind: None, - range, - } - .into(), - ExprTuple { - ctx: ExprContext::Load, - elts: vec![ - ExprConstant { - value: BigInt::from(3).into(), - kind: None, - range, - } - .into(), - ExprConstant { - value: BigInt::from(4).into(), - kind: None, - range, - } - .into(), - ExprConstant { - value: BigInt::from(5).into(), - kind: None, - range, - } - .into(), - ], - range, - } - .into(), - ], - range, - }; - let new_ast = ConstantOptimizer::new() - .fold_expr(ast.into()) - .unwrap_or_else(|e| match e {}); - assert_eq!( - new_ast, - ExprConstant { - value: Constant::Tuple(vec![ - BigInt::from(1).into(), - BigInt::from(2).into(), - Constant::Tuple(vec![ - BigInt::from(3).into(), - BigInt::from(4).into(), - BigInt::from(5).into(), - ]) - ]), - kind: None, - range, - } - .into(), - ); - } -} diff --git a/ast/src/source_locator.rs b/ast/src/source_locator.rs deleted file mode 100644 index 366c32bb0dc9a..0000000000000 --- a/ast/src/source_locator.rs +++ /dev/null @@ -1,288 +0,0 @@ -use crate::Fold; -use rustpython_parser_core::{ - source_code::{LinearLocator, RandomLocator, SourceLocation, SourceRange}, - text_size::TextRange, -}; -use std::{convert::Infallible, unreachable}; - -impl crate::fold::Fold for RandomLocator<'_> { - type TargetU = SourceRange; - type Error = std::convert::Infallible; - type UserContext = SourceLocation; - - fn will_map_user(&mut self, user: &TextRange) -> Self::UserContext { - self.locate(user.start()) - } - - fn map_user( - &mut self, - user: TextRange, - start: Self::UserContext, - ) -> Result { - let end = self.locate(user.end()); - Ok((start..end).into()) - } -} - -fn linear_locate_expr_joined_str( - locator: &mut LinearLocator<'_>, - node: crate::ExprJoinedStr, - location: SourceRange, -) -> Result, Infallible> { - let crate::ExprJoinedStr { range: _, values } = node; - - let mut located_values = Vec::with_capacity(values.len()); - for value in values.into_iter() { - let located = match value { - crate::Expr::Constant(constant) => { - let node = crate::ExprConstant { - range: location, - value: constant.value, - kind: constant.kind, - }; - crate::Expr::Constant(node) - } - crate::Expr::FormattedValue(formatted) => { - let node = crate::ExprFormattedValue { - range: location, - value: locator.fold(formatted.value)?, - conversion: formatted.conversion, - format_spec: formatted - .format_spec - .map(|spec| match *spec { - crate::Expr::JoinedStr(joined_str) => { - let node = - linear_locate_expr_joined_str(locator, joined_str, location)?; - Ok(crate::Expr::JoinedStr(node)) - } - expr => locator.fold(expr), - }) - .transpose()? - .map(Box::new), - }; - crate::Expr::FormattedValue(node) - } - _ => unreachable!("missing expr type for joined_str?"), - }; - located_values.push(located); - } - - Ok(crate::ExprJoinedStr { - range: location, - values: located_values, - }) -} - -impl crate::fold::Fold for LinearLocator<'_> { - type TargetU = SourceRange; - type Error = std::convert::Infallible; - type UserContext = SourceLocation; - - fn will_map_user(&mut self, user: &TextRange) -> Self::UserContext { - self.locate(user.start()) - } - - fn map_user( - &mut self, - user: TextRange, - start: Self::UserContext, - ) -> Result { - let end = self.locate(user.end()); - Ok((start..end).into()) - } - - fn fold_expr_dict( - &mut self, - node: crate::ExprDict, - ) -> Result, Self::Error> { - let crate::ExprDict { - range, - keys, - values, - } = node; - let context = self.will_map_user(&range); - assert_eq!(keys.len(), values.len()); - let mut located_keys = Vec::with_capacity(keys.len()); - let mut located_values = Vec::with_capacity(values.len()); - for (key, value) in keys.into_iter().zip(values.into_iter()) { - located_keys.push(self.fold(key)?); - located_values.push(self.fold(value)?); - } - let range = self.map_user(range, context)?; - Ok(crate::ExprDict { - range, - keys: located_keys, - values: located_values, - }) - } - - fn fold_expr_if_exp( - &mut self, - node: crate::ExprIfExp, - ) -> Result, Self::Error> { - let crate::ExprIfExp { - range, - test, - body, - orelse, - } = node; - let context = self.will_map_user(&range); - let body = self.fold(body)?; - let test = self.fold(test)?; - let orelse = self.fold(orelse)?; - let range = self.map_user(range, context)?; - Ok(crate::ExprIfExp { - range, - test, - body, - orelse, - }) - } - - fn fold_stmt_class_def( - &mut self, - node: crate::StmtClassDef, - ) -> Result, Self::Error> { - let crate::StmtClassDef { - name, - bases, - keywords, - body, - decorator_list, - range, - } = node; - let decorator_list = self.fold(decorator_list)?; - let context = self.will_map_user(&range); - - let name = self.fold(name)?; - let bases = self.fold(bases)?; - let keywords = self.fold(keywords)?; - let body = self.fold(body)?; - let range = self.map_user(range, context)?; - Ok(crate::StmtClassDef { - name, - bases, - keywords, - body, - decorator_list, - range, - }) - } - fn fold_stmt_function_def( - &mut self, - node: crate::StmtFunctionDef, - ) -> Result, Self::Error> { - let crate::StmtFunctionDef { - name, - args, - body, - decorator_list, - returns, - type_comment, - range, - } = node; - let decorator_list = self.fold(decorator_list)?; - let context = self.will_map_user(&range); - - let name = self.fold(name)?; - let args: Box> = self.fold(args)?; - let returns = self.fold(returns)?; - let body = self.fold(body)?; - let type_comment = self.fold(type_comment)?; - let range = self.map_user(range, context)?; - Ok(crate::StmtFunctionDef { - name, - args, - body, - decorator_list, - returns, - type_comment, - range, - }) - } - fn fold_stmt_async_function_def( - &mut self, - node: crate::StmtAsyncFunctionDef, - ) -> Result, Self::Error> { - let crate::StmtAsyncFunctionDef { - name, - args, - body, - decorator_list, - returns, - type_comment, - range, - } = node; - let decorator_list = self.fold(decorator_list)?; - let context = self.will_map_user(&range); - - let name = self.fold(name)?; - let args: Box> = self.fold(args)?; - let returns = self.fold(returns)?; - let body = self.fold(body)?; - let type_comment = self.fold(type_comment)?; - let range = self.map_user(range, context)?; - Ok(crate::StmtAsyncFunctionDef { - name, - args, - body, - decorator_list, - returns, - type_comment, - range, - }) - } - fn fold_expr_joined_str( - &mut self, - node: crate::ExprJoinedStr, - ) -> Result, Self::Error> { - let start = self.locate(node.range.start()); - let end = self.locate_only(node.range.end()); - let location = SourceRange::new(start, end); - linear_locate_expr_joined_str(self, node, location) - } - - fn fold_expr_call( - &mut self, - node: crate::ExprCall, - ) -> Result, Self::Error> { - let crate::ExprCall { - range, - func, - args, - keywords, - } = node; - let context = self.will_map_user(&range); - let func = self.fold(func)?; - let keywords = LinearLookaheadLocator(self).fold(keywords)?; - let args = self.fold(args)?; - let range = self.map_user(range, context)?; - Ok(crate::ExprCall { - range, - func, - args, - keywords, - }) - } -} - -struct LinearLookaheadLocator<'a, 'b>(&'b mut LinearLocator<'a>); - -impl crate::fold::Fold for LinearLookaheadLocator<'_, '_> { - type TargetU = SourceRange; - type Error = std::convert::Infallible; - type UserContext = SourceLocation; - - fn will_map_user(&mut self, user: &TextRange) -> Self::UserContext { - self.0.locate_only(user.start()) - } - - fn map_user( - &mut self, - user: TextRange, - start: Self::UserContext, - ) -> Result { - let end = self.0.locate_only(user.end()); - Ok((start..end).into()) - } -} diff --git a/ast/src/unparse.rs b/ast/src/unparse.rs deleted file mode 100644 index 95c0ba5b210f4..0000000000000 --- a/ast/src/unparse.rs +++ /dev/null @@ -1,638 +0,0 @@ -use crate::{ - Arg, ArgWithDefault, Arguments, BoolOp, Comprehension, Constant, ConversionFlag, Expr, - Identifier, Operator, PythonArguments, -}; -use std::fmt; - -mod precedence { - macro_rules! precedence { - ($($op:ident,)*) => { - precedence!(@0, $($op,)*); - }; - (@$i:expr, $op1:ident, $($op:ident,)*) => { - pub const $op1: u8 = $i; - precedence!(@$i + 1, $($op,)*); - }; - (@$i:expr,) => {}; - } - precedence!( - TUPLE, TEST, OR, AND, NOT, CMP, // "EXPR" = - BOR, BXOR, BAND, SHIFT, ARITH, TERM, FACTOR, POWER, AWAIT, ATOM, - ); - pub const EXPR: u8 = BOR; -} - -#[repr(transparent)] -struct Unparser<'a> { - f: fmt::Formatter<'a>, -} -impl<'a> Unparser<'a> { - fn new<'b>(f: &'b mut fmt::Formatter<'a>) -> &'b mut Unparser<'a> { - unsafe { &mut *(f as *mut fmt::Formatter<'a> as *mut Unparser<'a>) } - } - - fn p(&mut self, s: &str) -> fmt::Result { - self.f.write_str(s) - } - fn p_id(&mut self, s: &Identifier) -> fmt::Result { - self.f.write_str(s.as_str()) - } - fn p_if(&mut self, cond: bool, s: &str) -> fmt::Result { - if cond { - self.f.write_str(s)?; - } - Ok(()) - } - fn p_delim(&mut self, first: &mut bool, s: &str) -> fmt::Result { - self.p_if(!std::mem::take(first), s) - } - fn write_fmt(&mut self, f: fmt::Arguments<'_>) -> fmt::Result { - self.f.write_fmt(f) - } - - fn unparse_expr(&mut self, ast: &Expr, level: u8) -> fmt::Result { - macro_rules! op_prec { - ($op_ty:ident, $x:expr, $enu:path, $($var:ident($op:literal, $prec:ident)),*$(,)?) => { - match $x { - $(<$enu>::$var => (op_prec!(@space $op_ty, $op), precedence::$prec),)* - } - }; - (@space bin, $op:literal) => { - concat!(" ", $op, " ") - }; - (@space un, $op:literal) => { - $op - }; - } - macro_rules! group_if { - ($lvl:expr, $body:block) => {{ - let group = level > $lvl; - self.p_if(group, "(")?; - let ret = $body; - self.p_if(group, ")")?; - ret - }}; - } - match &ast { - Expr::BoolOp(crate::ExprBoolOp { - op, - values, - range: _range, - }) => { - let (op, prec) = op_prec!(bin, op, BoolOp, And("and", AND), Or("or", OR)); - group_if!(prec, { - let mut first = true; - for val in values { - self.p_delim(&mut first, op)?; - self.unparse_expr(val, prec + 1)?; - } - }) - } - Expr::NamedExpr(crate::ExprNamedExpr { - target, - value, - range: _range, - }) => { - group_if!(precedence::TUPLE, { - self.unparse_expr(target, precedence::ATOM)?; - self.p(" := ")?; - self.unparse_expr(value, precedence::ATOM)?; - }) - } - Expr::BinOp(crate::ExprBinOp { - left, - op, - right, - range: _range, - }) => { - let right_associative = matches!(op, Operator::Pow); - let (op, prec) = op_prec!( - bin, - op, - Operator, - Add("+", ARITH), - Sub("-", ARITH), - Mult("*", TERM), - MatMult("@", TERM), - Div("/", TERM), - Mod("%", TERM), - Pow("**", POWER), - LShift("<<", SHIFT), - RShift(">>", SHIFT), - BitOr("|", BOR), - BitXor("^", BXOR), - BitAnd("&", BAND), - FloorDiv("//", TERM), - ); - group_if!(prec, { - self.unparse_expr(left, prec + right_associative as u8)?; - self.p(op)?; - self.unparse_expr(right, prec + !right_associative as u8)?; - }) - } - Expr::UnaryOp(crate::ExprUnaryOp { - op, - operand, - range: _range, - }) => { - let (op, prec) = op_prec!( - un, - op, - crate::UnaryOp, - Invert("~", FACTOR), - Not("not ", NOT), - UAdd("+", FACTOR), - USub("-", FACTOR) - ); - group_if!(prec, { - self.p(op)?; - self.unparse_expr(operand, prec)?; - }) - } - Expr::Lambda(crate::ExprLambda { - args, - body, - range: _range, - }) => { - group_if!(precedence::TEST, { - let pos = args.args.len() + args.posonlyargs.len(); - self.p(if pos > 0 { "lambda " } else { "lambda" })?; - self.unparse_arguments(args)?; - write!(self, ": {}", **body)?; - }) - } - Expr::IfExp(crate::ExprIfExp { - test, - body, - orelse, - range: _range, - }) => { - group_if!(precedence::TEST, { - self.unparse_expr(body, precedence::TEST + 1)?; - self.p(" if ")?; - self.unparse_expr(test, precedence::TEST + 1)?; - self.p(" else ")?; - self.unparse_expr(orelse, precedence::TEST)?; - }) - } - Expr::Dict(crate::ExprDict { - keys, - values, - range: _range, - }) => { - self.p("{")?; - let mut first = true; - let (packed, unpacked) = values.split_at(keys.len()); - for (k, v) in keys.iter().zip(packed) { - self.p_delim(&mut first, ", ")?; - if let Some(k) = k { - write!(self, "{}: {}", *k, *v)?; - } else { - write!(self, "**{}", *v)?; - } - } - for d in unpacked { - self.p_delim(&mut first, ", ")?; - write!(self, "**{}", *d)?; - } - self.p("}")?; - } - Expr::Set(crate::ExprSet { - elts, - range: _range, - }) => { - self.p("{")?; - let mut first = true; - for v in elts { - self.p_delim(&mut first, ", ")?; - self.unparse_expr(v, precedence::TEST)?; - } - self.p("}")?; - } - Expr::ListComp(crate::ExprListComp { - elt, - generators, - range: _range, - }) => { - self.p("[")?; - self.unparse_expr(elt, precedence::TEST)?; - self.unparse_comp(generators)?; - self.p("]")?; - } - Expr::SetComp(crate::ExprSetComp { - elt, - generators, - range: _range, - }) => { - self.p("{")?; - self.unparse_expr(elt, precedence::TEST)?; - self.unparse_comp(generators)?; - self.p("}")?; - } - Expr::DictComp(crate::ExprDictComp { - key, - value, - generators, - range: _range, - }) => { - self.p("{")?; - self.unparse_expr(key, precedence::TEST)?; - self.p(": ")?; - self.unparse_expr(value, precedence::TEST)?; - self.unparse_comp(generators)?; - self.p("}")?; - } - Expr::GeneratorExp(crate::ExprGeneratorExp { - elt, - generators, - range: _range, - }) => { - self.p("(")?; - self.unparse_expr(elt, precedence::TEST)?; - self.unparse_comp(generators)?; - self.p(")")?; - } - Expr::Await(crate::ExprAwait { - value, - range: _range, - }) => { - group_if!(precedence::AWAIT, { - self.p("await ")?; - self.unparse_expr(value, precedence::ATOM)?; - }) - } - Expr::Yield(crate::ExprYield { - value, - range: _range, - }) => { - if let Some(value) = value { - write!(self, "(yield {})", **value)?; - } else { - self.p("(yield)")?; - } - } - Expr::YieldFrom(crate::ExprYieldFrom { - value, - range: _range, - }) => { - write!(self, "(yield from {})", **value)?; - } - Expr::Compare(crate::ExprCompare { - left, - ops, - comparators, - range: _range, - }) => { - group_if!(precedence::CMP, { - let new_lvl = precedence::CMP + 1; - self.unparse_expr(left, new_lvl)?; - for (op, cmp) in ops.iter().zip(comparators) { - self.p(" ")?; - self.p(op.as_str())?; - self.p(" ")?; - self.unparse_expr(cmp, new_lvl)?; - } - }) - } - Expr::Call(crate::ExprCall { - func, - args, - keywords, - range: _range, - }) => { - self.unparse_expr(func, precedence::ATOM)?; - self.p("(")?; - if let ( - [Expr::GeneratorExp(crate::ExprGeneratorExp { - elt, - generators, - range: _range, - })], - [], - ) = (&**args, &**keywords) - { - // make sure a single genexpr doesn't get double parens - self.unparse_expr(elt, precedence::TEST)?; - self.unparse_comp(generators)?; - } else { - let mut first = true; - for arg in args { - self.p_delim(&mut first, ", ")?; - self.unparse_expr(arg, precedence::TEST)?; - } - for kw in keywords { - self.p_delim(&mut first, ", ")?; - if let Some(arg) = &kw.arg { - self.p_id(arg)?; - self.p("=")?; - } else { - self.p("**")?; - } - self.unparse_expr(&kw.value, precedence::TEST)?; - } - } - self.p(")")?; - } - Expr::FormattedValue(crate::ExprFormattedValue { - value, - conversion, - format_spec, - range: _range, - }) => self.unparse_formatted(value, *conversion, format_spec.as_deref())?, - Expr::JoinedStr(crate::ExprJoinedStr { - values, - range: _range, - }) => self.unparse_joined_str(values, false)?, - Expr::Constant(crate::ExprConstant { - value, - kind, - range: _range, - }) => { - if let Some(kind) = kind { - self.p(kind)?; - } - assert_eq!(f64::MAX_10_EXP, 308); - let inf_str = "1e309"; - match value { - Constant::Float(f) if f.is_infinite() => self.p(inf_str)?, - Constant::Complex { real, imag } - if real.is_infinite() || imag.is_infinite() => - { - self.p(&value.to_string().replace("inf", inf_str))? - } - _ => fmt::Display::fmt(value, &mut self.f)?, - } - } - Expr::Attribute(crate::ExprAttribute { value, attr, .. }) => { - self.unparse_expr(value, precedence::ATOM)?; - let period = if let Expr::Constant(crate::ExprConstant { - value: Constant::Int(_), - .. - }) = value.as_ref() - { - " ." - } else { - "." - }; - self.p(period)?; - self.p_id(attr)?; - } - Expr::Subscript(crate::ExprSubscript { value, slice, .. }) => { - self.unparse_expr(value, precedence::ATOM)?; - let mut lvl = precedence::TUPLE; - if let Expr::Tuple(crate::ExprTuple { elts, .. }) = slice.as_ref() { - if elts.iter().any(|expr| expr.is_starred_expr()) { - lvl += 1 - } - } - self.p("[")?; - self.unparse_expr(slice, lvl)?; - self.p("]")?; - } - Expr::Starred(crate::ExprStarred { value, .. }) => { - self.p("*")?; - self.unparse_expr(value, precedence::EXPR)?; - } - Expr::Name(crate::ExprName { id, .. }) => self.p_id(id)?, - Expr::List(crate::ExprList { elts, .. }) => { - self.p("[")?; - let mut first = true; - for elt in elts { - self.p_delim(&mut first, ", ")?; - self.unparse_expr(elt, precedence::TEST)?; - } - self.p("]")?; - } - Expr::Tuple(crate::ExprTuple { elts, .. }) => { - if elts.is_empty() { - self.p("()")?; - } else { - group_if!(precedence::TUPLE, { - let mut first = true; - for elt in elts { - self.p_delim(&mut first, ", ")?; - self.unparse_expr(elt, precedence::TEST)?; - } - self.p_if(elts.len() == 1, ",")?; - }) - } - } - Expr::Slice(crate::ExprSlice { - lower, - upper, - step, - range: _range, - }) => { - if let Some(lower) = lower { - self.unparse_expr(lower, precedence::TEST)?; - } - self.p(":")?; - if let Some(upper) = upper { - self.unparse_expr(upper, precedence::TEST)?; - } - if let Some(step) = step { - self.p(":")?; - self.unparse_expr(step, precedence::TEST)?; - } - } - } - Ok(()) - } - - fn unparse_arguments(&mut self, args: &Arguments) -> fmt::Result { - let mut first = true; - for (i, arg) in args.posonlyargs.iter().chain(&args.args).enumerate() { - self.p_delim(&mut first, ", ")?; - self.unparse_function_arg(arg)?; - self.p_if(i + 1 == args.posonlyargs.len(), ", /")?; - } - if args.vararg.is_some() || !args.kwonlyargs.is_empty() { - self.p_delim(&mut first, ", ")?; - self.p("*")?; - } - if let Some(vararg) = &args.vararg { - self.unparse_arg(vararg)?; - } - for kwarg in args.kwonlyargs.iter() { - self.p_delim(&mut first, ", ")?; - self.unparse_function_arg(kwarg)?; - } - if let Some(kwarg) = &args.kwarg { - self.p_delim(&mut first, ", ")?; - self.p("**")?; - self.unparse_arg(kwarg)?; - } - Ok(()) - } - fn unparse_function_arg(&mut self, arg: &ArgWithDefault) -> fmt::Result { - self.p_id(&arg.def.arg)?; - if let Some(ann) = &arg.def.annotation { - write!(self, ": {}", **ann)?; - } - if let Some(default) = &arg.default { - write!(self, "={}", default)?; - } - Ok(()) - } - - #[allow(dead_code)] - fn unparse_python_arguments(&mut self, args: &PythonArguments) -> fmt::Result { - let mut first = true; - let defaults_start = args.posonlyargs.len() + args.args.len() - args.defaults.len(); - for (i, arg) in args.posonlyargs.iter().chain(&args.args).enumerate() { - self.p_delim(&mut first, ", ")?; - self.unparse_arg(arg)?; - if let Some(i) = i.checked_sub(defaults_start) { - write!(self, "={}", &args.defaults[i])?; - } - self.p_if(i + 1 == args.posonlyargs.len(), ", /")?; - } - if args.vararg.is_some() || !args.kwonlyargs.is_empty() { - self.p_delim(&mut first, ", ")?; - self.p("*")?; - } - if let Some(vararg) = &args.vararg { - self.unparse_arg(vararg)?; - } - let defaults_start = args.kwonlyargs.len() - args.kw_defaults.len(); - for (i, kwarg) in args.kwonlyargs.iter().enumerate() { - self.p_delim(&mut first, ", ")?; - self.unparse_arg(kwarg)?; - if let Some(default) = i - .checked_sub(defaults_start) - .and_then(|i| args.kw_defaults.get(i)) - { - write!(self, "={default}")?; - } - } - if let Some(kwarg) = &args.kwarg { - self.p_delim(&mut first, ", ")?; - self.p("**")?; - self.unparse_arg(kwarg)?; - } - Ok(()) - } - fn unparse_arg(&mut self, arg: &Arg) -> fmt::Result { - self.p_id(&arg.arg)?; - if let Some(ann) = &arg.annotation { - write!(self, ": {}", **ann)?; - } - Ok(()) - } - - fn unparse_comp(&mut self, generators: &[Comprehension]) -> fmt::Result { - for comp in generators { - self.p(if comp.is_async { - " async for " - } else { - " for " - })?; - self.unparse_expr(&comp.target, precedence::TUPLE)?; - self.p(" in ")?; - self.unparse_expr(&comp.iter, precedence::TEST + 1)?; - for cond in &comp.ifs { - self.p(" if ")?; - self.unparse_expr(cond, precedence::TEST + 1)?; - } - } - Ok(()) - } - - fn unparse_fstring_body(&mut self, values: &[Expr], is_spec: bool) -> fmt::Result { - for value in values { - self.unparse_fstring_elem(value, is_spec)?; - } - Ok(()) - } - - fn unparse_formatted( - &mut self, - val: &Expr, - conversion: ConversionFlag, - spec: Option<&Expr>, - ) -> fmt::Result { - let buffered = to_string_fmt(|f| Unparser::new(f).unparse_expr(val, precedence::TEST + 1)); - let brace = if buffered.starts_with('{') { - // put a space to avoid escaping the bracket - "{ " - } else { - "{" - }; - self.p(brace)?; - self.p(&buffered)?; - drop(buffered); - - if conversion != ConversionFlag::None { - self.p("!")?; - let buf = &[conversion as u8]; - let c = std::str::from_utf8(buf).unwrap(); - self.p(c)?; - } - - if let Some(spec) = spec { - self.p(":")?; - self.unparse_fstring_elem(spec, true)?; - } - - self.p("}")?; - - Ok(()) - } - - fn unparse_fstring_elem(&mut self, expr: &Expr, is_spec: bool) -> fmt::Result { - match &expr { - Expr::Constant(crate::ExprConstant { value, .. }) => { - if let Constant::Str(s) = value { - self.unparse_fstring_str(s) - } else { - unreachable!() - } - } - Expr::JoinedStr(crate::ExprJoinedStr { - values, - range: _range, - }) => self.unparse_joined_str(values, is_spec), - Expr::FormattedValue(crate::ExprFormattedValue { - value, - conversion, - format_spec, - range: _range, - }) => self.unparse_formatted(value, *conversion, format_spec.as_deref()), - _ => unreachable!(), - } - } - - fn unparse_fstring_str(&mut self, s: &str) -> fmt::Result { - let s = s.replace('{', "{{").replace('}', "}}"); - self.p(&s) - } - - fn unparse_joined_str(&mut self, values: &[Expr], is_spec: bool) -> fmt::Result { - if is_spec { - self.unparse_fstring_body(values, is_spec) - } else { - self.p("f")?; - let body = to_string_fmt(|f| Unparser::new(f).unparse_fstring_body(values, is_spec)); - rustpython_literal::escape::UnicodeEscape::new_repr(&body) - .str_repr() - .write(&mut self.f) - } - } -} - -impl fmt::Display for Expr { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - Unparser::new(f).unparse_expr(self, precedence::TEST) - } -} - -fn to_string_fmt(f: impl FnOnce(&mut fmt::Formatter) -> fmt::Result) -> String { - use std::cell::Cell; - struct Fmt(Cell>); - impl fmt::Result> fmt::Display for Fmt { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.take().unwrap()(f) - } - } - Fmt(Cell::new(Some(f))).to_string() -} diff --git a/core/Cargo.toml b/core/Cargo.toml index 867a146a7fe89..82e1cae5a4171 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -10,7 +10,6 @@ license = "MIT" [dependencies] # ruff dependency shouldn't be placed out of this crate ruff_text_size = { path = "../ruff_text_size" } -ruff_source_location = { path = "../ruff_source_location", optional = true } serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] } is-macro.workspace = true @@ -18,4 +17,3 @@ memchr.workspace = true [features] default = [] -location = ["dep:ruff_source_location"] diff --git a/core/src/lib.rs b/core/src/lib.rs index 06b2d3bfb5ffa..47dc115cb5fe1 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -4,8 +4,6 @@ mod error; mod format; pub mod mode; -#[cfg(feature = "location")] -pub mod source_code; pub use error::BaseError; pub use format::ConversionFlag; diff --git a/core/src/source_code.rs b/core/src/source_code.rs deleted file mode 100644 index b45f20067c156..0000000000000 --- a/core/src/source_code.rs +++ /dev/null @@ -1,347 +0,0 @@ -// re-export our public interface -use crate::text_size::{TextLen, TextSize}; -use memchr::memrchr2; - -pub use ruff_source_location::{ - newlines::{find_newline, UniversalNewlineIterator}, - LineIndex, OneIndexed, SourceCode, SourceLocation, -}; -pub type LineNumber = OneIndexed; - -#[derive(Debug, Copy, Clone, Default)] -pub struct SourceRange { - pub start: SourceLocation, - pub end: Option, -} - -impl SourceRange { - pub fn new(start: SourceLocation, end: SourceLocation) -> Self { - Self { - start, - end: Some(end), - } - } - pub fn unwrap_end(&self) -> SourceLocation { - self.end.unwrap() - } -} - -impl From> for SourceRange { - fn from(value: std::ops::Range) -> Self { - Self { - start: value.start, - end: Some(value.end), - } - } -} - -/// Converts source code byte-offset to Python convention line and column numbers. -pub struct RandomLocator<'a> { - pub source: &'a str, - index: LineIndex, -} - -impl<'a> RandomLocator<'a> { - #[inline] - pub fn new(source: &'a str) -> Self { - let index = LineIndex::from_source_text(source); - Self { source, index } - } - - pub fn to_source_code(&self) -> SourceCode { - SourceCode::new(self.source, &self.index) - } - - pub fn locate(&mut self, offset: crate::text_size::TextSize) -> SourceLocation { - let offset = offset.to_u32().into(); - self.to_source_code().source_location(offset) - } - - pub fn locate_error(&mut self, base: crate::error::BaseError) -> LocatedError - where - T: Into, - { - let location = self.locate(base.offset); - LocatedError { - error: base.error.into(), - location: Some(location), - source_path: base.source_path, - } - } -} - -/// Converts source code byte-offset to Python convention line and column numbers. -pub struct LinearLocator<'a> { - pub source: &'a str, - state: LinearLocatorState, - #[cfg(debug_assertions)] - index: LineIndex, -} - -struct LinearLocatorState { - line_start: TextSize, - line_end: Option, - line_number: OneIndexed, - cursor: TextSize, - is_ascii: bool, -} - -impl LinearLocatorState { - fn init(source: &str) -> Self { - let mut line_start = TextSize::default(); - if source.starts_with('\u{feff}') { - line_start += '\u{feff}'.text_len(); - } - let (line_end, is_ascii) = if let Some((position, line_ending)) = find_newline(source) { - let is_ascii = source[..position].is_ascii(); - ( - Some(TextSize::new(position as u32 + line_ending.len() as u32)), - is_ascii, - ) - } else { - (None, source.is_ascii()) - }; - let line_number = OneIndexed::MIN; - Self { - line_start, - line_end, - line_number, - cursor: line_start, - is_ascii, - } - } - - fn new_line_start(&self, next_offset: TextSize) -> Option { - if let Some(new_line_start) = self.line_end { - if new_line_start <= next_offset { - return Some(new_line_start); - } - } - None - } -} - -impl<'a> LinearLocator<'a> { - // nl = newline - - #[inline] - pub fn new(source: &'a str) -> Self { - let state = LinearLocatorState::init(source); - Self { - source, - state, - #[cfg(debug_assertions)] - index: LineIndex::from_source_text(source), - } - } - - pub fn locate(&mut self, offset: crate::text_size::TextSize) -> SourceLocation { - debug_assert!( - self.state.cursor <= offset, - "{:?} -> {:?} {}", - self.state.cursor, - offset, - &self.source[offset.to_usize()..self.state.cursor.to_usize()] - ); - let (column, new_state) = self.locate_inner(offset); - if let Some(state) = new_state { - self.state = state; - } else { - self.state.cursor = offset; - } - SourceLocation { - row: self.state.line_number, - column, - } - } - - pub fn locate_only(&mut self, offset: crate::text_size::TextSize) -> SourceLocation { - let (column, new_state) = self.locate_inner(offset); - let state = new_state.as_ref().unwrap_or(&self.state); - SourceLocation { - row: state.line_number, - column, - } - } - - fn locate_inner( - &mut self, - offset: crate::text_size::TextSize, - ) -> (OneIndexed, Option) { - let (column, new_state) = if let Some(new_line_start) = self.state.new_line_start(offset) { - // not fit in current line - let focused = &self.source[new_line_start.to_usize()..offset.to_usize()]; - let (lines, line_start, column) = - if let Some(last_newline) = memrchr2(b'\r', b'\n', focused.as_bytes()) { - let last_newline = new_line_start.to_usize() + last_newline; - let lines = UniversalNewlineIterator::from( - &self.source[self.state.cursor.to_usize()..last_newline + 1], - ) - .count(); - let line_start = last_newline as u32 + 1; - let column = offset.to_u32() - line_start; - (lines as u32, line_start, column) - } else { - let column = (offset - new_line_start).to_u32(); - (1, new_line_start.to_u32(), column) - }; - let line_number = self.state.line_number.saturating_add(lines); - let (line_end, is_ascii) = if let Some((newline, line_ending)) = - find_newline(&self.source[line_start as usize..]) - { - let newline = line_start as usize + newline; - let is_ascii = self.source[line_start as usize..newline].is_ascii(); - ( - Some(TextSize::new(newline as u32 + line_ending.len() as u32)), - is_ascii, - ) - } else { - let is_ascii = self.source[line_start as usize..].is_ascii(); - (None, is_ascii) - }; - let line_start = TextSize::new(line_start); - let state = LinearLocatorState { - line_start, - line_end, - line_number, - cursor: offset, - is_ascii, - }; - (column, Some(state)) - } else { - let column = (offset - self.state.line_start).to_u32(); - (column, None) - }; - let state = new_state.as_ref().unwrap_or(&self.state); - let column = if state.is_ascii { - column - } else { - self.source[state.line_start.to_usize()..][..column as usize] - .chars() - .count() as u32 - }; - let column = OneIndexed::from_zero_indexed(column); - #[cfg(debug_assertions)] - { - let location = SourceLocation { - row: state.line_number, - column, - }; - let source_code = SourceCode::new(self.source, &self.index); - assert_eq!( - location, - source_code.source_location(offset), - "input: {} -> {} {}", - self.state.cursor.to_usize(), - offset.to_usize(), - &self.source[self.state.cursor.to_usize()..offset.to_usize()] - ); - } - (column, new_state) - } - - pub fn locate_error(&mut self, base: crate::error::BaseError) -> LocatedError - where - T: Into, - { - let location = self.locate(base.offset); - LocatedError { - error: base.error.into(), - location: Some(location), - source_path: base.source_path, - } - } -} - -#[derive(Debug, PartialEq, Eq)] -pub struct LocatedError { - pub error: T, - pub location: Option, - pub source_path: String, -} - -impl LocatedError { - pub fn error(self) -> T { - self.error - } - - pub fn from(obj: LocatedError) -> Self - where - U: Into, - { - Self { - error: obj.error.into(), - location: obj.location, - source_path: obj.source_path, - } - } - - pub fn into(self) -> LocatedError - where - T: Into, - { - LocatedError::from(self) - } - - pub fn python_location(&self) -> (usize, usize) { - if let Some(location) = self.location { - (location.row.to_usize(), location.column.to_usize()) - } else { - (0, 0) - } - } -} - -impl std::fmt::Display for LocatedError -where - T: std::fmt::Display, -{ - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - let (row, column) = self - .location - .map_or((0, 0), |l| (l.row.to_usize(), l.column.to_usize())); - write!(f, "{} at row {} col {}", &self.error, row, column,) - } -} - -impl std::error::Error for LocatedError -where - T: std::error::Error + 'static, -{ - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - Some(&self.error) - } -} - -#[test] -fn test_linear_locator() { - let source = r#" -123456789 -abcdefghi - -유니코드 - "# - .strip_prefix(char::is_whitespace) - .unwrap(); - let mut locator = LinearLocator::new(source); - let mut random_locator = RandomLocator::new(source); - - let mut test = |(row, col), offset| { - let input = TextSize::from(offset); - let expected: SourceLocation = SourceLocation { - row: OneIndexed::new(row).unwrap(), - column: OneIndexed::new(col).unwrap(), - }; - let actual = locator.locate(input); - let actual2 = random_locator.locate(input); - assert_eq!(expected, actual); - assert_eq!(expected, actual2); - }; - - test((1, 1), 0); - test((1, 6), 5); - test((1, 9), 8); - test((2, 1), 10); - test((4, 1), 21); - test((4, 3), 27); -} diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 863a28a57aa4d..0ce4b3ccfff43 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -9,8 +9,7 @@ license = "MIT" edition = "2021" [features] -default = ["location", "malachite-bigint"] -location = ["rustpython-ast/location", "rustpython-parser-core/location"] +default = ["malachite-bigint"] serde = ["dep:serde", "rustpython-parser-core/serde"] all-nodes-with-ranges = ["rustpython-ast/all-nodes-with-ranges"] full-lexer = [] diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 53cec986839f4..5b56e54a54e1b 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -113,8 +113,6 @@ #![doc(html_root_url = "https://docs.rs/rustpython-parser/")] pub use rustpython_ast as ast; -#[cfg(feature = "location")] -pub use rustpython_parser_core::source_code; pub use rustpython_parser_core::{text_size, Mode}; mod function; diff --git a/ruff_source_location/Cargo.toml b/ruff_source_location/Cargo.toml deleted file mode 100644 index 3512307563a63..0000000000000 --- a/ruff_source_location/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -# NOTE: RUSTPYTHON -# This crate is not a real crate of ruff, but cut off a part of `ruff_python_ast` and vendored it to avoid cross dependency - -[package] -name = "ruff_source_location" -version = "0.0.0" -publish = false -edition = { workspace = true } -rust-version = { workspace = true } - -[lib] - -[dependencies] -ruff_text_size = { path = "../ruff_text_size" } - -memchr = { workspace = true } -once_cell = { workspace = true } diff --git a/ruff_source_location/src/lib.rs b/ruff_source_location/src/lib.rs deleted file mode 100644 index c7e8b9f677218..0000000000000 --- a/ruff_source_location/src/lib.rs +++ /dev/null @@ -1,227 +0,0 @@ -mod line_index; -// mod locator; -pub mod newlines; - -pub use crate::line_index::{LineIndex, OneIndexed}; -// TODO: RUSTPYTHON; import it later -// pub use locator::Locator; -use ruff_text_size::{TextRange, TextSize}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; -use std::fmt::{Debug, Formatter}; -use std::sync::Arc; - -/// Gives access to the source code of a file and allows mapping between [`TextSize`] and [`SourceLocation`]. -#[derive(Debug)] -pub struct SourceCode<'src, 'index> { - text: &'src str, - index: &'index LineIndex, -} - -impl<'src, 'index> SourceCode<'src, 'index> { - pub fn new(content: &'src str, index: &'index LineIndex) -> Self { - Self { - text: content, - index, - } - } - - /// Computes the one indexed row and column numbers for `offset`. - #[inline] - pub fn source_location(&self, offset: TextSize) -> SourceLocation { - self.index.source_location(offset, self.text) - } - - #[inline] - pub fn line_index(&self, offset: TextSize) -> OneIndexed { - self.index.line_index(offset) - } - - /// Take the source code up to the given [`TextSize`]. - #[inline] - pub fn up_to(&self, offset: TextSize) -> &'src str { - &self.text[TextRange::up_to(offset)] - } - - /// Take the source code after the given [`TextSize`]. - #[inline] - pub fn after(&self, offset: TextSize) -> &'src str { - &self.text[usize::from(offset)..] - } - - /// Take the source code between the given [`TextRange`]. - pub fn slice(&self, range: TextRange) -> &'src str { - &self.text[range] - } - - pub fn line_start(&self, line: OneIndexed) -> TextSize { - self.index.line_start(line, self.text) - } - - pub fn line_end(&self, line: OneIndexed) -> TextSize { - self.index.line_end(line, self.text) - } - - pub fn line_range(&self, line: OneIndexed) -> TextRange { - self.index.line_range(line, self.text) - } - - /// Returns the source text of the line with the given index - #[inline] - pub fn line_text(&self, index: OneIndexed) -> &'src str { - let range = self.index.line_range(index, self.text); - &self.text[range] - } - - /// Returns the source text - pub fn text(&self) -> &'src str { - self.text - } - - /// Returns the number of lines - #[inline] - pub fn line_count(&self) -> usize { - self.index.line_count() - } -} - -impl PartialEq for SourceCode<'_, '_> { - fn eq(&self, other: &Self) -> bool { - self.text == other.text - } -} - -impl Eq for SourceCode<'_, '_> {} - -/// A Builder for constructing a [`SourceFile`] -pub struct SourceFileBuilder { - name: Box, - code: Box, - index: Option, -} - -impl SourceFileBuilder { - /// Creates a new builder for a file named `name`. - pub fn new>, Code: Into>>(name: Name, code: Code) -> Self { - Self { - name: name.into(), - code: code.into(), - index: None, - } - } - - #[must_use] - pub fn line_index(mut self, index: LineIndex) -> Self { - self.index = Some(index); - self - } - - pub fn set_line_index(&mut self, index: LineIndex) { - self.index = Some(index); - } - - /// Consumes `self` and returns the [`SourceFile`]. - pub fn finish(self) -> SourceFile { - let index = if let Some(index) = self.index { - once_cell::sync::OnceCell::with_value(index) - } else { - once_cell::sync::OnceCell::new() - }; - - SourceFile { - inner: Arc::new(SourceFileInner { - name: self.name, - code: self.code, - line_index: index, - }), - } - } -} - -/// A source file that is identified by its name. Optionally stores the source code and [`LineIndex`]. -/// -/// Cloning a [`SourceFile`] is cheap, because it only requires bumping a reference count. -#[derive(Clone, Eq, PartialEq)] -pub struct SourceFile { - inner: Arc, -} - -impl Debug for SourceFile { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.debug_struct("SourceFile") - .field("name", &self.name()) - .field("code", &self.source_text()) - .finish() - } -} - -impl SourceFile { - /// Returns the name of the source file (filename). - #[inline] - pub fn name(&self) -> &str { - &self.inner.name - } - - #[inline] - pub fn slice(&self, range: TextRange) -> &str { - &self.source_text()[range] - } - - pub fn to_source_code(&self) -> SourceCode { - SourceCode { - text: self.source_text(), - index: self.index(), - } - } - - fn index(&self) -> &LineIndex { - self.inner - .line_index - .get_or_init(|| LineIndex::from_source_text(self.source_text())) - } - - /// Returns `Some` with the source text if set, or `None`. - #[inline] - pub fn source_text(&self) -> &str { - &self.inner.code - } -} - -struct SourceFileInner { - name: Box, - code: Box, - line_index: once_cell::sync::OnceCell, -} - -impl PartialEq for SourceFileInner { - fn eq(&self, other: &Self) -> bool { - self.name == other.name && self.code == other.code - } -} - -impl Eq for SourceFileInner {} - -#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Copy)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct SourceLocation { - pub row: OneIndexed, - pub column: OneIndexed, -} - -impl Default for SourceLocation { - fn default() -> Self { - Self { - row: OneIndexed::MIN, - column: OneIndexed::MIN, - } - } -} - -impl Debug for SourceLocation { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.debug_struct("SourceLocation") - .field("row", &self.row.get()) - .field("column", &self.column.get()) - .finish() - } -} diff --git a/ruff_source_location/src/line_index.rs b/ruff_source_location/src/line_index.rs deleted file mode 100644 index 35041b00b9d16..0000000000000 --- a/ruff_source_location/src/line_index.rs +++ /dev/null @@ -1,630 +0,0 @@ -use crate::SourceLocation; -use ruff_text_size::{TextLen, TextRange, TextSize}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; -use std::fmt; -use std::fmt::{Debug, Formatter}; -use std::num::NonZeroU32; -use std::ops::Deref; -use std::sync::Arc; - -/// Index for fast [byte offset](TextSize) to [`SourceLocation`] conversions. -/// -/// Cloning a [`LineIndex`] is cheap because it only requires bumping a reference count. -#[derive(Clone)] -pub struct LineIndex { - inner: Arc, -} - -struct LineIndexInner { - line_starts: Vec, - kind: IndexKind, -} - -impl LineIndex { - /// Builds the [`LineIndex`] from the source text of a file. - pub fn from_source_text(text: &str) -> Self { - let mut line_starts: Vec = Vec::with_capacity(text.len() / 88); - line_starts.push(TextSize::default()); - - let bytes = text.as_bytes(); - let mut utf8 = false; - - assert!(u32::try_from(bytes.len()).is_ok()); - - for (i, byte) in bytes.iter().enumerate() { - utf8 |= !byte.is_ascii(); - - match byte { - // Only track one line break for `\r\n`. - b'\r' if bytes.get(i + 1) == Some(&b'\n') => continue, - b'\n' | b'\r' => { - // SAFETY: Assertion above guarantees `i <= u32::MAX` - #[allow(clippy::cast_possible_truncation)] - line_starts.push(TextSize::from(i as u32) + TextSize::from(1)); - } - _ => {} - } - } - - let kind = if utf8 { - IndexKind::Utf8 - } else { - IndexKind::Ascii - }; - - Self { - inner: Arc::new(LineIndexInner { line_starts, kind }), - } - } - - fn kind(&self) -> IndexKind { - self.inner.kind - } - - /// Returns the row and column index for an offset. - /// - /// ## Examples - /// - /// ``` - /// # use ruff_text_size::TextSize; - /// # use ruff_source_location::{LineIndex, OneIndexed, SourceLocation}; - /// let source = "def a():\n pass"; - /// let index = LineIndex::from_source_text(source); - /// - /// assert_eq!( - /// index.source_location(TextSize::from(0), source), - /// SourceLocation { row: OneIndexed::from_zero_indexed(0), column: OneIndexed::from_zero_indexed(0) } - /// ); - /// - /// assert_eq!( - /// index.source_location(TextSize::from(4), source), - /// SourceLocation { row: OneIndexed::from_zero_indexed(0), column: OneIndexed::from_zero_indexed(4) } - /// ); - /// assert_eq!( - /// index.source_location(TextSize::from(13), source), - /// SourceLocation { row: OneIndexed::from_zero_indexed(1), column: OneIndexed::from_zero_indexed(4) } - /// ); - /// ``` - /// - /// ## Panics - /// - /// If the offset is out of bounds. - pub fn source_location(&self, offset: TextSize, content: &str) -> SourceLocation { - match self.binary_search_line(&offset) { - // Offset is at the start of a line - Ok(row) => SourceLocation { - row: OneIndexed::from_zero_indexed(row), - column: OneIndexed::from_zero_indexed(0), - }, - Err(next_row) => { - // SAFETY: Safe because the index always contains an entry for the offset 0 - let row = next_row - 1; - let mut line_start = self.line_starts()[row as usize]; - - let column = if self.kind().is_ascii() { - u32::from(offset - line_start) - } else { - // Don't count the BOM character as a column. - if line_start == TextSize::from(0) && content.starts_with('\u{feff}') { - line_start = '\u{feff}'.text_len(); - } - - let range = TextRange::new(line_start, offset); - content[range].chars().count().try_into().unwrap() - }; - - SourceLocation { - row: OneIndexed::from_zero_indexed(row), - column: OneIndexed::from_zero_indexed(column), - } - } - } - } - - /// Return the number of lines in the source code. - pub(crate) fn line_count(&self) -> usize { - self.line_starts().len() - } - - /// Returns the row number for a given offset. - /// - /// ## Examples - /// - /// ``` - /// # use ruff_text_size::TextSize; - /// # use ruff_source_location::{LineIndex, OneIndexed, SourceLocation}; - /// let source = "def a():\n pass"; - /// let index = LineIndex::from_source_text(source); - /// - /// assert_eq!(index.line_index(TextSize::from(0)), OneIndexed::from_zero_indexed(0)); - /// assert_eq!(index.line_index(TextSize::from(4)), OneIndexed::from_zero_indexed(0)); - /// assert_eq!(index.line_index(TextSize::from(13)), OneIndexed::from_zero_indexed(1)); - /// ``` - /// - /// ## Panics - /// - /// If the offset is out of bounds. - pub fn line_index(&self, offset: TextSize) -> OneIndexed { - match self.binary_search_line(&offset) { - // Offset is at the start of a line - Ok(row) => OneIndexed::from_zero_indexed(row), - Err(row) => { - // SAFETY: Safe because the index always contains an entry for the offset 0 - OneIndexed::from_zero_indexed(row - 1) - } - } - } - - /// Returns the [byte offset](TextSize) for the `line` with the given index. - pub(crate) fn line_start(&self, line: OneIndexed, contents: &str) -> TextSize { - let row_index = line.to_zero_indexed_usize(); - let starts = self.line_starts(); - - // If start-of-line position after last line - if row_index == starts.len() { - contents.text_len() - } else { - starts[row_index] - } - } - - /// Returns the [byte offset](TextSize) of the `line`'s end. - /// The offset is the end of the line, up to and including the newline character ending the line (if any). - pub(crate) fn line_end(&self, line: OneIndexed, contents: &str) -> TextSize { - let row_index = line.to_zero_indexed_usize(); - let starts = self.line_starts(); - - // If start-of-line position after last line - if row_index.saturating_add(1) >= starts.len() { - contents.text_len() - } else { - starts[row_index + 1] - } - } - - /// Returns the [`TextRange`] of the `line` with the given index. - /// The start points to the first character's [byte offset](TextSize), the end up to, and including - /// the newline character ending the line (if any). - pub(crate) fn line_range(&self, line: OneIndexed, contents: &str) -> TextRange { - let starts = self.line_starts(); - - if starts.len() == line.to_zero_indexed_usize() { - TextRange::empty(contents.text_len()) - } else { - TextRange::new( - self.line_start(line, contents), - self.line_start(line.saturating_add(1), contents), - ) - } - } - - /// Returns the [byte offsets](TextSize) for every line - pub fn line_starts(&self) -> &[TextSize] { - &self.inner.line_starts - } - - #[allow(clippy::trivially_copy_pass_by_ref)] // to keep same interface as `[T]::binary_search` - fn binary_search_line(&self, offset: &TextSize) -> Result { - // `try_into()` always success as long as TextSize is u32 - match self.line_starts().binary_search(offset) { - Ok(index) => Ok(index.try_into().unwrap()), - Err(index) => Err(index.try_into().unwrap()), - } - } -} - -impl Deref for LineIndex { - type Target = [TextSize]; - - fn deref(&self) -> &Self::Target { - self.line_starts() - } -} - -impl Debug for LineIndex { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - f.debug_list().entries(self.line_starts()).finish() - } -} - -#[derive(Debug, Clone, Copy)] -enum IndexKind { - /// Optimized index for an ASCII only document - Ascii, - - /// Index for UTF8 documents - Utf8, -} - -impl IndexKind { - const fn is_ascii(self) -> bool { - matches!(self, IndexKind::Ascii) - } -} - -/// Type-safe wrapper for a value whose logical range starts at `1`, for -/// instance the line or column numbers in a file -/// -/// Internally this is represented as a [`NonZeroU32`], this enables some -/// memory optimizations -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct OneIndexed(NonZeroU32); - -#[allow(clippy::cast_possible_truncation)] // manually checked -const fn try_to_u32(value: usize) -> Result { - if value <= u32::MAX as usize { - Ok(value as u32) - } else { - Err(value) - } -} - -impl OneIndexed { - // SAFETY: These constants are being initialized with non-zero values - /// The smallest value that can be represented by this integer type. - pub const MIN: Self = unwrap(Self::new(1)); - /// The largest value that can be represented by this integer type - pub const MAX: Self = unwrap(Self::new(u32::MAX)); - - const ONE: NonZeroU32 = unwrap(NonZeroU32::new(1)); - - /// Creates a non-zero if the given value is not zero. - pub const fn new(value: u32) -> Option { - match NonZeroU32::new(value) { - Some(value) => Some(Self(value)), - None => None, - } - } - - /// Construct a new [`OneIndexed`] from a zero-indexed value - pub const fn from_zero_indexed(value: u32) -> Self { - Self(Self::ONE.saturating_add(value)) - } - - /// Construct a new [`OneIndexed`] from a zero-indexed usize value - pub const fn try_from_zero_indexed(value: usize) -> Result { - match try_to_u32(value) { - Ok(value) => Ok(Self(Self::ONE.saturating_add(value))), - Err(value) => Err(value), - } - } - - /// Returns the value as a primitive type. - pub const fn get(self) -> u32 { - self.0.get() - } - - /// Return the usize value for this [`OneIndexed`] - pub const fn to_usize(self) -> usize { - self.get() as _ - } - - /// Return the zero-indexed primitive value for this [`OneIndexed`] - pub const fn to_zero_indexed(self) -> u32 { - self.0.get() - 1 - } - - /// Return the zero-indexed usize value for this [`OneIndexed`] - pub const fn to_zero_indexed_usize(self) -> usize { - self.to_zero_indexed() as _ - } - - /// Saturating integer addition. Computes `self + rhs`, saturating at - /// the numeric bounds instead of overflowing. - #[must_use] - pub const fn saturating_add(self, rhs: u32) -> Self { - match NonZeroU32::new(self.0.get().saturating_add(rhs)) { - Some(value) => Self(value), - None => Self::MAX, - } - } - - /// Saturating integer subtraction. Computes `self - rhs`, saturating - /// at the numeric bounds instead of overflowing. - #[must_use] - pub const fn saturating_sub(self, rhs: u32) -> Self { - match NonZeroU32::new(self.0.get().saturating_sub(rhs)) { - Some(value) => Self(value), - None => Self::MIN, - } - } -} - -impl std::fmt::Display for OneIndexed { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Debug::fmt(&self.0.get(), f) - } -} - -/// A const `Option::unwrap` without nightly features: -/// [Tracking issue](https://github.com/rust-lang/rust/issues/67441) -const fn unwrap(option: Option) -> T { - match option { - Some(value) => value, - None => panic!("unwrapping None"), - } -} - -#[cfg(test)] -mod tests { - use crate::line_index::LineIndex; - use crate::{OneIndexed, SourceLocation}; - use ruff_text_size::TextSize; - - #[test] - fn ascii_index() { - let index = LineIndex::from_source_text(""); - assert_eq!(index.line_starts(), &[TextSize::from(0)]); - - let index = LineIndex::from_source_text("x = 1"); - assert_eq!(index.line_starts(), &[TextSize::from(0)]); - - let index = LineIndex::from_source_text("x = 1\n"); - assert_eq!(index.line_starts(), &[TextSize::from(0), TextSize::from(6)]); - - let index = LineIndex::from_source_text("x = 1\ny = 2\nz = x + y\n"); - assert_eq!( - index.line_starts(), - &[ - TextSize::from(0), - TextSize::from(6), - TextSize::from(12), - TextSize::from(22) - ] - ); - } - - #[test] - fn ascii_source_location() { - let contents = "x = 1\ny = 2"; - let index = LineIndex::from_source_text(contents); - - // First row. - let loc = index.source_location(TextSize::from(2), contents); - assert_eq!( - loc, - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(2) - } - ); - - // Second row. - let loc = index.source_location(TextSize::from(6), contents); - assert_eq!( - loc, - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(0) - } - ); - - let loc = index.source_location(TextSize::from(11), contents); - assert_eq!( - loc, - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(5) - } - ); - } - - #[test] - fn ascii_carriage_return() { - let contents = "x = 4\ry = 3"; - let index = LineIndex::from_source_text(contents); - assert_eq!(index.line_starts(), &[TextSize::from(0), TextSize::from(6)]); - - assert_eq!( - index.source_location(TextSize::from(4), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(4) - } - ); - assert_eq!( - index.source_location(TextSize::from(6), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(0) - } - ); - assert_eq!( - index.source_location(TextSize::from(7), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(1) - } - ); - } - - #[test] - fn ascii_carriage_return_newline() { - let contents = "x = 4\r\ny = 3"; - let index = LineIndex::from_source_text(contents); - assert_eq!(index.line_starts(), &[TextSize::from(0), TextSize::from(7)]); - - assert_eq!( - index.source_location(TextSize::from(4), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(4) - } - ); - assert_eq!( - index.source_location(TextSize::from(7), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(0) - } - ); - assert_eq!( - index.source_location(TextSize::from(8), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(1) - } - ); - } - - #[test] - fn utf8_index() { - let index = LineIndex::from_source_text("x = '🫣'"); - assert_eq!(index.line_count(), 1); - assert_eq!(index.line_starts(), &[TextSize::from(0)]); - - let index = LineIndex::from_source_text("x = '🫣'\n"); - assert_eq!(index.line_count(), 2); - assert_eq!( - index.line_starts(), - &[TextSize::from(0), TextSize::from(11)] - ); - - let index = LineIndex::from_source_text("x = '🫣'\ny = 2\nz = x + y\n"); - assert_eq!(index.line_count(), 4); - assert_eq!( - index.line_starts(), - &[ - TextSize::from(0), - TextSize::from(11), - TextSize::from(17), - TextSize::from(27) - ] - ); - - let index = LineIndex::from_source_text("# 🫣\nclass Foo:\n \"\"\".\"\"\""); - assert_eq!(index.line_count(), 3); - assert_eq!( - index.line_starts(), - &[TextSize::from(0), TextSize::from(7), TextSize::from(18)] - ); - } - - #[test] - fn utf8_carriage_return() { - let contents = "x = '🫣'\ry = 3"; - let index = LineIndex::from_source_text(contents); - assert_eq!(index.line_count(), 2); - assert_eq!( - index.line_starts(), - &[TextSize::from(0), TextSize::from(11)] - ); - - // Second ' - assert_eq!( - index.source_location(TextSize::from(9), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(6) - } - ); - assert_eq!( - index.source_location(TextSize::from(11), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(0) - } - ); - assert_eq!( - index.source_location(TextSize::from(12), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(1) - } - ); - } - - #[test] - fn utf8_carriage_return_newline() { - let contents = "x = '🫣'\r\ny = 3"; - let index = LineIndex::from_source_text(contents); - assert_eq!(index.line_count(), 2); - assert_eq!( - index.line_starts(), - &[TextSize::from(0), TextSize::from(12)] - ); - - // Second ' - assert_eq!( - index.source_location(TextSize::from(9), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(6) - } - ); - assert_eq!( - index.source_location(TextSize::from(12), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(0) - } - ); - assert_eq!( - index.source_location(TextSize::from(13), contents), - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(1) - } - ); - } - - #[test] - fn utf8_byte_offset() { - let contents = "x = '☃'\ny = 2"; - let index = LineIndex::from_source_text(contents); - assert_eq!( - index.line_starts(), - &[TextSize::from(0), TextSize::from(10)] - ); - - // First row. - let loc = index.source_location(TextSize::from(0), contents); - assert_eq!( - loc, - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(0) - } - ); - - let loc = index.source_location(TextSize::from(5), contents); - assert_eq!( - loc, - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(5) - } - ); - - let loc = index.source_location(TextSize::from(8), contents); - assert_eq!( - loc, - SourceLocation { - row: OneIndexed::from_zero_indexed(0), - column: OneIndexed::from_zero_indexed(6) - } - ); - - // Second row. - let loc = index.source_location(TextSize::from(10), contents); - assert_eq!( - loc, - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(0) - } - ); - - // One-past-the-end. - let loc = index.source_location(TextSize::from(15), contents); - assert_eq!( - loc, - SourceLocation { - row: OneIndexed::from_zero_indexed(1), - column: OneIndexed::from_zero_indexed(5) - } - ); - } -} diff --git a/ruff_source_location/src/newlines.rs b/ruff_source_location/src/newlines.rs deleted file mode 100644 index 75d778b8cd5df..0000000000000 --- a/ruff_source_location/src/newlines.rs +++ /dev/null @@ -1,446 +0,0 @@ -use memchr::{memchr2, memrchr2}; -use ruff_text_size::{TextLen, TextRange, TextSize}; -use std::iter::FusedIterator; -use std::ops::Deref; - -/// Extension trait for [`str`] that provides a [`UniversalNewlineIterator`]. -pub trait StrExt { - fn universal_newlines(&self) -> UniversalNewlineIterator<'_>; -} - -impl StrExt for str { - fn universal_newlines(&self) -> UniversalNewlineIterator<'_> { - UniversalNewlineIterator::from(self) - } -} - -/// Like [`str#lines`], but accommodates LF, CRLF, and CR line endings, -/// the latter of which are not supported by [`str#lines`]. -/// -/// ## Examples -/// -/// ```rust -/// # use ruff_text_size::TextSize; -/// # use ruff_source_location::newlines::{Line, UniversalNewlineIterator}; -/// let mut lines = UniversalNewlineIterator::from("foo\nbar\n\r\nbaz\rbop"); -/// -/// assert_eq!(lines.next_back(), Some(Line::new("bop", TextSize::from(14)))); -/// assert_eq!(lines.next(), Some(Line::new("foo\n", TextSize::from(0)))); -/// assert_eq!(lines.next_back(), Some(Line::new("baz\r", TextSize::from(10)))); -/// assert_eq!(lines.next(), Some(Line::new("bar\n", TextSize::from(4)))); -/// assert_eq!(lines.next_back(), Some(Line::new("\r\n", TextSize::from(8)))); -/// assert_eq!(lines.next(), None); -/// ``` -pub struct UniversalNewlineIterator<'a> { - text: &'a str, - offset: TextSize, - offset_back: TextSize, -} - -impl<'a> UniversalNewlineIterator<'a> { - pub fn with_offset(text: &'a str, offset: TextSize) -> UniversalNewlineIterator<'a> { - UniversalNewlineIterator { - text, - offset, - offset_back: offset + text.text_len(), - } - } - - pub fn from(text: &'a str) -> UniversalNewlineIterator<'a> { - Self::with_offset(text, TextSize::default()) - } -} - -/// Finds the next newline character. Returns its position and the [`LineEnding`]. -#[inline] -pub fn find_newline(text: &str) -> Option<(usize, LineEnding)> { - let bytes = text.as_bytes(); - if let Some(position) = memchr2(b'\n', b'\r', bytes) { - // SAFETY: memchr guarantees to return valid positions - #[allow(unsafe_code)] - let newline_character = unsafe { *bytes.get_unchecked(position) }; - - let line_ending = match newline_character { - // Explicit branch for `\n` as this is the most likely path - b'\n' => LineEnding::Lf, - // '\r\n' - b'\r' if bytes.get(position.saturating_add(1)) == Some(&b'\n') => LineEnding::CrLf, - // '\r' - _ => LineEnding::Cr, - }; - - Some((position, line_ending)) - } else { - None - } -} - -impl<'a> Iterator for UniversalNewlineIterator<'a> { - type Item = Line<'a>; - - #[inline] - fn next(&mut self) -> Option> { - if self.text.is_empty() { - return None; - } - - let line = if let Some((newline_position, line_ending)) = find_newline(self.text) { - let (text, remainder) = self.text.split_at(newline_position + line_ending.len()); - - let line = Line { - offset: self.offset, - text, - }; - - self.text = remainder; - self.offset += text.text_len(); - - line - } - // Last line - else { - Line { - offset: self.offset, - text: std::mem::take(&mut self.text), - } - }; - - Some(line) - } - - fn last(mut self) -> Option { - self.next_back() - } -} - -impl DoubleEndedIterator for UniversalNewlineIterator<'_> { - #[inline] - fn next_back(&mut self) -> Option { - if self.text.is_empty() { - return None; - } - - let len = self.text.len(); - - // Trim any trailing newlines. - let haystack = match self.text.as_bytes()[len - 1] { - b'\n' if len > 1 && self.text.as_bytes()[len - 2] == b'\r' => &self.text[..len - 2], - b'\n' | b'\r' => &self.text[..len - 1], - _ => self.text, - }; - - // Find the end of the previous line. The previous line is the text up to, but not including - // the newline character. - let line = if let Some(line_end) = memrchr2(b'\n', b'\r', haystack.as_bytes()) { - // '\n' or '\r' or '\r\n' - let (remainder, line) = self.text.split_at(line_end + 1); - self.text = remainder; - self.offset_back -= line.text_len(); - - Line { - text: line, - offset: self.offset_back, - } - } else { - // Last line - let offset = self.offset_back - self.text.text_len(); - Line { - text: std::mem::take(&mut self.text), - offset, - } - }; - - Some(line) - } -} - -impl FusedIterator for UniversalNewlineIterator<'_> {} - -/// Like [`UniversalNewlineIterator`], but includes a trailing newline as an empty line. -pub struct NewlineWithTrailingNewline<'a> { - trailing: Option>, - underlying: UniversalNewlineIterator<'a>, -} - -impl<'a> NewlineWithTrailingNewline<'a> { - pub fn from(input: &'a str) -> NewlineWithTrailingNewline<'a> { - Self::with_offset(input, TextSize::default()) - } - - pub fn with_offset(input: &'a str, offset: TextSize) -> Self { - NewlineWithTrailingNewline { - underlying: UniversalNewlineIterator::with_offset(input, offset), - trailing: if input.ends_with(['\r', '\n']) { - Some(Line { - text: "", - offset: offset + input.text_len(), - }) - } else { - None - }, - } - } -} - -impl<'a> Iterator for NewlineWithTrailingNewline<'a> { - type Item = Line<'a>; - - #[inline] - fn next(&mut self) -> Option> { - self.underlying.next().or_else(|| self.trailing.take()) - } -} - -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct Line<'a> { - text: &'a str, - offset: TextSize, -} - -impl<'a> Line<'a> { - pub fn new(text: &'a str, offset: TextSize) -> Self { - Self { text, offset } - } - - #[inline] - pub const fn start(&self) -> TextSize { - self.offset - } - - /// Returns the byte offset where the line ends, including its terminating new line character. - #[inline] - pub fn full_end(&self) -> TextSize { - self.offset + self.full_text_len() - } - - /// Returns the byte offset where the line ends, excluding its new line character - #[inline] - pub fn end(&self) -> TextSize { - self.offset + self.as_str().text_len() - } - - /// Returns the range of the line, including its terminating new line character. - #[inline] - pub fn full_range(&self) -> TextRange { - TextRange::at(self.offset, self.text.text_len()) - } - - /// Returns the range of the line, excluding its terminating new line character - #[inline] - pub fn range(&self) -> TextRange { - TextRange::new(self.start(), self.end()) - } - - /// Returns the text of the line, excluding the terminating new line character. - #[inline] - pub fn as_str(&self) -> &'a str { - let mut bytes = self.text.bytes().rev(); - - let newline_len = match bytes.next() { - Some(b'\n') => { - if bytes.next() == Some(b'\r') { - 2 - } else { - 1 - } - } - Some(b'\r') => 1, - _ => 0, - }; - - &self.text[..self.text.len() - newline_len] - } - - /// Returns the line's text, including the terminating new line character. - #[inline] - pub fn as_full_str(&self) -> &'a str { - self.text - } - - #[inline] - pub fn full_text_len(&self) -> TextSize { - self.text.text_len() - } -} - -impl Deref for Line<'_> { - type Target = str; - - fn deref(&self) -> &Self::Target { - self.as_str() - } -} - -impl PartialEq<&str> for Line<'_> { - fn eq(&self, other: &&str) -> bool { - self.as_str() == *other - } -} - -impl PartialEq> for &str { - fn eq(&self, other: &Line<'_>) -> bool { - *self == other.as_str() - } -} - -/// The line ending style used in Python source code. -/// See -#[derive(Debug, PartialEq, Eq, Copy, Clone)] -pub enum LineEnding { - Lf, - Cr, - CrLf, -} - -impl Default for LineEnding { - fn default() -> Self { - if cfg!(windows) { - LineEnding::CrLf - } else { - LineEnding::Lf - } - } -} - -impl LineEnding { - pub const fn as_str(&self) -> &'static str { - match self { - LineEnding::Lf => "\n", - LineEnding::CrLf => "\r\n", - LineEnding::Cr => "\r", - } - } - - #[allow(clippy::len_without_is_empty)] - pub const fn len(&self) -> usize { - match self { - LineEnding::Lf | LineEnding::Cr => 1, - LineEnding::CrLf => 2, - } - } - - pub const fn text_len(&self) -> TextSize { - match self { - LineEnding::Lf | LineEnding::Cr => TextSize::new(1), - LineEnding::CrLf => TextSize::new(2), - } - } -} - -impl Deref for LineEnding { - type Target = str; - - fn deref(&self) -> &Self::Target { - self.as_str() - } -} - -#[cfg(test)] -mod tests { - use super::UniversalNewlineIterator; - use crate::newlines::Line; - use ruff_text_size::TextSize; - - #[test] - fn universal_newlines_empty_str() { - let lines: Vec<_> = UniversalNewlineIterator::from("").collect(); - assert_eq!(lines, Vec::::new()); - - let lines: Vec<_> = UniversalNewlineIterator::from("").rev().collect(); - assert_eq!(lines, Vec::::new()); - } - - #[test] - fn universal_newlines_forward() { - let lines: Vec<_> = UniversalNewlineIterator::from("foo\nbar\n\r\nbaz\rbop").collect(); - assert_eq!( - lines, - vec![ - Line::new("foo\n", TextSize::from(0)), - Line::new("bar\n", TextSize::from(4)), - Line::new("\r\n", TextSize::from(8)), - Line::new("baz\r", TextSize::from(10)), - Line::new("bop", TextSize::from(14)), - ] - ); - - let lines: Vec<_> = UniversalNewlineIterator::from("foo\nbar\n\r\nbaz\rbop\n").collect(); - assert_eq!( - lines, - vec![ - Line::new("foo\n", TextSize::from(0)), - Line::new("bar\n", TextSize::from(4)), - Line::new("\r\n", TextSize::from(8)), - Line::new("baz\r", TextSize::from(10)), - Line::new("bop\n", TextSize::from(14)), - ] - ); - - let lines: Vec<_> = UniversalNewlineIterator::from("foo\nbar\n\r\nbaz\rbop\n\n").collect(); - assert_eq!( - lines, - vec![ - Line::new("foo\n", TextSize::from(0)), - Line::new("bar\n", TextSize::from(4)), - Line::new("\r\n", TextSize::from(8)), - Line::new("baz\r", TextSize::from(10)), - Line::new("bop\n", TextSize::from(14)), - Line::new("\n", TextSize::from(18)), - ] - ); - } - - #[test] - fn universal_newlines_backwards() { - let lines: Vec<_> = UniversalNewlineIterator::from("foo\nbar\n\r\nbaz\rbop") - .rev() - .collect(); - assert_eq!( - lines, - vec![ - Line::new("bop", TextSize::from(14)), - Line::new("baz\r", TextSize::from(10)), - Line::new("\r\n", TextSize::from(8)), - Line::new("bar\n", TextSize::from(4)), - Line::new("foo\n", TextSize::from(0)), - ] - ); - - let lines: Vec<_> = UniversalNewlineIterator::from("foo\nbar\n\nbaz\rbop\n") - .rev() - .map(|line| line.as_str()) - .collect(); - - assert_eq!( - lines, - vec![ - Line::new("bop\n", TextSize::from(13)), - Line::new("baz\r", TextSize::from(9)), - Line::new("\n", TextSize::from(8)), - Line::new("bar\n", TextSize::from(4)), - Line::new("foo\n", TextSize::from(0)), - ] - ); - } - - #[test] - fn universal_newlines_mixed() { - let mut lines = UniversalNewlineIterator::from("foo\nbar\n\r\nbaz\rbop"); - - assert_eq!( - lines.next_back(), - Some(Line::new("bop", TextSize::from(14))) - ); - assert_eq!(lines.next(), Some(Line::new("foo\n", TextSize::from(0)))); - assert_eq!( - lines.next_back(), - Some(Line::new("baz\r", TextSize::from(10))) - ); - assert_eq!(lines.next(), Some(Line::new("bar\n", TextSize::from(4)))); - assert_eq!( - lines.next_back(), - Some(Line::new("\r\n", TextSize::from(8))) - ); - assert_eq!(lines.next(), None); - } -} diff --git a/scripts/update_asdl.sh b/scripts/update_asdl.sh index c7115a51dd0f6..985d780ee9a6b 100755 --- a/scripts/update_asdl.sh +++ b/scripts/update_asdl.sh @@ -4,5 +4,5 @@ set -e cd "$(dirname "$(dirname "$0")")" # rm ast/src/gen/*.rs -python ast/asdl_rs.py --ast-dir ast/src/gen/ --parser-dir parser/src/gen/ --ast-pyo3-dir ast-pyo3/src/gen/ --module-file ../RustPython/vm/src/stdlib/ast/gen.rs ast/Python.asdl -rustfmt ast/src/gen/*.rs parser/src/gen/*.rs ast-pyo3/src/gen/*.rs ../RustPython/vm/src/stdlib/ast/gen.rs +python ast/asdl_rs.py --ast-dir ast/src/gen/ --parser-dir parser/src/gen/ ast/Python.asdl +rustfmt ast/src/gen/*.rs parser/src/gen/*.rs