Пример #1
0
 private function get_children_from($tokens, $start, $end, $parent_node, &$last_node = null, $foroutput = false)
 {
     $branch_points = array('T_IF', 'T_FOR', 'T_FOREACH', 'T_WHILE', 'T_SWITCH', 'T_DO', 'T_BOOLEAN_OR', 'T_BOOLEAN_AND');
     $tp = $start;
     $tree = new tree();
     $current_node_id = $parent_node;
     $this->break_nodes = $this->return_nodes = $this->continue_nodes = array();
     while ($tp < $end) {
         $token_name = $this->token_name($tokens[$tp]);
         if ($token_name == 'T_FUNCTION') {
             if ($blockstart = $this->search_token($tokens, $tp, '{', array(';'))) {
                 if ($tp = $this->get_pair($tokens, $blockstart)) {
                     $tp++;
                     continue;
                 }
             }
         } elseif ($token_name == 'T_BREAK') {
             $level = $this->get_break_level($tokens, $tp);
             $break_target = $this->break_levels[count($this->break_levels) - $level];
             $this->jumps[$break_target][] = $current_node_id;
             $this->break_nodes[] = $current_node_id;
         } elseif ($token_name == 'T_CONTINUE') {
             $this->continue_nodes[] = $current_node_id;
         } elseif ($token_name == 'T_RETURN' || $token_name == 'T_THROW') {
             $this->return_nodes[] = $current_node_id;
         } elseif (in_array($token_name, $branch_points)) {
             if ($token_name == 'T_SWITCH') {
                 /*
                 $trace = debug_backtrace(false);
                 foreach ($trace as $t) var_dump($t['function']);
                 */
                 $node_children = $this->get_children_from_switch($tokens, $tp, $current_node_id, $current_node_id, $foroutput);
                 $tree->addChildren($node_children);
             } elseif (in_array($token_name, array('T_IF'))) {
                 $temp = $current_node_id;
                 $node_children = $this->get_children_from_if($tokens, $tp, $current_node_id, $current_node_id, $foroutput);
                 $tree->addChildren($node_children);
             } elseif ($token_name == 'T_DO') {
                 if ($node_children = $this->get_children_from_do($tokens, $tp, $current_node_id, $current_node_id, $foroutput)) {
                     $tree->addChildren($node_children);
                 }
             } elseif (in_array($token_name, array('T_BOOLEAN_AND', 'T_BOOLEAN_OR'))) {
                 $boolright = $this->get_right_of_boolean($tokens, $tp);
                 if ($node_children = $this->get_children_from_boolean($tokens, $tp, $boolright, $current_node_id, $current_node_id, $current_node_id, $foroutput)) {
                     $tree->addChildren($node_children);
                 }
             } else {
                 if ($node_children = $this->get_children_from_loop($tokens, $tp, $current_node_id, $current_node_id, $foroutput)) {
                     $tree->addChildren($node_children);
                 }
             }
         }
         $tp++;
     }
     $last_node = $current_node_id;
     return $tree;
 }