Skip to content

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

Merged
merged 2 commits into from
Feb 6, 2017
Merged

objc: Support method arguments #475

merged 2 commits into from
Feb 6, 2017

Conversation

scoopr
Copy link
Contributor

@scoopr scoopr commented Feb 4, 2017

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.

@highfive
Copy link

highfive commented Feb 4, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@bors-servo
Copy link

☔ The latest upstream changes (presumably #473) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@emilio emilio left a 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 {
Copy link
Contributor

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].

Copy link
Contributor

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... :)

Copy link
Contributor Author

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();
Copy link
Contributor

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());
Copy link
Contributor

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("")

Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Remove for now?

.map(|ref arg| {
let pat = arg.pat.clone().unwrap();
match pat.node {
ast::PatKind::Ident(_, spanning, _) => {
Copy link
Contributor

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.

Copy link
Contributor Author

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..

let arg_names: Vec<_> = fn_args.iter()
.map(|ref arg| {
let pat = arg.pat.clone().unwrap();
match pat.node {
Copy link
Contributor

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.

Copy link
Contributor

@emilio emilio left a 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!

@@ -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:
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, pretty much! :)

@@ -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 {
Copy link
Contributor

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().

@@ -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,
Copy link
Contributor

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.

@emilio
Copy link
Contributor

emilio commented Feb 6, 2017

@bors-servo r+

Thanks!

@bors-servo
Copy link

📌 Commit bc87b2a has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit bc87b2a with merge 7fa654c...

bors-servo pushed a commit that referenced this pull request Feb 6, 2017
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.
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: emilio
Pushing 7fa654c to master...

@bors-servo bors-servo merged commit bc87b2a into rust-lang:master Feb 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants