-
-
Notifications
You must be signed in to change notification settings - Fork 676
Add support for Objective-C classes #9179
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a418b35
Add internal support for anonymous variable declarations
jacob-carlborg f500da9
Add support for Objective-C classes
jacob-carlborg f973754
Add ABI documentation for Objective-C classes
jacob-carlborg c48b235
Deprecate Objective-C interfaces
jacob-carlborg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Deprecate Objective-C interfaces | ||
|
|
||
| Prior to this release, it was necessary to represent an Objective-C class | ||
| as a D interface. Now support for Objective-C classes has been implemented and | ||
| the `class` keyword should be used instead. | ||
|
|
||
| The reason for this deprecation is to allow `extern (Objective-C)` interfaces | ||
| to be repurposed for representing Objective-C protocols in the future. | ||
|
|
||
| Deprecated: | ||
| --- | ||
| extern (Objective-C) interface NSObject {} // deprecated | ||
| --- | ||
|
|
||
| Replace with: | ||
| --- | ||
| extern (Objective-C) class NSObject {} | ||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| Add support for Objective-C classes | ||
|
|
||
| Prior to this release D interfaces were used to represent Objective-C classes. | ||
| Now proper support for Objective-C classes has been added and D classes can | ||
| be used instead to represent Objective-C classes. It's preferred to use D | ||
| classes to represent Objective-C classes. | ||
|
|
||
| This release also adds support for implementing Objective-C subclasses and | ||
| methods in D. | ||
|
|
||
| To match the behavior in Objective-C some additional changes have been made: | ||
|
|
||
| $(UL | ||
| $(LI `static` and `final` methods are virtual. Although `final` methods are | ||
| virtual it's not possible to override a `final` method in a subclass) | ||
| $(LI `static` methods are overridable in subclasses) | ||
| ) | ||
|
|
||
| Example: | ||
|
|
||
| --- | ||
| extern (Objective-C) | ||
| class NSObject | ||
| { | ||
| static NSObject alloc() @selector("alloc"); | ||
| NSObject init() @selector("init"); | ||
| void release() @selector("release"); | ||
| } | ||
|
|
||
| extern (Objective-C) | ||
| class Foo : NSObject | ||
| { | ||
| override static Foo alloc() @selector("alloc"); | ||
| override Foo init() @selector("init"); | ||
|
|
||
| int bar(int a) @selector("bar:") | ||
| { | ||
| return a; | ||
| } | ||
| } | ||
|
|
||
| void main() | ||
| { | ||
| auto foo = Foo.alloc.init; | ||
| scope (exit) foo.release(); | ||
|
|
||
| assert(foo.bar(3) == 3); | ||
| } | ||
| --- | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
That sounds quite fishy. An
externdeclaration is used for compatibility, but we always stayed away from importing other language's semantic into D, as it's a hornets nest. It's fine to havefinalmethod as virtual if ObjC has no way to represent it, but allowingoverride staticis downright confusing.I assume this comes from the necessity to have it in the vtable, even if its static ?
Uh oh!
There was an error while loading. Please reload this page.
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.
Class/static methods in Objective-C are instance methods on the metaclass. In Objective-C classes are object themselves.
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.
There is no vtable for Objective-C classes. All method calls are lowered to a function in the Objective-C runtime.
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.
Without this, it is basically impossible to actually use existing Objective C classes. We sometimes need to be practical even when it sounds weird...
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.
@jacob-carlborg : Is there a way to expose this without changing the language ?
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.
Expose what? That static methods are overridable?