Make AST nodes Clone-able

This commit is contained in:
Charlie Marsh committed 2022-10-16 11:01:17 -04:00
1 parent 4be533ac60
commit d8f059bc58
3 files changed
+21 -21

No files matched your search

+1 -1
View File
@@ -190,7 +190,7 @@ class StructVisitor(TypeInfoEmitVisitor):
self.sum_with_constructors(sum, name, depth)
def emit_attrs(self, depth):
self.emit("#[derive(Debug, PartialEq)]", depth)
self.emit("#[derive(Clone, Debug, PartialEq)]", depth)
def simple_sum(self, sum, name, depth):
rustname = get_rust_type(name)
+19 -19
View File
@@ -7,7 +7,7 @@ pub use crate::Location;
type Ident = String;
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct Located<T, U = ()> {
pub location: Location,
pub custom: U,
@@ -24,7 +24,7 @@ impl<T> Located<T> {
}
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum Mod<U = ()> {
Module {
body: Vec<Stmt<U>>,
@@ -42,7 +42,7 @@ pub enum Mod<U = ()> {
},
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum StmtKind<U = ()> {
FunctionDef {
name: Ident,
@@ -164,7 +164,7 @@ pub enum StmtKind<U = ()> {
}
pub type Stmt<U = ()> = Located<StmtKind<U>, U>;
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum ExprKind<U = ()> {
BoolOp {
op: Boolop,
@@ -281,20 +281,20 @@ pub enum ExprKind<U = ()> {
}
pub type Expr<U = ()> = Located<ExprKind<U>, U>;
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum ExprContext {
Load,
Store,
Del,
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum Boolop {
And,
Or,
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum Operator {
Add,
Sub,
@@ -311,7 +311,7 @@ pub enum Operator {
FloorDiv,
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum Unaryop {
Invert,
Not,
@@ -319,7 +319,7 @@ pub enum Unaryop {
USub,
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum Cmpop {
Eq,
NotEq,
@@ -333,7 +333,7 @@ pub enum Cmpop {
NotIn,
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct Comprehension<U = ()> {
pub target: Box<Expr<U>>,
pub iter: Box<Expr<U>>,
@@ -341,7 +341,7 @@ pub struct Comprehension<U = ()> {
pub is_async: usize,
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum ExcepthandlerKind<U = ()> {
ExceptHandler {
type_: Option<Box<Expr<U>>>,
@@ -351,7 +351,7 @@ pub enum ExcepthandlerKind<U = ()> {
}
pub type Excepthandler<U = ()> = Located<ExcepthandlerKind<U>, U>;
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct Arguments<U = ()> {
pub posonlyargs: Vec<Arg<U>>,
pub args: Vec<Arg<U>>,
@@ -362,7 +362,7 @@ pub struct Arguments<U = ()> {
pub defaults: Vec<Expr<U>>,
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct ArgData<U = ()> {
pub arg: Ident,
pub annotation: Option<Box<Expr<U>>>,
@@ -370,34 +370,34 @@ pub struct ArgData<U = ()> {
}
pub type Arg<U = ()> = Located<ArgData<U>, U>;
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct KeywordData<U = ()> {
pub arg: Option<Ident>,
pub value: Box<Expr<U>>,
}
pub type Keyword<U = ()> = Located<KeywordData<U>, U>;
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct AliasData {
pub name: Ident,
pub asname: Option<Ident>,
}
pub type Alias<U = ()> = Located<AliasData, U>;
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct Withitem<U = ()> {
pub context_expr: Box<Expr<U>>,
pub optional_vars: Option<Box<Expr<U>>>,
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct MatchCase<U = ()> {
pub pattern: Box<Pattern<U>>,
pub guard: Option<Box<Expr<U>>>,
pub body: Vec<Stmt<U>>,
}
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum PatternKind<U = ()> {
MatchValue {
value: Box<Expr<U>>,
@@ -432,7 +432,7 @@ pub enum PatternKind<U = ()> {
}
pub type Pattern<U = ()> = Located<PatternKind<U>, U>;
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum TypeIgnore {
TypeIgnore { lineno: usize, tag: String },
}
+1 -1
View File
@@ -1,7 +1,7 @@
use num_bigint::BigInt;
pub use rustpython_compiler_core::ConversionFlag;
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum Constant {
None,
Bool(bool),