Skip to content
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

Generic arg refactor #261

Merged
merged 8 commits into from
Dec 5, 2017
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
40 changes: 32 additions & 8 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ ast_enum_of_structs! {
pub or2_token: Token![|],
}),

/// A block (`{ ... }` or `unsafe { ... }`)
/// An unsafe block (`unsafe { ... }`)
pub Unsafe(ExprUnsafe #full {
pub unsafe_token: Token![unsafe],
pub block: Block,
}),

/// A block (`{ ... }`)
pub Block(ExprBlock #full {
pub unsafety: Unsafety,
pub block: Block,
}),

Expand Down Expand Up @@ -628,6 +633,7 @@ fn arm_expr_requires_comma(expr: &Expr) -> bool {
// see https://github.com/rust-lang/rust/blob/eb8f2586e
// /src/libsyntax/parse/classify.rs#L17-L37
match expr.node {
ExprKind::Unsafe(..) |
ExprKind::Block(..) |
ExprKind::If(..) |
ExprKind::IfLet(..) |
Expand Down Expand Up @@ -1192,6 +1198,8 @@ pub mod parsing {
|
syn!(ExprYield) => { ExprKind::Yield }
|
syn!(ExprUnsafe) => { ExprKind::Unsafe }
|
call!(expr_closure, allow_struct)
|
cond_reduce!(allow_block, map!(syn!(ExprBlock), ExprKind::Block))
Expand Down Expand Up @@ -1238,6 +1246,8 @@ pub mod parsing {
|
syn!(ExprYield) => { ExprKind::Yield }
|
syn!(ExprUnsafe) => { ExprKind::Unsafe }
|
syn!(ExprBlock) => { ExprKind::Block }
), Expr::from));

Expand Down Expand Up @@ -1272,7 +1282,6 @@ pub mod parsing {
kind: InPlaceKind::In(in_),
value: Box::new(Expr {
node: ExprBlock {
unsafety: Unsafety::Normal,
block: Block {
stmts: value.0,
brace_token: value.1,
Expand Down Expand Up @@ -1403,7 +1412,6 @@ pub mod parsing {
do_parse!(
else_block: braces!(call!(Block::parse_within)) >>
(ExprKind::Block(ExprBlock {
unsafety: Unsafety::Normal,
block: Block {
stmts: else_block.0,
brace_token: else_block.1,
Expand Down Expand Up @@ -1537,7 +1545,6 @@ pub mod parsing {
body: syn!(Block) >>
(ReturnType::Type(ty, arrow),
ExprKind::Block(ExprBlock {
unsafety: Unsafety::Normal,
block: body,
}).into())
)
Expand Down Expand Up @@ -1738,13 +1745,23 @@ pub mod parsing {
));
}

#[cfg(feature = "full")]
impl Synom for ExprUnsafe {
named!(parse -> Self, do_parse!(
unsafe_: keyword!(unsafe) >>
b: syn!(Block) >>
(ExprUnsafe {
unsafe_token: unsafe_,
block: b,
})
));
}

#[cfg(feature = "full")]
impl Synom for ExprBlock {
named!(parse -> Self, do_parse!(
rules: syn!(Unsafety) >>
b: syn!(Block) >>
(ExprBlock {
unsafety: rules,
block: b,
})
));
Expand Down Expand Up @@ -2567,10 +2584,17 @@ mod printing {
}
}

#[cfg(feature = "full")]
impl ToTokens for ExprUnsafe {
fn to_tokens(&self, tokens: &mut Tokens) {
self.unsafe_token.to_tokens(tokens);
self.block.to_tokens(tokens);
}
}

#[cfg(feature = "full")]
impl ToTokens for ExprBlock {
fn to_tokens(&self, tokens: &mut Tokens) {
self.unsafety.to_tokens(tokens);
self.block.to_tokens(tokens);
}
}
Expand Down
118 changes: 88 additions & 30 deletions src/gen/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn fold_abi(&mut self, i: Abi) -> Abi { fold_abi(self, i) }

fn fold_abi_kind(&mut self, i: AbiKind) -> AbiKind { fold_abi_kind(self, i) }

fn fold_angle_bracketed_parameter_data(&mut self, i: AngleBracketedParameterData) -> AngleBracketedParameterData { fold_angle_bracketed_parameter_data(self, i) }
fn fold_angle_bracketed_generic_arguments(&mut self, i: AngleBracketedGenericArguments) -> AngleBracketedGenericArguments { fold_angle_bracketed_generic_arguments(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_arg_captured(&mut self, i: ArgCaptured) -> ArgCaptured { fold_arg_captured(self, i) }
# [ cfg ( feature = "full" ) ]
Expand Down Expand Up @@ -97,6 +97,8 @@ fn fold_body_struct(&mut self, i: BodyStruct) -> BodyStruct { fold_body_struct(s
fn fold_bound_lifetimes(&mut self, i: BoundLifetimes) -> BoundLifetimes { fold_bound_lifetimes(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_capture_by(&mut self, i: CaptureBy) -> CaptureBy { fold_capture_by(self, i) }

fn fold_const_param(&mut self, i: ConstParam) -> ConstParam { fold_const_param(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_constness(&mut self, i: Constness) -> Constness { fold_constness(self, i) }
# [ cfg ( feature = "full" ) ]
Expand Down Expand Up @@ -176,6 +178,8 @@ fn fold_expr_type(&mut self, i: ExprType) -> ExprType { fold_expr_type(self, i)

fn fold_expr_unary(&mut self, i: ExprUnary) -> ExprUnary { fold_expr_unary(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_expr_unsafe(&mut self, i: ExprUnsafe) -> ExprUnsafe { fold_expr_unsafe(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_expr_while(&mut self, i: ExprWhile) -> ExprWhile { fold_expr_while(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_expr_while_let(&mut self, i: ExprWhileLet) -> ExprWhileLet { fold_expr_while_let(self, i) }
Expand All @@ -202,6 +206,8 @@ fn fold_foreign_item_static(&mut self, i: ForeignItemStatic) -> ForeignItemStati
# [ cfg ( feature = "full" ) ]
fn fold_foreign_item_type(&mut self, i: ForeignItemType) -> ForeignItemType { fold_foreign_item_type(self, i) }

fn fold_generic_argument(&mut self, i: GenericArgument) -> GenericArgument { fold_generic_argument(self, i) }

fn fold_generic_param(&mut self, i: GenericParam) -> GenericParam { fold_generic_param(self, i) }

fn fold_generics(&mut self, i: Generics) -> Generics { fold_generics(self, i) }
Expand Down Expand Up @@ -274,7 +280,7 @@ fn fold_mutability(&mut self, i: Mutability) -> Mutability { fold_mutability(sel

fn fold_nested_meta_item(&mut self, i: NestedMetaItem) -> NestedMetaItem { fold_nested_meta_item(self, i) }

fn fold_parenthesized_parameter_data(&mut self, i: ParenthesizedParameterData) -> ParenthesizedParameterData { fold_parenthesized_parameter_data(self, i) }
fn fold_parenthesized_generic_arguments(&mut self, i: ParenthesizedGenericArguments) -> ParenthesizedGenericArguments { fold_parenthesized_generic_arguments(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_pat(&mut self, i: Pat) -> Pat { fold_pat(self, i) }
# [ cfg ( feature = "full" ) ]
Expand All @@ -301,15 +307,15 @@ fn fold_pat_tuple_struct(&mut self, i: PatTupleStruct) -> PatTupleStruct { fold_
fn fold_pat_wild(&mut self, i: PatWild) -> PatWild { fold_pat_wild(self, i) }

fn fold_path(&mut self, i: Path) -> Path { fold_path(self, i) }

fn fold_path_arguments(&mut self, i: PathArguments) -> PathArguments { fold_path_arguments(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_path_glob(&mut self, i: PathGlob) -> PathGlob { fold_path_glob(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_path_list(&mut self, i: PathList) -> PathList { fold_path_list(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_path_list_item(&mut self, i: PathListItem) -> PathListItem { fold_path_list_item(self, i) }

fn fold_path_parameters(&mut self, i: PathParameters) -> PathParameters { fold_path_parameters(self, i) }

fn fold_path_segment(&mut self, i: PathSegment) -> PathSegment { fold_path_segment(self, i) }
# [ cfg ( feature = "full" ) ]
fn fold_path_simple(&mut self, i: PathSimple) -> PathSimple { fold_path_simple(self, i) }
Expand Down Expand Up @@ -422,13 +428,11 @@ pub fn fold_abi_kind<V: Folder + ?Sized>(_visitor: &mut V, _i: AbiKind) -> AbiKi
}
}

pub fn fold_angle_bracketed_parameter_data<V: Folder + ?Sized>(_visitor: &mut V, _i: AngleBracketedParameterData) -> AngleBracketedParameterData {
AngleBracketedParameterData {
pub fn fold_angle_bracketed_generic_arguments<V: Folder + ?Sized>(_visitor: &mut V, _i: AngleBracketedGenericArguments) -> AngleBracketedGenericArguments {
AngleBracketedGenericArguments {
turbofish: _i . turbofish,
lt_token: _i . lt_token,
lifetimes: _i . lifetimes,
types: FoldHelper::lift(_i . types, |it| { _visitor.fold_type(it) }),
bindings: FoldHelper::lift(_i . bindings, |it| { _visitor.fold_type_binding(it) }),
args: FoldHelper::lift(_i . args, |it| { _visitor.fold_generic_argument(it) }),
gt_token: _i . gt_token,
}
}
Expand Down Expand Up @@ -750,6 +754,18 @@ pub fn fold_capture_by<V: Folder + ?Sized>(_visitor: &mut V, _i: CaptureBy) -> C
Ref => { Ref }
}
}

pub fn fold_const_param<V: Folder + ?Sized>(_visitor: &mut V, _i: ConstParam) -> ConstParam {
ConstParam {
attrs: FoldHelper::lift(_i . attrs, |it| { _visitor.fold_attribute(it) }),
const_token: _i . const_token,
ident: _i . ident,
colon_token: _i . colon_token,
ty: _visitor.fold_type(_i . ty),
eq_token: _i . eq_token,
default: (_i . default).map(|it| { _visitor.fold_expr(it) }),
}
}
# [ cfg ( feature = "full" ) ]
pub fn fold_constness<V: Folder + ?Sized>(_visitor: &mut V, _i: Constness) -> Constness {
use ::Constness::*;
Expand Down Expand Up @@ -833,7 +849,6 @@ pub fn fold_expr_binary<V: Folder + ?Sized>(_visitor: &mut V, _i: ExprBinary) ->
# [ cfg ( feature = "full" ) ]
pub fn fold_expr_block<V: Folder + ?Sized>(_visitor: &mut V, _i: ExprBlock) -> ExprBlock {
ExprBlock {
unsafety: _visitor.fold_unsafety(_i . unsafety),
block: _visitor.fold_block(_i . block),
}
}
Expand Down Expand Up @@ -1058,6 +1073,11 @@ pub fn fold_expr_kind<V: Folder + ?Sized>(_visitor: &mut V, _i: ExprKind) -> Exp
full!(_visitor.fold_expr_closure(_binding_0)),
)
}
Unsafe(_binding_0, ) => {
Unsafe (
full!(_visitor.fold_expr_unsafe(_binding_0)),
)
}
Block(_binding_0, ) => {
Block (
full!(_visitor.fold_expr_block(_binding_0)),
Expand Down Expand Up @@ -1279,6 +1299,13 @@ pub fn fold_expr_unary<V: Folder + ?Sized>(_visitor: &mut V, _i: ExprUnary) -> E
}
}
# [ cfg ( feature = "full" ) ]
pub fn fold_expr_unsafe<V: Folder + ?Sized>(_visitor: &mut V, _i: ExprUnsafe) -> ExprUnsafe {
ExprUnsafe {
unsafe_token: _i . unsafe_token,
block: _visitor.fold_block(_i . block),
}
}
# [ cfg ( feature = "full" ) ]
pub fn fold_expr_while<V: Folder + ?Sized>(_visitor: &mut V, _i: ExprWhile) -> ExprWhile {
ExprWhile {
cond: Box::new(_visitor.fold_expr(* _i . cond)),
Expand Down Expand Up @@ -1439,6 +1466,32 @@ pub fn fold_foreign_item_type<V: Folder + ?Sized>(_visitor: &mut V, _i: ForeignI
}
}

pub fn fold_generic_argument<V: Folder + ?Sized>(_visitor: &mut V, _i: GenericArgument) -> GenericArgument {
use ::GenericArgument::*;
match _i {
Lifetime(_binding_0, ) => {
Lifetime (
_binding_0,
)
}
Type(_binding_0, ) => {
Type (
_visitor.fold_type(_binding_0),
)
}
TypeBinding(_binding_0, ) => {
TypeBinding (
_visitor.fold_type_binding(_binding_0),
)
}
Const(_binding_0, ) => {
Const (
full!(_visitor.fold_expr_block(_binding_0)),
)
}
}
}

pub fn fold_generic_param<V: Folder + ?Sized>(_visitor: &mut V, _i: GenericParam) -> GenericParam {
use ::GenericParam::*;
match _i {
Expand All @@ -1452,6 +1505,11 @@ pub fn fold_generic_param<V: Folder + ?Sized>(_visitor: &mut V, _i: GenericParam
_visitor.fold_type_param(_binding_0),
)
}
Const(_binding_0, ) => {
Const (
_visitor.fold_const_param(_binding_0),
)
}
}
}

Expand Down Expand Up @@ -1951,8 +2009,8 @@ pub fn fold_nested_meta_item<V: Folder + ?Sized>(_visitor: &mut V, _i: NestedMet
}
}

pub fn fold_parenthesized_parameter_data<V: Folder + ?Sized>(_visitor: &mut V, _i: ParenthesizedParameterData) -> ParenthesizedParameterData {
ParenthesizedParameterData {
pub fn fold_parenthesized_generic_arguments<V: Folder + ?Sized>(_visitor: &mut V, _i: ParenthesizedGenericArguments) -> ParenthesizedGenericArguments {
ParenthesizedGenericArguments {
paren_token: _i . paren_token,
inputs: FoldHelper::lift(_i . inputs, |it| { _visitor.fold_type(it) }),
output: _visitor.fold_return_type(_i . output),
Expand Down Expand Up @@ -2119,6 +2177,23 @@ pub fn fold_path<V: Folder + ?Sized>(_visitor: &mut V, _i: Path) -> Path {
segments: FoldHelper::lift(_i . segments, |it| { _visitor.fold_path_segment(it) }),
}
}

pub fn fold_path_arguments<V: Folder + ?Sized>(_visitor: &mut V, _i: PathArguments) -> PathArguments {
use ::PathArguments::*;
match _i {
None => { None }
AngleBracketed(_binding_0, ) => {
AngleBracketed (
_visitor.fold_angle_bracketed_generic_arguments(_binding_0),
)
}
Parenthesized(_binding_0, ) => {
Parenthesized (
_visitor.fold_parenthesized_generic_arguments(_binding_0),
)
}
}
}
# [ cfg ( feature = "full" ) ]
pub fn fold_path_glob<V: Folder + ?Sized>(_visitor: &mut V, _i: PathGlob) -> PathGlob {
PathGlob {
Expand All @@ -2145,27 +2220,10 @@ pub fn fold_path_list_item<V: Folder + ?Sized>(_visitor: &mut V, _i: PathListIte
}
}

pub fn fold_path_parameters<V: Folder + ?Sized>(_visitor: &mut V, _i: PathParameters) -> PathParameters {
use ::PathParameters::*;
match _i {
None => { None }
AngleBracketed(_binding_0, ) => {
AngleBracketed (
_visitor.fold_angle_bracketed_parameter_data(_binding_0),
)
}
Parenthesized(_binding_0, ) => {
Parenthesized (
_visitor.fold_parenthesized_parameter_data(_binding_0),
)
}
}
}

pub fn fold_path_segment<V: Folder + ?Sized>(_visitor: &mut V, _i: PathSegment) -> PathSegment {
PathSegment {
ident: _i . ident,
parameters: _visitor.fold_path_parameters(_i . parameters),
arguments: _visitor.fold_path_arguments(_i . arguments),
}
}
# [ cfg ( feature = "full" ) ]
Expand Down
Loading