Exemple #1
0
 private function get_children_from_if($tokens, &$start, $parent_node, &$last_node, $foroutput = false)
 {
     $tree = new tree();
     $current_node_id = $parent_node;
     $tp = $start;
     $tree = new tree();
     while (1) {
         $token_name = $this->token_name($tokens[$this->get_next_non_comment($tokens, $tp)]);
         if (in_array($token_name, array('T_IF', 'T_ELSE', 'T_ELSEIF'))) {
             if ($token_name == 'T_ELSE') {
                 $elsefound = true;
                 $start = $this->search_token($tokens, $tp, '{', array(';'));
             } else {
                 if ($token_name == 'T_IF') {
                     if (isset($found_if)) {
                         break;
                     }
                     $found_if = true;
                 }
                 $boolleft = $start = $this->search_token($tokens, $tp, '(', array(';'));
                 $boolright = $start = $this->get_pair($tokens, $start);
                 $temp_current_node = $current_node_id;
                 $parent_node_old = $parent_node;
                 if ($node_children = $this->get_children_from_boolean($tokens, $boolleft, $boolright, $current_node_id, $current_node_id, $current_node_id, $foroutput)) {
                     if ($temp_current_node != $current_node_id) {
                         $parent_node = $current_node_id;
                         $tree->addChildToAllDecendants($temp_current_node + 1, $current_node_id + 1);
                     }
                     $tree->addChildren($node_children);
                 }
                 $start = $this->search_token($tokens, $start, '{', array(';'));
             }
             $end = $this->get_pair($tokens, $start);
             $new_node = $current_node_id = $current_node_id + 1;
             if (!in_array($parent_node, array_merge($this->break_nodes, $this->continue_nodes, $this->return_nodes))) {
                 $tree->addChild($parent_node, $new_node);
             }
             $this->add_tokens_to_be_inserted_after($start + 1, "/*{$new_node}*/" . "\\codespy\\Analyzer::\$executionbranches[__FILE__][__CLASS__][__FUNCTION__][\\codespy\\Analyzer::\$instancenumberfor[__FILE__][__CLASS__][__FUNCTION__]][{$new_node}] = 1;", $foroutput ? $new_node : false);
             if ($children = $this->get_children_from($tokens, $start, $end, $current_node_id, $current_node_id, $foroutput)) {
                 $tree->addChildren($children);
             }
             $tp = $end + 1;
         } else {
             break;
         }
     }
     $new_node = $current_node_id + 1;
     if (!isset($elsefound)) {
         if (!in_array($parent_node_old, array_merge($this->break_nodes, $this->continue_nodes, $this->return_nodes))) {
             $tree->addChild($parent_node_old, $new_node);
         }
     }
     echo "Pn = {$parent_node_old}";
     $tree->addChildToAllLeavesOfParent($parent_node, $new_node, array_merge($this->break_nodes, $this->continue_nodes, $this->return_nodes));
     $this->add_tokens_to_be_inserted_after($end + 1, "/*{$new_node}*/" . "\\codespy\\Analyzer::\$executionbranches[__FILE__][__CLASS__][__FUNCTION__][\\codespy\\Analyzer::\$instancenumberfor[__FILE__][__CLASS__][__FUNCTION__]][{$new_node}] = 1;", $foroutput ? $new_node : false);
     $last_node = $new_node;
     $start = $end;
     array_pop($this->break_levels);
     return $tree;
 }