Cmpop::as_str (#72)

* clean up pyo3 generation

* Cmpop::as_str
This commit is contained in:
Jeong, YunWon 2023-05-29 01:53:54 +09:00 committed by GitHub
parent 4de0cb1827
commit 531aeb3511
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 37 deletions

View file

@ -1653,8 +1653,8 @@ impl ToPyAst for ast::StmtPass<TextRange> {
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
let Self { range: _range } = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
Ok(instance)
}
@ -1665,8 +1665,8 @@ impl ToPyAst for ast::StmtBreak<TextRange> {
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
let Self { range: _range } = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
Ok(instance)
}
@ -1677,8 +1677,8 @@ impl ToPyAst for ast::StmtContinue<TextRange> {
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
let Self { range: _range } = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
Ok(instance)
}
@ -3429,8 +3429,8 @@ impl ToPyAst for ast::StmtPass<SourceRange> {
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
let Self { range: _range } = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
let cache = ast_cache();
instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?;
@ -3449,8 +3449,8 @@ impl ToPyAst for ast::StmtBreak<SourceRange> {
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
let Self { range: _range } = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
let cache = ast_cache();
instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?;
@ -3469,8 +3469,8 @@ impl ToPyAst for ast::StmtContinue<SourceRange> {
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
let cache = Self::py_type_cache().get().unwrap();
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
let Self { range: _range } = self;
let instance = Py::<PyAny>::as_ref(&cache.0, py).call0()?;
let cache = ast_cache();
instance.setattr(cache.lineno.as_ref(py), _range.start.row.get())?;

View file

@ -131,6 +131,19 @@ struct AstCache {
}
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::<PyAny>::as_ref(&self.none, py)

View file

@ -93,7 +93,7 @@ impl<T: ToPyWrapper> ToPyWrapper for Vec<T> {
}
}
#[pyclass(module = "rustpython_ast", subclass)]
#[pyclass(module = "rustpython_ast", name = "AST", subclass)]
pub struct Ast;
#[pymethods]