-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
rewrite_self_arg
to allow generic output macro
- Loading branch information
Showing
3 changed files
with
119 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod __rewrite_self_arg; | ||
mod declare_class; | ||
mod extern_class; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! __rewrite_self_arg { | ||
{ | ||
($out_macro:path) | ||
($($args:tt)*) | ||
$($macro_args:tt)* | ||
} => { | ||
$crate::__rewrite_self_arg! { | ||
($out_macro) | ||
// Duplicate args out so that we can match on `self`, while still | ||
// use it as a function argument | ||
@($($args)*) | ||
@($($args)*) | ||
$($macro_args)* | ||
} | ||
}; | ||
|
||
// Instance method | ||
{ | ||
($out_macro:path) | ||
@(&mut self $($__rest_args:tt)*) | ||
@(&mut $self:ident $(, $($rest_args:tt)*)?) | ||
$($macro_args:tt)* | ||
} => { | ||
$out_macro! { | ||
$($macro_args)* | ||
@(instance_method) | ||
@( | ||
$self: &mut Self, | ||
_: $crate::runtime::Sel, | ||
$($($rest_args)*)? | ||
) | ||
} | ||
}; | ||
{ | ||
($out_macro:path) | ||
@(&self $($__rest_args:tt)*) | ||
@(&$self:ident $(, $($rest_args:tt)*)?) | ||
$($macro_args:tt)* | ||
} => { | ||
$out_macro! { | ||
$($macro_args)* | ||
@(instance_method) | ||
@( | ||
$self: &Self, | ||
_: $crate::runtime::Sel, | ||
$($($rest_args)*)? | ||
) | ||
} | ||
}; | ||
{ | ||
($out_macro:path) | ||
@(mut self: $__self_ty:ty $(, $($__rest_args:tt)*)?) | ||
@(mut $self:ident: $self_ty:ty $(, $($rest_args:tt)*)?) | ||
$($macro_args:tt)* | ||
} => { | ||
$out_macro! { | ||
$($macro_args)* | ||
@(instance_method) | ||
@( | ||
mut $self: $self_ty, | ||
_: $crate::runtime::Sel, | ||
$($($rest_args)*)? | ||
) | ||
} | ||
}; | ||
{ | ||
($out_macro:path) | ||
@(self: $__self_ty:ty $(, $($__rest_args:tt)*)?) | ||
@($self:ident: $self_ty:ty $(, $($rest_args:tt)*)?) | ||
$($macro_args:tt)* | ||
} => { | ||
$out_macro! { | ||
$($macro_args)* | ||
@(instance_method) | ||
@( | ||
$self: $self_ty, | ||
_: $crate::runtime::Sel, | ||
$($($rest_args)*)? | ||
) | ||
} | ||
}; | ||
|
||
// Class method | ||
{ | ||
($out_macro:path) | ||
@($($__args:tt)*) | ||
@($($args:tt)*) | ||
$($macro_args:tt)* | ||
} => { | ||
$out_macro! { | ||
$($macro_args)* | ||
@(class_method) | ||
@( | ||
_: &$crate::runtime::Class, | ||
_: $crate::runtime::Sel, | ||
$($args)* | ||
) | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters