summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-05-03 14:48:02 -0500
committerGitHub <noreply@github.com>2017-05-03 14:48:02 -0500
commit765671df1a6b93fccf7460043be865055de7ceb2 (patch)
tree83f2d370b530749c21eb9e16d6866ae4237dd0ee /src/codegen/mod.rs
parent8e9b3884961802a8c5c102ecfff06419e9695199 (diff)
parent335e5c726608e73af062315bcd76cf639e27330c (diff)
Auto merge of #673 - scoopr:objc, r=emilio
objc: Fixes to properly parse most of Foundation I had half of these just lying around in my commit queue for a while, having problems with the template param thing. Incidentally, either some other fixes made it work, or I had accidentally built against clang 4.0, which I guess doesn't work with the current approach. With these I'm able to parse and generate code for Foundation.framework, with regex ^NS.* (and skipping that one id redefine). Also needed --no-doc-comments, that I guess generated comment for an enum in the wrong place, didn't look at that.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 39b115fa..697c140f 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -2805,7 +2805,8 @@ impl CodeGenerator for Function {
fn objc_method_codegen(ctx: &BindgenContext,
method: &ObjCMethod,
- class_name: Option<&str>)
+ class_name: Option<&str>,
+ prefix: &str)
-> (ast::ImplItem, ast::TraitItem) {
let signature = method.signature();
let fn_args = utils::fnsig_arguments(ctx, signature);
@@ -2864,9 +2865,11 @@ fn objc_method_codegen(ctx: &BindgenContext,
let attrs = vec![];
+ let method_name = format!("{}{}", prefix, method.rust_name());
+
let impl_item = ast::ImplItem {
id: ast::DUMMY_NODE_ID,
- ident: ctx.rust_ident(method.rust_name()),
+ ident: ctx.rust_ident(&method_name),
vis: ast::Visibility::Inherited, // Public,
attrs: attrs.clone(),
node: ast::ImplItemKind::Method(sig.clone(), P(block)),
@@ -2876,7 +2879,7 @@ fn objc_method_codegen(ctx: &BindgenContext,
let trait_item = ast::TraitItem {
id: ast::DUMMY_NODE_ID,
- ident: ctx.rust_ident(method.rust_name()),
+ ident: ctx.rust_ident(&method_name),
attrs: attrs,
node: ast::TraitItemKind::Method(sig, None),
span: ctx.span(),
@@ -2898,14 +2901,23 @@ impl CodeGenerator for ObjCInterface {
for method in self.methods() {
let (impl_item, trait_item) =
- objc_method_codegen(ctx, method, None);
+ objc_method_codegen(ctx, method, None, "");
impl_items.push(impl_item);
trait_items.push(trait_item)
}
+ let instance_method_names : Vec<_> = self.methods().iter().map( { |m| m.rust_name() } ).collect();
+
for class_method in self.class_methods() {
+
+ let ambiquity = instance_method_names.contains(&class_method.rust_name());
+ let prefix = if ambiquity {
+ "class_"
+ } else {
+ ""
+ };
let (impl_item, trait_item) =
- objc_method_codegen(ctx, class_method, Some(self.name()));
+ objc_method_codegen(ctx, class_method, Some(self.name()), prefix);
impl_items.push(impl_item);
trait_items.push(trait_item)
}
@@ -2982,13 +2994,13 @@ mod utils {
result: &mut Vec<P<ast::Item>>) {
let use_objc = if ctx.options().objc_extern_crate {
quote_item!(ctx.ext_cx(),
- use objc;
+ #[macro_use]
+ extern crate objc;
)
.unwrap()
} else {
quote_item!(ctx.ext_cx(),
- #[macro_use]
- extern crate objc;
+ use objc;
)
.unwrap()
};