From 6965c7935deab3432e19230f2bb666dd3667611b Mon Sep 17 00:00:00 2001 From: Andres Gutierrez Date: Fri, 24 Oct 2014 10:50:17 -0500 Subject: [PATCH] Fixing warning in logger, fixing declaration of variables with initial defaults --- Library/ClassMethod.php | 95 +++++++++++++++++++++++++++-------------- Library/Logger.php | 26 ++++++----- 2 files changed, 77 insertions(+), 44 deletions(-) diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index 475a716977..8ae0fdecb9 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -1425,10 +1425,21 @@ public function compile(CompilationContext $compilationContext) case 'int': case 'uint': case 'long': + $initVarCode .= "\t" . 'ZEPHIR_INIT_VAR(' . $variable->getName() . ');' . PHP_EOL; + $initVarCode .= "\t" . 'ZVAL_LONG(' . $variable->getName() . ', ' . $defaultValue['value'] . ');' . PHP_EOL; + break; + case 'char': case 'uchar': + if (strlen($defaultValue['value']) > 2) { + if (strlen($defaultValue['value']) > 10) { + throw new CompilerException("Invalid char literal: '" . substr($defaultValue['value'], 0, 10) . "...'", $defaultValue); + } else { + throw new CompilerException("Invalid char literal: '" . $defaultValue['value'] . "'", $defaultValue); + } + } $initVarCode .= "\t" . 'ZEPHIR_INIT_VAR(' . $variable->getName() . ');' . PHP_EOL; - $initVarCode .= "\t" . 'ZVAL_LONG(' . $variable->getName() . ', ' . $defaultValue['value'] . ');' . PHP_EOL; + $initVarCode .= "\t" . 'ZVAL_LONG(' . $variable->getName() . ', \'' . $defaultValue['value'] . '\');' . PHP_EOL; break; case 'null': @@ -1640,8 +1651,6 @@ public function compile(CompilationContext $compilationContext) switch ($dataType) { case 'variable': - /*case 'string': - case 'array':*/ case 'resource': case 'object': case 'callable': @@ -1855,6 +1864,7 @@ public function compile(CompilationContext $compilationContext) * @var $variables Variable[] */ foreach ($variables as $variable) { + if (($type == 'variable' || $type == 'string' || $type == 'array' || $type == 'resource' || $type == 'callable' || $type == 'object') && $variable->mustInitNull()) { if ($variable->isLocalOnly()) { $groupVariables[] = $variable->getName() . ' = zval_used_for_init'; @@ -1865,42 +1875,61 @@ public function compile(CompilationContext $compilationContext) $groupVariables[] = $pointer . $variable->getName() . ' = NULL'; } } - } else { - if ($variable->isLocalOnly()) { - $groupVariables[] = $variable->getName(); + continue; + } + + if ($variable->isLocalOnly()) { + $groupVariables[] = $variable->getName(); + continue; + } + + if ($variable->isDoublePointer()) { + if ($variable->mustInitNull()) { + $groupVariables[] = $pointer . $pointer . $variable->getName() . ' = NULL'; } else { - if ($variable->isDoublePointer()) { - if ($variable->mustInitNull()) { - $groupVariables[] = $pointer . $pointer . $variable->getName() . ' = NULL'; - } else { - $groupVariables[] = $pointer . $pointer . $variable->getName(); - } - } else { - $defaultValue = $variable->getDefaultInitValue(); - if ($defaultValue !== null) { - switch($type) { - case 'variable': - case 'string': - case 'array': - case 'resource': - case 'callable': - case 'object': - $groupVariables[] = $pointer . $variable->getName(); - break; - default: - $groupVariables[] = $pointer . $variable->getName() . ' = ' . $defaultValue; - break; - } - } else { - if ($variable->mustInitNull() && $pointer) { - $groupVariables[] = $pointer . $variable->getName() . ' = NULL'; + $groupVariables[] = $pointer . $pointer . $variable->getName(); + } + continue; + } + + $defaultValue = $variable->getDefaultInitValue(); + if ($defaultValue !== null) { + + switch($type) { + + case 'variable': + case 'string': + case 'array': + case 'resource': + case 'callable': + case 'object': + $groupVariables[] = $pointer . $variable->getName(); + break; + + case 'char': + if (strlen($defaultValue) > 2) { + if (strlen($defaultValue) > 10) { + throw new CompilerException("Invalid char literal: '" . substr($defaultValue, 0, 10) . "...'", $variable->getOriginal()); } else { - $groupVariables[] = $pointer . $variable->getName(); + throw new CompilerException("Invalid char literal: '" . $defaultValue . "'", $variable->getOriginal()); } } - } + /* no break */ + + default: + $groupVariables[] = $pointer . $variable->getName() . ' = ' . $defaultValue; + break; } + + continue; } + + if ($variable->mustInitNull() && $pointer) { + $groupVariables[] = $pointer . $variable->getName() . ' = NULL'; + continue; + } + + $groupVariables[] = $pointer . $variable->getName(); } $codePrinter->preOutput("\t" . $code . join(', ', $groupVariables) . ';'); diff --git a/Library/Logger.php b/Library/Logger.php index 4512c31e39..a9e4e66b43 100755 --- a/Library/Logger.php +++ b/Library/Logger.php @@ -26,17 +26,17 @@ */ class Logger { - private static $_files = array(); + private static $files = array(); /** * Stderr handler */ - protected $_handler; + protected $handler; /** * @var Config */ - protected $_config; + protected $config; /** * Logger constructor @@ -45,7 +45,7 @@ class Logger */ public function __construct(Config $config) { - $this->_config = $config; + $this->config = $config; } /** @@ -56,10 +56,12 @@ public function __construct(Config $config) */ public function set($type, $value) { - $this->_config->set($type, $value, 'warnings'); + $this->config->set($type, $value, 'warnings'); } /** + * Sends a warning to the logger + * * @param $message * @param $type * @param $node @@ -68,8 +70,8 @@ public function set($type, $value) */ public function warning($message, $type, $node) { - if (!$this->_config->get('silent')) { - if (!$this->_config->get($type, 'warnings')) { + if (!$this->config->get('silent')) { + if (!$this->config->get($type, 'warnings')) { return false; } @@ -102,11 +104,11 @@ public function warning($message, $type, $node) $warning .= PHP_EOL; } - if (!$this->_handler) { - $this->_handler = STDERR; + if (!$this->handler) { + $this->handler = STDERR; } - fprintf($this->_handler, Color::warning($warning)); + fprintf($this->handler, "%s", Color::warning($warning)); return true; } @@ -115,12 +117,14 @@ public function warning($message, $type, $node) } /** + * Outputs a message to stdout if the silent flag is not enabled + * * @param $message * @return bool */ public function output($message) { - if (!$this->_config->get('silent')) { + if (!$this->config->get('silent')) { echo $message . PHP_EOL; return true; }