protected function walkFor(ForNode $for)
 {
     $variableNames = array();
     foreach ($for->getBody() as $statement) {
         foreach ($this->walk($statement) as $name => $_) {
             $variableNames[$name] = true;
         }
     }
     if ($for->getElseBody() !== null) {
         foreach ($for->getElseBody() as $statement) {
             foreach ($this->walk($statement) as $name => $_) {
                 $variableNames[$name] = true;
             }
         }
     }
     return $variableNames;
 }
Exemple #2
0
 protected function walkFor(ForNode $for)
 {
     $ret = "for (\${$for->getVariableName()} = ";
     $ret .= $this->walk($for->getFrom()) . ", ";
     $toSym = $this->gensym();
     $ret .= "{$toSym} = " . $this->walk($for->getTo()) . ", ";
     $iterationsSym = $this->gensym();
     $ret .= "{$iterationsSym} = 0; ";
     $ret .= "\${$for->getVariableName()} <= {$toSym}; ";
     $ret .= "\${$for->getVariableName()} += " . ($for->getStep() === null ? "1" : $this->walk($for->getStep()));
     $ret .= ", ++{$iterationsSym}) {" . implode("", $this->walkEach((array) $for->getBody())) . "}";
     $ret .= "if ({$iterationsSym} < 1) {" . implode("", $this->walkEach((array) $for->getElseBody())) . "}";
     return $ret;
 }
 protected function walkFor(ForNode $for)
 {
     return new ForNode($for->getVariableName(), $for->getFrom(), $for->getTo(), $for->getStep(), $this->walkEach($for->getBody()), $this->walkEach($for->getElseBody()));
 }
 protected function walkFor(ForNode $for)
 {
     $this->walkEachDisallow($for->getBody(), "for");
     $this->walkEachDisallow($for->getElseBody(), "forelse");
 }