Fix some prettyprinting issues

This commit is contained in:
nikic 2011-05-29 20:38:36 +02:00
parent 15e268cd8b
commit 489f8c8b56
2 changed files with 34 additions and 12 deletions

View File

@ -299,7 +299,7 @@ class PrettyPrinter_Zend extends PrettyPrinterAbstract
} }
public function pExpr_StaticCall(Node_Expr_StaticCall $node) { public function pExpr_StaticCall(Node_Expr_StaticCall $node) {
return $this->p($node->class) . '::' return $this->pClassName($node->class) . '::'
. ($node->func instanceof Node_Variable ? $this->p($node->func) : $node->func) . ($node->func instanceof Node_Variable ? $this->p($node->func) : $node->func)
. '(' . $this->pCommaSeparated($node->args) . ')'; . '(' . $this->pCommaSeparated($node->args) . ')';
} }
@ -351,7 +351,7 @@ class PrettyPrinter_Zend extends PrettyPrinterAbstract
} }
public function pExpr_StaticPropertyFetch(Node_Expr_StaticPropertyFetch $node) { public function pExpr_StaticPropertyFetch(Node_Expr_StaticPropertyFetch $node) {
return $this->p($node->class) . '::$' . $this->pObjectProperty($node->name); return $this->pClassName($node->class) . '::$' . $this->pObjectProperty($node->name);
} }
public function pExpr_ShellExec(Node_Expr_ShellExec $node) { public function pExpr_ShellExec(Node_Expr_ShellExec $node) {
@ -370,7 +370,7 @@ class PrettyPrinter_Zend extends PrettyPrinterAbstract
} }
public function pExpr_New(Node_Expr_New $node) { public function pExpr_New(Node_Expr_New $node) {
return 'new ' . $this->p($node->class) . '(' . $this->pCommaSeparated($node->args) . ')'; return 'new ' . $this->pClassName($node->class) . '(' . $this->pCommaSeparated($node->args) . ')';
} }
public function pExpr_Ternary(Node_Expr_Ternary $node) { public function pExpr_Ternary(Node_Expr_Ternary $node) {
@ -406,7 +406,9 @@ class PrettyPrinter_Zend extends PrettyPrinterAbstract
return $this->pModifiers($node->type) return $this->pModifiers($node->type)
. 'function ' . $node->name . 'function ' . $node->name
. '(' . $this->pCommaSeparated($node->params) . ')' . '(' . $this->pCommaSeparated($node->params) . ')'
. "\n" . '{' . "\n" . $this->pIndent($this->pStmts($node->stmts)) . '}'; . (null !== $node->stmts
? "\n" . '{' . "\n" . $this->pIndent($this->pStmts($node->stmts)) . '}'
: ';');
} }
public function pStmt_ClassConst(Node_Stmt_ClassConst $node) { public function pStmt_ClassConst(Node_Stmt_ClassConst $node) {
@ -535,12 +537,10 @@ class PrettyPrinter_Zend extends PrettyPrinterAbstract
} }
public function pClassName($node) { public function pClassName($node) {
if ($node instanceof Node_Name) { if ($node == 'static') {
return $this->pName($node);
} elseif ($node == 'static') {
return 'static'; return 'static';
} else { } else {
throw new InvalidArgumentException(); return $this->p($node);
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
$DIR = '..'; $DIR = '../../symfony2';
function __autoload($class) { function __autoload($class) {
is_file($file = '../lib/' . strtr($class, '_', '/') . '.php') && require_once $file; is_file($file = '../lib/' . strtr($class, '_', '/') . '.php') && require_once $file;
@ -30,6 +30,10 @@ echo '<!DOCTYPE html>
.failReason { .failReason {
background-color: rgba(255, 0, 0, 0.3); background-color: rgba(255, 0, 0, 0.3);
} }
.failCount {
color: red;
}
</style> </style>
<table> <table>
<tr> <tr>
@ -37,10 +41,12 @@ echo '<!DOCTYPE html>
<td>Parse</td> <td>Parse</td>
<td>Time</td> <td>Time</td>
<td>PrettyPrint</td> <td>PrettyPrint</td>
<td>Same</td> <td>Compare</td>
</tr>'; </tr>';
$GST = microtime(true); $totalStartTime = microtime(true);
$parseFail = $parseCount = $ppFail = $ppCount = $compareFail = $compareCount = 0;
foreach (new RecursiveIteratorIterator( foreach (new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($DIR), new RecursiveDirectoryIterator($DIR),
RecursiveIteratorIterator::LEAVES_ONLY) RecursiveIteratorIterator::LEAVES_ONLY)
@ -67,6 +73,7 @@ foreach (new RecursiveIteratorIterator(
$time = microtime(true) - $startTime; $time = microtime(true) - $startTime;
++$parseCount;
if (false !== $stmts) { if (false !== $stmts) {
$code = '<?php' . "\n" . $prettyPrinter->pStmts($stmts); $code = '<?php' . "\n" . $prettyPrinter->pStmts($stmts);
@ -77,7 +84,9 @@ foreach (new RecursiveIteratorIterator(
} }
); );
++$ppCount;
if (false !== $ppStmts) { if (false !== $ppStmts) {
++$compareCount;
if ($stmts == $ppStmts) { if ($stmts == $ppStmts) {
echo ' echo '
<td class="pass">PASS</td> <td class="pass">PASS</td>
@ -91,6 +100,8 @@ foreach (new RecursiveIteratorIterator(
<td class="pass">PASS</td> <td class="pass">PASS</td>
<td class="fail">FAIL</td> <td class="fail">FAIL</td>
</tr>'; </tr>';
++$compareFail;
} }
} else { } else {
echo ' echo '
@ -99,6 +110,8 @@ foreach (new RecursiveIteratorIterator(
<td class="fail">FAIL</td> <td class="fail">FAIL</td>
<td></td> <td></td>
</tr>'; </tr>';
++$ppFail;
} }
} else { } else {
echo ' echo '
@ -108,12 +121,21 @@ foreach (new RecursiveIteratorIterator(
<td></td> <td></td>
</tr> </tr>
<tr class="failReason"><td colspan="5">' . $errMsg . '</td></tr>'; <tr class="failReason"><td colspan="5">' . $errMsg . '</td></tr>';
++$parseFail;
} }
flush(); flush();
} }
echo ' echo '
<tr>
<td>Fail / Total:</td>
<td><span class="failCount">' . $parseFail . '</span> / ' . $parseCount . '</td>
<td></td>
<td><span class="failCount">' . $ppFail . '</span> / ' . $ppCount . '</td>
<td><span class="failCount">' . $compareFail . '</span> / ' . $compareCount . '</td>
</tr>
</table>'; </table>';
echo 'Total time: ', microtime(true) - $GST; echo 'Total time: ', microtime(true) - $totalStartTime;