Exemple #1
0
 private function get_children_from_do($tokens, &$start, $parent_node, &$last_node, $foroutput = false)
 {
     $tree = new tree();
     $current_node_id = $parent_node;
     $tp = $start;
     $tree = new tree();
     if (!($temp = $this->search_token($tokens, $start, '{', array(';')))) {
         return false;
     }
     $start = $temp;
     $end = $this->get_pair($tokens, $start);
     $this->break_levels[] = $end;
     $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;
     $tp = $this->search_token($tokens, $tp, '(');
     $end = $this->get_pair($tokens, $tp) + 1;
     $new_node = $current_node_id + 1;
     if (!in_array($parent_node, $this->break_nodes)) {
         $tree->addChild($parent_node, $new_node);
     }
     $tree->addChildToAllLeavesOfParent($parent_node, $new_node, array_merge($this->break_nodes, $this->continue_nodes, $this->return_nodes));
     if (isset($this->jumps[$end])) {
         foreach ($this->jumps[$end] as $jn) {
             $tree->addChild($jn, $new_node);
         }
     }
     $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;
 }
<?php

require_once '../thinkedit.init.php';
require_once ROOT . '/class/tree.class.php';
echo '<pre>';
$tree = new tree();
// we start at "root"
$tree->setNodeId(1);
$tree->addChild('article', 'table', '5');
foreach ($tree->getChildren() as $node) {
    print_r($node);
}