Skip to content

Commit

Permalink
Refactor __rewrite_self_arg a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Aug 13, 2022
1 parent dcd57c1 commit ad3e42e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
18 changes: 9 additions & 9 deletions objc2/src/macros/__rewrite_self_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ macro_rules! __rewrite_self_arg {
{
($out_macro:path)
@(&mut self $($__rest_args:tt)*)
@(&mut $self:ident $(, $($rest_args:tt)*)?)
@(&mut $self:ident $(, $($rest:tt)*)?)
$($macro_args:tt)*
} => {
$out_macro! {
Expand All @@ -29,14 +29,14 @@ macro_rules! __rewrite_self_arg {
@(
$self: &mut Self,
_: $crate::runtime::Sel,
$($($rest_args)*)?
)
@($($($rest)*)?)
}
};
{
($out_macro:path)
@(&self $($__rest_args:tt)*)
@(&$self:ident $(, $($rest_args:tt)*)?)
@(&$self:ident $(, $($rest:tt)*)?)
$($macro_args:tt)*
} => {
$out_macro! {
Expand All @@ -45,14 +45,14 @@ macro_rules! __rewrite_self_arg {
@(
$self: &Self,
_: $crate::runtime::Sel,
$($($rest_args)*)?
)
@($($($rest)*)?)
}
};
{
($out_macro:path)
@(mut self: $__self_ty:ty $(, $($__rest_args:tt)*)?)
@(mut $self:ident: $self_ty:ty $(, $($rest_args:tt)*)?)
@(mut $self:ident: $self_ty:ty $(, $($rest:tt)*)?)
$($macro_args:tt)*
} => {
$out_macro! {
Expand All @@ -61,14 +61,14 @@ macro_rules! __rewrite_self_arg {
@(
mut $self: $self_ty,
_: $crate::runtime::Sel,
$($($rest_args)*)?
)
@($($($rest)*)?)
}
};
{
($out_macro:path)
@(self: $__self_ty:ty $(, $($__rest_args:tt)*)?)
@($self:ident: $self_ty:ty $(, $($rest_args:tt)*)?)
@($self:ident: $self_ty:ty $(, $($rest:tt)*)?)
$($macro_args:tt)*
} => {
$out_macro! {
Expand All @@ -77,8 +77,8 @@ macro_rules! __rewrite_self_arg {
@(
$self: $self_ty,
_: $crate::runtime::Sel,
$($($rest_args)*)?
)
@($($($rest)*)?)
}
};

Expand All @@ -95,8 +95,8 @@ macro_rules! __rewrite_self_arg {
@(
_: &$crate::runtime::Class,
_: $crate::runtime::Sel,
$($args)*
)
@($($args)*)
}
};
}
25 changes: 16 additions & 9 deletions objc2/src/macros/declare_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ macro_rules! __inner_declare_class {
@($($ret)?)
@($body)
// Will add @(kind)
// Will add @(args)
// Will add @(args_start)
// Will add @(args_rest)
}

$crate::__inner_declare_class! {
Expand Down Expand Up @@ -54,6 +55,8 @@ macro_rules! __inner_declare_class {
@($name)
@($($ret)?)
@($body)

// Same as above
}

$crate::__inner_declare_class! {
Expand All @@ -73,12 +76,13 @@ macro_rules! __inner_declare_class {
@()
@($($body:tt)*)
@($($_kind:tt)*)
@($($args:tt)*)
@($($args_start:tt)*)
@($($args_rest:tt)*)
} => {
$crate::__attribute_helper! {
@strip_sel
$(@[$($m)*])*
($($qualifiers)* fn $name($($args)*) {
($($qualifiers)* fn $name($($args_start)* $($args_rest)*) {
$($body)*
})
}
Expand All @@ -92,12 +96,13 @@ macro_rules! __inner_declare_class {
@($ret:ty)
@($($body:tt)*)
@($($_kind:tt)*)
@($($args:tt)*)
@($($args_start:tt)*)
@($($args_rest:tt)*)
} => {
$crate::__attribute_helper! {
@strip_sel
$(@[$($m)*])*
($($qualifiers)* fn $name($($args)*) -> <$ret as $crate::encode::EncodeConvert>::Encode {
($($qualifiers)* fn $name($($args_start)* $($args_rest)*) -> <$ret as $crate::encode::EncodeConvert>::Encode {
<$ret as $crate::encode::EncodeConvert>::into_encode($($body)*)
})
}
Expand All @@ -111,7 +116,8 @@ macro_rules! __inner_declare_class {
@($($_ret:tt)*)
@($($_body:tt)*)
@(class_method)
@($($args:tt)*)
@($($args_start:tt)*)
@($($args_rest:tt)*)
} => {
$builder.add_class_method(
$crate::__attribute_helper! {
Expand All @@ -121,7 +127,7 @@ macro_rules! __inner_declare_class {
@call_sel
},
Self::$name as $crate::__fn_ptr! {
@($($qualifiers)*) $($args)*
@($($qualifiers)*) $($args_start)* $($args_rest)*
},
);
};
Expand All @@ -133,7 +139,8 @@ macro_rules! __inner_declare_class {
@($($_ret:tt)*)
@($($_body:tt)*)
@(instance_method)
@($($args:tt)*)
@($($args_start:tt)*)
@($($args_rest:tt)*)
} => {
$builder.add_method(
$crate::__attribute_helper! {
Expand All @@ -143,7 +150,7 @@ macro_rules! __inner_declare_class {
@call_sel
},
Self::$name as $crate::__fn_ptr! {
@($($qualifiers)*) $($args)*
@($($qualifiers)*) $($args_start)* $($args_rest)*
},
);
};
Expand Down

0 comments on commit ad3e42e

Please sign in to comment.