Support haxe/java oddities.

This commit is contained in:
back2dos
2013-10-20 12:38:09 +02:00
parent bf6098c9dc
commit 583f404089
3 changed files with 46 additions and 23 deletions

View File

@@ -4,8 +4,8 @@
"license": "MIT",
"tags": ["tink", "macro", "utility"],
"description": "The macro toolkit ;)",
"version": "0.0.1-beta",
"releasenote": "Minor enhancements.",
"version": "0.0.2-beta",
"releasenote": "Support haxe/java oddities.",
"contributors": ["back2dos"],
"dependencies": {
"tink_core": "1.0.0-beta.4"

View File

@@ -48,28 +48,36 @@ class ClassBuilder {
if (constructor == null)
if (fallback != null)
new Constructor(fallback);
else if (target.superClass != null && target.superClass.t.get().constructor != null) {
try {
var ctor = Context.getLocalClass().get().superClass.t.get().constructor.get();
var func = Context.getTypedExpr(ctor.expr()).getFunction().sure();
else {
var sup = target.superClass;
while (sup != null) {
var cl = sup.t.get();
if (cl.constructor != null) {
try {
var ctor = cl.constructor.get();
var func = Context.getTypedExpr(ctor.expr()).getFunction().sure();
//TODO: Check that the code below is no longer necessary
// for (arg in func.args)
// arg.type = null;
for (arg in func.args) //this is to deal with type parameter substitutions
arg.type = null;
func.expr = "super".resolve().call(func.getArgIdents());
constructor = new Constructor(func);
if (ctor.isPublic)
constructor.publish();
func.expr = "super".resolve().call(func.getArgIdents());
constructor = new Constructor(func);
if (ctor.isPublic)
constructor.publish();
}
catch (e:Dynamic) {//fails for unknown reason
if (e == 'assert')
neko.Lib.rethrow(e);
constructor = new Constructor(null);
}
break;
}
else sup = cl.superClass;
}
catch (e:Dynamic) {//fails for unknown reason
if (e == 'assert')
neko.Lib.rethrow(e);
if (constructor == null)
constructor = new Constructor(null);
}
}
else
constructor = new Constructor(null);
return constructor;
}

View File

@@ -87,8 +87,23 @@ class Constructor {
var tmp = MacroApi.tempName();
if (options.bypass) {
addStatement(macro @:pos(pos) if (false) { var $tmp = this.$name; $i{tmp} = $e; }, true);
addStatement(macro @:pos(pos) (untyped this).$name = $e, options.prepend);
if (haxe.macro.Context.defined('java')) {
addStatement(
macro @:pos(pos)
if (Math.random() < .0) {
//if this is false, then it gets thrown out before reaching the backend which will then generate invalid code
var $tmp = this.$name;
$i{tmp} = $e;
this.$name = $i{tmp};
},
true
);
addStatement(macro @:pos(pos) (cast this).$name = $e, options.prepend);
}
else {
addStatement(macro @:pos(pos) if (false) { var $tmp = this.$name; $i{tmp} = $e; }, true);
addStatement(macro @:pos(pos) (cast this).$name = $e, options.prepend);
}
}
else
addStatement(macro @:pos(pos) this.$name = $e, options.prepend);