Beispiel #1
0
 public function printCFGNode()
 {
     $prettyPrinter = new PhpParser\PrettyPrinter\Standard();
     print "[Loop Header Node] : ";
     if ($this->loop_type == CFGNodeLoopHeader::FOR_LOOP) {
         print "[For Loop] : \n";
         print "(";
         foreach ($this->expr->init as $initExpr) {
             print $prettyPrinter->prettyPrintExpr($initExpr) . " ; ";
         }
         print ")\n";
         print "(";
         foreach ($this->expr->cond as $condExpr) {
             print $prettyPrinter->prettyPrintExpr($condExpr) . " ; ";
         }
         print ")\n";
         print "(";
         foreach ($this->expr->loop as $loopExpr) {
             print $prettyPrinter->prettyPrintExpr($loopExpr) . " ; ";
         }
         print ")\n";
     } else {
         if ($this->loop_type == CFGNodeLoopHeader::FOREACH_LOOP) {
             print "[Foreach Loop] : \n";
             print $prettyPrinter->prettyPrintExpr($this->expr->expr) . " ;\n";
             // TODO: Fix null reference.
             //print ($prettyPrinter->prettyPrintExpr($this->expr->keyVar)) . " ;\n";
             //print ($prettyPrinter->prettyPrintExpr($this->expr->valueVar)) . " ;\n";
         } else {
             if ($this->loop_type == CFGNodeLoopHeader::WHILE_LOOP) {
                 print "[While Loop] : \n";
                 print $prettyPrinter->prettyPrintExpr($this->expr->cond) . " ;\n";
             } else {
                 print "Unrecognized Loop.\n";
             }
         }
     }
 }
 /**
  * @param       $cache_file
  * @param array $source_files
  */
 public function generateMerge($cache_file, array $source_files)
 {
     $parser = new \PhpParser\Parser(new \PhpParser\Lexer());
     $config = new \PhpParser\Node\Expr\Array_();
     foreach ($source_files as $basename => $file) {
         $stmts = $parser->parse(file_get_contents($file));
         if (empty($stmts) || !$stmts[0] instanceof \PhpParser\Node\Stmt\Return_) {
             throw new \RuntimeException("Unable to locate return statement with config items in {$file}");
         }
         $config->items[] = new \PhpParser\Node\Expr\ArrayItem($stmts[0]->expr, new \PhpParser\Node\Scalar\String_($basename));
     }
     $prettyPrinter = new \PhpParser\PrettyPrinter\Standard();
     $out = $prettyPrinter->prettyPrintExpr($config);
     file_put_contents($cache_file, '<?php' . PHP_EOL . PHP_EOL . '// THIS IS AUTOGENERATED FILE! DO NOT EDIT IT!' . PHP_EOL . PHP_EOL . 'return ' . $out . ';' . PHP_EOL);
 }
Beispiel #3
0
function printExpr($expr)
{
    $prettyPrinter = new PhpParser\PrettyPrinter\Standard();
    $code = $prettyPrinter->prettyPrintExpr($expr);
    print $code . "\n";
}