Skip to content

Commit

Permalink
Fixing warning in logger, fixing declaration of variables with initia…
Browse files Browse the repository at this point in the history
…l defaults
  • Loading branch information
andresgutierrez committed Oct 24, 2014
1 parent edd567a commit 6965c79
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 44 deletions.
95 changes: 62 additions & 33 deletions Library/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -1640,8 +1651,6 @@ public function compile(CompilationContext $compilationContext)

switch ($dataType) {
case 'variable':
/*case 'string':
case 'array':*/
case 'resource':
case 'object':
case 'callable':
Expand Down Expand Up @@ -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';
Expand All @@ -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) . ';');
Expand Down
26 changes: 15 additions & 11 deletions Library/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,7 +45,7 @@ class Logger
*/
public function __construct(Config $config)
{
$this->_config = $config;
$this->config = $config;
}

/**
Expand All @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 6965c79

Please sign in to comment.