Skip to content

Commit 842a34d

Browse files
committed
location support
1 parent 8d56692 commit 842a34d

File tree

5 files changed

+383
-294
lines changed

5 files changed

+383
-294
lines changed

ast/asdl_rs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,11 +1053,12 @@ def emit_to_pyo3_with_fields(self, cons, type, name):
10531053
if type.value.attributes and self.namespace == "located":
10541054
self.emit(
10551055
"""
1056-
instance.setattr(py, "lineno", _range.start.row.get())?;
1057-
instance.setattr(py, "col_offset", _range.start.column.get())?;
1056+
let cache = ast_key_cache().get().unwrap();
1057+
instance.setattr(py, cache.lineno.as_ref(py), _range.start.row.get())?;
1058+
instance.setattr(py, cache.col_offset.as_ref(py), _range.start.column.get())?;
10581059
if let Some(end) = _range.end {
1059-
instance.setattr(py, "end_lineno", end.row.get())?;
1060-
instance.setattr(py, "end_col_offset", end.column.get())?;
1060+
instance.setattr(py, cache.end_lineno.as_ref(py), end.row.get())?;
1061+
instance.setattr(py, cache.end_col_offset.as_ref(py), end.column.get())?;
10611062
}
10621063
""",
10631064
1,
@@ -1148,8 +1149,7 @@ def emit_class(self, name, rust_name, simple, base="super::AST"):
11481149
}}
11491150
impl ToPyObject for {rust_name} {{
11501151
fn to_object(&self, py: Python) -> PyObject {{
1151-
let initializer = PyClassInitializer::from(AST)
1152-
.add_subclass(self.clone());
1152+
let initializer = Self::new();
11531153
Py::new(py, initializer).unwrap().into_py(py)
11541154
}}
11551155
}}

ast/src/gen/pyo3_wrapper_located.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl Mod {
1919
}
2020
impl ToPyObject for Mod {
2121
fn to_object(&self, py: Python) -> PyObject {
22-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
22+
let initializer = Self::new();
2323
Py::new(py, initializer).unwrap().into_py(py)
2424
}
2525
}
@@ -207,7 +207,7 @@ impl Stmt {
207207
}
208208
impl ToPyObject for Stmt {
209209
fn to_object(&self, py: Python) -> PyObject {
210-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
210+
let initializer = Self::new();
211211
Py::new(py, initializer).unwrap().into_py(py)
212212
}
213213
}
@@ -1481,7 +1481,7 @@ impl Expr {
14811481
}
14821482
impl ToPyObject for Expr {
14831483
fn to_object(&self, py: Python) -> PyObject {
1484-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
1484+
let initializer = Self::new();
14851485
Py::new(py, initializer).unwrap().into_py(py)
14861486
}
14871487
}
@@ -2671,7 +2671,7 @@ impl ExprContext {
26712671
}
26722672
impl ToPyObject for ExprContext {
26732673
fn to_object(&self, py: Python) -> PyObject {
2674-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
2674+
let initializer = Self::new();
26752675
Py::new(py, initializer).unwrap().into_py(py)
26762676
}
26772677
}
@@ -2731,7 +2731,7 @@ impl Boolop {
27312731
}
27322732
impl ToPyObject for Boolop {
27332733
fn to_object(&self, py: Python) -> PyObject {
2734-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
2734+
let initializer = Self::new();
27352735
Py::new(py, initializer).unwrap().into_py(py)
27362736
}
27372737
}
@@ -2779,7 +2779,7 @@ impl Operator {
27792779
}
27802780
impl ToPyObject for Operator {
27812781
fn to_object(&self, py: Python) -> PyObject {
2782-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
2782+
let initializer = Self::new();
27832783
Py::new(py, initializer).unwrap().into_py(py)
27842784
}
27852785
}
@@ -2959,7 +2959,7 @@ impl Unaryop {
29592959
}
29602960
impl ToPyObject for Unaryop {
29612961
fn to_object(&self, py: Python) -> PyObject {
2962-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
2962+
let initializer = Self::new();
29632963
Py::new(py, initializer).unwrap().into_py(py)
29642964
}
29652965
}
@@ -3031,7 +3031,7 @@ impl Cmpop {
30313031
}
30323032
impl ToPyObject for Cmpop {
30333033
fn to_object(&self, py: Python) -> PyObject {
3034-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
3034+
let initializer = Self::new();
30353035
Py::new(py, initializer).unwrap().into_py(py)
30363036
}
30373037
}
@@ -3226,7 +3226,7 @@ impl Excepthandler {
32263226
}
32273227
impl ToPyObject for Excepthandler {
32283228
fn to_object(&self, py: Python) -> PyObject {
3229-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
3229+
let initializer = Self::new();
32303230
Py::new(py, initializer).unwrap().into_py(py)
32313231
}
32323232
}
@@ -3582,7 +3582,7 @@ impl Pattern {
35823582
}
35833583
impl ToPyObject for Pattern {
35843584
fn to_object(&self, py: Python) -> PyObject {
3585-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
3585+
let initializer = Self::new();
35863586
Py::new(py, initializer).unwrap().into_py(py)
35873587
}
35883588
}
@@ -3938,7 +3938,7 @@ impl TypeIgnore {
39383938
}
39393939
impl ToPyObject for TypeIgnore {
39403940
fn to_object(&self, py: Python) -> PyObject {
3941-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
3941+
let initializer = Self::new();
39423942
Py::new(py, initializer).unwrap().into_py(py)
39433943
}
39443944
}

ast/src/gen/pyo3_wrapper_ranged.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl Mod {
1919
}
2020
impl ToPyObject for Mod {
2121
fn to_object(&self, py: Python) -> PyObject {
22-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
22+
let initializer = Self::new();
2323
Py::new(py, initializer).unwrap().into_py(py)
2424
}
2525
}
@@ -207,7 +207,7 @@ impl Stmt {
207207
}
208208
impl ToPyObject for Stmt {
209209
fn to_object(&self, py: Python) -> PyObject {
210-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
210+
let initializer = Self::new();
211211
Py::new(py, initializer).unwrap().into_py(py)
212212
}
213213
}
@@ -1481,7 +1481,7 @@ impl Expr {
14811481
}
14821482
impl ToPyObject for Expr {
14831483
fn to_object(&self, py: Python) -> PyObject {
1484-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
1484+
let initializer = Self::new();
14851485
Py::new(py, initializer).unwrap().into_py(py)
14861486
}
14871487
}
@@ -2671,7 +2671,7 @@ impl ExprContext {
26712671
}
26722672
impl ToPyObject for ExprContext {
26732673
fn to_object(&self, py: Python) -> PyObject {
2674-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
2674+
let initializer = Self::new();
26752675
Py::new(py, initializer).unwrap().into_py(py)
26762676
}
26772677
}
@@ -2731,7 +2731,7 @@ impl Boolop {
27312731
}
27322732
impl ToPyObject for Boolop {
27332733
fn to_object(&self, py: Python) -> PyObject {
2734-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
2734+
let initializer = Self::new();
27352735
Py::new(py, initializer).unwrap().into_py(py)
27362736
}
27372737
}
@@ -2779,7 +2779,7 @@ impl Operator {
27792779
}
27802780
impl ToPyObject for Operator {
27812781
fn to_object(&self, py: Python) -> PyObject {
2782-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
2782+
let initializer = Self::new();
27832783
Py::new(py, initializer).unwrap().into_py(py)
27842784
}
27852785
}
@@ -2959,7 +2959,7 @@ impl Unaryop {
29592959
}
29602960
impl ToPyObject for Unaryop {
29612961
fn to_object(&self, py: Python) -> PyObject {
2962-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
2962+
let initializer = Self::new();
29632963
Py::new(py, initializer).unwrap().into_py(py)
29642964
}
29652965
}
@@ -3031,7 +3031,7 @@ impl Cmpop {
30313031
}
30323032
impl ToPyObject for Cmpop {
30333033
fn to_object(&self, py: Python) -> PyObject {
3034-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
3034+
let initializer = Self::new();
30353035
Py::new(py, initializer).unwrap().into_py(py)
30363036
}
30373037
}
@@ -3226,7 +3226,7 @@ impl Excepthandler {
32263226
}
32273227
impl ToPyObject for Excepthandler {
32283228
fn to_object(&self, py: Python) -> PyObject {
3229-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
3229+
let initializer = Self::new();
32303230
Py::new(py, initializer).unwrap().into_py(py)
32313231
}
32323232
}
@@ -3582,7 +3582,7 @@ impl Pattern {
35823582
}
35833583
impl ToPyObject for Pattern {
35843584
fn to_object(&self, py: Python) -> PyObject {
3585-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
3585+
let initializer = Self::new();
35863586
Py::new(py, initializer).unwrap().into_py(py)
35873587
}
35883588
}
@@ -3938,7 +3938,7 @@ impl TypeIgnore {
39383938
}
39393939
impl ToPyObject for TypeIgnore {
39403940
fn to_object(&self, py: Python) -> PyObject {
3941-
let initializer = PyClassInitializer::from(AST).add_subclass(self.clone());
3941+
let initializer = Self::new();
39423942
Py::new(py, initializer).unwrap().into_py(py)
39433943
}
39443944
}

0 commit comments

Comments
 (0)