Compare commits

..

7 Commits
0.6.3 ... 0.6.4

Author SHA1 Message Date
back2dos
df01d82300 Release 0.6.4 2015-05-28 08:59:18 +02:00
back2dos
9b4e9cb81f Merge branch 'master' of https://github.com/haxetink/tink_macro 2015-05-28 08:58:18 +02:00
back2dos
b90aae8386 Minor simplification in constructor generation. 2015-05-28 08:57:55 +02:00
back2dos
ab34b31bbd Updated doc. 2015-05-22 09:01:01 +02:00
Juraj Kirchheim
ad3526795c Merge pull request #3 from grisevg/master
Made imports and using expressions to use CoreApi redefinitions.
2015-05-19 18:27:27 +02:00
Eugene Griskov
f4bf23a66b Made imports and using expressions to use CoreApi redefinitions. 2015-05-19 17:22:23 +01:00
back2dos
a01a1b16ae Minor fix. 2015-05-19 01:45:02 +02:00
7 changed files with 11 additions and 11 deletions

View File

@@ -335,7 +335,7 @@ The first thing to point out is that constructors are handled separately. This i
As for the rest of the members, you can just iterate over them. It's worth noting that the iterator runs over a snapshot made at the time of its creation, so removing and adding fields during iteration has no effect on the iteration itself.
You can add a member. If you try adding a member named `"new"`, you'll get an exception. So don't do it. Read up on constructors below. If you try adding a duplicate member, you will get a compilation error at the second member's `Position`. If you add a member that already exists in the super class, the `override` is added automatically.
You can add a member. If you try adding a member named `"new"`, you'll get an exception - so don't. Find out about how tink_macro handles constructors below. If you add a member that already exists in the super class, the `override` is added automatically.
And when you're done, you can `export` everything to an array of fields. If you set `verbose` to true, you will get compiler warnings for every generated field at the position of the field. This is way you can see the generated code even if the application cannot compile for some reason.
@@ -343,7 +343,7 @@ The intended use is with `run` that will send the same `ClassBuilder` through a
## Constructor
Constructors are relatively tricky, especially when you have inheritance. If you do not specify a constructor, than that of the the super class is used. If you do specify one, then it needn't be compatible with the super class, but it needs to call it. Macros represent them as an instance field called `new` that must be a function. However if you think about it, a constructor belongs to a class, not an instance. So this is all a little dodgy.
Constructors are relatively tricky, especially when you have inheritance. If you do not specify a constructor, than that of the the super class is used. If you do specify one, then it needn't be compatible with the super class, but it needs to call it. Macros represent them as an instance field called `new` that must be a function. However if you think about it, a constructor belongs to a class, not an instance. So this is all a little dodgy. The constructor API is an attempt to create a more rigid solution.
The `Constructor` API is the result of countless struggles with constructors. Still it may not be for you. In that case feedback is appreciated and currently the suggested method is to deal with the constructor after you've exported all fields from the `ClassBuilder`.

View File

@@ -11,8 +11,8 @@
"contributors": [
"back2dos"
],
"releasenote": "Make class builder lazy and less opinionated.",
"version": "0.6.3",
"releasenote": "Minor simplification in constructor generation.",
"version": "0.6.4",
"url": "http://haxetink.org/tink_macro",
"dependencies": {
"tink_core": ""

View File

@@ -17,7 +17,7 @@ typedef Unops = tink.macro.Ops.Unary;
//TODO: consider adding stuff from haxe.macro.Expr here
typedef MacroOutcome<D, F> = tink.core.Outcome<D, F>;
typedef MacroOutcomeTools = tink.core.Outcome.OutcomeTools;
typedef MacroOutcomeTools = tink.OutcomeTools;
typedef Option<T> = haxe.ds.Option<T>;

View File

@@ -115,8 +115,10 @@ class ClassBuilder {
return ret;
}
public function iterator():Iterator<Member>
public function iterator():Iterator<Member> {
init();
return this.memberList.copy().iterator();
}
public function hasOwnMember(name:String):Bool {
init();

View File

@@ -96,9 +96,7 @@ class Constructor {
case Success(member): member.addMeta(':isVar');
default:
}
addStatement(macro @:pos(pos) if (false) { var $tmp = this.$name; $i{tmp} = $e; }, true);
addStatement(macro @:pos(pos) (cast this).$name = $e, options.prepend);
addStatement(macro @:pos(pos) (cast this).$name = if (true) $e else this.$name, options.prepend);
}
else
addStatement(macro @:pos(pos) this.$name = $e, options.prepend);

View File

@@ -14,7 +14,7 @@ using StringTools;
using tink.macro.Positions;
using tink.macro.Exprs;
using tink.macro.Types;
using tink.core.Outcome;
using tink.CoreApi;
typedef VarDecl = { name : String, type : ComplexType, expr : Null<Expr> };
typedef ParamSubst = {

View File

@@ -10,7 +10,7 @@ import haxe.macro.Type;
using tink.macro.Exprs;
using tink.macro.Positions;
using tink.macro.Functions;
using tink.core.Outcome;
using tink.CoreApi;
class Types {
static var types = new Map<Int,Void->Type>();