[dmd-internals] Refactoring of the Objective-C integration
Jacob Carlborg via dmd-internals
dmd-internals at puremagic.com
Sun Feb 26 09:01:19 PST 2017
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.
—
/Jacob Carlborg
More information about the dmd-internals
mailing list