@@ -42,26 +42,12 @@ class HashLinkFixer {
4242 var cl = clRef .get ();
4343
4444 if (cl .isAbstract || cl .isExtern || cl .isInterface ) return fields ;
45- if (! cl .name .endsWith (" _Impl_" ) && ! cl .name .endsWith (" _HSX" ) && ! cl .name .endsWith (" _HSC" ) && ! cl .name .endsWith (" _HLFHelper" )) {
46- var metas = cl .meta .get ();
47-
45+ if (! cl .name .endsWith (" _Impl_" ) && ! cl .name .endsWith (" _HSX" ) && ! cl .name .endsWith (" _HSC" )) {
4846 if (cl .params .length > 0 )
4947 return fields ;
5048
51- if (cl .module == " EReg" ) return fields ; // private typedef in same class
52- if (cl .module == " hl.Format" ) return fields ; // enum in same class
53-
5449 var definedFields = [];
5550
56- var helperClass = macro class {
57-
58- };
59-
60- helperClass .pos = cl .pos ;
61-
62- var module = cl .module + " _HLFHelper" ;
63- var hcClassName = cl .name + " _HLFHelper" ;
64-
6551 for (f in fields .copy ()) {
6652 if (f == null )
6753 continue ;
@@ -70,10 +56,12 @@ class HashLinkFixer {
7056
7157 if (definedFields .contains (f .name )) continue ; // no duplicate fields
7258
59+ var hlNativeMeta = null ;
7360 var hasHlNative = false ;
7461 for (m in f .meta )
7562 if (m .name == " :hlNative" ) {
7663 hasHlNative = true ;
64+ hlNativeMeta = m ;
7765 break ;
7866 }
7967
@@ -92,67 +80,72 @@ class HashLinkFixer {
9280 var overrideExpr : Expr ;
9381 var returns : Bool = ! fun .ret .match (TPath ({name : " Void" }));
9482
83+ var printer = new haxe.macro. Printer ();
84+ if (cl .module == " hl.Gc" && fun .ret == null ) returns = false ; // fix since they dont explicitly set :Void
85+ if (cl .module == " hl.Format" && fun .ret == null ) returns = false ; // fix since they dont explicitly set :Void
86+
9587 var name = ' hlf_ ${f .name }' ;
9688
9789 var arguments = fun .args == null ? [] : [for (a in fun .args ) macro $i {a .name }];
9890
99- var funcExpr : Expr = returns ? {
100- // macro return $i{name}($a{arguments});
101- macro return @:privateAccess $i {hcClassName }.$name ($a {arguments });
102- } : {
103- macro @:privateAccess $i {hcClassName }.$name ($a {arguments });
104- };
91+ var funcExpr : Expr = macro @:privateAccess $i {name }($a {arguments });
92+ if (returns ) funcExpr = macro return $funcExpr ;
93+
94+ var cleanMeta = f .meta .copy ().filter (function (m ) return m .name != " :hlNative" );
95+ var hasBareMeta = hlNativeMeta .params .length == 0 ;
96+
97+ var meta = f .meta .copy ();
98+ switch hlNativeMeta {
99+ case {params : []}:
100+ meta = [{name : " :hlNative" , params : [macro " std" , macro $v {f .name }], pos : Context .currentPos ()}].concat (cleanMeta );
101+ case {params : [_ .expr => EConst (CString (name ))]}:
102+ meta = [{name : " :hlNative" , params : [macro " std" , macro $v {name }], pos : Context .currentPos ()}].concat (cleanMeta );
103+ case {params : [_ .expr => EConst (CFloat (version ))]}:
104+ var curVersion = Context .definedValue (" hl_ver" );
105+ if (curVersion == null ) curVersion = " " ;
106+ if (version > curVersion ) {
107+ meta = cleanMeta ;
108+ if (f .meta .filter ((m ) -> m .name == " :noExpr" ).length > 0 )
109+ Context .error (" Missing function body" , f .pos );
110+ funcExpr = fun .expr ; // restore to default behaviour
111+ } else {
112+ meta = [{name : " :hlNative" , params : [macro " std" , macro $v {f .name }], pos : Context .currentPos ()}].concat (cleanMeta );
113+ }
114+ default :
115+ }
105116
106117 var fiel : Field = {
107118 name : name ,
108119 pos : Context .currentPos (),
109120 kind : FFun ({
110121 ret : fun .ret ,
111122 params : fun .params .copy (),
112- expr : fun . expr ,
123+ expr : funcExpr ,
113124 args : fun .args .copy ()
114125 }),
115- access : f .access .copy (),
116- meta : f . meta . copy ()
126+ access : f .access .copy (). filter ( function ( a ) return a != APublic && a != APrivate ). concat ([ APrivate ]) ,
127+ meta : meta
117128 };
118- helperClass . fields .push (fiel );
129+ fields .push (fiel );
119130 definedFields .push (f .name );
120131
132+ // Remove meta from original function
121133 for (m in f .meta .copy ())
122134 if (m .name == " :hlNative" ) {
123135 f .meta .remove (m );
124136 }
125137
126- fun .expr = funcExpr ;
127138 default :
128139 }
129140 }
130141
131- helperClass .pack = cl .pack .copy ();
132- helperClass .pos = cl .pos ;
133- helperClass .name = hcClassName ;
134-
135- if (definedFields .length > 0 ) {
142+ /* if(definedFields.length > 0) {
136143 trace(cl.module);
137144
138- /* for(m in metas.copy()) {
139- trace(" " + m.name);
140- if(m.name == ":coreApi") {
141- metas.remove(m);
142- }
143- }*/
144-
145- var imports = Context .getLocalImports ().copy ();
146- Context .defineModule (module , [helperClass ], imports );
147-
148- Context .getLocalImports ().push ({
149- path : [for (m in module .split (" ." )) {
150- name : m ,
151- pos : Context .currentPos ()
152- }],
153- mode : INormal
154- });
155- }
145+ var printer = new haxe.macro.Printer();
146+ for(field in fields) if(field.name.startsWith("hlf_"))
147+ Sys.println(printer.printField(field));
148+ }*/
156149 }
157150
158151 return fields ;
0 commit comments