[dmd-internals] Refactoring of the Objective-C integration

Iain Buclaw via dmd-internals dmd-internals at puremagic.com
Tue Mar 7 10:27:59 PST 2017


On 26 February 2017 at 18:01, Jacob Carlborg via dmd-internals
<dmd-internals at puremagic.com> wrote:
> Hi,
>
> I would like to refactor the code in DMD for the Objective-C integration. I’m mostly interested in replacing the way used to determine if the Objective-C integration should be enabled or not.
>
> This is currently done in the makefile by either adding a file containing the code for the Objective-C integration or a stub implementation for the targets that does not support the Objective-C integration. Since this is determined at build time (of the compiler) this does not work well with cross-compiling, LDC have all targets enabled by default.
>
> I would like to change this to determine if the Objective-C integration should be enabled or not at runtime (of the compiler). I was thinking I could do that by having an interface with two classes implementing the interface. One which is used when the Objective-C integration should be enabled and one when it should be disabled. Example:
>
> __gshared Objc objc;
>
> void initialize()
> {
>     objc = global.params.hasObjectiveC ? new Supported : new Unsupported;
> }
>
> interface Objc
> {
>     void setObjc(ClassDeclaration cd);
> }
>
> final class Unsupported : Objc
> {
>     void setObjc(ClassDeclaration cd)
>     {
>         cd.error("Objective-C classes not supported");
>     }
> }
>
> final class Supported : Objc
> {
>     void setObjc(ClassDeclaration cd)
>     {
>         cd.objc.objc = true;
>     }
> }
>
> Does this sound like an acceptable solution or are there better alternatives? I’m also open to suggestions for better names for the classes.
>

IMO, at the very least it should be encapsulated into a struct like we
have Target or Port, removing all the free functions.

At some point in the future, all global.params.isXXX should be moved
to Target.  And hasObjectiveC should be encapsulated as an internal
state of the Objc struct also.



More information about the dmd-internals mailing list