Compare commits

...

20 Commits

Author SHA1 Message Date
Juraj Kirchheim
5f959f788e Release 0.17.1 2018-10-02 09:12:28 +02:00
Juraj Kirchheim
4f84570bb7 Improve type parameter treatment. 2018-10-01 16:10:45 +02:00
Juraj Kirchheim
e398d0e694 Add helper for getting field suggestions. 2018-10-01 16:10:34 +02:00
Juraj Kirchheim
13d11f4f66 Make type comparator available. 2018-09-22 10:12:02 +02:00
Kevin Leung
d6142847eb Update ci script 2018-09-19 16:40:12 +08:00
Kevin Leung
e6a0304016 Release 0.17.0 2018-09-08 14:14:22 +08:00
Kevin Leung
69368937a4 let lix manage travix 2018-09-08 13:59:47 +08:00
Kevin Leung
df2389d2c8 Merge branch 'master' of https://github.com/haxetink/tink_macro 2018-09-08 13:53:37 +08:00
Kevin Leung
aad80afec2 Standardize build script 2018-09-08 13:53:27 +08:00
Juraj Kirchheim
b68c6ac4a1 Fix complex type intersection. 2018-09-03 18:49:08 +02:00
Juraj Kirchheim
682aeacce8 Add ComplexType::intersect. 2018-09-01 15:09:05 +02:00
Juraj Kirchheim
9bcec770eb Update travix. 2018-09-01 15:08:53 +02:00
Juraj Kirchheim
2310b6d8e4 Release 0.16.7 2018-08-23 11:24:32 +02:00
Kevin Leung
7f13916154 Fix haxe version check 2018-08-22 21:40:17 +08:00
Juraj Kirchheim
2b7204f8d3 Release 0.16.6 2018-07-26 12:57:57 +02:00
Juraj Kirchheim
7ca0d4a650 Merge branch 'master' of https://github.com/haxetink/tink_macro 2018-07-26 12:57:08 +02:00
Juraj Kirchheim
e38f5ae147 Expand metadata API of member. 2018-07-26 12:55:05 +02:00
Juraj Kirchheim
4186225eb5 Add haxe3 polyfill for ObjectField. 2018-07-26 12:54:31 +02:00
Juraj Kirchheim
f5a3d73c55 Merge pull request #22 from kLabz/fix/constructor-without-expr
Fix ClassBuilder's getConstructor() when super class is extern
2018-05-08 16:33:51 +02:00
k
f65df0e94b Fix ClassBuilder's getConstructor() when super class is extern
Handle super class constructor's expr being `null`, which happens
when the super class is an extern with a constructor definition.
2018-05-08 16:23:12 +02:00
15 changed files with 191 additions and 48 deletions

View File

@@ -1 +1 @@
{"version":"3.4.4","resolveLibs":"scoped"} {"version":"3.4.7","resolveLibs":"scoped"}

View File

@@ -1,28 +1,41 @@
sudo: required sudo: required
dist: trusty dist: trusty
language: haxe stages:
haxe: - test
- 3.2.1 - deploy
- development
matrix: language: node_js
allow_failures: node_js: 8
- haxe: development
install: os:
- haxelib install travix - linux
- haxelib run travix install # - osx
- haxelib install hx3compat
script:
- haxelib run travix node -lib hx3compat
env: env:
secure: T4SCtY5qmEsK1ARWPevJmqLm23tv4CobLrbPOQV3FsoQno7FCP1S/+9GmuoJKzeTjWMzdTeDsp8TVwZ6AyGjvhl2nZNjhU+QTsir4tfbYYRyvsz/QK6pveFbPQVv7OsnnaB4wbZtqGZ8mzFeQf7Ol4tsNe7iUFJb/iVc+4/lUxo= - HAXE_VERSION=3.4.7
- HAXE_VERSION=latest
install:
- npm i -g lix
- lix install haxe $HAXE_VERSION
- lix download
deploy: script:
provider: script - lix run travix node -lib hx3compat
script: haxe && haxelib run travix release
on: jobs:
tags: true include:
# - stage: test # should uncomment this when there is no matrix above (e.g. only one os, one env, etc)
- stage: deploy
language: haxe
haxe: "3.4.7"
os: linux
install: skip
script: skip
env:
secure: T4SCtY5qmEsK1ARWPevJmqLm23tv4CobLrbPOQV3FsoQno7FCP1S/+9GmuoJKzeTjWMzdTeDsp8TVwZ6AyGjvhl2nZNjhU+QTsir4tfbYYRyvsz/QK6pveFbPQVv7OsnnaB4wbZtqGZ8mzFeQf7Ol4tsNe7iUFJb/iVc+4/lUxo=
after_success:
- haxelib install travix
- haxelib run travix install
- haxelib run travix release

View File

@@ -0,0 +1,3 @@
-D hx3compat=1.0.0
# @install: lix --silent download "haxelib:/hx3compat#1.0.0" into hx3compat/1.0.0/haxelib
-cp ${HAXE_LIBCACHE}/hx3compat/1.0.0/haxelib/std

View File

@@ -0,0 +1,8 @@
-D tink_cli=0.3.1
# @install: lix --silent download "haxelib:/tink_cli#0.3.1" into tink_cli/0.3.1/haxelib
-lib tink_io
-lib tink_stringly
-lib tink_macro
-cp ${HAXE_LIBCACHE}/tink_cli/0.3.1/haxelib/src
# Make sure docs are generated
-D use-rtti-doc

View File

@@ -0,0 +1,5 @@
-D tink_io=0.5.0
# @install: lix --silent download "haxelib:/tink_io#0.5.0" into tink_io/0.5.0/haxelib
-lib tink_streams
-lib tink_core
-cp ${HAXE_LIBCACHE}/tink_io/0.5.0/haxelib/src

View File

@@ -0,0 +1,4 @@
-D tink_streams=0.2.1
# @install: lix --silent download "haxelib:/tink_streams#0.2.1" into tink_streams/0.2.1/haxelib
-lib tink_core
-cp ${HAXE_LIBCACHE}/tink_streams/0.2.1/haxelib/src

View File

@@ -0,0 +1,4 @@
-D tink_stringly=0.2.0
# @install: lix --silent download "haxelib:/tink_stringly#0.2.0" into tink_stringly/0.2.0/haxelib
-lib tink_core
-cp ${HAXE_LIBCACHE}/tink_stringly/0.2.0/haxelib/src

View File

@@ -1,4 +1,6 @@
# @run: haxelib run-dir travix ${HAXESHIM_LIBCACHE}/travix/0.10.3/haxelib -D travix=0.12.2
# @install: lix --silent download "haxelib:travix#0.10.3" into travix/0.10.3/haxelib # @install: lix --silent download "gh://github.com/back2dos/travix#f46e67b6330d2e85b487a9fd512b10e4e0f1058f" into travix/0.12.2/github/f46e67b6330d2e85b487a9fd512b10e4e0f1058f
-D travix=0.10.3 # @post-install: cd ${HAXE_LIBCACHE}/travix/0.12.2/github/f46e67b6330d2e85b487a9fd512b10e4e0f1058f && haxe -cp src --run travix.PostDownload
-cp ${HAXESHIM_LIBCACHE}/travix/0.10.3/haxelib/src # @run: haxelib run-dir travix ${HAXE_LIBCACHE}/travix/0.12.2/github/f46e67b6330d2e85b487a9fd512b10e4e0f1058f
-lib tink_cli
-cp ${HAXE_LIBCACHE}/travix/0.12.2/github/f46e67b6330d2e85b487a9fd512b10e4e0f1058f/src

View File

@@ -9,8 +9,8 @@
"contributors": [ "contributors": [
"back2dos" "back2dos"
], ],
"version": "0.16.5", "version": "0.17.1",
"releasenote": "Fix setter bypass.", "releasenote": "Improve type parameter treatment. Add helper for getting field suggestions. Make type comparator available.",
"tags": [ "tags": [
"tink", "tink",
"macro", "macro",

View File

@@ -37,3 +37,50 @@ class MacroApi {
return haxe.macro.Context.currentPos(); return haxe.macro.Context.currentPos();
} }
#if (haxe_ver >= 4)
typedef ObjectField = haxe.macro.Expr.ObjectField;
typedef QuoteStatus = haxe.macro.Expr.QuoteStatus;
#else
enum QuoteStatus {
Unquoted;
Quoted;
}
private typedef F = {
var field:String;
var expr:haxe.macro.Expr;
}
@:forward
abstract ObjectField(F) to F {
static var QUOTED = "@$__hx__";
inline function new(o) this = o;
public var field(get, never):String;
function get_field()
return
if (quotes == Quoted)
this.field.substr(QUOTED.length);
else this.field;
public var quotes(get, never):QuoteStatus;
function get_quotes()
return if (StringTools.startsWith(this.field, QUOTED)) Quoted else Unquoted;
@:from static function ofFull(o:{>F, quotes:QuoteStatus }):ObjectField
return switch o.quotes {
case null | Unquoted:
new ObjectField({ field: o.field, expr: o.expr });
default:
new ObjectField({ field: QUOTED + o.field, expr: o.expr });
}
@:from static function ofOld(o:F):ObjectField
return new ObjectField(o);
}
#end

View File

@@ -63,7 +63,9 @@ class ClassBuilder {
if (cl.constructor != null) { if (cl.constructor != null) {
try { try {
var ctor = cl.constructor.get(); var ctor = cl.constructor.get();
var func = Context.getTypedExpr(ctor.expr()).getFunction().sure(); var ctorExpr = ctor.expr();
if (ctorExpr == null) throw 'Super constructor has no expression';
var func = Context.getTypedExpr(ctorExpr).getFunction().sure();
for (arg in func.args) //this is to deal with type parameter substitutions for (arg in func.args) //this is to deal with type parameter substitutions
arg.type = null; arg.type = null;
@@ -196,4 +198,4 @@ class ClassBuilder {
p(builder); p(builder);
return builder.export(verbose); return builder.export(verbose);
} }
} }

View File

@@ -32,6 +32,7 @@ abstract Member(Field) from Field to Field {
} }
public var name(get, set):String; public var name(get, set):String;
public var meta(get, set):Metadata;
public var doc(get, set):Null<String>; public var doc(get, set):Null<String>;
public var kind(get, set):FieldType; public var kind(get, set):FieldType;
public var pos(get, set):Position; public var pos(get, set):Position;
@@ -76,6 +77,11 @@ abstract Member(Field) from Field to Field {
} }
return pos.makeFailure('missing @$name'); return pos.makeFailure('missing @$name');
} }
public function metaNamed(name)
return
if (this.meta == null) [];
else [for (tag in this.meta) if (tag.name == name) tag];
public inline function asField():Field return this; public inline function asField():Field return this;
public function publish() public function publish()
@@ -86,6 +92,12 @@ abstract Member(Field) from Field to Field {
this.access.push(APublic); this.access.push(APublic);
} }
inline function get_meta() return switch this.meta {
case null: this.meta = [];
case v: v;
}
inline function set_meta(param) return this.meta = param;
inline function get_name() return this.name; inline function get_name() return this.name;
inline function set_name(param) return this.name = param; inline function set_name(param) return this.name = param;

View File

@@ -70,7 +70,16 @@ class Sisyphus {
case TInst(_.get() => classType, params): case TInst(_.get() => classType, params):
switch (classType.kind) { switch (classType.kind) {
case KTypeParameter(_): case KTypeParameter(_):
direct();//TODO: check if the parameter is in scope, in which case the name can simply be used var ct = Types.asComplexType(classType.name);
switch Types.toType(ct) {
case Success(TInst(_.get() => cl, _)) if (
cl.kind.match(KTypeParameter(_))
&& cl.module == classType.module
&& cl.pack.join('.') == classType.pack.join('.')
): ct;
default:
direct();
}
default: default:
TPath(toTypePath(classType, params)); TPath(toTypePath(classType, params));
} }

View File

@@ -5,7 +5,6 @@ import haxe.ds.BalancedTree;
import haxe.macro.Context; import haxe.macro.Context;
import haxe.macro.Type; import haxe.macro.Type;
using haxe.macro.Tools;
using tink.MacroApi; using tink.MacroApi;
class TypeMap<V> extends BalancedTree<Type, V> implements IMap<Type, V> { class TypeMap<V> extends BalancedTree<Type, V> implements IMap<Type, V> {
@@ -16,18 +15,7 @@ class TypeMap<V> extends BalancedTree<Type, V> implements IMap<Type, V> {
super(); super();
} }
override function compare(k1:Type, k2:Type):Int { override function compare(k1:Type, k2:Type):Int
return k1.compare(k2, follow);
if (follow) {
k1 = k1.reduce();
k2 = k2.reduce();
}
return switch k1.getIndex() - k2.getIndex() {
case 0:
Reflect.compare(k1.toString(), k2.toString());//much to my surprise, this actually seems to work (at least with 3.4)
case v: v;
}
}
} }

View File

@@ -1,15 +1,13 @@
package tink.macro; package tink.macro;
import haxe.macro.Printer; import haxe.macro.Printer;
import Type in Enums;
import haxe.macro.Context; import haxe.macro.Context;
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.macro.Type; import haxe.macro.Type;
using tink.macro.Exprs; using haxe.macro.Tools;
using tink.macro.Positions; using tink.MacroApi;
using tink.macro.Functions;
using tink.CoreApi; using tink.CoreApi;
class Types { class Types {
@@ -183,6 +181,33 @@ class Types {
return ret; return ret;
} }
static public function intersect(types:Array<ComplexType>, ?pos:Position):Outcome<ComplexType, Error> {
if (types.length == 1) return Success(types[1]);
var paths = [],
fields = [];
for (t in types)
switch t {
case TPath(p): paths.push(p);
case TAnonymous(f):
for (f in f) fields.push(f);
case TExtend(p, f):
for (f in f) fields.push(f);
for (p in p) paths.push(p);
default:
return Failure(new Error(t.toString() + ' cannot be interesected', pos));
}
return Success(TExtend(paths, fields));
}
static public function lazyComplex(f:Void->Type) static public function lazyComplex(f:Void->Type)
return return
TPath({ TPath({
@@ -201,4 +226,25 @@ class Types {
throw 'assert'; throw 'assert';
} }
static public function compare(t1:Type, t2:Type, ?follow:Bool = true) {
if (follow) {
t1 = t1.reduce();
t2 = t2.reduce();
}
return switch t1.getIndex() - t2.getIndex() {
case 0:
Reflect.compare(t1.toString(), t2.toString());//much to my surprise, this actually seems to work (at least with 3.4)
case v: v;
}
}
static var SUGGESTIONS = ~/ \(Suggestions?: .*\)$/;
static public function getFieldSuggestions(type:ComplexType, name:String):String
return switch (macro (null : $type).$name).typeof() {
case Failure(SUGGESTIONS.match(_.message) => true): SUGGESTIONS.matched(0);
default: '';
}
} }