@@ -99,8 +99,6 @@ class Macros {
9999 };
100100 }
101101
102- // Generates a value extraction expression, unwrapping single-column lists recursively
103- // Returns null for types that use typed getters instead (TProperties, TPolymorph)
104102 function initExpr (sheet : cdb. Sheet , col : cdb. Data . Column , source : Expr ): Null <Expr > {
105103 var colName = col .name ;
106104 var prop : Expr = macro ($source : Dynamic ).$colName ;
@@ -125,9 +123,8 @@ class Macros {
125123
126124 var splitRegex = ~/ ::(. +? )::/ g ;
127125 function buildText (col : cdb. Data . Column , val : String , id : String ): FieldType {
128- if (! splitRegex .match (val )) {
126+ if (! splitRegex .match (val ))
129127 return FVar (macro :String , macro $v {val });
130- }
131128 var args = new Array <haxe.macro. Expr . Field >();
132129 var map = new Map <String , Bool >();
133130 splitRegex .map (val , function (r ) {
@@ -156,15 +153,6 @@ class Macros {
156153 });
157154 }
158155
159- function getVal (obj : Dynamic ): {col :cdb. Data . Column , val :Dynamic } {
160- for (col in polySheet .columns ) {
161- var v = Reflect .field (obj , col .name );
162- if (v != null )
163- return {col : col , val : v };
164- }
165- return null ;
166- }
167-
168156 for (line in sheet .getLines ()) {
169157 var id = Reflect .field (line , idCol .name );
170158 var pobj = Reflect .field (line , polyCol .name );
@@ -173,19 +161,28 @@ class Macros {
173161 if (pobj == null )
174162 continue ;
175163
176- var pval = getVal (pobj );
177- if (pval == null )
164+ var col : cdb. Data . Column = null ;
165+ var val : Dynamic = null ;
166+ for (c in polySheet .columns ) {
167+ var v = Reflect .field (pobj , c .name );
168+ if (v != null ) {
169+ col = c ;
170+ val = v ;
171+ break ;
172+ }
173+ }
174+ if (col == null )
178175 continue ;
179176
180- var t = getType (polySheet , pval . col );
177+ var t = getType (polySheet , col );
181178 if (t == null )
182179 continue ;
183180
184- var pvar : FieldType = switch (pval . col .type ) {
181+ var pvar : FieldType = switch (col .type ) {
185182 case TString :
186- buildText (pval . col , pval . val , id );
183+ buildText (col , val , id );
187184 case TProperties | TPolymorph :
188- var colName = pval . col .name ;
185+ var colName = col .name ;
189186 fields .push ({
190187 name : " get_" + id ,
191188 pos : pos ,
@@ -203,12 +200,12 @@ class Macros {
203200 case TList | TInt | TFloat | TBool :
204201 initExprs .push (macro {
205202 var obj : Dynamic = ${getData (id )};
206- $i {id } = ${initExpr (polySheet , pval . col , macro obj .$polyColName )};
203+ $i {id } = ${initExpr (polySheet , col , macro obj .$polyColName )};
207204 });
208- var initVal = pval . col .type == TList ? macro null : macro $v {pval . val };
205+ var initVal = col .type == TList ? macro null : macro $v {val };
209206 FVar (t , initVal );
210207 default :
211- error (' Unsupported column type: ${pval . col .type }' );
208+ error (' Unsupported column type: ${col .type }' );
212209 null ;
213210 };
214211
0 commit comments