@@ -28,7 +28,6 @@ public function visit(array $ast, $fnName, $expr)
2828 ->write ('' )
2929 ->write ('function %s(Ti $interpreter, $value) { ' , $ fnName )
3030 ->indent ()
31- ->write ('$current = $value; ' )
3231 ->dispatch ($ ast )
3332 ->write ('' )
3433 ->write ('return $value; ' )
@@ -116,6 +115,29 @@ private function visit_or(array $node)
116115 ->write ('} ' );
117116 }
118117
118+ private function visit_and (array $ node )
119+ {
120+ $ a = $ this ->makeVar ('beforeAnd ' );
121+ return $ this
122+ ->write ('%s = $value; ' , $ a )
123+ ->dispatch ($ node ['children ' ][0 ])
124+ ->write ('if ($value || $value === "0" || $value === 0) { ' )
125+ ->indent ()
126+ ->write ('$value = %s; ' , $ a )
127+ ->dispatch ($ node ['children ' ][1 ])
128+ ->outdent ()
129+ ->write ('} ' );
130+ }
131+
132+ private function visit_not (array $ node )
133+ {
134+ return $ this
135+ ->write ('// Visiting not node ' )
136+ ->dispatch ($ node ['children ' ][0 ])
137+ ->write ('// Applying boolean not to result of not node ' )
138+ ->write ('$value = !Utils::isTruthy($value); ' );
139+ }
140+
119141 private function visit_subexpression (array $ node )
120142 {
121143 return $ this
@@ -182,7 +204,6 @@ private function visit_pipe(array $node)
182204 {
183205 return $ this
184206 ->dispatch ($ node ['children ' ][0 ])
185- ->write ('$current = $value; ' )
186207 ->dispatch ($ node ['children ' ][1 ]);
187208 }
188209
@@ -193,13 +214,11 @@ private function visit_multi_select_list(array $node)
193214
194215 private function visit_multi_select_hash (array $ node )
195216 {
196- $ tmpCurrent = $ this ->makeVar ('cur ' );
197217 $ listVal = $ this ->makeVar ('list ' );
198218 $ value = $ this ->makeVar ('prev ' );
199219 $ this ->write ('if ($value !== null) { ' )
200220 ->indent ()
201221 ->write ('%s = []; ' , $ listVal )
202- ->write ('%s = $current; ' , $ tmpCurrent )
203222 ->write ('%s = $value; ' , $ value );
204223
205224 $ first = true ;
@@ -220,24 +239,20 @@ private function visit_multi_select_hash(array $node)
220239
221240 return $ this
222241 ->write ('$value = %s; ' , $ listVal )
223- ->write ('$current = %s; ' , $ tmpCurrent )
224242 ->outdent ()
225243 ->write ('} ' );
226244 }
227245
228246 private function visit_function (array $ node )
229247 {
230248 $ value = $ this ->makeVar ('val ' );
231- $ current = $ this ->makeVar ('current ' );
232249 $ args = $ this ->makeVar ('args ' );
233250 $ this ->write ('%s = $value; ' , $ value )
234- ->write ('%s = $current; ' , $ current )
235251 ->write ('%s = []; ' , $ args );
236252
237253 foreach ($ node ['children ' ] as $ arg ) {
238254 $ this ->dispatch ($ arg );
239255 $ this ->write ('%s[] = $value; ' , $ args )
240- ->write ('$current = %s; ' , $ current )
241256 ->write ('$value = %s; ' , $ value );
242257 }
243258
@@ -347,47 +362,51 @@ private function visit_projection(array $node)
347362
348363 private function visit_condition (array $ node )
349364 {
365+ $ value = $ this ->makeVar ('beforeCondition ' );
350366 return $ this
351- ->write ('// Visiting projection node ' )
367+ ->write ('%s = $value; ' , $ value )
368+ ->write ('// Visiting condition node ' )
352369 ->dispatch ($ node ['children ' ][0 ])
353- ->write ('if ($value !== null) { ' )
370+ ->write ('// Checking result of condition node ' )
371+ ->write ('if (Utils::isTruthy($value)) { ' )
354372 ->indent ()
373+ ->write ('$value = %s; ' , $ value )
355374 ->dispatch ($ node ['children ' ][1 ])
356375 ->outdent ()
376+ ->write ('} else { ' )
377+ ->indent ()
378+ ->write ('$value = null; ' )
379+ ->outdent ()
357380 ->write ('} ' );
358381 }
359382
360383 private function visit_comparator (array $ node )
361384 {
362385 $ value = $ this ->makeVar ('val ' );
363- $ tmpCurrent = $ this ->makeVar ('cur ' );
364386 $ a = $ this ->makeVar ('left ' );
365387 $ b = $ this ->makeVar ('right ' );
366388
367389 $ this
368390 ->write ('// Visiting comparator node ' )
369391 ->write ('%s = $value; ' , $ value )
370- ->write ('%s = $current; ' , $ tmpCurrent )
371392 ->dispatch ($ node ['children ' ][0 ])
372393 ->write ('%s = $value; ' , $ a )
373394 ->write ('$value = %s; ' , $ value )
374395 ->dispatch ($ node ['children ' ][1 ])
375396 ->write ('%s = $value; ' , $ b );
376397
377398 if ($ node ['value ' ] == '== ' ) {
378- $ this ->write ('$result = Utils::isEqual(%s, %s); ' , $ a , $ b );
399+ $ this ->write ('$value = Utils::isEqual(%s, %s); ' , $ a , $ b );
379400 } elseif ($ node ['value ' ] == '!= ' ) {
380- $ this ->write ('$result = !Utils::isEqual(%s, %s); ' , $ a , $ b );
401+ $ this ->write ('$value = !Utils::isEqual(%s, %s); ' , $ a , $ b );
381402 } else {
382403 $ this ->write (
383- '$result = is_int(%s) && is_int(%s) && %s %s %s; ' ,
404+ '$value = is_int(%s) && is_int(%s) && %s %s %s; ' ,
384405 $ a , $ b , $ a , $ node ['value ' ], $ b
385406 );
386407 }
387408
388- return $ this
389- ->write ('$value = $result === true ? %s : null; ' , $ value )
390- ->write ('$current = %s; ' , $ tmpCurrent );
409+ return $ this ;
391410 }
392411
393412 /** @internal */
0 commit comments