Skip to content

Update to the latest ASDL #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
259 changes: 259 additions & 0 deletions ast-pyo3/src/gen/to_py_ast.rs

Large diffs are not rendered by default.

217 changes: 217 additions & 0 deletions ast-pyo3/src/gen/wrapper_located.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl ToPyWrapper for ast::Stmt<SourceRange> {
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::TypeAlias(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),
Expand Down Expand Up @@ -310,6 +311,12 @@ impl StmtFunctionDef {
fn get_type_comment(&self, py: Python) -> PyResult<PyObject> {
self.0.type_comment.to_py_wrapper(py)
}

#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
}

#[pyclass(module="rustpython_ast.located", name="_AsyncFunctionDef", extends=Stmt, frozen)]
Expand Down Expand Up @@ -375,6 +382,12 @@ impl StmtAsyncFunctionDef {
fn get_type_comment(&self, py: Python) -> PyResult<PyObject> {
self.0.type_comment.to_py_wrapper(py)
}

#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
}

#[pyclass(module="rustpython_ast.located", name="_ClassDef", extends=Stmt, frozen)]
Expand Down Expand Up @@ -434,6 +447,12 @@ impl StmtClassDef {
fn get_decorator_list(&self, py: Python) -> PyResult<PyObject> {
self.0.decorator_list.to_py_wrapper(py)
}

#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}
}

#[pyclass(module="rustpython_ast.located", name="_Return", extends=Stmt, frozen)]
Expand Down Expand Up @@ -553,6 +572,53 @@ impl StmtAssign {
}
}

#[pyclass(module="rustpython_ast.located", name="_TypeAlias", extends=Stmt, frozen)]
#[derive(Clone, Debug)]
pub struct StmtTypeAlias(pub &'static ast::StmtTypeAlias<SourceRange>);

impl From<&'static ast::StmtTypeAlias<SourceRange>> for StmtTypeAlias {
fn from(node: &'static ast::StmtTypeAlias<SourceRange>) -> Self {
StmtTypeAlias(node)
}
}

impl ToPyObject for StmtTypeAlias {
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::StmtTypeAlias<SourceRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(StmtTypeAlias(self).to_object(py))
}
}

#[pymethods]
impl StmtTypeAlias {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}

#[getter]
#[inline]
fn get_type_params(&self, py: Python) -> PyResult<PyObject> {
self.0.type_params.to_py_wrapper(py)
}

#[getter]
#[inline]
fn get_value(&self, py: Python) -> PyResult<PyObject> {
self.0.value.to_py_wrapper(py)
}
}

#[pyclass(module="rustpython_ast.located", name="_AugAssign", extends=Stmt, frozen)]
#[derive(Clone, Debug)]
pub struct StmtAugAssign(pub &'static ast::StmtAugAssign<SourceRange>);
Expand Down Expand Up @@ -3993,6 +4059,152 @@ impl TypeIgnoreTypeIgnore {
}
}

#[pyclass(module="rustpython_ast.located", name="_type_param", extends=super::Ast, frozen, subclass)]
#[derive(Clone, Debug)]
pub struct TypeParam;

impl From<&'static ast::TypeParam<SourceRange>> for TypeParam {
fn from(_node: &'static ast::TypeParam<SourceRange>) -> Self {
TypeParam
}
}

#[pymethods]
impl TypeParam {
#[new]
fn new() -> PyClassInitializer<Self> {
PyClassInitializer::from(Ast).add_subclass(Self)
}
}
impl ToPyObject for TypeParam {
fn to_object(&self, py: Python) -> PyObject {
let initializer = Self::new();
Py::new(py, initializer).unwrap().into_py(py)
}
}

impl ToPyWrapper for ast::TypeParam<SourceRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
match &self {
Self::TypeVar(cons) => cons.to_py_wrapper(py),
Self::ParamSpec(cons) => cons.to_py_wrapper(py),
Self::TypeVarTuple(cons) => cons.to_py_wrapper(py),
}
}
}

#[pyclass(module="rustpython_ast.located", name="_TypeVar", extends=TypeParam, frozen)]
#[derive(Clone, Debug)]
pub struct TypeParamTypeVar(pub &'static ast::TypeParamTypeVar<SourceRange>);

impl From<&'static ast::TypeParamTypeVar<SourceRange>> for TypeParamTypeVar {
fn from(node: &'static ast::TypeParamTypeVar<SourceRange>) -> Self {
TypeParamTypeVar(node)
}
}

impl ToPyObject for TypeParamTypeVar {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(TypeParam)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}

impl ToPyWrapper for ast::TypeParamTypeVar<SourceRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(TypeParamTypeVar(self).to_object(py))
}
}

#[pymethods]
impl TypeParamTypeVar {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}

#[getter]
#[inline]
fn get_bound(&self, py: Python) -> PyResult<PyObject> {
self.0.bound.to_py_wrapper(py)
}
}

#[pyclass(module="rustpython_ast.located", name="_ParamSpec", extends=TypeParam, frozen)]
#[derive(Clone, Debug)]
pub struct TypeParamParamSpec(pub &'static ast::TypeParamParamSpec<SourceRange>);

impl From<&'static ast::TypeParamParamSpec<SourceRange>> for TypeParamParamSpec {
fn from(node: &'static ast::TypeParamParamSpec<SourceRange>) -> Self {
TypeParamParamSpec(node)
}
}

impl ToPyObject for TypeParamParamSpec {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(TypeParam)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}

impl ToPyWrapper for ast::TypeParamParamSpec<SourceRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(TypeParamParamSpec(self).to_object(py))
}
}

#[pymethods]
impl TypeParamParamSpec {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}
}

#[pyclass(module="rustpython_ast.located", name="_TypeVarTuple", extends=TypeParam, frozen)]
#[derive(Clone, Debug)]
pub struct TypeParamTypeVarTuple(pub &'static ast::TypeParamTypeVarTuple<SourceRange>);

impl From<&'static ast::TypeParamTypeVarTuple<SourceRange>> for TypeParamTypeVarTuple {
fn from(node: &'static ast::TypeParamTypeVarTuple<SourceRange>) -> Self {
TypeParamTypeVarTuple(node)
}
}

impl ToPyObject for TypeParamTypeVarTuple {
fn to_object(&self, py: Python) -> PyObject {
let initializer = PyClassInitializer::from(Ast)
.add_subclass(TypeParam)
.add_subclass(self.clone());
Py::new(py, initializer).unwrap().into_py(py)
}
}

impl ToPyWrapper for ast::TypeParamTypeVarTuple<SourceRange> {
#[inline]
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
Ok(TypeParamTypeVarTuple(self).to_object(py))
}
}

#[pymethods]
impl TypeParamTypeVarTuple {
#[getter]
#[inline]
fn get_name(&self, py: Python) -> PyResult<PyObject> {
self.0.name.to_py_wrapper(py)
}
}

impl ToPyWrapper for ast::ExprContext {
#[inline]
fn to_py_wrapper(&self, py: Python) -> PyResult<Py<PyAny>> {
Expand Down Expand Up @@ -4303,6 +4515,7 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
super::init_type::<StmtReturn, ast::StmtReturn>(py, m)?;
super::init_type::<StmtDelete, ast::StmtDelete>(py, m)?;
super::init_type::<StmtAssign, ast::StmtAssign>(py, m)?;
super::init_type::<StmtTypeAlias, ast::StmtTypeAlias>(py, m)?;
super::init_type::<StmtAugAssign, ast::StmtAugAssign>(py, m)?;
super::init_type::<StmtAnnAssign, ast::StmtAnnAssign>(py, m)?;
super::init_type::<StmtFor, ast::StmtFor>(py, m)?;
Expand Down Expand Up @@ -4409,5 +4622,9 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
super::init_type::<PatternMatchOr, ast::PatternMatchOr>(py, m)?;
super::init_type::<TypeIgnore, ast::TypeIgnore>(py, m)?;
super::init_type::<TypeIgnoreTypeIgnore, ast::TypeIgnoreTypeIgnore>(py, m)?;
super::init_type::<TypeParam, ast::TypeParam>(py, m)?;
super::init_type::<TypeParamTypeVar, ast::TypeParamTypeVar>(py, m)?;
super::init_type::<TypeParamParamSpec, ast::TypeParamParamSpec>(py, m)?;
super::init_type::<TypeParamTypeVarTuple, ast::TypeParamTypeVarTuple>(py, m)?;
Ok(())
}
Loading