Exemple #1
0
 protected function compile_Stmt_Foreach($node)
 {
     $iteratePtr = Zval::ptrFactory();
     $this->compileChild($node, 'expr', $iteratePtr);
     $this->opArray->beginLoop();
     $key = null;
     if ($node->keyVar) {
         $key = Zval::ptrFactory();
         $this->compileChild($node, 'keyVar', $key);
     }
     $value = Zval::ptrFactory();
     $this->compileChild($node, 'valueVar', $value);
     $iterator = Zval::iteratorFactory();
     if ($node->byRef) {
         $this->opArray[] = $iterateOp = new OpLines\IterateByRef($node->getLine(), $iteratePtr, null, $iterator);
         $iterateValuesJumpPos = $this->opArray->getNextOffset();
         $this->opArray[] = new OpLines\IterateValuesByRef($node->getLine(), $iterator, $key, $value);
     } else {
         $this->opArray[] = $iterateOp = new OpLines\Iterate($node->getLine(), $iteratePtr, null, $iterator);
         $iterateValuesJumpPos = $this->opArray->getNextOffset();
         $this->opArray[] = new OpLines\IterateValues($node->getLine(), $iterator, $key, $value);
     }
     $this->compileChild($node, 'stmts');
     $continueJumpPos = $this->opArray->getNextOffset();
     $this->opArray[] = new OpLines\IterateNext($node->getLine(), $iterator, $iterateValuesJumpPos);
     $iterateOp->op2 = $this->opArray->getNextOffset();
     $this->opArray->endLoop($continueJumpPos);
 }