@@ -17,11 +17,6 @@ using StringTools;
1717 */
1818class PolymodScriptClassMacro
1919{
20- /**
21- * The name for the Haxe resource that stores the abstract static field paths.
22- */
23- static inline final ABSTRACT_STATICS_RES_NAME : String = ' PolymodScriptClassMacro_AbstractStatics' ;
24-
2520 /**
2621 * Returns a `Map<String, Class<Dynamic>>` which maps superclass paths to scripted classes.
2722 * So `class ScriptedStage extends Stage implements HScriptable` will be `"Stage" -> ScriptedStage`
@@ -59,27 +54,6 @@ class PolymodScriptClassMacro
5954 return macro polymod.hscript._internal. PolymodScriptClassMacro .fetchAbstractImpls ();
6055 }
6156
62- /**
63- * @return An expression containing a map of abstract field names to
64- * the internal class, generated by Polymod, to store that value (accessible via Reflection).
65- */
66- public static macro function listAbstractStatics (): ExprOf <Map <String , Class <Dynamic >>>
67- {
68- if (! onAfterTypingCallbackRegistered )
69- {
70- onAfterTypingCallbackRegistered = true ;
71- haxe.macro. Context .onAfterTyping (onAfterTyping );
72- }
73-
74- if (! onGenerateCallbackRegistered )
75- {
76- onGenerateCallbackRegistered = true ;
77- haxe.macro. Context .onGenerate (onGenerate );
78- }
79-
80- return macro polymod.hscript._internal. PolymodScriptClassMacro .fetchAbstractStatics ();
81- }
82-
8357 /**
8458 * @return An expression containing a map of each typedef name to
8559 * the underlying class type.
@@ -106,7 +80,6 @@ class PolymodScriptClassMacro
10680
10781 var hscriptedClassEntries : Array <Expr > = [];
10882 var abstractImplEntries : Array <Expr > = [];
109- var abstractStaticEntries : Array <{}> = [];
11083 var typedefEntries : Array <Expr > = [];
11184
11285 var startTime : Float = Sys .time ();
@@ -213,33 +186,6 @@ class PolymodScriptClassMacro
213186
214187 abstractImplEntries .push (macro $a {entryData });
215188
216- for (field in abstractImpl .statics .get ())
217- {
218- switch (field .type )
219- {
220- case TAbstract (_ , _ ):
221- //
222- case TType (_ , _ ):
223- //
224- default :
225- continue ;
226- }
227-
228- var key : String = ' ${abstractImplPath }. ${field .name }' ;
229-
230- if (! staticFieldToClass .exists (key ))
231- {
232- continue ;
233- }
234-
235- var staticEntryData =
236- {
237- fieldPath : key ,
238- reflectClassPath : staticFieldToClass [key ]
239- };
240-
241- abstractStaticEntries .push (staticEntryData );
242- }
243189 default :
244190 continue ;
245191 }
@@ -252,7 +198,6 @@ class PolymodScriptClassMacro
252198 Context .info (' PolymodScriptClassMacro: '
253199 + ' Registered ${hscriptedClassEntries .length } HScriptedClasses, '
254200 + ' ${abstractImplEntries .length } abstract impls, '
255- + ' ${abstractStaticEntries .length } abstract statics, '
256201 + ' ${typedefEntries .length } typedefs '
257202 + ' in ${duration } sec.' ,
258203 Context .currentPos ());
@@ -264,24 +209,17 @@ class PolymodScriptClassMacro
264209 polymodScriptClassClassType .meta .add (' abstractImpls' , abstractImplEntries , Context .currentPos ());
265210 polymodScriptClassClassType .meta .remove (' typedefs' );
266211 polymodScriptClassClassType .meta .add (' typedefs' , typedefEntries , Context .currentPos ());
267-
268- // It can get VERY BIG so we have to resort to store it as a resource instead.
269- var absStaticsData : String = haxe. Serializer .run (abstractStaticEntries );
270- Context .addResource (ABSTRACT_STATICS_RES_NAME , haxe.io. Bytes .ofString (absStaticsData ));
271212 }
272213
273- static var iteration : Int = 0 ;
274- static var staticFieldToClass : Map <String , String > = [];
275-
276214 static function onAfterTyping (types : Array <ModuleType >): Void
277215 {
278- var fields : Array <Field > = [];
279-
280216 var startTime : Float = Sys .time ();
281217
218+ var count : Int = 0 ;
219+
282220 for (type in types )
283221 {
284- var sfields : Array <Field > = [];
222+ var fields : Array <Field > = [];
285223
286224 switch (type )
287225 {
@@ -366,12 +304,10 @@ class PolymodScriptClassMacro
366304
367305 if (canGet || canSet )
368306 {
369- var fieldName : String = ' ${abstractImplPath .replace (' .' , ' _' )}_ ${field .name }' ;
370-
371307 fields .push (
372308 {
373309 pos : Context .currentPos (),
374- name : fieldName ,
310+ name : field . name ,
375311 access : [Access . APublic , Access . AStatic ],
376312 kind : FProp (canGet ? ' get' : ' never' , canSet ? ' set' : ' never' , (macro : Dynamic ), null )
377313 });
@@ -395,7 +331,7 @@ class PolymodScriptClassMacro
395331 fields .push (
396332 {
397333 pos : Context .currentPos (),
398- name : ' get_ ${fieldName }' ,
334+ name : ' get_ ${field . name }' ,
399335 access : [Access . APublic , Access . AStatic ],
400336 kind : FFun (
401337 {
@@ -412,7 +348,7 @@ class PolymodScriptClassMacro
412348 fields .push (
413349 {
414350 pos : Context .currentPos (),
415- name : ' set_ ${fieldName }' ,
351+ name : ' set_ ${field . name }' ,
416352 access : [Access . APublic , Access . AStatic ],
417353 kind : FFun (
418354 {
@@ -424,14 +360,12 @@ class PolymodScriptClassMacro
424360 })
425361 });
426362 }
427-
428- staticFieldToClass .set (' ${abstractImplPath }. ${field .name }' , ' polymod.hscript._internal.AbstractStaticMembers_ ${iteration }' );
429363 }
430364
431365 case FMethod (k ):
432366 if (k != MethInline ) continue ;
433367 if (abstractPath .startsWith (' cpp' )) continue ;
434- if (abstractPath .endsWith ( ' HashOrArray' )) continue ;
368+ if (abstractPath .startsWith ( ' flixel.graphics.atlas. HashOrArray' )) continue ; // has to be ragebait
435369 if (abstractType .isPrivate ) continue ;
436370
437371 switch (field .type )
@@ -452,7 +386,7 @@ class PolymodScriptClassMacro
452386 var isVoid = haxe.macro. TypeTools .toString (ret ) == ' Void' ;
453387 var callExprString = ' ${isVoid ? ' ' : ' returnValue = ' }__typedThis. ${field .name }( ${[for (a in fieldArgs ) a .name ].join (' , ' )})' ;
454388
455- sfields .push (
389+ fields .push (
456390 {
457391 pos : Context .currentPos (),
458392 name : field .name ,
@@ -493,41 +427,32 @@ class PolymodScriptClassMacro
493427 }
494428 }
495429
430+ if (fields .length == 0 ) continue ;
431+
496432 Context .defineType (
497433 {
498434 pos : Context .currentPos (),
499435 pack : [' polymod' , ' hscript' , ' _internal' , ' _abstract' ].concat (abstractType .pack ),
500436 name : ' ${abstractType .name }_PolymodImpl_' , // we need to give them a different name, because else types with an empty package will not work
501437 kind : TDClass (null , [], false , false , false ),
502- fields : sfields
438+ fields : fields
503439 });
440+
441+ count ++ ;
504442 }
505443 default :
506444 continue ;
507445 }
508446 }
509447
510- if (fields .length == 0 )
511- {
512- return ;
513- }
514-
515- Context .defineType (
516- {
517- pos : Context .currentPos (),
518- pack : [' polymod' , ' hscript' , ' _internal' ],
519- name : ' AbstractStaticMembers_ ${iteration }' ,
520- kind : TDClass (null , [], false , false , false ),
521- fields : fields
522- });
523-
524448 var endTime : Float = Sys .time ();
525449
526450 var duration : Float = endTime - startTime ;
527451
528- Context .info (' PolymodScriptClassMacro: Processed ${fields .length } static fields in ${duration } sec (iteration # ${iteration }).' , Context .currentPos ());
529-
530- iteration ++ ;
452+ if (count > 0 )
453+ {
454+ Context .info (' PolymodScriptClassMacro: Created ${count } custom abstract implementations in ${duration } sec.' , Context .currentPos ());
455+ }
531456 }
532457 #end
533458
@@ -630,41 +555,6 @@ class PolymodScriptClassMacro
630555 }
631556 }
632557
633- public static function fetchAbstractStatics (): Map <String , Class <Dynamic >>
634- {
635- var resDataContent : Null <String > = haxe. Resource .getString (ABSTRACT_STATICS_RES_NAME );
636- if (resDataContent == null )
637- {
638- throw ' " $ABSTRACT_STATICS_RES_NAME " resource not found!' ;
639- }
640- var abstractStatics : Array <{fieldPath : String , reflectClassPath : String }> = cast haxe. Unserializer .run (resDataContent );
641-
642- if (abstractStatics != null )
643- {
644- var result : Map <String , Class <Dynamic >> = [];
645-
646- // Each element is formatted as `[abstractPathImpl.fieldName, reflectClass]`.
647-
648- for (element in abstractStatics )
649- {
650- if ((element .fieldPath ?. length ?? 0 ) == 0 || (element .reflectClassPath ?. length ?? 0 ) == 0 )
651- {
652- throw ' Malformed element in abstractStatics: ' + element ;
653- }
654-
655- var reflectClass : Class <Dynamic > = cast Type .resolveClass (element .reflectClassPath );
656-
657- result .set (element .fieldPath , reflectClass );
658- }
659-
660- return result ;
661- }
662- else
663- {
664- throw ' No abstractStatics found in " ${ABSTRACT_STATICS_RES_NAME }" resource!' ;
665- }
666- }
667-
668558 public static function fetchTypedefs (): Map <String , Class <Dynamic >>
669559 {
670560 var metaData = Meta .getType (PolymodScriptClassMacro );
0 commit comments