Merge pull request #4218 from charliermarsh/charlie/clone

Make AST nodes Clone-able
This commit is contained in:
Jeong YunWon 2022-10-17 13:47:21 +09:00 committed by GitHub
commit 2e830bab55
3 changed files with 21 additions and 21 deletions

View file

@ -190,7 +190,7 @@ class StructVisitor(TypeInfoEmitVisitor):
self.sum_with_constructors(sum, name, depth) self.sum_with_constructors(sum, name, depth)
def emit_attrs(self, 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): def simple_sum(self, sum, name, depth):
rustname = get_rust_type(name) rustname = get_rust_type(name)

View file

@ -7,7 +7,7 @@ pub use crate::Location;
type Ident = String; type Ident = String;
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct Located<T, U = ()> { pub struct Located<T, U = ()> {
pub location: Location, pub location: Location,
pub end_location: Option<Location>, pub end_location: Option<Location>,
@ -26,7 +26,7 @@ impl<T> Located<T> {
} }
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Mod<U = ()> { pub enum Mod<U = ()> {
Module { Module {
body: Vec<Stmt<U>>, body: Vec<Stmt<U>>,
@ -44,7 +44,7 @@ pub enum Mod<U = ()> {
}, },
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum StmtKind<U = ()> { pub enum StmtKind<U = ()> {
FunctionDef { FunctionDef {
name: Ident, name: Ident,
@ -166,7 +166,7 @@ pub enum StmtKind<U = ()> {
} }
pub type Stmt<U = ()> = Located<StmtKind<U>, U>; pub type Stmt<U = ()> = Located<StmtKind<U>, U>;
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum ExprKind<U = ()> { pub enum ExprKind<U = ()> {
BoolOp { BoolOp {
op: Boolop, op: Boolop,
@ -283,20 +283,20 @@ pub enum ExprKind<U = ()> {
} }
pub type Expr<U = ()> = Located<ExprKind<U>, U>; pub type Expr<U = ()> = Located<ExprKind<U>, U>;
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum ExprContext { pub enum ExprContext {
Load, Load,
Store, Store,
Del, Del,
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Boolop { pub enum Boolop {
And, And,
Or, Or,
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Operator { pub enum Operator {
Add, Add,
Sub, Sub,
@ -313,7 +313,7 @@ pub enum Operator {
FloorDiv, FloorDiv,
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Unaryop { pub enum Unaryop {
Invert, Invert,
Not, Not,
@ -321,7 +321,7 @@ pub enum Unaryop {
USub, USub,
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Cmpop { pub enum Cmpop {
Eq, Eq,
NotEq, NotEq,
@ -335,7 +335,7 @@ pub enum Cmpop {
NotIn, NotIn,
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct Comprehension<U = ()> { pub struct Comprehension<U = ()> {
pub target: Box<Expr<U>>, pub target: Box<Expr<U>>,
pub iter: Box<Expr<U>>, pub iter: Box<Expr<U>>,
@ -343,7 +343,7 @@ pub struct Comprehension<U = ()> {
pub is_async: usize, pub is_async: usize,
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum ExcepthandlerKind<U = ()> { pub enum ExcepthandlerKind<U = ()> {
ExceptHandler { ExceptHandler {
type_: Option<Box<Expr<U>>>, type_: Option<Box<Expr<U>>>,
@ -353,7 +353,7 @@ pub enum ExcepthandlerKind<U = ()> {
} }
pub type Excepthandler<U = ()> = Located<ExcepthandlerKind<U>, U>; pub type Excepthandler<U = ()> = Located<ExcepthandlerKind<U>, U>;
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct Arguments<U = ()> { pub struct Arguments<U = ()> {
pub posonlyargs: Vec<Arg<U>>, pub posonlyargs: Vec<Arg<U>>,
pub args: Vec<Arg<U>>, pub args: Vec<Arg<U>>,
@ -364,7 +364,7 @@ pub struct Arguments<U = ()> {
pub defaults: Vec<Expr<U>>, pub defaults: Vec<Expr<U>>,
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct ArgData<U = ()> { pub struct ArgData<U = ()> {
pub arg: Ident, pub arg: Ident,
pub annotation: Option<Box<Expr<U>>>, pub annotation: Option<Box<Expr<U>>>,
@ -372,34 +372,34 @@ pub struct ArgData<U = ()> {
} }
pub type Arg<U = ()> = Located<ArgData<U>, U>; pub type Arg<U = ()> = Located<ArgData<U>, U>;
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct KeywordData<U = ()> { pub struct KeywordData<U = ()> {
pub arg: Option<Ident>, pub arg: Option<Ident>,
pub value: Box<Expr<U>>, pub value: Box<Expr<U>>,
} }
pub type Keyword<U = ()> = Located<KeywordData<U>, U>; pub type Keyword<U = ()> = Located<KeywordData<U>, U>;
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct AliasData { pub struct AliasData {
pub name: Ident, pub name: Ident,
pub asname: Option<Ident>, pub asname: Option<Ident>,
} }
pub type Alias<U = ()> = Located<AliasData, U>; pub type Alias<U = ()> = Located<AliasData, U>;
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct Withitem<U = ()> { pub struct Withitem<U = ()> {
pub context_expr: Box<Expr<U>>, pub context_expr: Box<Expr<U>>,
pub optional_vars: Option<Box<Expr<U>>>, pub optional_vars: Option<Box<Expr<U>>>,
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct MatchCase<U = ()> { pub struct MatchCase<U = ()> {
pub pattern: Box<Pattern<U>>, pub pattern: Box<Pattern<U>>,
pub guard: Option<Box<Expr<U>>>, pub guard: Option<Box<Expr<U>>>,
pub body: Vec<Stmt<U>>, pub body: Vec<Stmt<U>>,
} }
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum PatternKind<U = ()> { pub enum PatternKind<U = ()> {
MatchValue { MatchValue {
value: Box<Expr<U>>, value: Box<Expr<U>>,
@ -434,7 +434,7 @@ pub enum PatternKind<U = ()> {
} }
pub type Pattern<U = ()> = Located<PatternKind<U>, U>; pub type Pattern<U = ()> = Located<PatternKind<U>, U>;
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum TypeIgnore { pub enum TypeIgnore {
TypeIgnore { lineno: usize, tag: String }, TypeIgnore { lineno: usize, tag: String },
} }

View file

@ -1,7 +1,7 @@
use num_bigint::BigInt; use num_bigint::BigInt;
pub use rustpython_compiler_core::ConversionFlag; pub use rustpython_compiler_core::ConversionFlag;
#[derive(Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Constant { pub enum Constant {
None, None,
Bool(bool), Bool(bool),