-
Notifications
You must be signed in to change notification settings - Fork 747
objc: Support method arguments #475
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
Conversation
☔ The latest upstream changes (presumably #473) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
Looks great! I have a few comments, nothing excessively important. Thanks!
src/ir/objc.rs
Outdated
} | ||
|
||
/// Formats the method call | ||
pub fn format_method_call(&self, args: &Vec<String>) -> String { |
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.
nit: This can take a &[String]
.
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.
Also, I'm not super-fond on the name of this method, but I can't suggest anything clearly better so oh well... :)
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.
The hard things in computer science :)
src/ir/objc.rs
Outdated
/// Formats the method call | ||
pub fn format_method_call(&self, args: &Vec<String>) -> String { | ||
let split_name: Vec<&str> = | ||
self.name.split(':').filter(|p| p.len() > 0).collect(); |
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.
nit: !p.is_empty()
instead of p.len > 0
?
src/ir/objc.rs
Outdated
if args.len() != split_name.len() { | ||
panic!("Incorrect method name or arguments for objc method, {} != {}", | ||
args.len(), | ||
split_name.len()); |
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.
Probably worth printing the argument lists?
src/ir/objc.rs
Outdated
.map(|parts| format!("{}:{} ", parts.0, parts.1)) | ||
.collect::<Vec<_>>() | ||
.join("") | ||
|
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.
nit: extra newline.
src/ir/objc.rs
Outdated
use clang; | ||
use clang_sys::CXChildVisit_Continue; | ||
use clang_sys::CXCursor_ObjCInstanceMethodDecl; | ||
use super::context::BindgenContext; | ||
use super::function::FunctionSig; | ||
// use clang_sys::CXCursor_ObjCSuperClassRef; |
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.
nit: Remove for now?
src/codegen/mod.rs
Outdated
.map(|ref arg| { | ||
let pat = arg.pat.clone().unwrap(); | ||
match pat.node { | ||
ast::PatKind::Ident(_, spanning, _) => { |
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.
not super awesome, but I guess it works. Alternatively, maybe get an Option<&mut Vec<String>>
in fnsig_arguments
that gets the argument names? That could also get used by arguments_for_signature
in src/codegen/helpers.rs
.
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.
Yeah, that actually makes perfect sense, and I quickly tried to implement that, but I'm still a bit of a noob in rust, and couldn't make mutable thing within option, modified in a map()'s FnMut thing to work, I guess I have some learning to do here..
src/codegen/mod.rs
Outdated
let arg_names: Vec<_> = fn_args.iter() | ||
.map(|ref arg| { | ||
let pat = arg.pat.clone().unwrap(); | ||
match pat.node { |
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 think you should be able to avoid this clone if you use match arg.pat.node
and use ref spanning
below.
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.
One last thing I overlooked, can be done in a followup if it's too much work for some reason.
Thanks again!
src/ir/function.rs
Outdated
@@ -85,6 +85,7 @@ fn get_abi(cc: CXCallingConv) -> abi::Abi { | |||
CXCallingConv_X86FastCall => abi::Abi::Fastcall, | |||
CXCallingConv_AAPCS => abi::Abi::Aapcs, | |||
CXCallingConv_X86_64Win64 => abi::Abi::Win64, | |||
CXCallingConv_Invalid => abi::Abi::C, // TODO: |
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.
Instead of this, could we make this function return Option<abi::Abi>
, commenting that it should only return None
for objective C stuff, and asserting that in the caller?
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.
Like this? (as separate commit)
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.
Yup, pretty much! :)
src/ir/function.rs
Outdated
@@ -228,6 +228,11 @@ impl FunctionSig { | |||
let ret = Item::from_ty_or_ref(ty_ret_type, None, None, ctx); | |||
let abi = get_abi(ty.call_conv()); | |||
|
|||
if abi == None { |
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.
nit: if abi.is_none()
.
src/ir/function.rs
Outdated
@@ -228,6 +228,11 @@ impl FunctionSig { | |||
let ret = Item::from_ty_or_ref(ty_ret_type, None, None, ctx); | |||
let abi = get_abi(ty.call_conv()); | |||
|
|||
if abi == None { | |||
assert!(cursor.kind() == CXCursor_ObjCInstanceMethodDecl, |
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.
nit: if you use assert_eq!
instead, the panic message will also show the failing cursor kind.
@bors-servo r+ Thanks! |
📌 Commit bc87b2a has been approved by |
objc: Support method arguments Welp, I attempted to get the method arguments working. I must confess, that I have not ran this against actual objective c code yet though.
☀️ Test successful - status-travis |
Welp, I attempted to get the method arguments working.
I must confess, that I have not ran this against actual objective c code yet though.