-
Notifications
You must be signed in to change notification settings - Fork 340
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
Allow function aliases #218
Changes from 2 commits
5c91efe
8f7891c
f70508b
2aceb7e
f81a2d7
fa9799b
6d63840
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ pub struct Parser<'a> { | |
pub doc: Option<&'a mut Doc>, | ||
pub derives: Option<&'a mut Vec<Derive>>, | ||
pub repr: Option<&'a mut Option<Atom>>, | ||
pub alias: Option<&'a mut Option<Ident>>, | ||
} | ||
|
||
pub(super) fn parse_doc(cx: &mut Errors, attrs: &[Attribute]) -> Doc { | ||
|
@@ -57,8 +58,19 @@ pub(super) fn parse(cx: &mut Errors, attrs: &[Attribute], mut parser: Parser) { | |
} | ||
Err(err) => return cx.push(err), | ||
} | ||
} else if attr.path.is_ident("alias") { | ||
match attr.parse_args_with(|input: ParseStream| input.parse()) { | ||
Ok(alias) => { | ||
if let Some(a) = &mut parser.alias { | ||
**a = Some(alias); | ||
continue; | ||
} | ||
} | ||
Err(err) => return cx.push(err), | ||
} | ||
} else { | ||
return cx.error(attr, "unsupported attribute"); | ||
} | ||
return cx.error(attr, "unsupported attribute"); | ||
Comment on lines
+71
to
-61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was correct before the PR. The change made in the PR makes well-formed attributes silently accepted anywhere where not expected, like putting a #[derive()] attribute on a function or a #[repr()] attribute on a function. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ impl<'a> Types<'a> { | |
rust.insert(ident); | ||
} | ||
Api::CxxFunction(efn) | Api::RustFunction(efn) => { | ||
let ident = &efn.ident; | ||
let ident = if let Some(alias) = &efn.alias { alias } else { &efn.ident }; | ||
if !function_names.insert((&efn.receiver, ident)) { | ||
duplicate_name(cx, efn, ident); | ||
} | ||
Comment on lines
+119
to
122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As implemented in this PR, the
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this implementation of functions having an "ident" and an optional "alias", and especially counting on each use site to remember whether they should be checking for presence of the alias.
In my mind every function should have a non-optional rust name and non-optional c++ name. That's how we should store them post-parsing. Every place which uses of a function name will pick which of the two they want.