Add support for Objective-C class/static methods#7762
Conversation
|
Thanks for your pull request and interest in making D better, @jacob-carlborg! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
60c78e8 to
2019571
Compare
741d089 to
4eadda2
Compare
|
There is not a word about what this actually does. |
Yeah, that's why the unchecked list item, "Could use some more documentation", in the description. |
|
@stefan-koch-sociomantic On a high level the Objective-C ABI looks something like this: extern (Objective-C) interface NSObject
{
NSObject init() @selector("init");
}
NSObject o;
o.init();The above method call is translated to a regular C function call in the form of: For a more detailed explanation see the commit message of the first phase of the Objective-C integration 867d547. There's also this Wikipedia page about Objective-C metaclasses [1]. |
9217b2c to
ff304fa
Compare
docs/objective-c_abi.md
Outdated
|
|
||
| There are several Objective-C ABIs available: | ||
|
|
||
| * Apple legacy ABI (also know as fragile ABI) - used on macOS 32bit and the old |
There was a problem hiding this comment.
Just so I have the link correct in my head, this is also known as the Nextstep abi?
There was a problem hiding this comment.
Yes. I've moved the work on the ABI documentation to a separate branch until it's ready [1]. The description in the separate branch is a bit more clear and thorough.
There was a problem hiding this comment.
OK.
I've just checked, and gcc objc seems to support all of these ABIs. I should see if I can re-use the existing code sometime in gdc.
There was a problem hiding this comment.
Before Apple used Clang, they used GCC with this ABI that is implemented here. I don't think anything has changed since then. I'm not sure if that was only supported in their own version of GCC or in the standard version as well.
There was a problem hiding this comment.
BTW, some code review would be nice 😉.
|
I don't see any issue with the code in this PR, but I don't know anything about Objective-C, or what D's goals are in supporting it. Isn't Objective-C reaching end of life with the emergence of Swift? |
D's goals are to support as much of Objective-C as possible or what's necessary to implement meaningful Cocoa applications [1].
All of the Apple frameworks are still implemented in Objective-C. Apple is not, most likely, going to replace them in the near future. Swift can interface with Objective-C as well, which is a crucial part since all the frameworks are written in Objective-C. That means that D can interface with Swift code as well, assuming both use the Objective-C interface. Apple might implement new frameworks using Swift and possible rewrite existing frameworks as well, but they would need to support an Objective-C interface for a significant future. Why was the |
Documentation helps the review, and if, from the author's perspective, a PR is not complete enough to be merged, it is indeed a WIP. |
Well, it depends. I think the code is ready as is. Documentation is missing yes, but keep in mind that most code in DMD was reviewed and merged without documentation. I mean, I don't see any documentation describing any of the C++ ABIs. |
src/dmd/objc.d
Outdated
| else | ||
| { | ||
| error("base " ~ errorType ~ " for an Objective-C " ~ | ||
| errorType ~ " must be extern (Objective-C)"); |
There was a problem hiding this comment.
tick marks around extern (Objective-C), I believe.
There was a problem hiding this comment.
Yes, good catch.
ff304fa to
860a7f4
Compare
|
|
||
| private: | ||
|
|
||
| char[] format(size_t bufLength, Args...)(return ref char[bufLength] buffer, |
There was a problem hiding this comment.
Yes, that's why the "Could use some more documentation" checkbox in the PR description is not checked 😃.
| return symbol; | ||
| } | ||
|
|
||
| Symbol* getClassReference(const ClassDeclaration classDeclaration) |
| return moduleInfo; | ||
| } | ||
|
|
||
| Symbol* getClassName(const ClassDeclaration classDeclaration) |
| return false; | ||
| } | ||
|
|
||
| Symbol* symbolName(const(char)[] name, int sclass, type* t) |
There was a problem hiding this comment.
Ddoc comment for these three
src/dmd/objc.d
Outdated
| } | ||
| } | ||
|
|
||
| private void setMetaclass(alias newMetaclass, T)(T classDeclaration, Scope* sc) |
src/dmd/objc.d
Outdated
|
|
||
|
|
||
| /** | ||
| * This struct contains all data for a class declaration that is needed for the |
There was a problem hiding this comment.
remove This struct contains. It's redundant.
|
Please see #7923 as well. |
87eafec to
201059e
Compare
|
Added documentation. |
201059e to
bf824c6
Compare
|
Created a PR for the dlang.org part now as well: dlang/dlang.org#2246. Everything on my todo list has been completed. This is ready to go. |
|
@JinShil more than 72 hours have passed. |
|
Thanks. |
A few missing things:
Documentation of the Objective-C ABI has been started, available in a separate branch: https://github.com/jacob-carlborg/dmd/blob/objc_abi_docs/docs/objective-c_abi.md.
The dlang.org part dlang/dlang.org#2246.