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", "license": "MIT",
"tags": ["tink", "macro", "utility"], "tags": ["tink", "macro", "utility"],
"description": "The macro toolkit ;)", "description": "The macro toolkit ;)",
"version": "0.0.1-beta", "version": "0.0.2-beta",
"releasenote": "Minor enhancements.", "releasenote": "Support haxe/java oddities.",
"contributors": ["back2dos"], "contributors": ["back2dos"],
"dependencies": { "dependencies": {
"tink_core": "1.0.0-beta.4" "tink_core": "1.0.0-beta.4"

View File

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

View File

@@ -87,8 +87,23 @@ class Constructor {
var tmp = MacroApi.tempName(); var tmp = MacroApi.tempName();
if (options.bypass) { if (options.bypass) {
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) if (false) { var $tmp = this.$name; $i{tmp} = $e; }, true);
addStatement(macro @:pos(pos) (untyped this).$name = $e, options.prepend); addStatement(macro @:pos(pos) (cast this).$name = $e, options.prepend);
}
} }
else else
addStatement(macro @:pos(pos) this.$name = $e, options.prepend); addStatement(macro @:pos(pos) this.$name = $e, options.prepend);