diff --git a/.editorconfig b/.editorconfig index 12d5583362..5b33155d27 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,7 +11,7 @@ insert_final_newline = true indent_style = space indent_size = 4 -[*.{c,h,awk,w32,bat,mk,Makefile,frag,zep,lemon,re,psm1}] +[*.{c,h,awk,w32,bat,mk,Makefile,frag,zep,lemon,re,psm1,sh}] charset = utf-8 end_of_line = lf indent_size = 4 @@ -20,7 +20,7 @@ tab_width = 4 trim_trailing_whitespace = true insert_final_newline = true -[*.{yml,m4,sh,json,xml}] +[*.{yml,m4,json,xml}] charset = utf-8 end_of_line = lf indent_size = 4 diff --git a/.gitattributes b/.gitattributes index 7406383562..96fd3d7a36 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,10 @@ -*.html ident +*.html ident + +prototypes/* linguist-vendored + +tests/* linguist-vendored +unit-tests/* linguist-vendored +unit-tests/fixtures/* linguist-vendored + +*.xml.dist text eol=lf linguist-language=XML +*.json.dist text eol=lf linguist-language=JSON diff --git a/.gitignore b/.gitignore index f7ba966a49..6e0b06aa3d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,52 +5,26 @@ # # https://help.github.com/articles/ignoring-files/#create-a-global-gitignore -*.dSYM/ -composer.lock -vendor/ -build/ - -phpunit.xml -phpcs.xml - -# Ignore for all projects based on Zephir .temp/ .libs/ +ext/ +ide/ +doc/ +vendor/ + *.gch *.lo *.la *.loT -ide/ -doc/ +*.dSYM + compile.log compile-errors.log -# Runtime -runtime/.deps -runtime/Makefile -runtime/Makefile.fragments -runtime/Makefile.global -runtime/Makefile.objects -runtime/acinclude.m4 -runtime/aclocal.m4 -runtime/autom4te.cache/ -runtime/config.guess -runtime/config.h -runtime/config.h.in -runtime/config.h.in~ -runtime/config.log -runtime/config.nice -runtime/config.status -runtime/config.sub -runtime/configure -runtime/configure.in -runtime/install-sh -runtime/libtool -runtime/ltmain.sh -runtime/missing -runtime/mkinstalldirs -runtime/modules/ -runtime/run-tests.php -runtime/a.zep -runtime/index.php -runtime/parser.out +composer.lock + +phpunit.xml +phpcs.xml + +zephir.phar +box.json diff --git a/.travis.yml b/.travis.yml index 88201e2ea5..ffff273d10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: false language: php php: - - master + - 'master' - '7.3' - '7.2' - '7.1' @@ -12,67 +12,85 @@ php: git: depth: 1 +branches: + only: + - master + - development + addons: apt: packages: - - gdb - - lcov + - gdb + - lcov -env: - global: - - LD_LIBRARY_PATH="$TRAVIS_BUILD_DIR/build/lib":$LD_LIBRARY_PATH - - LIBRARY_PATH="$TRAVIS_BUILD_DIR/build/lib":$LIBRARY_PATH - - C_INCLUDE_PATH="$TRAVIS_BUILD_DIR/build/include" - - CFLAGS="-g3 -O0 -Wall -fvisibility=hidden" - - REPORT_EXIT_STATUS=1 - - PATH="${HOME}/bin:${PATH}" - - RE2C_VERSION="1.1.1" - - ZEPHIR_PARSER_VERSION="v1.1.2" - - DEFAULT_ZFLAGS="-Wnonexistent-function -Wnonexistent-class -Wunused-variable" - - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest" - - REPORT_COVERAGE=1 matrix: fast_finish: true allow_failures: - # There is still memory leaks - # and other issues like https://github.com/sebastianbergmann/phpunit/pull/3359 - php: 'master' cache: apt: true - ccache: true timeout: 604800 directories: - - $HOME/.ccache - $HOME/.composer/cache - $HOME/.local/opt/re2c - $HOME/.cache/re2c + - $HOME/.cache/php-psr + +env: + global: + - CFLAGS="-g -O0 -Wall -fvisibility=hidden" + - RE2C_VERSION="1.1.1" + - ZEPHIR_PARSER_VERSION="v1.1.3" + - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest" + - REPORT_COVERAGE=1 + - PHPUNIT_DONT_EXIT=0 + - PHPUNIT_CONF=phpunit.xml.dist + - BOX_VERSION=3.1.2 + - PATH="${HOME}/bin:${PATH}" before_install: - - if [[ ! -z "${GH_TOKEN}" ]]; then composer config github-oauth.github.com ${GH_TOKEN}; echo "Configured Github token"; fi; - - export PHP_MAJOR="$(`phpenv which php` -r 'echo phpversion();' | cut -d '.' -f 1)" - - export PHP_MINOR="$(`phpenv which php` -r 'echo phpversion();' | cut -d '.' -f 2)" + - '[[ -z "${GH_TOKEN}" ]] || composer config github-oauth.github.com ${GH_TOKEN}; echo "Configured Github token"' + - export PHP_MAJOR="$(php -r 'echo phpversion();' | cut -d '.' -f 1)" + - export PHP_MINOR="$(php -r 'echo phpversion();' | cut -d '.' -f 2)" + - export PHP_VERNUM="$(php-config --vernum)" - ulimit -c unlimited -S - phpenv config-add ./unit-tests/ci/999-default.ini + - echo "$TRAVIS_PHP_VERSION" install: - travis_retry composer install $DEFAULT_COMPOSER_FLAGS - - travis_retry gem install coveralls-lcov - ./unit-tests/ci/install-re2c.sh $RE2C_VERSION - ./unit-tests/ci/install-zephir-parser.sh - - ./install + - ./install-nosudo + # We need this because there is no PHP 5 compatible PSR extension + - '[[ "${PHP_VERNUM}" -lt 70000 ]] || (./unit-tests/ci/install-php-psr.sh && cp -R ./unit-tests/integration ./test)' + - ./unit-tests/ci/install-test-ext.sh before_script: - - ./unit-tests/ci/install-test-ext.sh + # see: https://github.com/sebastianbergmann/phpunit/pull/3359 + - '[[ "${PHP_VERNUM}" -lt 70300 ]] || export USE_ZEND_ALLOC=1 PHPUNIT_CONF=phpunit-no-coverage.xml.dist' script: - - ./unit-tests/ci/run-unit-tests.sh - + - | + php \ + -d extension=ext/modules/test.so \ + unit-tests/phpunit \ + -c ${PHPUNIT_CONF} \ + --testsuite "Extension Test Suite" + - | + php \ + -d extension=ext/modules/test.so \ + unit-tests/phpunit \ + -c ${PHPUNIT_CONF} \ + --testsuite "Zephir Test Suite" jobs: include: - stage: Static Code Analysis php: 7.2 + env: + - REPORT_COVERAGE=0 script: - vendor/bin/phpcs - stage: Compiller testing @@ -81,17 +99,47 @@ jobs: env: - CC=clang - REPORT_COVERAGE=0 + script: + - | + php \ + -d extension=ext/modules/test.so \ + unit-tests/phpunit \ + -c ${PHPUNIT_CONF} \ + --testsuite "Extension Test Suite" + - stage: Packaging Test + php: 7.2 + env: + - REPORT_COVERAGE=0 + install: + - travis_retry composer install $DEFAULT_COMPOSER_FLAGS + - ./unit-tests/ci/install-re2c.sh $RE2C_VERSION + - ./unit-tests/ci/install-zephir-parser.sh + - mkdir -p ${HOME}/bin + - | + wget \ + "https://github.com/humbug/box/releases/download/${BOX_VERSION}/box.phar" \ + --quiet \ + -O "${HOME}/bin/box" + - chmod +x "${HOME}/bin/box" + - ./bin/packer before_script: - - ./unit-tests/ci/install-test-ext.sh + - phpenv config-rm xdebug.ini || true script: - - ./unit-tests/ci/run-unit-tests.sh + - ./zephir.phar compile + - | + php \ + -d extension=ext/modules/test.so \ + unit-tests/phpunit \ + -c ${PHPUNIT_CONF} \ + --testsuite "Extension Test Suite" - stage: Benchmark php: 7.2 + env: + - REPORT_COVERAGE=0 before_script: - - ./unit-tests/ci/install-test-ext.sh - script: - phpenv config-rm xdebug.ini || true - - $(phpenv which php) -d extension=ext/modules/test.so unit-tests/microbench.php + script: + - php -d extension=ext/modules/test.so unit-tests/microbench.php after_success: - ./unit-tests/ci/after-success.sh diff --git a/Library/AliasManager.php b/Library/AliasManager.php index 5b69727b3e..e9d78c7491 100644 --- a/Library/AliasManager.php +++ b/Library/AliasManager.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/ArgInfoDefinition.php b/Library/ArgInfoDefinition.php new file mode 100644 index 0000000000..559d4ea020 --- /dev/null +++ b/Library/ArgInfoDefinition.php @@ -0,0 +1,328 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir; + +/** + * Zephir\ArgInfoDefinition + * + * @package Zephir + */ +class ArgInfoDefinition +{ + /** @var bool */ + private $returnByRef = false; + + /** @var ClassMethod */ + private $method; + + /** @var string */ + private $name = ''; + + /** @var ClassMethodParameters|null */ + private $parameters; + + /** @var CodePrinter */ + private $codePrinter; + + /** @var CompilationContext */ + private $compilationContext; + + /** @var string */ + private $booleanDefinition = '_IS_BOOL'; + + /** @var bool */ + private $richFormat = true; + + public function __construct( + $name, + ClassMethod $method, + CodePrinter $codePrinter, + CompilationContext $compilationContext, + $returnByRef = false + ) { + $this->method = $method; + $this->codePrinter = $codePrinter; + $this->compilationContext = $compilationContext; + + $this->name = $name; + $this->parameters = $this->method->getParameters(); + + $this->returnByRef = $returnByRef; + } + + public function setBooleanDefinition($definition) + { + $this->booleanDefinition = (string)$definition; + } + + public function setRichFormat($flag) + { + $this->richFormat = (bool)$flag; + } + + /** + * Render argument information. + * + * @throws Exception + */ + public function render() + { + if ($this->richFormat && + $this->method->isReturnTypesHintDetermined() && + $this->method->areReturnTypesCompatible() + ) { + $this->richRenderStart(); + + if ($this->hasParameters() == false) { + $this->codePrinter->output('ZEND_END_ARG_INFO()'); + $this->codePrinter->outputBlankLine(); + } + } elseif ($this->hasParameters() == true) { + $this->codePrinter->output( + sprintf( + "ZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)", + $this->name, + (int)$this->returnByRef, + $this->method->getNumberOfRequiredParameters() + ) + ); + } + + if ($this->hasParameters() == true) { + $this->renderEnd(); + + $this->codePrinter->output('ZEND_END_ARG_INFO()'); + $this->codePrinter->outputBlankLine(); + } + } + + private function richRenderStart() + { + if (array_key_exists('object', $this->method->getReturnTypes())) { + $class = 'NULL'; + + if (count($this->method->getReturnClassTypes()) == 1) { + $class = key($this->method->getReturnClassTypes()); + $class = escape_class($this->compilationContext->getFullName($class)); + } + + $this->codePrinter->output('#if PHP_VERSION_ID >= 70200'); + $this->codePrinter->output( + sprintf( + 'ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(%s, %d, %d, %s, %d)', + $this->name, + (int)$this->returnByRef, + $this->method->getNumberOfRequiredParameters(), + $class, + (int)$this->method->areReturnTypesNullCompatible() + ) + ); + $this->codePrinter->output('#else'); + $this->codePrinter->output( + sprintf( + 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, IS_OBJECT, "%s", %d)', + $this->name, + (int)$this->returnByRef, + $this->method->getNumberOfRequiredParameters(), + $class, + (int)$this->method->areReturnTypesNullCompatible() + ) + ); + $this->codePrinter->output('#endif'); + + return; + } + + $this->codePrinter->output('#if PHP_VERSION_ID >= 70200'); + $this->codePrinter->output( + sprintf( + 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, %d)', + $this->name, + (int)$this->returnByRef, + $this->method->getNumberOfRequiredParameters(), + $this->getReturnType(), + (int)$this->method->areReturnTypesNullCompatible() + ) + ); + + $this->codePrinter->output('#else'); + + $this->codePrinter->output( + sprintf( + 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(%s, %d, %d, %s, NULL, %d)', + $this->name, + (int)$this->returnByRef, + $this->method->getNumberOfRequiredParameters(), + $this->getReturnType(), + (int)$this->method->areReturnTypesNullCompatible() + ) + ); + + $this->codePrinter->output('#endif'); + } + + private function renderEnd() + { + $flag = $this->richFormat ? '1' : '0'; + + foreach ($this->parameters->getParameters() as $parameter) { + switch ("{$flag}:" . $parameter['data-type']) { + case '0:array': + case '1:array': + $this->codePrinter->output( + sprintf( + "\tZEND_ARG_ARRAY_INFO(%d, %s, %d)", + $this->passByReference($parameter), + $parameter['name'], + (int)$this->allowNull($parameter) + ) + ); + break; + case '0:variable': + case '1:variable': + if (isset($parameter['cast'])) { + switch ($parameter['cast']['type']) { + case 'variable': + $value = $parameter['cast']['value']; + $this->codePrinter->output( + sprintf( + "\tZEND_ARG_OBJ_INFO(%d, %s, %s, %d)", + $this->passByReference($parameter), + $parameter['name'], + escape_class($this->compilationContext->getFullName($value)), + (int)$this->allowNull($parameter) + ) + ); + break; + + default: + throw new Exception('Unexpected exception'); + } + } else { + $this->codePrinter->output( + sprintf( + "\tZEND_ARG_INFO(%d, %s)", + $this->passByReference($parameter), + $parameter['name'] + ) + ); + } + break; + + case '1:bool': + case '1:boolean': + $this->codePrinter->output( + sprintf( + "\tZEND_ARG_TYPE_INFO(%d, %s, %s, %d)", + $this->passByReference($parameter), + $parameter['name'], + $this->booleanDefinition, + (int)$this->allowNull($parameter) + ) + ); + break; + case '1:uchar': + case '1:int': + case '1:uint': + case '1:long': + case '1:ulong': + $this->codePrinter->output( + sprintf( + "\tZEND_ARG_TYPE_INFO(%d, %s, IS_LONG, %d)", + $this->passByReference($parameter), + $parameter['name'], + (int)$this->allowNull($parameter) + ) + ); + break; + case '1:double': + $this->codePrinter->output( + sprintf( + "\tZEND_ARG_TYPE_INFO(%d, %s, IS_DOUBLE, %d)", + $this->passByReference($parameter), + $parameter['name'], + (int)$this->allowNull($parameter) + ) + ); + break; + case '1:char': + case '1:string': + $this->codePrinter->output( + sprintf( + "\tZEND_ARG_TYPE_INFO(%d, %s, IS_STRING, %d)", + $this->passByReference($parameter), + $parameter['name'], + (int)$this->allowNull($parameter) + ) + ); + break; + default: + $this->codePrinter->output( + sprintf( + "\tZEND_ARG_INFO(%d, %s)", + $this->passByReference($parameter), + $parameter['name'] + ) + ); + break; + } + } + } + + private function hasParameters() + { + return $this->parameters !== null && count($this->parameters->getParameters()) > 0; + } + + private function allowNull($parameter) + { + if (!isset($parameter['default']) || !is_array($parameter['default'])) { + return false; + } + + if ($parameter['default']['type'] == 'null') { + return true; + } + + return false; + } + + private function passByReference($parameter) + { + return isset($parameter['reference']) ? $parameter['reference'] : 0; + } + + private function getReturnType() + { + if ($this->method->areReturnTypesIntCompatible()) { + return 'IS_LONG'; + } + + if ($this->method->areReturnTypesDoubleCompatible()) { + return 'IS_DOUBLE'; + } + + if ($this->method->areReturnTypesBoolCompatible()) { + return '_IS_BOOL'; + } + + if ($this->method->areReturnTypesStringCompatible()) { + return 'IS_STRING'; + } + + if (array_key_exists('array', $this->method->getReturnTypes())) { + return 'IS_ARRAY'; + } + + return 'IS_NULL'; + } +} diff --git a/Library/Backends/ZendEngine2/Backend.php b/Library/Backends/ZendEngine2/Backend.php index 3f6458eff7..647db820ae 100644 --- a/Library/Backends/ZendEngine2/Backend.php +++ b/Library/Backends/ZendEngine2/Backend.php @@ -1,29 +1,27 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Backends\ZendEngine2; -use Zephir\Utils; -use Zephir\Variable; -use Zephir\Compiler; -use Zephir\CodePrinter; -use Zephir\ClassMethod; use Zephir\BaseBackend; -use Zephir\GlobalConstant; -use Zephir\CompiledExpression; +use Zephir\ClassMethod; +use Zephir\CodePrinter; use Zephir\CompilationContext; +use Zephir\CompiledExpression; +use Zephir\Compiler; use Zephir\Compiler\CompilerException; use Zephir\Fcall\FcallManagerInterface; +use Zephir\GlobalConstant; +use Zephir\Variable; +use function Zephir\add_slashes; /** * Zephir\Backends\ZendEngine2\Backend @@ -34,7 +32,11 @@ class Backend extends BaseBackend { protected $name = 'ZendEngine2'; - /* TODO: This should not be used, temporary (until its completely refactored) */ + /** + * {@inheritdoc} + * + * @return bool + */ public function isZE3() { return false; @@ -248,18 +250,18 @@ public function getTypeofCondition(Variable $variableVariable, $operator, $value break; default: - throw new CompilerException('Unknown type: "' . $value . '" in typeof comparison', $expr['right']); + throw new CompilerException(sprintf('Unknown type: "%s" in typeof comparison', $value)); } return $condition; } - public function onPreInitVar($method, CompilationContext $context) + public function onPreInitVar(ClassMethod $method, CompilationContext $context) { return ''; } - public function onPreCompile($method, CompilationContext $context) + public function onPreCompile(ClassMethod $method, CompilationContext $context) { $codePrinter = $context->codePrinter; /** @@ -286,7 +288,7 @@ public function onPreCompile($method, CompilationContext $context) } } - public function onPostCompile($method, CompilationContext $context) + public function onPostCompile(ClassMethod $method, CompilationContext $context) { $codePrinter = $context->codePrinter; if (preg_match('/^zephir_init_properties/', $method->getName())) { @@ -340,6 +342,7 @@ public function generateInitCode(&$groupVariables, $type, $pointer, Variable $va $groupVariables[] = $pointer . $variable->getName(); break; + /** @noinspection PhpMissingBreakStatementInspection */ case 'char': if (strlen($defaultValue) > 4) { if (strlen($defaultValue) > 10) { @@ -417,7 +420,11 @@ public function initializeVariableDefaults($variables, CompilationContext $compi break; case 'string': - $compilationContext->backend->assignString($variable, Utils::addSlashes($defaultValue['value'], true), $compilationContext); + $compilationContext->backend->assignString( + $variable, + add_slashes($defaultValue['value']), + $compilationContext + ); break; case 'array': @@ -445,7 +452,11 @@ public function initializeVariableDefaults($variables, CompilationContext $compi $compilationContext->backend->initVar($variable, $compilationContext); switch ($defaultValue['type']) { case 'string': - $compilationContext->backend->assignString($variable, Utils::addSlashes($defaultValue['value'], true), $compilationContext); + $compilationContext->backend->assignString( + $variable, + add_slashes($defaultValue['value']), + $compilationContext + ); break; case 'null': @@ -593,7 +604,7 @@ public function declareConstant($type, $name, $value, CompilationContext $contex case 'string': case 'char': if ($type == 'string' || $type == 'char') { - $value = "\"" . Utils::addSlashes($value) . "\""; + $value = "\"" . add_slashes($value) . "\""; } $dType = 'string'; break; @@ -998,7 +1009,16 @@ public function arrayUnset(Variable $variable, $exprIndex, $flags, CompilationCo } } - private function resolveOffsetExprs($offsetExprs, $compilationContext) + /** + * Resolve expressions. + * + * @param CompiledExpression[]|string[] $offsetExprs + * @param CompilationContext $compilationContext + * @return array + * + * @throws CompilerException + */ + private function resolveOffsetExprs($offsetExprs, CompilationContext $compilationContext) { $keys = ''; $offsetItems = array(); @@ -1027,7 +1047,12 @@ private function resolveOffsetExprs($offsetExprs, $compilationContext) break; case 'variable': - $variableIndex = $compilationContext->symbolTable->getVariableForRead($offsetExpr->getCode(), $compilationContext, null); + $variableIndex = $compilationContext->symbolTable->getVariableForRead( + $offsetExpr->getCode(), + $compilationContext, + null + ); + switch ($variableIndex->getType()) { case 'int': case 'uint': @@ -1044,12 +1069,18 @@ private function resolveOffsetExprs($offsetExprs, $compilationContext) $numberParams++; break; default: - throw new CompilerException("Variable: " . $variableIndex->getType() . " cannot be used as array index", $statement); + throw new CompilerException( + sprintf('Variable: %s cannot be used as array index', $variableIndex->getType()), + $offsetExpr->getOriginal() + ); } break; default: - throw new CompilerException("Value: " . $offsetExpr->getType() . " cannot be used as array index", $statement); + throw new CompilerException( + sprintf('Value: %s cannot be used as array index', $offsetExpr->getType()), + $offsetExpr->getOriginal() + ); } } return array($keys, $offsetItems, $numberParams); diff --git a/Library/Backends/ZendEngine2/FcallManager.php b/Library/Backends/ZendEngine2/FcallManager.php index 8066a43090..517ea4df2b 100644 --- a/Library/Backends/ZendEngine2/FcallManager.php +++ b/Library/Backends/ZendEngine2/FcallManager.php @@ -1,21 +1,19 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Backends\ZendEngine2; -use Zephir\Utils; use Zephir\CodePrinter; use Zephir\Fcall\FcallManagerInterface; +use function Zephir\file_put_contents_ex; /** * Zephir\Backends\ZendEngine2\FcallManager @@ -163,6 +161,6 @@ public function genFcallCode() $codePrinter->decreaseLevel(); $codePrinter->output("#endif"); - Utils::checkAndWriteIfNeeded($codePrinter->getOutput(), 'ext/kernel/fcall_internal.h'); + file_put_contents_ex($codePrinter->getOutput(), 'ext/kernel/fcall_internal.h'); } } diff --git a/Library/Backends/ZendEngine2/StringsManager.php b/Library/Backends/ZendEngine2/StringsManager.php index f44a060c0b..526cef50f6 100644 --- a/Library/Backends/ZendEngine2/StringsManager.php +++ b/Library/Backends/ZendEngine2/StringsManager.php @@ -1,20 +1,18 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Backends\ZendEngine2; -use Zephir\Utils; use Zephir\StringsManager as BaseStringsManager; +use function Zephir\file_put_contents_ex; /** * Class StringsManager @@ -27,11 +25,11 @@ class StringsManager extends BaseStringsManager * List of headers * @var array */ - protected $concatKeys = array( + protected $concatKeys = [ 'vv' => true, 'vs' => true, 'sv' => true - ); + ]; /** * Adds a concatenation combination to the manager @@ -115,7 +113,6 @@ public function genConcatCode() $macros[] = '#define ZEPHIR_SCONCAT_' . strtoupper($key) . '(result, ' . join(', ', $sparams) . ') \\' . PHP_EOL . "\t" . ' zephir_concat_' . $key . '(&result, ' . join(', ', $lparams) . ', 1 TSRMLS_CC);'; $macros[] = ''; - $proto = 'void zephir_concat_' . $key . '(zval **result, ' . join(', ', $params) . ', int self_var TSRMLS_DC)'; $proto = 'void zephir_concat_' . $key . '(zval **result, ' . join(', ', $params) . ', int self_var TSRMLS_DC)'; $codeh .= '' . $proto . ';' . PHP_EOL; @@ -216,8 +213,9 @@ public function genConcatCode() } } "; - Utils::checkAndWriteIfNeeded($pcodeh . join(PHP_EOL, $macros) . PHP_EOL . PHP_EOL . $codeh, 'ext/kernel/concat.h'); - Utils::checkAndWriteIfNeeded($code, 'ext/kernel/concat.c'); + $contents = $pcodeh . join(PHP_EOL, $macros) . PHP_EOL . PHP_EOL . $codeh; + file_put_contents_ex($contents, 'ext/kernel/concat.h'); + file_put_contents_ex($code, 'ext/kernel/concat.c'); } /** diff --git a/Library/Backends/ZendEngine3/Backend.php b/Library/Backends/ZendEngine3/Backend.php index 6f4c3bc325..44c3030090 100644 --- a/Library/Backends/ZendEngine3/Backend.php +++ b/Library/Backends/ZendEngine3/Backend.php @@ -1,30 +1,28 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Backends\ZendEngine3; -use Zephir\Utils; -use Zephir\Variable; -use Zephir\Compiler; -use Zephir\ClassMethod; -use Zephir\GlobalConstant; +use Zephir\Backends\ZendEngine2\Backend as BackendZendEngine2; use Zephir\ClassDefinition; +use Zephir\ClassMethod; use Zephir\CompilationContext; use Zephir\CompiledExpression; -use Zephir\FunctionDefinition; -use Zephir\Fcall\FcallManagerInterface; +use Zephir\Compiler; use Zephir\Compiler\CompilerException; -use Zephir\Backends\ZendEngine2\Backend as BackendZendEngine2; +use Zephir\Fcall\FcallManagerInterface; +use Zephir\FunctionDefinition; +use Zephir\GlobalConstant; +use Zephir\Variable; +use function Zephir\add_slashes; /** * Zephir\Backends\ZendEngine3\Backend @@ -35,7 +33,11 @@ class Backend extends BackendZendEngine2 { protected $name = 'ZendEngine3'; - /* TODO: This should not be used, temporary (until its completely refactored) */ + /** + * {@inheritdoc} + * + * @return bool + */ public function isZE3() { return true; @@ -174,7 +176,7 @@ public function getTypeofCondition(Variable $variableVariable, $operator, $value return $condition; } - public function onPreInitVar($method, CompilationContext $context) + public function onPreInitVar(ClassMethod $method, CompilationContext $context) { if ($method instanceof FunctionDefinition) { return; @@ -184,7 +186,7 @@ public function onPreInitVar($method, CompilationContext $context) } } - public function onPreCompile($method, CompilationContext $context) + public function onPreCompile(ClassMethod $method, CompilationContext $context) { $codePrinter = $context->codePrinter; /** @@ -200,7 +202,7 @@ public function onPreCompile($method, CompilationContext $context) } } - public function onPostCompile($method, CompilationContext $context) + public function onPostCompile(ClassMethod $method, CompilationContext $context) { $codePrinter = $context->codePrinter; if (preg_match('/^zephir_init_properties/', $method->getName())) { @@ -258,6 +260,7 @@ public function generateInitCode(&$groupVariables, $type, $pointer, Variable $va $groupVariables[] = $pointer . $variable->getName(); break; + /** @noinspection PhpMissingBreakStatementInspection */ case 'char': if (strlen($defaultValue) > 4) { if (strlen($defaultValue) > 10) { @@ -305,7 +308,7 @@ public function declareConstant($type, $name, $value, CompilationContext $contex case 'string': case 'char': if ($type == 'string' || $type == 'char') { - $value = "\"" . Utils::addSlashes($value) . "\""; + $value = "\"" . add_slashes($value) . "\""; } $dType = 'string'; break; diff --git a/Library/Backends/ZendEngine3/FcallManager.php b/Library/Backends/ZendEngine3/FcallManager.php index 9771ae5563..8bedbf6226 100644 --- a/Library/Backends/ZendEngine3/FcallManager.php +++ b/Library/Backends/ZendEngine3/FcallManager.php @@ -1,22 +1,20 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Backends\ZendEngine3; -use Zephir\Utils; +use Zephir\Backends\ZendEngine2\FcallManager as ZE2FcallManager; use Zephir\CodePrinter; use Zephir\Fcall\FcallManagerInterface; -use Zephir\Backends\ZendEngine2\FcallManager as ZE2FcallManager; +use function Zephir\file_put_contents_ex; /** * Zephir\Backends\ZendEngine3\FcallManager @@ -116,6 +114,6 @@ public function genFcallCode() $codePrinter->decreaseLevel(); $codePrinter->output("#endif"); - Utils::checkAndWriteIfNeeded($codePrinter->getOutput(), 'ext/kernel/fcall_internal.h'); + file_put_contents_ex($codePrinter->getOutput(), 'ext/kernel/fcall_internal.h'); } } diff --git a/Library/Backends/ZendEngine3/StringsManager.php b/Library/Backends/ZendEngine3/StringsManager.php index 409a70faf1..96f120175a 100644 --- a/Library/Backends/ZendEngine3/StringsManager.php +++ b/Library/Backends/ZendEngine3/StringsManager.php @@ -1,20 +1,18 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Backends\ZendEngine3; -use Zephir\Utils; use Zephir\StringsManager as BaseStringsManager; +use function Zephir\file_put_contents_ex; /** * Class StringsManager @@ -108,7 +106,6 @@ public function genConcatCode() $macros[] = '#define ZEPHIR_SCONCAT_' . strtoupper($key) . '(result, ' . join(', ', $sparams) . ') \\' . PHP_EOL . "\t" . ' zephir_concat_' . $key . '(result, ' . join(', ', $lparams) . ', 1);'; $macros[] = ''; - $proto = 'void zephir_concat_' . $key . '(zval *result, ' . join(', ', $params) . ', int self_var)'; $proto = 'void zephir_concat_' . $key . '(zval *result, ' . join(', ', $params) . ', int self_var)'; $codeh .= '' . $proto . ';' . PHP_EOL; @@ -207,8 +204,9 @@ public function genConcatCode() $codeh .= "void zephir_concat_function(zval *result, zval *op1, zval *op2); #endif /* ZEPHIR_KERNEL_CONCAT_H */ "; - Utils::checkAndWriteIfNeeded($pcodeh . join(PHP_EOL, $macros) . PHP_EOL . PHP_EOL . $codeh, 'ext/kernel/concat.h'); - Utils::checkAndWriteIfNeeded($code, 'ext/kernel/concat.c'); + $contents = $pcodeh . join(PHP_EOL, $macros) . PHP_EOL . PHP_EOL . $codeh; + file_put_contents_ex($contents, 'ext/kernel/concat.h'); + file_put_contents_ex($code, 'ext/kernel/concat.c'); } /** diff --git a/Library/BaseBackend.php b/Library/BaseBackend.php index 020ace9770..3523d0325d 100644 --- a/Library/BaseBackend.php +++ b/Library/BaseBackend.php @@ -1,18 +1,17 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; +use Zephir\Di\Singleton; use Zephir\Fcall\FcallAwareInterface; use Zephir\Fcall\FcallManagerInterface; @@ -38,48 +37,59 @@ abstract class BaseBackend implements FcallAwareInterface * BaseBackend constructor * * @param Config $config - * @throws Exception */ public function __construct(Config $config) { $this->config = $config; } + /** + * TODO: This should not be used, temporary (until its completely refactored). + * + * @return bool + */ + abstract public function isZE3(); + public function getName() { return $this->name; } /** - * Resolves the path to the source kernel files of the backend - * @return string Absolute path to kernel files + * Resolves the path to the source kernel files of the backend. + * + * @return string */ public function getInternalKernelPath() { - return realpath(__DIR__ . '/../kernels/' . $this->name); + return Singleton::getDefault()->get(Environment::class)->getKernelsPath($this->name); } /** - * Resolves the path to the source template files of the backend - * @return string Absolute path to template files + * Resolves the path to the source template files of the backend. + * + * @return string */ public function getInternalTemplatePath() { - return realpath(__DIR__ . '/../templates/' . $this->name); + return Singleton::getDefault()->get(Environment::class)->getTemplatesPath($this->name); } /** - * Resolves the path to the source template file of the backend + * Resolves the path to the source template file of the backend. * - * @param string $filename - * @return string Absolute path to template file + * @param string $filename + * @return string */ public function getTemplateFileContents($filename) { - $filepath = realpath(rtrim($this->config->get('templatepath', 'backend'), '/').'/'.$this->name.'/'.$filename); - if (!file_exists($filepath)) { - $filepath = realpath(__DIR__ . '/../templates/'.$this->name.'/'.$filename); + $templatepath = rtrim($this->config->get('templatepath', 'backend'), '\\/'); + if (empty($templatepath)) { + $templatepath = Singleton::getDefault()->get(Environment::class)->getTemplatesPath(); } + + $filepath = $templatepath . DIRECTORY_SEPARATOR . $this->name . DIRECTORY_SEPARATOR . $filename; + return file_get_contents($filepath); } @@ -160,9 +170,9 @@ abstract public function forStatement(Variable $exprVariable, $keyVariable, $var abstract public function forStatementIterator(Variable $iteratorVariable, Variable $targetVariable, CompilationContext $compilationContext); abstract public function destroyIterator(Variable $iteratorVariable, CompilationContext $context); - abstract public function onPreInitVar($method, CompilationContext $context); - abstract public function onPreCompile($method, CompilationContext $context); - abstract public function onPostCompile($method, CompilationContext $context); + abstract public function onPreInitVar(ClassMethod $method, CompilationContext $context); + abstract public function onPreCompile(ClassMethod $method, CompilationContext $context); + abstract public function onPostCompile(ClassMethod $method, CompilationContext $context); /** * @param Variable $variable diff --git a/Library/Bootstrap.php b/Library/Bootstrap.php index ffa6a0c9c9..8b87eff237 100644 --- a/Library/Bootstrap.php +++ b/Library/Bootstrap.php @@ -1,88 +1,57 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir; use Zephir\Commands\Manager; use Zephir\Exception\ExceptionInterface; +use Zephir\Providers\CompillerProvider; +use Psr\Container\ContainerInterface; /** * Zephir\Bootstrap * - * Main compiler bootstrap - * * @package Zephir */ -class Bootstrap +final class Bootstrap { /** - * The Zephir base direcrory. - * @var string - */ - private $baseDir; - - /** - * Commands manager. - * @var Manager - */ - private $commandsManager; - - /** - * Bootstrap constructor. + * The Service Registrator instance. * - * @param string $baseDir The base Zephir direcrory. + * @var ServiceRegistrator */ - public function __construct($baseDir = null) - { - $baseDir = realpath($baseDir ?: dirname(__DIR__)); - - if (!is_string($baseDir) || !is_dir($baseDir)) { - fwrite( - STDERR, - sprintf( - "Unable to locate Zephir installation path.\n\nDouble check Zephir installation " . - "and/or try to setup ZEPHIRDIR variable to the proper Zephir installation path.\n\n" . - "Current ZEPHIRDIR value: %s\nThe base path passed to the Bootstrap: %s\n", - getenv('ZEPHIRDIR'), - is_string($baseDir) ? $baseDir : gettype($baseDir) - ) - ); - - exit(1); - } - - $this->baseDir = rtrim($baseDir, '\\/'); - $this->commandsManager = new Manager(); - } + protected $serviceRegistrator; /** - * Gets the Zephir base direcrory. + * Bootstrap constructor. * - * @return string + * @param string $basePath The Zephir compiller base direcrory. + * @param ContainerInterface $container The DI container (if any). */ - public function getBaseDir() + public function __construct($basePath, ContainerInterface $container = null) { - return $this->baseDir; + $this->serviceRegistrator = new ServiceRegistrator($basePath, $container); + $this->registerCompiller(); } /** - * Gets currently initialized Command Manager. + * Register Zephir compiller. * - * @return Manager + * @return void */ - public function getCommandsManager() + protected function registerCompiller() { - return $this->commandsManager; + $this->serviceRegistrator->registerService( + new CompillerProvider() + ); } /** @@ -90,30 +59,29 @@ public function getCommandsManager() * * @return void */ - public function boot() + public function execute() { - try { - // Global Config - $config = Config::fromServer(); - - // Global Logger - $logger = new Logger($config); - - if (isset($_SERVER['argv'][1])) { - $action = $_SERVER['argv'][1]; - } else { - $action = 'help'; - } + $container = $this->serviceRegistrator->getContainer(); - $manager = new Manager(); - $manager->registerBuiltinCommands(); + if (isset($_SERVER['argv'][1])) { + $action = $_SERVER['argv'][1]; + } else { + $action = 'help'; + } + try { + /** @var Manager $manager */ + $manager = $container->get(Manager::class); $command = $manager->resolveByActionName($action); // Execute the command - $command->execute($config, $logger); + $command->execute($container->get(Config::class), $container->get(Logger::class)); } catch (\Exception $e) { - fwrite(STDERR, $this->formatErrorMessage($e, isset($config) ? $config : null)); + fwrite( + STDERR, + $this->formatErrorMessage($e, $container->has(Config::class) ? $container->get(Config::class) : null) + ); + exit(1); } } @@ -121,21 +89,21 @@ public function boot() /** * Formats error message to show an exception opening the file and highlighting the wrong part. * - * @param \Exception $e - * @param Config $config Current config object [optional]. + * @param \Exception $exception + * @param Config $config Current config object [optional]. * @return string */ - protected function formatErrorMessage(\Exception $e, Config $config = null) + protected function formatErrorMessage(\Exception $exception, Config $config = null) { $message = ''; if ($config && $config->get('verbose')) { - $message .= sprintf('[%s]: ', get_class($e)); + $message .= sprintf('[%s]: ', get_class($exception)); } - $message .= $e->getMessage() . PHP_EOL; + $message .= $exception->getMessage() . PHP_EOL; - if ($e instanceof ExceptionInterface && $extraInfo = $e->getErrorRegion()) { + if ($exception instanceof ExceptionInterface && $extraInfo = $exception->getErrorRegion()) { $message .= sprintf("\n%s", $extraInfo); } @@ -144,17 +112,21 @@ protected function formatErrorMessage(\Exception $e, Config $config = null) return $message; } - $base = $this->baseDir; - $preparePaths = function ($path) use ($base) { - if (is_string($base)) { - $path = str_replace(rtrim($base, '\\/') . DIRECTORY_SEPARATOR, '', $path); + $container = $this->serviceRegistrator->getContainer(); + + /** @var Environment $environment */ + $environment = $container->has(Environment::class) ? $container->get(Environment::class) : null; + + $preparePaths = function ($path) use ($environment) { + if ($environment) { + $path = str_replace($environment->getPath() . DIRECTORY_SEPARATOR, '', $path); } return $path; }; - $message .= sprintf("at %s(%s)\n\n", $preparePaths($e->getFile()), $e->getLine()); - $message .= sprintf("Stack trace:\n%s\n", $preparePaths($e->getTraceAsString())); + $message .= sprintf("at %s(%s)\n\n", $preparePaths($exception->getFile()), $exception->getLine()); + $message .= sprintf("Stack trace:\n%s\n", $preparePaths($exception->getTraceAsString())); return $message; } diff --git a/Library/Branch.php b/Library/Branch.php index 558ec83a2a..30e9d87640 100644 --- a/Library/Branch.php +++ b/Library/Branch.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/BranchGraph.php b/Library/BranchGraph.php index b4f898dc3b..5df319f925 100644 --- a/Library/BranchGraph.php +++ b/Library/BranchGraph.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/BranchGraphNode.php b/Library/BranchGraphNode.php index 8007ae7002..3bd9985cf9 100644 --- a/Library/BranchGraphNode.php +++ b/Library/BranchGraphNode.php @@ -1,37 +1,42 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; /** - * BranchGraphNode + * Branch\BranchGraphNode * * Allows to visualize assignments for a specific variable in every branch used + * + * @package Zephir */ class BranchGraphNode { - protected $_increase = 0; + /** @var int */ + protected $increase = 0; + + /** @var Branch[] */ + protected $branches = []; - protected $_branches = array(); + /** @var Branch */ + protected $branch; /** * BranchGraphNode * * @param Branch $branch */ - public function __construct($branch) + public function __construct(Branch $branch) { - $this->_branch = $branch; + $this->branch = $branch; } /** @@ -41,8 +46,8 @@ public function __construct($branch) */ public function insert(BranchGraphNode $branch) { - if (!in_array($branch, $this->_branches)) { - $this->_branches[] = $branch; + if (!in_array($branch, $this->branches)) { + $this->branches[] = $branch; } } @@ -51,7 +56,7 @@ public function insert(BranchGraphNode $branch) */ public function increase() { - $this->_increase++; + $this->increase++; } /** @@ -61,10 +66,10 @@ public function increase() */ public function show($padding = 0) { - echo str_repeat(" ", $padding), $this->_branch->getUniqueId(), ':' , $this->_increase; - if (count($this->_branches)) { + echo str_repeat(" ", $padding), $this->branch->getUniqueId(), ':' , $this->increase; + if (count($this->branches)) { echo ':', PHP_EOL; - foreach ($this->_branches as $node) { + foreach ($this->branches as $node) { $node->show($padding + 1); } } else { diff --git a/Library/BranchManager.php b/Library/BranchManager.php index dd6aa36bba..5722596676 100644 --- a/Library/BranchManager.php +++ b/Library/BranchManager.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/Builder/FunctionCallBuilder.php b/Library/Builder/FunctionCallBuilder.php index 30e6c621ff..b4985f756a 100644 --- a/Library/Builder/FunctionCallBuilder.php +++ b/Library/Builder/FunctionCallBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder; diff --git a/Library/Builder/LiteralBuilder.php b/Library/Builder/LiteralBuilder.php index 0cb99c9595..baeae38e10 100644 --- a/Library/Builder/LiteralBuilder.php +++ b/Library/Builder/LiteralBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder; diff --git a/Library/Builder/Operators/AbstractOperatorBuilder.php b/Library/Builder/Operators/AbstractOperatorBuilder.php index 32ec25470d..b3f423cc44 100644 --- a/Library/Builder/Operators/AbstractOperatorBuilder.php +++ b/Library/Builder/Operators/AbstractOperatorBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Operators; diff --git a/Library/Builder/Operators/BinaryOperatorBuilder.php b/Library/Builder/Operators/BinaryOperatorBuilder.php index de87f7ae99..2be0cf998a 100644 --- a/Library/Builder/Operators/BinaryOperatorBuilder.php +++ b/Library/Builder/Operators/BinaryOperatorBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Operators; diff --git a/Library/Builder/Operators/CastOperatorBuilder.php b/Library/Builder/Operators/CastOperatorBuilder.php index 2e4991feab..b07c665144 100644 --- a/Library/Builder/Operators/CastOperatorBuilder.php +++ b/Library/Builder/Operators/CastOperatorBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Operators; diff --git a/Library/Builder/Operators/NewInstanceOperatorBuilder.php b/Library/Builder/Operators/NewInstanceOperatorBuilder.php index 6a44b5beef..b40513a6fe 100644 --- a/Library/Builder/Operators/NewInstanceOperatorBuilder.php +++ b/Library/Builder/Operators/NewInstanceOperatorBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Operators; diff --git a/Library/Builder/Operators/TypeOfOperatorBuilder.php b/Library/Builder/Operators/TypeOfOperatorBuilder.php index a457a986f4..d3e7fef339 100644 --- a/Library/Builder/Operators/TypeOfOperatorBuilder.php +++ b/Library/Builder/Operators/TypeOfOperatorBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Operators; diff --git a/Library/Builder/Operators/UnaryOperatorBuilder.php b/Library/Builder/Operators/UnaryOperatorBuilder.php index e12b38e6d5..4d95558eba 100644 --- a/Library/Builder/Operators/UnaryOperatorBuilder.php +++ b/Library/Builder/Operators/UnaryOperatorBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Operators; diff --git a/Library/Builder/ParameterBuilder.php b/Library/Builder/ParameterBuilder.php index 4704be37b9..47db657a2c 100644 --- a/Library/Builder/ParameterBuilder.php +++ b/Library/Builder/ParameterBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder; diff --git a/Library/Builder/RawExpressionBuilder.php b/Library/Builder/RawExpressionBuilder.php index e5c251276c..111cf67aa4 100644 --- a/Library/Builder/RawExpressionBuilder.php +++ b/Library/Builder/RawExpressionBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder; diff --git a/Library/Builder/Statements/AbstractStatementBuilder.php b/Library/Builder/Statements/AbstractStatementBuilder.php index fa4f1ddcef..a571ee6c70 100644 --- a/Library/Builder/Statements/AbstractStatementBuilder.php +++ b/Library/Builder/Statements/AbstractStatementBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Statements; diff --git a/Library/Builder/Statements/IfStatementBuilder.php b/Library/Builder/Statements/IfStatementBuilder.php index 6e3e5c5226..6fb1202d82 100644 --- a/Library/Builder/Statements/IfStatementBuilder.php +++ b/Library/Builder/Statements/IfStatementBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Statements; diff --git a/Library/Builder/Statements/LetStatementBuilder.php b/Library/Builder/Statements/LetStatementBuilder.php index 4052bd359f..12dc0e52c0 100644 --- a/Library/Builder/Statements/LetStatementBuilder.php +++ b/Library/Builder/Statements/LetStatementBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Statements; diff --git a/Library/Builder/Statements/ReturnStatementBuilder.php b/Library/Builder/Statements/ReturnStatementBuilder.php index c30e252e76..d5f04115f3 100644 --- a/Library/Builder/Statements/ReturnStatementBuilder.php +++ b/Library/Builder/Statements/ReturnStatementBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Statements; diff --git a/Library/Builder/Statements/ThrowStatementBuilder.php b/Library/Builder/Statements/ThrowStatementBuilder.php index de8ddc748f..29468712a7 100644 --- a/Library/Builder/Statements/ThrowStatementBuilder.php +++ b/Library/Builder/Statements/ThrowStatementBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder\Statements; diff --git a/Library/Builder/StatementsBlockBuilder.php b/Library/Builder/StatementsBlockBuilder.php index 1404dd8492..6a53a12cd1 100644 --- a/Library/Builder/StatementsBlockBuilder.php +++ b/Library/Builder/StatementsBlockBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder; diff --git a/Library/Builder/VariableBuilder.php b/Library/Builder/VariableBuilder.php index 765d83d695..3c3ac0adaa 100644 --- a/Library/Builder/VariableBuilder.php +++ b/Library/Builder/VariableBuilder.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Builder; diff --git a/Library/Cache/ClassEntryCache.php b/Library/Cache/ClassEntryCache.php index 45bd9433c3..7c719daf9c 100644 --- a/Library/Cache/ClassEntryCache.php +++ b/Library/Cache/ClassEntryCache.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Cache; @@ -30,6 +28,7 @@ class ClassEntryCache * @param string $className * @param boolean $dynamic * @param CompilationContext $compilationContext + * @return \Zephir\Variable */ public function get($className, $dynamic, CompilationContext $compilationContext) { diff --git a/Library/Cache/FunctionCache.php b/Library/Cache/FunctionCache.php index 726b421a4a..b303415543 100644 --- a/Library/Cache/FunctionCache.php +++ b/Library/Cache/FunctionCache.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Cache; diff --git a/Library/Cache/MethodCache.php b/Library/Cache/MethodCache.php index 38225dc329..8b319547ee 100644 --- a/Library/Cache/MethodCache.php +++ b/Library/Cache/MethodCache.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Cache; diff --git a/Library/Cache/SlotsCache.php b/Library/Cache/SlotsCache.php index 9e993a9480..90ee6bb23e 100644 --- a/Library/Cache/SlotsCache.php +++ b/Library/Cache/SlotsCache.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Cache; diff --git a/Library/Cache/StaticMethodCache.php b/Library/Cache/StaticMethodCache.php index 1aa6621a3d..996b8d22b7 100644 --- a/Library/Cache/StaticMethodCache.php +++ b/Library/Cache/StaticMethodCache.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Cache; diff --git a/Library/CacheManager.php b/Library/CacheManager.php index ddd1e82d5c..ab17cb0e2f 100644 --- a/Library/CacheManager.php +++ b/Library/CacheManager.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/Call.php b/Library/Call.php index b14c129917..0416327189 100644 --- a/Library/Call.php +++ b/Library/Call.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; @@ -17,9 +15,11 @@ use Zephir\Detectors\ReadDetector; /** - * Call + * Zephir\Call * * Base class for common functionality in functions/calls + * + * @package Zephir */ class Call { @@ -27,25 +27,25 @@ class Call * Call expression * @var Expression */ - protected $_expression; + protected $expression; - protected $_mustInit; + protected $mustInit; - protected $_symbolVariable; + protected $symbolVariable; - protected $_isExpecting = false; + protected $isExpecting = false; - protected $_resolvedParams; + protected $resolvedParams; - protected $_reflection; + protected $reflection; - protected $_resolvedTypes = []; + protected $resolvedTypes = []; - protected $_resolvedDynamicTypes = []; + protected $resolvedDynamicTypes = []; - protected $_temporalVariables = []; + protected $temporalVariables = []; - protected $_mustCheckForCopy = []; + protected $mustCheckForCopy = []; /** * Processes the symbol variable that will be used to return @@ -55,7 +55,7 @@ class Call */ public function processExpectedReturn(CompilationContext $compilationContext) { - $expr = $this->_expression; + $expr = $this->expression; $expression = $expr->getExpression(); /** @@ -82,9 +82,9 @@ public function processExpectedReturn(CompilationContext $compilationContext) } } - $this->_mustInit = $mustInit; - $this->_symbolVariable = $symbolVariable; - $this->_isExpecting = $isExpecting; + $this->mustInit = $mustInit; + $this->symbolVariable = $symbolVariable; + $this->isExpecting = $isExpecting; } /** @@ -95,7 +95,7 @@ public function processExpectedReturn(CompilationContext $compilationContext) */ public function processExpectedObservedReturn(CompilationContext $compilationContext) { - $expr = $this->_expression; + $expr = $this->expression; $expression = $expr->getExpression(); /** @@ -118,9 +118,9 @@ public function processExpectedObservedReturn(CompilationContext $compilationCon } } - $this->_mustInit = $mustInit; - $this->_symbolVariable = $symbolVariable; - $this->_isExpecting = $isExpecting; + $this->mustInit = $mustInit; + $this->symbolVariable = $symbolVariable; + $this->isExpecting = $isExpecting; } /** @@ -132,7 +132,7 @@ public function processExpectedObservedReturn(CompilationContext $compilationCon */ public function processExpectedComplexLiteralReturn(CompilationContext $compilationContext) { - $expr = $this->_expression; + $expr = $this->expression; $expression = $expr->getExpression(); /** @@ -154,9 +154,9 @@ public function processExpectedComplexLiteralReturn(CompilationContext $compilat } } - $this->_mustInit = $mustInit; - $this->_symbolVariable = $symbolVariable; - $this->_isExpecting = $isExpecting; + $this->mustInit = $mustInit; + $this->symbolVariable = $symbolVariable; + $this->isExpecting = $isExpecting; } /** @@ -166,7 +166,7 @@ public function processExpectedComplexLiteralReturn(CompilationContext $compilat */ public function isExpectingReturn() { - return $this->_isExpecting; + return $this->isExpecting; } /** @@ -176,22 +176,24 @@ public function isExpectingReturn() */ public function mustInitSymbolVariable() { - return $this->_mustInit; + return $this->mustInit; } /** * Returns the symbol variable that must be returned by the call * - * @param boolean $useTemp - * @param CompilationContext $compilationContext + * @param bool $useTemp + * @param CompilationContext|null $compilationContext * @return Variable */ public function getSymbolVariable($useTemp = false, CompilationContext $compilationContext = null) { - $symbolVariable = $this->_symbolVariable; + $symbolVariable = $this->symbolVariable; + if ($useTemp && !is_object($symbolVariable)) { return $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext); } + return $symbolVariable; } @@ -209,7 +211,7 @@ public function getSymbolVariable($useTemp = false, CompilationContext $compilat */ public function getResolvedParamsAsExpr($parameters, CompilationContext $compilationContext, $expression, $readOnly = false) { - if (!$this->_resolvedParams) { + if (!$this->resolvedParams) { $hasParametersByName = false; foreach ($parameters as $parameter) { if (isset($parameter['name'])) { @@ -230,9 +232,9 @@ public function getResolvedParamsAsExpr($parameters, CompilationContext $compila } if ($hasParametersByName) { - if ($this->_reflection) { + if ($this->reflection) { $positionalParameters = array(); - foreach ($this->_reflection->getParameters() as $position => $reflectionParameter) { + foreach ($this->reflection->getParameters() as $position => $reflectionParameter) { if (is_object($reflectionParameter)) { $positionalParameters[$reflectionParameter->getName()] = $position; } else { @@ -285,10 +287,10 @@ public function getResolvedParamsAsExpr($parameters, CompilationContext $compila throw new CompilerException("Invalid expression ", $expression); } - $this->_resolvedParams = $params; + $this->resolvedParams = $params; } - return $this->_resolvedParams; + return $this->resolvedParams; } /** @@ -312,12 +314,10 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo * Static typed parameters in final/private methods are promotable to read only parameters * Recursive calls with static typed methods also also promotable */ - $isFinal = false; $readOnlyParameters = array(); if (is_object($calleeDefinition)) { if ($calleeDefinition instanceof ClassMethod) { if ($calleeDefinition->isFinal() || $calleeDefinition->isPrivate() || $calleeDefinition->isInternal() || $compilationContext->currentMethod == $calleeDefinition) { - $isFinal = true; foreach ($calleeDefinition->getParameters() as $position => $parameter) { if (isset($parameter['data-type'])) { switch ($parameter['data-type']) { @@ -349,7 +349,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo $parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext); $params[] = $compilationContext->backend->getVariableCode($parameterVariable); $compilationContext->backend->assignNull($parameterVariable, $compilationContext); - $this->_temporalVariables[] = $parameterVariable; + $this->temporalVariables[] = $parameterVariable; $types[] = $compiledExpression->getType(); $dynamicTypes[] = $compiledExpression->getType(); break; @@ -360,7 +360,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo $parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext); $params[] = $compilationContext->backend->getVariableCode($parameterVariable); $compilationContext->backend->assignLong($parameterVariable, $compiledExpression->getCode(), $compilationContext); - $this->_temporalVariables[] = $parameterVariable; + $this->temporalVariables[] = $parameterVariable; $types[] = $compiledExpression->getType(); $dynamicTypes[] = $compiledExpression->getType(); break; @@ -369,7 +369,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo $parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext); $params[] = $compilationContext->backend->getVariableCode($parameterVariable); $compilationContext->backend->assignDouble($parameterVariable, $compiledExpression->getCode(), $compilationContext); - $this->_temporalVariables[] = $parameterVariable; + $this->temporalVariables[] = $parameterVariable; $types[] = $compiledExpression->getType(); break; @@ -384,7 +384,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo $params[] = $compilationContext->backend->getVariableCode($parameterVariable); $compilationContext->backend->assignBool($parameterVariable, $value, $compilationContext); - $this->_temporalVariables[] = $parameterVariable; + $this->temporalVariables[] = $parameterVariable; $types[] = $compiledExpression->getType(); $dynamicTypes[] = $compiledExpression->getType(); break; @@ -393,8 +393,16 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo case 'string': case 'istring': $parameterVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression); - $compilationContext->backend->assignString($parameterVariable, Utils::addSlashes($compiledExpression->getCode()), $compilationContext, true, 'ZEPHIR_TEMP_PARAM_COPY'); - $this->_temporalVariables[] = $parameterVariable; + + $compilationContext->backend->assignString( + $parameterVariable, + add_slashes($compiledExpression->getCode()), + $compilationContext, + true, + 'ZEPHIR_TEMP_PARAM_COPY' + ); + + $this->temporalVariables[] = $parameterVariable; /* ZE3 copies strings */ if ($compilationContext->backend->getName() == 'ZendEngine2') { $mustCheck[] = $parameterVariable->getName(); @@ -422,7 +430,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo $parameterTempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext); $params[] = $compilationContext->backend->getVariableCode($parameterTempVariable); $compilationContext->backend->assignLong($parameterTempVariable, $parameterVariable, $compilationContext); - $this->_temporalVariables[] = $parameterTempVariable; + $this->temporalVariables[] = $parameterTempVariable; $types[] = $parameterVariable->getType(); $dynamicTypes[] = $parameterVariable->getType(); break; @@ -431,7 +439,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo $parameterTempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext); $compilationContext->backend->assignDouble($parameterTempVariable, $parameterVariable, $compilationContext); $params[] = $compilationContext->backend->getVariableCode($parameterTempVariable); - $this->_temporalVariables[] = $parameterTempVariable; + $this->temporalVariables[] = $parameterTempVariable; $types[] = $parameterVariable->getType(); $dynamicTypes[] = $parameterVariable->getType(); break; @@ -475,9 +483,9 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo } } - $this->_resolvedTypes = $types; - $this->_resolvedDynamicTypes = $dynamicTypes; - $this->_mustCheckForCopy = $mustCheck; + $this->resolvedTypes = $types; + $this->resolvedDynamicTypes = $dynamicTypes; + $this->mustCheckForCopy = $mustCheck; return $params; } @@ -515,7 +523,7 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi case 'long': $parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext, true); $compilationContext->backend->assignLong($parameterVariable, $compiledExpression->getCode(), $compilationContext); - $this->_temporalVariables[] = $parameterVariable; + $this->temporalVariables[] = $parameterVariable; $params[] = '&' . $parameterVariable->getName(); $types[] = $parameterVariable->getType(); $dynamicTypes[] = $parameterVariable->getType(); @@ -528,9 +536,15 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi } else { $parameterVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression); } - $compilationContext->backend->assignString($parameterVariable, Utils::addSlashes($compiledExpression->getCode()), $compilationContext, true, false); + $compilationContext->backend->assignString( + $parameterVariable, + add_slashes($compiledExpression->getCode()), + $compilationContext, + true, + false + ); - $this->_temporalVariables[] = $parameterVariable; + $this->temporalVariables[] = $parameterVariable; $params[] = '&' . $parameterVariable->getName(); $types[] = $parameterVariable->getType(); $dynamicTypes[] = $parameterVariable->getType(); @@ -539,7 +553,7 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi case 'double': $parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext, true); $codePrinter->output('ZVAL_DOUBLE(&' . $parameterVariable->getName() . ', ' . $compiledExpression->getCode() . ');'); - $this->_temporalVariables[] = $parameterVariable; + $this->temporalVariables[] = $parameterVariable; $params[] = '&' . $parameterVariable->getName(); $types[] = $parameterVariable->getType(); $dynamicTypes[] = $parameterVariable->getType(); @@ -567,8 +581,16 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi } else { $parameterVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression); } - $compilationContext->backend->assignString($parameterVariable, Utils::addSlashes($compiledExpression->getCode()), $compilationContext, true, false); - $this->_temporalVariables[] = $parameterVariable; + + $compilationContext->backend->assignString( + $parameterVariable, + add_slashes($compiledExpression->getCode()), + $compilationContext, + true, + false + ); + + $this->temporalVariables[] = $parameterVariable; $params[] = '&' . $parameterVariable->getName(); $types[] = $parameterVariable->getType(); $dynamicTypes[] = $parameterVariable->getType(); @@ -593,7 +615,7 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi $params[] = '&' . $parameterTempVariable->getName(); $types[] = $parameterTempVariable->getType(); $dynamicTypes[] = $parameterTempVariable->getType(); - $this->_temporalVariables[] = $parameterTempVariable; + $this->temporalVariables[] = $parameterTempVariable; break; case 'char': @@ -605,7 +627,7 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi $parameterVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression); $codePrinter->output('ZVAL_STRINGL(&' . $parameterVariable->getName() . ', &' . $compiledExpression->getCode() . ', 1);'); } - $this->_temporalVariables[] = $parameterVariable; + $this->temporalVariables[] = $parameterVariable; $params[] = '&' . $parameterVariable->getName(); $types[] = $parameterVariable->getType(); $dynamicTypes[] = $parameterVariable->getType(); @@ -617,7 +639,7 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi $params[] = '&' . $parameterTempVariable->getName(); $types[] = $parameterTempVariable->getType(); $dynamicTypes[] = $parameterTempVariable->getType(); - $this->_temporalVariables[] = $parameterTempVariable; + $this->temporalVariables[] = $parameterTempVariable; break; case 'bool': @@ -646,8 +668,8 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi } } - $this->_resolvedTypes = $types; - $this->_resolvedDynamicTypes = $dynamicTypes; + $this->resolvedTypes = $types; + $this->resolvedDynamicTypes = $dynamicTypes; return $params; } @@ -706,7 +728,7 @@ public function checkTempParameters(CompilationContext $compilationContext) */ public function getResolvedTypes() { - return $this->_resolvedTypes; + return $this->resolvedTypes; } /** @@ -716,7 +738,7 @@ public function getResolvedTypes() */ public function getResolvedDynamicTypes() { - return $this->_resolvedDynamicTypes; + return $this->resolvedDynamicTypes; } /** @@ -726,7 +748,7 @@ public function getResolvedDynamicTypes() */ public function getTemporalVariables() { - return $this->_temporalVariables; + return $this->temporalVariables; } /** @@ -736,6 +758,6 @@ public function getTemporalVariables() */ public function getMustCheckForCopyVariables() { - return $this->_mustCheckForCopy; + return $this->mustCheckForCopy; } } diff --git a/Library/ClassConstant.php b/Library/ClassConstant.php index 3c473a0288..fd20d9bfed 100644 --- a/Library/ClassConstant.php +++ b/Library/ClassConstant.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index ab1da40922..63175982aa 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -1,21 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; @@ -24,116 +16,76 @@ use Zephir\Compiler\CompilerException; /** - * ClassDefinition + * Zephir\ClassDefinition + * + * Represents a class/interface and their properties and methods. * - * Represents a class/interface and their properties and methods + * @package Zephir */ class ClassDefinition { - /** - * @var string - */ + /** @var string */ protected $namespace; - /** - * @var string - */ + /** @var string */ protected $name; - /** - * @var string - */ + /** @var string */ protected $shortName; - /** - * @var string - */ + /** @var string */ protected $type = 'class'; - /** - * @var string - */ + /** @var string */ protected $extendsClass; - /** - * @var array - */ + /** @var array */ protected $interfaces; - /** - * @var bool - */ + /** @var bool */ protected $final; - /** - * @var bool - */ + /** @var bool */ protected $abstract; - /** - * @var bool - */ + /** @var bool */ protected $external = false; - /** - * @var ClassDefinition - */ + /** @var ClassDefinition */ protected $extendsClassDefinition; - /** - * @var ClassDefinition[] - */ + /** @var ClassDefinition[] */ protected $implementedInterfaceDefinitions; - /** - * @var ClassProperty[] - */ - protected $properties = array(); + /** @var ClassProperty[] */ + protected $properties = []; - /** - * @var ClassConstant[] - */ - protected $constants = array(); + /** @var ClassConstant[] */ + protected $constants = []; - /** - * @var ClassMethod[] - */ - protected $methods = array(); + /** @var ClassMethod[] */ + protected $methods = []; - /** - * @var string - */ + /** @var string */ protected $docBlock; - /** - * @var Docblock - */ + /** @var Docblock */ protected $parsedDocblock; - /** - * @var int - */ + /** @var int */ protected $dependencyRank = 0; - /** - * @var array - */ + /** @var array */ protected $originalNode; - /** - * @var EventsManager - */ + /** @var EventsManager */ protected $eventsManager; - /** - * @var bool - */ + /** @var bool */ protected $isBundled = false; - /** - * @var AliasManager - */ - protected $_aliasManager = null; + /** @var AliasManager */ + protected $aliasManager = null; /** * Whether the constructor was generated by zephir @@ -142,17 +94,15 @@ class ClassDefinition */ protected $isGeneratedConstructor = false; - /** - * @var Compiler - */ + /** @var Compiler */ protected $compiler; /** * ClassDefinition * - * @param string $namespace - * @param string $name - * @param string $shortName + * @param string $namespace + * @param string $name + * @param string|null $shortName */ public function __construct($namespace, $name, $shortName = null) { @@ -990,7 +940,7 @@ public function addInitMethod(StatementsBlock $statementsBlock) $classMethod = new ClassMethod( $this, - array('internal'), + ['internal'], 'zephir_init_properties_' . $initClassName, null, $statementsBlock @@ -1290,161 +1240,109 @@ public function compile(CompilationContext $compilationContext) } /** - * Create argument info + * Specifying Argument Information */ foreach ($methods as $method) { - $parameters = $method->getParameters(); - $argInfoName = 'arginfo_' . strtolower($this->getCNamespace() . '_' . $this->getName() . '_' . $method->getName()); - - if ($this->compiler->backend->isZE3() && $method->hasReturnTypes()) { - if (array_key_exists('object', $method->getReturnTypes())) { - $class = 'NULL'; - - if (count($method->getReturnClassTypes()) == 1) { - $class = Utils::escapeClassName($compilationContext->getFullName(key($method->getReturnClassTypes()))); - } - - $codePrinter->output('#ifdef ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX'); - $codePrinter->output( - 'ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(' . $argInfoName . ', 0, ' . - $method->getNumberOfRequiredParameters() . ', ' . - $class . ', ' . ($method->areReturnTypesNullCompatible() ? 1 : 0) . ')' - ); - $codePrinter->output('#else'); - $codePrinter->output( - 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(' . $argInfoName . ', 0, ' . - $method->getNumberOfRequiredParameters() . ', ' . - 'NULL, "' . $class . '", ' . ($method->areReturnTypesNullCompatible() ? 1 : 0) . ')' - ); - $codePrinter->output('#endif'); - } else { - $type = 'IS_NULL'; - - if ($method->areReturnTypesIntCompatible()) { - $type = 'IS_LONG'; - } - if ($method->areReturnTypesDoubleCompatible()) { - $type = 'IS_DOUBLE'; - } - if ($method->areReturnTypesBoolCompatible()) { - $type = '_IS_BOOL'; - } - if ($method->areReturnTypesStringCompatible()) { - $type = 'IS_STRING'; - } + $argInfo = new ArgInfoDefinition( + $method->getArgInfoName($this), + $method, + $codePrinter, + $compilationContext + ); - $codePrinter->output('#ifdef ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX'); - $codePrinter->output( - 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(' . $argInfoName . ', 0, ' . - $method->getNumberOfRequiredParameters() . ', ' . - $type . ', ' . ($method->areReturnTypesNullCompatible() ? 1 : 0) . ')' - ); - $codePrinter->output('#else'); - $codePrinter->output( - 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(' . $argInfoName . ', 0, ' . - $method->getNumberOfRequiredParameters() . ', ' . - $type . ', NULL, ' . ($method->areReturnTypesNullCompatible() ? 1 : 0) . ')' - ); - $codePrinter->output('#endif'); - } + $argInfo->setBooleanDefinition($this->compiler->backend->isZE3() ? '_IS_BOOL' : 'IS_BOOL'); + $argInfo->setRichFormat($this->compiler->backend->isZE3()); - if ($parameters == null || !count($parameters->getParameters())) { - $codePrinter->output('ZEND_END_ARG_INFO()'); - $codePrinter->outputBlankLine(); - } - } elseif ($parameters != null && count($parameters->getParameters())) { - $codePrinter->output( - 'ZEND_BEGIN_ARG_INFO_EX(' . $argInfoName . ', 0, 0, ' . - $method->getNumberOfRequiredParameters() . ')' - ); - } - - if ($parameters != null && count($parameters->getParameters())) { - foreach ($parameters->getParameters() as $parameter) { - switch (($this->compiler->backend->isZE3() ? '3:' : '2:') . $parameter['data-type']) { - case '2:array': - case '3:array': - $codePrinter->output("\t" . 'ZEND_ARG_ARRAY_INFO(' . (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . $parameter['name'] . ', ' . (isset($parameter['default']) ? 1 : 0) . ')'); - break; - - case '2:variable': - case '3:variable': - if (isset($parameter['cast'])) { - switch ($parameter['cast']['type']) { - case 'variable': - $value = $parameter['cast']['value']; - $codePrinter->output("\t" . 'ZEND_ARG_OBJ_INFO(' . (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . $parameter['name'] . ', ' . Utils::escapeClassName($compilationContext->getFullName($value)) . ', ' . (isset($parameter['default']) ? 1 : 0) . ')'); - break; - - default: - throw new Exception('Unexpected exception'); - } - } else { - $codePrinter->output("\t" . 'ZEND_ARG_INFO(' . (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . $parameter['name'] . ')'); - } - break; - - case '3:bool': - case '3:boolean': - $codePrinter->output("\t" . 'ZEND_ARG_TYPE_INFO(' . (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . $parameter['name'] . ', ' . ($this->compiler->backend->isZE3() ? '_IS_BOOL' : 'IS_BOOL') . ', ' . (isset($parameter['default']) ? 1 : 0) . ')'); - break; - - case '3:uchar': - case '3:int': - case '3:uint': - case '3:long': - case '3:ulong': - $codePrinter->output("\t" . 'ZEND_ARG_TYPE_INFO(' . (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . $parameter['name'] . ', IS_LONG, ' . (isset($parameter['default']) ? 1 : 0) . ')'); - break; - - case '3:double': - $codePrinter->output("\t" . 'ZEND_ARG_TYPE_INFO(' . (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . $parameter['name'] . ', IS_DOUBLE, ' . (isset($parameter['default']) ? 1 : 0) . ')'); - break; - - case '3:char': - case '3:string': - $codePrinter->output("\t" . 'ZEND_ARG_TYPE_INFO(' . (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . $parameter['name'] . ', IS_STRING, ' . (isset($parameter['default']) ? 1 : 0) . ')'); - break; - - default: - $codePrinter->output("\t" . 'ZEND_ARG_INFO(' . (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . $parameter['name'] . ')'); - break; - } - } - $codePrinter->output('ZEND_END_ARG_INFO()'); - $codePrinter->outputBlankLine(); - } + $argInfo->render(); } if (count($methods)) { - $codePrinter->output('ZEPHIR_INIT_FUNCS(' . strtolower($this->getCNamespace() . '_' . $this->getName()) . '_method_entry) {'); + $codePrinter->output( + sprintf( + 'ZEPHIR_INIT_FUNCS(%s_%s_method_entry) {', + strtolower($this->getCNamespace()), + strtolower($this->getName()) + ) + ); + foreach ($methods as $method) { if ($this->getType() == 'class') { if (!$method->isInternal()) { - if (($this->compiler->backend->isZE3() && $method->hasReturnTypes()) || $method->hasParameters()) { - $codePrinter->output("\t" . 'PHP_ME(' . $this->getCNamespace() . '_' . $this->getName() . ', ' . $method->getName() . ', arginfo_' . strtolower($this->getCNamespace() . '_' . $this->getName() . '_' . $method->getName()) . ', ' . $method->getModifiers() . ')'); + $richFormat = $this->compiler->backend->isZE3() && + $method->isReturnTypesHintDetermined() && + $method->areReturnTypesCompatible(); + + if ($richFormat || $method->hasParameters()) { + $codePrinter->output( + sprintf( + "\tPHP_ME(%s_%s, %s, %s, %s)", + $this->getCNamespace(), + $this->getName(), + $method->getName(), + $method->getArgInfoName($this), + $method->getModifiers() + ) + ); } else { - $codePrinter->output("\t" . 'PHP_ME(' . $this->getCNamespace() . '_' . $this->getName() . ', ' . $method->getName() . ', NULL, ' . $method->getModifiers() . ')'); + $codePrinter->output( + sprintf( + "\tPHP_ME(%s_%s, %s, NULL, %s)", + $this->getCNamespace(), + $this->getName(), + $method->getName(), + $method->getModifiers() + ) + ); } } } else { + $richFormat = $this->compiler->backend->isZE3() && + $method->isReturnTypesHintDetermined() && + $method->areReturnTypesCompatible(); + if ($method->isStatic()) { - if (($this->compiler->backend->isZE3() && $method->hasReturnTypes()) || $method->hasParameters()) { - $codePrinter->output("\t" . 'ZEND_FENTRY(' . $method->getName() . ', NULL, arginfo_' . strtolower($this->getCNamespace() . '_' . $this->getName() . '_' . $method->getName()) . ', ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC)'); + if ($richFormat || $method->hasParameters()) { + $codePrinter->output( + sprintf( + "\tZEND_FENTRY(%s, NULL, %s, ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC)", + $method->getName(), + $method->getArgInfoName($this) + ) + ); } else { - $codePrinter->output("\t" . 'ZEND_FENTRY(' . $method->getName() . ', NULL, NULL, ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC)'); + $codePrinter->output( + sprintf( + "\tZEND_FENTRY(%s, NULL, NULL, ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_PUBLIC)", + $method->getName() + ) + ); } } else { - if (($this->compiler->backend->isZE3() && $method->hasReturnTypes()) || $method->hasParameters()) { - $codePrinter->output("\t" . 'PHP_ABSTRACT_ME(' . $this->getCNamespace() . '_' . $this->getName() . ', ' . $method->getName() . ', arginfo_' . strtolower($this->getCNamespace() . '_' . $this->getName() . '_' . $method->getName()) . ')'); + if ($richFormat || $method->hasParameters()) { + $codePrinter->output( + sprintf( + "\tPHP_ABSTRACT_ME(%s_%s, %s, %s)", + $this->getCNamespace(), + $this->getName(), + $method->getName(), + $method->getArgInfoName($this) + ) + ); } else { - $codePrinter->output("\t" . 'PHP_ABSTRACT_ME(' . $this->getCNamespace() . '_' . $this->getName() . ', ' . $method->getName() . ', NULL)'); + $codePrinter->output( + sprintf( + "\tPHP_ABSTRACT_ME(%s_%s, %s, NULL)", + $this->getCNamespace(), + $this->getName(), + $method->getName() + ) + ); } } } } $codePrinter->output("\t" . 'PHP_FE_END'); - $codePrinter->output('};'); + $codePrinter->output('};'); // ZEPHIR_INIT_FUNCS } $compilationContext->headerPrinter = $codePrinter; @@ -1455,7 +1353,7 @@ public function compile(CompilationContext $compilationContext) */ public function getAliasManager() { - return $this->_aliasManager; + return $this->aliasManager; } /** @@ -1463,7 +1361,7 @@ public function getAliasManager() */ public function setAliasManager(AliasManager $aliasManager) { - $this->_aliasManager = $aliasManager; + $this->aliasManager = $aliasManager; } /** @@ -1850,7 +1748,7 @@ public function getClassEntryByClassName($className, CompilationContext $compila if (!$check) { throw new CompilerException('Unknown class entry for "' . $className . '"'); } else { - $classEntry = $compilationContext->backend->fetchClassEntry(Utils::escapeClassName(strtolower($className))); + $classEntry = $compilationContext->backend->fetchClassEntry(escape_class(strtolower($className))); } } @@ -1892,9 +1790,12 @@ public static function buildFromReflection(\ReflectionClass $class) $parameters[] = $params; } - $classMethod = new ClassMethod($classDefinition, array(), $method->getName(), new ClassMethodParameters( - $parameters - )); + $classMethod = new ClassMethod( + $classDefinition, + [], + $method->getName(), + new ClassMethodParameters($parameters) + ); $classMethod->setIsStatic($method->isStatic()); $classMethod->setIsBundled(true); $classDefinition->addMethod($classMethod); diff --git a/Library/ClassDefinitionRuntime.php b/Library/ClassDefinitionRuntime.php index 88f4918a63..993afb7fef 100644 --- a/Library/ClassDefinitionRuntime.php +++ b/Library/ClassDefinitionRuntime.php @@ -1,21 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index c4b6cac71e..9084b6520d 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -1,21 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; @@ -34,31 +26,22 @@ */ class ClassMethod { - /** - * @var ClassDefinition - */ + /** @var ClassDefinition */ protected $classDefinition; - /** - * @var array - */ + /** @var array */ protected $visibility; - /** - * @var string - */ + /** @var string */ protected $name; - /** - * @var ClassMethodParameters - */ + /** @var ClassMethodParameters|null */ protected $parameters; + /** @var StatementsBlock|null */ protected $statements; - /** - * @var string - */ + /** @var string|null */ protected $docblock; /** @@ -71,14 +54,14 @@ class ClassMethod * * @var array */ - protected $returnTypes = array(); + protected $returnTypes = []; /** * Raw-types returned by the method * * @var array */ - protected $returnTypesRaw = array(); + protected $returnTypesRaw = []; /** * Class type hints returned by the method @@ -141,11 +124,7 @@ class ClassMethod */ protected $isInitializer = false; - /** - * @var array|null - * - * @var boolean - */ + /** @var array|null */ protected $expression; /** @@ -169,20 +148,30 @@ class ClassMethod */ protected $callGathererPass; + public $optimizable = true; + /** * ClassMethod constructor * - * @param ClassDefinition $classDefinition - * @param array $visibility - * @param $name - * @param $parameters - * @param StatementsBlock $statements - * @param null $docblock - * @param null $returnType - * @param array $original - */ - public function __construct(ClassDefinition $classDefinition, array $visibility, $name, $parameters, StatementsBlock $statements = null, $docblock = null, $returnType = null, array $original = null) - { + * @param ClassDefinition $classDefinition + * @param array $visibility + * @param string $name + * @param ClassMethodParameters|null $parameters + * @param StatementsBlock|null $statements + * @param string|null $docblock + * @param array|null $returnType + * @param array|null $original + */ + public function __construct( + ClassDefinition $classDefinition, + array $visibility, + $name, + ClassMethodParameters $parameters = null, + StatementsBlock $statements = null, + $docblock = null, + array $returnType = null, + array $original = null + ) { $this->checkVisibility($visibility, $name, $original); $this->classDefinition = $classDefinition; @@ -196,35 +185,43 @@ public function __construct(ClassDefinition $classDefinition, array $visibility, $this->setReturnTypes($returnType); } - public function setReturnTypes($returnType) + public function setReturnTypes(array $returnType = null) { $this->returnTypesRaw = $returnType; + if ($returnType === null) { + return; + } if (isset($returnType['void']) && $returnType['void']) { $this->void = true; return; } - if (isset($returnType['list'])) { - $types = array(); - $castTypes = array(); - foreach ($returnType['list'] as $returnTypeItem) { - if (isset($returnTypeItem['cast'])) { - if (isset($returnTypeItem['cast']['collection'])) { - continue; - } - $castTypes[$returnTypeItem['cast']['value']] = $returnTypeItem['cast']['value']; - } else { - $types[$returnTypeItem['data-type']] = $returnTypeItem; + if (!isset($returnType['list'])) { + return; + } + + $types = []; + $castTypes = []; + + foreach ($returnType['list'] as $returnTypeItem) { + if (isset($returnTypeItem['cast'])) { + if (isset($returnTypeItem['cast']['collection'])) { + continue; } + $castTypes[$returnTypeItem['cast']['value']] = $returnTypeItem['cast']['value']; + } else { + $types[$returnTypeItem['data-type']] = $returnTypeItem; } - if (count($castTypes)) { - $types['object'] = array(); - $this->returnClassTypes = $castTypes; - } - if (count($types)) { - $this->returnTypes = $types; - } + } + + if (count($castTypes)) { + $types['object'] = []; + $this->returnClassTypes = $castTypes; + } + + if (count($types)) { + $this->returnTypes = $types; } } @@ -427,8 +424,9 @@ public function setupOptimized(CompilationContext $compilationContext) $optimizedMethod->setReturnTypes($this->returnTypes); $classDefinition->addMethod($optimizedMethod); } + + return $this; } - public $optimizable = true; public function getOptimizedMethod() { @@ -1226,11 +1224,21 @@ public function assignDefaultValue(array $parameter, CompilationContext $compila case 'string': $compilationContext->backend->initVar($paramVariable, $compilationContext); - $compilationContext->backend->assignString($paramVariable, Utils::addSlashes($parameter['default']['value'], true), $compilationContext); + $compilationContext->backend->assignString( + $paramVariable, + add_slashes($parameter['default']['value']), + $compilationContext + ); break; default: - throw new CompilerException("Default parameter value type: " . $parameter['default']['type'] . " cannot be assigned to variable(string)", $parameter); + throw new CompilerException( + sprintf( + 'Default parameter value type: %s cannot be assigned to variable(string)', + $parameter['default']['type'] + ), + $parameter + ); } break; @@ -1294,7 +1302,11 @@ public function assignDefaultValue(array $parameter, CompilationContext $compila $compilationContext->symbolTable->mustGrownStack(true); $compilationContext->headersManager->add('kernel/memory'); $compilationContext->backend->initVar($symbolVariable, $compilationContext); - $compilationContext->backend->assignString($paramVariable, Utils::addSlashes($parameter['default']['value'], true), $compilationContext); + $compilationContext->backend->assignString( + $paramVariable, + add_slashes($parameter['default']['value']), + $compilationContext + ); break; case 'bool': @@ -1658,7 +1670,7 @@ public function compile(CompilationContext $compilationContext) /** * Assuming they're initialized */ - $symbolParam->setIsInitialized(true, $compilationContext, $parameter); + $symbolParam->setIsInitialized(true, $compilationContext); /** * Initialize auxiliary parameter zvals to null @@ -2062,7 +2074,10 @@ public function compile(CompilationContext $compilationContext) * If a method has return-type hints we need to ensure the last statement is a 'return' statement */ if ($this->hasReturnTypes()) { - throw new CompilerException('Reached end of the method without returning a valid type specified in the return-type hints', $this->expression['return-type']); + throw new CompilerException( + 'Reached end of the method without returning a valid type specified in the return-type hints', + $this->expression['return-type'] + ); } } } @@ -2150,4 +2165,101 @@ public function getInternalName() $classDefinition = $this->getClassDefinition(); return 'zep_' . $classDefinition->getCNamespace() . '_' . $classDefinition->getName() . '_' . $this->getName(); } + + /** + * Returns arginfo name for current method. + * + * @param ClassDefinition|null $classDefinition + * @return string + */ + public function getArgInfoName(ClassDefinition $classDefinition = null) + { + if ($classDefinition != null) { + return sprintf( + 'arginfo_%s_%s_%s', + strtolower($classDefinition->getCNamespace()), + strtolower($classDefinition->getName()), + strtolower($this->getName()) + ); + } + + return sprintf('arginfo_%s', strtolower($this->getInternalName())); + } + + /** + * Is method have determined return type hint. + * + * This method is used to generate: + * + * - ZEND_BEGIN_ARG_INFO_EX + * - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX + * + * Examples: + * + * - FALSE: function foo() -> void; + * - TRUE: function foo() -> null; + * - TRUE: function foo() -> bool|string|..; + * - TRUE: function foo() -> <\stdClass>; + * - FALSE: function foo(); + * - FALSE: function foo() -> var; + * - FALSE: function foo() -> resource|callable; + * + * @return bool + */ + public function isReturnTypesHintDetermined() + { + if (count($this->returnTypes) == 0 || $this->isVoid()) { + return false; + } + + foreach ($this->returnTypes as $returnType => $definition) { + switch ($returnType) { + case 'variable': + case 'callable': + case 'resource': + return false; + } + + if (isset($definition['type']) && $definition['type'] === 'return-type-annotation') { + if ($this->areReturnTypesBoolCompatible() || + $this->areReturnTypesDoubleCompatible() || + $this->areReturnTypesIntCompatible() || + $this->areReturnTypesNullCompatible() || + $this->areReturnTypesStringCompatible() || + array_key_exists('array', $this->getReturnTypes()) + ) { + continue; + } + + /** + * @todo Probable we should detect return type more more carefully. + * It is hard to process return type from the annotations at this time. + * Thus we just return false here. + */ + return false; + } + } + + return true; + } + + /** + * Checks if the method have compatible return types. + * + * @return bool + */ + public function areReturnTypesCompatible() + { + // null | T1 | T2 + if (count($this->returnTypes) > 2) { + return false; + } + + // T1 | T2 + if (count($this->returnTypes) == 2 && !isset($this->returnTypes['null'])) { + return false; + } + + return true; + } } diff --git a/Library/ClassMethodParameters.php b/Library/ClassMethodParameters.php index 5736b276b8..c1c335b02e 100644 --- a/Library/ClassMethodParameters.php +++ b/Library/ClassMethodParameters.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/ClassProperty.php b/Library/ClassProperty.php index 0686d4a5fc..65a2fb8b41 100644 --- a/Library/ClassProperty.php +++ b/Library/ClassProperty.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; @@ -332,6 +330,8 @@ public function compile(CompilationContext $compilationContext) /** * Removes all initialization statements related to this property + * + * @param array $statements */ protected function removeInitializationStatements(&$statements) { @@ -441,7 +441,15 @@ protected function declareProperty(CompilationContext $compilationContext, $type case Types::CHAR: case Types::STRING: - $codePrinter->output("zend_declare_property_string(" . $classEntry . ", SL(\"" . $this->getName() . "\"), \"" . Utils::addSlashes($value, true, $type) . "\", " . $this->getVisibilityAccessor() . " TSRMLS_CC);"); + $codePrinter->output( + sprintf( + 'zend_declare_property_string(%s, SL("%s"), "%s", %s TSRMLS_CC);', + $classEntry, + $this->getName(), + add_slashes($value), + $this->getVisibilityAccessor() + ) + ); break; case 'array': diff --git a/Library/Code/Builder/Struct.php b/Library/Code/Builder/Struct.php index 26e7def3c5..a2d4ca6c15 100644 --- a/Library/Code/Builder/Struct.php +++ b/Library/Code/Builder/Struct.php @@ -1,20 +1,18 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Code\Builder; /** - * Class Struct + * Zephir\Code\Builder\Struct * * Represents an internal extension global structure * @@ -22,24 +20,19 @@ */ class Struct { - /** - * @var string - */ - protected $_name; + /** @var string */ + protected $name; - /** - * @var string - */ - protected $_simpleName; + /** @var string */ + protected $simpleName; - /** - * @var array - */ - protected $_properties = array(); + /** @var array */ + protected $properties = []; /** * @param string $name * @param string $simpleName + * * @throws \InvalidArgumentException */ public function __construct($name, $simpleName) @@ -56,8 +49,8 @@ public function __construct($name, $simpleName) throw new \InvalidArgumentException('Struct name must not be empty'); } - $this->_name = $name; - $this->_simpleName = $simpleName; + $this->name = $name; + $this->simpleName = $simpleName; } /** @@ -79,11 +72,11 @@ public function addProperty($field, $global) throw new \InvalidArgumentException('Property name must be string'); } - if (isset($this->_properties[$field])) { + if (isset($this->properties[$field])) { throw new \InvalidArgumentException('Property was defined more than once'); } - $this->_properties[$field] = $this->convertToCType($global['type']); + $this->properties[$field] = $this->convertToCType($global['type']); } /** @@ -134,10 +127,10 @@ public function getCDefault($name, $global, $namespace) return ''; /* if ($global['default'] === true) { - return "\t" . $namespace . '_globals->' . $this->_simpleName . '.' . $name . ' = 1;'; + return "\t" . $namespace . '_globals->' . $this->simpleName . '.' . $name . ' = 1;'; } else { if ($global['default'] === false) { - return "\t" . $namespace . '_globals->' . $this->_simpleName . '.' . $name . ' = 0;'; + return "\t" . $namespace . '_globals->' . $this->simpleName . '.' . $name . ' = 0;'; } else { throw new \Exception('Invalid default type for boolean field "' . $name . '", it must be false/true'); } @@ -150,7 +143,7 @@ public function getCDefault($name, $global, $namespace) case 'long': case 'double': case 'hash': - return "\t" . $namespace . '_globals->' . $this->_simpleName . '.' . $name . ' = ' . $global['default'] . ';'; + return "\t" . $namespace . '_globals->' . $this->simpleName . '.' . $name . ' = ' . $global['default'] . ';'; default: throw new \Exception('Unknown global type: ' . $global['type']); @@ -162,13 +155,13 @@ public function getCDefault($name, $global, $namespace) */ public function __toString() { - $code = 'typedef struct '. $this->_name .' { '.PHP_EOL; + $code = 'typedef struct '. $this->name .' { '.PHP_EOL; - foreach ($this->_properties as $name => $type) { - $code .= T . $type . ' ' . $name . ';' . PHP_EOL; + foreach ($this->properties as $name => $type) { + $code .= sprintf("\t%s %s;%s", $type, $name, PHP_EOL); } - return $code . '} ' . substr($this->_name, 1) . ';' . PHP_EOL; + return $code . '} ' . substr($this->name, 1) . ';' . PHP_EOL; } /** @@ -180,7 +173,7 @@ public function getInitEntry($name, $global, $namespace) if (isset($global['ini-entry'])) { $iniEntry = $global['ini-entry']; } - $structName = $this->_simpleName . '.' . $name; + $structName = $this->simpleName . '.' . $name; if (!isset($iniEntry['name'])) { $iniName = $namespace . '.' . $structName; } else { diff --git a/Library/CodePrinter.php b/Library/CodePrinter.php index 8e56997a4b..2f2386cf0d 100644 --- a/Library/CodePrinter.php +++ b/Library/CodePrinter.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/Color.php b/Library/Color.php index ac074d9f4b..6cb371ad11 100644 --- a/Library/Color.php +++ b/Library/Color.php @@ -1,24 +1,24 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; /** - * Color + * Zephir\Color * * Allows to generate messages using colors on xterm, ddterm, linux, etc. * This class is based on Phalcon\Script available in Phalcon DevTools * licensed under New BSD license + * + * @package Zephir */ class Color { @@ -61,7 +61,7 @@ class Color /** * @var array Map of supported foreground colors */ - private static $_fg = array( + private static $fg = [ self::FG_BLACK => '0;30', self::FG_DARK_GRAY => '1;30', self::FG_RED => '0;31', @@ -78,12 +78,12 @@ class Color self::FG_LIGHT_CYAN => '1;36', self::FG_LIGHT_GRAY => '0;37', self::FG_WHITE => '1;37', - ); + ]; /** * @var array Map of supported background colors */ - private static $_bg = array( + private static $bg = [ self::BG_BLACK => '40', self::BG_RED => '41', self::BG_GREEN => '42', @@ -92,12 +92,12 @@ class Color self::BG_MAGENTA => '45', self::BG_CYAN => '46', self::BG_LIGHT_GRAY => '47', - ); + ]; /** * @var array Map of supported attributes */ - private static $_at = array( + private static $at = [ self::AT_NORMAL => '0', self::AT_BOLD => '1', self::AT_ITALIC => '3', @@ -107,18 +107,18 @@ class Color self::AT_REVERSE => '7', self::AT_NONDISP => '8', self::AT_STRIKE => '9', - ); + ]; /** * Supported terminals * * @var string */ - private static $_supportedShells = array( + private static $supportedShells = [ 'xterm' => true, 'xterm-256color' => true, 'xterm-color' => true, - ); + ]; /** * Identify if console supports colors @@ -130,12 +130,12 @@ public static function isSupportedShell() $flag = false; if (isset($_ENV['TERM'])) { - if (isset(self::$_supportedShells[$_ENV['TERM']])) { + if (isset(self::$supportedShells[$_ENV['TERM']])) { $flag = true; } } else { if (isset($_SERVER['TERM'])) { - if (isset(self::$_supportedShells[$_SERVER['TERM']])) { + if (isset(self::$supportedShells[$_SERVER['TERM']])) { $flag = true; } } @@ -165,18 +165,18 @@ public static function colorize($string, $fg = null, $at = null, $bg = null) $colored = ''; // Check if given foreground color is supported - if (isset(static::$_fg[$fg])) { - $colored .= "\033[" . static::$_fg[$fg] . "m"; + if (isset(static::$fg[$fg])) { + $colored .= "\033[" . static::$fg[$fg] . "m"; } // Check if given background color is supported - if (isset(static::$_bg[$bg])) { - $colored .= "\033[" . static::$_bg[$bg] . "m"; + if (isset(static::$bg[$bg])) { + $colored .= "\033[" . static::$bg[$bg] . "m"; } // Check if given attribute is supported - if (isset(static::$_at[$at])) { - $colored .= "\033[" . static::$_at[$at] . "m"; + if (isset(static::$at[$at])) { + $colored .= "\033[" . static::$at[$at] . "m"; } // Add string and end coloring diff --git a/Library/CommandArgumentParser.php b/Library/CommandArgumentParser.php index 95315ba674..05cf490615 100644 --- a/Library/CommandArgumentParser.php +++ b/Library/CommandArgumentParser.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir; diff --git a/Library/Commands/CommandAbstract.php b/Library/Commands/CommandAbstract.php index 94e977fc88..fc63edb772 100644 --- a/Library/Commands/CommandAbstract.php +++ b/Library/Commands/CommandAbstract.php @@ -1,34 +1,36 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ - namespace Zephir\Commands; +use Psr\Container\ContainerInterface; +use Zephir\CommandArgumentParser; +use Zephir\Compiler; use Zephir\Config; +use Zephir\Di\ContainerAwareTrait; +use Zephir\Di\InjectionAwareInterface; use Zephir\Logger; -use Zephir\Parser; -use Zephir\Compiler; -use Zephir\BaseBackend; -use Zephir\Exception\IllegalStateException; /** - * CommandAbstract + * Zephir\Commands\CommandAbstract * * Provides a superclass for any command. * * @package Zephir\Commands */ -abstract class CommandAbstract implements CommandInterface +abstract class CommandAbstract implements CommandInterface, InjectionAwareInterface { + use ContainerAwareTrait { + ContainerAwareTrait::__construct as protected __DiInject; + } + private $parameters = []; /** @@ -37,13 +39,22 @@ abstract class CommandAbstract implements CommandInterface */ private $commandsManager; + /** + * The Zephir base direcrory. + * @var string + */ + private $baseDir; + /** * CommandAbstract constructor. * - * @param Manager $commandsManager + * @param Manager $commandsManager + * @param ContainerInterface|null $container */ - public function __construct(Manager $commandsManager) + public function __construct(Manager $commandsManager, ContainerInterface $container = null) { + $this->__DiInject($container); + $this->commandsManager = $commandsManager; } @@ -93,7 +104,8 @@ public function parseArguments() if (count($_SERVER['argv']) > 2) { $commandArgs = array_slice($_SERVER['argv'], 2); - $parser = $this->getCommandsManager()->getCommandArgumentParser(); + /** @var CommandArgumentParser $parser */ + $parser = $this->getContainer()->get(CommandArgumentParser::class); $params = $parser->parseArgs(array_merge(['command'], $commandArgs)); } @@ -108,7 +120,9 @@ public function parseArguments() public function hasHelpOption() { $params = $this->parseArguments(); - $parser = $this->getCommandsManager()->getCommandArgumentParser(); + + /** @var CommandArgumentParser $parser */ + $parser = $this->getContainer()->get(CommandArgumentParser::class); return $parser->hasHelpOption($params); } @@ -116,29 +130,18 @@ public function hasHelpOption() /** * {@inheritdoc} * - * @param Config $config - * @param Logger $logger + * @param Config $config + * @param Logger $logger + * @return void */ public function execute(Config $config, Logger $logger) { - $params = $this->parseArguments(); - if ($this->hasHelpOption()) { echo $this->getSynopsis(); return; } - $backend = empty($params['backend']) ? BaseBackend::getActiveBackend() : $params['backend']; - $className = "Zephir\\Backends\\{$backend}\\Backend"; - - if (!class_exists($className)) { - throw new IllegalStateException("Backend {$backend} doesn't exist."); - } - - $backend = new $className($config); - - $parserManager = new Parser\Manager(new Parser(), $logger, $params); - $compiler = new Compiler($config, $logger, $backend, $parserManager); + $compiler = $this->container->get(Compiler::class); $command = $this->getCommand(); $compiler->$command($this); diff --git a/Library/Commands/CommandApi.php b/Library/Commands/CommandApi.php index ce2f31ea6c..5286b79c04 100644 --- a/Library/Commands/CommandApi.php +++ b/Library/Commands/CommandApi.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandBuild.php b/Library/Commands/CommandBuild.php index 682adccdf5..e65a5211c5 100644 --- a/Library/Commands/CommandBuild.php +++ b/Library/Commands/CommandBuild.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandBuildDev.php b/Library/Commands/CommandBuildDev.php index 609b9861ec..834e1b321f 100644 --- a/Library/Commands/CommandBuildDev.php +++ b/Library/Commands/CommandBuildDev.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandClean.php b/Library/Commands/CommandClean.php index 057d64d090..0c90c0e6ba 100644 --- a/Library/Commands/CommandClean.php +++ b/Library/Commands/CommandClean.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandCompile.php b/Library/Commands/CommandCompile.php index b7d2914a60..42b0024b32 100644 --- a/Library/Commands/CommandCompile.php +++ b/Library/Commands/CommandCompile.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandFullClean.php b/Library/Commands/CommandFullClean.php index 1d3f9fa64a..c761b063ea 100644 --- a/Library/Commands/CommandFullClean.php +++ b/Library/Commands/CommandFullClean.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandGenerate.php b/Library/Commands/CommandGenerate.php index 009297444d..0f6341ab05 100644 --- a/Library/Commands/CommandGenerate.php +++ b/Library/Commands/CommandGenerate.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandHelp.php b/Library/Commands/CommandHelp.php index 369236a901..db2d681d6c 100644 --- a/Library/Commands/CommandHelp.php +++ b/Library/Commands/CommandHelp.php @@ -1,21 +1,19 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; use Zephir\Config; use Zephir\Logger; -use Zephir\Compiler; +use Zephir\Version; /** * Zephir\Commands\CommandHelp @@ -69,11 +67,13 @@ public function execute(Config $config, Logger $logger) return fprintf(STDIN, $this->getSynopsis()); } + $version = $this->getContainer()->get(Version::class); + return fprintf( STDOUT, "%s\nZephir version %s\n\n%s\nAvailable commands:\n%s\n%s", $this->banner(), - Compiler::getCurrentVersion(), + $version, $this->usage(), $this->commands(), $this->options() diff --git a/Library/Commands/CommandInitialize.php b/Library/Commands/CommandInitialize.php index 6b3ff6e76e..b6f2e9b475 100644 --- a/Library/Commands/CommandInitialize.php +++ b/Library/Commands/CommandInitialize.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandInstall.php b/Library/Commands/CommandInstall.php index ce3eb4d799..b0be95ca4f 100644 --- a/Library/Commands/CommandInstall.php +++ b/Library/Commands/CommandInstall.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandInterface.php b/Library/Commands/CommandInterface.php index cc0e2e57b4..a8a900cde5 100644 --- a/Library/Commands/CommandInterface.php +++ b/Library/Commands/CommandInterface.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandStubs.php b/Library/Commands/CommandStubs.php index 5fc4743fdd..30bebd78c8 100644 --- a/Library/Commands/CommandStubs.php +++ b/Library/Commands/CommandStubs.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; diff --git a/Library/Commands/CommandVersion.php b/Library/Commands/CommandVersion.php index be3b974b7c..79aa0d80bc 100644 --- a/Library/Commands/CommandVersion.php +++ b/Library/Commands/CommandVersion.php @@ -1,21 +1,19 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; use Zephir\Config; use Zephir\Logger; -use Zephir\Compiler; +use Zephir\Version; /** * Zephir\Commands\CommandVersion @@ -69,6 +67,8 @@ public function execute(Config $config, Logger $logger) return; } - echo Compiler::getCurrentVersion(), PHP_EOL; + $version = $this->getContainer()->get(Version::class); + + echo $version, PHP_EOL; } } diff --git a/Library/Commands/Manager.php b/Library/Commands/Manager.php index 0585cbbdf2..ee8d6eee90 100644 --- a/Library/Commands/Manager.php +++ b/Library/Commands/Manager.php @@ -1,63 +1,62 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Commands; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; use ReflectionClass; use SplObjectStorage; -use RecursiveIteratorIterator; -use RecursiveDirectoryIterator; -use Zephir\CommandArgumentParser; -use Zephir\Exception\ValidationException; -use Zephir\Exception\OutOfBoundsException; +use Zephir\Di\ContainerAwareTrait; +use Zephir\Di\InjectionAwareInterface; +use Zephir\Environment; use Zephir\Exception\BadMethodCallException; +use Zephir\Exception\OutOfBoundsException; +use Zephir\Exception\ValidationException; /** * Zephir\Commands\Manager * * @package Zephir\Commands */ -class Manager extends SplObjectStorage +class Manager extends SplObjectStorage implements InjectionAwareInterface { - private $similarSounds = []; - - /** - * Command argument parser - * - * @var CommandArgumentParser - */ - private $argumentParser; - - /** - * Manager constructor. - */ - public function __construct() - { - $this->argumentParser = new CommandArgumentParser(); + use ContainerAwareTrait { + ContainerAwareTrait::__construct as protected __DiInject; } + private $similarSounds = []; + /** * Registers builtin commands. * * @return void + * + * @throws \ReflectionException */ public function registerBuiltinCommands() { - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__))); + /** @var Environment $environment */ + $environment = $this->container->get(Environment::class); + $environment->getPath(); + + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator( + $this->container->get(Environment::class)->getPath('Library/Commands') + )); + $iterator->rewind(); while ($iterator->valid()) { $fileInfo = $iterator->current(); + if ($fileInfo->isDir() || $fileInfo->getExtension() !== 'php') { $iterator->next(); continue; @@ -80,7 +79,9 @@ public function registerBuiltinCommands() continue; } - $command = $command->newInstanceArgs([$this]); + $command = $command->newInstanceArgs([$this, $this->container]); + + /** @var CommandAbstract $command */ $data = [ 'usage' => $command->getUsage(), 'description' => $command->getDescription(), @@ -106,16 +107,6 @@ public function getHash($object) return $object->getCommand(); } - /** - * Gets Command argument parser - * - * @return CommandArgumentParser - */ - public function getCommandArgumentParser() - { - return $this->argumentParser; - } - /** * {@inheritdoc} * @@ -153,8 +144,9 @@ public function detach($object) /** * Resolves and returns a compiller command. * - * @param string $action Action name + * @param string $action Action name. * @return CommandInterface + * * @throws OutOfBoundsException * @throws BadMethodCallException */ diff --git a/Library/CompilationContext.php b/Library/CompilationContext.php index 240a54db73..7bf87e8dea 100644 --- a/Library/CompilationContext.php +++ b/Library/CompilationContext.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; @@ -204,6 +202,6 @@ public function getFullName($className) $isFunction = $this->currentMethod && $this->currentMethod instanceof FunctionDefinition; $namespace = $isFunction ? $this->currentMethod->getNamespace() : $this->classDefinition->getNamespace(); - return Utils::getFullName($className, $namespace, $this->aliasManager); + return fqcn($className, $namespace, $this->aliasManager); } } diff --git a/Library/CompiledExpression.php b/Library/CompiledExpression.php index b9a6953a63..2048bc79e5 100644 --- a/Library/CompiledExpression.php +++ b/Library/CompiledExpression.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; @@ -142,7 +140,7 @@ public function resolve($result, CompilationContext $compilationContext) $compilationContext ); $compilationContext->codePrinter->output($code($tempVariable->getName())); - $tempVariable->setIsInitialized(true, $compilationContext, array()); + $tempVariable->setIsInitialized(true, $compilationContext); return $tempVariable->getName(); } return $code($result); diff --git a/Library/Compiler.php b/Library/Compiler.php index d3ec759cc8..8338dd1970 100644 --- a/Library/Compiler.php +++ b/Library/Compiler.php @@ -1,26 +1,26 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir; -use Zephir\Parser\Manager; -use Zephir\Parser\ParseException; use Zephir\Commands\CommandGenerate; use Zephir\Commands\CommandInterface; use Zephir\Compiler\CompilerException; -use Zephir\Fcall\FcallManagerInterface; +use Zephir\Di\ContainerAwareTrait; +use Zephir\Di\InjectionAwareInterface; use Zephir\Exception\IllegalStateException; +use Zephir\Fcall\FcallManagerInterface; use Zephir\FileSystem\HardDisk as FileSystem; +use Zephir\Parser\Manager; +use Zephir\Parser\ParseException; /** * Zephir\Compiler @@ -29,9 +29,11 @@ * * @package Zephir */ -class Compiler +class Compiler implements InjectionAwareInterface { - const VERSION = '0.11.1'; + use ContainerAwareTrait { + ContainerAwareTrait::__construct as protected __DiInject; + } public $parserCompiled = false; @@ -43,53 +45,53 @@ class Compiler /** * @var FunctionDefinition[] */ - public $functionDefinitions = array(); + public $functionDefinitions = []; /** * @var CompilerFile[] */ - protected $files = array(); + protected $files = []; /** * @var array|string[] */ - protected $anonymousFiles = array(); + protected $anonymousFiles = []; /** * Additional initializer code * used for static property initialization * @var array */ - protected $internalInitializers = array(); + protected $internalInitializers = []; /** * @var ClassDefinition[] */ - protected $definitions = array(); + protected $definitions = []; /** * @var array|string[] */ - protected $compiledFiles = array(); + protected $compiledFiles = []; /** * */ - protected $constants = array(); + protected $constants = []; /** * Extension globals * * @var array */ - protected $globals = array(); + protected $globals = []; /** * External dependencies * * @var array */ - protected $externalDependencies = array(); + protected $externalDependencies = []; /** * @var StringsManager @@ -114,22 +116,17 @@ class Compiler /** * @var \ReflectionClass[] */ - protected static $internalDefinitions = array(); + protected static $internalDefinitions = []; /** * @var boolean */ protected static $loadedPrototypes = false; - /** - * @var string - */ - protected static $currentVersion; - /** * @var array */ - protected $extraFiles = array(); + protected $extraFiles = []; /** * The Zephir Parser Manager @@ -142,18 +139,26 @@ class Compiler */ protected $fileSystem; + /** + * The Zephir base direcrory. + * @var string + */ + private $baseDir; + /** * Compiler constructor * - * @param Config $config - * @param Logger $logger + * @param Config $config + * @param Logger $logger * @param BaseBackend $backend - * @param Manager $manager + * @param Manager $manager * * @throws Exception */ public function __construct(Config $config, Logger $logger, BaseBackend $backend, Manager $manager) { + $this->__DiInject(); + $this->config = $config; $this->logger = $logger; $this->fileSystem = new FileSystem(); @@ -176,16 +181,19 @@ public function getParserManager() } /** - * Adds a function to the function definitions + * Adds a function to the function definitions. + * + * @param FunctionDefinition $func + * @param array $statement + * @return void * - * @param FunctionDefinition $func - * @param array $statement * @throws CompilerException */ public function addFunction(FunctionDefinition $func, $statement = null) { $funcName = strtolower($func->getInternalName()); if (isset($this->functionDefinitions[$funcName])) { + // @todo Cover by test throw new CompilerException( "Function '" . $func->getCompleteName() . "' was defined more than one time", $statement @@ -199,6 +207,7 @@ public function addFunction(FunctionDefinition $func, $statement = null) * Pre-compiles classes creating a CompilerFile definition * * @param string $filePath + * * @throws CompilerException * @throws IllegalStateException * @throws ParseException @@ -217,7 +226,7 @@ protected function preCompile($filePath) return ucfirst($i); }, explode('\\', $className))); - $this->files[$className] = new CompilerFile($className, $filePath, $this->config, $this->logger, $this->backend); + $this->files[$className] = new CompilerFile($className, $filePath, $this->config, $this->logger); $this->files[$className]->preCompile($this); $this->definitions[$className] = $this->files[$className]->getClassDefinition(); @@ -240,7 +249,7 @@ protected function recursivePreCompile($path) /** * Pre compile all files */ - $files = array(); + $files = []; $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST @@ -513,11 +522,11 @@ protected function loadConstantsSources($constantsSources) foreach (file($constantsSource) as $line) { if (preg_match('/^\#define[ \t]+([A-Z0-9\_]+)[ \t]+([0-9]+)/', $line, $matches)) { - $this->constants[$matches[1]] = array('int', $matches[2]); + $this->constants[$matches[1]] = ['int', $matches[2]]; continue; } if (preg_match('/^\#define[ \t]+([A-Z0-9\_]+)[ \t]+(\'(.){1}\')/', $line, $matches)) { - $this->constants[$matches[1]] = array('char', $matches[3]); + $this->constants[$matches[1]] = ['char', $matches[3]]; } } } @@ -581,38 +590,6 @@ public function getExtensionGlobal($name) return $this->globals[$name]; } - /** - * Returns the current version + the ident if available - * - * @return string - */ - public static function getCurrentVersion() - { - $version = '$Id$'; - if (strlen($version) != 4) { - return self::VERSION . '-' . substr($version, 0, 10); - } - - if (!Utils::isWindows()) { - if (self::$currentVersion === null) { - if (file_exists(__DIR__ . '/../.git')) { - exec('cd ' . __DIR__ . '/.. && git log --format="%H" -n 1', $xversion); - if (isset($xversion[0]) && strlen($xversion[0]) > 10) { - self::$currentVersion = substr($xversion[0], 0, 10); - } else { - self::$currentVersion = false; - } - } - } - - if (self::$currentVersion) { - return self::VERSION . '-' . self::$currentVersion; - } - } - - return self::VERSION; - } - /** * Returns GCC flags for current compilation * @@ -621,7 +598,7 @@ public static function getCurrentVersion() */ public function getGccFlags($development = false) { - if (!Utils::isWindows()) { + if (!$this->environment->isWindows()) { $gccFlags = getenv('CFLAGS'); if (!is_string($gccFlags)) { if (!$development) { @@ -646,9 +623,9 @@ public function getGccFlags($development = false) */ public function getPhpIncludeDirs() { - $version = self::getCurrentVersion(); + $version = $this->container->get(Version::class); - if (!Utils::isWindows()) { + if (!$this->environment->isWindows()) { $this->fileSystem->system('php-config --includes', 'stdout', $version . '/php-includes'); } @@ -660,8 +637,8 @@ public function getPhpIncludeDirs() */ public function preCompileHeaders() { - if (!Utils::isWindows()) { - $version = self::getCurrentVersion(); + if (!$this->environment->isWindows()) { + $version = $this->container->get(Version::class); $phpIncludes = $this->getPhpIncludeDirs(); foreach (new \DirectoryIterator('ext/kernel') as $file) { @@ -770,47 +747,6 @@ public function generate(CommandInterface $command) } } - /** - * Check if there are module/request/global destructors - */ - $includes = ''; - $destructors = $this->config->get('destructors'); - if (is_array($destructors)) { - $invokeRequestDestructors = $this->processCodeInjection($destructors, 'request'); - $includes .= PHP_EOL . $invokeRequestDestructors[0]; - $reqDestructors = $invokeRequestDestructors[1]; - - $invokePostRequestDestructors = $this->processCodeInjection($destructors, 'post-request'); - $includes .= PHP_EOL . $invokePostRequestDestructors[0]; - $prqDestructors = $invokePostRequestDestructors[1]; - - $invokeModuleDestructors = $this->processCodeInjection($destructors, 'module'); - $includes .= PHP_EOL . $invokeModuleDestructors[0]; - $modDestructors = $invokeModuleDestructors[1]; - - $invokeGlobalsDestructors = $this->processCodeInjection($destructors, 'globals'); - $includes .= PHP_EOL . $invokeGlobalsDestructors[0]; - $glbDestructors = $invokeGlobalsDestructors[1]; - } - - /** - * Check if there are module/request/global initializers - */ - $initializers = $this->config->get('initializers'); - if (is_array($initializers)) { - $invokeRequestInitializers = $this->processCodeInjection($initializers, 'request'); - $includes .= PHP_EOL . $invokeRequestInitializers[0]; - $reqInitializers = $invokeRequestInitializers[1]; - - $invokeModuleInitializers = $this->processCodeInjection($initializers, 'module'); - $includes .= PHP_EOL . $invokeModuleInitializers[0]; - $modInitializers = $invokeModuleInitializers[1]; - - $invokeGlobalsInitializers = $this->processCodeInjection($initializers, 'globals'); - $includes .= PHP_EOL . $invokeGlobalsInitializers[0]; - $glbInitializers = $invokeGlobalsInitializers[1]; - } - /** * Round 1. pre-compile all files in memory */ @@ -831,8 +767,8 @@ public function generate(CommandInterface $command) /** * Sort the files by dependency ranking */ - $files = array(); - $rankedFiles = array(); + $files = []; + $rankedFiles = []; $this->calculateDependencies($this->files); foreach ($this->files as $rankFile) { @@ -866,7 +802,7 @@ public function generate(CommandInterface $command) * Load function optimizers */ if (self::$loadedPrototypes === false) { - FunctionCall::addOptimizerDir(ZEPHIRPATH . '/Library/Optimizers/FunctionCall'); + FunctionCall::addOptimizerDir($this->environment->getPath('Library/Optimizers/FunctionCall')); $optimizerDirs = $this->config->get('optimizer-dirs'); if (is_array($optimizerDirs)) { @@ -875,17 +811,24 @@ public function generate(CommandInterface $command) } } - if (is_dir(ZEPHIRPATH . '/prototypes') && is_readable(ZEPHIRPATH . '/prototypes')) { + $prototypes = $this->environment->getPrototypesPath(); + + if (is_dir($prototypes) && is_readable($prototypes)) { /** * Load additional extension prototypes * @var $file \DirectoryIterator */ - foreach (new \DirectoryIterator(ZEPHIRPATH . '/prototypes') as $file) { - if (!$file->isDir()) { - $extension = str_replace('.php', '', $file); - if (!extension_loaded($extension)) { - require_once $file->getRealPath(); - } + foreach (new \DirectoryIterator($prototypes) as $file) { + if ($file->isDir() || $file->isDot()) { + continue; + } + + // Do not use $file->getRealPath() because it does not work inside phar + $realPath = $file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename(); + + $extension = $file->getBasename(".{$file->getExtension()}"); + if (!extension_loaded($extension)) { + require_once $realPath; } } } @@ -918,7 +861,7 @@ public function generate(CommandInterface $command) /** * Round 3. Compile all files to C sources */ - $files = array(); + $files = []; $hash = ""; foreach ($this->files as $compileFile) { @@ -929,7 +872,7 @@ public function generate(CommandInterface $command) $compileFile->compile($this, $this->stringManager); $compiledFile = $compileFile->getCompiledFile(); - $methods = array(); + $methods = []; $classDefinition = $compileFile->getClassDefinition(); foreach ($classDefinition->getMethods() as $method) { $methods[] = '[' . $method->getName() . ':' . join('-', $method->getVisibility()) . ']'; @@ -952,7 +895,7 @@ public function generate(CommandInterface $command) $compileFile->compile($this, $this->stringManager); $compiledFile = $compileFile->getCompiledFile(); - $methods = array(); + $methods = []; $classDefinition = $compileFile->getClassDefinition(); foreach ($classDefinition->getMethods() as $method) { $methods[] = '[' . $method->getName() . ':' . join('-', $method->getVisibility()) . ']'; @@ -973,7 +916,7 @@ public function generate(CommandInterface $command) if (is_array($extraSources)) { $this->extraFiles = $extraSources; } else { - $this->extraFiles = array(); + $this->extraFiles = []; } /** @@ -1001,7 +944,7 @@ public function generate(CommandInterface $command) $needConfigure |= $this->createProjectFiles($extensionName); $needConfigure |= $this->checkIfPhpized(); - $version = self::getCurrentVersion(); + $version = $this->container->get(Version::class); /** * When a new file is added or removed we need to run configure again @@ -1052,10 +995,10 @@ public function compile(CommandInterface $command, $development = false) $needConfigure = $this->generate($command); if ($needConfigure) { - if (Utils::isWindows()) { + if ($this->environment->isWindows()) { exec('cd ext && %PHP_DEVPACK%\\phpize --clean', $output, $exit); - $releaseFolder = Utils::resolveWindowsReleaseFolder(); + $releaseFolder = $this->environment->getWindowsReleaseDir(); if (file_exists($releaseFolder)) { exec('rd /s /q ' . $releaseFolder, $output, $exit); } @@ -1114,7 +1057,7 @@ public function compile(CommandInterface $command, $development = false) $currentDir = getcwd(); $this->logger->output('Compiling...'); - if (Utils::isWindows()) { + if ($this->environment->isWindows()) { exec( 'cd ext && nmake 2>' . $currentDir . '\compile-errors.log 1>' . $currentDir . '\compile.log', @@ -1146,6 +1089,8 @@ public function api(CommandInterface $command, $fromGenerate = false) } $documentator = new Documentation($this->files, $this->config, $this->logger, $command); + $documentator->setContainer($this->container); + $this->logger->output('Generating API into ' . $documentator->getOutputDirectory()); $documentator->build(); } @@ -1193,7 +1138,7 @@ public function install(CommandInterface $command, $development = false) @unlink("ext/modules/" . $namespace . ".so"); $this->compile($command, $development); - if (Utils::isWindows()) { + if ($this->environment->isWindows()) { $this->logger->output("Installation is not implemented for windows yet! Aborting!"); exit(); } @@ -1236,11 +1181,11 @@ public function test(CommandInterface $command) /** * Get global namespace */ - $namespace = $this->checkDirectory(); + $this->checkDirectory(); $this->logger->output('Running tests...'); - if (!Utils::isWindows()) { + if (!$this->environment->isWindows()) { system( 'export CC="gcc" && export CFLAGS="-O0 -g" && export NO_INTERACTION=1 && cd ext && make test', $exit @@ -1256,7 +1201,8 @@ public function test(CommandInterface $command) public function clean(CommandInterface $command) { $this->fileSystem->clean(); - if (Utils::isWindows()) { + + if ($this->environment->isWindows()) { system('cd ext && nmake clean-all'); } else { system('cd ext && make clean > /dev/null'); @@ -1271,7 +1217,7 @@ public function clean(CommandInterface $command) public function fullClean(CommandInterface $command) { $this->fileSystem->clean(); - if (Utils::isWindows()) { + if ($this->environment->isWindows()) { system('cd ext && nmake clean-all'); system('cd ext && phpize --clean'); system('cd ext && ./clean'); @@ -1311,15 +1257,15 @@ public function buildDev(CommandInterface $command) */ protected function processAddSources($sources, $project) { - $groupSources = array(); + $groupSources = []; foreach ($sources as $source) { $dirName = str_replace(DIRECTORY_SEPARATOR, '/', dirname($source)); if (!isset($groupSources[$dirName])) { - $groupSources[$dirName] = array(); + $groupSources[$dirName] = []; } $groupSources[$dirName][] = basename($source); } - $groups = array(); + $groups = []; foreach ($groupSources as $dirname => $files) { $groups[] = 'ADD_SOURCES(configure_module_dirname + "/' . $dirname . '", "' . join(' ', $files) . '", "' . $project . '");'; @@ -1367,7 +1313,7 @@ public function createConfigFiles($project) return str_replace('.c', '.zep.h', $file); }, $this->compiledFiles); } else { - $compiledHeaders = array('php_' . strtoupper($project) . '.h'); + $compiledHeaders = ['php_' . strtoupper($project) . '.h']; } /* @@ -1380,7 +1326,7 @@ public function createConfigFiles($project) /** * Generate config.m4 */ - $toReplace = array( + $toReplace = [ '%PROJECT_LOWER_SAFE%' => strtolower($safeProject), '%PROJECT_LOWER%' => strtolower($project), '%PROJECT_UPPER%' => strtoupper($project), @@ -1390,18 +1336,18 @@ public function createConfigFiles($project) '%EXTRA_FILES_COMPILED%' => implode("\n\t", $this->extraFiles), '%PROJECT_EXTRA_LIBS%' => $extraLibs, '%PROJECT_EXTRA_CFLAGS%' => $extraCflags, - ); + ]; foreach ($toReplace as $mark => $replace) { $contentM4 = str_replace($mark, $replace, $contentM4); } - $needConfigure = Utils::checkAndWriteIfNeeded($contentM4, 'ext/config.m4'); + file_put_contents_ex($contentM4, 'ext/config.m4'); /** * Generate config.w32 */ - $toReplace = array( + $toReplace = [ '%PROJECT_LOWER_SAFE%' => strtolower($safeProject), '%PROJECT_LOWER%' => strtolower($project), '%PROJECT_UPPER%' => strtoupper($project), @@ -1413,13 +1359,13 @@ public function createConfigFiles($project) "\r\n\t", $this->processAddSources($this->extraFiles, strtolower($project)) ), - ); + ]; foreach ($toReplace as $mark => $replace) { $contentW32 = str_replace($mark, $replace, $contentW32); } - $needConfigure = Utils::checkAndWriteIfNeeded($contentW32, 'ext/config.w32'); + $needConfigure = file_put_contents_ex($contentW32, 'ext/config.w32'); /** * php_ext.h @@ -1429,15 +1375,15 @@ public function createConfigFiles($project) throw new Exception("Template php_ext.h doesn't exist"); } - $toReplace = array( + $toReplace = [ '%PROJECT_LOWER_SAFE%' => strtolower($safeProject) - ); + ]; foreach ($toReplace as $mark => $replace) { $content = str_replace($mark, $replace, $content); } - Utils::checkAndWriteIfNeeded($content, 'ext/php_ext.h'); + file_put_contents_ex($content, 'ext/php_ext.h'); /** * ext.h @@ -1447,15 +1393,15 @@ public function createConfigFiles($project) throw new Exception("Template ext.h doesn't exist"); } - $toReplace = array( + $toReplace = [ '%PROJECT_LOWER_SAFE%' => strtolower($safeProject) - ); + ]; foreach ($toReplace as $mark => $replace) { $content = str_replace($mark, $replace, $content); } - Utils::checkAndWriteIfNeeded($content, 'ext/ext.h'); + file_put_contents_ex($content, 'ext/ext.h'); /** * ext_config.h @@ -1465,15 +1411,15 @@ public function createConfigFiles($project) throw new Exception("Template ext_config.h doesn't exist"); } - $toReplace = array( + $toReplace = [ '%PROJECT_LOWER%' => strtolower($project) - ); + ]; foreach ($toReplace as $mark => $replace) { $content = str_replace($mark, $replace, $content); } - Utils::checkAndWriteIfNeeded($content, 'ext/ext_config.h'); + file_put_contents_ex($content, 'ext/ext_config.h'); /** * ext_clean @@ -1483,7 +1429,7 @@ public function createConfigFiles($project) throw new Exception("Clean file doesn't exist"); } - if (Utils::checkAndWriteIfNeeded($content, 'ext/clean')) { + if (file_put_contents_ex($content, 'ext/clean')) { chmod('ext/clean', 0755); } @@ -1495,15 +1441,15 @@ public function createConfigFiles($project) throw new Exception("Install file doesn't exist"); } - $toReplace = array( + $toReplace = [ '%PROJECT_LOWER%' => strtolower($project) - ); + ]; foreach ($toReplace as $mark => $replace) { $content = str_replace($mark, $replace, $content); } - if (Utils::checkAndWriteIfNeeded($content, 'ext/install')) { + if (file_put_contents_ex($content, 'ext/install')) { chmod('ext/install', 0755); } @@ -1522,16 +1468,16 @@ public function processExtensionGlobals($namespace) { $globalCode = ''; $globalStruct = ''; - $globalsDefault = array(array(), array()); - $initEntries = array(); + $globalsDefault = [[], []]; + $initEntries = []; /** * Generate the extensions globals declaration */ $globals = $this->config->get('globals'); if (is_array($globals)) { - $structures = array(); - $variables = array(); + $structures = []; + $variables = []; foreach ($globals as $name => $global) { $parts = explode('.', $name); if (isset($parts[1])) { @@ -1619,7 +1565,7 @@ public function processExtensionGlobals($namespace) } $globalCode .= "\t" . $type . ' ' . $name . ';' . PHP_EOL . PHP_EOL; - $iniEntry = array(); + $iniEntry = []; if (isset($global['ini-entry'])) { $iniEntry = $global['ini-entry']; } @@ -1659,7 +1605,7 @@ public function processExtensionGlobals($namespace) $globalsDefault[0] = implode('', $globalsDefault[0]); $globalsDefault[1] = implode('', $globalsDefault[1]); - return array($globalCode, $globalStruct, $globalsDefault, $initEntries); + return [$globalCode, $globalStruct, $globalsDefault, $initEntries]; } /** @@ -1676,7 +1622,7 @@ public function processExtensionInfo() foreach ($info as $table) { $phpinfo .= "\t" . 'php_info_print_table_start();' . PHP_EOL; if (isset($table['header'])) { - $headerArray = array(); + $headerArray = []; foreach ($table['header'] as $header) { $headerArray[] = '"' . htmlentities($header) . '"'; } @@ -1686,7 +1632,7 @@ public function processExtensionInfo() } if (isset($table['rows'])) { foreach ($table['rows'] as $row) { - $rowArray = array(); + $rowArray = []; foreach ($row as $field) { $rowArray[] = '"' . htmlentities($field) . '"'; } @@ -1703,15 +1649,16 @@ public function processExtensionInfo() } /** - * Process extension code injection + * Process extension code injection. * - * @param array $entries + * @param array $entries + * @param string $section * @return array */ public function processCodeInjection(array $entries, $section = 'request') { - $codes = array(); - $includes = array(); + $codes = []; + $includes = []; if (isset($entries[$section])) { foreach ($entries[$section] as $entry) { @@ -1724,7 +1671,7 @@ public function processCodeInjection(array $entries, $section = 'request') } } - return array(join(PHP_EOL, $includes), join("\n\t", $codes)); + return [implode(PHP_EOL, $includes), implode("\n\t", $codes)]; } /** @@ -1746,7 +1693,7 @@ public function calculateDependencies($files, $_dependency = null) * We first build a dependency tree and then set the rank accordingly */ if ($_dependency == null) { - $dependencyTree = array(); + $dependencyTree = []; foreach ($files as $file) { if (!$file->isExternal()) { $classDefinition = $file->getClassDefinition(); @@ -1809,11 +1756,11 @@ public function createProjectFiles($project) */ $this->calculateDependencies($files); - $classEntries = array(); - $classInits = array(); + $classEntries = []; + $classInits = []; - $interfaceEntries = array(); - $interfaceInits = array(); + $interfaceEntries = []; + $interfaceInits = []; /** * Round 2. Generate the ZEPHIR_INIT calls according to the dependency rank @@ -1826,8 +1773,8 @@ public function createProjectFiles($project) $dependencyRank = $classDefinition->getDependencyRank(); if ($classDefinition->getType() == 'class') { if (!isset($classInits[$dependencyRank])) { - $classEntries[$dependencyRank] = array(); - $classInits[$dependencyRank] = array(); + $classEntries[$dependencyRank] = []; + $classInits[$dependencyRank] = []; } $classEntries[$dependencyRank][] = 'zend_class_entry *' . $classDefinition->getClassEntry() . ';'; @@ -1836,8 +1783,8 @@ public function createProjectFiles($project) $classDefinition->getName() . ');'; } else { if (!isset($interfaceInits[$dependencyRank])) { - $interfaceEntries[$dependencyRank] = array(); - $interfaceInits[$dependencyRank] = array(); + $interfaceEntries[$dependencyRank] = []; + $interfaceInits[$dependencyRank] = []; } $interfaceEntries[$dependencyRank][] = 'zend_class_entry *' . $classDefinition->getClassEntry() . ';'; @@ -1854,25 +1801,25 @@ public function createProjectFiles($project) krsort($interfaceInits); krsort($interfaceEntries); - $completeInterfaceInits = array(); + $completeInterfaceInits = []; foreach ($interfaceInits as $rankInterfaceInits) { asort($rankInterfaceInits, SORT_STRING); $completeInterfaceInits = array_merge($completeInterfaceInits, $rankInterfaceInits); } - $completeInterfaceEntries = array(); + $completeInterfaceEntries = []; foreach ($interfaceEntries as $rankInterfaceEntries) { asort($rankInterfaceEntries, SORT_STRING); $completeInterfaceEntries = array_merge($completeInterfaceEntries, $rankInterfaceEntries); } - $completeClassInits = array(); + $completeClassInits = []; foreach ($classInits as $rankClassInits) { asort($rankClassInits, SORT_STRING); $completeClassInits = array_merge($completeClassInits, $rankClassInits); } - $completeClassEntries = array(); + $completeClassEntries = []; foreach ($classEntries as $rankClassEntries) { asort($rankClassEntries, SORT_STRING); $completeClassEntries = array_merge($completeClassEntries, $rankClassEntries); @@ -1954,7 +1901,7 @@ public function createProjectFiles($project) } } - $toReplace = array( + $toReplace = [ '%PROJECT_LOWER_SAFE%' => strtolower($safeProject), '%PROJECT_LOWER%' => strtolower($project), '%PROJECT_UPPER%' => strtoupper($project), @@ -1969,7 +1916,7 @@ public function createProjectFiles($project) ), '%INIT_GLOBALS%' => implode( PHP_EOL . "\t", - array_merge((array)$globalsDefault[0], array($glbInitializers)) + array_merge((array)$globalsDefault[0], [$glbInitializers]) ), '%INIT_MODULE_GLOBALS%' => $globalsDefault[1], '%DESTROY_GLOBALS%' => $glbDestructors, @@ -1982,12 +1929,12 @@ public function createProjectFiles($project) '%MOD_DESTRUCTORS%' => $modDestructors, '%REQ_INITIALIZERS%' => implode( PHP_EOL . "\t", - array_merge($this->internalInitializers, array($reqInitializers)) + array_merge($this->internalInitializers, [$reqInitializers]) ), '%REQ_DESTRUCTORS%' => $reqDestructors, '%POSTREQ_DESTRUCTORS%' => empty($prqDestructors) ? '' : implode( PHP_EOL, - array( + [ '#define ZEPHIR_POST_REQUEST 1', 'static PHP_PRSHUTDOWN_FUNCTION(' . strtolower($project) . ')', '{', @@ -1996,12 +1943,12 @@ public function createProjectFiles($project) explode(PHP_EOL, $prqDestructors) ), '}' - ) + ] ), '%FE_HEADER%' => $feHeader, '%FE_ENTRIES%' => $feEntries, '%PROJECT_INI_ENTRIES%' => implode(PHP_EOL . "\t", $initEntries) - ); + ]; foreach ($toReplace as $mark => $replace) { $content = str_replace($mark, $replace, $content); } @@ -2009,7 +1956,7 @@ public function createProjectFiles($project) /** * Round 5. Generate and place the entry point of the project */ - Utils::checkAndWriteIfNeeded($content, 'ext/' . $safeProject . '.c'); + file_put_contents_ex($content, 'ext/' . $safeProject . '.c'); unset($content); /** @@ -2020,7 +1967,7 @@ public function createProjectFiles($project) throw new Exception("Template project.h doesn't exists"); } - $includeHeaders = array(); + $includeHeaders = []; foreach ($this->compiledFiles as $file) { if ($file) { $fileH = str_replace(".c", ".zep.h", $file); @@ -2042,15 +1989,15 @@ public function createProjectFiles($project) } } - $toReplace = array( + $toReplace = [ '%INCLUDE_HEADERS%' => implode(PHP_EOL, $includeHeaders) - ); + ]; foreach ($toReplace as $mark => $replace) { $content = str_replace($mark, $replace, $content); } - Utils::checkAndWriteIfNeeded($content, 'ext/' . $safeProject . '.h'); + file_put_contents_ex($content, 'ext/' . $safeProject . '.h'); unset($content); /** @@ -2061,9 +2008,9 @@ public function createProjectFiles($project) throw new Exception("Template php_project.h doesn't exist"); } - $version = self::getCurrentVersion(); + $version = $this->container->get(Version::class); - $toReplace = array( + $toReplace = [ '%PROJECT_LOWER_SAFE%' => strtolower($safeProject), '%PROJECT_LOWER%' => strtolower($project), '%PROJECT_UPPER%' => strtoupper($project), @@ -2072,16 +2019,16 @@ public function createProjectFiles($project) '%PROJECT_AUTHOR%' => utf8_decode($this->config->get('author')), '%PROJECT_VERSION%' => utf8_decode($this->config->get('version')), '%PROJECT_DESCRIPTION%' => utf8_decode($this->config->get('description')), - '%PROJECT_ZEPVERSION%' => $version, + '%PROJECT_ZEPVERSION%' => (string) $version, '%EXTENSION_GLOBALS%' => $globalCode, '%EXTENSION_STRUCT_GLOBALS%' => $globalStruct - ); + ]; foreach ($toReplace as $mark => $replace) { $content = str_replace($mark, $replace, $content); } - Utils::checkAndWriteIfNeeded($content, 'ext/php_' . $safeProject . '.h'); + file_put_contents_ex($content, 'ext/php_' . $safeProject . '.h'); unset($content); return $needConfigure; @@ -2093,174 +2040,36 @@ public function generateFunctionInformation() $entryPrinter = new CodePrinter(); /** - * Create argument info + * Specifying Argument Information */ foreach ($this->functionDefinitions as $func) { + $argInfo = new ArgInfoDefinition( + $func->getArgInfoName(), + $func, + $headerPrinter, + $func->getCallGathererPass()->getCompilationContext() + ); + $funcName = $func->getInternalName(); - $argInfoName = 'arginfo_' . strtolower($funcName); + $argInfoName = $func->getArgInfoName(); $headerPrinter->output('PHP_FUNCTION(' . $funcName . ');'); - $parameters = $func->getParameters(); - if ($this->backend->isZE3() && $func->hasReturnTypes()) { - if (array_key_exists('object', $func->getReturnTypes())) { - $class = 'NULL'; + $argInfo->setBooleanDefinition($this->backend->isZE3() ? '_IS_BOOL' : 'IS_BOOL'); + $argInfo->setRichFormat($this->backend->isZE3()); - if (count($func->getReturnClassTypes()) == 1) { - $compilationContext = $func->getCallGathererPass()->getCompilationContext(); - $class = Utils::escapeClassName($compilationContext->getFullName(key($func->getReturnClassTypes()))); - } - - $headerPrinter->output('#ifdef ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX'); - $headerPrinter->output( - 'ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(' . $argInfoName . ', 0, ' . - $func->getNumberOfRequiredParameters() . ', ' . - $class . ', ' . ($func->areReturnTypesNullCompatible() ? 1 : 0) . ')' - ); - $headerPrinter->output('#else'); - $headerPrinter->output( - 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(' . $argInfoName . ', 0, ' . - $func->getNumberOfRequiredParameters() . ', ' . - 'NULL, "' . $class . '", ' . ($func->areReturnTypesNullCompatible() ? 1 : 0) . ')' - ); - $headerPrinter->output('#endif'); - } else { - $type = 'IS_NULL'; + $argInfo->render(); - if ($func->areReturnTypesIntCompatible()) { - $type = 'IS_LONG'; - } - if ($func->areReturnTypesDoubleCompatible()) { - $type = 'IS_DOUBLE'; - } - if ($func->areReturnTypesBoolCompatible()) { - $type = '_IS_BOOL'; - } - if ($func->areReturnTypesStringCompatible()) { - $type = 'IS_STRING'; - } - - $headerPrinter->output('#ifdef ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX'); - $headerPrinter->output( - 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(' . $argInfoName . ', 0, ' . - $func->getNumberOfRequiredParameters() . ', ' . - $type . ', ' . ($func->areReturnTypesNullCompatible() ? 1 : 0) . ')' - ); - $headerPrinter->output('#else'); - $headerPrinter->output( - 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(' . $argInfoName . ', 0, ' . - $func->getNumberOfRequiredParameters() . ', ' . - $type . ', NULL, ' . ($func->areReturnTypesNullCompatible() ? 1 : 0) . ')' - ); - $headerPrinter->output('#endif'); - } - - if ($parameters == null || !count($parameters->getParameters())) { - $headerPrinter->output('ZEND_END_ARG_INFO()'); - $headerPrinter->outputBlankLine(); - } - } elseif ($parameters != null && count($parameters->getParameters())) { - $headerPrinter->output( - 'ZEND_BEGIN_ARG_INFO_EX(' . $argInfoName . ', 0, 0, ' . - $func->getNumberOfRequiredParameters() . ')' - ); - } - - if ($parameters != null && count($parameters->getParameters())) { - foreach ($parameters->getParameters() as $parameter) { - switch (($this->backend->isZE3() ? '3:' : '2:') . $parameter['data-type']) { - case '2:array': - case '3:array': - $headerPrinter->output( - "\t" . 'ZEND_ARG_ARRAY_INFO(' . - (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . - $parameter['name'] . ', ' . - (isset($parameter['default']) ? 1 : 0) . ')' - ); - break; - - case '2:variable': - case '3:variable': - if (isset($parameter['cast'])) { - switch ($parameter['cast']['type']) { - case 'variable': - $compilationContext = $func->getCallGathererPass()->getCompilationContext(); - $value = $parameter['cast']['value']; - - $headerPrinter->output( - "\t" . 'ZEND_ARG_OBJ_INFO(' . - (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . - $parameter['name'] . ', ' . - Utils::escapeClassName($compilationContext->getFullName($value)) . ', ' . - (isset($parameter['default']) ? 1 : 0) . ')' - ); - break; - - default: - throw new Exception('Unexpected exception'); - } - } else { - $headerPrinter->output("\t" . 'ZEND_ARG_INFO(' . - (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . - $parameter['name'] . ')'); - } - break; - - case '3:bool': - case '3:boolean': - $headerPrinter->output( - "\t" . 'ZEND_ARG_TYPE_INFO(' . - (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . - $parameter['name'] . ', ' . - ($this->backend->isZE3() ? '_IS_BOOL' : 'IS_BOOL') . ', ' . - (isset($parameter['default']) ? 1 : 0) . ')' - ); - break; - - case '3:uchar': - case '3:int': - case '3:uint': - case '3:long': - case '3:ulong': - $headerPrinter->output( - "\t" . 'ZEND_ARG_TYPE_INFO(' . - (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . - $parameter['name'] . ', IS_LONG, ' . - (isset($parameter['default']) ? 1 : 0) . ')' - ); - break; - - case '3:double': - $headerPrinter->output( - "\t" . 'ZEND_ARG_TYPE_INFO(' . - (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . - $parameter['name'] . ', IS_DOUBLE, ' . - (isset($parameter['default']) ? 1 : 0) . ')' - ); - break; + /** Generate FE's */ + $paramData = 'NULL'; - case '3:char': - case '3:string': - $headerPrinter->output( - "\t" . 'ZEND_ARG_TYPE_INFO(' . - (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . - $parameter['name'] . ', IS_STRING, ' . - (isset($parameter['default']) ? 1 : 0) . ')' - ); - break; + $richFormat = $this->backend->isZE3() && + $func->isReturnTypesHintDetermined() && + $func->areReturnTypesCompatible(); - default: - $headerPrinter->output("\t" . 'ZEND_ARG_INFO(' . - (isset($parameter['reference']) ? $parameter['reference'] : 0) . ', ' . - $parameter['name'] . ')'); - break; - } - } - $headerPrinter->output('ZEND_END_ARG_INFO()'); - $headerPrinter->outputBlankLine(); + if ($richFormat || $func->hasParameters()) { + $paramData = $argInfoName; } - /** Generate FE's */ - $paramData = ((($this->backend->isZE3() && $func->hasReturnTypes()) || $func->hasParameters()) ? $argInfoName : 'NULL'); if ($func->isGlobal()) { $entryPrinter->output( @@ -2277,7 +2086,7 @@ public function generateFunctionInformation() } $entryPrinter->output('ZEND_FE_END'); - return array($headerPrinter->getOutput(), $entryPrinter->getOutput()); + return [$headerPrinter->getOutput(), $entryPrinter->getOutput()]; } /** @@ -2320,18 +2129,6 @@ public function getFileSystem() return $this->fileSystem; } - /** - * Returns a short path - * - * @param string $path - * - * @return string - */ - public static function getShortPath($path) - { - return str_replace(ZEPHIRPATH . DIRECTORY_SEPARATOR, '', $path); - } - /** * Returns a short user path * @@ -2390,12 +2187,12 @@ public function generatePackageDependenciesM4($contentM4) } } - $toReplace = array( + $toReplace = [ '%PACKAGE_LOWER%' => strtolower($pkg), '%PACKAGE_UPPER%' => strtoupper($pkg), '%PACKAGE_REQUESTED_VERSION%' => $operator . ' ' . $version, '%PACKAGE_PKG_CONFIG_COMPARE_VERSION%' => $operatorCmd . '=' . $version, - ); + ]; foreach ($toReplace as $mark => $replace) { $pkgM4Buf = str_replace($mark, $replace, $pkgM4Buf); @@ -2416,7 +2213,11 @@ public function generatePackageDependenciesM4($contentM4) } /** - * Check require extensions orther when build your extension + * Check require extensions orther when build your extension. + * + * @return void + * + * @throws Exception */ protected function checkRequires() { @@ -2484,7 +2285,7 @@ protected function checkKernelFiles() ); if (!$configured) { - $this->logger->output('Cleaning old kernel files...'); + $this->logger->output("\nCleaning old kernel files..."); $this->recursiveDeletePath($kernelPath, '@^.*\.[lcho]$@'); @mkdir($kernelPath); @@ -2517,15 +2318,15 @@ protected function checkDirectory() $this->fileSystem->initialize(); } - $version = self::getCurrentVersion(); + $version = $this->container->get(Version::class); - if (!$this->fileSystem->exists($version)) { + if (!$this->fileSystem->exists((string) $version)) { if (!$this->checkIfPhpized()) { $this->logger->output( 'Zephir version has changed, use "zephir fullclean" to perform a full clean of the project' ); } - $this->fileSystem->makeDirectory($version); + $this->fileSystem->makeDirectory((string) $version); } return $namespace; @@ -2538,9 +2339,9 @@ protected function checkDirectory() */ protected function getGccVersion() { - $version = self::getCurrentVersion(); + $version = $this->container->get(Version::class); - if (!Utils::isWindows()) { + if (!$this->environment->isWindows()) { if ($this->fileSystem->exists($version . '/gcc-version')) { return $this->fileSystem->read($version . '/gcc-version'); } diff --git a/Library/Compiler/CompilerException.php b/Library/Compiler/CompilerException.php index 8af57fe643..b363775d82 100644 --- a/Library/Compiler/CompilerException.php +++ b/Library/Compiler/CompilerException.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Compiler; diff --git a/Library/Compiler/FileInterface.php b/Library/Compiler/FileInterface.php index 10d1ee2a90..7bc239bddd 100644 --- a/Library/Compiler/FileInterface.php +++ b/Library/Compiler/FileInterface.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Compiler; diff --git a/Library/Compiler/IllegalOperationException.php b/Library/Compiler/IllegalOperationException.php index 7625a9c5ff..52a7ccf9ba 100644 --- a/Library/Compiler/IllegalOperationException.php +++ b/Library/Compiler/IllegalOperationException.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Compiler; diff --git a/Library/CompilerFile.php b/Library/CompilerFile.php index 2d8eb09329..6413b9fdb9 100644 --- a/Library/CompilerFile.php +++ b/Library/CompilerFile.php @@ -1,81 +1,75 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir; -use Zephir\Parser\ParseException; -use Zephir\Compiler\FileInterface; use Zephir\Compiler\CompilerException; +use Zephir\Compiler\FileInterface; +use Zephir\Di\ContainerAwareTrait; +use Zephir\Di\InjectionAwareInterface; use Zephir\Documentation\DocblockParser; use Zephir\Exception\IllegalStateException; +use Zephir\Parser\ParseException; /** - * CompilerFile + * Zephir\CompilerFile * - * This class represents every file compiled in a project - * Every file may contain a class or an interface + * This class represents every file compiled in a project. + * Every file may contain a class or an interface. + * + * @package Zephir */ -class CompilerFile implements FileInterface +class CompilerFile implements FileInterface, InjectionAwareInterface { + use ContainerAwareTrait { + ContainerAwareTrait::__construct as protected __DiInject; + } + /** * Namespace of the */ - protected $_namespace; + protected $namespace; - protected $_className; + protected $className; - protected $_filePath; + protected $filePath; - protected $_external = false; + protected $external = false; /** * Original internal representation (IR) of the file */ - protected $_ir; + protected $ir; - protected $_originalNode; + protected $originalNode; - protected $_compiledFile; + protected $compiledFile; - /** - * @var ClassDefinition - */ - protected $_classDefinition; + /** @var ClassDefinition */ + protected $classDefinition; - /** - * @var FunctionDefinition[] - */ - protected $_functionDefinitions = array(); + /** @var FunctionDefinition[] */ + protected $functionDefinitions = []; - /** - * @var array - */ - protected $_headerCBlocks; + /** @var array */ + protected $headerCBlocks; - /** - * @var Config - */ - protected $_config = null; + /** @var Config */ + protected $config = null; - /** - * @var Logger - */ - protected $_logger = null; + /** @var Logger */ + protected $logger = null; - /** - * @var AliasManager - */ - protected $_aliasManager; + /** @var AliasManager */ + protected $aliasManager; /** * CompilerFile constructor @@ -87,12 +81,14 @@ class CompilerFile implements FileInterface */ public function __construct($className, $filePath, Config $config, Logger $logger) { - $this->_className = $className; - $this->_filePath = $filePath; - $this->_headerCBlocks = array(); - $this->_config = $config; - $this->_logger = $logger; - $this->_aliasManager = new AliasManager(); + $this->__DiInject(); + + $this->className = $className; + $this->filePath = $filePath; + $this->headerCBlocks = []; + $this->config = $config; + $this->logger = $logger; + $this->aliasManager = new AliasManager(); } /** @@ -102,13 +98,13 @@ public function __construct($className, $filePath, Config $config, Logger $logge */ public function getClassDefinition() { - $this->_classDefinition->setAliasManager($this->_aliasManager); - return $this->_classDefinition; + $this->classDefinition->setAliasManager($this->aliasManager); + return $this->classDefinition; } public function getFunctionDefinitions() { - return $this->_functionDefinitions; + return $this->functionDefinitions; } /** @@ -118,7 +114,7 @@ public function getFunctionDefinitions() */ public function setIsExternal($external) { - $this->_external = (bool) $external; + $this->external = (bool) $external; } /** @@ -128,7 +124,7 @@ public function setIsExternal($external) */ public function isExternal() { - return $this->_external; + return $this->external; } /** @@ -144,10 +140,10 @@ public function addFunction(Compiler $compiler, FunctionDefinition $func, $state { $compiler->addFunction($func, $statement); $funcName = strtolower($func->getInternalName()); - if (isset($this->_functionDefinitions[$funcName])) { + if (isset($this->functionDefinitions[$funcName])) { throw new CompilerException("Function '" . $func->getName() . "' was defined more than one time (in the same file)", $statement); } - $this->_functionDefinitions[$funcName] = $func; + $this->functionDefinitions[$funcName] = $func; } /** @@ -161,9 +157,11 @@ public function addFunction(Compiler $compiler, FunctionDefinition $func, $state */ public function genIR(Compiler $compiler) { - $normalizedPath = str_replace(array(DIRECTORY_SEPARATOR, ":", '/'), '_', realpath($this->_filePath)); - $compilePath = DIRECTORY_SEPARATOR . Compiler::getCurrentVersion() . DIRECTORY_SEPARATOR . $normalizedPath . ".js"; - $zepRealPath = realpath($this->_filePath); + $version = $this->container->get(Version::class); + $normalizedPath = str_replace(array(DIRECTORY_SEPARATOR, ":", '/'), '_', realpath($this->filePath)); + + $compilePath = DIRECTORY_SEPARATOR . $version . DIRECTORY_SEPARATOR . $normalizedPath . ".js"; + $zepRealPath = realpath($this->filePath); $changed = false; @@ -204,7 +202,7 @@ public function genIR(Compiler $compiler) */ public function compileClass(CompilationContext $compilationContext, $namespace, $classStatement) { - $classDefinition = $this->_classDefinition; + $classDefinition = $this->classDefinition; /** * Do the compilation @@ -257,7 +255,7 @@ public function compileComment(CompilationContext $compilationContext, $topState public function preCompileInterface($namespace, $topStatement, $docblock) { $classDefinition = new ClassDefinition($namespace, $topStatement['name']); - $classDefinition->setIsExternal($this->_external); + $classDefinition->setIsExternal($this->external); if (isset($topStatement['extends'])) { foreach ($topStatement['extends'] as &$extend) { @@ -309,14 +307,16 @@ public function preCompileInterface($namespace, $topStatement, $docblock) } } - $this->_classDefinition = $classDefinition; + $this->classDefinition = $classDefinition; } /** - * Creates the property shortcuts + * Creates the property shortcuts. + * + * @param array $property + * @param ClassDefinition $classDefinition + * @return void * - * @param array $property - * @param ClassDefinition $classDefinition * @throws CompilerException */ protected function _processShorcuts(array $property, ClassDefinition $classDefinition) @@ -329,7 +329,7 @@ protected function _processShorcuts(array $property, ClassDefinition $classDefin } $docBlock = isset($shortcut['docblock']) ? $shortcut['docblock'] : isset($property['docblock']) ? $property['docblock'] : null; - $returnsType = array(); + $returnsType = []; if ($docBlock) { $docBlockParser = new DocblockParser('/' . $docBlock .'/'); @@ -342,7 +342,7 @@ protected function _processShorcuts(array $property, ClassDefinition $classDefin } // Clear annotations - $docBlockParsed->setAnnotations(array()); + $docBlockParsed->setAnnotations([]); $docBlock = $docBlockParsed->generate(); } @@ -351,7 +351,7 @@ protected function _processShorcuts(array $property, ClassDefinition $classDefin $classDefinition->addMethod(new ClassMethod( $classDefinition, array('public'), - 'get' . Utils::camelize($name), + 'get' . camelize($name), null, new StatementsBlock(array( array( @@ -370,7 +370,7 @@ protected function _processShorcuts(array $property, ClassDefinition $classDefin ) )), $docBlock, - $this->createReturnsType($returnsType), + $this->createReturnsType($returnsType, true), $shortcut ), $shortcut); break; @@ -379,7 +379,7 @@ protected function _processShorcuts(array $property, ClassDefinition $classDefin $classDefinition->addMethod(new ClassMethod( $classDefinition, array('public'), - 'set' . Utils::camelize($name), + 'set' . camelize($name), new ClassMethodParameters(array( array( 'type' => 'parameter', @@ -474,7 +474,7 @@ protected function _processShorcuts(array $property, ClassDefinition $classDefin public function preCompileClass(CompilationContext $compilationContext, $namespace, $topStatement, $docblock) { $classDefinition = new ClassDefinition($namespace, $topStatement['name']); - $classDefinition->setIsExternal($this->_external); + $classDefinition->setIsExternal($this->external); if (isset($topStatement['extends'])) { $classDefinition->setExtendsClass($this->getFullName($topStatement['extends'])); @@ -557,7 +557,7 @@ public function preCompileClass(CompilationContext $compilationContext, $namespa } } - $this->_classDefinition = $classDefinition; + $this->classDefinition = $classDefinition; /** * Assign current class definition to the compilation context @@ -583,7 +583,7 @@ public function preCompile(Compiler $compiler) $ir = $this->genIR($compiler); if (!is_array($ir)) { - throw new Exception("Cannot parse file: " . realpath($this->_filePath)); + throw new Exception("Cannot parse file: " . realpath($this->filePath)); } if (isset($ir['type']) && $ir['type'] == 'error') { @@ -603,17 +603,17 @@ public function preCompile(Compiler $compiler) /** * Set global config in the compilation context */ - $compilationContext->config = $this->_config; + $compilationContext->config = $this->config; /** * Set global logger in the compilation context */ - $compilationContext->logger = $this->_logger; + $compilationContext->logger = $this->logger; /** * Alias manager */ - $compilationContext->aliasManager = $this->_aliasManager; + $compilationContext->aliasManager = $this->aliasManager; $compilationContext->backend = $compiler->backend; @@ -628,14 +628,14 @@ public function preCompile(Compiler $compiler) throw new CompilerException("The namespace must be defined just one time", $topStatement); } $namespace = $topStatement['name']; - $this->_namespace = $namespace; + $this->namespace = $namespace; if (!preg_match('/^[A-Z]/', $namespace)) { throw new CompilerException("Namespace '" . $namespace . "' must be in camelized-form", $topStatement); } break; case 'cblock': - $this->_headerCBlocks[] = $topStatement['value']; + $this->headerCBlocks[] = $topStatement['value']; break; case 'function': @@ -659,7 +659,7 @@ public function preCompile(Compiler $compiler) } /* Set namespace and flag as global, if before namespace declaration */ - foreach ($this->_functionDefinitions as $funcDef) { + foreach ($this->functionDefinitions as $funcDef) { if ($funcDef->getNamespace() == null) { $funcDef->setGlobal(true); $funcDef->setNamespace($compiler->getConfig()->get('namespace')); @@ -679,7 +679,7 @@ public function preCompile(Compiler $compiler) $class = true; $name = $topStatement['name']; $this->preCompileClass($compilationContext, $namespace, $topStatement, $lastComment); - $this->_originalNode = $topStatement; + $this->originalNode = $topStatement; $lastComment = null; break; @@ -690,7 +690,7 @@ public function preCompile(Compiler $compiler) $interface = true; $name = $topStatement['name']; $this->preCompileInterface($namespace, $topStatement, $lastComment); - $this->_originalNode = $topStatement; + $this->originalNode = $topStatement; $lastComment = null; break; @@ -698,7 +698,7 @@ public function preCompile(Compiler $compiler) if ($interface || $class) { throw new CompilerException("Aliasing must be done before declaring any class or interface", $topStatement); } - $this->_aliasManager->add($topStatement); + $this->aliasManager->add($topStatement); break; case 'comment': @@ -711,11 +711,11 @@ public function preCompile(Compiler $compiler) throw new CompilerException("Every file must contain at least a class or an interface", $topStatement); } - if (!$this->_external) { + if (!$this->external) { $expectedPath = strtolower(str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR . $name) . '.zep'; - if (strtolower($this->_filePath) != $expectedPath) { + if (strtolower($this->filePath) != $expectedPath) { $className = $namespace . '\\' . $name; - $message = 'Unexpected class name ' . $className . ' in file: ' . $this->_filePath . ', expected: ' . $expectedPath; + $message = 'Unexpected class name ' . $className . ' in file: ' . $this->filePath . ', expected: ' . $expectedPath; throw new CompilerException($message); } } @@ -731,7 +731,7 @@ public function preCompile(Compiler $compiler) } } - $this->_ir = $ir; + $this->ir = $ir; } /** @@ -741,7 +741,7 @@ public function preCompile(Compiler $compiler) */ public function getCompiledFile() { - return $this->_compiledFile; + return $this->compiledFile; } /** @@ -751,7 +751,7 @@ public function getCompiledFile() */ public function checkDependencies(Compiler $compiler) { - $classDefinition = $this->_classDefinition; + $classDefinition = $this->classDefinition; $extendedClass = $classDefinition->getExtendsClass(); if ($extendedClass) { @@ -766,7 +766,7 @@ public function checkDependencies(Compiler $compiler) } else { $extendedDefinition = new ClassDefinitionRuntime($extendedClass); $classDefinition->setExtendsClassDefinition($extendedDefinition); - $this->_logger->warning('Cannot locate class "' . $extendedClass . '" when extending class "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->_originalNode); + $this->logger->warning('Cannot locate class "' . $extendedClass . '" when extending class "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->originalNode); } } } else { @@ -780,7 +780,7 @@ public function checkDependencies(Compiler $compiler) } else { $extendedDefinition = new ClassDefinitionRuntime($extendedClass); $classDefinition->setExtendsClassDefinition($extendedDefinition); - $this->_logger->warning('Cannot locate class "' . $extendedClass . '" when extending interface "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->_originalNode); + $this->logger->warning('Cannot locate class "' . $extendedClass . '" when extending interface "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->originalNode); } } } @@ -788,7 +788,7 @@ public function checkDependencies(Compiler $compiler) $implementedInterfaces = $classDefinition->getImplementedInterfaces(); if ($implementedInterfaces) { - $interfaceDefinitions = array(); + $interfaceDefinitions = []; foreach ($implementedInterfaces as $interface) { if ($compiler->isInterface($interface)) { @@ -799,7 +799,7 @@ public function checkDependencies(Compiler $compiler) } else { $extendedDefinition = new ClassDefinitionRuntime($extendedClass); $classDefinition->setExtendsClassDefinition($extendedDefinition); - $this->_logger->warning('Cannot locate class "' . $interface . '" when extending interface "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->_originalNode); + $this->logger->warning('Cannot locate class "' . $interface . '" when extending interface "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->originalNode); } } } @@ -819,14 +819,14 @@ public function checkDependencies(Compiler $compiler) */ public function compile(Compiler $compiler, StringsManager $stringsManager) { - if (!$this->_ir) { + if (!$this->ir) { throw new CompilerException('IR related to compiled file is missing'); } /** * External classes should not be compiled as part of the extension */ - if ($this->_external) { + if ($this->external) { return; } @@ -843,12 +843,12 @@ public function compile(Compiler $compiler, StringsManager $stringsManager) /** * Set global config in the compilation context */ - $compilationContext->config = $this->_config; + $compilationContext->config = $this->config; /** * Set global logger in the compilation context */ - $compilationContext->logger = $this->_logger; + $compilationContext->logger = $this->logger; /** * Set global strings manager @@ -872,21 +872,21 @@ public function compile(Compiler $compiler, StringsManager $stringsManager) /** * Alias manager */ - $compilationContext->aliasManager = $this->_aliasManager; + $compilationContext->aliasManager = $this->aliasManager; $codePrinter->outputBlankLine(); $class = false; $interface = false; - foreach ($this->_ir as $topStatement) { + foreach ($this->ir as $topStatement) { switch ($topStatement['type']) { case 'class': if ($interface || $class) { throw new CompilerException("More than one class defined in the same file", $topStatement); } $class = true; - $this->compileClass($compilationContext, $this->_namespace, $topStatement); + $this->compileClass($compilationContext, $this->namespace, $topStatement); break; case 'interface': @@ -894,7 +894,7 @@ public function compile(Compiler $compiler, StringsManager $stringsManager) throw new CompilerException("More than one class defined in the same file", $topStatement); } $class = true; - $this->compileClass($compilationContext, $this->_namespace, $topStatement); + $this->compileClass($compilationContext, $this->namespace, $topStatement); break; case 'comment': @@ -904,20 +904,20 @@ public function compile(Compiler $compiler, StringsManager $stringsManager) } /* ensure functions are handled last */ - foreach ($this->_functionDefinitions as $funcDef) { + foreach ($this->functionDefinitions as $funcDef) { $this->compileFunction($compilationContext, $funcDef); } /* apply headers */ $this->applyClassHeaders($compilationContext); - $classDefinition = $this->_classDefinition; + $classDefinition = $this->classDefinition; if (!$classDefinition) { - $this->_ir = null; + $this->ir = null; return; } - $classDefinition->setOriginalNode($this->_originalNode); + $classDefinition->setOriginalNode($this->originalNode); $completeName = $classDefinition->getCompleteName(); @@ -968,13 +968,13 @@ public function compile(Compiler $compiler, StringsManager $stringsManager) /** * Add to file compiled */ - $this->_compiledFile = $path . '.c'; - $this->_ir = null; + $this->compiledFile = $path . '.c'; + $this->ir = null; } public function applyClassHeaders(CompilationContext $compilationContext) { - $classDefinition = $this->_classDefinition; + $classDefinition = $this->classDefinition; $separators = str_repeat('../', count(explode('\\', $classDefinition->getCompleteName())) - 1); @@ -1006,8 +1006,8 @@ public function applyClassHeaders(CompilationContext $compilationContext) } } - if (count($this->_headerCBlocks) > 0) { - $code .= implode($this->_headerCBlocks, PHP_EOL) . PHP_EOL; + if (count($this->headerCBlocks) > 0) { + $code .= implode($this->headerCBlocks, PHP_EOL) . PHP_EOL; } /** @@ -1024,7 +1024,7 @@ public function applyClassHeaders(CompilationContext $compilationContext) */ protected function getFullName($name) { - return Utils::getFullName($name, $this->_namespace, $this->_aliasManager); + return fqcn($name, $this->namespace, $this->aliasManager); } /** @@ -1034,33 +1034,36 @@ protected function getFullName($name) */ public function getFilePath() { - return $this->_filePath; + return $this->filePath; } /** - * @param array $types - * @return array|null + * Create returns type list. + * + * @param array $types + * @param bool $annotated + * @return array */ - protected function createReturnsType(array $types) + protected function createReturnsType(array $types, $annotated = false) { if (!$types) { return null; } - $list = array(); + $list = []; foreach ($types as $type) { - $list[] = array( - 'type' => 'return-type-parameter', + $list[] = [ + 'type' => $annotated ? 'return-type-annotation' : 'return-type-paramater', 'data-type' => $type == 'mixed' ? 'variable' : $type, - 'mandatory' => false - ); + 'mandatory' => false, + ]; } - return array( + return [ 'type' => 'return-type', 'list' => $list, 'void' => empty($list), - ); + ]; } } diff --git a/Library/CompilerFileAnonymous.php b/Library/CompilerFileAnonymous.php index 3a28a62518..4378915c2f 100644 --- a/Library/CompilerFileAnonymous.php +++ b/Library/CompilerFileAnonymous.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/Config.php b/Library/Config.php index 7e47e1a39d..122f87076b 100644 --- a/Library/Config.php +++ b/Library/Config.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir; @@ -116,6 +114,7 @@ public function __construct() * Factory method to create a Config instence from the $_SERVER['argv']. * * @return Config + * @throws Exception */ public static function fromServer() { diff --git a/Library/ConfigException.php b/Library/ConfigException.php index 49b532adc4..c9a6dc4335 100644 --- a/Library/ConfigException.php +++ b/Library/ConfigException.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/DependencyMap.php b/Library/DependencyMap.php index ea4c241501..8686921261 100644 --- a/Library/DependencyMap.php +++ b/Library/DependencyMap.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/Detectors/ForValueUseDetector.php b/Library/Detectors/ForValueUseDetector.php index 2582487191..0f6fae459a 100644 --- a/Library/Detectors/ForValueUseDetector.php +++ b/Library/Detectors/ForValueUseDetector.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Detectors; diff --git a/Library/Detectors/ReadDetector.php b/Library/Detectors/ReadDetector.php index c8e547f660..0ea2671428 100644 --- a/Library/Detectors/ReadDetector.php +++ b/Library/Detectors/ReadDetector.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Detectors; @@ -34,7 +32,6 @@ public function detect($variable, array $expression) /* Remove branch from variable name */ $pos = strpos($variable, Variable::BRANCH_MAGIC); if ($pos > -1) { - $branchId = intval(substr($variable, $pos + strlen(Variable::BRANCH_MAGIC))); $variable = substr($variable, 0, $pos); } diff --git a/Library/Detectors/WriteDetector.php b/Library/Detectors/WriteDetector.php index c2aa6bfe3d..bab96707bc 100644 --- a/Library/Detectors/WriteDetector.php +++ b/Library/Detectors/WriteDetector.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Detectors; @@ -24,9 +22,9 @@ */ class WriteDetector { - protected $_detectionFlags = 0; + protected $detectionFlags = 0; - protected $_mutations = array(); + protected $mutations = array(); const DETECT_NONE = 0; @@ -58,7 +56,7 @@ public function detect($variable, array $statements) */ public function setDetectionFlags($flags) { - $this->_detectionFlags = $flags; + $this->detectionFlags = $flags; } /** @@ -69,10 +67,10 @@ public function setDetectionFlags($flags) */ public function increaseMutations($variable) { - if (isset($this->_mutations[$variable])) { - $this->_mutations[$variable]++; + if (isset($this->mutations[$variable])) { + $this->mutations[$variable]++; } else { - $this->_mutations[$variable] = 1; + $this->mutations[$variable] = 1; } return $this; } @@ -85,8 +83,8 @@ public function increaseMutations($variable) */ public function getNumberOfMutations($variable) { - if (isset($this->_mutations[$variable])) { - return $this->_mutations[$variable]; + if (isset($this->mutations[$variable])) { + return $this->mutations[$variable]; } return 0; } @@ -103,7 +101,7 @@ public function passLetStatement(array $statement) $this->passExpression($assignment['expr']); } $this->increaseMutations($assignment['variable']); - if (($this->_detectionFlags & self::DETECT_VALUE_IN_ASSIGNMENT) == self::DETECT_VALUE_IN_ASSIGNMENT) { + if (($this->detectionFlags & self::DETECT_VALUE_IN_ASSIGNMENT) == self::DETECT_VALUE_IN_ASSIGNMENT) { if (isset($assignment['expr'])) { if ($assignment['expr']['type'] == 'variable') { $this->increaseMutations($assignment['expr']['value']); @@ -123,7 +121,7 @@ public function passCall(array $expression) { if (isset($expression['parameters'])) { foreach ($expression['parameters'] as $parameter) { - $usePass = ($this->_detectionFlags & self::DETECT_PARAM_PASS) == self::DETECT_PARAM_PASS; + $usePass = ($this->detectionFlags & self::DETECT_PARAM_PASS) == self::DETECT_PARAM_PASS; if ($usePass && $parameter['parameter']['type'] == 'variable') { $this->increaseMutations($parameter['parameter']['value']); } else { @@ -141,7 +139,7 @@ public function passCall(array $expression) public function passArray(array $expression) { foreach ($expression['left'] as $item) { - $usePass = ($this->_detectionFlags & self::DETECT_ARRAY_USE) == self::DETECT_ARRAY_USE; + $usePass = ($this->detectionFlags & self::DETECT_ARRAY_USE) == self::DETECT_ARRAY_USE; if ($usePass && $item['value']['type'] == 'variable') { $this->increaseMutations($item['value']['value']); } else { @@ -159,7 +157,7 @@ public function passNew(array $expression) { if (isset($expression['parameters'])) { foreach ($expression['parameters'] as $parameter) { - $usePass = ($this->_detectionFlags & self::DETECT_PARAM_PASS) == self::DETECT_PARAM_PASS; + $usePass = ($this->detectionFlags & self::DETECT_PARAM_PASS) == self::DETECT_PARAM_PASS; if ($usePass && $parameter['parameter']['type'] == 'variable') { $this->increaseMutations($parameter['parameter']['value']); } else { diff --git a/Library/Di/ContainerAwareTrait.php b/Library/Di/ContainerAwareTrait.php new file mode 100644 index 0000000000..c86707dbde --- /dev/null +++ b/Library/Di/ContainerAwareTrait.php @@ -0,0 +1,123 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Di; + +use League\Container\Container; +use League\Container\ReflectionContainer; +use Psr\Container\ContainerInterface; +use Zephir\Exception\ContainerException; +use Zephir\Exception\InvalidCallException; +use Zephir\Exception\UnknownPropertyException; +use Zephir\Support\PropertyAccessor; + +/** + * Zephir\Di\ContainerAwareTrait + * + * @package Zephir\Di + * + * @property-read \Zephir\Environment $environment + */ +trait ContainerAwareTrait +{ + use PropertyAccessor { + PropertyAccessor::__get as protected missingMethod; + } + + /** + * The Dependency Injection container. + * + * @var ContainerInterface|Container + */ + private $container; + + /** + * Latest container build. + * + * @var ContainerInterface|null + */ + private static $default; + + /** + * ContainerAwareTrait constructor. + * + * @param ContainerInterface|Container|null $container + */ + public function __construct(ContainerInterface $container = null) + { + if ($container == null) { + $container = Singleton::getDefault() ?: $this->createContainer(); + } + + Singleton::setDefault($container); + $this->setContainer($container); + } + + /** + * {@inheritdoc} + * + * @see InjectionAwareInterface + * @return Container + * + * @throws ContainerException + */ + public function getContainer() + { + if ($this->container instanceof ContainerInterface) { + return $this->container; + } + + throw new ContainerException('No container implementation has been set.'); + } + + /** + * {@inheritdoc} + * + * @see InjectionAwareInterface + * @param ContainerInterface|Container $container + * @return void + */ + public function setContainer(ContainerInterface $container) + { + $this->container = $container; + } + + protected function createContainer(Container $container = null) + { + $container = $container ?: new Container(); + + // Required to enable auto wiring + $container->delegate(new ReflectionContainer()); + + return $container; + } + + /** + * Magic method to get services using internal container. + * + * @param string $name + * + * @return mixed + * + * @throws InvalidCallException + * @throws UnknownPropertyException + */ + public function __get($name) + { + $container = $this->getContainer(); + + if ($container && $container->has($name)) { + return $container->get($name); + } + + return $this->missingMethod($name); + } +} diff --git a/Library/Di/InjectionAwareInterface.php b/Library/Di/InjectionAwareInterface.php new file mode 100644 index 0000000000..b371cf8336 --- /dev/null +++ b/Library/Di/InjectionAwareInterface.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Di; + +use Psr\Container\ContainerInterface; + +/** + * Zephir\Di\InjectionAwareInterface + * + * @package Zephir\Di + */ +interface InjectionAwareInterface +{ + /** + * Set a container + * + * @param ContainerInterface $container + * @return void + */ + public function setContainer(ContainerInterface $container); + + /** + * Get the container + * + * @return ContainerInterface + */ + public function getContainer(); +} diff --git a/Library/Di/ServiceProviderInterface.php b/Library/Di/ServiceProviderInterface.php new file mode 100644 index 0000000000..d6ca0a0302 --- /dev/null +++ b/Library/Di/ServiceProviderInterface.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Di; + +use League\Container\Container; +use Psr\Container\ContainerInterface; + +/** + * Zephir\Di\ServiceProviderInterface + * + * @package Zephir\Di + */ +interface ServiceProviderInterface +{ + /** + * Registers a service provider. + * + * @param ContainerInterface|Container $container + * @return void + */ + public function register(ContainerInterface $container); +} diff --git a/Library/Di/Singleton.php b/Library/Di/Singleton.php new file mode 100644 index 0000000000..60b0c8a3fb --- /dev/null +++ b/Library/Di/Singleton.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Di; + +use League\Container\Container; +use Psr\Container\ContainerInterface; + +/** + * Zephir\Di\Singleton + * + * @package Zephir + */ +final class Singleton +{ + /** + * Latest container build. + * + * @var ContainerInterface|null + */ + private static $default; + + /** + * Set a default dependency injection container to be obtained into static methods. + * + * @param ContainerInterface|Container $container + * @return void + */ + public static function setDefault(ContainerInterface $container) + { + self::$default = $container; + } + + /** + * Return the latest container created. + * + * @return ContainerInterface|Container|null + */ + public static function getDefault() + { + return self::$default; + } + + /** + * Resets the internal default container. + * + * @return void + */ + public static function reset() + { + self::$default = null; + } +} diff --git a/Library/Documentation.php b/Library/Documentation.php index b7471d6276..dd2998319f 100644 --- a/Library/Documentation.php +++ b/Library/Documentation.php @@ -1,53 +1,48 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; use Zephir\Commands\CommandInterface; +use Zephir\Di\ContainerAwareTrait; +use Zephir\Di\InjectionAwareInterface; use Zephir\Documentation\File; -use Zephir\Documentation\Theme; use Zephir\Documentation\NamespaceAccessor; +use Zephir\Documentation\Theme; +use Zephir\Exception\InvalidArgumentException; /** * Documentation Generator */ -class Documentation +class Documentation implements InjectionAwareInterface { + use ContainerAwareTrait { + ContainerAwareTrait::__construct as protected __DiInject; + } + protected $outputDirectory; - /** - * @var Config - */ + /** @var Config */ protected $config; - /** - * @var CompilerFile[] - */ + /** @var CompilerFile[] */ protected $classes; - /** - * @var Theme - */ + /** @var Theme */ protected $theme; - /** - * @var Logger - */ + /** @var Logger */ protected $logger; - /** - * @var CommandInterface - */ + /** @var CommandInterface */ protected $command; protected $baseUrl; @@ -55,15 +50,20 @@ class Documentation protected $themesDirectories; /** - * @param CompilerFile[] $classes - * @param Config $config - * @param Logger $logger + * Documentation constructor. + * + * @param CompilerFile[] $classes + * @param Config $config + * @param Logger $logger * @param CommandInterface $command + * * @throws ConfigException * @throws Exception */ public function __construct(array $classes, Config $config, Logger $logger, CommandInterface $command) { + $this->__DiInject(); + ksort($classes); $this->config = $config; @@ -77,13 +77,13 @@ public function __construct(array $classes, Config $config, Logger $logger, Comm throw new ConfigException("Theme configuration is not present"); } - $themeDir = $this->__findThemeDirectory($themeConfig, $config, $command); + $themeDir = $this->findThemeDirectory($themeConfig, $command); if (!file_exists($themeDir)) { throw new ConfigException("There is no theme named " . $themeConfig["name"]); } - $outputDir = $this->__findOutputDirectory($themeConfig, $config, $command); + $outputDir = $this->findOutputDirectory($command); if (!$outputDir) { throw new ConfigException("Api path (output directory) is not configured"); @@ -101,11 +101,11 @@ public function __construct(array $classes, Config $config, Logger $logger, Comm throw new Exception("Can't write output directory $outputDir"); } - $themeConfig["options"] = $this->__prepareThemeOptions($themeConfig, $command); + $themeConfig["options"] = $this->prepareThemeOptions($themeConfig, $command); $this->theme = new Theme($themeDir, $outputDir, $themeConfig, $config, $this); - $this->baseUrl = $this->__parseBaseUrl($config, $command); + $this->baseUrl = $this->parseBaseUrl($command); } /** @@ -119,7 +119,7 @@ public function __construct(array $classes, Config $config, Logger $logger, Comm * @return array * @throws Exception */ - private function __prepareThemeOptions($themeConfig, CommandInterface $command) + private function prepareThemeOptions($themeConfig, CommandInterface $command) { $optionsFromCommand = $command->getParameter("theme-options"); @@ -161,14 +161,11 @@ private function __prepareThemeOptions($themeConfig, CommandInterface $command) * => if not ; check if config config[api][path] was given * * - * @param $themeConfig - * @param Config $config * @param CommandInterface $command + * * @return null|string - * @throws ConfigException - * @throws Exception */ - private function __findOutputDirectory($themeConfig, Config $config, CommandInterface $command) + private function findOutputDirectory(CommandInterface $command) { $outputDir = $command->getParameter("output-directory"); @@ -192,16 +189,15 @@ private function __findOutputDirectory($themeConfig, Config $config, CommandInte * - the command line argument base-url * - or the config config["api"]["base-url"] * - * @param Config $config - * @param CommandInterface $command + * @param CommandInterface $command * @return mixed|string */ - private function __parseBaseUrl(Config $config, CommandInterface $command) + private function parseBaseUrl(CommandInterface $command) { $baseUrl = $command->getParameter("base-url"); if (!$baseUrl) { - $baseUrl = $config->get("base-url", "api"); + $baseUrl = $this->config->get("base-url", "api"); } return $baseUrl; @@ -216,51 +212,65 @@ private function __parseBaseUrl(Config $config, CommandInterface $command) * search the theme from the name ($config['api']['theme']['name'] in the theme directories, * if nothing was found, we look in the zephir install dir default themes (templates/Api/themes) * - * @param $themeConfig - * @param Config $config - * @param CommandInterface $command + * @param array $themeConfig + * @param CommandInterface $command * @return null|string + * + * @throws InvalidArgumentException * @throws ConfigException - * @throws Exception */ - private function __findThemeDirectory($themeConfig, Config $config, CommandInterface $command) + private function findThemeDirectory($themeConfig, CommandInterface $command) { - // check if there are additional theme paths in the config - $themeDirectoriesConfig = $config->get("theme-directories", "api"); + $themeDirectoriesConfig = $this->config->get("theme-directories", "api"); if ($themeDirectoriesConfig) { if (is_array($themeDirectoriesConfig)) { $themesDirectories = $themeDirectoriesConfig; } else { - throw new ConfigException("invalid value for theme config 'theme-directories'"); + throw new InvalidArgumentException("Invalid value for theme config 'theme-directories'"); } } else { - $themesDirectories = array(); + $themesDirectories = []; } - $themesDirectories[] = ZEPHIRPATH . "/templates/Api/themes"; - $this->themesDirectories = $themesDirectories; + /** @var Environment $environment */ + $environment = $this->container->get(Environment::class); + + $themesDirectories[] = $environment->getPath('templates/Api/themes'); + $this->themesDirectories = $themesDirectories; // check if the path was set from the command $themePath = $command->getParameter("theme-path"); - if (null!==$themePath) { + if (null !== $themePath) { + echo $themePath, PHP_EOL; if (file_exists($themePath) && is_dir($themePath)) { return $themePath; } else { - throw new Exception("Invalid value for option 'theme-path' : the theme '$themePath' was not found or is not a valid theme."); + throw new InvalidArgumentException( + sprintf( + "Invalid value for option 'theme-path': the theme '%s' was not found or is not a valid theme.", + $themePath + ) + ); } } if (!isset($themeConfig["name"]) || !$themeConfig["name"]) { - throw new ConfigException("There is no theme neither in the the theme config nor as a command line argument"); + throw new ConfigException( + 'There is no theme neither in the the theme config nor as a command line argument' + ); } return $this->findThemePathByName($themeConfig["name"]); } /** - * search if a theme by its name, return the absolute path to it if it exists - * @param $name + * Search a theme by its name. + * + * Return the path to it if it exists. Otherwise NULL. + * + * @param string $name + * @return string|null */ public function findThemePathByName($name) { @@ -268,9 +278,12 @@ public function findThemePathByName($name) $path = null; foreach ($this->themesDirectories as $themeDir) { - $dir = rtrim($themeDir, "/") . "/"; - $path = realpath($dir . $name); - if ($path) { + $path = rtrim($themeDir, '\\/') . DIRECTORY_SEPARATOR . $name; + if (strpos($path, 'phar://') !== 0) { + $path = realpath($path); + } + + if (is_dir($path)) { break; } } @@ -307,10 +320,11 @@ public function build() } - if ($this->baseUrl) { - $sitemapFile = new File\Sitemap($this->baseUrl, $this->classes, $byNamespace); - $this->theme->drawFile($sitemapFile); - } + /** @var Environment $environment */ + $environment = $this->container->get(Environment::class); + + $sitemapFile = new File\Sitemap($environment->getPath(), $this->baseUrl, $this->classes, $byNamespace); + $this->theme->drawFile($sitemapFile); // namespaces files (namespaces.html) $nsfile = new File\NamespacesFile($this->config, $namespaceAccessor); diff --git a/Library/Documentation/AbstractFile.php b/Library/Documentation/AbstractFile.php index 2ff750c47c..b304014909 100644 --- a/Library/Documentation/AbstractFile.php +++ b/Library/Documentation/AbstractFile.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation; diff --git a/Library/Documentation/Annotation.php b/Library/Documentation/Annotation.php index b8d46b0d70..3593d2bd7f 100644 --- a/Library/Documentation/Annotation.php +++ b/Library/Documentation/Annotation.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation; diff --git a/Library/Documentation/Annotation/Link.php b/Library/Documentation/Annotation/Link.php index e925bc4fd9..b05230368a 100644 --- a/Library/Documentation/Annotation/Link.php +++ b/Library/Documentation/Annotation/Link.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation\Annotation; diff --git a/Library/Documentation/Annotation/ReturnAnnotation.php b/Library/Documentation/Annotation/ReturnAnnotation.php index a0a5939296..f6638d3473 100644 --- a/Library/Documentation/Annotation/ReturnAnnotation.php +++ b/Library/Documentation/Annotation/ReturnAnnotation.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation\Annotation; diff --git a/Library/Documentation/Annotation/See.php b/Library/Documentation/Annotation/See.php index 25afb29063..e0159db5d0 100644 --- a/Library/Documentation/Annotation/See.php +++ b/Library/Documentation/Annotation/See.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation\Annotation; diff --git a/Library/Documentation/Docblock.php b/Library/Documentation/Docblock.php index ce56e455d2..8ae15bf6bc 100644 --- a/Library/Documentation/Docblock.php +++ b/Library/Documentation/Docblock.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation; diff --git a/Library/Documentation/DocblockParser.php b/Library/Documentation/DocblockParser.php index 6b6f1d7cee..31d6b8ec96 100644 --- a/Library/Documentation/DocblockParser.php +++ b/Library/Documentation/DocblockParser.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation; diff --git a/Library/Documentation/File/ClassFile.php b/Library/Documentation/File/ClassFile.php index 6fd1054cc5..0e0fdef3fc 100644 --- a/Library/Documentation/File/ClassFile.php +++ b/Library/Documentation/File/ClassFile.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation\File; diff --git a/Library/Documentation/File/ClassesFile.php b/Library/Documentation/File/ClassesFile.php index 44c4d44dae..8b5f1809cb 100644 --- a/Library/Documentation/File/ClassesFile.php +++ b/Library/Documentation/File/ClassesFile.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation\File; diff --git a/Library/Documentation/File/IndexFile.php b/Library/Documentation/File/IndexFile.php index f236c72ae9..16a382f940 100644 --- a/Library/Documentation/File/IndexFile.php +++ b/Library/Documentation/File/IndexFile.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation\File; diff --git a/Library/Documentation/File/NamespaceFile.php b/Library/Documentation/File/NamespaceFile.php index ea3fdcafcb..b23674755c 100644 --- a/Library/Documentation/File/NamespaceFile.php +++ b/Library/Documentation/File/NamespaceFile.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation\File; diff --git a/Library/Documentation/File/NamespacesFile.php b/Library/Documentation/File/NamespacesFile.php index 6f0d5361e6..1ed6665515 100644 --- a/Library/Documentation/File/NamespacesFile.php +++ b/Library/Documentation/File/NamespacesFile.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation\File; diff --git a/Library/Documentation/File/Sitemap.php b/Library/Documentation/File/Sitemap.php index 4dba277b8c..d513971920 100644 --- a/Library/Documentation/File/Sitemap.php +++ b/Library/Documentation/File/Sitemap.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation\File; @@ -20,26 +18,28 @@ class Sitemap extends AbstractFile protected $classes; protected $namespaces; protected $baseUrl; + private $baseDir; - public function __construct($baseUrl, $classList, $namespaceList) + public function __construct($baseDir, $baseUrl, $classList, $namespaceList) { $this->classes = $classList; $this->namespaces = $namespaceList; $this->baseUrl = rtrim($baseUrl, "/") . "/"; + $this->baseDir = $baseDir; } public function getTemplateName() { - return ZEPHIRPATH . "/templates/Api/sitemap.php"; + return $this->baseDir . "/templates/Api/sitemap.php"; } public function getData() { - return array( + return [ "classes" => $this->classes, "namespaces" => $this->namespaces, "baseUrl" => $this->baseUrl, - ); + ]; } public function getOutputFile() diff --git a/Library/Documentation/File/SourceFile.php b/Library/Documentation/File/SourceFile.php index afa4546117..f7f86624c5 100644 --- a/Library/Documentation/File/SourceFile.php +++ b/Library/Documentation/File/SourceFile.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation\File; diff --git a/Library/Documentation/NamespaceAccessor.php b/Library/Documentation/NamespaceAccessor.php index 255358f1b1..103a0eb917 100644 --- a/Library/Documentation/NamespaceAccessor.php +++ b/Library/Documentation/NamespaceAccessor.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation; @@ -63,7 +61,6 @@ public function build() $isRoot = false; } else { $previous = null; - $isRoot = false; $isRoot = true; } $actualStr.= $n; diff --git a/Library/Documentation/NamespaceHelper.php b/Library/Documentation/NamespaceHelper.php index 071c9d132b..84ecb53b62 100644 --- a/Library/Documentation/NamespaceHelper.php +++ b/Library/Documentation/NamespaceHelper.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation; diff --git a/Library/Documentation/Template.php b/Library/Documentation/Template.php index 575c4e9e53..2005dcb3bd 100644 --- a/Library/Documentation/Template.php +++ b/Library/Documentation/Template.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Documentation; use Zephir\Config; @@ -23,8 +32,6 @@ class Template public function __construct(Theme $theme, $data, $template, $nestedLevel = 0) { - - // todo clean buffer before exception if ($nestedLevel > 800) { throw new Exception("Recursive inclusion detected in theme creation"); @@ -176,7 +183,7 @@ public function parse() private function __getTemplatePath($fileName) { - if ("/" == $fileName{0}) { + if ("/" == $fileName{0} || strpos($fileName, 'phar://') === 0) { return $fileName; } diff --git a/Library/Documentation/Theme.php b/Library/Documentation/Theme.php index 2809fff135..57a1e1c7f3 100644 --- a/Library/Documentation/Theme.php +++ b/Library/Documentation/Theme.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Documentation; @@ -189,11 +187,8 @@ public function buildJsonClassDefinition($classList, NamespaceAccessor $nsA) } } - - $tree = $nsA->getNamespaceTree(); $namespaces = $nsA->getByNamespace(); - foreach ($namespaces as $ns) { $subclasses = array(); $subnamespaces = array(); diff --git a/Library/Environment.php b/Library/Environment.php new file mode 100644 index 0000000000..4ebde17343 --- /dev/null +++ b/Library/Environment.php @@ -0,0 +1,222 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir; + +use Psr\Container\ContainerInterface; +use Zephir\Di\ContainerAwareTrait; +use Zephir\Di\InjectionAwareInterface; +use Zephir\Exception\InvalidArgumentException; + +/** + * Zephir\Environment + * + * @package Zephir + */ +final class Environment implements InjectionAwareInterface +{ + use ContainerAwareTrait { + ContainerAwareTrait::__construct as protected __DiInject; + } + + /** + * The base path for the application. + * + * @var string + */ + protected $basePath; + + /** + * ServiceRegistrator constructor. + * + * @param string|null $basePath + * @param ContainerInterface|null $container + */ + public function __construct($basePath, ContainerInterface $container = null) + { + $this->__DiInject($container); + + $this->getContainer()->share(\get_class($this), $this); + $this->setBasePath(empty($basePath) ? \dirname(__DIR__) : $basePath); + } + + /** + * Set the base path for the Zephir installation. + * + * @param string $basePath + * @return void + * + * @throws InvalidArgumentException + */ + public function setBasePath($basePath) + { + $message = 'Unable to locate Zephir installation path.' . PHP_EOL . PHP_EOL . + 'Double check the Zephir installation. When installing from sources,' . PHP_EOL . + 'it is enough to specify ZEPHIRDIR environment variable to the proper' . PHP_EOL . + 'Zephir installation path.' . PHP_EOL . PHP_EOL . + 'Current ZEPHIRDIR value is: "%s"' . PHP_EOL . + 'The base path used by the Zephir compiler is: "%s"'; + + if (!\is_string($basePath) || !\is_dir($basePath) || !\file_exists($basePath)) { + throw new InvalidArgumentException( + sprintf($message, \getenv('ZEPHIRDIR'), \is_scalar($basePath) ? $basePath : \gettype($basePath)) + ); + } + + $this->basePath = rtrim($basePath, '\\/'); + $this->registerPaths(); + } + + /** + * Initialize all of the application paths in the DI container. + * + * @return void + */ + protected function registerPaths() + { + $this->getContainer()->share('paths', (object) [ + 'base' => $this->getPath(), + 'templates' => $this->getPath('templates'), + 'kernels' => $this->getPath('kernels'), + 'prototypes' => $this->getPath('prototypes'), + ]); + } + + /** + * Get the path to the Zephir installation. + * + * @param string $path + * @return string + */ + public function getPath($path = '') + { + return $this->basePath . ($path ? DIRECTORY_SEPARATOR . $path : $path); + } + + /** + * Get the path to the templates. + * + * @param string $path + * @return string + */ + public function getTemplatesPath($path = '') + { + $basePath = $this->getContainer()->get('paths')->templates; + + return $basePath . ($path ? DIRECTORY_SEPARATOR . $path : $path); + } + + /** + * Get the path to the kernels. + * + * @param string $path + * @return string + */ + public function getKernelsPath($path = '') + { + $basePath = $this->getContainer()->get('paths')->kernels; + + return $basePath . ($path ? DIRECTORY_SEPARATOR . $path : $path); + } + + /** + * Get the path to the prototypes. + * + * @param string $path + * @return string + */ + public function getPrototypesPath($path = '') + { + $basePath = $this->getContainer()->get('paths')->prototypes; + + return $basePath . ($path ? DIRECTORY_SEPARATOR . $path : $path); + } + + /** + * Checks if currently running under MS Windows. + * + * @return bool + */ + public function isWindows() + { + return 'WIN' === \strtoupper(\substr(PHP_OS, 0, 3)); + } + + /** + * Checks if currently running under macOs. + * + * @return bool + */ + public function isMacOs() + { + return 'DARWIN' === \strtoupper(\substr(PHP_OS, 0, 6)); + } + + /** + * Checks if currently running under BSD based OS. + * + * @link https://en.wikipedia.org/wiki/List_of_BSD_operating_systems + * @return bool + */ + public function isBsd() + { + return false !== \stristr(\strtolower(PHP_OS), 'bsd'); + } + + /** + * Checks if current PHP is thread safe. + * + * @return bool + */ + public function isZts() + { + if (\defined('PHP_ZTS') && PHP_ZTS == 1) { + return true; + } + + \ob_start(); + \phpinfo(INFO_GENERAL); + + return (bool) \preg_match('/Thread\s*Safety\s*enabled/i', \strip_tags(\ob_get_clean())); + } + + /** + * Resolves Windows release folder. + * + * @return string + */ + public function getWindowsReleaseDir() + { + if ($this->isZts()) { + if (PHP_INT_SIZE === 4) { + // 32-bit version of PHP + return "ext\\Release_TS"; + } elseif (PHP_INT_SIZE === 8) { + // 64-bit version of PHP + return "ext\\x64\\Release_TS"; + } else { + // fallback + return "ext\\Release_TS"; + } + } else { + if (PHP_INT_SIZE === 4) { + // 32-bit version of PHP + return "ext\\Release"; + } elseif (PHP_INT_SIZE === 8) { + // 64-bit version of PHP + return "ext\\x64\\Release"; + } else { + // fallback + return "ext\\Release"; + } + } + } +} diff --git a/Library/EventsManager.php b/Library/EventsManager.php index a55c954d38..c43f651f44 100644 --- a/Library/EventsManager.php +++ b/Library/EventsManager.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/Exception.php b/Library/Exception.php index 28cb0682fb..d2a6902ae4 100644 --- a/Library/Exception.php +++ b/Library/Exception.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/Exception/BadMethodCallException.php b/Library/Exception/BadMethodCallException.php index 02ee147ffe..761a401ac5 100644 --- a/Library/Exception/BadMethodCallException.php +++ b/Library/Exception/BadMethodCallException.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Exception; diff --git a/Library/Exception/ContainerException.php b/Library/Exception/ContainerException.php new file mode 100644 index 0000000000..20d23ce79d --- /dev/null +++ b/Library/Exception/ContainerException.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Exception; + +use Psr\Container\ContainerExceptionInterface; + +/** + * Zephir\Exception\ContainerException + * + * @package Zephir\Exception + */ +class ContainerException extends RuntimeException implements ContainerExceptionInterface +{ +} diff --git a/Library/Exception/ExceptionExtraAwareTrait.php b/Library/Exception/ExceptionExtraAwareTrait.php index b38971eb26..5ef0d53bf2 100644 --- a/Library/Exception/ExceptionExtraAwareTrait.php +++ b/Library/Exception/ExceptionExtraAwareTrait.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Exception; diff --git a/Library/Exception/ExceptionInterface.php b/Library/Exception/ExceptionInterface.php index d2198b0530..265f03d27c 100644 --- a/Library/Exception/ExceptionInterface.php +++ b/Library/Exception/ExceptionInterface.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Exception; diff --git a/Library/Exception/IllegalStateException.php b/Library/Exception/IllegalStateException.php index ac1a96bee2..fbd5b8d865 100644 --- a/Library/Exception/IllegalStateException.php +++ b/Library/Exception/IllegalStateException.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Exception; diff --git a/Library/Exception/InvalidArgumentException.php b/Library/Exception/InvalidArgumentException.php index 6e0e3974f7..0e3f836205 100644 --- a/Library/Exception/InvalidArgumentException.php +++ b/Library/Exception/InvalidArgumentException.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Exception; diff --git a/Library/Exception/InvalidCallException.php b/Library/Exception/InvalidCallException.php new file mode 100644 index 0000000000..5e800c6d3b --- /dev/null +++ b/Library/Exception/InvalidCallException.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Exception; + +/** + * Zephir\Exception\InvalidCallException + * + * @package Zephir\Exception + */ +class InvalidCallException extends LogicException +{ +} diff --git a/Library/Exception/LogicException.php b/Library/Exception/LogicException.php new file mode 100644 index 0000000000..28aaa29e6c --- /dev/null +++ b/Library/Exception/LogicException.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Exception; + +/** + * Zephir\Exception\LogicException + * + * @package Zephir\Exception + */ +class LogicException extends \LogicException implements ExceptionInterface +{ + use ExceptionExtraAwareTrait; +} diff --git a/Library/Exception/OutOfBoundsException.php b/Library/Exception/OutOfBoundsException.php index eee95991d3..7b3e4e5564 100644 --- a/Library/Exception/OutOfBoundsException.php +++ b/Library/Exception/OutOfBoundsException.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Exception; diff --git a/Library/Exception/RuntimeException.php b/Library/Exception/RuntimeException.php index 4798347da5..fed13bf1de 100644 --- a/Library/Exception/RuntimeException.php +++ b/Library/Exception/RuntimeException.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Exception; diff --git a/Library/Exception/UnknownPropertyException.php b/Library/Exception/UnknownPropertyException.php new file mode 100644 index 0000000000..cecfb2af4f --- /dev/null +++ b/Library/Exception/UnknownPropertyException.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Exception; + +/** + * Zephir\Exception\UnknownPropertyException + * + * @package Zephir\Exception + */ +class UnknownPropertyException extends LogicException +{ +} diff --git a/Library/Exception/ValidationException.php b/Library/Exception/ValidationException.php index 4258974240..c1fba13e23 100644 --- a/Library/Exception/ValidationException.php +++ b/Library/Exception/ValidationException.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Exception; diff --git a/Library/Expression.php b/Library/Expression.php index 418d557f46..80186261a9 100644 --- a/Library/Expression.php +++ b/Library/Expression.php @@ -1,98 +1,96 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; use Zephir\Compiler\CompilerException; +use Zephir\Expression\Closure; +use Zephir\Expression\ClosureArrow; +use Zephir\Expression\Constants; +use Zephir\Expression\NativeArray; +use Zephir\Expression\NativeArrayAccess; +use Zephir\Expression\PropertyAccess; +use Zephir\Expression\PropertyDynamicAccess; +use Zephir\Expression\Reference; +use Zephir\Expression\StaticConstantAccess; +use Zephir\Expression\StaticPropertyAccess; use Zephir\Operators\Arithmetical\AddOperator; -use Zephir\Operators\Arithmetical\SubOperator; -use Zephir\Operators\Arithmetical\MulOperator; use Zephir\Operators\Arithmetical\DivOperator; use Zephir\Operators\Arithmetical\ModOperator; -use Zephir\Operators\Other\ShortTernaryOperator; -use Zephir\Operators\Unary\MinusOperator; -use Zephir\Operators\Unary\NotOperator; -use Zephir\Operators\Logical\AndOperator; -use Zephir\Operators\Logical\OrOperator; -use Zephir\Operators\Comparison\EqualsOperator; -use Zephir\Operators\Comparison\NotEqualsOperator; -use Zephir\Operators\Comparison\IdenticalOperator; -use Zephir\Operators\Comparison\NotIdenticalOperator; -use Zephir\Operators\Comparison\LessEqualOperator; -use Zephir\Operators\Comparison\LessOperator; -use Zephir\Operators\Comparison\GreaterOperator; -use Zephir\Operators\Comparison\GreaterEqualOperator; -use Zephir\Operators\Bitwise\BitwiseNotOperator; +use Zephir\Operators\Arithmetical\MulOperator; +use Zephir\Operators\Arithmetical\SubOperator; use Zephir\Operators\Bitwise\BitwiseAndOperator; +use Zephir\Operators\Bitwise\BitwiseNotOperator; use Zephir\Operators\Bitwise\BitwiseOrOperator; use Zephir\Operators\Bitwise\BitwiseXorOperator; use Zephir\Operators\Bitwise\ShiftLeftOperator; use Zephir\Operators\Bitwise\ShiftRightOperator; -use Zephir\Operators\Other\NewInstanceOperator; -use Zephir\Operators\Other\NewInstanceTypeOperator; +use Zephir\Operators\Comparison\EqualsOperator; +use Zephir\Operators\Comparison\GreaterEqualOperator; +use Zephir\Operators\Comparison\GreaterOperator; +use Zephir\Operators\Comparison\IdenticalOperator; +use Zephir\Operators\Comparison\LessEqualOperator; +use Zephir\Operators\Comparison\LessOperator; +use Zephir\Operators\Comparison\NotEqualsOperator; +use Zephir\Operators\Comparison\NotIdenticalOperator; +use Zephir\Operators\Logical\AndOperator; +use Zephir\Operators\Logical\OrOperator; +use Zephir\Operators\Other\CastOperator; use Zephir\Operators\Other\CloneOperator; use Zephir\Operators\Other\ConcatOperator; use Zephir\Operators\Other\EmptyOperator; -use Zephir\Operators\Other\IssetOperator; use Zephir\Operators\Other\FetchOperator; -use Zephir\Operators\Other\LikelyOperator; -use Zephir\Operators\Other\UnlikelyOperator; -use Zephir\Operators\Other\TernaryOperator; use Zephir\Operators\Other\InstanceOfOperator; -use Zephir\Operators\Other\RequireOperator; -use Zephir\Operators\Other\TypeOfOperator; -use Zephir\Operators\Other\CastOperator; -use Zephir\Operators\Other\RangeInclusiveOperator; +use Zephir\Operators\Other\IssetOperator; +use Zephir\Operators\Other\LikelyOperator; +use Zephir\Operators\Other\NewInstanceOperator; +use Zephir\Operators\Other\NewInstanceTypeOperator; use Zephir\Operators\Other\RangeExclusiveOperator; +use Zephir\Operators\Other\RangeInclusiveOperator; +use Zephir\Operators\Other\RequireOperator; +use Zephir\Operators\Other\ShortTernaryOperator; +use Zephir\Operators\Other\TernaryOperator; use Zephir\Operators\Other\TypeHintOperator; -use Zephir\Expression\Closure; -use Zephir\Expression\ClosureArrow; -use Zephir\Expression\Constants; -use Zephir\Expression\Reference; -use Zephir\Expression\NativeArray; -use Zephir\Expression\NativeArrayAccess; -use Zephir\Expression\PropertyAccess; -use Zephir\Expression\PropertyDynamicAccess; -use Zephir\Expression\StaticConstantAccess; -use Zephir\Expression\StaticPropertyAccess; +use Zephir\Operators\Other\TypeOfOperator; +use Zephir\Operators\Other\UnlikelyOperator; +use Zephir\Operators\Unary\MinusOperator; +use Zephir\Operators\Unary\NotOperator; /** - * Expressions + * Zephir\Expressions * * Represents an expression. Most language constructs in a language are expressions + * + * @package Zephir */ class Expression { - protected $_expression; + protected $expression; - protected $_expecting = true; + protected $expecting = true; - protected $_readOnly = false; + protected $readOnly = false; - protected $_noisy = true; + protected $noisy = true; /** * @deprecated * @var bool */ - protected $_stringOperation = false; + protected $stringOperation = false; - /** - * @var Variable - */ - protected $_expectingVariable; + /** @var Variable */ + protected $expectingVariable; - protected $_evalMode = false; + protected $evalMode = false; /** * Expression constructor @@ -101,7 +99,7 @@ class Expression */ public function __construct(array $expression) { - $this->_expression = $expression; + $this->expression = $expression; } /** @@ -111,7 +109,7 @@ public function __construct(array $expression) */ public function getExpression() { - return $this->_expression; + return $this->expression; } /** @@ -123,8 +121,8 @@ public function getExpression() */ public function setExpectReturn($expecting, Variable $expectingVariable = null) { - $this->_expecting = $expecting; - $this->_expectingVariable = $expectingVariable; + $this->expecting = $expecting; + $this->expectingVariable = $expectingVariable; } /** @@ -134,7 +132,7 @@ public function setExpectReturn($expecting, Variable $expectingVariable = null) */ public function setReadOnly($readOnly) { - $this->_readOnly = $readOnly; + $this->readOnly = $readOnly; } /** @@ -144,7 +142,7 @@ public function setReadOnly($readOnly) */ public function isReadOnly() { - return $this->_readOnly; + return $this->readOnly; } /** @@ -155,7 +153,7 @@ public function isReadOnly() */ public function isExpectingReturn() { - return $this->_expecting; + return $this->expecting; } /** @@ -166,7 +164,7 @@ public function isExpectingReturn() */ public function getExpectingVariable() { - return $this->_expectingVariable; + return $this->expectingVariable; } /** @@ -176,7 +174,7 @@ public function getExpectingVariable() */ public function setNoisy($noisy) { - $this->_noisy = $noisy; + $this->noisy = $noisy; } /** @@ -186,7 +184,7 @@ public function setNoisy($noisy) */ public function isNoisy() { - return $this->_noisy; + return $this->noisy; } /** @@ -198,7 +196,7 @@ public function isNoisy() */ public function setStringOperation($stringOperation) { - $this->_stringOperation = $stringOperation; + $this->stringOperation = $stringOperation; } /** @@ -210,7 +208,7 @@ public function setStringOperation($stringOperation) */ public function isStringOperation() { - return $this->_stringOperation; + return $this->stringOperation; } /** @@ -220,7 +218,7 @@ public function isStringOperation() */ public function setEvalMode($evalMode) { - $this->_evalMode = $evalMode; + $this->evalMode = $evalMode; } /** @@ -235,9 +233,9 @@ public function emptyArray($expression, CompilationContext $compilationContext) /** * Resolves the symbol that expects the value */ - if ($this->_expecting) { - if ($this->_expectingVariable) { - $symbolVariable = & $this->_expectingVariable; + if ($this->expecting) { + if ($this->expectingVariable) { + $symbolVariable = & $this->expectingVariable; $symbolVariable->initVariant($compilationContext); } else { $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression); @@ -272,7 +270,7 @@ public function emptyArray($expression, CompilationContext $compilationContext) */ public function compile(CompilationContext $compilationContext) { - $expression = $this->_expression; + $expression = $this->expression; $type = $expression['type']; $compilableExpression = null; @@ -481,7 +479,7 @@ public function compile(CompilationContext $compilationContext) case 'concat': $expr = new ConcatOperator(); - $expr->setExpectReturn($this->_expecting, $this->_expectingVariable); + $expr->setExpectReturn($this->expecting, $this->expectingVariable); return $expr->compile($expression, $compilationContext); case 'irange': @@ -498,7 +496,7 @@ public function compile(CompilationContext $compilationContext) } $numberPrints = $compilationContext->codePrinter->getNumberPrints(); $expr = new Expression($expression['left']); - $expr->setExpectReturn($this->_expecting, $this->_expectingVariable); + $expr->setExpectReturn($this->expecting, $this->expectingVariable); $resolved = $expr->compile($compilationContext); if (($compilationContext->codePrinter->getNumberPrints() - $numberPrints) <= 1) { if (strpos($resolved->getCode(), ' ') !== false) { @@ -514,7 +512,7 @@ public function compile(CompilationContext $compilationContext) case 'type-hint': $expr = new TypeHintOperator(); $expr->setReadOnly($this->isReadOnly()); - $expr->setExpectReturn($this->_expecting, $this->_expectingVariable); + $expr->setExpectReturn($this->expecting, $this->expectingVariable); return $expr->compile($expression, $compilationContext); case 'instanceof': @@ -532,11 +530,11 @@ public function compile(CompilationContext $compilationContext) case 'short-ternary': $expr = new ShortTernaryOperator(); $expr->setReadOnly($this->isReadOnly()); - $expr->setExpectReturn($this->_expecting, $this->_expectingVariable); + $expr->setExpectReturn($this->expecting, $this->expectingVariable); return $expr->compile($expression, $compilationContext); case 'likely': - if (!$this->_evalMode) { + if (!$this->evalMode) { throw new CompilerException("'likely' operator can only be used in evaluation expressions", $expression); } $expr = new LikelyOperator(); @@ -544,7 +542,7 @@ public function compile(CompilationContext $compilationContext) return $expr->compile($expression, $compilationContext); case 'unlikely': - if (!$this->_evalMode) { + if (!$this->evalMode) { throw new CompilerException("'unlikely' operator can only be used in evaluation expressions", $expression); } $expr = new UnlikelyOperator(); @@ -579,7 +577,7 @@ public function compile(CompilationContext $compilationContext) throw new CompilerException("Unknown expression passed as compilableExpression", $expression); } $compilableExpression->setReadOnly($this->isReadOnly()); - $compilableExpression->setExpectReturn($this->_expecting, $this->_expectingVariable); + $compilableExpression->setExpectReturn($this->expecting, $this->expectingVariable); return $compilableExpression->compile($expression, $compilationContext); } } diff --git a/Library/Expression/Builder/AbstractBuilder.php b/Library/Expression/Builder/AbstractBuilder.php index e390660d5c..4425688e14 100644 --- a/Library/Expression/Builder/AbstractBuilder.php +++ b/Library/Expression/Builder/AbstractBuilder.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder; /** diff --git a/Library/Expression/Builder/BuilderFactory.php b/Library/Expression/Builder/BuilderFactory.php index dbff7090ca..635fc3265d 100644 --- a/Library/Expression/Builder/BuilderFactory.php +++ b/Library/Expression/Builder/BuilderFactory.php @@ -1,50 +1,45 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder; use Zephir\Expression\Builder\Factory\OperatorsFactory; use Zephir\Expression\Builder\Factory\StatementsFactory; /** - * Class BuilderFactory + * Zephir\Expression\Builder\BuilderFactory + * * @package Zephir\Expression\Builder */ class BuilderFactory { - /** - * @var OperatorsFactory - */ + /** @var OperatorsFactory */ protected $operatorsFactory; - /** - * @var StatementsFactory - */ + /** @var StatementsFactory */ protected $statementsFactory; - /** - * @var self - */ - protected static $_instance; + /** @var self */ + protected static $instance; /** * @return self */ public static function getInstance() { - if (!static::$_instance) { - static::$_instance = new static(); + if (!static::$instance) { + static::$instance = new static(); } - return static::$_instance; + return static::$instance; } /** diff --git a/Library/Expression/Builder/Factory/OperatorsFactory.php b/Library/Expression/Builder/Factory/OperatorsFactory.php index 899977ff52..f23e0fc88c 100644 --- a/Library/Expression/Builder/Factory/OperatorsFactory.php +++ b/Library/Expression/Builder/Factory/OperatorsFactory.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Factory; use Zephir\Expression\Builder\AbstractBuilder; diff --git a/Library/Expression/Builder/Factory/StatementsFactory.php b/Library/Expression/Builder/Factory/StatementsFactory.php index 2c03157f4c..c30cbc5490 100644 --- a/Library/Expression/Builder/Factory/StatementsFactory.php +++ b/Library/Expression/Builder/Factory/StatementsFactory.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Factory; use Zephir\Expression\Builder\AbstractBuilder; diff --git a/Library/Expression/Builder/Operators/AbstractOperator.php b/Library/Expression/Builder/Operators/AbstractOperator.php index 02ac926d44..cf61bdc8db 100644 --- a/Library/Expression/Builder/Operators/AbstractOperator.php +++ b/Library/Expression/Builder/Operators/AbstractOperator.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Operators; use Zephir\Expression\Builder\AbstractBuilder; @@ -19,5 +19,4 @@ */ abstract class AbstractOperator extends AbstractBuilder { - } diff --git a/Library/Expression/Builder/Operators/AssignPropertyOperator.php b/Library/Expression/Builder/Operators/AssignPropertyOperator.php index 33e465ae95..0a6b5b1964 100644 --- a/Library/Expression/Builder/Operators/AssignPropertyOperator.php +++ b/Library/Expression/Builder/Operators/AssignPropertyOperator.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Operators; use Zephir\Expression\Builder\AbstractBuilder; diff --git a/Library/Expression/Builder/Operators/AssignVariableOperator.php b/Library/Expression/Builder/Operators/AssignVariableOperator.php index 8a883c2b45..e00d1edb3e 100644 --- a/Library/Expression/Builder/Operators/AssignVariableOperator.php +++ b/Library/Expression/Builder/Operators/AssignVariableOperator.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Operators; use Zephir\Expression\Builder\AbstractBuilder; diff --git a/Library/Expression/Builder/Operators/BinaryOperator.php b/Library/Expression/Builder/Operators/BinaryOperator.php index 6c8c640f47..816e711d05 100644 --- a/Library/Expression/Builder/Operators/BinaryOperator.php +++ b/Library/Expression/Builder/Operators/BinaryOperator.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Operators; use Zephir\Expression\Builder\AbstractBuilder; diff --git a/Library/Expression/Builder/Operators/RawOperator.php b/Library/Expression/Builder/Operators/RawOperator.php index 496748fb2c..25c919cc17 100644 --- a/Library/Expression/Builder/Operators/RawOperator.php +++ b/Library/Expression/Builder/Operators/RawOperator.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Operators; /** diff --git a/Library/Expression/Builder/Operators/UnaryOperator.php b/Library/Expression/Builder/Operators/UnaryOperator.php index 45efc66a6b..c7f474dbfe 100644 --- a/Library/Expression/Builder/Operators/UnaryOperator.php +++ b/Library/Expression/Builder/Operators/UnaryOperator.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Operators; use Zephir\Expression\Builder\AbstractBuilder; diff --git a/Library/Expression/Builder/RawExpression.php b/Library/Expression/Builder/RawExpression.php index eb5509fdc3..1b563a8ed7 100644 --- a/Library/Expression/Builder/RawExpression.php +++ b/Library/Expression/Builder/RawExpression.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder; /** diff --git a/Library/Expression/Builder/Statements/AbstractStatement.php b/Library/Expression/Builder/Statements/AbstractStatement.php index e9e9f797f2..b0344616e1 100644 --- a/Library/Expression/Builder/Statements/AbstractStatement.php +++ b/Library/Expression/Builder/Statements/AbstractStatement.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Statements; use Zephir\Expression\Builder\AbstractBuilder; @@ -19,5 +19,4 @@ */ abstract class AbstractStatement extends AbstractBuilder { - } diff --git a/Library/Expression/Builder/Statements/CallFunctionStatement.php b/Library/Expression/Builder/Statements/CallFunctionStatement.php index 058d45a06f..fdd7846ed3 100644 --- a/Library/Expression/Builder/Statements/CallFunctionStatement.php +++ b/Library/Expression/Builder/Statements/CallFunctionStatement.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Statements; use Zephir\FunctionCall; diff --git a/Library/Expression/Builder/Statements/CallMethodStatement.php b/Library/Expression/Builder/Statements/CallMethodStatement.php index caebff9d34..575a9a7e4b 100644 --- a/Library/Expression/Builder/Statements/CallMethodStatement.php +++ b/Library/Expression/Builder/Statements/CallMethodStatement.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Statements; /** diff --git a/Library/Expression/Builder/Statements/CallStaticStatement.php b/Library/Expression/Builder/Statements/CallStaticStatement.php index d63d59f21d..270ed0a9fa 100644 --- a/Library/Expression/Builder/Statements/CallStaticStatement.php +++ b/Library/Expression/Builder/Statements/CallStaticStatement.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Statements; /** diff --git a/Library/Expression/Builder/Statements/IfStatement.php b/Library/Expression/Builder/Statements/IfStatement.php index ce847338e6..4fe7c1eec7 100644 --- a/Library/Expression/Builder/Statements/IfStatement.php +++ b/Library/Expression/Builder/Statements/IfStatement.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Statements; use Zephir\Expression\Builder\Operators\AbstractOperator; diff --git a/Library/Expression/Builder/Statements/LetStatement.php b/Library/Expression/Builder/Statements/LetStatement.php index a859e637c8..0812ad9483 100644 --- a/Library/Expression/Builder/Statements/LetStatement.php +++ b/Library/Expression/Builder/Statements/LetStatement.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Statements; /** diff --git a/Library/Expression/Builder/Statements/RawStatement.php b/Library/Expression/Builder/Statements/RawStatement.php index cca2b49e5e..4499ea3a20 100644 --- a/Library/Expression/Builder/Statements/RawStatement.php +++ b/Library/Expression/Builder/Statements/RawStatement.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Statements; /** diff --git a/Library/Expression/Builder/Statements/StatementsBlock.php b/Library/Expression/Builder/Statements/StatementsBlock.php index 6f23141efa..9f7a9d62e7 100644 --- a/Library/Expression/Builder/Statements/StatementsBlock.php +++ b/Library/Expression/Builder/Statements/StatementsBlock.php @@ -1,14 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir\Expression\Builder\Statements; use Zephir\Expression\Builder\AbstractBuilder; diff --git a/Library/Expression/Closure.php b/Library/Expression/Closure.php index 755cc469ec..dc3aa050a4 100644 --- a/Library/Expression/Closure.php +++ b/Library/Expression/Closure.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Expression; diff --git a/Library/Expression/ClosureArrow.php b/Library/Expression/ClosureArrow.php index a000e7af60..109218e299 100644 --- a/Library/Expression/ClosureArrow.php +++ b/Library/Expression/ClosureArrow.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Expression; diff --git a/Library/Expression/Constants.php b/Library/Expression/Constants.php index 4bc396fc27..0e32553279 100644 --- a/Library/Expression/Constants.php +++ b/Library/Expression/Constants.php @@ -1,47 +1,40 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Expression; -use Zephir\Types; -use Zephir\Variable; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Compiler\CompilerException; use Zephir\LiteralCompiledExpression; -use Zephir\Utils; +use Zephir\Variable; +use function Zephir\add_slashes; /** - * Constants + * Zephir\Expression\Constants * * Resolves PHP or Zephir constants into C-Code + * + * @package Zephir\Expression */ class Constants { - /** - * @var bool - */ - protected $_expecting = true; + /** @var bool */ + protected $expecting = true; - /** - * @var bool - */ - protected $_readOnly = false; + /** @var bool */ + protected $readOnly = false; - /** - * @var Variable - */ - protected $_expectingVariable; + /** @var Variable */ + protected $expectingVariable; /** * Sets if the variable must be resolved into a direct variable symbol @@ -52,8 +45,8 @@ class Constants */ public function setExpectReturn($expecting, Variable $expectingVariable = null) { - $this->_expecting = $expecting; - $this->_expectingVariable = $expectingVariable; + $this->expecting = $expecting; + $this->expectingVariable = $expectingVariable; } /** @@ -63,7 +56,7 @@ public function setExpectReturn($expecting, Variable $expectingVariable = null) */ public function setReadOnly($readOnly) { - $this->_readOnly = $readOnly; + $this->readOnly = $readOnly; } /** @@ -161,7 +154,7 @@ public function compile(array $expression, CompilationContext $compilationContex return new LiteralCompiledExpression('double', $constantName, $expression); case 'string': - return new LiteralCompiledExpression('string', Utils::addSlashes($constantName, true, Types::STRING), $expression); + return new LiteralCompiledExpression('string', add_slashes($constantName), $expression); case 'object': throw new CompilerException('?'); @@ -176,14 +169,14 @@ public function compile(array $expression, CompilationContext $compilationContex case '__CLASS__': return new CompiledExpression( 'string', - Utils::addSlashes($compilationContext->classDefinition->getCompleteName(), true, Types::STRING), + add_slashes($compilationContext->classDefinition->getCompleteName()), $expression ); //no break case '__NAMESPACE__': return new CompiledExpression( 'string', - Utils::addSlashes($compilationContext->classDefinition->getNamespace(), true, Types::STRING), + add_slashes($compilationContext->classDefinition->getNamespace()), $expression ); //no break @@ -207,8 +200,8 @@ public function compile(array $expression, CompilationContext $compilationContex return new LiteralCompiledExpression('null', null, $expression); } - if ($this->_expecting && $this->_expectingVariable) { - $symbolVariable = $this->_expectingVariable; + if ($this->expecting && $this->expectingVariable) { + $symbolVariable = $this->expectingVariable; $symbolVariable->setLocalOnly(false); $symbolVariable->setMustInitNull(true); diff --git a/Library/Expression/NativeArray.php b/Library/Expression/NativeArray.php index 8ab0a5ef56..3783283f8d 100644 --- a/Library/Expression/NativeArray.php +++ b/Library/Expression/NativeArray.php @@ -1,39 +1,39 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Expression; -use Zephir\Variable; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Compiler\CompilerException; use Zephir\Expression; use Zephir\GlobalConstant; +use Zephir\Variable; /** - * NativeArray + * Zephir\Expression\NativeArray * * Resolves expressions that create arrays + * + * @package Zephir\Expression */ class NativeArray { - protected $_expecting = true; + protected $expecting = true; - protected $_readOnly = false; + protected $readOnly = false; - protected $_noisy = true; + protected $noisy = true; - protected $_expectingVariable; + protected $expectingVariable; /** * Sets if the variable must be resolved into a direct variable symbol @@ -44,8 +44,8 @@ class NativeArray */ public function setExpectReturn($expecting, Variable $expectingVariable = null) { - $this->_expecting = $expecting; - $this->_expectingVariable = $expectingVariable; + $this->expecting = $expecting; + $this->expectingVariable = $expectingVariable; } /** @@ -55,7 +55,7 @@ public function setExpectReturn($expecting, Variable $expectingVariable = null) */ public function setReadOnly($readOnly) { - $this->_readOnly = $readOnly; + $this->readOnly = $readOnly; } /** @@ -65,7 +65,7 @@ public function setReadOnly($readOnly) */ public function setNoisy($noisy) { - $this->_noisy = $noisy; + $this->noisy = $noisy; } /** @@ -170,9 +170,9 @@ public function compile($expression, CompilationContext $compilationContext) /** * Resolves the symbol that expects the value */ - if ($this->_expecting) { - if ($this->_expectingVariable) { - $symbolVariable = $this->_expectingVariable; + if ($this->expecting) { + if ($this->expectingVariable) { + $symbolVariable = $this->expectingVariable; $symbolVariable->initVariant($compilationContext); if ($symbolVariable->getType() != 'variable' && $symbolVariable->getType() != 'array') { throw new CompilerException("Cannot use variable type: " . $symbolVariable->getType() . " as an array", $expression); diff --git a/Library/Expression/NativeArrayAccess.php b/Library/Expression/NativeArrayAccess.php index 8e6d0f30cf..e428df3d7e 100644 --- a/Library/Expression/NativeArrayAccess.php +++ b/Library/Expression/NativeArrayAccess.php @@ -1,50 +1,42 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Expression; -use Zephir\Variable; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Compiler\CompilerException; use Zephir\Expression; +use Zephir\Variable; /** - * NativeArrayAccess + * Zephir\Expression\NativeArrayAccess * * Resolves expressions that read array indexes + * + * @package Zephir\Expression */ class NativeArrayAccess { - /** - * @var bool - */ - protected $_expecting = true; + /** @var bool */ + protected $expecting = true; - /** - * @var bool - */ - protected $_readOnly = false; + /** @var bool */ + protected $readOnly = false; - /** - * @var Variable|null - */ - protected $_expectingVariable; + /** @var Variable|null */ + protected $expectingVariable; - /** - * @var boolean - */ - protected $_noisy = true; + /** @var boolean */ + protected $noisy = true; /** * Sets if the variable must be resolved into a direct variable symbol @@ -55,8 +47,8 @@ class NativeArrayAccess */ public function setExpectReturn($expecting, Variable $expectingVariable = null) { - $this->_expecting = $expecting; - $this->_expectingVariable = $expectingVariable; + $this->expecting = $expecting; + $this->expectingVariable = $expectingVariable; } /** @@ -66,7 +58,7 @@ public function setExpectReturn($expecting, Variable $expectingVariable = null) */ public function setReadOnly($readOnly) { - $this->_readOnly = $readOnly; + $this->readOnly = $readOnly; } /** @@ -76,7 +68,7 @@ public function setReadOnly($readOnly) */ public function setNoisy($noisy) { - $this->_noisy = $noisy; + $this->noisy = $noisy; } /** @@ -86,9 +78,9 @@ public function setNoisy($noisy) */ protected function _accessStringOffset($expression, Variable $variableVariable, CompilationContext $compilationContext) { - if ($this->_expecting) { - if ($this->_expectingVariable) { - $symbolVariable = $this->_expectingVariable; + if ($this->expecting) { + if ($this->expectingVariable) { + $symbolVariable = $this->expectingVariable; if ($symbolVariable->getType() != 'char' && $symbolVariable->getType() != 'uchar') { $symbolVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('uchar', $compilationContext); } @@ -160,16 +152,14 @@ protected function _accessDimensionArray($expression, Variable $variableVariable } } - $codePrinter = $compilationContext->codePrinter; - /** * Resolves the symbol that expects the value */ $readOnly = false; - $symbolVariable = $this->_expectingVariable; + $symbolVariable = $this->expectingVariable; - if ($this->_readOnly) { - if ($this->_expecting && $this->_expectingVariable) { + if ($this->readOnly) { + if ($this->expecting && $this->expectingVariable) { /** * If a variable is assigned once in the method, we try to promote it * to a read only variable @@ -193,7 +183,7 @@ protected function _accessDimensionArray($expression, Variable $variableVariable if (!$readOnly) { if ($symbolVariable->getName() != 'return_value') { $symbolVariable->observeVariant($compilationContext); - $this->_readOnly = false; + $this->readOnly = false; } else { $symbolVariable = $compilationContext->symbolTable->getTempNonTrackedUninitializedVariable('variable', $compilationContext, $expression); } @@ -202,7 +192,7 @@ protected function _accessDimensionArray($expression, Variable $variableVariable $symbolVariable = $compilationContext->symbolTable->getTempNonTrackedUninitializedVariable('variable', $compilationContext, $expression); } } else { - if ($this->_expecting && $this->_expectingVariable) { + if ($this->expecting && $this->expectingVariable) { /** * If a variable is assigned once in the method, we try to promote it * to a read only variable @@ -226,7 +216,7 @@ protected function _accessDimensionArray($expression, Variable $variableVariable if (!$readOnly) { if ($symbolVariable->getName() != 'return_value') { $symbolVariable->observeVariant($compilationContext); - $this->_readOnly = false; + $this->readOnly = false; } else { $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext, $expression); } @@ -248,14 +238,14 @@ protected function _accessDimensionArray($expression, Variable $variableVariable */ $symbolVariable->setDynamicTypes('undefined'); - if ($this->_readOnly || $readOnly) { - if ($this->_noisy) { + if ($this->readOnly || $readOnly) { + if ($this->noisy) { $flags = 'PH_NOISY | PH_READONLY'; } else { $flags = 'PH_READONLY'; } } else { - if ($this->_noisy) { + if ($this->noisy) { $flags = 'PH_NOISY'; } else { $flags = '0'; diff --git a/Library/Expression/PropertyAccess.php b/Library/Expression/PropertyAccess.php index 825e659c9a..68df7b51c7 100644 --- a/Library/Expression/PropertyAccess.php +++ b/Library/Expression/PropertyAccess.php @@ -1,41 +1,41 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Expression; -use Zephir\Variable; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Compiler\CompilerException; use Zephir\Expression; +use Zephir\Variable; /** - * PropertyAccess + * Zephir\Expression\PropertyAccess * * Resolves expressions that read properties + * + * @package Zephir\Expression */ class PropertyAccess { - protected $_expecting = true; + /** @var boolean */ + protected $expecting = true; - protected $_readOnly = false; + /** @var boolean */ + protected $readOnly = false; - protected $_expectingVariable; + protected $expectingVariable; - /** - * @var boolean - */ - protected $_noisy = true; + /** @var boolean */ + protected $noisy = true; /** * Sets if the variable must be resolved into a direct variable symbol @@ -46,8 +46,8 @@ class PropertyAccess */ public function setExpectReturn($expecting, Variable $expectingVariable = null) { - $this->_expecting = $expecting; - $this->_expectingVariable = $expectingVariable; + $this->expecting = $expecting; + $this->expectingVariable = $expectingVariable; } /** @@ -57,7 +57,7 @@ public function setExpectReturn($expecting, Variable $expectingVariable = null) */ public function setReadOnly($readOnly) { - $this->_readOnly = $readOnly; + $this->readOnly = $readOnly; } /** @@ -67,7 +67,7 @@ public function setReadOnly($readOnly) */ public function setNoisy($noisy) { - $this->_noisy = $noisy; + $this->noisy = $noisy; } /** @@ -79,8 +79,6 @@ public function setNoisy($noisy) */ public function compile($expression, CompilationContext $compilationContext) { - $codePrinter = $compilationContext->codePrinter; - $propertyAccess = $expression; $expr = new Expression($propertyAccess['left']); @@ -160,7 +158,7 @@ public function compile($expression, CompilationContext $compilationContext) if ($classDefinition == $currentClassDefinition) { if ($propertyDefinition->isPrivate()) { $declarationDefinition = $propertyDefinition->getClassDefinition(); - if ($declarationDefinition != $currentClassDefinition) { + if ($declarationDefinition !== $currentClassDefinition) { throw new CompilerException("Attempt to access private property '" . $property . "' outside of its declared class context: '" . $declarationDefinition->getCompleteName() . "'", $expression); } } @@ -169,7 +167,7 @@ public function compile($expression, CompilationContext $compilationContext) } else { if ($propertyDefinition->isPrivate()) { $declarationDefinition = $propertyDefinition->getClassDefinition(); - if ($declarationDefinition != $currentClassDefinition) { + if ($declarationDefinition !== $currentClassDefinition) { throw new CompilerException("Attempt to access private property '" . $property . "' outside of its declared class context: '" . $declarationDefinition->getCompleteName() . "'", $expression); } } @@ -183,9 +181,9 @@ public function compile($expression, CompilationContext $compilationContext) */ $readOnly = false; $makeSymbolVariable = false; - if ($this->_expecting) { - if ($this->_expectingVariable) { - $symbolVariable = $this->_expectingVariable; + if ($this->expecting) { + if ($this->expectingVariable) { + $symbolVariable = $this->expectingVariable; /** * If a variable is assigned once in the method, we try to promote it @@ -210,13 +208,13 @@ public function compile($expression, CompilationContext $compilationContext) if (!$readOnly) { if ($symbolVariable->getName() != 'return_value') { $symbolVariable->observeVariant($compilationContext); - $this->_readOnly = false; + $this->readOnly = false; } else { $makeSymbolVariable = true; } } - $this->_readOnly = false; + $this->readOnly = false; } else { $makeSymbolVariable = true; } @@ -224,7 +222,7 @@ public function compile($expression, CompilationContext $compilationContext) $makeSymbolVariable = true; } - $readOnly = $this->_readOnly || $readOnly; + $readOnly = $this->readOnly || $readOnly; $useOptimized = $classDefinition == $currentClassDefinition; if (!$compilationContext->backend->isZE3()) { $readOnly = $useOptimized && $readOnly; diff --git a/Library/Expression/PropertyDynamicAccess.php b/Library/Expression/PropertyDynamicAccess.php index b5ba84c84b..54d28d528d 100644 --- a/Library/Expression/PropertyDynamicAccess.php +++ b/Library/Expression/PropertyDynamicAccess.php @@ -1,43 +1,40 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Expression; -use Zephir\Variable; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Compiler\CompilerException; use Zephir\Expression; -use Zephir\Utils; +use Zephir\Variable; +use function Zephir\add_slashes; /** - * PropertyDynamicAccess + * Zephir\Expression\PropertyDynamicAccess * * Resolves expressions that read properties with a dynamic variable as property + * + * @package Zephir\Expression */ class PropertyDynamicAccess { - protected $_expecting = true; + protected $expecting = true; - protected $_readOnly = false; + protected $readOnly = false; - protected $_expectingVariable; + protected $expectingVariable; - /** - * @var boolean - */ - protected $_noisy = true; + /**@var boolean */ + protected $noisy = true; /** * Sets if the variable must be resolved into a direct variable symbol @@ -48,8 +45,8 @@ class PropertyDynamicAccess */ public function setExpectReturn($expecting, Variable $expectingVariable = null) { - $this->_expecting = $expecting; - $this->_expectingVariable = $expectingVariable; + $this->expecting = $expecting; + $this->expectingVariable = $expectingVariable; } /** @@ -59,7 +56,7 @@ public function setExpectReturn($expecting, Variable $expectingVariable = null) */ public function setReadOnly($readOnly) { - $this->_readOnly = $readOnly; + $this->readOnly = $readOnly; } /** @@ -69,7 +66,7 @@ public function setReadOnly($readOnly) */ public function setNoisy($noisy) { - $this->_noisy = $noisy; + $this->noisy = $noisy; } /** @@ -81,8 +78,6 @@ public function setNoisy($noisy) */ public function compile($expression, CompilationContext $compilationContext) { - $codePrinter = $compilationContext->codePrinter; - $propertyAccess = $expression; $expr = new Expression($propertyAccess['left']); @@ -116,9 +111,9 @@ public function compile($expression, CompilationContext $compilationContext) /** * Resolves the symbol that expects the value */ - if ($this->_expecting) { - if ($this->_expectingVariable) { - $symbolVariable = $this->_expectingVariable; + if ($this->expecting) { + if ($this->expectingVariable) { + $symbolVariable = $this->expectingVariable; if ($symbolVariable->getName() != 'return_value') { $symbolVariable->observeVariant($compilationContext); } else { @@ -143,7 +138,7 @@ public function compile($expression, CompilationContext $compilationContext) $compilationContext->headersManager->add('kernel/object'); - $property = $propertyVariable ? $propertyVariable : Utils::addSlashes($expression['right']['value']); + $property = $propertyVariable ? $propertyVariable : add_slashes($expression['right']['value']); $compilationContext->backend->fetchProperty($symbolVariable, $variableVariable, $property, false, $compilationContext, false); diff --git a/Library/Expression/Reference.php b/Library/Expression/Reference.php index e056ee47d5..69251ba85b 100644 --- a/Library/Expression/Reference.php +++ b/Library/Expression/Reference.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Expression; @@ -22,17 +20,19 @@ use Zephir\Expression; /** - * Reference + * Zephir\Expression\Reference * * Resolves expressions that create arrays + * + * @package Zephir\Expression */ class Reference { - protected $_expecting = true; + protected $expecting = true; - protected $_readOnly = false; + protected $readOnly = false; - protected $_expectingVariable; + protected $expectingVariable; /** * Sets if the variable must be resolved into a direct variable symbol @@ -43,8 +43,8 @@ class Reference */ public function setExpectReturn($expecting, Variable $expectingVariable = null) { - $this->_expecting = $expecting; - $this->_expectingVariable = $expectingVariable; + $this->expecting = $expecting; + $this->expectingVariable = $expectingVariable; } /** @@ -54,7 +54,7 @@ public function setExpectReturn($expecting, Variable $expectingVariable = null) */ public function setReadOnly($readOnly) { - $this->_readOnly = $readOnly; + $this->readOnly = $readOnly; } /** @@ -160,9 +160,9 @@ public function compile($expression, CompilationContext $compilationContext) /** * Resolves the symbol that expects the value */ - if ($this->_expecting) { - if ($this->_expectingVariable) { - $symbolVariable = $this->_expectingVariable; + if ($this->expecting) { + if ($this->expectingVariable) { + $symbolVariable = $this->expectingVariable; if ($symbolVariable->getType() != 'variable') { throw new CompilerException("Cannot use variable type: " . $symbolVariable->getType() . " to store a reference", $expression); } @@ -174,7 +174,7 @@ public function compile($expression, CompilationContext $compilationContext) } $leftExpr = new Expression($expression['left']); - $leftExpr->setReadOnly($this->_readOnly); + $leftExpr->setReadOnly($this->readOnly); $left = $leftExpr->compile($compilationContext); switch ($left->getType()) { diff --git a/Library/Expression/StaticConstantAccess.php b/Library/Expression/StaticConstantAccess.php index c8bd5f95bc..e688ed8411 100644 --- a/Library/Expression/StaticConstantAccess.php +++ b/Library/Expression/StaticConstantAccess.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Expression; diff --git a/Library/Expression/StaticPropertyAccess.php b/Library/Expression/StaticPropertyAccess.php index e7b16fa681..7d1250bca9 100644 --- a/Library/Expression/StaticPropertyAccess.php +++ b/Library/Expression/StaticPropertyAccess.php @@ -1,39 +1,37 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Expression; use Zephir\ClassProperty; -use Zephir\Variable; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Compiler\CompilerException; +use Zephir\Variable; /** - * StaticPropertyAccess + * Zephir\Expression\StaticPropertyAccess * * Resolves class static properties + * + * @package Zephir\Expression */ class StaticPropertyAccess { - protected $_expecting = true; + protected $expecting = true; - protected $_readOnly = false; + protected $readOnly = false; - /** - * @var Variable|null - */ - protected $_expectingVariable; + /** @var Variable|null */ + protected $expectingVariable; /** * Sets if the variable must be resolved into a direct variable symbol @@ -44,8 +42,8 @@ class StaticPropertyAccess */ public function setExpectReturn($expecting, Variable $expectingVariable = null) { - $this->_expecting = $expecting; - $this->_expectingVariable = $expectingVariable; + $this->expecting = $expecting; + $this->expectingVariable = $expectingVariable; } /** @@ -55,7 +53,7 @@ public function setExpectReturn($expecting, Variable $expectingVariable = null) */ public function setReadOnly($readOnly) { - $this->_readOnly = $readOnly; + $this->readOnly = $readOnly; } /** @@ -127,9 +125,9 @@ public function compile($expression, CompilationContext $compilationContext) /** * Resolves the symbol that expects the value */ - if ($this->_expecting) { - if ($this->_expectingVariable) { - $symbolVariable = $this->_expectingVariable; + if ($this->expecting) { + if ($this->expectingVariable) { + $symbolVariable = $this->expectingVariable; if ($symbolVariable->getName() == 'return_value') { $symbolVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext); } @@ -151,13 +149,13 @@ public function compile($expression, CompilationContext $compilationContext) $compilationContext->headersManager->add('kernel/object'); - $readOnly = $this->_readOnly; + $readOnly = $this->readOnly; if (!$readOnly) { if ($symbolVariable->getName() != 'return_value') { $symbolVariable->observeVariant($compilationContext); } } - $compilationContext->backend->fetchStaticProperty($symbolVariable, $classDefinition, $property, $this->_readOnly, $compilationContext); + $compilationContext->backend->fetchStaticProperty($symbolVariable, $classDefinition, $property, $this->readOnly, $compilationContext); return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression); } diff --git a/Library/Fcall/FcallAwareInterface.php b/Library/Fcall/FcallAwareInterface.php index c23be13547..746c43b814 100644 --- a/Library/Fcall/FcallAwareInterface.php +++ b/Library/Fcall/FcallAwareInterface.php @@ -1,20 +1,16 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Fcall; -use Zephir\Fcall\FcallManagerInterface; - /** * Zephir\Fcall\FcallAwareInterface * diff --git a/Library/Fcall/FcallManagerInterface.php b/Library/Fcall/FcallManagerInterface.php index cd072ec7ed..7348aac84b 100644 --- a/Library/Fcall/FcallManagerInterface.php +++ b/Library/Fcall/FcallManagerInterface.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Fcall; diff --git a/Library/FileSystem/HardDisk.php b/Library/FileSystem/HardDisk.php index 8f904709fa..e16bf6e223 100644 --- a/Library/FileSystem/HardDisk.php +++ b/Library/FileSystem/HardDisk.php @@ -1,28 +1,34 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\FileSystem; -use Zephir\Compiler; -use Zephir\Utils; +use Zephir\Di\ContainerAwareTrait; +use Zephir\Di\InjectionAwareInterface; +use Zephir\Version; +use function Zephir\unlink_recursive; /** - * HardDisk + * Zephir\FileSystem\HardDisk + * + * Uses the standard hard-disk as filesystem for temporary operations. * - * Uses the standard hard-disk as filesystem for temporary operations + * @package Zephir\FileSystem */ -class HardDisk +class HardDisk implements InjectionAwareInterface { + use ContainerAwareTrait { + ContainerAwareTrait::__construct as protected __DiInject; + } + protected $basePath; protected $initialized = false; @@ -34,6 +40,8 @@ class HardDisk */ public function __construct($basePath = '.temp/') { + $this->__DiInject(); + $this->basePath = $basePath; } @@ -156,14 +164,13 @@ public function requireFile($path) } /** - * Deletes the temporary directory + * Deletes the temporary directory. + * + * @return void */ public function clean() { - if (is_dir($this->basePath)) { - Utils::recursiveRmDir($this->basePath); - rmdir($this->basePath); - } + unlink_recursive($this->basePath); } /** @@ -181,7 +188,9 @@ public function getHashFile($algorithm, $path, $cache = false) return hash_file($algorithm, $path); } else { $changed = false; - $cacheFile = $this->basePath . Compiler::getCurrentVersion() . DIRECTORY_SEPARATOR . str_replace(array(DIRECTORY_SEPARATOR, ':', '/'), '_', $path) . '.md5'; + $version = $this->container->get(Version::class); + + $cacheFile = $this->basePath . $version . DIRECTORY_SEPARATOR . str_replace([DIRECTORY_SEPARATOR, ':', '/'], '_', $path) . '.md5'; if (!file_exists($cacheFile)) { $hash = hash_file($algorithm, $path); file_put_contents($cacheFile, $hash); diff --git a/Library/FileSystem/Redis.php b/Library/FileSystem/Redis.php index 2dccd4b31f..9ef6756816 100644 --- a/Library/FileSystem/Redis.php +++ b/Library/FileSystem/Redis.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\FileSystem; diff --git a/Library/FunctionCall.php b/Library/FunctionCall.php index 6dd2b31d98..b6b9e6d994 100644 --- a/Library/FunctionCall.php +++ b/Library/FunctionCall.php @@ -1,25 +1,27 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; use Zephir\Compiler\CompilerException; +use Zephir\Di\Singleton; use Zephir\Optimizers\OptimizerAbstract; /** - * FunctionCall + * Zephir\FunctionCall + * * Call functions. By default functions are called in the PHP userland if an optimizer * was not found or there is not a user-handler for it + * + * @package Zephir */ class FunctionCall extends Call { @@ -38,39 +40,37 @@ class FunctionCall extends Call */ const CALL_DYNAMIC_STRING = 3; - protected static $_optimizers = []; + protected static $optimizers = []; - protected static $_functionReflection = []; + protected static $functionReflection = []; - protected static $_optimizerDirectories = []; - - private static $_functionCache = null; + protected static $optimizerDirectories = []; /** * Process the ReflectionFunction for the specified function name * * @param string $funcName * - * @return \ReflectionFunction + * @return \ReflectionFunction|null */ public function getReflector($funcName) { /** * Check if the optimizer is already cached */ - if (!isset(self::$_functionReflection[$funcName])) { + if (!isset(self::$functionReflection[$funcName])) { try { $reflectionFunction = new \ReflectionFunction($funcName); - } catch (\Exception $e) { + } catch (\ReflectionException $e) { $reflectionFunction = null; } - self::$_functionReflection[$funcName] = $reflectionFunction; - $this->_reflection = $reflectionFunction; + self::$functionReflection[$funcName] = $reflectionFunction; + $this->reflection = $reflectionFunction; return $reflectionFunction; } - $reflectionFunction = self::$_functionReflection[$funcName]; - $this->_reflection = $reflectionFunction; + $reflectionFunction = self::$functionReflection[$funcName]; + $this->reflection = $reflectionFunction; return $reflectionFunction; } @@ -226,18 +226,21 @@ protected function optimize($funcName, array $expression, Call $call, Compilatio /** * Check if the optimizer is already cached */ - if (!isset(self::$_optimizers[$funcName])) { - $camelizeFunctionName = Utils::camelize($funcName); + if (!isset(self::$optimizers[$funcName])) { + $camelizeFunctionName = camelize($funcName); /** * Check every optimizer directory for an optimizer */ - foreach (self::$_optimizerDirectories as $directory) { + foreach (self::$optimizerDirectories as $directory) { $path = $directory . DIRECTORY_SEPARATOR . $camelizeFunctionName . 'Optimizer.php'; + $className = 'Zephir\Optimizers\FunctionCall\\' . $camelizeFunctionName . 'Optimizer'; + if (file_exists($path)) { - require_once $path; + if (!class_exists($className, false)) { + require_once $path; + } - $className = 'Zephir\Optimizers\FunctionCall\\' . $camelizeFunctionName . 'Optimizer'; if (!class_exists($className, false)) { throw new Exception("Class {$className} cannot be loaded"); } @@ -248,13 +251,15 @@ protected function optimize($funcName, array $expression, Call $call, Compilatio throw new Exception("Class {$className} must be instance of OptimizerAbstract"); } + $optimizer->setContainer(Singleton::getDefault()); + break; } } - self::$_optimizers[$funcName] = $optimizer; + self::$optimizers[$funcName] = $optimizer; } else { - $optimizer = self::$_optimizers[$funcName]; + $optimizer = self::$optimizers[$funcName]; } if ($optimizer) { @@ -677,7 +682,7 @@ protected function _callDynamic(array $expression, CompilationContext $compilati */ public function compile(Expression $expr, CompilationContext $compilationContext) { - $this->_expression = $expr; + $this->expression = $expr; $expression = $expr->getExpression(); switch ($expression['call-type']) { @@ -697,6 +702,6 @@ public function compile(Expression $expr, CompilationContext $compilationContext */ public static function addOptimizerDir($directory) { - self::$_optimizerDirectories[] = $directory; + self::$optimizerDirectories[] = $directory; } } diff --git a/Library/FunctionDefinition.php b/Library/FunctionDefinition.php index 1836104aff..c4d36dbfca 100644 --- a/Library/FunctionDefinition.php +++ b/Library/FunctionDefinition.php @@ -1,21 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir; diff --git a/Library/GlobalConstant.php b/Library/GlobalConstant.php index 7a7e872671..9ee2f6b285 100644 --- a/Library/GlobalConstant.php +++ b/Library/GlobalConstant.php @@ -1,15 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir; diff --git a/Library/HeadersManager.php b/Library/HeadersManager.php index 7a83f3278f..fad38bbc53 100644 --- a/Library/HeadersManager.php +++ b/Library/HeadersManager.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/LiteralCompiledExpression.php b/Library/LiteralCompiledExpression.php index c81acdd7fe..b7486e0844 100644 --- a/Library/LiteralCompiledExpression.php +++ b/Library/LiteralCompiledExpression.php @@ -1,15 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir; diff --git a/Library/Loader.php b/Library/Loader.php deleted file mode 100644 index c84e0c7fb3..0000000000 --- a/Library/Loader.php +++ /dev/null @@ -1,48 +0,0 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ + namespace Zephir; use Zephir\Compiler\CompilerException; diff --git a/Library/MethodCall.php b/Library/MethodCall.php index 31020bfe6a..9bbf27881b 100644 --- a/Library/MethodCall.php +++ b/Library/MethodCall.php @@ -1,15 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir; @@ -256,7 +255,7 @@ public function compile(Expression $expr, CompilationContext $compilationContext * Private methods must be called in their declaration scope */ if ($classMethod->isPrivate()) { - if ($classMethod->getClassDefinition() != $classDefinition) { + if ($classMethod->getClassDefinition() !== $classDefinition) { throw new CompilerException("Cannot call private method '" . $expression['name'] . "' out of its scope", $expression); } } @@ -392,7 +391,7 @@ public function compile(Expression $expr, CompilationContext $compilationContext } if (isset($method)) { - $this->_reflection = $method; + $this->reflection = $method; } /** diff --git a/Library/MethodCallWarmUp.php b/Library/MethodCallWarmUp.php index 96092f1884..f5fe6fd1db 100644 --- a/Library/MethodCallWarmUp.php +++ b/Library/MethodCallWarmUp.php @@ -1,15 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir; diff --git a/Library/Operators/Arithmetical/AddOperator.php b/Library/Operators/Arithmetical/AddOperator.php index 6ecca4689f..deeed8a8b1 100644 --- a/Library/Operators/Arithmetical/AddOperator.php +++ b/Library/Operators/Arithmetical/AddOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Arithmetical; @@ -20,9 +18,9 @@ */ class AddOperator extends ArithmeticalBaseOperator { - protected $_operator = '+'; + protected $operator = '+'; - protected $_bitOperator = '|'; + protected $bitOperator = '|'; - protected $_zvalOperator = 'zephir_add_function'; + protected $zvalOperator = 'zephir_add_function'; } diff --git a/Library/Operators/Arithmetical/ArithmeticalBaseOperator.php b/Library/Operators/Arithmetical/ArithmeticalBaseOperator.php index 1b2cf6cb1c..f9fdec5c30 100644 --- a/Library/Operators/Arithmetical/ArithmeticalBaseOperator.php +++ b/Library/Operators/Arithmetical/ArithmeticalBaseOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Arithmetical; @@ -18,6 +16,8 @@ use Zephir\Expression; use Zephir\Compiler\CompilerException; use Zephir\CompiledExpression; +use Zephir\Exception; +use Zephir\Variable; /** * BaseOperator @@ -27,15 +27,17 @@ */ class ArithmeticalBaseOperator extends BaseOperator { - protected $_literalOnly = true; + protected $literalOnly = true; /** - * This tries to perform arithmetical operations + * This tries to perform arithmetical operations. + * * Probably gcc/clang will optimize them without this optimization * - * @see http://en.wikipedia.org/wiki/Constant_folding - * @param array $expression - * @param CompilationContext $compilationContext + * @link http://en.wikipedia.org/wiki/Constant_folding + * + * @param array $expression + * @param CompilationContext $compilationContext * @return bool|CompiledExpression */ public function optimizeConstantFolding(array $expression, CompilationContext $compilationContext) @@ -46,7 +48,7 @@ public function optimizeConstantFolding(array $expression, CompilationContext $c if ($compilationContext->config->get('constant-folding', 'optimizations')) { if ($expression['left']['type'] == 'int' && $expression['right']['type'] == 'int') { - switch ($this->_operator) { + switch ($this->operator) { case '+': return new CompiledExpression('int', $expression['left']['value'] + $expression['right']['value'], $expression); @@ -59,7 +61,7 @@ public function optimizeConstantFolding(array $expression, CompilationContext $c } if (($expression['left']['type'] == 'double' && $expression['right']['type'] == 'double') || ($expression['left']['type'] == 'double' && $expression['right']['type'] == 'int') || ($expression['left']['type'] == 'int' && $expression['right']['type'] == 'double')) { - switch ($this->_operator) { + switch ($this->operator) { case '+': return new CompiledExpression('double', $expression['left']['value'] + $expression['right']['value'], $expression); @@ -82,9 +84,9 @@ public function optimizeConstantFolding(array $expression, CompilationContext $c * @param Variable $right * @return string */ - private function getDynamicTypes($left, $right) + private function getDynamicTypes(Variable $left, Variable $right) { - if ($this->_operator == '/') { + if ($this->operator == '/') { return 'double'; } @@ -109,24 +111,25 @@ private function getDynamicTypes($left, $right) /** * Compiles the arithmetical operation * - * @param array $expression - * @param CompilationContext $compilationContext + * @param array $expression + * @param CompilationContext $compilationContext + * @return CompiledExpression + * + * @throws Exception + * @throws CompilerException */ public function compile($expression, CompilationContext $compilationContext) { if (!isset($expression['left'])) { - throw new \Exception("Missing left part of the expression"); + throw new CompilerException('Missing left part of the expression', $expression); } if (!isset($expression['right'])) { - throw new \Exception("Missing right part of the expression"); + throw new CompilerException('Missing right part of the expression', $expression); } - /** - * Check for constant folding optimizations - */ - $optimized = $this->optimizeConstantFolding($expression, $compilationContext); - if ($optimized) { + // Check for constant folding optimizations + if ($optimized = $this->optimizeConstantFolding($expression, $compilationContext)) { return $optimized; } @@ -148,13 +151,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'double': - return new CompiledExpression('double', '((double) ' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('double', '((double) ' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression); @@ -163,18 +166,18 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('double', '(double) (' . $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('double', '(double) (' . $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableRight = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); default: throw new CompilerException("Cannot operate variable('int') with variable('" . $variableRight->getType() . "')", $expression); @@ -196,7 +199,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('long', '(' . $left->getBooleanCode() . ' + ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); default: throw new CompilerException("Cannot operate 'bool' with '" . $right->getType() . "'", $expression); @@ -209,13 +212,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->_operator . ' (double) (' . $right->getCode() . '))', $expression); + return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->operator . ' (double) (' . $right->getCode() . '))', $expression); case 'double': - return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression); @@ -225,15 +228,15 @@ public function compile($expression, CompilationContext $compilationContext) case 'long': case 'ulong': case 'bool': - return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('double', '(double) (' . $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('double', '(double) (' . $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableRight = $compilationContext->backend->getVariableCode($variableRight, $compilationContext); - return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->_operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); + return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); default: throw new CompilerException("Cannot operate variable('double') with variable('" . $variableRight->getType() . "')", $expression); @@ -265,7 +268,7 @@ public function compile($expression, CompilationContext $compilationContext) case 'long': case 'ulong': case 'double': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); @@ -275,15 +278,15 @@ public function compile($expression, CompilationContext $compilationContext) case 'long': case 'ulong': case 'bool': - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('double', '((double) ' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('double', '((double) ' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableRight = $compilationContext->backend->getVariableCode($variableRight, $compilationContext); - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); default: throw new CompilerException("Cannot operate variable('int') with variable('" . $variableRight->getType() . "')", $expression); @@ -301,7 +304,7 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); @@ -310,12 +313,12 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableRight = $compilationContext->backend->getVariableCode($variableRight, $compilationContext); - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); default: throw new CompilerException("Cannot operate variable('char') with variable('" . $variableRight->getType() . "')", $expression); @@ -333,10 +336,10 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); @@ -346,15 +349,15 @@ public function compile($expression, CompilationContext $compilationContext) case 'long': case 'ulong': case 'double': - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_bitOperator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->bitOperator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableRight = $compilationContext->backend->getVariableCode($variableRight, $compilationContext); - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); default: throw new CompilerException("Cannot operate variable('int') with variable('" . $variableRight->getType() . "')", $expression); @@ -372,13 +375,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->_operator . ' (double) ' . $right->getCode() . ')', $expression); + return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->operator . ' (double) ' . $right->getCode() . ')', $expression); case 'double': - return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('double', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); @@ -387,18 +390,18 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('double', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' (double) ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('double', '(' . $variableLeft->getName() . ' ' . $this->operator . ' (double) ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('double', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('double', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_bitOperator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->bitOperator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableRight = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' zephir_get_numberval(' . $variableRight . '))', $expression); default: throw new CompilerException("Cannot operate variable('double') with variable('" . $variableRight->getType() . "')", $expression); @@ -426,7 +429,7 @@ public function compile($expression, CompilationContext $compilationContext) $compilationContext->headersManager->add('kernel/operators'); $expected = $this->getExpected($compilationContext, $expression); - $compilationContext->backend->zvalOperator($this->_zvalOperator, $expected, $variableLeft, $variableRight, $compilationContext); + $compilationContext->backend->zvalOperator($this->zvalOperator, $expected, $variableLeft, $variableRight, $compilationContext); if ($variableLeft->isTemporal()) { $variableLeft->setIdle(true); @@ -455,7 +458,7 @@ public function compile($expression, CompilationContext $compilationContext) case 'ulong': case 'double': $compilationContext->headersManager->add('kernel/operators'); - $op = $this->_operator; + $op = $this->operator; $op1 = $compilationContext->backend->getVariableCode($variableLeft); $op2 = $right->getCode(); @@ -477,14 +480,14 @@ public function compile($expression, CompilationContext $compilationContext) case 'ulong': $compilationContext->headersManager->add('kernel/operators'); $variableLeft = $compilationContext->backend->getVariableCode($variableLeft); - return new CompiledExpression('int', '(zephir_get_numberval(' . $variableLeft . ') ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(zephir_get_numberval(' . $variableLeft . ') ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); break; /* a(var) + a(bool) */ case 'bool': $compilationContext->headersManager->add('kernel/operators'); $variableLeft = $compilationContext->backend->getVariableCode($variableLeft); - return new CompiledExpression('int', '(zephir_get_numberval(' . $variableLeft . ') ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(zephir_get_numberval(' . $variableLeft . ') ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); break; /* a(var) + a(var) */ @@ -493,7 +496,7 @@ public function compile($expression, CompilationContext $compilationContext) $compilationContext->headersManager->add('kernel/operators'); $expected = $this->getExpected($compilationContext, $expression); - $compilationContext->backend->zvalOperator($this->_zvalOperator, $expected, $variableLeft, $variableRight, $compilationContext); + $compilationContext->backend->zvalOperator($this->zvalOperator, $expected, $variableLeft, $variableRight, $compilationContext); if ($variableLeft->isTemporal()) { $variableLeft->setIdle(true); diff --git a/Library/Operators/Arithmetical/DivOperator.php b/Library/Operators/Arithmetical/DivOperator.php index 3e511ce759..8c3411ff9c 100644 --- a/Library/Operators/Arithmetical/DivOperator.php +++ b/Library/Operators/Arithmetical/DivOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Arithmetical; @@ -25,11 +23,11 @@ */ class DivOperator extends ArithmeticalBaseOperator { - protected $_operator = '/'; + protected $operator = '/'; - protected $_bitOperator = '-'; + protected $bitOperator = '-'; - protected $_zvalOperator = 'div_function'; + protected $zvalOperator = 'div_function'; /** * Compiles the arithmetical division operation @@ -112,7 +110,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('long', '(' . $left->getBooleanCode() . ' - ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); default: throw new CompilerException("Cannot operate 'bool' with '" . $right->getType() . "'", $expression); @@ -228,7 +226,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('bool', '(' . $left->getCode() . ', ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); @@ -243,7 +241,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_div_long_double(' . $variableLeft->getName() . ', ' . $variableRight->getName() . ' TSRMLS_CC)', $expression); case 'bool': - return new CompiledExpression('double', 'zephir_safe_div_long_long(' . $variableLeft->getName() . ' ' . $this->_bitOperator . ' ' . $variableRight->getName() . ' TSRMLS_CC)', $expression); + return new CompiledExpression('double', 'zephir_safe_div_long_long(' . $variableLeft->getName() . ' ' . $this->bitOperator . ' ' . $variableRight->getName() . ' TSRMLS_CC)', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); @@ -275,7 +273,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_div_double_long(' . $left->getCode() . ', ' . $right->getCode() . ' TSRMLS_CC)', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); @@ -290,7 +288,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_div_double_long(' . $variableLeft->getName() . ', ' . $variableRight->getName() . ' TSRMLS_CC)', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_bitOperator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->bitOperator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); @@ -352,7 +350,7 @@ public function compile($expression, CompilationContext $compilationContext) $expected = $this->getExpected($compilationContext, $expression); $expectedCode = $compilationContext->backend->getVariableCode($expected); - $compilationContext->codePrinter->output($this->_zvalOperator . '(' . $expectedCode . ', ' . $op1 . ', ' . $op2 . ' TSRMLS_CC);'); + $compilationContext->codePrinter->output($this->zvalOperator . '(' . $expectedCode . ', ' . $op1 . ', ' . $op2 . ' TSRMLS_CC);'); if ($variableLeft->isTemporal()) { $variableLeft->setIdle(true); @@ -411,12 +409,12 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_div_zval_double(' . $variableLeft->getName() . ', ' . $variableRight->getName() . ' TSRMLS_CC)', $expression); case 'bool': - return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->_bitOperator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->bitOperator . ' ' . $variableRight->getName(), $expression); case 'variable': $expected = $this->getExpected($compilationContext, $expression); $expectedCode = $compilationContext->backend->getVariableCode($expected); - $compilationContext->codePrinter->output($this->_zvalOperator . '(' . $expectedCode . ', ' . $op1 . ', ' . $op2 . ');'); + $compilationContext->codePrinter->output($this->zvalOperator . '(' . $expectedCode . ', ' . $op1 . ', ' . $op2 . ');'); return new CompiledExpression('variable', $expected->getName(), $expression); default: diff --git a/Library/Operators/Arithmetical/ModOperator.php b/Library/Operators/Arithmetical/ModOperator.php index d743d9278f..3831d8488f 100644 --- a/Library/Operators/Arithmetical/ModOperator.php +++ b/Library/Operators/Arithmetical/ModOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Arithmetical; @@ -25,11 +23,11 @@ */ class ModOperator extends ArithmeticalBaseOperator { - protected $_operator = '%'; + protected $operator = '%'; - protected $_bitOperator = '-'; + protected $bitOperator = '-'; - protected $_zvalOperator = 'mod_function'; + protected $zvalOperator = 'mod_function'; /** * Compiles the arithmetical modulus operation @@ -116,7 +114,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('long', '(' . $left->getBooleanCode() . ' - ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); default: throw new CompilerException("Cannot operate 'bool' with '" . $right->getType() . "'", $expression); @@ -233,7 +231,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('bool', '(' . $left->getCode() . ', ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); @@ -248,7 +246,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_mod_long_double(' . $variableLeft->getName() . ', ' . $variableRight->getName() . ' TSRMLS_CC)', $expression); case 'bool': - return new CompiledExpression('double', 'zephir_safe_mod_long_long(' . $variableLeft->getName() . ' ' . $this->_bitOperator . ' ' . $variableRight->getName() . ' TSRMLS_CC)', $expression); + return new CompiledExpression('double', 'zephir_safe_mod_long_long(' . $variableLeft->getName() . ' ' . $this->bitOperator . ' ' . $variableRight->getName() . ' TSRMLS_CC)', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); @@ -279,7 +277,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_mod_double_long(' . $left->getCode() . ', ' . $right->getCode() . ' TSRMLS_CC)', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); @@ -294,7 +292,7 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_mod_double_long(' . $variableLeft->getName() . ', ' . $variableRight->getName() . ' TSRMLS_CC)', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_bitOperator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->bitOperator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); @@ -360,7 +358,7 @@ public function compile($expression, CompilationContext $compilationContext) $expected = $this->getExpected($compilationContext, $expression); $symbol = $compilationContext->backend->getVariableCode($expected); - $compilationContext->codePrinter->output($this->_zvalOperator . '(' . $symbol . ', ' . $op1 . ', ' . $op2 . ' TSRMLS_CC);'); + $compilationContext->codePrinter->output($this->zvalOperator . '(' . $symbol . ', ' . $op1 . ', ' . $op2 . ' TSRMLS_CC);'); if ($variableLeft->isTemporal()) { $variableLeft->setIdle(true); @@ -417,14 +415,14 @@ public function compile($expression, CompilationContext $compilationContext) return new CompiledExpression('double', 'zephir_safe_mod_zval_double(' . $op1 . ', ' . $variableRight->getName() . ' TSRMLS_CC)', $expression); case 'bool': - return new CompiledExpression('bool', $op1 . ' ' . $this->_bitOperator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', $op1 . ' ' . $this->bitOperator . ' ' . $variableRight->getName(), $expression); case 'variable': $op2 = $compilationContext->backend->getVariableCode($variableRight); $expected = $this->getExpected($compilationContext, $expression); $symbol = $compilationContext->backend->getVariableCode($expected); - $compilationContext->codePrinter->output($this->_zvalOperator . '(' . $symbol . ', ' . $op1 . ', ' . $op2 . ');'); + $compilationContext->codePrinter->output($this->zvalOperator . '(' . $symbol . ', ' . $op1 . ', ' . $op2 . ');'); return new CompiledExpression('variable', $expected->getName(), $expression); default: diff --git a/Library/Operators/Arithmetical/MulOperator.php b/Library/Operators/Arithmetical/MulOperator.php index 0d03dd3b6c..b751d2b114 100644 --- a/Library/Operators/Arithmetical/MulOperator.php +++ b/Library/Operators/Arithmetical/MulOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Arithmetical; @@ -20,9 +18,9 @@ */ class MulOperator extends ArithmeticalBaseOperator { - protected $_operator = '*'; + protected $operator = '*'; - protected $_bitOperator = '+'; + protected $bitOperator = '+'; - protected $_zvalOperator = 'mul_function'; + protected $zvalOperator = 'mul_function'; } diff --git a/Library/Operators/Arithmetical/SubOperator.php b/Library/Operators/Arithmetical/SubOperator.php index 10630efbbf..79c409a806 100644 --- a/Library/Operators/Arithmetical/SubOperator.php +++ b/Library/Operators/Arithmetical/SubOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Arithmetical; @@ -20,9 +18,9 @@ */ class SubOperator extends ArithmeticalBaseOperator { - protected $_operator = '-'; + protected $operator = '-'; - protected $_bitOperator = '&'; + protected $bitOperator = '&'; - protected $_zvalOperator = 'zephir_sub_function'; + protected $zvalOperator = 'zephir_sub_function'; } diff --git a/Library/Operators/BaseOperator.php b/Library/Operators/BaseOperator.php index f63e3e859c..c34bf4091f 100644 --- a/Library/Operators/BaseOperator.php +++ b/Library/Operators/BaseOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators; @@ -18,16 +16,16 @@ class BaseOperator { - protected $_expecting = true; + protected $operator; - protected $_readOnly = false; + protected $expecting = true; - protected $_literalOnly = true; + protected $readOnly = false; - /** - * @var Variable|null - */ - protected $_expectingVariable; + protected $literalOnly = true; + + /** @var Variable|null */ + protected $expectingVariable; /** * Sets if the variable must be resolved into a direct variable symbol @@ -38,8 +36,8 @@ class BaseOperator */ public function setExpectReturn($expecting, Variable $expectingVariable = null) { - $this->_expecting = $expecting; - $this->_expectingVariable = $expectingVariable; + $this->expecting = $expecting; + $this->expectingVariable = $expectingVariable; } /** @@ -53,8 +51,8 @@ public function setExpectReturn($expecting, Variable $expectingVariable = null) */ public function getExpectedNonLiteral(CompilationContext $compilationContext, $expression, $init = true) { - $isExpecting = $this->_expecting; - $symbolVariable = $this->_expectingVariable; + $isExpecting = $this->expecting; + $symbolVariable = $this->expectingVariable; if ($isExpecting) { if (is_object($symbolVariable)) { @@ -84,8 +82,8 @@ public function getExpectedNonLiteral(CompilationContext $compilationContext, $e */ public function getExpected(CompilationContext $compilationContext, $expression, $init = true) { - $isExpecting = $this->_expecting; - $symbolVariable = $this->_expectingVariable; + $isExpecting = $this->expecting; + $symbolVariable = $this->expectingVariable; if ($isExpecting) { if (is_object($symbolVariable)) { @@ -95,8 +93,8 @@ public function getExpected(CompilationContext $compilationContext, $expression, } $symbolVariable->initVariant($compilationContext); } else { - if (!$this->_readOnly) { - if (!$this->_literalOnly) { + if (!$this->readOnly) { + if (!$this->literalOnly) { $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression); } else { $symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite('variable', $compilationContext, $expression); @@ -106,8 +104,8 @@ public function getExpected(CompilationContext $compilationContext, $expression, } } } else { - if (!$this->_readOnly) { - if (!$this->_literalOnly) { + if (!$this->readOnly) { + if (!$this->literalOnly) { $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression); } else { $symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite('variable', $compilationContext, $expression); @@ -132,22 +130,22 @@ public function getExpected(CompilationContext $compilationContext, $expression, */ public function getExpectedComplexLiteral(CompilationContext $compilationContext, $expression, $type = 'variable') { - $isExpecting = $this->_expecting; - $symbolVariable = $this->_expectingVariable; + $isExpecting = $this->expecting; + $symbolVariable = $this->expectingVariable; if ($isExpecting) { if (is_object($symbolVariable)) { if ($symbolVariable->getType() == $type || $symbolVariable->getName() == 'return_value') { $symbolVariable->initVariant($compilationContext); } else { - if (!$this->_readOnly) { + if (!$this->readOnly) { $symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite($type, $compilationContext, $expression); } else { $symbolVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite($type, $compilationContext, $expression); } } } else { - if (!$this->_readOnly) { + if (!$this->readOnly) { $symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite($type, $compilationContext, $expression); } else { $symbolVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite($type, $compilationContext, $expression); @@ -165,7 +163,7 @@ public function getExpectedComplexLiteral(CompilationContext $compilationContext */ public function isExpecting() { - return $this->_expecting; + return $this->expecting; } /** @@ -175,7 +173,7 @@ public function isExpecting() */ public function setReadOnly($readOnly) { - $this->_readOnly = $readOnly; + $this->readOnly = $readOnly; } /** @@ -185,6 +183,6 @@ public function setReadOnly($readOnly) */ public function isReadOnly() { - return $this->_readOnly; + return $this->readOnly; } } diff --git a/Library/Operators/Bitwise/BitwiseAndOperator.php b/Library/Operators/Bitwise/BitwiseAndOperator.php index 0a0d1189d0..69d2f8d32e 100644 --- a/Library/Operators/Bitwise/BitwiseAndOperator.php +++ b/Library/Operators/Bitwise/BitwiseAndOperator.php @@ -1,23 +1,21 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Bitwise; class BitwiseAndOperator extends BitwiseBaseOperator { - protected $_operator = '&'; + protected $operator = '&'; - protected $_bitOperator = '&'; + protected $bitOperator = '&'; - protected $_zvalOperator = 'zephir_bitwise_and_function'; + protected $zvalOperator = 'zephir_bitwise_and_function'; } diff --git a/Library/Operators/Bitwise/BitwiseBaseOperator.php b/Library/Operators/Bitwise/BitwiseBaseOperator.php index 50bbde161a..e78f47d31c 100644 --- a/Library/Operators/Bitwise/BitwiseBaseOperator.php +++ b/Library/Operators/Bitwise/BitwiseBaseOperator.php @@ -1,17 +1,13 @@ | - +--------------------------------------------------------------------------+ -*/ +/** + * This file is part of the Zephir. + * + * (c) Zephir Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Bitwise; @@ -29,7 +25,7 @@ */ class BitwiseBaseOperator extends BaseOperator { - protected $_literalOnly = true; + protected $literalOnly = true; /** * This tries to perform arithmetical operations @@ -74,7 +70,7 @@ public function optimizeConstantFolding(array $expression, CompilationContext $c /** * Return value will be always int */ - switch ($this->_operator) { + switch ($this->operator) { case '&': return new CompiledExpression('int', $expression['left']['value'] & $expression['right']['value'], $expression); @@ -141,13 +137,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'ulong': case 'char': case 'uchar': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'double': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' (int) (' . $right->getCode() . '))', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' (int) (' . $right->getCode() . '))', $expression); case 'bool': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression); @@ -156,18 +152,18 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' (int) (' . $variableRight->getName() . '))', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' (int) (' . $variableRight->getName() . '))', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $symbol = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' zephir_get_numberval(' . $symbol . '))', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' zephir_get_numberval(' . $symbol . '))', $expression); break; default: @@ -186,10 +182,10 @@ public function compile($expression, CompilationContext $compilationContext) case 'long': case 'ulong': case 'double': - return new CompiledExpression('int', '(' . $left->getBooleanCode() . ' ' . $this->_bitOperator . '((' . $right->getCode() . ') ? 1 : 0))', $expression); + return new CompiledExpression('int', '(' . $left->getBooleanCode() . ' ' . $this->bitOperator . '((' . $right->getCode() . ') ? 1 : 0))', $expression); case 'bool': - return new CompiledExpression('int', '(' . $left->getBooleanCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getBooleanCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($expression['right']['value'], $compilationContext, $expression); @@ -198,18 +194,18 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '((int) (' . $left->getBooleanCode() . ') ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '((int) (' . $left->getBooleanCode() . ') ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('int', '((int) (' . $left->getBooleanCode() . ') ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '((int) (' . $left->getBooleanCode() . ') ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('int', '((int) (' . $left->getBooleanCode() . ') ' . $this->_operator . ' (int) (' . $variableRight->getName() . '))', $expression); + return new CompiledExpression('int', '((int) (' . $left->getBooleanCode() . ') ' . $this->operator . ' (int) (' . $variableRight->getName() . '))', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $symbol = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('int', '((int) (' . $left->getBooleanCode() . ') ' . $this->_operator . ' zephir_get_numberval(' . $symbol . '))', $expression); + return new CompiledExpression('int', '((int) (' . $left->getBooleanCode() . ') ' . $this->operator . ' zephir_get_numberval(' . $symbol . '))', $expression); break; default: @@ -228,13 +224,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'double': - return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->_operator . ' (int) (' . $right->getCode() . '))', $expression); + return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->operator . ' (int) (' . $right->getCode() . '))', $expression); case 'bool': - return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->_operator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->operator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($expression['right']['value'], $compilationContext, $expression); @@ -243,18 +239,18 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->_operator . ' (int) (' . $variableRight->getName() . '))', $expression); + return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->operator . ' (int) (' . $variableRight->getName() . '))', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $symbol = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->_operator . ' zephir_get_numberval(' . $symbol . '))', $expression); + return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->operator . ' zephir_get_numberval(' . $symbol . '))', $expression); break; default: @@ -291,7 +287,7 @@ public function compile($expression, CompilationContext $compilationContext) case 'double': case 'char': case 'uchar': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); @@ -302,18 +298,18 @@ public function compile($expression, CompilationContext $compilationContext) case 'ulong': case 'char': case 'uchar': - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' (int) (' . $variableRight->getName() . '))', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' (int) (' . $variableRight->getName() . '))', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $symbol = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' (int) (zephir_get_numberval(' . $symbol . ')))', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' (int) (zephir_get_numberval(' . $symbol . ')))', $expression); break; default: @@ -332,10 +328,10 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); @@ -344,18 +340,18 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' (int) (' . $variableRight->getName() . '))', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' (int) (' . $variableRight->getName() . '))', $expression); case 'bool': - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_bitOperator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->bitOperator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $symbol = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' zephir_get_numberval(' . $symbol . '))', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' zephir_get_numberval(' . $symbol . '))', $expression); break; default: @@ -374,13 +370,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'double': - return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->_operator . ' (int) (' . $right->getCode() . '))', $expression); + return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->operator . ' (int) (' . $right->getCode() . '))', $expression); case 'bool': - return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('int', '((int) (' . $left->getCode() . ') ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($expression['right']['value'], $compilationContext, $expression['right']); @@ -389,17 +385,17 @@ public function compile($expression, CompilationContext $compilationContext) case 'uint': case 'long': case 'ulong': - return new CompiledExpression('int', '((int) (' . $variableLeft->getName() . ') ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '((int) (' . $variableLeft->getName() . ') ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('int', '((int) (' . $variableLeft->getName() . ') ' . $this->_operator . ' (int) (' . $variableRight->getName() . '))', $expression); + return new CompiledExpression('int', '((int) (' . $variableLeft->getName() . ') ' . $this->operator . ' (int) (' . $variableRight->getName() . '))', $expression); case 'bool': - return new CompiledExpression('int', '((int) (' . $variableLeft->getName() . ') ' . $this->_bitOperator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '((int) (' . $variableLeft->getName() . ') ' . $this->bitOperator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $symbol = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('int', '((int) (' . $variableLeft->getName() . ') ' . $this->_operator . ' (int) (zephir_get_numberval(' . $symbol . ')))', $expression); + return new CompiledExpression('int', '((int) (' . $variableLeft->getName() . ') ' . $this->operator . ' (int) (zephir_get_numberval(' . $symbol . ')))', $expression); break; @@ -425,7 +421,7 @@ public function compile($expression, CompilationContext $compilationContext) case 'ulong': case 'double': $compilationContext->headersManager->add('kernel/operators'); - $op = $this->_operator; + $op = $this->operator; $op1 = $compilationContext->backend->getVariableCode($variableLeft); $op2 = $right->getCode(); if ($right->getType() == 'double') { @@ -446,13 +442,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'long': case 'ulong': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('int', '((int) (zephir_get_numberval(' . $symbol . ')) ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '((int) (zephir_get_numberval(' . $symbol . ')) ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); break; /* a(var) + a(bool) */ case 'bool': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('int', '((int) (zephir_get_numberval(' . $symbol . ')) ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('int', '((int) (zephir_get_numberval(' . $symbol . ')) ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); break; /* a(var) + a(var) */ @@ -463,7 +459,7 @@ public function compile($expression, CompilationContext $compilationContext) $expected = $this->getExpected($compilationContext, $expression); $expectedSymbol = $compilationContext->backend->getVariableCode($expected); - $compilationContext->codePrinter->output($this->_zvalOperator . '(' . $expectedSymbol . ', ' . $op1 . ', ' . $op2 . ' TSRMLS_CC);'); + $compilationContext->codePrinter->output($this->zvalOperator . '(' . $expectedSymbol . ', ' . $op1 . ', ' . $op2 . ' TSRMLS_CC);'); if ($variableLeft->isTemporal()) { $variableLeft->setIdle(true); diff --git a/Library/Operators/Bitwise/BitwiseNotOperator.php b/Library/Operators/Bitwise/BitwiseNotOperator.php index 54023336e8..454f866083 100644 --- a/Library/Operators/Bitwise/BitwiseNotOperator.php +++ b/Library/Operators/Bitwise/BitwiseNotOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Bitwise; @@ -34,7 +32,7 @@ public function compile($expression, CompilationContext $compilationContext) } $leftExpr = new Expression($expression['left']); - $leftExpr->setReadOnly($this->_readOnly); + $leftExpr->setReadOnly($this->readOnly); $left = $leftExpr->compile($compilationContext); switch ($left->getType()) { diff --git a/Library/Operators/Bitwise/BitwiseOrOperator.php b/Library/Operators/Bitwise/BitwiseOrOperator.php index ce09515373..31229e3b57 100644 --- a/Library/Operators/Bitwise/BitwiseOrOperator.php +++ b/Library/Operators/Bitwise/BitwiseOrOperator.php @@ -1,23 +1,21 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Bitwise; class BitwiseOrOperator extends BitwiseBaseOperator { - protected $_operator = '|'; + protected $operator = '|'; - protected $_bitOperator = '|'; + protected $bitOperator = '|'; - protected $_zvalOperator = 'zephir_bitwise_or_function'; + protected $zvalOperator = 'zephir_bitwise_or_function'; } diff --git a/Library/Operators/Bitwise/BitwiseXorOperator.php b/Library/Operators/Bitwise/BitwiseXorOperator.php index 36cfad8473..a21c864223 100644 --- a/Library/Operators/Bitwise/BitwiseXorOperator.php +++ b/Library/Operators/Bitwise/BitwiseXorOperator.php @@ -1,23 +1,21 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Bitwise; class BitwiseXorOperator extends BitwiseBaseOperator { - protected $_operator = '^'; + protected $operator = '^'; - protected $_bitOperator = '^'; + protected $bitOperator = '^'; - protected $_zvalOperator = 'zephir_bitwise_xor_function'; + protected $zvalOperator = 'zephir_bitwise_xor_function'; } diff --git a/Library/Operators/Bitwise/ShiftLeftOperator.php b/Library/Operators/Bitwise/ShiftLeftOperator.php index 9c15243bf4..3d4846e943 100644 --- a/Library/Operators/Bitwise/ShiftLeftOperator.php +++ b/Library/Operators/Bitwise/ShiftLeftOperator.php @@ -1,23 +1,21 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Bitwise; class ShiftLeftOperator extends BitwiseBaseOperator { - protected $_operator = '<<'; + protected $operator = '<<'; - protected $_bitOperator = '<<'; + protected $bitOperator = '<<'; - protected $_zvalOperator = 'zephir_shift_left_function'; + protected $zvalOperator = 'zephir_shift_left_function'; } diff --git a/Library/Operators/Bitwise/ShiftRightOperator.php b/Library/Operators/Bitwise/ShiftRightOperator.php index e01fac1e2b..e2bd8e9528 100644 --- a/Library/Operators/Bitwise/ShiftRightOperator.php +++ b/Library/Operators/Bitwise/ShiftRightOperator.php @@ -1,23 +1,21 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Bitwise; class ShiftRightOperator extends BitwiseBaseOperator { - protected $_operator = '>>'; + protected $operator = '>>'; - protected $_bitOperator = '>>'; + protected $bitOperator = '>>'; - protected $_zvalOperator = 'zephir_shift_right_function'; + protected $zvalOperator = 'zephir_shift_right_function'; } diff --git a/Library/Operators/Comparison/ComparisonBaseOperator.php b/Library/Operators/Comparison/ComparisonBaseOperator.php index 20a818e9fd..26a1b3637b 100644 --- a/Library/Operators/Comparison/ComparisonBaseOperator.php +++ b/Library/Operators/Comparison/ComparisonBaseOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Comparison; @@ -26,9 +24,9 @@ */ class ComparisonBaseOperator extends BaseOperator { - protected $_literalOnly = true; + protected $literalOnly = true; - protected $_commutative = false; + protected $commutative = false; /** * @@ -195,20 +193,20 @@ public function compile($expression, CompilationContext $compilationContext) case 'null': switch ($right->getType()) { case 'null': - return new CompiledExpression('bool', '(0 ' . $this->_operator . ' 0)', $expression); + return new CompiledExpression('bool', '(0 ' . $this->operator . ' 0)', $expression); case 'int': case 'uint': case 'long': case 'ulong': - return new CompiledExpression('bool', '(0 ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('bool', '(0 ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'char': case 'uchar': - return new CompiledExpression('bool', '(\'\\0\' ' . $this->_operator . ' \'' . $right->getCode() . '\')', $expression); + return new CompiledExpression('bool', '(\'\\0\' ' . $this->operator . ' \'' . $right->getCode() . '\')', $expression); case 'double': - return new CompiledExpression('bool', '(0 ' . $this->_operator . ' (int) ' . $right->getCode() . ')', $expression); + return new CompiledExpression('bool', '(0 ' . $this->operator . ' (int) ' . $right->getCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['left']); @@ -219,11 +217,11 @@ public function compile($expression, CompilationContext $compilationContext) case 'ulong': case 'double': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', '0 ' . $this->_operator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', '0 ' . $this->operator . ' ' . $variableRight->getName(), $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); - $condition = $compilationContext->backend->getTypeofCondition($variableRight, $this->_operator, 'null', $compilationContext); + $condition = $compilationContext->backend->getTypeofCondition($variableRight, $this->operator, 'null', $compilationContext); return new CompiledExpression('bool', $condition, $expression); default: @@ -245,20 +243,20 @@ public function compile($expression, CompilationContext $compilationContext) case 'uchar': switch ($right->getType()) { case 'null': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator, $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator, $expression); case 'int': case 'uint': case 'long': case 'ulong': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode(), $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode(), $expression); case 'char': case 'uchar': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' \'' . $right->getCode() . '\'', $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' \'' . $right->getCode() . '\'', $expression); case 'double': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' (int) ' . $right->getCode(), $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' (int) ' . $right->getCode(), $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['left']); @@ -269,12 +267,12 @@ public function compile($expression, CompilationContext $compilationContext) case 'ulong': case 'double': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName(), $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableCode = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('bool', $this->_zvalLongNegOperator . '(' . $variableCode . ', ' . $left->getCode() . ')', $expression); + return new CompiledExpression('bool', $this->zvalLongNegOperator . '(' . $variableCode . ', ' . $left->getCode() . ')', $expression); default: throw new CompilerException("Unknown type: " . $variableRight->getType(), $expression['right']); @@ -289,23 +287,23 @@ public function compile($expression, CompilationContext $compilationContext) case 'bool': switch ($right->getType()) { case 'null': - return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->_operator . ' 0', $expression); + return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->operator . ' 0', $expression); case 'int': case 'uint': case 'long': case 'ulong': - return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->_operator . ' ' . $right->getCode(), $expression); + return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->operator . ' ' . $right->getCode(), $expression); case 'char': case 'uchar': - return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->_operator . ' \'' . $right->getCode() . '\'', $expression); + return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->operator . ' \'' . $right->getCode() . '\'', $expression); case 'double': - return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->_operator . ' (int) ' . $right->getCode(), $expression); + return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->operator . ' (int) ' . $right->getCode(), $expression); case 'bool': - return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->_operator . ' ' . $right->getBooleanCode(), $expression); + return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->operator . ' ' . $right->getBooleanCode(), $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['left']); @@ -316,11 +314,11 @@ public function compile($expression, CompilationContext $compilationContext) case 'ulong': case 'double': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->_operator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', $left->getBooleanCode() . ' ' . $this->operator . ' ' . $variableRight->getName(), $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); - $boolOperator = $left->getBooleanCode() == '1' ? $this->_zvalBoolTrueOperator : $this->_zvalBoolFalseOperator; + $boolOperator = $left->getBooleanCode() == '1' ? $this->zvalBoolTrueOperator : $this->zvalBoolFalseOperator; $variableRight = $compilationContext->backend->getVariableCode($variableRight); return new CompiledExpression('bool', $boolOperator . '(' . $variableRight . ')', $expression); default: @@ -342,7 +340,7 @@ public function compile($expression, CompilationContext $compilationContext) case 'null': $rightStr = $right->getType() == 'null' ? '' : $right->getCode(); $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $this->_zvalStringOperator . '(' . $variableLeftCode . ', "' . $rightStr . '")', $expression['left']); + return new CompiledExpression('bool', $this->zvalStringOperator . '(' . $variableLeftCode . ', "' . $rightStr . '")', $expression['left']); break; case 'variable': @@ -352,7 +350,7 @@ public function compile($expression, CompilationContext $compilationContext) case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableRight = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('bool', $this->_zvalOperator . '(' . $variableLeftCode . ', ' . $variableRight . ')', $expression); + return new CompiledExpression('bool', $this->zvalOperator . '(' . $variableLeftCode . ', ' . $variableRight . ')', $expression); break; default: @@ -381,14 +379,14 @@ public function compile($expression, CompilationContext $compilationContext) case 'long': case 'ulong': case 'double': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode(), $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode(), $expression); case 'char': case 'uchar': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' \'' . $right->getCode() . '\'', $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' \'' . $right->getCode() . '\'', $expression); case 'bool': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' ' . $right->getBooleanCode(), $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' ' . $right->getBooleanCode(), $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['left']); @@ -400,13 +398,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'char': case 'uchar': case 'double': - return new CompiledExpression('bool', $variable->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', $variable->getName() . ' ' . $this->operator . ' ' . $variableRight->getName(), $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableRightCode = $compilationContext->backend->getVariableCode($variableRight); $variableCode = $compilationContext->backend->getVariableCode($variable); - return new CompiledExpression('bool', $this->_zvalLongNegOperator . '(' . $variableRightCode . ', ' . $variableCode . ')', $expression); + return new CompiledExpression('bool', $this->zvalLongNegOperator . '(' . $variableRightCode . ', ' . $variableCode . ')', $expression); break; default: @@ -426,14 +424,14 @@ public function compile($expression, CompilationContext $compilationContext) case 'long': case 'ulong': case 'double': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode(), $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode(), $expression); case 'bool': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' ' . $right->getBooleanCode(), $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' ' . $right->getBooleanCode(), $expression); case 'char': case 'uchar': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' \'' . $right->getCode() . '\'', $expression); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' \'' . $right->getCode() . '\'', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['left']); @@ -443,13 +441,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'long': case 'ulong': case 'double': - return new CompiledExpression('bool', $variable->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', $variable->getName() . ' ' . $this->operator . ' ' . $variableRight->getName(), $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableRightCode = $compilationContext->backend->getVariableCode($variableRight); $variableCode = $compilationContext->backend->getVariableCode($variable); - return new CompiledExpression('bool', $this->_zvalDoubleNegOperator . '(' . $variableRightCode . ', ' . $variableCode . ')', $expression); + return new CompiledExpression('bool', $this->zvalDoubleNegOperator . '(' . $variableRightCode . ', ' . $variableCode . ')', $expression); default: throw new CompilerException("Unknown type: " . $variableRight->getType(), $expression['right']); @@ -464,13 +462,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'bool': switch ($right->getType()) { case 'int': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode(), $expression['left']); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode(), $expression['left']); case 'bool': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' ' . $right->getBooleanCode(), $expression['left']); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' ' . $right->getBooleanCode(), $expression['left']); case 'null': - return new CompiledExpression('bool', $left->getCode() . ' ' . $this->_operator . ' 0', $expression['left']); + return new CompiledExpression('bool', $left->getCode() . ' ' . $this->operator . ' 0', $expression['left']); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['left']); @@ -482,11 +480,11 @@ public function compile($expression, CompilationContext $compilationContext) case 'ulong': case 'bool': case 'double': - return new CompiledExpression('bool', $variable->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', $variable->getName() . ' ' . $this->operator . ' ' . $variableRight->getName(), $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); - $boolOperator = $left->getBooleanCode() == '1' ? $this->_zvalBoolTrueOperator : $this->_zvalBoolFalseOperator; + $boolOperator = $left->getBooleanCode() == '1' ? $this->zvalBoolTrueOperator : $this->zvalBoolFalseOperator; $variableRightCode = $compilationContext->backend->getVariableCode($variableRight); return new CompiledExpression('bool', $boolOperator . '(' . $variableRightCode . ')', $expression); @@ -504,7 +502,7 @@ public function compile($expression, CompilationContext $compilationContext) switch ($right->getType()) { case 'null': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $this->_zvalStringOperator . '(' . $variableCode . ', "")', $expression['left']); + return new CompiledExpression('bool', $this->zvalStringOperator . '(' . $variableCode . ', "")', $expression['left']); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['left']); @@ -514,7 +512,7 @@ public function compile($expression, CompilationContext $compilationContext) case 'array': $compilationContext->headersManager->add('kernel/operators'); $variableRight = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('bool', $this->_zvalOperator . '(' . $variableCode . ', ' . $variableRight . ')', $expression); + return new CompiledExpression('bool', $this->zvalOperator . '(' . $variableCode . ', ' . $variableRight . ')', $expression); default: throw new CompilerException("Unknown type: " . $variableRight->getType(), $expression['right']); @@ -530,11 +528,11 @@ public function compile($expression, CompilationContext $compilationContext) switch ($right->getType()) { case 'null': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $this->_zvalStringOperator . '(' . $variableCode . ', "")', $expression['left']); + return new CompiledExpression('bool', $this->zvalStringOperator . '(' . $variableCode . ', "")', $expression['left']); case 'string': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $this->_zvalStringOperator . '(' . $variableCode . ', "' . $right->getCode() . '")', $expression['left']); + return new CompiledExpression('bool', $this->zvalStringOperator . '(' . $variableCode . ', "' . $right->getCode() . '")', $expression['left']); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['left']); @@ -544,7 +542,7 @@ public function compile($expression, CompilationContext $compilationContext) $compilationContext->headersManager->add('kernel/operators'); $variableRight = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('bool', $this->_zvalOperator . '(' . $variableCode . ', ' . $variableRight . ')', $expression); + return new CompiledExpression('bool', $this->zvalOperator . '(' . $variableCode . ', ' . $variableRight . ')', $expression); default: throw new CompilerException("Unknown type: " . $variableRight->getType(), $expression['right']); @@ -560,7 +558,7 @@ public function compile($expression, CompilationContext $compilationContext) switch ($right->getType()) { case 'null': $compilationContext->headersManager->add('kernel/operators'); - $condition = $compilationContext->backend->getTypeofCondition($variable, $this->_operator, 'null', $compilationContext); + $condition = $compilationContext->backend->getTypeofCondition($variable, $this->operator, 'null', $compilationContext); return new CompiledExpression('bool', $condition, $expression['left']); case 'int': @@ -569,21 +567,21 @@ public function compile($expression, CompilationContext $compilationContext) case 'ulong': case 'double': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $this->_zvalLongOperator . '(' . $variableCode . ', ' . $right->getCode() . ')', $expression['left']); + return new CompiledExpression('bool', $this->zvalLongOperator . '(' . $variableCode . ', ' . $right->getCode() . ')', $expression['left']); case 'char': case 'uchar': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $this->_zvalLongOperator . '(' . $variableCode . ', \'' . $right->getCode() . '\')', $expression['left']); + return new CompiledExpression('bool', $this->zvalLongOperator . '(' . $variableCode . ', \'' . $right->getCode() . '\')', $expression['left']); case 'bool': $compilationContext->headersManager->add('kernel/operators'); - $zvalBoolOperator = $right->getCode() == 'true' ? $this->_zvalBoolTrueOperator : $this->_zvalBoolFalseOperator; + $zvalBoolOperator = $right->getCode() == 'true' ? $this->zvalBoolTrueOperator : $this->zvalBoolFalseOperator; return new CompiledExpression('bool', $zvalBoolOperator . '(' . $variableCode . ')', $expression['left']); case 'string': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $this->_zvalStringOperator . '(' . $variableCode . ', "' . $right->getCode() . '")', $expression['left']); + return new CompiledExpression('bool', $this->zvalStringOperator . '(' . $variableCode . ', "' . $right->getCode() . '")', $expression['left']); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['left']); @@ -593,22 +591,22 @@ public function compile($expression, CompilationContext $compilationContext) case 'long': case 'ulong': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $this->_zvalLongOperator . '(' . $variableCode . ', ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', $this->zvalLongOperator . '(' . $variableCode . ', ' . $variableRight->getName() . ')', $expression); case 'double': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $this->_zvalDoubleOperator . '(' . $variableCode . ', ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', $this->zvalDoubleOperator . '(' . $variableCode . ', ' . $variableRight->getName() . ')', $expression); case 'bool': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', $this->_zvalBoolOperator . '(' . $variableCode . ', ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', $this->zvalBoolOperator . '(' . $variableCode . ', ' . $variableRight->getName() . ')', $expression); case 'string': case 'variable': case 'array': $compilationContext->headersManager->add('kernel/operators'); $variableRight = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('bool', $this->_zvalOperator . '(' . $variableCode . ', ' . $variableRight . ')', $expression); + return new CompiledExpression('bool', $this->zvalOperator . '(' . $variableCode . ', ' . $variableRight . ')', $expression); default: throw new CompilerException("Unknown type: " . $variableRight->getType(), $expression['right']); diff --git a/Library/Operators/Comparison/EqualsOperator.php b/Library/Operators/Comparison/EqualsOperator.php index 0ea02dbf61..95881787e5 100644 --- a/Library/Operators/Comparison/EqualsOperator.php +++ b/Library/Operators/Comparison/EqualsOperator.php @@ -1,37 +1,35 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Comparison; class EqualsOperator extends ComparisonBaseOperator { - protected $_commutative = true; + protected $commutative = true; - protected $_operator = '=='; + protected $operator = '=='; - protected $_bitOperator = '=='; + protected $bitOperator = '=='; - protected $_zvalOperator = 'ZEPHIR_IS_EQUAL'; + protected $zvalOperator = 'ZEPHIR_IS_EQUAL'; - protected $_zvalLongOperator = 'ZEPHIR_IS_LONG'; + protected $zvalLongOperator = 'ZEPHIR_IS_LONG'; - protected $_zvalLongNegOperator = 'ZEPHIR_IS_LONG'; + protected $zvalLongNegOperator = 'ZEPHIR_IS_LONG'; - protected $_zvalStringOperator = 'ZEPHIR_IS_STRING'; + protected $zvalStringOperator = 'ZEPHIR_IS_STRING'; - protected $_zvalBoolOperator = 'ZEPHIR_IS_BOOL_VALUE'; + protected $zvalBoolOperator = 'ZEPHIR_IS_BOOL_VALUE'; - protected $_zvalBoolTrueOperator = 'ZEPHIR_IS_TRUE'; + protected $zvalBoolTrueOperator = 'ZEPHIR_IS_TRUE'; - protected $_zvalBoolFalseOperator = 'ZEPHIR_IS_FALSE'; + protected $zvalBoolFalseOperator = 'ZEPHIR_IS_FALSE'; } diff --git a/Library/Operators/Comparison/GreaterEqualOperator.php b/Library/Operators/Comparison/GreaterEqualOperator.php index 8673850e20..37e5c9a5ee 100644 --- a/Library/Operators/Comparison/GreaterEqualOperator.php +++ b/Library/Operators/Comparison/GreaterEqualOperator.php @@ -1,31 +1,29 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Comparison; class GreaterEqualOperator extends ComparisonBaseOperator { - protected $_operator = '>='; + protected $operator = '>='; - protected $_bitOperator = '>='; + protected $bitOperator = '>='; - protected $_zvalOperator = 'ZEPHIR_GE'; + protected $zvalOperator = 'ZEPHIR_GE'; - protected $_zvalLongOperator = 'ZEPHIR_GE_LONG'; + protected $zvalLongOperator = 'ZEPHIR_GE_LONG'; - protected $_zvalLongNegOperator = 'ZEPHIR_LE_LONG'; + protected $zvalLongNegOperator = 'ZEPHIR_LE_LONG'; - protected $_zvalDoubleOperator = '!ZEPHIR_LT_DOUBLE'; + protected $zvalDoubleOperator = '!ZEPHIR_LT_DOUBLE'; - protected $_zvalDoubleNegOperator = '!ZEPHIR_GT_DOUBLE'; + protected $zvalDoubleNegOperator = '!ZEPHIR_GT_DOUBLE'; } diff --git a/Library/Operators/Comparison/GreaterOperator.php b/Library/Operators/Comparison/GreaterOperator.php index dc795513a9..120316caa6 100644 --- a/Library/Operators/Comparison/GreaterOperator.php +++ b/Library/Operators/Comparison/GreaterOperator.php @@ -1,31 +1,29 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Comparison; class GreaterOperator extends ComparisonBaseOperator { - protected $_operator = '>'; + protected $operator = '>'; - protected $_bitOperator = '>'; + protected $bitOperator = '>'; - protected $_zvalOperator = 'ZEPHIR_GT'; + protected $zvalOperator = 'ZEPHIR_GT'; - protected $_zvalLongOperator = 'ZEPHIR_GT_LONG'; + protected $zvalLongOperator = 'ZEPHIR_GT_LONG'; - protected $_zvalLongNegOperator = 'ZEPHIR_LT_LONG'; + protected $zvalLongNegOperator = 'ZEPHIR_LT_LONG'; - protected $_zvalDoubleOperator = 'ZEPHIR_GT_DOUBLE'; + protected $zvalDoubleOperator = 'ZEPHIR_GT_DOUBLE'; - protected $_zvalDoubleNegOperator = 'ZEPHIR_LT_DOUBLE'; + protected $zvalDoubleNegOperator = 'ZEPHIR_LT_DOUBLE'; } diff --git a/Library/Operators/Comparison/IdenticalOperator.php b/Library/Operators/Comparison/IdenticalOperator.php index f5286e8365..448c526f4a 100644 --- a/Library/Operators/Comparison/IdenticalOperator.php +++ b/Library/Operators/Comparison/IdenticalOperator.php @@ -1,37 +1,35 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Comparison; class IdenticalOperator extends ComparisonBaseOperator { - protected $_commutative = true; + protected $commutative = true; - protected $_operator = '=='; + protected $operator = '=='; - protected $_bitOperator = '=='; + protected $bitOperator = '=='; - protected $_zvalOperator = 'ZEPHIR_IS_IDENTICAL'; + protected $zvalOperator = 'ZEPHIR_IS_IDENTICAL'; - protected $_zvalLongOperator = 'ZEPHIR_IS_LONG_IDENTICAL'; + protected $zvalLongOperator = 'ZEPHIR_IS_LONG_IDENTICAL'; - protected $_zvalLongNegOperator = 'ZEPHIR_IS_LONG_IDENTICAL'; + protected $zvalLongNegOperator = 'ZEPHIR_IS_LONG_IDENTICAL'; - protected $_zvalStringOperator = 'ZEPHIR_IS_STRING_IDENTICAL'; + protected $zvalStringOperator = 'ZEPHIR_IS_STRING_IDENTICAL'; - protected $_zvalBoolOperator = 'ZEPHIR_IS_BOOL_IDENTICAL'; + protected $zvalBoolOperator = 'ZEPHIR_IS_BOOL_IDENTICAL'; - protected $_zvalBoolTrueOperator = 'ZEPHIR_IS_TRUE_IDENTICAL'; + protected $zvalBoolTrueOperator = 'ZEPHIR_IS_TRUE_IDENTICAL'; - protected $_zvalBoolFalseOperator = 'ZEPHIR_IS_FALSE_IDENTICAL'; + protected $zvalBoolFalseOperator = 'ZEPHIR_IS_FALSE_IDENTICAL'; } diff --git a/Library/Operators/Comparison/LessEqualOperator.php b/Library/Operators/Comparison/LessEqualOperator.php index 3dac9a19e2..c80463590b 100644 --- a/Library/Operators/Comparison/LessEqualOperator.php +++ b/Library/Operators/Comparison/LessEqualOperator.php @@ -1,31 +1,29 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Comparison; class LessEqualOperator extends ComparisonBaseOperator { - protected $_operator = '<='; + protected $operator = '<='; - protected $_bitOperator = '<='; + protected $bitOperator = '<='; - protected $_zvalOperator = 'ZEPHIR_LE'; + protected $zvalOperator = 'ZEPHIR_LE'; - protected $_zvalLongOperator = 'ZEPHIR_LE_LONG'; + protected $zvalLongOperator = 'ZEPHIR_LE_LONG'; - protected $_zvalLongNegOperator = 'ZEPHIR_GE_LONG'; + protected $zvalLongNegOperator = 'ZEPHIR_GE_LONG'; - protected $_zvalDoubleOperator = '!ZEPHIR_GT_DOUBLE'; + protected $zvalDoubleOperator = '!ZEPHIR_GT_DOUBLE'; - protected $_zvalDoubleNegOperator = '!ZEPHIR_LT_DOUBLE'; + protected $zvalDoubleNegOperator = '!ZEPHIR_LT_DOUBLE'; } diff --git a/Library/Operators/Comparison/LessOperator.php b/Library/Operators/Comparison/LessOperator.php index 6196810aaa..9e3df4ef3c 100644 --- a/Library/Operators/Comparison/LessOperator.php +++ b/Library/Operators/Comparison/LessOperator.php @@ -1,31 +1,29 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Comparison; class LessOperator extends ComparisonBaseOperator { - protected $_operator = '<'; + protected $operator = '<'; - protected $_bitOperator = '<'; + protected $bitOperator = '<'; - protected $_zvalOperator = 'ZEPHIR_LT'; + protected $zvalOperator = 'ZEPHIR_LT'; - protected $_zvalLongOperator = 'ZEPHIR_LT_LONG'; + protected $zvalLongOperator = 'ZEPHIR_LT_LONG'; - protected $_zvalLongNegOperator = 'ZEPHIR_GT_LONG'; + protected $zvalLongNegOperator = 'ZEPHIR_GT_LONG'; - protected $_zvalDoubleOperator = 'ZEPHIR_LT_DOUBLE'; + protected $zvalDoubleOperator = 'ZEPHIR_LT_DOUBLE'; - protected $_zvalDoubleNegOperator = 'ZEPHIR_GT_DOUBLE'; + protected $zvalDoubleNegOperator = 'ZEPHIR_GT_DOUBLE'; } diff --git a/Library/Operators/Comparison/NotEqualsOperator.php b/Library/Operators/Comparison/NotEqualsOperator.php index 8df70e6fbc..ab960f436d 100644 --- a/Library/Operators/Comparison/NotEqualsOperator.php +++ b/Library/Operators/Comparison/NotEqualsOperator.php @@ -1,41 +1,39 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Comparison; class NotEqualsOperator extends ComparisonBaseOperator { - protected $_commutative = true; + protected $commutative = true; - protected $_inverse = true; + protected $inverse = true; - protected $_operator = '!='; + protected $operator = '!='; - protected $_bitOperator = '!='; + protected $bitOperator = '!='; - protected $_zvalOperator = '!ZEPHIR_IS_EQUAL'; + protected $zvalOperator = '!ZEPHIR_IS_EQUAL'; - protected $_zvalLongOperator = '!ZEPHIR_IS_LONG'; + protected $zvalLongOperator = '!ZEPHIR_IS_LONG'; - protected $_zvalLongNegOperator = '!ZEPHIR_IS_LONG'; + protected $zvalLongNegOperator = '!ZEPHIR_IS_LONG'; - protected $_zvalDoubleOperator = '!ZEPHIR_IS_DOUBLE'; + protected $zvalDoubleOperator = '!ZEPHIR_IS_DOUBLE'; - protected $_zvalStringOperator = '!ZEPHIR_IS_STRING'; + protected $zvalStringOperator = '!ZEPHIR_IS_STRING'; - protected $_zvalBoolOperator = '!ZEPHIR_IS_BOOL_VALUE'; + protected $zvalBoolOperator = '!ZEPHIR_IS_BOOL_VALUE'; - protected $_zvalBoolTrueOperator = '!ZEPHIR_IS_TRUE'; + protected $zvalBoolTrueOperator = '!ZEPHIR_IS_TRUE'; - protected $_zvalBoolFalseOperator = '!ZEPHIR_IS_FALSE'; + protected $zvalBoolFalseOperator = '!ZEPHIR_IS_FALSE'; } diff --git a/Library/Operators/Comparison/NotIdenticalOperator.php b/Library/Operators/Comparison/NotIdenticalOperator.php index 746d484839..ef521ecc51 100644 --- a/Library/Operators/Comparison/NotIdenticalOperator.php +++ b/Library/Operators/Comparison/NotIdenticalOperator.php @@ -1,39 +1,37 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Comparison; class NotIdenticalOperator extends ComparisonBaseOperator { - protected $_commutative = true; + protected $commutative = true; - protected $_inverse = true; + protected $inverse = true; - protected $_operator = '!='; + protected $operator = '!='; - protected $_bitOperator = '!='; + protected $bitOperator = '!='; - protected $_zvalOperator = '!ZEPHIR_IS_IDENTICAL'; + protected $zvalOperator = '!ZEPHIR_IS_IDENTICAL'; - protected $_zvalLongOperator = '!ZEPHIR_IS_LONG_IDENTICAL'; + protected $zvalLongOperator = '!ZEPHIR_IS_LONG_IDENTICAL'; - protected $_zvalLongNegOperator = '!ZEPHIR_IS_LONG_IDENTICAL'; + protected $zvalLongNegOperator = '!ZEPHIR_IS_LONG_IDENTICAL'; - protected $_zvalStringOperator = '!ZEPHIR_IS_STRING_IDENTICAL'; + protected $zvalStringOperator = '!ZEPHIR_IS_STRING_IDENTICAL'; - protected $_zvalBoolOperator = '!ZEPHIR_IS_BOOL_IDENTICAL'; + protected $zvalBoolOperator = '!ZEPHIR_IS_BOOL_IDENTICAL'; - protected $_zvalBoolTrueOperator = '!ZEPHIR_IS_TRUE_IDENTICAL'; + protected $zvalBoolTrueOperator = '!ZEPHIR_IS_TRUE_IDENTICAL'; - protected $_zvalBoolFalseOperator = '!ZEPHIR_IS_FALSE_IDENTICAL'; + protected $zvalBoolFalseOperator = '!ZEPHIR_IS_FALSE_IDENTICAL'; } diff --git a/Library/Operators/Logical/AndOperator.php b/Library/Operators/Logical/AndOperator.php index d363d13f57..38a0fd2998 100644 --- a/Library/Operators/Logical/AndOperator.php +++ b/Library/Operators/Logical/AndOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Logical; @@ -21,9 +19,9 @@ class AndOperator extends LogicalBaseOperator { - protected $_operator = '&&'; + protected $operator = '&&'; - protected $_bitOperator = '&&'; + protected $bitOperator = '&&'; public function compile($expression, CompilationContext $compilationContext) { @@ -36,7 +34,7 @@ public function compile($expression, CompilationContext $compilationContext) } $leftExpr = new Expression($expression['left']); - $leftExpr->setReadOnly($this->_readOnly); + $leftExpr->setReadOnly($this->readOnly); $left = $leftExpr->compile($compilationContext); /** @@ -98,7 +96,7 @@ public function compile($expression, CompilationContext $compilationContext) $compilationContext->codePrinter->increaseLevel(); $rightExpr = new Expression($expression['right']); - $rightExpr->setReadOnly($this->_readOnly); + $rightExpr->setReadOnly($this->readOnly); $right = $rightExpr->compile($compilationContext); switch ($right->getType()) { diff --git a/Library/Operators/Logical/LogicalBaseOperator.php b/Library/Operators/Logical/LogicalBaseOperator.php index 9fdf8241db..92029936be 100644 --- a/Library/Operators/Logical/LogicalBaseOperator.php +++ b/Library/Operators/Logical/LogicalBaseOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Logical; @@ -37,41 +35,41 @@ public function compile($expression, CompilationContext $compilationContext) } $leftExpr = new Expression($expression['left']); - $leftExpr->setReadOnly($this->_readOnly); + $leftExpr->setReadOnly($this->readOnly); $left = $leftExpr->compile($compilationContext); $rightExpr = new Expression($expression['right']); - $rightExpr->setReadOnly($this->_readOnly); + $rightExpr->setReadOnly($this->readOnly); $right = $rightExpr->compile($compilationContext); switch ($left->getType()) { case 'int': switch ($right->getType()) { case 'int': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'double': - return new CompiledExpression('double', '((double) ' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('double', '((double) ' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('int', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression); switch ($variableRight->getType()) { case 'int': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableCode = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_operator . ' zephir_is_true(' . $variableCode . '))', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->operator . ' zephir_is_true(' . $variableCode . '))', $expression); default: throw new CompilerException("Cannot compare variable('int') with variable('" . $variableRight->getType() . "')", $expression); @@ -87,27 +85,27 @@ public function compile($expression, CompilationContext $compilationContext) switch ($right->getType()) { case 'int': case 'double': - return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->_bitOperator . ' ((' . $right->getCode() . ') ? 1 : 0))', $expression); + return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->bitOperator . ' ((' . $right->getCode() . ') ? 1 : 0))', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression); switch ($variableRight->getType()) { case 'int': - return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $variableCode = $compilationContext->backend->getVariableCode($variableRight); $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->_operator . ' zephir_is_true(' . $variableCode . '))', $expression); + return new CompiledExpression('bool', '(' . $left->getBooleanCode() . ' ' . $this->operator . ' zephir_is_true(' . $variableCode . '))', $expression); default: throw new CompilerException("Cannot add variable('int') with variable('" . $variableRight->getType() . "')", $expression); @@ -121,13 +119,13 @@ public function compile($expression, CompilationContext $compilationContext) case 'double': switch ($right->getType()) { case 'int': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'double': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->_operator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $left->getCode() . ' ' . $this->operator . ' ' . $right->getBooleanCode() . ')', $expression); default: throw new CompilerException("Cannot compare 'double' with '" . $right->getType() . "'", $expression); @@ -147,24 +145,24 @@ public function compile($expression, CompilationContext $compilationContext) case 'int': switch ($right->getType()) { case 'int': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); switch ($variableRight->getType()) { case 'int': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'double': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableCode = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' zephir_is_true(' . $variableCode . '))', $expression); + return new CompiledExpression('int', '(' . $variableLeft->getName() . ' ' . $this->operator . ' zephir_is_true(' . $variableCode . '))', $expression); default: throw new CompilerException("Cannot compare variable('int') with variable('" . $variableRight->getType() . "')", $expression); @@ -179,24 +177,24 @@ public function compile($expression, CompilationContext $compilationContext) case 'bool': switch ($right->getType()) { case 'int': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $right->getCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $right->getCode() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->bitOperator . ' ' . $right->getBooleanCode() . ')', $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); switch ($variableRight->getType()) { case 'int': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName() . ')', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_bitOperator . ' ' . $variableRight->getName() . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->bitOperator . ' ' . $variableRight->getName() . ')', $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableCode = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->_operator . ' zephir_is_true(' . $variableCode . '))', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' ' . $this->operator . ' zephir_is_true(' . $variableCode . '))', $expression); default: throw new CompilerException("Cannot compare variable('int') with variable('" . $variableRight->getType() . "')", $expression); @@ -211,30 +209,30 @@ public function compile($expression, CompilationContext $compilationContext) case 'double': switch ($right->getType()) { case 'int': - return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->_operator . ' ' . $right->getCode(), $expression); + return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->operator . ' ' . $right->getCode(), $expression); case 'double': - return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->_operator . ' ' . $right->getCode(), $expression); + return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->operator . ' ' . $right->getCode(), $expression); case 'bool': - return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->_bitOperator . '' . $right->getBooleanCode(), $expression); + return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->bitOperator . '' . $right->getBooleanCode(), $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); switch ($variableRight->getType()) { case 'int': - return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->_operator . ' (double) ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->operator . ' (double) ' . $variableRight->getName(), $expression); case 'double': - return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->_operator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->operator . ' ' . $variableRight->getName(), $expression); case 'bool': - return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->_bitOperator . '' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->bitOperator . '' . $variableRight->getName(), $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableCode = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->_operator . ' zephir_is_true(' . $variableCode . ')', $expression); + return new CompiledExpression('bool', $variableLeft->getName() . ' ' . $this->operator . ' zephir_is_true(' . $variableCode . ')', $expression); default: throw new CompilerException("Cannot compare variable('double') with variable('" . $variableRight->getType() . "')", $expression); @@ -249,33 +247,33 @@ public function compile($expression, CompilationContext $compilationContext) case 'string': switch ($right->getType()) { case 'int': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->_operator . ' ' . $right->getCode(), $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->operator . ' ' . $right->getCode(), $expression); case 'double': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->_operator . ' ' . $right->getCode(), $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->operator . ' ' . $right->getCode(), $expression); case 'bool': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->_bitOperator . '' . $right->getBooleanCode(), $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->bitOperator . '' . $right->getBooleanCode(), $expression); case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); switch ($variableRight->getType()) { case 'int': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->_operator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->operator . ' ' . $variableRight->getName(), $expression); case 'double': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->_operator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->operator . ' ' . $variableRight->getName(), $expression); case 'string': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->_operator . ' (' . $variableRight->getName() . ' && Z_STRLEN_P(' . $variableRight->getName() . '))', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->operator . ' (' . $variableRight->getName() . ' && Z_STRLEN_P(' . $variableRight->getName() . '))', $expression); case 'bool': - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->_bitOperator . ' ' . $variableRight->getName(), $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . $this->bitOperator . ' ' . $variableRight->getName(), $expression); case 'variable': $compilationContext->headersManager->add('kernel/operators'); $variableCode = $compilationContext->backend->getVariableCode($variableRight); - return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . ' ' . $this->_operator . ' zephir_is_true(' . $variableCode . ')', $expression); + return new CompiledExpression('bool', '(' . $variableLeft->getName() . ' && Z_STRLEN_P(' . $variableLeft->getName() . ')) ' . ' ' . $this->operator . ' zephir_is_true(' . $variableCode . ')', $expression); default: throw new CompilerException("Cannot compare variable('double') with variable('" . $variableRight->getType() . "')", $expression); @@ -294,7 +292,7 @@ public function compile($expression, CompilationContext $compilationContext) case 'int': case 'double': $compilationContext->headersManager->add('kernel/operators'); - $op = $this->_operator; + $op = $this->operator; $op1 = $variableLeftCode; $op2 = $right->getCode(); $compilationContext->headersManager->add('kernel/operators'); @@ -303,7 +301,7 @@ public function compile($expression, CompilationContext $compilationContext) /* a && 1 */ case 'bool': $compilationContext->headersManager->add('kernel/operators'); - $op = $this->_operator; + $op = $this->operator; $op1 = $variableLeftCode; $op2 = $right->getCode(); $compilationContext->headersManager->add('kernel/operators'); @@ -317,12 +315,12 @@ public function compile($expression, CompilationContext $compilationContext) /* a(var) && a(int) */ case 'int': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', 'zephir_is_true(' . $variableLeftCode . ') ' . $this->_operator . ' ' . $variableRightCode, $expression); + return new CompiledExpression('bool', 'zephir_is_true(' . $variableLeftCode . ') ' . $this->operator . ' ' . $variableRightCode, $expression); /* a(var) && a(bool) */ case 'bool': $compilationContext->headersManager->add('kernel/operators'); - return new CompiledExpression('bool', 'zephir_is_true(' . $variableLeftCode . ') ' . $this->_operator . ' ' . $variableRightCode, $expression); + return new CompiledExpression('bool', 'zephir_is_true(' . $variableLeftCode . ') ' . $this->operator . ' ' . $variableRightCode, $expression); /* a(var) && a(var) */ case 'variable': diff --git a/Library/Operators/Logical/OrOperator.php b/Library/Operators/Logical/OrOperator.php index b9be96331f..0549793e0a 100644 --- a/Library/Operators/Logical/OrOperator.php +++ b/Library/Operators/Logical/OrOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Logical; @@ -21,9 +19,9 @@ class OrOperator extends LogicalBaseOperator { - protected $_operator = '||'; + protected $operator = '||'; - protected $_bitOperator = '||'; + protected $bitOperator = '||'; public function compile($expression, CompilationContext $compilationContext) { @@ -36,7 +34,7 @@ public function compile($expression, CompilationContext $compilationContext) } $leftExpr = new Expression($expression['left']); - $leftExpr->setReadOnly($this->_readOnly); + $leftExpr->setReadOnly($this->readOnly); $left = $leftExpr->compile($compilationContext); /** @@ -98,7 +96,7 @@ public function compile($expression, CompilationContext $compilationContext) $compilationContext->codePrinter->increaseLevel(); $rightExpr = new Expression($expression['right']); - $rightExpr->setReadOnly($this->_readOnly); + $rightExpr->setReadOnly($this->readOnly); $right = $rightExpr->compile($compilationContext); switch ($right->getType()) { diff --git a/Library/Operators/Other/CastOperator.php b/Library/Operators/Other/CastOperator.php index 86dbca1fdf..c00b735556 100644 --- a/Library/Operators/Other/CastOperator.php +++ b/Library/Operators/Other/CastOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; @@ -259,9 +257,9 @@ public function compile($expression, CompilationContext $compilationContext) case 'variable': $compilationContext->headersManager->add('kernel/operators'); $compilationContext->symbolTable->mustGrownStack(true); - $symbolVariable = $compilationContext->symbolTable->getTempVariable('array', $compilationContext, $expression); + $symbolVariable = $compilationContext->symbolTable->getTempVariable('array', $compilationContext); $symbolVariable->setMustInitNull(true); - $symbolVariable->setIsInitialized(true, $compilationContext, $expression); + $symbolVariable->setIsInitialized(true, $compilationContext); $symbolVariable->increaseUses(); $symbol = $compilationContext->backend->getVariableCode($symbolVariable); $resolvedVariable = $compilationContext->symbolTable->getVariableForRead($resolved->getCode(), $compilationContext); diff --git a/Library/Operators/Other/CloneOperator.php b/Library/Operators/Other/CloneOperator.php index 8edca1e2ad..64c316cb38 100644 --- a/Library/Operators/Other/CloneOperator.php +++ b/Library/Operators/Other/CloneOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; @@ -61,7 +59,7 @@ public function compile(array $expression, CompilationContext $compilationContex $symbolVariable->setDynamicTypes('object'); - $symbolVariable->setIsInitialized(true, $compilationContext, $expression); + $symbolVariable->setIsInitialized(true, $compilationContext); /* Inherit the dynamic type data from the cloned object */ $symbolVariable->setDynamicTypes($clonedVariable->getDynamicTypes()); diff --git a/Library/Operators/Other/ConcatOperator.php b/Library/Operators/Other/ConcatOperator.php index 4056e2dae3..7a15f43a22 100644 --- a/Library/Operators/Other/ConcatOperator.php +++ b/Library/Operators/Other/ConcatOperator.php @@ -1,24 +1,22 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; -use Zephir\Operators\BaseOperator; use Zephir\CompilationContext; -use Zephir\Expression; -use Zephir\Compiler\CompilerException; use Zephir\CompiledExpression; -use Zephir\Utils; +use Zephir\Compiler\CompilerException; +use Zephir\Expression; +use Zephir\Operators\BaseOperator; +use function Zephir\add_slashes; /** * ConcatOperator @@ -67,7 +65,7 @@ private function _getOptimizedConcat($expression, CompilationContext $compilatio break; default: - $expr->setReadOnly($this->_readOnly); + $expr->setReadOnly($this->readOnly); break; } @@ -102,7 +100,7 @@ private function _getOptimizedConcat($expression, CompilationContext $compilatio case 'string': $key .= 's'; - $concatParts[] = '"' . Utils::addSlashes($compiledExpr->getCode()) . '"'; + $concatParts[] = '"' . add_slashes($compiledExpr->getCode()) . '"'; break; case 'int': @@ -169,7 +167,7 @@ public function compile($expression, CompilationContext $compilationContext) break; default: - $leftExpr->setReadOnly($this->_readOnly); + $leftExpr->setReadOnly($this->readOnly); break; } $left = $leftExpr->compile($compilationContext); @@ -187,7 +185,7 @@ public function compile($expression, CompilationContext $compilationContext) break; default: - $rightExpr->setReadOnly($this->_readOnly); + $rightExpr->setReadOnly($this->readOnly); break; } $right = $rightExpr->compile($compilationContext); diff --git a/Library/Operators/Other/EmptyOperator.php b/Library/Operators/Other/EmptyOperator.php index a2b8ec52d7..43c68019bc 100644 --- a/Library/Operators/Other/EmptyOperator.php +++ b/Library/Operators/Other/EmptyOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; diff --git a/Library/Operators/Other/FetchOperator.php b/Library/Operators/Other/FetchOperator.php index 5f38f6d53e..2c1f058718 100644 --- a/Library/Operators/Other/FetchOperator.php +++ b/Library/Operators/Other/FetchOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; @@ -55,7 +53,7 @@ public function compile(array $expression, CompilationContext $compilationContex $numberMutations = $compilationContext->symbolTable->getExpectedMutations($variable->getName()); if ($numberMutations == 1) { if ($variable->getNumberMutations() == 1) { - $variable->setIsInitialized(true, $compilationContext, $expression); + $variable->setIsInitialized(true, $compilationContext); $variable->setMemoryTracked(false); $variable->setDynamicTypes('undefined'); $readOnly = true; @@ -64,13 +62,13 @@ public function compile(array $expression, CompilationContext $compilationContex } if (!$readOnly || $expression['right']['type'] != 'array-access') { - $variable->setIsInitialized(true, $compilationContext, $expression); + $variable->setIsInitialized(true, $compilationContext); $variable->observeVariant($compilationContext); $variable->setDynamicTypes('undefined'); $variable->setPossibleValue(new CompiledExpression('undefined', '', $expression), $compilationContext); } } else { - $variable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext, $expression); + $variable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext); } if ($readOnly) { diff --git a/Library/Operators/Other/InstanceOfOperator.php b/Library/Operators/Other/InstanceOfOperator.php index b8c6117419..46a21fc9ff 100644 --- a/Library/Operators/Other/InstanceOfOperator.php +++ b/Library/Operators/Other/InstanceOfOperator.php @@ -1,24 +1,23 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; -use Zephir\Operators\BaseOperator; use Zephir\CompilationContext; -use Zephir\Expression; use Zephir\CompiledExpression; -use Zephir\Utils; use Zephir\Compiler\CompilerException; +use Zephir\Expression; +use Zephir\Operators\BaseOperator; +use function Zephir\escape_class; +use function Zephir\fqcn; /** * InstanceOf @@ -54,7 +53,7 @@ public function compile($expression, CompilationContext $context) switch ($resolved->getType()) { case 'string': - $className = Utils::getFullName($resolvedVariable, $context->classDefinition->getNamespace(), $context->aliasManager); + $className = fqcn($resolvedVariable, $context->classDefinition->getNamespace(), $context->aliasManager); if ($context->compiler->isClass($className)) { $classDefinition = $context->compiler->getClassDefinition($className); @@ -95,11 +94,11 @@ public function compile($expression, CompilationContext $context) $classEntry = $classDefinition->getClassEntry($context); } else { if (!class_exists($className, false)) { - $code = 'SL("' . trim(Utils::escapeClassName($className), "\\") . '")'; + $code = 'SL("' . trim(escape_class($className), "\\") . '")'; } else { $classEntry = $context->classDefinition->getClassEntryByClassName($className, $context, true); if (!$classEntry) { - $code = 'SL("' . trim(Utils::escapeClassName($className), "\\") . '")'; + $code = 'SL("' . trim(escape_class($className), "\\") . '")'; } } } diff --git a/Library/Operators/Other/IssetOperator.php b/Library/Operators/Other/IssetOperator.php index 82ab73ab77..cf0e8a976f 100644 --- a/Library/Operators/Other/IssetOperator.php +++ b/Library/Operators/Other/IssetOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; diff --git a/Library/Operators/Other/LikelyOperator.php b/Library/Operators/Other/LikelyOperator.php index 006ac53102..6c896b1367 100644 --- a/Library/Operators/Other/LikelyOperator.php +++ b/Library/Operators/Other/LikelyOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; diff --git a/Library/Operators/Other/NewInstanceOperator.php b/Library/Operators/Other/NewInstanceOperator.php index 304b4ca9c5..fe1cca144d 100644 --- a/Library/Operators/Other/NewInstanceOperator.php +++ b/Library/Operators/Other/NewInstanceOperator.php @@ -1,25 +1,23 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; -use Zephir\Operators\BaseOperator; use Zephir\CompilationContext; -use Zephir\Expression; use Zephir\CompiledExpression; -use Zephir\MethodCall; -use Zephir\Utils; use Zephir\Compiler\CompilerException; +use Zephir\Expression; +use Zephir\MethodCall; +use Zephir\Operators\BaseOperator; +use function Zephir\escape_class; /** * NewInstance @@ -28,7 +26,7 @@ */ class NewInstanceOperator extends BaseOperator { - protected $_literalOnly = false; + protected $literalOnly = false; /** * Creates a new instance @@ -45,7 +43,7 @@ public function compile(array $expression, CompilationContext $compilationContex /** * Resolves the symbol that expects the value */ - $this->_literalOnly = false; + $this->literalOnly = false; $symbolVariable = $this->getExpectedNonLiteral($compilationContext, $expression); if (!$symbolVariable->isVariable()) { throw new CompilerException("Objects can only be instantiated into dynamic variables", $expression); @@ -121,9 +119,9 @@ public function compile(array $expression, CompilationContext $compilationContex * Use a safe string version of the variable to avoid segfaults */ $compilationContext->headersManager->add('kernel/object'); - $safeSymbolVariable = $compilationContext->symbolTable->getTempVariable('variable', $compilationContext, $expression); + $safeSymbolVariable = $compilationContext->symbolTable->getTempVariable('variable', $compilationContext); $safeSymbolVariable->setMustInitNull(true); - $safeSymbolVariable->setIsInitialized(true, $compilationContext, $expression); + $safeSymbolVariable->setIsInitialized(true, $compilationContext); $safeSymbolVariable->increaseUses(); $safeSymbol = $compilationContext->backend->getVariableCode($safeSymbolVariable); $classNameSymbol = $compilationContext->backend->getVariableCode($classNameVariable); @@ -135,7 +133,7 @@ public function compile(array $expression, CompilationContext $compilationContex } else { if (!class_exists($className, false)) { $compilationContext->logger->warning('Class "' . $className . '" does not exist at compile time', "nonexistent-class", $expression); - $classNameToFetch = 'SL("' . Utils::escapeClassName($className) . '")'; + $classNameToFetch = 'SL("' . escape_class($className) . '")'; $zendClassEntry = $compilationContext->cacheManager->getClassEntryCache()->get($classNameToFetch, false, $compilationContext); $classEntry = $zendClassEntry->getName(); @@ -153,7 +151,7 @@ public function compile(array $expression, CompilationContext $compilationContex $classEntry = $compilationContext->classDefinition->getClassEntryByClassName($className, $compilationContext, true); if (!$classEntry) { - $classNameToFetch = 'SL("' . Utils::escapeClassName($className) . '")'; + $classNameToFetch = 'SL("' . escape_class($className) . '")'; $zendClassEntry = $compilationContext->cacheManager->getClassEntryCache()->get($classNameToFetch, false, $compilationContext); $classEntry = $zendClassEntry->getName(); } else { @@ -170,7 +168,7 @@ public function compile(array $expression, CompilationContext $compilationContex /** * Mark variable initialized */ - $symbolVariable->setIsInitialized(true, $compilationContext, $expression); + $symbolVariable->setIsInitialized(true, $compilationContext); /** * Don't check the constructor for stdclass instances diff --git a/Library/Operators/Other/NewInstanceTypeOperator.php b/Library/Operators/Other/NewInstanceTypeOperator.php index d1eab01f81..257f946839 100644 --- a/Library/Operators/Other/NewInstanceTypeOperator.php +++ b/Library/Operators/Other/NewInstanceTypeOperator.php @@ -1,21 +1,20 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; use Zephir\Operators\BaseOperator; use Zephir\CompilationContext; use Zephir\Expression; +use Zephir\Exception; use Zephir\CompiledExpression; use Zephir\Compiler\CompilerException; use Zephir\Builder\FunctionCallBuilder; @@ -28,7 +27,7 @@ */ class NewInstanceTypeOperator extends BaseOperator { - protected $_literalOnly = false; + protected $literalOnly = false; /** * Executes the operator @@ -74,8 +73,12 @@ public function compile(array $expression, CompilationContext $compilationContex $castBuilder = new CastOperatorBuilder($expression['internal-type'], $builder); $expression = new Expression($castBuilder->get()); - $expression->setReadOnly($this->_readOnly); + $expression->setReadOnly($this->readOnly); - return $expression->compile($compilationContext); + try { + return $expression->compile($compilationContext); + } catch (Exception $e) { + throw new CompilerException($e->getMessage(), $expression, $e->getCode(), $e); + } } } diff --git a/Library/Operators/Other/RangeExclusiveOperator.php b/Library/Operators/Other/RangeExclusiveOperator.php index 15f2dd9b0d..29fd679e44 100644 --- a/Library/Operators/Other/RangeExclusiveOperator.php +++ b/Library/Operators/Other/RangeExclusiveOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; @@ -52,7 +50,7 @@ public function compile(array $expression, CompilationContext $compilationContex ->functionCall('range', array($expression['left'], $expression['right']))); $expression = new Expression($castBuilder->build()); - $expression->setReadOnly($this->_readOnly); + $expression->setReadOnly($this->readOnly); return $expression->compile($compilationContext); } } diff --git a/Library/Operators/Other/RangeInclusiveOperator.php b/Library/Operators/Other/RangeInclusiveOperator.php index bce012bf3c..3090e34359 100644 --- a/Library/Operators/Other/RangeInclusiveOperator.php +++ b/Library/Operators/Other/RangeInclusiveOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; @@ -52,7 +50,7 @@ public function compile(array $expression, CompilationContext $compilationContex ->functionCall('range', array($expression['left'], $expression['right']))); $expression = new Expression($castBuilder->build()); - $expression->setReadOnly($this->_readOnly); + $expression->setReadOnly($this->readOnly); return $expression->compile($compilationContext); } } diff --git a/Library/Operators/Other/RequireOperator.php b/Library/Operators/Other/RequireOperator.php index 04ea527ac7..d80668e53b 100644 --- a/Library/Operators/Other/RequireOperator.php +++ b/Library/Operators/Other/RequireOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; @@ -39,7 +37,6 @@ public function compile(array $expression, CompilationContext $compilationContex $expr->setExpectReturn(true); $exprPath = $expr->compile($compilationContext); - $exprVar = $exprPath->getCode(); if ($exprPath->getType() == 'variable') { $exprVariable = $compilationContext->symbolTable->getVariableForRead($exprPath->getCode(), $compilationContext, $expression); $exprVar = $compilationContext->backend->getVariableCode($exprVariable); diff --git a/Library/Operators/Other/ShortTernaryOperator.php b/Library/Operators/Other/ShortTernaryOperator.php index fbfe98a166..c23b054be1 100644 --- a/Library/Operators/Other/ShortTernaryOperator.php +++ b/Library/Operators/Other/ShortTernaryOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; diff --git a/Library/Operators/Other/TernaryOperator.php b/Library/Operators/Other/TernaryOperator.php index 0f4a475113..c0bb5302bf 100644 --- a/Library/Operators/Other/TernaryOperator.php +++ b/Library/Operators/Other/TernaryOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; diff --git a/Library/Operators/Other/TypeHintOperator.php b/Library/Operators/Other/TypeHintOperator.php index 1f9c2d129d..6faf380c70 100644 --- a/Library/Operators/Other/TypeHintOperator.php +++ b/Library/Operators/Other/TypeHintOperator.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Operators\Other; diff --git a/Library/Operators/Other/TypeOfOperator.php b/Library/Operators/Other/TypeOfOperator.php index 32a7c114a2..7ad28dbb7d 100644 --- a/Library/Operators/Other/TypeOfOperator.php +++ b/Library/Operators/Other/TypeOfOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; diff --git a/Library/Operators/Other/UnlikelyOperator.php b/Library/Operators/Other/UnlikelyOperator.php index 30bbdd7bda..20eb394677 100644 --- a/Library/Operators/Other/UnlikelyOperator.php +++ b/Library/Operators/Other/UnlikelyOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Other; diff --git a/Library/Operators/Unary/MinusOperator.php b/Library/Operators/Unary/MinusOperator.php index 7713855d0c..a58d49ac1b 100644 --- a/Library/Operators/Unary/MinusOperator.php +++ b/Library/Operators/Unary/MinusOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Unary; @@ -36,7 +34,7 @@ public function compile($expression, CompilationContext $compilationContext) } $leftExpr = new Expression($expression['left']); - $leftExpr->setReadOnly($this->_readOnly); + $leftExpr->setReadOnly($this->readOnly); $left = $leftExpr->compile($compilationContext); switch ($left->getType()) { diff --git a/Library/Operators/Unary/NotOperator.php b/Library/Operators/Unary/NotOperator.php index d692fec31b..79e189540a 100644 --- a/Library/Operators/Unary/NotOperator.php +++ b/Library/Operators/Unary/NotOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Unary; @@ -34,7 +32,7 @@ public function compile($expression, CompilationContext $compilationContext) } $leftExpr = new Expression($expression['left']); - $leftExpr->setReadOnly($this->_readOnly); + $leftExpr->setReadOnly($this->readOnly); $left = $leftExpr->compile($compilationContext); switch ($left->getType()) { diff --git a/Library/Operators/Unary/PlusOperator.php b/Library/Operators/Unary/PlusOperator.php index a79f919180..4b0121f959 100644 --- a/Library/Operators/Unary/PlusOperator.php +++ b/Library/Operators/Unary/PlusOperator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Operators\Unary; @@ -36,7 +34,7 @@ public function compile($expression, CompilationContext $compilationContext) } $leftExpr = new Expression($expression['left']); - $leftExpr->setReadOnly($this->_readOnly); + $leftExpr->setReadOnly($this->readOnly); $left = $leftExpr->compile($compilationContext); switch ($left->getType()) { diff --git a/Library/Optimizers/EvalExpression.php b/Library/Optimizers/EvalExpression.php index f2c6f267e3..fc207c8ac2 100644 --- a/Library/Optimizers/EvalExpression.php +++ b/Library/Optimizers/EvalExpression.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers; @@ -27,11 +25,11 @@ */ class EvalExpression { - protected $_unreachable = null; + protected $unreachable = null; - protected $_unreachableElse = null; + protected $unreachableElse = null; - protected $_usedVariables = array(); + protected $usedVariables = array(); /** * Skips the not operator by recursively optimizing the expression at its right @@ -49,11 +47,11 @@ public function optimizeNot($expr, CompilationContext $compilationContext) if ($expr['type'] == 'not') { $conditions = $this->optimize($expr['left'], $compilationContext); if ($conditions !== false) { - if ($this->_unreachable !== null) { - $this->_unreachable = !$this->_unreachable; + if ($this->unreachable !== null) { + $this->unreachable = !$this->unreachable; } - if ($this->_unreachableElse !== null) { - $this->_unreachableElse = !$this->_unreachableElse; + if ($this->unreachableElse !== null) { + $this->unreachableElse = !$this->unreachableElse; } return '!(' . $conditions . ')'; } @@ -102,7 +100,7 @@ public function optimize($exprRaw, CompilationContext $compilationContext) */ switch ($compiledExpression->getType()) { case 'null': - $this->_unreachable = true; + $this->unreachable = true; return '0'; case 'int': @@ -113,9 +111,9 @@ public function optimize($exprRaw, CompilationContext $compilationContext) $code = $compiledExpression->getCode(); if (is_numeric($code)) { if ($code == '1') { - $this->_unreachableElse = true; + $this->unreachableElse = true; } else { - $this->_unreachable = true; + $this->unreachable = true; } } return $code; @@ -127,10 +125,10 @@ public function optimize($exprRaw, CompilationContext $compilationContext) case 'bool': $code = $compiledExpression->getBooleanCode(); if ($code == '1') { - $this->_unreachableElse = true; + $this->unreachableElse = true; } else { if ($code == '0') { - $this->_unreachable = true; + $this->unreachable = true; } } return $code; @@ -148,30 +146,30 @@ public function optimize($exprRaw, CompilationContext $compilationContext) if ($possibleValue instanceof LiteralCompiledExpression) { switch ($possibleValue->getType()) { case 'null': - $this->_unreachable = true; + $this->unreachable = true; break; case 'bool': if ($possibleValue->getBooleanCode() == '0') { - $this->_unreachable = true; + $this->unreachable = true; } else { - $this->_unreachableElse = true; + $this->unreachableElse = true; } break; case 'int': if (!intval($possibleValue->getCode())) { - $this->_unreachable = true; + $this->unreachable = true; } else { - $this->_unreachableElse = true; + $this->unreachableElse = true; } break; case 'double': if (!floatval($possibleValue->getCode())) { - $this->_unreachable = true; + $this->unreachable = true; } else { - $this->_unreachableElse = true; + $this->unreachableElse = true; } break; @@ -183,7 +181,7 @@ public function optimize($exprRaw, CompilationContext $compilationContext) } } - $this->_usedVariables[] = $variableRight->getName(); + $this->usedVariables[] = $variableRight->getName(); /** * Evaluate the variable @@ -229,7 +227,7 @@ public function optimize($exprRaw, CompilationContext $compilationContext) */ public function isUnreachable() { - return $this->_unreachable; + return $this->unreachable; } /** @@ -239,7 +237,7 @@ public function isUnreachable() */ public function isUnreachableElse() { - return $this->_unreachableElse; + return $this->unreachableElse; } /** @@ -249,7 +247,7 @@ public function isUnreachableElse() */ public function getEvalVariable() { - return end($this->_usedVariables); + return end($this->usedVariables); } /** @@ -257,6 +255,6 @@ public function getEvalVariable() */ public function getUsedVariables() { - return $this->_usedVariables; + return $this->usedVariables; } } diff --git a/Library/Optimizers/FunctionCall/ACosOptimizer.php b/Library/Optimizers/FunctionCall/ACosOptimizer.php index bc50686a23..8e65bddc2d 100644 --- a/Library/Optimizers/FunctionCall/ACosOptimizer.php +++ b/Library/Optimizers/FunctionCall/ACosOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/ASinOptimizer.php b/Library/Optimizers/FunctionCall/ASinOptimizer.php index d041b2504e..e1f041e95b 100644 --- a/Library/Optimizers/FunctionCall/ASinOptimizer.php +++ b/Library/Optimizers/FunctionCall/ASinOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/AddslashesOptimizer.php b/Library/Optimizers/FunctionCall/AddslashesOptimizer.php index ae916465d8..4a08a9c0d7 100644 --- a/Library/Optimizers/FunctionCall/AddslashesOptimizer.php +++ b/Library/Optimizers/FunctionCall/AddslashesOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/ArrayKeyExistsOptimizer.php b/Library/Optimizers/FunctionCall/ArrayKeyExistsOptimizer.php index 22cecb2778..750b2c9300 100644 --- a/Library/Optimizers/FunctionCall/ArrayKeyExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/ArrayKeyExistsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/ArrayKeysOptimizer.php b/Library/Optimizers/FunctionCall/ArrayKeysOptimizer.php index ed4f5a3391..1e0c01c3f4 100644 --- a/Library/Optimizers/FunctionCall/ArrayKeysOptimizer.php +++ b/Library/Optimizers/FunctionCall/ArrayKeysOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/ArrayMergeOptimizer.php b/Library/Optimizers/FunctionCall/ArrayMergeOptimizer.php index 0108f0ae14..39dba4a387 100644 --- a/Library/Optimizers/FunctionCall/ArrayMergeOptimizer.php +++ b/Library/Optimizers/FunctionCall/ArrayMergeOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/BasenameOptimizer.php b/Library/Optimizers/FunctionCall/BasenameOptimizer.php index a608eb7ac9..2dc47f9c44 100644 --- a/Library/Optimizers/FunctionCall/BasenameOptimizer.php +++ b/Library/Optimizers/FunctionCall/BasenameOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CallUserFuncArrayOptimizer.php b/Library/Optimizers/FunctionCall/CallUserFuncArrayOptimizer.php index 34085e228f..3957cd6d95 100644 --- a/Library/Optimizers/FunctionCall/CallUserFuncArrayOptimizer.php +++ b/Library/Optimizers/FunctionCall/CallUserFuncArrayOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CallUserFuncOptimizer.php b/Library/Optimizers/FunctionCall/CallUserFuncOptimizer.php index ff7ef7f990..2d94b19be9 100644 --- a/Library/Optimizers/FunctionCall/CallUserFuncOptimizer.php +++ b/Library/Optimizers/FunctionCall/CallUserFuncOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CamelizeOptimizer.php b/Library/Optimizers/FunctionCall/CamelizeOptimizer.php index 707a45dd04..ed4fc9fd3f 100644 --- a/Library/Optimizers/FunctionCall/CamelizeOptimizer.php +++ b/Library/Optimizers/FunctionCall/CamelizeOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CeilOptimizer.php b/Library/Optimizers/FunctionCall/CeilOptimizer.php index 19f90b50bb..f564b789a7 100644 --- a/Library/Optimizers/FunctionCall/CeilOptimizer.php +++ b/Library/Optimizers/FunctionCall/CeilOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/ClassExistsOptimizer.php b/Library/Optimizers/FunctionCall/ClassExistsOptimizer.php index 288794e563..31c30e98b6 100644 --- a/Library/Optimizers/FunctionCall/ClassExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/ClassExistsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CompareMtimeOptimizer.php b/Library/Optimizers/FunctionCall/CompareMtimeOptimizer.php index 801918288b..c93ff1063b 100644 --- a/Library/Optimizers/FunctionCall/CompareMtimeOptimizer.php +++ b/Library/Optimizers/FunctionCall/CompareMtimeOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CosOptimizer.php b/Library/Optimizers/FunctionCall/CosOptimizer.php index a0a80e83fe..31ab9552fe 100644 --- a/Library/Optimizers/FunctionCall/CosOptimizer.php +++ b/Library/Optimizers/FunctionCall/CosOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CountOptimizer.php b/Library/Optimizers/FunctionCall/CountOptimizer.php index c5973b259d..c2927ab28c 100644 --- a/Library/Optimizers/FunctionCall/CountOptimizer.php +++ b/Library/Optimizers/FunctionCall/CountOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/Crc32Optimizer.php b/Library/Optimizers/FunctionCall/Crc32Optimizer.php index 83b17e7371..eee1abc5d0 100644 --- a/Library/Optimizers/FunctionCall/Crc32Optimizer.php +++ b/Library/Optimizers/FunctionCall/Crc32Optimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CreateArrayOptimizer.php b/Library/Optimizers/FunctionCall/CreateArrayOptimizer.php index 590fa26cc2..16d2982e03 100644 --- a/Library/Optimizers/FunctionCall/CreateArrayOptimizer.php +++ b/Library/Optimizers/FunctionCall/CreateArrayOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CreateInstanceOptimizer.php b/Library/Optimizers/FunctionCall/CreateInstanceOptimizer.php index eb6d675989..64fcf0a783 100644 --- a/Library/Optimizers/FunctionCall/CreateInstanceOptimizer.php +++ b/Library/Optimizers/FunctionCall/CreateInstanceOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CreateInstanceParamsOptimizer.php b/Library/Optimizers/FunctionCall/CreateInstanceParamsOptimizer.php index 09bf75dde3..165cb24c24 100644 --- a/Library/Optimizers/FunctionCall/CreateInstanceParamsOptimizer.php +++ b/Library/Optimizers/FunctionCall/CreateInstanceParamsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/CreateSymbolTableOptimizer.php b/Library/Optimizers/FunctionCall/CreateSymbolTableOptimizer.php index 885e22cb7b..0c105d7674 100644 --- a/Library/Optimizers/FunctionCall/CreateSymbolTableOptimizer.php +++ b/Library/Optimizers/FunctionCall/CreateSymbolTableOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/DieOptimizer.php b/Library/Optimizers/FunctionCall/DieOptimizer.php index 4768bf258f..4af4f46f48 100644 --- a/Library/Optimizers/FunctionCall/DieOptimizer.php +++ b/Library/Optimizers/FunctionCall/DieOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/DoublevalOptimizer.php b/Library/Optimizers/FunctionCall/DoublevalOptimizer.php index 266fb8d29f..8be57586ec 100644 --- a/Library/Optimizers/FunctionCall/DoublevalOptimizer.php +++ b/Library/Optimizers/FunctionCall/DoublevalOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/EndsWithOptimizer.php b/Library/Optimizers/FunctionCall/EndsWithOptimizer.php index 3422bdaeba..70af45f70a 100644 --- a/Library/Optimizers/FunctionCall/EndsWithOptimizer.php +++ b/Library/Optimizers/FunctionCall/EndsWithOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/EvalOptimizer.php b/Library/Optimizers/FunctionCall/EvalOptimizer.php index b7f9b39756..cb4d30af3a 100644 --- a/Library/Optimizers/FunctionCall/EvalOptimizer.php +++ b/Library/Optimizers/FunctionCall/EvalOptimizer.php @@ -1,7 +1,7 @@ * @@ -63,10 +63,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont } $evalContext = str_replace( - [ - ZEPHIRPATH . '\\', - ZEPHIRPATH . '/', - ], + [getcwd() . '\\', getcwd() . '/'], '', $expression['file'] . ':' . $expression['line'] ); diff --git a/Library/Optimizers/FunctionCall/ExitOptimizer.php b/Library/Optimizers/FunctionCall/ExitOptimizer.php index 7436a9d91c..790605427b 100644 --- a/Library/Optimizers/FunctionCall/ExitOptimizer.php +++ b/Library/Optimizers/FunctionCall/ExitOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/ExplodeOptimizer.php b/Library/Optimizers/FunctionCall/ExplodeOptimizer.php index 2fd955c760..8885cc1b43 100644 --- a/Library/Optimizers/FunctionCall/ExplodeOptimizer.php +++ b/Library/Optimizers/FunctionCall/ExplodeOptimizer.php @@ -1,24 +1,22 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; use Zephir\Call; use Zephir\CompilationContext; -use Zephir\Compiler\CompilerException; use Zephir\CompiledExpression; +use Zephir\Compiler\CompilerException; use Zephir\Optimizers\OptimizerAbstract; -use Zephir\Utils; +use function Zephir\add_slashes; /** * ExplodeOptimizer @@ -64,7 +62,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont } if ($expression['parameters'][0]['parameter']['type'] == 'string') { - $str = Utils::addSlashes($expression['parameters'][0]['parameter']['value']); + $str = add_slashes($expression['parameters'][0]['parameter']['value']); unset($expression['parameters'][0]); if (count($expression['parameters']) == 2) { $limitOffset = 1; diff --git a/Library/Optimizers/FunctionCall/FcloseOptimizer.php b/Library/Optimizers/FunctionCall/FcloseOptimizer.php index e2bc455cab..5f21b6619f 100644 --- a/Library/Optimizers/FunctionCall/FcloseOptimizer.php +++ b/Library/Optimizers/FunctionCall/FcloseOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/FeofOptimizer.php b/Library/Optimizers/FunctionCall/FeofOptimizer.php index 5252cd8c46..ff1cdd5413 100644 --- a/Library/Optimizers/FunctionCall/FeofOptimizer.php +++ b/Library/Optimizers/FunctionCall/FeofOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/FileExistsOptimizer.php b/Library/Optimizers/FunctionCall/FileExistsOptimizer.php index 7d4beb9246..10287999ed 100644 --- a/Library/Optimizers/FunctionCall/FileExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FileExistsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/FileGetContentsOptimizer.php b/Library/Optimizers/FunctionCall/FileGetContentsOptimizer.php index cacfcdf01f..3c4aed51a2 100644 --- a/Library/Optimizers/FunctionCall/FileGetContentsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FileGetContentsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/FilePutContentsOptimizer.php b/Library/Optimizers/FunctionCall/FilePutContentsOptimizer.php index c11df10131..ff389b462b 100644 --- a/Library/Optimizers/FunctionCall/FilePutContentsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FilePutContentsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/FilemtimeOptimizer.php b/Library/Optimizers/FunctionCall/FilemtimeOptimizer.php index 5defd8dc21..18be7ac57d 100644 --- a/Library/Optimizers/FunctionCall/FilemtimeOptimizer.php +++ b/Library/Optimizers/FunctionCall/FilemtimeOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/FloorOptimizer.php b/Library/Optimizers/FunctionCall/FloorOptimizer.php index c322c91527..01f1705d2b 100644 --- a/Library/Optimizers/FunctionCall/FloorOptimizer.php +++ b/Library/Optimizers/FunctionCall/FloorOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/FuncGetArgOptimizer.php b/Library/Optimizers/FunctionCall/FuncGetArgOptimizer.php index 45cc8bd801..f67d7a09d2 100644 --- a/Library/Optimizers/FunctionCall/FuncGetArgOptimizer.php +++ b/Library/Optimizers/FunctionCall/FuncGetArgOptimizer.php @@ -1,15 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ + namespace Zephir\Optimizers\FunctionCall; use Zephir\Call; diff --git a/Library/Optimizers/FunctionCall/FuncGetArgsOptimizer.php b/Library/Optimizers/FunctionCall/FuncGetArgsOptimizer.php index fd5c196cc6..ed3519ae43 100644 --- a/Library/Optimizers/FunctionCall/FuncGetArgsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FuncGetArgsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/FuncNumArgsOptimizer.php b/Library/Optimizers/FunctionCall/FuncNumArgsOptimizer.php index b0e79e6f82..f4d21383d0 100644 --- a/Library/Optimizers/FunctionCall/FuncNumArgsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FuncNumArgsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/FunctionExistsOptimizer.php b/Library/Optimizers/FunctionCall/FunctionExistsOptimizer.php index 45dffe2e22..6cbc53f9be 100644 --- a/Library/Optimizers/FunctionCall/FunctionExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/FunctionExistsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; @@ -17,7 +15,7 @@ use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Optimizers\OptimizerAbstract; -use Zephir\Utils; +use function Zephir\add_slashes; /** * FunctionExistsOptimizer @@ -39,7 +37,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont } if ($expression['parameters'][0]['parameter']['type'] == 'string') { - $str = Utils::addSlashes($expression['parameters'][0]['parameter']['value']); + $str = add_slashes($expression['parameters'][0]['parameter']['value']); unset($expression['parameters'][0]); } diff --git a/Library/Optimizers/FunctionCall/FwriteOptimizer.php b/Library/Optimizers/FunctionCall/FwriteOptimizer.php index ead4b8fb7f..8645aa0ee7 100644 --- a/Library/Optimizers/FunctionCall/FwriteOptimizer.php +++ b/Library/Optimizers/FunctionCall/FwriteOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/GetCalledClassOptimizer.php b/Library/Optimizers/FunctionCall/GetCalledClassOptimizer.php index 5f697fa854..b7aa052158 100644 --- a/Library/Optimizers/FunctionCall/GetCalledClassOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetCalledClassOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/GetClassLowerOptimizer.php b/Library/Optimizers/FunctionCall/GetClassLowerOptimizer.php index d64119262f..523da45776 100644 --- a/Library/Optimizers/FunctionCall/GetClassLowerOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetClassLowerOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/GetClassNsOptimizer.php b/Library/Optimizers/FunctionCall/GetClassNsOptimizer.php index f376d2d0c5..e75fbc2e60 100644 --- a/Library/Optimizers/FunctionCall/GetClassNsOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetClassNsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/GetClassOptimizer.php b/Library/Optimizers/FunctionCall/GetClassOptimizer.php index 1da22e2b9e..b944d06085 100644 --- a/Library/Optimizers/FunctionCall/GetClassOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetClassOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/GetDefinedVarsOptimizer.php b/Library/Optimizers/FunctionCall/GetDefinedVarsOptimizer.php index 4594f09815..48c40710d9 100644 --- a/Library/Optimizers/FunctionCall/GetDefinedVarsOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetDefinedVarsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/GetNsClassOptimizer.php b/Library/Optimizers/FunctionCall/GetNsClassOptimizer.php index a6777e3def..a487062169 100644 --- a/Library/Optimizers/FunctionCall/GetNsClassOptimizer.php +++ b/Library/Optimizers/FunctionCall/GetNsClassOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/GettypeOptimizer.php b/Library/Optimizers/FunctionCall/GettypeOptimizer.php index 9cb3a45004..f1855548ae 100644 --- a/Library/Optimizers/FunctionCall/GettypeOptimizer.php +++ b/Library/Optimizers/FunctionCall/GettypeOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/GlobalsGetOptimizer.php b/Library/Optimizers/FunctionCall/GlobalsGetOptimizer.php index e97a6397f6..8a221cd653 100644 --- a/Library/Optimizers/FunctionCall/GlobalsGetOptimizer.php +++ b/Library/Optimizers/FunctionCall/GlobalsGetOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/GlobalsSetOptimizer.php b/Library/Optimizers/FunctionCall/GlobalsSetOptimizer.php index 9d5238961c..f0994b4095 100644 --- a/Library/Optimizers/FunctionCall/GlobalsSetOptimizer.php +++ b/Library/Optimizers/FunctionCall/GlobalsSetOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/HashEqualsOptimizer.php b/Library/Optimizers/FunctionCall/HashEqualsOptimizer.php index cf4e55eccc..deeac531ea 100644 --- a/Library/Optimizers/FunctionCall/HashEqualsOptimizer.php +++ b/Library/Optimizers/FunctionCall/HashEqualsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/ImplodeOptimizer.php b/Library/Optimizers/FunctionCall/ImplodeOptimizer.php index 9f8b0dbffb..70e607c490 100644 --- a/Library/Optimizers/FunctionCall/ImplodeOptimizer.php +++ b/Library/Optimizers/FunctionCall/ImplodeOptimizer.php @@ -1,24 +1,22 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; use Zephir\Call; use Zephir\CompilationContext; -use Zephir\Compiler\CompilerException; use Zephir\CompiledExpression; +use Zephir\Compiler\CompilerException; use Zephir\Optimizers\OptimizerAbstract; -use Zephir\Utils; +use function Zephir\add_slashes; /** * ImplodeOptimizer @@ -55,7 +53,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont } if ($expression['parameters'][0]['parameter']['type'] == 'string') { - $str = Utils::addSlashes($expression['parameters'][0]['parameter']['value']); + $str = add_slashes($expression['parameters'][0]['parameter']['value']); unset($expression['parameters'][0]); } diff --git a/Library/Optimizers/FunctionCall/InArrayOptimizer.php b/Library/Optimizers/FunctionCall/InArrayOptimizer.php index 6e7406612f..b700e57666 100644 --- a/Library/Optimizers/FunctionCall/InArrayOptimizer.php +++ b/Library/Optimizers/FunctionCall/InArrayOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/InterfaceExistsOptimizer.php b/Library/Optimizers/FunctionCall/InterfaceExistsOptimizer.php index 64f1fc4bc2..52383ac722 100644 --- a/Library/Optimizers/FunctionCall/InterfaceExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/InterfaceExistsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IntvalOptimizer.php b/Library/Optimizers/FunctionCall/IntvalOptimizer.php index 374c20f028..39e66ae235 100644 --- a/Library/Optimizers/FunctionCall/IntvalOptimizer.php +++ b/Library/Optimizers/FunctionCall/IntvalOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsArrayOptimizer.php b/Library/Optimizers/FunctionCall/IsArrayOptimizer.php index 2eb395d659..9800058843 100644 --- a/Library/Optimizers/FunctionCall/IsArrayOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsArrayOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsBoolOptimizer.php b/Library/Optimizers/FunctionCall/IsBoolOptimizer.php index 683aff8fad..99ddb3fb2f 100644 --- a/Library/Optimizers/FunctionCall/IsBoolOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsBoolOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsCallableOptimizer.php b/Library/Optimizers/FunctionCall/IsCallableOptimizer.php index d937406f18..75f04e2a69 100644 --- a/Library/Optimizers/FunctionCall/IsCallableOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsCallableOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsIntOptimizer.php b/Library/Optimizers/FunctionCall/IsIntOptimizer.php index b0fc7aca06..8cd3ac4787 100644 --- a/Library/Optimizers/FunctionCall/IsIntOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsIntOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsNullOptimizer.php b/Library/Optimizers/FunctionCall/IsNullOptimizer.php index d2e92939b5..4c7a94b1c5 100644 --- a/Library/Optimizers/FunctionCall/IsNullOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsNullOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsNumericOptimizer.php b/Library/Optimizers/FunctionCall/IsNumericOptimizer.php index bd67d9d3fb..1e90781d05 100644 --- a/Library/Optimizers/FunctionCall/IsNumericOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsNumericOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsObjectOptimizer.php b/Library/Optimizers/FunctionCall/IsObjectOptimizer.php index 612b21ac7b..16742033fc 100644 --- a/Library/Optimizers/FunctionCall/IsObjectOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsObjectOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsPhpVersionOptimizer.php b/Library/Optimizers/FunctionCall/IsPhpVersionOptimizer.php index 823c4e5f17..a9ff9e1f69 100644 --- a/Library/Optimizers/FunctionCall/IsPhpVersionOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsPhpVersionOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsPrivatePropertyOptimizer.php b/Library/Optimizers/FunctionCall/IsPrivatePropertyOptimizer.php index 8379b4a162..a94814ae73 100644 --- a/Library/Optimizers/FunctionCall/IsPrivatePropertyOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsPrivatePropertyOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsResourceOptimizer.php b/Library/Optimizers/FunctionCall/IsResourceOptimizer.php index 06c36d31df..91b3ff5160 100644 --- a/Library/Optimizers/FunctionCall/IsResourceOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsResourceOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsScalarOptimizer.php b/Library/Optimizers/FunctionCall/IsScalarOptimizer.php index 764ea58794..4253addb2e 100644 --- a/Library/Optimizers/FunctionCall/IsScalarOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsScalarOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/IsStringOptimizer.php b/Library/Optimizers/FunctionCall/IsStringOptimizer.php index f60c9571ea..ed40ca1a18 100644 --- a/Library/Optimizers/FunctionCall/IsStringOptimizer.php +++ b/Library/Optimizers/FunctionCall/IsStringOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/JoinOptimizer.php b/Library/Optimizers/FunctionCall/JoinOptimizer.php index badeb90442..66c4771bea 100644 --- a/Library/Optimizers/FunctionCall/JoinOptimizer.php +++ b/Library/Optimizers/FunctionCall/JoinOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/JsonDecodeOptimizer.php b/Library/Optimizers/FunctionCall/JsonDecodeOptimizer.php index 7dc10d4ac3..ada4d34170 100644 --- a/Library/Optimizers/FunctionCall/JsonDecodeOptimizer.php +++ b/Library/Optimizers/FunctionCall/JsonDecodeOptimizer.php @@ -1,17 +1,13 @@ | - +--------------------------------------------------------------------------+ -*/ +/** + * This file is part of the Zephir. + * + * (c) Zephir Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/JsonEncodeOptimizer.php b/Library/Optimizers/FunctionCall/JsonEncodeOptimizer.php index e16a391e9f..c351091214 100644 --- a/Library/Optimizers/FunctionCall/JsonEncodeOptimizer.php +++ b/Library/Optimizers/FunctionCall/JsonEncodeOptimizer.php @@ -1,17 +1,13 @@ | - +--------------------------------------------------------------------------+ -*/ +/** + * This file is part of the Zephir. + * + * (c) Zephir Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/LdexpOptimizer.php b/Library/Optimizers/FunctionCall/LdexpOptimizer.php index 5282a294c0..ad2a29d971 100644 --- a/Library/Optimizers/FunctionCall/LdexpOptimizer.php +++ b/Library/Optimizers/FunctionCall/LdexpOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/LtrimOptimizer.php b/Library/Optimizers/FunctionCall/LtrimOptimizer.php index 6ba027c3d5..0af2615d72 100644 --- a/Library/Optimizers/FunctionCall/LtrimOptimizer.php +++ b/Library/Optimizers/FunctionCall/LtrimOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/Md5Optimizer.php b/Library/Optimizers/FunctionCall/Md5Optimizer.php index fb61d06c7d..b9f639d3a9 100644 --- a/Library/Optimizers/FunctionCall/Md5Optimizer.php +++ b/Library/Optimizers/FunctionCall/Md5Optimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/MemstrOptimizer.php b/Library/Optimizers/FunctionCall/MemstrOptimizer.php index b2c6e652bb..4fadac80f0 100644 --- a/Library/Optimizers/FunctionCall/MemstrOptimizer.php +++ b/Library/Optimizers/FunctionCall/MemstrOptimizer.php @@ -1,24 +1,22 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; use Zephir\Call; use Zephir\CompilationContext; use Zephir\CompiledExpression; -use Zephir\Optimizers\OptimizerAbstract; -use Zephir\Utils; use Zephir\Compiler; +use Zephir\Optimizers\OptimizerAbstract; +use function Zephir\add_slashes; /** * MemnstrOptimizer @@ -44,7 +42,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont } if ($expression['parameters'][1]['parameter']['type'] == 'string') { - $str = Utils::addSlashes($expression['parameters'][1]['parameter']['value']); + $str = add_slashes($expression['parameters'][1]['parameter']['value']); unset($expression['parameters'][1]); } diff --git a/Library/Optimizers/FunctionCall/MergeAppendOptimizer.php b/Library/Optimizers/FunctionCall/MergeAppendOptimizer.php index f5ca14a244..9534a18563 100644 --- a/Library/Optimizers/FunctionCall/MergeAppendOptimizer.php +++ b/Library/Optimizers/FunctionCall/MergeAppendOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/MethodExistsOptimizer.php b/Library/Optimizers/FunctionCall/MethodExistsOptimizer.php index f605fbaa47..3ec67ffbaf 100644 --- a/Library/Optimizers/FunctionCall/MethodExistsOptimizer.php +++ b/Library/Optimizers/FunctionCall/MethodExistsOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; @@ -17,7 +15,7 @@ use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Optimizers\OptimizerAbstract; -use Zephir\Utils; +use function Zephir\add_slashes; /** * MethodExistsOptimizer @@ -43,7 +41,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont } if ($expression['parameters'][1]['parameter']['type'] == 'string') { - $str = Utils::addSlashes($expression['parameters'][1]['parameter']['value']); + $str = add_slashes($expression['parameters'][1]['parameter']['value']); unset($expression['parameters'][1]); } diff --git a/Library/Optimizers/FunctionCall/MicrotimeOptimizer.php b/Library/Optimizers/FunctionCall/MicrotimeOptimizer.php index 66aeacf6e2..16ce0a1d39 100644 --- a/Library/Optimizers/FunctionCall/MicrotimeOptimizer.php +++ b/Library/Optimizers/FunctionCall/MicrotimeOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/MtRandOptimizer.php b/Library/Optimizers/FunctionCall/MtRandOptimizer.php index 7d452f1fb4..3ee848b901 100644 --- a/Library/Optimizers/FunctionCall/MtRandOptimizer.php +++ b/Library/Optimizers/FunctionCall/MtRandOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/NextOptimizer.php b/Library/Optimizers/FunctionCall/NextOptimizer.php deleted file mode 100644 index a8cefb2407..0000000000 --- a/Library/Optimizers/FunctionCall/NextOptimizer.php +++ /dev/null @@ -1,54 +0,0 @@ -headersManager->add('kernel/array'); - //$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression); - //return new CompiledExpression('fcall', 'zephir_array_next(' . $resolvedParams[0] . ' TSRMLS_CC)', $expression); - } -} diff --git a/Library/Optimizers/FunctionCall/ObStart.php b/Library/Optimizers/FunctionCall/ObStart.php deleted file mode 100644 index 2d2aee76d3..0000000000 --- a/Library/Optimizers/FunctionCall/ObStart.php +++ /dev/null @@ -1,52 +0,0 @@ - 0) { - return false; - } - - $context->headersManager->add('kernel/array'); - $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression); - return new CompiledExpression('null', 'zephir_ob_start(TSRMLS_C)', $expression); - } -} diff --git a/Library/Optimizers/FunctionCall/PowOptimizer.php b/Library/Optimizers/FunctionCall/PowOptimizer.php index b94349310f..9b9332e048 100644 --- a/Library/Optimizers/FunctionCall/PowOptimizer.php +++ b/Library/Optimizers/FunctionCall/PowOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/PregMatchAllOptimizer.php b/Library/Optimizers/FunctionCall/PregMatchAllOptimizer.php index 620fff64a4..6d9946d330 100644 --- a/Library/Optimizers/FunctionCall/PregMatchAllOptimizer.php +++ b/Library/Optimizers/FunctionCall/PregMatchAllOptimizer.php @@ -1,17 +1,13 @@ | - +--------------------------------------------------------------------------+ -*/ +/** + * This file is part of the Zephir. + * + * (c) Zephir Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/PregMatchOptimizer.php b/Library/Optimizers/FunctionCall/PregMatchOptimizer.php index 15151437a1..c0c25db9ec 100644 --- a/Library/Optimizers/FunctionCall/PregMatchOptimizer.php +++ b/Library/Optimizers/FunctionCall/PregMatchOptimizer.php @@ -1,121 +1,221 @@ | - +--------------------------------------------------------------------------+ -*/ +/** + * This file is part of the Zephir. + * + * (c) Zephir Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; use Zephir\Call; use Zephir\CompilationContext; -use Zephir\Compiler\CompilerException; use Zephir\CompiledExpression; +use Zephir\Compiler\CompilerException; +use Zephir\Exception; use Zephir\Optimizers\OptimizerAbstract; +use Zephir\Variable; /** - * PregMatchOptimizer + * Zephir\Optimizers\FunctionCall\PregMatchOptimizer * - * Optimizes calls to 'preg_match' using internal function + * Optimizes calls to 'preg_match' using internal function. + * + * @package Zephir\Optimizers\FunctionCall */ class PregMatchOptimizer extends OptimizerAbstract { const GLOBAL_MATCH = 0; /** - * @param array $expression - * @param Call $call - * @param CompilationContext $context - * @return bool|CompiledExpression|mixed + * {@inheritdoc} + * + * @param array $expression + * @param Call $call + * @param CompilationContext $context + * @return CompiledExpression + * * @throws CompilerException */ public function optimize(array $expression, Call $call, CompilationContext $context) { - if (!isset($expression['parameters'])) { - return false; + if (!isset($expression['parameters']) || count($expression['parameters']) < 2) { + throw new CompilerException( + sprintf( + 'preg_match() expects at least 2 parameters, %d given', + isset($expression['parameters']) ? count($expression['parameters']) : 0 + ), + $expression + ); } - if (count($expression['parameters']) < 2 || count($expression['parameters']) > 3) { - return false; + if (count($expression['parameters']) > 5) { + throw new CompilerException( + sprintf( + 'preg_match() expects at most 5 parameters, %d given', + count($expression['parameters']) + ), + $expression + ); } + $matches = $this->createMatches($expression, $context); + list($flags, $offset) = $this->processOptionals($expression, $call, $context); + /** - * Process the matches result + * Process the expected symbol to be returned */ - if (isset($expression['parameters'][2]) && $expression['parameters'][2]['parameter']['type'] == 'variable') { - $matchesVariable = $context->symbolTable->getVariable($expression['parameters'][2]['parameter']['value']); - if (!$matchesVariable->isInitialized()) { - $matchesVariable->initVariant($context); - $matchesVariable->setIsInitialized(true, $context, array()); + $call->processExpectedReturn($context); + + $symbolVariable = $call->getSymbolVariable(true, $context); + + if (!$symbolVariable->isVariable()) { + throw new CompilerException( + 'Returned values by functions can only be assigned to variant variables', + $expression + ); + } + + $context->headersManager->add('kernel/string'); + + try { + $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression); + + if ($call->mustInitSymbolVariable()) { + $symbolVariable->initVariant($context); } - } else { - $matchesVariable = $context->symbolTable->addTemp('variable', $context); - $matchesVariable->initVariant($context); + + $symbol = $context->backend->getVariableCode($symbolVariable); + $matchesSymbol = $context->backend->getVariableCode($matches); + + $context->codePrinter->output( + sprintf( + 'zephir_preg_match(%s, %s, %s, %s, %d, %s, %s TSRMLS_CC);', + $symbol, + $resolvedParams[0], + $resolvedParams[1], + $matchesSymbol, + static::GLOBAL_MATCH, + $flags, + $offset + ) + ); + + return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression); + } catch (Exception $e) { + throw new CompilerException($e->getMessage(), $expression, $e->getCode(), $e); } + } - $matchesVariable->setDynamicTypes('array'); + /** + * Process optional parameters. + * + * preg_match(pattern, subject, matches, flags, offset) + * + * @param array $expression + * @param Call $call + * @param CompilationContext $context + * @return array + * + * @throws CompilerException + */ + private function processOptionals(array &$expression, Call $call, CompilationContext $context) + { + $flags = null; + $offset = null; - /** - * Process optional parameters - */ $offsetParamOffset = 4; - if (isset($expression['parameters'][4]) && $expression['parameters'][4]['parameter']['type'] == 'int') { + if (isset($expression['parameters'][4]) && $expression['parameters'][4]['parameter']['type'] === 'int') { $offset = $expression['parameters'][4]['parameter']['value'] . ' '; unset($expression['parameters'][4]); } - if (isset($expression['parameters'][3]) && $expression['parameters'][3]['parameter']['type'] == 'int') { + if (isset($expression['parameters'][3]) && $expression['parameters'][3]['parameter']['type'] === 'int') { $flags = $expression['parameters'][3]['parameter']['value'] . ' '; - unset($expression['parameters'][3]); $offsetParamOffset = 3; + unset($expression['parameters'][3]); } - /** - * Process the expected symbol to be returned - */ - $call->processExpectedReturn($context); - - $symbolVariable = $call->getSymbolVariable(true, $context); - - if (!$symbolVariable->isVariable()) { - throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression); - } - - $context->headersManager->add('kernel/string'); - - $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression); + try { + $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression); - if (!isset($offset) && isset($resolvedParams[$offsetParamOffset])) { - $context->headersManager->add('kernel/operators'); - $offset = 'zephir_get_intval(' . $resolvedParams[$offsetParamOffset] . ') '; - } + if ($offset === null && isset($resolvedParams[$offsetParamOffset])) { + $context->headersManager->add('kernel/operators'); + $offset = 'zephir_get_intval(' . $resolvedParams[$offsetParamOffset] . ') '; + } - if (!isset($flags) && isset($resolvedParams[3])) { - $context->headersManager->add('kernel/operators'); - $flags = 'zephir_get_intval(' . $resolvedParams[3] . ') '; + if ($flags === null && isset($resolvedParams[3])) { + $context->headersManager->add('kernel/operators'); + $flags = 'zephir_get_intval(' . $resolvedParams[3] . ') '; + } + } catch (Exception $e) { + throw new CompilerException($e->getMessage(), $expression, $e->getCode(), $e); } - if (!isset($flags)) { + if ($flags === null) { $flags = '0 '; } - if (!isset($offset)) { + + if ($offset === null) { $offset = '0 '; } - if ($call->mustInitSymbolVariable()) { - $symbolVariable->initVariant($context); + return [$flags, $offset]; + } + + /** + * Process the matches result. + * + * preg_match(pattern, subject, matches) + * + * @param array $expression + * @param CompilationContext $context + * + * @return Variable + */ + private function createMatches(array $expression, CompilationContext $context) + { + if (isset($expression['parameters'][2])) { + $type = $expression['parameters'][2]['parameter']['type']; + + if ($type !== 'variable') { + throw new CompilerException('Only variables can be passed by reference', $expression); + } + + $name = $expression['parameters'][2]['parameter']['value']; + + if (!$variable = $context->symbolTable->getVariable($name)) { + throw new CompilerException( + sprintf("Cannot mutate variable '%s' because it wasn't defined", $name), + $expression + ); + } + + if (!in_array($variable->getType(), ['variable', 'array'], true)) { + throw new CompilerException( + sprintf( + "The '%s' variable must be either a variable or an array, got %s", + $name, + $variable->getType() + ), + $expression + ); + } + + if ($variable->isInitialized() == false) { + $variable->initVariant($context); + $variable->setIsInitialized(true, $context); + } + } else { + $variable = $context->symbolTable->addTemp('variable', $context); + $variable->initVariant($context); } - $symbol = $context->backend->getVariableCode($symbolVariable); - $matchesSymbol = $context->backend->getVariableCode($matchesVariable); - $context->codePrinter->output('zephir_preg_match(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', ' . $matchesSymbol . ', ' . $this::GLOBAL_MATCH . ', ' . $flags . ', ' . $offset . ' TSRMLS_CC);'); - return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression); + + $variable->setDynamicTypes('array'); + + return $variable; } } diff --git a/Library/Optimizers/FunctionCall/PrepareVirtualPathOptimizer.php b/Library/Optimizers/FunctionCall/PrepareVirtualPathOptimizer.php index 637d5f37ca..730da5cffb 100644 --- a/Library/Optimizers/FunctionCall/PrepareVirtualPathOptimizer.php +++ b/Library/Optimizers/FunctionCall/PrepareVirtualPathOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/RoundOptimizer.php b/Library/Optimizers/FunctionCall/RoundOptimizer.php index 07c313646e..7620779211 100644 --- a/Library/Optimizers/FunctionCall/RoundOptimizer.php +++ b/Library/Optimizers/FunctionCall/RoundOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/RtrimOptimizer.php b/Library/Optimizers/FunctionCall/RtrimOptimizer.php index 1b04d11584..ca941c42f9 100644 --- a/Library/Optimizers/FunctionCall/RtrimOptimizer.php +++ b/Library/Optimizers/FunctionCall/RtrimOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/SinOptimizer.php b/Library/Optimizers/FunctionCall/SinOptimizer.php index df404ceccb..1992227711 100644 --- a/Library/Optimizers/FunctionCall/SinOptimizer.php +++ b/Library/Optimizers/FunctionCall/SinOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/SqrtOptimizer.php b/Library/Optimizers/FunctionCall/SqrtOptimizer.php index 895ac7c28a..c6328df8ee 100644 --- a/Library/Optimizers/FunctionCall/SqrtOptimizer.php +++ b/Library/Optimizers/FunctionCall/SqrtOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/StartsWithOptimizer.php b/Library/Optimizers/FunctionCall/StartsWithOptimizer.php index 709a8d03a9..f04dbb858f 100644 --- a/Library/Optimizers/FunctionCall/StartsWithOptimizer.php +++ b/Library/Optimizers/FunctionCall/StartsWithOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php b/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php index 30c06a01a7..d823cc53c1 100644 --- a/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrReplaceOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/StripcslashesOptimizer.php b/Library/Optimizers/FunctionCall/StripcslashesOptimizer.php index 27c710b717..e8ba68f489 100644 --- a/Library/Optimizers/FunctionCall/StripcslashesOptimizer.php +++ b/Library/Optimizers/FunctionCall/StripcslashesOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/StripslashesOptimizer.php b/Library/Optimizers/FunctionCall/StripslashesOptimizer.php index acd5c6d3c2..954796ad56 100644 --- a/Library/Optimizers/FunctionCall/StripslashesOptimizer.php +++ b/Library/Optimizers/FunctionCall/StripslashesOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/StrlenOptimizer.php b/Library/Optimizers/FunctionCall/StrlenOptimizer.php index c2c7ae5e77..be7321430d 100644 --- a/Library/Optimizers/FunctionCall/StrlenOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrlenOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/StrposOptimizer.php b/Library/Optimizers/FunctionCall/StrposOptimizer.php index ccd09e888f..6d7d986c10 100644 --- a/Library/Optimizers/FunctionCall/StrposOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrposOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/StrtokOptimizer.php b/Library/Optimizers/FunctionCall/StrtokOptimizer.php index b4a75e3159..bf507d18f7 100644 --- a/Library/Optimizers/FunctionCall/StrtokOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrtokOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/StrtolowerOptimizer.php b/Library/Optimizers/FunctionCall/StrtolowerOptimizer.php index 6de9fa1674..6583b6bed5 100644 --- a/Library/Optimizers/FunctionCall/StrtolowerOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrtolowerOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/StrtoupperOptimizer.php b/Library/Optimizers/FunctionCall/StrtoupperOptimizer.php index de404b21e9..a7e0782852 100644 --- a/Library/Optimizers/FunctionCall/StrtoupperOptimizer.php +++ b/Library/Optimizers/FunctionCall/StrtoupperOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/SubstrOptimizer.php b/Library/Optimizers/FunctionCall/SubstrOptimizer.php index 4587124b94..2b868062c0 100644 --- a/Library/Optimizers/FunctionCall/SubstrOptimizer.php +++ b/Library/Optimizers/FunctionCall/SubstrOptimizer.php @@ -1,17 +1,13 @@ | - +--------------------------------------------------------------------------+ -*/ +/** + * This file is part of the Zephir. + * + * (c) Zephir Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/TanOptimizer.php b/Library/Optimizers/FunctionCall/TanOptimizer.php index 3c5acd687a..92d3723853 100644 --- a/Library/Optimizers/FunctionCall/TanOptimizer.php +++ b/Library/Optimizers/FunctionCall/TanOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/TimeOptimizer.php b/Library/Optimizers/FunctionCall/TimeOptimizer.php index 61f8c11edd..f780819fa1 100644 --- a/Library/Optimizers/FunctionCall/TimeOptimizer.php +++ b/Library/Optimizers/FunctionCall/TimeOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/TrimOptimizer.php b/Library/Optimizers/FunctionCall/TrimOptimizer.php index 7c4017ca6b..eb9f00653e 100644 --- a/Library/Optimizers/FunctionCall/TrimOptimizer.php +++ b/Library/Optimizers/FunctionCall/TrimOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/UcfirstOptimizer.php b/Library/Optimizers/FunctionCall/UcfirstOptimizer.php index 64b95a88d4..e24373970f 100644 --- a/Library/Optimizers/FunctionCall/UcfirstOptimizer.php +++ b/Library/Optimizers/FunctionCall/UcfirstOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/UncamelizeOptimizer.php b/Library/Optimizers/FunctionCall/UncamelizeOptimizer.php index e09059943e..8ad8f0def4 100644 --- a/Library/Optimizers/FunctionCall/UncamelizeOptimizer.php +++ b/Library/Optimizers/FunctionCall/UncamelizeOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/UniqueKeyOptimizer.php b/Library/Optimizers/FunctionCall/UniqueKeyOptimizer.php index 6c6635d732..4c9d7dc80e 100644 --- a/Library/Optimizers/FunctionCall/UniqueKeyOptimizer.php +++ b/Library/Optimizers/FunctionCall/UniqueKeyOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/UniquePathKeyOptimizer.php b/Library/Optimizers/FunctionCall/UniquePathKeyOptimizer.php index 1ccd1b0ab3..63e6d33707 100644 --- a/Library/Optimizers/FunctionCall/UniquePathKeyOptimizer.php +++ b/Library/Optimizers/FunctionCall/UniquePathKeyOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/VarDumpOptimizer.php b/Library/Optimizers/FunctionCall/VarDumpOptimizer.php index 0a88fa39f5..ddcc817497 100644 --- a/Library/Optimizers/FunctionCall/VarDumpOptimizer.php +++ b/Library/Optimizers/FunctionCall/VarDumpOptimizer.php @@ -1,17 +1,13 @@ | - +--------------------------------------------------------------------------+ -*/ +/** + * This file is part of the Zephir. + * + * (c) Zephir Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/VarExportOptimizer.php b/Library/Optimizers/FunctionCall/VarExportOptimizer.php index 55e24c2ca7..725a9358e2 100644 --- a/Library/Optimizers/FunctionCall/VarExportOptimizer.php +++ b/Library/Optimizers/FunctionCall/VarExportOptimizer.php @@ -1,17 +1,13 @@ | - +--------------------------------------------------------------------------+ -*/ +/** + * This file is part of the Zephir. + * + * (c) Zephir Team + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/FunctionCall/ZephirStringToHexOptimizer.php b/Library/Optimizers/FunctionCall/ZephirStringToHexOptimizer.php index 360b1891c8..620f6dacc6 100644 --- a/Library/Optimizers/FunctionCall/ZephirStringToHexOptimizer.php +++ b/Library/Optimizers/FunctionCall/ZephirStringToHexOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers\FunctionCall; diff --git a/Library/Optimizers/IsTypeOptimizerAbstract.php b/Library/Optimizers/IsTypeOptimizerAbstract.php index 5769eac7bc..4b13e111a9 100644 --- a/Library/Optimizers/IsTypeOptimizerAbstract.php +++ b/Library/Optimizers/IsTypeOptimizerAbstract.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers; diff --git a/Library/Optimizers/MathOptimizer.php b/Library/Optimizers/MathOptimizer.php index 22f05aee93..44792968c4 100644 --- a/Library/Optimizers/MathOptimizer.php +++ b/Library/Optimizers/MathOptimizer.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers; diff --git a/Library/Optimizers/OptimizerAbstract.php b/Library/Optimizers/OptimizerAbstract.php index 654d6e419b..3b44eab11f 100644 --- a/Library/Optimizers/OptimizerAbstract.php +++ b/Library/Optimizers/OptimizerAbstract.php @@ -1,26 +1,30 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Optimizers; use Zephir\Call; use Zephir\CompilationContext; +use Zephir\Di\InjectionAwareInterface; +use Zephir\Di\ContainerAwareTrait; /** * Class OptimizerAbstract */ -abstract class OptimizerAbstract +abstract class OptimizerAbstract implements InjectionAwareInterface { + use ContainerAwareTrait { + ContainerAwareTrait::__construct as protected __DiInject; + } + /** * @param array $expression * @param Call $call diff --git a/Library/Parser.php b/Library/Parser.php index 3af3d7ce42..e085fab69b 100644 --- a/Library/Parser.php +++ b/Library/Parser.php @@ -1,17 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ - namespace Zephir; use Zephir\Parser\ParseException; diff --git a/Library/Parser/Manager.php b/Library/Parser/Manager.php index 081cd7b3de..8b75488249 100644 --- a/Library/Parser/Manager.php +++ b/Library/Parser/Manager.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Parser; @@ -50,11 +48,10 @@ class Manager /** * Manager constructor. * - * @param Parser $parser The Zephir Parser - * @param Logger $logger The Zephir Logger - * @param array $parameters Additional parameters [Optional] + * @param Parser $parser The Zephir Parser + * @param Logger $logger The Zephir Logger */ - public function __construct(Parser $parser, Logger $logger, array $parameters = []) + public function __construct(Parser $parser, Logger $logger) { $this->parser = $parser; $this->logger = $logger; diff --git a/Library/Parser/ParseException.php b/Library/Parser/ParseException.php index 1780fa8164..8ef768ae2f 100644 --- a/Library/Parser/ParseException.php +++ b/Library/Parser/ParseException.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Parser; diff --git a/Library/Passes/CallGathererPass.php b/Library/Passes/CallGathererPass.php index a98b8d0480..ff4174957b 100644 --- a/Library/Passes/CallGathererPass.php +++ b/Library/Passes/CallGathererPass.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir\Passes; diff --git a/Library/Passes/LocalContextPass.php b/Library/Passes/LocalContextPass.php index 445d4c70ba..d79cc634f0 100644 --- a/Library/Passes/LocalContextPass.php +++ b/Library/Passes/LocalContextPass.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Passes; diff --git a/Library/Passes/LoopBreakPass.php b/Library/Passes/LoopBreakPass.php index f4adb586c7..53ece62303 100644 --- a/Library/Passes/LoopBreakPass.php +++ b/Library/Passes/LoopBreakPass.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Passes; diff --git a/Library/Passes/MutateGathererPass.php b/Library/Passes/MutateGathererPass.php index 329b673ead..ffeb2a568c 100644 --- a/Library/Passes/MutateGathererPass.php +++ b/Library/Passes/MutateGathererPass.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Passes; diff --git a/Library/Passes/SkipVariantInit.php b/Library/Passes/SkipVariantInit.php index 1ba0993018..2129f888e1 100644 --- a/Library/Passes/SkipVariantInit.php +++ b/Library/Passes/SkipVariantInit.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Passes; diff --git a/Library/Passes/StaticTypeInference.php b/Library/Passes/StaticTypeInference.php index 10bc3ff3cb..f097a398a0 100644 --- a/Library/Passes/StaticTypeInference.php +++ b/Library/Passes/StaticTypeInference.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Passes; diff --git a/Library/Providers/BackendProvider.php b/Library/Providers/BackendProvider.php new file mode 100644 index 0000000000..b67db2bc8a --- /dev/null +++ b/Library/Providers/BackendProvider.php @@ -0,0 +1,89 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Providers; + +use League\Container\Container; +use Psr\Container\ContainerInterface; +use Zephir\BaseBackend; +use Zephir\CommandArgumentParser; +use Zephir\Config; +use Zephir\Di\ServiceProviderInterface; +use Zephir\Exception\IllegalStateException; + +/** + * Zephir\Providers\BackendProvider + * + * @package Zephir\Providers + */ +final class BackendProvider implements ServiceProviderInterface +{ + /** + * {@inheritdoc} + * + * @param ContainerInterface|Container $container + * @return void + * + * @throws IllegalStateException + */ + public function register(ContainerInterface $container) + { + $backendClassName = $this->resolveBackendClass($container); + + $container->add(BaseBackend::class, function () use ($container, $backendClassName) { + return new $backendClassName($container->get(Config::class)); + }); + } + + /** + * Resolve backend class. + * + * @param ContainerInterface $container + * @return string + * + * @throws IllegalStateException + */ + private function resolveBackendClass(ContainerInterface $container) + { + $params = []; + + if (count($_SERVER['argv']) > 2) { + $args = array_slice($_SERVER['argv'], 2); + + /** @var CommandArgumentParser $parser */ + $parser = $container->get(CommandArgumentParser::class); + $params = $parser->parseArgs(array_merge(['command'], $args)); + } + + // Do not use this feature for typical use case. + // Overriding backend using env var provided only for + // testing purposes and may be removed in future. + if ($backend = getenv('ZEPHIR_BACKEND')) { + $params['backend'] = $backend; + } elseif ($container->has('ZEPHIR_BACKEND')) { + $params['backend'] = $container->get('ZEPHIR_BACKEND'); + } + + if (isset($params['backend'])) { + $backend = $params['backend']; + } else { + $backend = BaseBackend::getActiveBackend(); + } + + $className = "Zephir\\Backends\\{$backend}\\Backend"; + + if (!class_exists($className)) { + throw new IllegalStateException(sprintf('Backend class "%s" doesn\'t exist.', $backend)); + } + + return $className; + } +} diff --git a/Library/Providers/CommandsManagerProvider.php b/Library/Providers/CommandsManagerProvider.php new file mode 100644 index 0000000000..c7f17bbabd --- /dev/null +++ b/Library/Providers/CommandsManagerProvider.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Providers; + +use League\Container\Container; +use Psr\Container\ContainerInterface; +use Zephir\Commands\Manager; +use Zephir\Di\ServiceProviderInterface; + +/** + * Zephir\Providers\CommandsManagerProvider + * + * @package Zephir\Providers + */ +final class CommandsManagerProvider implements ServiceProviderInterface +{ + /** + * {@inheritdoc} + * + * @param ContainerInterface|Container $container + * @return void + */ + public function register(ContainerInterface $container) + { + $container->share(Manager::class, function () use ($container) { + $manager = new Manager($container); + $manager->registerBuiltinCommands(); + + return $manager; + }); + } +} diff --git a/Library/Providers/CompillerProvider.php b/Library/Providers/CompillerProvider.php new file mode 100644 index 0000000000..c61c265cd1 --- /dev/null +++ b/Library/Providers/CompillerProvider.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Providers; + +use League\Container\Container; +use Psr\Container\ContainerInterface; +use Zephir\BaseBackend; +use Zephir\Compiler; +use Zephir\Config; +use Zephir\Di\ServiceProviderInterface; +use Zephir\Logger; +use Zephir\Parser\Manager; + +/** + * Zephir\Providers\CompillerProvider + * + * @package Zephir\Providers + */ +final class CompillerProvider implements ServiceProviderInterface +{ + /** + * {@inheritdoc} + * + * @param ContainerInterface|Container $container + * @return void + */ + public function register(ContainerInterface $container) + { + $container->add( + Compiler::class, + function () use ($container) { + $compiller = new Compiler( + $container->get(Config::class), + $container->get(Logger::class), + $container->get(BaseBackend::class), + $container->get(Manager::class) + ); + + $compiller->setContainer($container); + + return $compiller; + } + ); + } +} diff --git a/Library/Providers/ConfigProvider.php b/Library/Providers/ConfigProvider.php new file mode 100644 index 0000000000..ea2c1f3992 --- /dev/null +++ b/Library/Providers/ConfigProvider.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Providers; + +use League\Container\Container; +use Psr\Container\ContainerInterface; +use Zephir\Config; +use Zephir\Di\ServiceProviderInterface; + +/** + * Zephir\Providers\ConfigProvider + * + * @package Zephir\Providers + */ +final class ConfigProvider implements ServiceProviderInterface +{ + /** + * {@inheritdoc} + * + * @param ContainerInterface|Container $container + * @return void + */ + public function register(ContainerInterface $container) + { + $container->share(Config::class, Config::fromServer()); + } +} diff --git a/Library/Providers/ParserManagerProvider.php b/Library/Providers/ParserManagerProvider.php new file mode 100644 index 0000000000..0ef56c706e --- /dev/null +++ b/Library/Providers/ParserManagerProvider.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Providers; + +use League\Container\Container; +use Psr\Container\ContainerInterface; +use Zephir\Di\ServiceProviderInterface; +use Zephir\Logger; +use Zephir\Parser; +use Zephir\Parser\Manager; + +/** + * Zephir\Providers\ParserManagerProvider + * + * @package Zephir\Providers + */ +final class ParserManagerProvider implements ServiceProviderInterface +{ + /** + * {@inheritdoc} + * + * @param ContainerInterface|Container $container + * @return void + */ + public function register(ContainerInterface $container) + { + $container->share(Manager::class, function () use ($container) { + return new Manager($container->get(Parser::class), $container->get(Logger::class)); + }); + } +} diff --git a/Library/ServiceRegistrator.php b/Library/ServiceRegistrator.php new file mode 100644 index 0000000000..ccb01de2ee --- /dev/null +++ b/Library/ServiceRegistrator.php @@ -0,0 +1,198 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir; + +use Psr\Container\ContainerInterface; +use Zephir\Di\ContainerAwareTrait; +use Zephir\Di\InjectionAwareInterface; +use Zephir\Di\ServiceProviderInterface; +use Zephir\Exception\InvalidArgumentException; +use Zephir\Providers\BackendProvider; +use Zephir\Providers\CommandsManagerProvider; +use Zephir\Providers\ConfigProvider; +use Zephir\Providers\ParserManagerProvider; + +/** + * Zephir\ServiceRegistrator + * + * @package Zephir + */ +final class ServiceRegistrator implements InjectionAwareInterface +{ + use ContainerAwareTrait { + ContainerAwareTrait::__construct as protected __DiInject; + } + + /** + * The base path for the application. + * + * @var string + */ + protected $basePath; + + /** + * A list of the registered service providers. + * + * @var ServiceProviderInterface[] + */ + public $serviceProviders = []; + + /** + * ServiceRegistrator constructor. + * + * @param string|null $basePath + * @param ContainerInterface|null $container + */ + public function __construct($basePath, ContainerInterface $container = null) + { + $this->__DiInject($container); + + $this->registerBaseBindings(); + $this->createEnvironment($basePath); + $this->registerBaseServices(); + } + + /** + * Registers the base bindings. + * + * @return void + */ + protected function registerBaseBindings() + { + $container = $this->getContainer(); + + $container->share(Version::class, Version::class); + $container->share(Parser::class, Parser::class); + $container->share(CommandArgumentParser::class, CommandArgumentParser::class); + + $container->share(Logger::class, function () use ($container) { + return new Logger($container->get(Config::class)); + }); + } + + /** + * Registers the base services. + * + * @return void + */ + protected function registerBaseServices() + { + $this->registerService(new ConfigProvider()); + $this->registerService(new ParserManagerProvider()); + $this->registerService(new BackendProvider()); + $this->registerService(new CommandsManagerProvider()); + } + + /** + * Creates and registers application environment. + * + * @param string|null $basePath + * @return void + */ + protected function createEnvironment($basePath) + { + $this->container->share('environment', new Environment($basePath, $this->getContainer())); + } + + /** + * Registers a Service Provider in the internal stack. + * + * @param ServiceProviderInterface|string $provider + * @param bool $force + * @return ServiceProviderInterface + * + * @throws InvalidArgumentException + */ + public function registerService($provider, $force = false) + { + $registered = $this->getServiceProviderByInstanceOf($provider); + + if ($registered && $force == false) { + // Do not register twice + return $registered; + } + + if (is_string($provider)) { + $provider = $this->instantiateProvider($provider); + } + + $provider->register($this->getContainer()); + $this->serviceProviders[] = $provider; + + return $provider; + } + + /** + * Gets a Service Provider matched by provided instance (if any). + * + * @param ServiceProviderInterface|string $serviceProvider + * @return ServiceProviderInterface|null + * + * @throws InvalidArgumentException + */ + public function getServiceProviderByInstanceOf($serviceProvider) + { + $providers = $this->getServiceProvidersByInstanceOf($serviceProvider); + + return count($providers) ? $providers[0] : null; + } + + /** + * Gets Service Providers matched by provided instance. + * + * @param ServiceProviderInterface|string $serviceProvider + * @return ServiceProviderInterface[] + * + * @throws InvalidArgumentException + */ + public function getServiceProvidersByInstanceOf($serviceProvider) + { + $this->assertIsStringOrInstanceOfObject($serviceProvider); + + $className = is_string($serviceProvider) ? $serviceProvider : get_class($serviceProvider); + + return array_filter($this->serviceProviders, function ($name) use ($className) { + return $name instanceof $className; + }); + } + + /** + * Instantiate a service provider. + * + * @param string $serviceProvider + * @return object|ServiceProviderInterface + */ + public function instantiateProvider($serviceProvider) + { + return new $serviceProvider(); + } + + /** + * Validates $serviceProvider parameter. + * + * @param string|object $serviceProvider + * @return void + * + * @throws InvalidArgumentException + */ + protected function assertIsStringOrInstanceOfObject($serviceProvider) + { + if (is_string($serviceProvider) == false && is_object($serviceProvider) == false) { + throw new InvalidArgumentException( + sprintf( + 'The $serviceProvider parameter must be either a string or an object instance, got %s', + gettype($serviceProvider) + ) + ); + } + } +} diff --git a/Library/Statements/BreakStatement.php b/Library/Statements/BreakStatement.php index 5c3ab7f2f4..64171c6d87 100644 --- a/Library/Statements/BreakStatement.php +++ b/Library/Statements/BreakStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -32,7 +30,7 @@ public function compile(CompilationContext $compilationContext) if ($compilationContext->insideCycle || $compilationContext->insideSwitch) { $compilationContext->codePrinter->output('break;'); } else { - throw new CompilerException("Cannot use 'break' outside of a loop", $this->_statement); + throw new CompilerException("Cannot use 'break' outside of a loop", $this->statement); } } } diff --git a/Library/Statements/ContinueStatement.php b/Library/Statements/ContinueStatement.php index 923ade8409..cd662ce8a6 100644 --- a/Library/Statements/ContinueStatement.php +++ b/Library/Statements/ContinueStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -32,7 +30,7 @@ public function compile(CompilationContext $compilationContext) if ($compilationContext->insideCycle) { $compilationContext->codePrinter->output('continue;'); } else { - throw new CompilerException("Cannot use 'continue' outside of a loop", $this->_statement); + throw new CompilerException("Cannot use 'continue' outside of a loop", $this->statement); } } } diff --git a/Library/Statements/DeclareStatement.php b/Library/Statements/DeclareStatement.php index 68929de0ff..0a072e7f77 100644 --- a/Library/Statements/DeclareStatement.php +++ b/Library/Statements/DeclareStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -30,10 +28,10 @@ class DeclareStatement extends StatementAbstract */ public function compile(CompilationContext $compilationContext) { - $statement = $this->_statement; + $statement = $this->statement; if (!isset($statement['data-type'])) { - throw new CompilerException("Data type is required", $this->_statement); + throw new CompilerException("Data type is required", $this->statement); } $typeInference = $compilationContext->typeInference; diff --git a/Library/Statements/DoWhileStatement.php b/Library/Statements/DoWhileStatement.php index aa9dd937f3..1cb41fd7ac 100644 --- a/Library/Statements/DoWhileStatement.php +++ b/Library/Statements/DoWhileStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -29,7 +27,7 @@ class DoWhileStatement extends StatementAbstract */ public function compile(CompilationContext $compilationContext) { - $exprRaw = $this->_statement['expr']; + $exprRaw = $this->statement['expr']; $codePrinter = $compilationContext->codePrinter; $codePrinter->output('do {'); @@ -42,8 +40,8 @@ public function compile(CompilationContext $compilationContext) /** * Compile statements in the 'while' block */ - if (isset($this->_statement['statements'])) { - $st = new StatementsBlock($this->_statement['statements']); + if (isset($this->statement['statements'])) { + $st = new StatementsBlock($this->statement['statements']); $st->compile($compilationContext); } diff --git a/Library/Statements/EchoStatement.php b/Library/Statements/EchoStatement.php index e9600b1b03..9912235ac7 100644 --- a/Library/Statements/EchoStatement.php +++ b/Library/Statements/EchoStatement.php @@ -1,22 +1,20 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; use Zephir\CompilationContext; use Zephir\Compiler\CompilerException; use Zephir\Expression; -use Zephir\Utils; +use function Zephir\add_slashes; /** * EchoStatement @@ -31,7 +29,7 @@ class EchoStatement extends StatementAbstract */ public function compile(CompilationContext $compilationContext) { - foreach ($this->_statement['expressions'] as $echoExpr) { + foreach ($this->statement['expressions'] as $echoExpr) { $expr = new Expression($echoExpr); $expr->setReadOnly(true); $resolvedExpr = $expr->compile($compilationContext); @@ -59,7 +57,9 @@ public function compile(CompilationContext $compilationContext) break; case 'string': - $compilationContext->codePrinter->output('php_printf("%s", "' . Utils::addSlashes($resolvedExpr->getCode()) . '");'); + $compilationContext->codePrinter->output( + 'php_printf("%s", "' . add_slashes($resolvedExpr->getCode()) . '");' + ); break; case 'null': diff --git a/Library/Statements/ForStatement.php b/Library/Statements/ForStatement.php index a18c2a3dbd..6399a42e59 100644 --- a/Library/Statements/ForStatement.php +++ b/Library/Statements/ForStatement.php @@ -1,28 +1,26 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; use Zephir\CompilationContext; use Zephir\Compiler\CompilerException; +use Zephir\Detectors\ForValueUseDetector; +use Zephir\Expression; +use Zephir\Expression\Builder\BuilderFactory; use Zephir\FunctionCall; use Zephir\Optimizers\EvalExpression; use Zephir\StatementsBlock; -use Zephir\Expression; -use Zephir\Expression\Builder\BuilderFactory; -use Zephir\Detectors\ForValueUseDetector; use Zephir\Variable; -use Zephir\Utils; +use function Zephir\add_slashes; /** * ForStatement @@ -52,7 +50,7 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) $parameters = $functionCall->getResolvedParamsAsExpr($exprRaw['parameters'], $compilationContext, $exprRaw); if (count($parameters) != 2 && count($parameters) != 3) { - throw new CompilerException("Wrong number of parameters", $this->_statement['expr']); + throw new CompilerException("Wrong number of parameters", $this->statement['expr']); } if ($parameters[0]->getType() != 'variable') { @@ -73,23 +71,23 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) /** * Initialize 'key' variable */ - if (isset($this->_statement['key'])) { + if (isset($this->statement['key'])) { /** * This variable is used to check if the loop is in its first iteration */ - $keyVariable = $compilationContext->symbolTable->getTempVariableForWrite('long', $compilationContext, $this->_statement); + $keyVariable = $compilationContext->symbolTable->getTempVariableForWrite('long', $compilationContext, $this->statement); $keyVariable->increaseUses(); } /** * This variable is used to check if the loop is in its first iteration */ - $flagVariable = $compilationContext->symbolTable->getTempVariableForWrite('bool', $compilationContext, $this->_statement); + $flagVariable = $compilationContext->symbolTable->getTempVariableForWrite('bool', $compilationContext, $this->statement); if ($parameters[0]->getType() != 'variable') { $tempVariable = $compilationContext->symbolTable->addTemp($parameters[0]->getType(), $compilationContext); } else { - $rangeVariable = $compilationContext->symbolTable->getVariableForRead($parameters[0]->getCode(), $compilationContext, $this->_statement['expr']); + $rangeVariable = $compilationContext->symbolTable->getVariableForRead($parameters[0]->getCode(), $compilationContext, $this->statement['expr']); $tempVariable = $compilationContext->symbolTable->addTemp($rangeVariable->getType(), $compilationContext); } @@ -100,7 +98,7 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) if ($parameters[1]->getType() != 'variable') { $upperBoundVariable = $compilationContext->symbolTable->getTempVariable($parameters[1]->getType(), $compilationContext); } else { - $rangeVariable = $compilationContext->symbolTable->getVariableForRead($parameters[1]->getCode(), $compilationContext, $this->_statement['expr']); + $rangeVariable = $compilationContext->symbolTable->getVariableForRead($parameters[1]->getCode(), $compilationContext, $this->statement['expr']); $upperBoundVariable = $compilationContext->symbolTable->getTempVariable($rangeVariable->getType(), $compilationContext); } @@ -110,29 +108,29 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) $builderLet = $exprBuilder->statements()->let(); $builderLet->setAssignments(array($exprBuilder->operators() ->assignVariable($upperBoundVariable->getName(), $exprBuilder->literal($parameters[1]->getType(), $parameters[1]->getCode()) - ->setFile($this->_statement['file']) - ->setLine($this->_statement['line']) - ->setChar($this->_statement['char'])) - ->setFile($this->_statement['file']) - ->setLine($this->_statement['line']) - ->setChar($this->_statement['char']) + ->setFile($this->statement['file']) + ->setLine($this->statement['line']) + ->setChar($this->statement['char'])) + ->setFile($this->statement['file']) + ->setLine($this->statement['line']) + ->setChar($this->statement['char']) )); $statement = new LetStatement($builderLet->build()); $statement->compile($compilationContext); - if ($this->_statement['reverse']) { + if ($this->statement['reverse']) { /** * Create an implicit 'let' operation for the initialize expression */ $builderLet->setAssignments(array($exprBuilder->operators() ->assignVariable($tempVariable->getName(), $exprBuilder->variable($upperBoundVariable->getName()) - ->setFile($this->_statement['file']) - ->setLine($this->_statement['line']) - ->setChar($this->_statement['char'])) - ->setFile($this->_statement['file']) - ->setLine($this->_statement['line']) - ->setChar($this->_statement['char']) + ->setFile($this->statement['file']) + ->setLine($this->statement['line']) + ->setChar($this->statement['char'])) + ->setFile($this->statement['file']) + ->setLine($this->statement['line']) + ->setChar($this->statement['char']) )); $statement = new LetStatement($builderLet->build()); } else { @@ -141,12 +139,12 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) */ $builderLet->setAssignments(array($exprBuilder->operators() ->assignVariable($tempVariable->getName(), $exprBuilder->literal($parameters[0]->getType(), $parameters[0]->getCode()) - ->setFile($this->_statement['file']) - ->setLine($this->_statement['line']) - ->setChar($this->_statement['char'])) - ->setFile($this->_statement['file']) - ->setLine($this->_statement['line']) - ->setChar($this->_statement['char']) + ->setFile($this->statement['file']) + ->setLine($this->statement['line']) + ->setChar($this->statement['char'])) + ->setFile($this->statement['file']) + ->setLine($this->statement['line']) + ->setChar($this->statement['char']) )); $statement = new LetStatement($builderLet->build()); } @@ -156,12 +154,12 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) /** * Initialize 'key' variable */ - if (isset($this->_statement['key'])) { + if (isset($this->statement['key'])) { $codePrinter->output($keyVariable->getName() . ' = 0;'); } $codePrinter->output($flagVariable->getName() . ' = 0;'); - if ($this->_statement['reverse']) { + if ($this->statement['reverse']) { $conditionExpr = array( 'type' => 'greater-equal', 'left' => array('type' => 'variable', 'value' => $tempVariable->getName()), @@ -193,11 +191,11 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) $codePrinter->increaseLevel(); - if (isset($this->_statement['key'])) { + if (isset($this->statement['key'])) { $codePrinter->output($keyVariable->getName() . '++;'); } - if ($this->_statement['reverse']) { + if ($this->statement['reverse']) { if (!isset($parameters[2])) { $statement = new LetStatement(array( 'type' => 'let', @@ -205,9 +203,9 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) array( 'assign-type' => 'decr', 'variable' => $tempVariable->getName(), - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ) ) )); @@ -222,13 +220,13 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) 'expr' => array( 'type' => $parameters[2]->getType(), 'value' => $parameters[2]->getCode(), - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ), - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ) ) )); @@ -241,9 +239,9 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) array( 'assign-type' => 'incr', 'variable' => $tempVariable->getName(), - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ) ) )); @@ -258,13 +256,13 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) 'expr' => array( 'type' => $parameters[2]->getType(), 'value' => $parameters[2]->getCode(), - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ), - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ) ) )); @@ -289,12 +287,12 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) /** * Initialize 'key' variable */ - if (isset($this->_statement['key'])) { + if (isset($this->statement['key'])) { /** * Check for anonymous variables */ - if ($this->_statement['key'] != '_') { - $keyVariableName = $this->_statement['key']; + if ($this->statement['key'] != '_') { + $keyVariableName = $this->statement['key']; } else { $keyVariableName = $keyVariable->getName(); } @@ -312,13 +310,13 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) 'expr' => array( 'type' => 'variable', 'value' => $keyVariable->getName(), - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ), - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ) ) )); @@ -329,12 +327,12 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) /** * Initialize 'value' variable */ - if (isset($this->_statement['value'])) { + if (isset($this->statement['value'])) { /** * Check for anonymous variables */ - if ($this->_statement['value'] != '_') { - $valueVariable = $this->_statement['value']; + if ($this->statement['value'] != '_') { + $valueVariable = $this->statement['value']; } else { $valueVariable = $tempVariable->getName(); } @@ -352,13 +350,13 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) 'expr' => array( 'type' => 'variable', 'value' => $tempVariable->getName(), - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ), - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ) ) )); @@ -371,13 +369,13 @@ public function compileRange($exprRaw, CompilationContext $compilationContext) /** * Compile statements in the 'for' block */ - if (isset($this->_statement['statements'])) { - $st = new StatementsBlock($this->_statement['statements']); + if (isset($this->statement['statements'])) { + $st = new StatementsBlock($this->statement['statements']); $st->isLoop(true); - if (isset($this->_statement['key'])) { - $st->getMutateGatherer()->increaseMutations($this->_statement['key']); + if (isset($this->statement['key'])) { + $st->getMutateGatherer()->increaseMutations($this->statement['key']); } - $st->getMutateGatherer()->increaseMutations($this->_statement['value']); + $st->getMutateGatherer()->increaseMutations($this->statement['value']); $st->compile($compilationContext); } @@ -419,7 +417,7 @@ public function compileIterator(array $exprRaw, CompilationContext $compilationC throw new CompilerException("Unknown type: " . $expression->getType(), $exprRaw); } - $exprVariable = $compilationContext->symbolTable->getVariableForRead($expression->getCode(), $compilationContext, $this->_statement['expr']); + $exprVariable = $compilationContext->symbolTable->getVariableForRead($expression->getCode(), $compilationContext, $this->statement['expr']); switch ($exprVariable->getType()) { case 'variable': break; @@ -428,11 +426,11 @@ public function compileIterator(array $exprRaw, CompilationContext $compilationC /** * Initialize 'key' variable */ - if (isset($this->_statement['key'])) { - if ($this->_statement['key'] != '_') { - $keyVariable = $compilationContext->symbolTable->getVariableForWrite($this->_statement['key'], $compilationContext, $this->_statement['expr']); + if (isset($this->statement['key'])) { + if ($this->statement['key'] != '_') { + $keyVariable = $compilationContext->symbolTable->getVariableForWrite($this->statement['key'], $compilationContext, $this->statement['expr']); if ($keyVariable->getType() != 'variable') { - throw new CompilerException("Cannot use variable: " . $this->_statement['key'] . " type: " . $keyVariable->getType() . " as key in hash traversal", $this->_statement['expr']); + throw new CompilerException("Cannot use variable: " . $this->statement['key'] . " type: " . $keyVariable->getType() . " as key in hash traversal", $this->statement['expr']); } } else { /** @@ -443,18 +441,18 @@ public function compileIterator(array $exprRaw, CompilationContext $compilationC } $keyVariable->setMustInitNull(true); - $keyVariable->setIsInitialized(true, $compilationContext, $this->_statement); + $keyVariable->setIsInitialized(true, $compilationContext); $keyVariable->setDynamicTypes('undefined'); } /** * Initialize 'value' variable */ - if (isset($this->_statement['value'])) { - if ($this->_statement['value'] != '_') { - $variable = $compilationContext->symbolTable->getVariableForWrite($this->_statement['value'], $compilationContext, $this->_statement['expr']); + if (isset($this->statement['value'])) { + if ($this->statement['value'] != '_') { + $variable = $compilationContext->symbolTable->getVariableForWrite($this->statement['value'], $compilationContext, $this->statement['expr']); if ($variable->getType() != 'variable') { - throw new CompilerException("Cannot use variable: " . $this->_statement['value'] . " type: " . $variable->getType() . " as value in hash traversal", $this->_statement['expr']); + throw new CompilerException("Cannot use variable: " . $this->statement['value'] . " type: " . $variable->getType() . " as value in hash traversal", $this->statement['expr']); } } else { /** @@ -465,7 +463,7 @@ public function compileIterator(array $exprRaw, CompilationContext $compilationC } $variable->setMustInitNull(true); - $variable->setIsInitialized(true, $compilationContext, $this->_statement); + $variable->setIsInitialized(true, $compilationContext); $variable->setDynamicTypes('undefined'); } @@ -479,12 +477,12 @@ public function compileIterator(array $exprRaw, CompilationContext $compilationC $codePrinter->output($iteratorVariable ->getName() . '->funcs->rewind(' . $iteratorVariable->getName() . ' TSRMLS_CC);'); $codePrinter->output('for (;' . $iteratorVariable->getName() . '->funcs->valid(' . $iteratorVariable->getName() . ' TSRMLS_CC) == SUCCESS && !EG(exception); ' . $iteratorVariable ->getName() . '->funcs->move_forward(' . $iteratorVariable ->getName() . ' TSRMLS_CC)) {'); - if (isset($this->_statement['key'])) { + if (isset($this->statement['key'])) { $compilationContext->symbolTable->mustGrownStack(true); - $codePrinter->output("\t" . 'ZEPHIR_GET_IMKEY(' . $this->_statement['key'] . ', ' . $iteratorVariable->getName() . ');'); + $codePrinter->output("\t" . 'ZEPHIR_GET_IMKEY(' . $this->statement['key'] . ', ' . $iteratorVariable->getName() . ');'); } - if (isset($this->_statement['value'])) { + if (isset($this->statement['value'])) { $compilationContext->symbolTable->mustGrownStack(true); $codePrinter->increaseLevel(); $codePrinter->output('{'); @@ -498,13 +496,13 @@ public function compileIterator(array $exprRaw, CompilationContext $compilationC /** * Compile statements in the 'for' block */ - if (isset($this->_statement['statements'])) { - $st = new StatementsBlock($this->_statement['statements']); + if (isset($this->statement['statements'])) { + $st = new StatementsBlock($this->statement['statements']); $st->isLoop(true); - if (isset($this->_statement['key'])) { - $st->getMutateGatherer()->increaseMutations($this->_statement['key']); + if (isset($this->statement['key'])) { + $st->getMutateGatherer()->increaseMutations($this->statement['key']); } - $st->getMutateGatherer()->increaseMutations($this->_statement['value']); + $st->getMutateGatherer()->increaseMutations($this->statement['value']); $st->compile($compilationContext); } @@ -535,9 +533,9 @@ public function compileStringTraverse($expression, CompilationContext $compilati /** * Initialize 'key' variable */ - if (isset($this->_statement['key'])) { - if ($this->_statement['key'] != '_') { - $keyVariable = $compilationContext->symbolTable->getVariableForWrite($this->_statement['key'], $compilationContext, $this->_statement['expr']); + if (isset($this->statement['key'])) { + if ($this->statement['key'] != '_') { + $keyVariable = $compilationContext->symbolTable->getVariableForWrite($this->statement['key'], $compilationContext, $this->statement['expr']); switch ($keyVariable->getType()) { case 'int': case 'uint': @@ -547,7 +545,7 @@ public function compileStringTraverse($expression, CompilationContext $compilati case 'uchar': break; default: - throw new CompilerException("Cannot use variable: " . $this->_statement['key'] . " type: " . $keyVariable->getType() . " as key in string traversal", $this->_statement['expr']); + throw new CompilerException("Cannot use variable: " . $this->statement['key'] . " type: " . $keyVariable->getType() . " as key in string traversal", $this->statement['expr']); } } else { $keyVariable = $compilationContext->symbolTable->getTempVariableForWrite('int', $compilationContext); @@ -555,15 +553,15 @@ public function compileStringTraverse($expression, CompilationContext $compilati } $keyVariable->setMustInitNull(true); - $keyVariable->setIsInitialized(true, $compilationContext, $this->_statement); + $keyVariable->setIsInitialized(true, $compilationContext); } /** * Initialize 'value' variable */ - if (isset($this->_statement['value'])) { - if ($this->_statement['value'] != '_') { - $variable = $compilationContext->symbolTable->getVariableForWrite($this->_statement['value'], $compilationContext, $this->_statement['expr']); + if (isset($this->statement['value'])) { + if ($this->statement['value'] != '_') { + $variable = $compilationContext->symbolTable->getVariableForWrite($this->statement['value'], $compilationContext, $this->statement['expr']); switch ($variable->getType()) { case 'int': case 'uint': @@ -573,7 +571,7 @@ public function compileStringTraverse($expression, CompilationContext $compilati case 'uchar': break; default: - throw new CompilerException("Cannot use variable: " . $this->_statement['value'] . " type: " . $variable->getType() . " as value in string traversal", $this->_statement['expr']); + throw new CompilerException("Cannot use variable: " . $this->statement['value'] . " type: " . $variable->getType() . " as value in string traversal", $this->statement['expr']); } } else { $variable = $compilationContext->symbolTable->getTempVariableForWrite('char', $compilationContext); @@ -581,7 +579,7 @@ public function compileStringTraverse($expression, CompilationContext $compilati } $variable->setMustInitNull(true); - $variable->setIsInitialized(true, $compilationContext, $this->_statement); + $variable->setIsInitialized(true, $compilationContext); } $tempVariable = $compilationContext->symbolTable->addTemp('long', $compilationContext); @@ -590,21 +588,29 @@ public function compileStringTraverse($expression, CompilationContext $compilati * Create a temporary value to store the constant string */ if ($expression->getType() == 'string') { - $constantVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $this->_statement); - $compilationContext->backend->assignString($constantVariable, Utils::addSlashes($expression->getCode()), $compilationContext, true, false); + $constantVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $this->statement); + + $compilationContext->backend->assignString( + $constantVariable, + add_slashes($expression->getCode()), + $compilationContext, + true, + false + ); + $stringVariable = $constantVariable; } else { $stringVariable = $exprVariable; } $stringVariableCode = $compilationContext->backend->getVariableCode($stringVariable); - if ($this->_statement['reverse']) { + if ($this->statement['reverse']) { $codePrinter->output('for (' . $tempVariable->getName() . ' = Z_STRLEN_P(' . $stringVariableCode . '); ' . $tempVariable->getName() . ' >= 0; ' . $tempVariable->getName() . '--) {'); } else { $codePrinter->output('for (' . $tempVariable->getName() . ' = 0; ' . $tempVariable->getName() . ' < Z_STRLEN_P(' . $stringVariableCode . '); ' . $tempVariable->getName() . '++) {'); } - if (isset($this->_statement['key'])) { + if (isset($this->statement['key'])) { $codePrinter->output("\t" . $keyVariable->getName() . ' = ' . $tempVariable->getName() . '; '); } @@ -619,13 +625,13 @@ public function compileStringTraverse($expression, CompilationContext $compilati /** * Compile statements in the 'for' block */ - if (isset($this->_statement['statements'])) { - $st = new StatementsBlock($this->_statement['statements']); + if (isset($this->statement['statements'])) { + $st = new StatementsBlock($this->statement['statements']); $st->isLoop(true); - if (isset($this->_statement['key'])) { - $st->getMutateGatherer()->increaseMutations($this->_statement['key']); + if (isset($this->statement['key'])) { + $st->getMutateGatherer()->increaseMutations($this->statement['key']); } - $st->getMutateGatherer()->increaseMutations($this->_statement['value']); + $st->getMutateGatherer()->increaseMutations($this->statement['value']); $st->compile($compilationContext); } @@ -647,41 +653,39 @@ public function compileStringTraverse($expression, CompilationContext $compilati */ public function compileHashTraverse($expression, CompilationContext $compilationContext, Variable $exprVariable) { - $codePrinter = $compilationContext->codePrinter; - /** * Initialize 'key' variable */ - if (isset($this->_statement['key'])) { - if ($this->_statement['key'] != '_') { - $keyVariable = $compilationContext->symbolTable->getVariableForWrite($this->_statement['key'], $compilationContext, $this->_statement['expr']); + if (isset($this->statement['key'])) { + if ($this->statement['key'] != '_') { + $keyVariable = $compilationContext->symbolTable->getVariableForWrite($this->statement['key'], $compilationContext, $this->statement['expr']); if ($keyVariable->getType() != 'variable') { - throw new CompilerException("Cannot use variable: " . $this->_statement['key'] . " type: " . $keyVariable->getType() . " as key in hash traversal", $this->_statement['expr']); + throw new CompilerException("Cannot use variable: " . $this->statement['key'] . " type: " . $keyVariable->getType() . " as key in hash traversal", $this->statement['expr']); } } else { $keyVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext); } $keyVariable->setMustInitNull(true); - $keyVariable->setIsInitialized(true, $compilationContext, $this->_statement); + $keyVariable->setIsInitialized(true, $compilationContext); $keyVariable->setDynamicTypes('undefined'); } /** * Initialize 'value' variable */ - if (isset($this->_statement['value'])) { - if ($this->_statement['value'] != '_') { - $variable = $compilationContext->symbolTable->getVariableForWrite($this->_statement['value'], $compilationContext, $this->_statement['expr']); + if (isset($this->statement['value'])) { + if ($this->statement['value'] != '_') { + $variable = $compilationContext->symbolTable->getVariableForWrite($this->statement['value'], $compilationContext, $this->statement['expr']); if ($variable->getType() != 'variable') { - throw new CompilerException("Cannot use variable: " . $this->_statement['value'] . " type: " . $variable->getType() . " as value in hash traversal", $this->_statement['expr']); + throw new CompilerException("Cannot use variable: " . $this->statement['value'] . " type: " . $variable->getType() . " as value in hash traversal", $this->statement['expr']); } } else { $variable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext); } $variable->setMustInitNull(true); - $variable->setIsInitialized(true, $compilationContext, $this->_statement); + $variable->setIsInitialized(true, $compilationContext); $variable->increaseVariantIfNull(); $variable->setDynamicTypes('undefined'); } @@ -700,27 +704,24 @@ public function compileHashTraverse($expression, CompilationContext $compilation * We have to check if hashes are modified within the for's block */ $st = null; - if (isset($this->_statement['statements'])) { + if (isset($this->statement['statements'])) { /** * Create the statements block here to obtain the last use line */ - $st = new StatementsBlock($this->_statement['statements']); + $st = new StatementsBlock($this->statement['statements']); $detector = new ForValueUseDetector(); - if ($detector->detect($exprVariable->getName(), $this->_statement['statements'])) { + if ($detector->detect($exprVariable->getName(), $this->statement['statements'])) { $duplicateHash = '1'; } /** * Detect if the key is modified or passed to an external scope */ - if (isset($this->_statement['key'])) { + if (isset($this->statement['key'])) { if (!$keyVariable->isTemporal()) { $detector->setDetectionFlags(ForValueUseDetector::DETECT_ALL); - if ($detector->detect($keyVariable->getName(), $this->_statement['statements'])) { - $loopContext = $compilationContext->currentMethod->getLocalContextPass(); - //echo $st->getLastLine(); - //echo $loopContext->getLastVariableUseLine($keyVariable->getName()); + if ($detector->detect($keyVariable->getName(), $this->statement['statements'])) { $duplicateKey = true; } } @@ -729,11 +730,11 @@ public function compileHashTraverse($expression, CompilationContext $compilation $compilationContext->backend->forStatement( $exprVariable, - isset($this->_statement['key']) ? $keyVariable : null, - isset($this->_statement['value']) ? $variable : null, + isset($this->statement['key']) ? $keyVariable : null, + isset($this->statement['value']) ? $variable : null, $duplicateKey, $duplicateHash, - $this->_statement, + $this->statement, $st, $compilationContext ); @@ -750,7 +751,7 @@ public function compileHashTraverse($expression, CompilationContext $compilation */ public function compile(CompilationContext $compilationContext) { - $exprRaw = $this->_statement['expr']; + $exprRaw = $this->statement['expr']; /** * @TODO implement optimizers here @@ -787,7 +788,7 @@ public function compile(CompilationContext $compilationContext) throw new CompilerException("Unknown type: " . $expression->getType(), $exprRaw); } - $exprVariable = $compilationContext->symbolTable->getVariableForRead($expression->getCode(), $compilationContext, $this->_statement['expr']); + $exprVariable = $compilationContext->symbolTable->getVariableForRead($expression->getCode(), $compilationContext, $this->statement['expr']); switch ($exprVariable->getType()) { case 'variable': case 'array': diff --git a/Library/Statements/IfStatement.php b/Library/Statements/IfStatement.php index cff4d90f36..84ba5760f6 100644 --- a/Library/Statements/IfStatement.php +++ b/Library/Statements/IfStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -32,7 +30,7 @@ class IfStatement extends StatementAbstract */ public function compile(CompilationContext $compilationContext) { - $exprRaw = $this->_statement['expr']; + $exprRaw = $this->statement['expr']; $expr = new EvalExpression(); $condition = $expr->optimize($exprRaw, $compilationContext); @@ -40,25 +38,25 @@ public function compile(CompilationContext $compilationContext) /** * This pass tries to move dynamic variable initialization out of the if/else branch */ - if (isset($this->_statement['statements']) && (isset($this->_statement['else_statements']) || isset($this->_statement['elseif_statements']))) { + if (isset($this->statement['statements']) && (isset($this->statement['else_statements']) || isset($this->statement['elseif_statements']))) { $readDetector = new ReadDetector(); $skipVariantInit = new SkipVariantInit(); $skipVariantInit->setVariablesToSkip(0, $expr->getUsedVariables()); - $skipVariantInit->pass(0, new StatementsBlock($this->_statement['statements'])); + $skipVariantInit->pass(0, new StatementsBlock($this->statement['statements'])); $lastBranchId = 0; - if (isset($this->_statement['else_statements'])) { + if (isset($this->statement['else_statements'])) { ++$lastBranchId; $skipVariantInit->setVariablesToSkip($lastBranchId, $expr->getUsedVariables()); - $skipVariantInit->pass($lastBranchId, new StatementsBlock($this->_statement['else_statements'])); + $skipVariantInit->pass($lastBranchId, new StatementsBlock($this->statement['else_statements'])); } - if (isset($this->_statement['elseif_statements'])) { - foreach ($this->_statement['elseif_statements'] as $key => $statement) { - $this->_statement['elseif_statements'][$key]['condition'] = $expr->optimize($statement['expr'], $compilationContext); + if (isset($this->statement['elseif_statements'])) { + foreach ($this->statement['elseif_statements'] as $key => $statement) { + $this->statement['elseif_statements'][$key]['condition'] = $expr->optimize($statement['expr'], $compilationContext); $lastBranchId++; $skipVariantInit->setVariablesToSkip($lastBranchId, $expr->getUsedVariables()); @@ -86,7 +84,7 @@ public function compile(CompilationContext $compilationContext) } $compilationContext->codePrinter->output('if (' . $condition . ') {'); - $this->_evalExpression = $expr; + $this->evalExpression = $expr; /** * Try to mark latest temporary variable used as idle @@ -101,8 +99,8 @@ public function compile(CompilationContext $compilationContext) /** * Compile statements in the 'if' block */ - if (isset($this->_statement['statements'])) { - $st = new StatementsBlock($this->_statement['statements']); + if (isset($this->statement['statements'])) { + $st = new StatementsBlock($this->statement['statements']); $branch = $st->compile($compilationContext, $expr->isUnreachable(), Branch::TYPE_CONDITIONAL_TRUE); $branch->setRelatedStatement($this); } @@ -110,8 +108,8 @@ public function compile(CompilationContext $compilationContext) /** * Compile statements in the 'elseif' block */ - if (isset($this->_statement['elseif_statements'])) { - foreach ($this->_statement['elseif_statements'] as $key => $statement) { + if (isset($this->statement['elseif_statements'])) { + foreach ($this->statement['elseif_statements'] as $key => $statement) { if (!isset($statement['statements'])) { continue; } @@ -126,9 +124,9 @@ public function compile(CompilationContext $compilationContext) /** * Compile statements in the 'else' block */ - if (isset($this->_statement['else_statements'])) { + if (isset($this->statement['else_statements'])) { $compilationContext->codePrinter->output('} else {'); - $st = new StatementsBlock($this->_statement['else_statements']); + $st = new StatementsBlock($this->statement['else_statements']); $branch = $st->compile($compilationContext, $expr->isUnreachableElse(), Branch::TYPE_CONDITIONAL_FALSE); $branch->setRelatedStatement($this); } diff --git a/Library/Statements/Let/ArrayIndex.php b/Library/Statements/Let/ArrayIndex.php index 2a0b242536..872b9af8ed 100644 --- a/Library/Statements/Let/ArrayIndex.php +++ b/Library/Statements/Let/ArrayIndex.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -38,8 +36,6 @@ class ArrayIndex */ protected function _getResolvedArrayItem(CompiledExpression $resolvedExpr, CompilationContext $compilationContext) { - $codePrinter = $compilationContext->codePrinter; - switch ($resolvedExpr->getType()) { case 'null': $symbolVariable = new GlobalConstant('ZEPHIR_GLOBAL(global_null)'); @@ -151,8 +147,6 @@ protected function _assignArrayIndexSingle($variable, ZephirVariable $symbolVari throw new CompilerException("Index: " . $exprIndex->getType() . " cannot be used as array offset in assignment without cast", $statement['index-expr'][0]); } - $codePrinter = $compilationContext->codePrinter; - /** * Create a temporal zval (if needed) */ diff --git a/Library/Statements/Let/ArrayIndexAppend.php b/Library/Statements/Let/ArrayIndexAppend.php index 6053bfb513..1092a3dedc 100644 --- a/Library/Statements/Let/ArrayIndexAppend.php +++ b/Library/Statements/Let/ArrayIndexAppend.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -37,8 +35,6 @@ class ArrayIndexAppend extends ArrayIndex */ protected function _assignArrayIndexMultiple($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement) { - $codePrinter = $compilationContext->codePrinter; - $offsetExprs = array(); foreach ($statement['index-expr'] as $indexExpr) { $expression = new Expression($indexExpr); diff --git a/Library/Statements/Let/Decr.php b/Library/Statements/Let/Decr.php index fd18ba4864..784b841234 100644 --- a/Library/Statements/Let/Decr.php +++ b/Library/Statements/Let/Decr.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; diff --git a/Library/Statements/Let/ExportSymbol.php b/Library/Statements/Let/ExportSymbol.php index 9a67dc6618..eb7102d0d9 100644 --- a/Library/Statements/Let/ExportSymbol.php +++ b/Library/Statements/Let/ExportSymbol.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; diff --git a/Library/Statements/Let/ExportSymbolString.php b/Library/Statements/Let/ExportSymbolString.php index 8036492d27..a477320559 100644 --- a/Library/Statements/Let/ExportSymbolString.php +++ b/Library/Statements/Let/ExportSymbolString.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; diff --git a/Library/Statements/Let/Incr.php b/Library/Statements/Let/Incr.php index 15b1780da1..a4b3b4c21d 100644 --- a/Library/Statements/Let/Incr.php +++ b/Library/Statements/Let/Incr.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; diff --git a/Library/Statements/Let/ObjectDynamicProperty.php b/Library/Statements/Let/ObjectDynamicProperty.php index ce0704c2c6..939ec4c6bd 100644 --- a/Library/Statements/Let/ObjectDynamicProperty.php +++ b/Library/Statements/Let/ObjectDynamicProperty.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; diff --git a/Library/Statements/Let/ObjectDynamicStringProperty.php b/Library/Statements/Let/ObjectDynamicStringProperty.php index f9372977aa..877abf644d 100644 --- a/Library/Statements/Let/ObjectDynamicStringProperty.php +++ b/Library/Statements/Let/ObjectDynamicStringProperty.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -71,7 +69,6 @@ public function assign($variable, ZephirVariable $symbolVariable, CompiledExpres $compilationContext->logger->warning('Possible attempt to update property on non-object dynamic property', 'non-valid-objectupdate', $statement); } - $codePrinter = $compilationContext->codePrinter; $compilationContext->headersManager->add('kernel/object'); switch ($resolvedExpr->getType()) { diff --git a/Library/Statements/Let/ObjectProperty.php b/Library/Statements/Let/ObjectProperty.php index 84c647ae31..c6b86a4925 100644 --- a/Library/Statements/Let/ObjectProperty.php +++ b/Library/Statements/Let/ObjectProperty.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; diff --git a/Library/Statements/Let/ObjectPropertyAppend.php b/Library/Statements/Let/ObjectPropertyAppend.php index 087a28a434..a2f237a332 100644 --- a/Library/Statements/Let/ObjectPropertyAppend.php +++ b/Library/Statements/Let/ObjectPropertyAppend.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -59,8 +57,6 @@ public function assign($variable, ZephirVariable $symbolVariable, CompiledExpres if (!$classDefinition->hasProperty($property)) { throw new CompilerException("Class '" . $classDefinition->getCompleteName() . "' does not have a property called: '" . $property . "'", $statement); } - - $propertyDefinition = $classDefinition->getProperty($property); } else { /** * If we know the class related to a variable we could check if the property diff --git a/Library/Statements/Let/ObjectPropertyArrayIndex.php b/Library/Statements/Let/ObjectPropertyArrayIndex.php index 283e6cd512..3a93704ff4 100644 --- a/Library/Statements/Let/ObjectPropertyArrayIndex.php +++ b/Library/Statements/Let/ObjectPropertyArrayIndex.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -38,8 +36,6 @@ class ObjectPropertyArrayIndex extends ArrayIndex */ protected function _assignPropertyArraySingleIndex($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, array $statement) { - $codePrinter = $compilationContext->codePrinter; - $property = $statement['property']; $compilationContext->headersManager->add('kernel/object'); @@ -116,8 +112,6 @@ protected function _assignPropertyArraySingleIndex($variable, ZephirVariable $sy if (!$classDefinition->hasProperty($property)) { throw new CompilerException("Class '" . $classDefinition->getCompleteName() . "' does not have a property called: '" . $property . "'", $statement); } - - $propertyDefinition = $classDefinition->getProperty($property); } else { /** * If we know the class related to a variable we could check if the property @@ -244,8 +238,6 @@ protected function _assignPropertyArraySingleIndex($variable, ZephirVariable $sy */ protected function _assignPropertyArrayMultipleIndex($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, array $statement) { - $codePrinter = $compilationContext->codePrinter; - $property = $statement['property']; $compilationContext->headersManager->add('kernel/object'); diff --git a/Library/Statements/Let/ObjectPropertyArrayIndexAppend.php b/Library/Statements/Let/ObjectPropertyArrayIndexAppend.php index 6a53ed31f9..024d33a0cb 100644 --- a/Library/Statements/Let/ObjectPropertyArrayIndexAppend.php +++ b/Library/Statements/Let/ObjectPropertyArrayIndexAppend.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -38,8 +36,6 @@ class ObjectPropertyArrayIndexAppend extends ArrayIndex */ protected function _assignPropertyArrayMultipleIndex($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, array $statement) { - $codePrinter = $compilationContext->codePrinter; - $property = $statement['property']; $compilationContext->headersManager->add('kernel/object'); @@ -83,8 +79,6 @@ protected function _assignPropertyArrayMultipleIndex($variable, ZephirVariable $ if (!$classDefinition->hasProperty($property)) { throw new CompilerException("Class '" . $classDefinition->getCompleteName() . "' does not have a property called: '" . $property . "'", $statement); } - - $propertyDefinition = $classDefinition->getProperty($property); } else { /** * If we know the class related to a variable we could check if the property diff --git a/Library/Statements/Let/ObjectPropertyDecr.php b/Library/Statements/Let/ObjectPropertyDecr.php index 406c8ae1ea..86f85a6a4f 100644 --- a/Library/Statements/Let/ObjectPropertyDecr.php +++ b/Library/Statements/Let/ObjectPropertyDecr.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -75,8 +73,6 @@ public function assign($variable, $property, ZephirVariable $symbolVariable, Com if (!$classDefinition->hasProperty($property)) { throw new CompilerException("Class '" . $classDefinition->getCompleteName() . "' does not have a property called: '" . $property . "'", $statement); } - - $propertyDefinition = $classDefinition->getProperty($property); } else { /** * If we know the class related to a variable we could check if the property diff --git a/Library/Statements/Let/ObjectPropertyIncr.php b/Library/Statements/Let/ObjectPropertyIncr.php index aa618f69d1..062e281374 100644 --- a/Library/Statements/Let/ObjectPropertyIncr.php +++ b/Library/Statements/Let/ObjectPropertyIncr.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -76,8 +74,6 @@ public function assign($variable, $property, ZephirVariable $symbolVariable, Com if (!$classDefinition->hasProperty($property)) { throw new CompilerException("Class '" . $classDefinition->getCompleteName() . "' does not have a property called: '" . $property . "'", $statement); } - - $propertyDefinition = $classDefinition->getProperty($property); } else { /** * If we know the class related to a variable we could check if the property diff --git a/Library/Statements/Let/StaticProperty.php b/Library/Statements/Let/StaticProperty.php index 3843b06ccc..82455a0e04 100644 --- a/Library/Statements/Let/StaticProperty.php +++ b/Library/Statements/Let/StaticProperty.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -233,6 +231,7 @@ public function assignStatic($className, $property, CompiledExpression $resolved case 'string': switch ($statement['operator']) { + /** @noinspection PhpMissingBreakStatementInspection */ case 'concat-assign': $tempVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext, true); $expression = new Expression(array( diff --git a/Library/Statements/Let/StaticPropertyAppend.php b/Library/Statements/Let/StaticPropertyAppend.php index 5c1b970b77..6bde30f230 100644 --- a/Library/Statements/Let/StaticPropertyAppend.php +++ b/Library/Statements/Let/StaticPropertyAppend.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -35,8 +33,6 @@ class StaticPropertyAppend extends ArrayIndex */ protected function _assignStaticPropertyArrayMultipleIndex($classEntry, $property, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement) { - $codePrinter = $compilationContext->codePrinter; - $property = $statement['property']; $compilationContext->headersManager->add('kernel/object'); diff --git a/Library/Statements/Let/StaticPropertyArrayIndex.php b/Library/Statements/Let/StaticPropertyArrayIndex.php index 2ee5b27836..66c805664c 100644 --- a/Library/Statements/Let/StaticPropertyArrayIndex.php +++ b/Library/Statements/Let/StaticPropertyArrayIndex.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -36,8 +34,6 @@ class StaticPropertyArrayIndex extends ArrayIndex */ protected function _assignStaticPropertyArrayMultipleIndex($classEntry, $property, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement) { - $codePrinter = $compilationContext->codePrinter; - $property = $statement['property']; $compilationContext->headersManager->add('kernel/object'); diff --git a/Library/Statements/Let/StaticPropertyArrayIndexAppend.php b/Library/Statements/Let/StaticPropertyArrayIndexAppend.php index 0b6d72f110..585ba9a300 100644 --- a/Library/Statements/Let/StaticPropertyArrayIndexAppend.php +++ b/Library/Statements/Let/StaticPropertyArrayIndexAppend.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -36,8 +34,6 @@ class StaticPropertyArrayIndexAppend extends ArrayIndex */ protected function _assignStaticPropertyArrayMultipleIndex($classEntry, $property, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement) { - $codePrinter = $compilationContext->codePrinter; - $property = $statement['property']; $compilationContext->headersManager->add('kernel/object'); diff --git a/Library/Statements/Let/Variable.php b/Library/Statements/Let/Variable.php index d9ad0c37d0..584c16879d 100644 --- a/Library/Statements/Let/Variable.php +++ b/Library/Statements/Let/Variable.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; diff --git a/Library/Statements/Let/VariableAppend.php b/Library/Statements/Let/VariableAppend.php index c8e06514a6..86a88ff810 100644 --- a/Library/Statements/Let/VariableAppend.php +++ b/Library/Statements/Let/VariableAppend.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements\Let; @@ -62,8 +60,6 @@ public function assign($variable, ZephirVariable $symbolVariable, CompiledExpres } } - $codePrinter = $compilationContext->codePrinter; - $compilationContext->headersManager->add('kernel/array'); $type = $symbolVariable->getType(); diff --git a/Library/Statements/LetStatement.php b/Library/Statements/LetStatement.php index 7466d438eb..38ae72b4d2 100644 --- a/Library/Statements/LetStatement.php +++ b/Library/Statements/LetStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -53,7 +51,7 @@ public function compile(CompilationContext $compilationContext) { $readDetector = new ReadDetector(); - $statement = $this->_statement; + $statement = $this->statement; foreach ($statement['assignments'] as $assignment) { $variable = $assignment['variable']; diff --git a/Library/Statements/LoopStatement.php b/Library/Statements/LoopStatement.php index 517c278532..5e18cb66cf 100644 --- a/Library/Statements/LoopStatement.php +++ b/Library/Statements/LoopStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -42,11 +40,11 @@ public function compile(CompilationContext $compilationContext) /** * Compile statements in the 'loop' block */ - if (!isset($this->_statement['statements'])) { - throw new CompilerException("Infinite loop without at least a 'break' statement is not allowed", $this->_statement); + if (!isset($this->statement['statements'])) { + throw new CompilerException("Infinite loop without at least a 'break' statement is not allowed", $this->statement); } - $st = new StatementsBlock($this->_statement['statements']); + $st = new StatementsBlock($this->statement['statements']); /** * Check if the block contain at least a break statement @@ -54,7 +52,7 @@ public function compile(CompilationContext $compilationContext) $loopBreakPass = new LoopBreakPass(); $loopBreakPass->pass($st); if (!$loopBreakPass->hasBreak()) { - throw new CompilerException("Infinite loop without at least a 'break' statement is not allowed", $this->_statement); + throw new CompilerException("Infinite loop without at least a 'break' statement is not allowed", $this->statement); } $st->isLoop(true); diff --git a/Library/Statements/RequireStatement.php b/Library/Statements/RequireStatement.php index e1d30ecc25..0eee2b9e91 100644 --- a/Library/Statements/RequireStatement.php +++ b/Library/Statements/RequireStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -32,10 +30,10 @@ public function compile(CompilationContext $compilationContext) { $expression = array( 'type' => 'require', - 'left' => $this->_statement['expr'], - 'file' => $this->_statement['file'], - 'line' => $this->_statement['line'], - 'char' => $this->_statement['char'] + 'left' => $this->statement['expr'], + 'file' => $this->statement['file'], + 'line' => $this->statement['line'], + 'char' => $this->statement['char'] ); $expr = new Expression($expression); diff --git a/Library/Statements/ReturnStatement.php b/Library/Statements/ReturnStatement.php index a2fb4eb088..4b24155057 100644 --- a/Library/Statements/ReturnStatement.php +++ b/Library/Statements/ReturnStatement.php @@ -1,22 +1,20 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; use Zephir\CompilationContext; use Zephir\Compiler\CompilerException; use Zephir\Expression; -use Zephir\Utils; +use function Zephir\add_slashes; /** * ReturnStatement @@ -31,7 +29,7 @@ class ReturnStatement extends StatementAbstract */ public function compile(CompilationContext $compilationContext) { - $statement = $this->_statement; + $statement = $this->statement; $codePrinter = $compilationContext->codePrinter; @@ -180,7 +178,10 @@ public function compile(CompilationContext $compilationContext) case 'string': case 'istring': - $compilationContext->backend->returnString(Utils::addSlashes($resolvedExpr->getCode()), $compilationContext); + $compilationContext->backend->returnString( + add_slashes($resolvedExpr->getCode()), + $compilationContext + ); break; case 'array': diff --git a/Library/Statements/StatementAbstract.php b/Library/Statements/StatementAbstract.php index ea4943d282..c16b25cf8a 100644 --- a/Library/Statements/StatementAbstract.php +++ b/Library/Statements/StatementAbstract.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -17,18 +15,20 @@ use Zephir\Optimizers\EvalExpression; /** - * Class StatementAbstract + * Zephir\Statements\StatementAbstract + * + * @package Zephir\Statements */ abstract class StatementAbstract { - protected $_statement; + protected $statement; - protected $_uniqueId; + protected $uniqueId; /** @var EvalExpression|null */ - protected $_evalExpression; + protected $evalExpression; - protected static $_uniqueGenerator; + protected static $uniqueGenerator; /** * StatementAbstract construct @@ -37,7 +37,7 @@ abstract class StatementAbstract */ public function __construct(array $statement) { - $this->_statement = $statement; + $this->statement = $statement; } /** @@ -47,10 +47,10 @@ public function __construct(array $statement) */ public function getUniqueId() { - if (!$this->_uniqueId) { - $this->_uniqueId = self::$_uniqueGenerator++; + if (!$this->uniqueId) { + $this->uniqueId = self::$uniqueGenerator++; } - return $this->_uniqueId; + return $this->uniqueId; } /** @@ -58,7 +58,7 @@ public function getUniqueId() */ public function getEvalExpression() { - return $this->_evalExpression; + return $this->evalExpression; } /** diff --git a/Library/Statements/SwitchStatement.php b/Library/Statements/SwitchStatement.php index 4659c06f1d..709e90a1d4 100644 --- a/Library/Statements/SwitchStatement.php +++ b/Library/Statements/SwitchStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -31,7 +29,7 @@ class SwitchStatement extends StatementAbstract */ public function compile(CompilationContext $compilationContext) { - $exprRaw = $this->_statement['expr']; + $exprRaw = $this->statement['expr']; $codePrinter = $compilationContext->codePrinter; @@ -41,7 +39,7 @@ public function compile(CompilationContext $compilationContext) $exprEval->setReadOnly(true); $resolvedExpr = $exprEval->compile($compilationContext); - if (isset($this->_statement['clauses'])) { + if (isset($this->statement['clauses'])) { $evalExpr = new EvalExpression(); $codePrinter->output('do {'); @@ -81,7 +79,7 @@ public function compile(CompilationContext $compilationContext) $tempVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $exprRaw); } - $clauses = $this->normalizeClauses($this->_statement['clauses']); + $clauses = $this->normalizeClauses($this->statement['clauses']); $tempLeft = array('type' => 'variable', 'value' => $tempVariable->getRealName()); /** diff --git a/Library/Statements/ThrowStatement.php b/Library/Statements/ThrowStatement.php index 574235635c..3027e4136c 100644 --- a/Library/Statements/ThrowStatement.php +++ b/Library/Statements/ThrowStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -18,7 +16,8 @@ use Zephir\Compiler; use Zephir\Compiler\CompilerException; use Zephir\Expression; -use Zephir\Utils; +use function Zephir\add_slashes; +use function Zephir\fqcn; /** * ThrowStatement @@ -36,7 +35,7 @@ public function compile(CompilationContext $compilationContext) $compilationContext->headersManager->add('kernel/exception'); $codePrinter = $compilationContext->codePrinter; - $statement = $this->_statement; + $statement = $this->statement; $expr = $statement['expr']; /** @@ -48,7 +47,12 @@ public function compile(CompilationContext $compilationContext) count($expr['parameters']) == 1 && $expr['parameters'][0]['parameter']['type'] == 'string' ) { - $className = Utils::getFullName($expr['class'], $compilationContext->classDefinition->getNamespace(), $compilationContext->aliasManager); + $className = fqcn( + $expr['class'], + $compilationContext->classDefinition->getNamespace(), + $compilationContext->aliasManager + ); + if ($compilationContext->compiler->isClass($className)) { $classDefinition = $compilationContext->compiler->getClassDefinition($className); $message = $expr['parameters'][0]['parameter']['value']; @@ -57,7 +61,11 @@ public function compile(CompilationContext $compilationContext) return; } else { if ($compilationContext->compiler->isBundledClass($className)) { - $classEntry = $compilationContext->classDefinition->getClassEntryByClassName($className, $compilationContext, true); + $classEntry = $compilationContext->classDefinition->getClassEntryByClassName( + $className, + $compilationContext, + true + ); if ($classEntry) { $message = $expr['parameters'][0]['parameter']['value']; $this->throwStringException($codePrinter, $classEntry, $message, $statement['expr']); @@ -111,10 +119,16 @@ public function compile(CompilationContext $compilationContext) */ private function throwStringException(CodePrinter $printer, $class, $message, $expression) { - $message = Utils::addSlashes($message); + $message = add_slashes($message); $path = Compiler::getShortUserPath($expression['file']); $printer->output( - sprintf('ZEPHIR_THROW_EXCEPTION_DEBUG_STR(%s, "%s", "%s", %s);', $class, $message, $path, $expression['line']) + sprintf( + 'ZEPHIR_THROW_EXCEPTION_DEBUG_STR(%s, "%s", "%s", %s);', + $class, + $message, + $path, + $expression['line'] + ) ); $printer->output('return;'); } diff --git a/Library/Statements/TryCatchStatement.php b/Library/Statements/TryCatchStatement.php index f33777bdd0..8b3172da8b 100644 --- a/Library/Statements/TryCatchStatement.php +++ b/Library/Statements/TryCatchStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -40,8 +38,8 @@ public function compile(CompilationContext $compilationContext) $codePrinter->output('/* try_start_' . $currentTryCatch . ': */'); $codePrinter->outputBlankLine(); - if (isset($this->_statement['statements'])) { - $st = new StatementsBlock($this->_statement['statements']); + if (isset($this->statement['statements'])) { + $st = new StatementsBlock($this->statement['statements']); $st->compile($compilationContext); } @@ -55,7 +53,7 @@ public function compile(CompilationContext $compilationContext) $compilationContext->insideTryCatch--; - if (isset($this->_statement['catches'])) { + if (isset($this->statement['catches'])) { /** * Check if there was an exception */ @@ -68,7 +66,7 @@ public function compile(CompilationContext $compilationContext) $exprBuilder = BuilderFactory::getInstance(); $ifs = array(); - foreach ($this->_statement['catches'] as $catch) { + foreach ($this->statement['catches'] as $catch) { if (isset($catch['variable'])) { $variable = $compilationContext->symbolTable->getVariableForWrite($catch['variable']['value'], $compilationContext, $catch['variable']); if ($variable->getType() != 'variable') { @@ -87,7 +85,7 @@ public function compile(CompilationContext $compilationContext) /** * @TODO, use a builder here */ - $variable->setIsInitialized(true, $compilationContext, $catch); + $variable->setIsInitialized(true, $compilationContext); $variable->setMustInitNull(true); /** @@ -98,8 +96,6 @@ public function compile(CompilationContext $compilationContext) $exprBuilder->operators()->assignVariable($variable->getName(), $exprBuilder->variable($variable->getName())) )); - $assignExceptVarStmt = new \Zephir\Expression\Builder\Statements\LetStatement($assignExceptVar->build()); - $ifs[] = $exprBuilder->statements()->ifX() ->setCondition( $exprBuilder->operators()->binary( diff --git a/Library/Statements/UnsetStatement.php b/Library/Statements/UnsetStatement.php index 46501d75a5..ad67f84264 100644 --- a/Library/Statements/UnsetStatement.php +++ b/Library/Statements/UnsetStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -29,7 +27,7 @@ class UnsetStatement extends StatementAbstract public function compile(CompilationContext $compilationContext) { $compilationContext->headersManager->add('kernel/array'); - $expression = $this->_statement['expr']; + $expression = $this->statement['expr']; $flags = 'PH_SEPARATE'; @@ -42,7 +40,7 @@ public function compile(CompilationContext $compilationContext) $expr = new Expression($expression['left']); $expr->setReadOnly(true); $exprVar = $expr->compile($compilationContext); - $variable = $compilationContext->symbolTable->getVariableForWrite($exprVar->getCode(), $compilationContext, $this->_statement); + $variable = $compilationContext->symbolTable->getVariableForWrite($exprVar->getCode(), $compilationContext, $this->statement); $expr = new Expression($expression['right']); $expr->setReadOnly(true); @@ -53,7 +51,7 @@ public function compile(CompilationContext $compilationContext) $expr = new Expression($expression['left']); $expr->setReadOnly(true); $exprVar = $expr->compile($compilationContext); - $variable = $compilationContext->symbolTable->getVariableForWrite($exprVar->getCode(), $compilationContext, $this->_statement); + $variable = $compilationContext->symbolTable->getVariableForWrite($exprVar->getCode(), $compilationContext, $this->statement); $variableCode = $compilationContext->backend->getVariableCode($variable); $compilationContext->headersManager->add('kernel/object'); diff --git a/Library/Statements/WhileStatement.php b/Library/Statements/WhileStatement.php index c86a232f19..0ce210b54f 100644 --- a/Library/Statements/WhileStatement.php +++ b/Library/Statements/WhileStatement.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Statements; @@ -29,7 +27,7 @@ class WhileStatement extends StatementAbstract */ public function compile(CompilationContext $compilationContext) { - $exprRaw = $this->_statement['expr']; + $exprRaw = $this->statement['expr']; $codePrinter = $compilationContext->codePrinter; /** @@ -46,7 +44,7 @@ public function compile(CompilationContext $compilationContext) $expr = new EvalExpression(); $condition = $expr->optimize($exprRaw, $compilationContext); - $this->_evalExpression = $expr; + $this->evalExpression = $expr; $codePrinter->output('if (!(' . $condition . ')) {'); $codePrinter->output("\t" . 'break;'); @@ -57,8 +55,8 @@ public function compile(CompilationContext $compilationContext) /** * Compile statements in the 'while' block */ - if (isset($this->_statement['statements'])) { - $st = new StatementsBlock($this->_statement['statements']); + if (isset($this->statement['statements'])) { + $st = new StatementsBlock($this->statement['statements']); $st->isLoop(true); $st->compile($compilationContext); } diff --git a/Library/StatementsBlock.php b/Library/StatementsBlock.php index 12ad36e5f8..29eac88bef 100644 --- a/Library/StatementsBlock.php +++ b/Library/StatementsBlock.php @@ -1,15 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir; diff --git a/Library/StaticCall.php b/Library/StaticCall.php index 694f0d6716..95104e67c8 100644 --- a/Library/StaticCall.php +++ b/Library/StaticCall.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; @@ -580,7 +578,7 @@ public function compile(Expression $expr, CompilationContext $compilationContext } else { $method = $classDefinition->getMethod($methodName); - if ($method->isPrivate() && $method->getClassDefinition() != $compilationContext->classDefinition) { + if ($method->isPrivate() && $method->getClassDefinition() !== $compilationContext->classDefinition) { throw new CompilerException("Cannot call private method '" . $methodName . "' out of its scope", $expression); } @@ -618,7 +616,7 @@ public function compile(Expression $expr, CompilationContext $compilationContext } else { if (!isset($method)) { $method = $classDefinition->getMethod("__callStatic"); - if ($method->isPrivate() && $method->getClassDefinition() != $compilationContext->classDefinition) { + if ($method->isPrivate() && $method->getClassDefinition() !== $compilationContext->classDefinition) { throw new CompilerException("Cannot call private magic method '__call' out of its scope", $expression); } } diff --git a/Library/StringsManager.php b/Library/StringsManager.php index 440668f31b..9e65181251 100644 --- a/Library/StringsManager.php +++ b/Library/StringsManager.php @@ -1,15 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir; diff --git a/Library/Stubs/DocBlock.php b/Library/Stubs/DocBlock.php index 9462008631..8b51532380 100644 --- a/Library/Stubs/DocBlock.php +++ b/Library/Stubs/DocBlock.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Stubs; diff --git a/Library/Stubs/Generator.php b/Library/Stubs/Generator.php index 53398c7d33..810785df57 100644 --- a/Library/Stubs/Generator.php +++ b/Library/Stubs/Generator.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Stubs; @@ -288,6 +286,10 @@ protected function buildMethod(ClassMethod $method, $isInterface, $indent) $return = 'string'; $supported++; } + if (array_key_exists('array', $method->getReturnTypes())) { + $return = 'array'; + $supported++; + } if ($method->areReturnTypesNullCompatible()) { if (version_compare(PHP_VERSION, '7.1.0', '>=')) { diff --git a/Library/Stubs/MethodDocBlock.php b/Library/Stubs/MethodDocBlock.php index 12514dd755..d5925edfe0 100644 --- a/Library/Stubs/MethodDocBlock.php +++ b/Library/Stubs/MethodDocBlock.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Stubs; diff --git a/Library/Support/PropertyAccessor.php b/Library/Support/PropertyAccessor.php new file mode 100644 index 0000000000..dad6848ac6 --- /dev/null +++ b/Library/Support/PropertyAccessor.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir\Support; + +use Zephir\Exception\InvalidCallException; +use Zephir\Exception\UnknownPropertyException; + +/** + * Zephir\Support\PropertyAccessor + * + * @package Zephir\Support + */ +trait PropertyAccessor +{ + /** + * Gets the internal Object's property. + * + * Do not call this method directly as it is a PHP magic method that + * will be implicitly called when executing `$value = $object->property;`. + * + * @param string $name + * @return mixed + * + * @throws InvalidCallException + * @throws UnknownPropertyException + */ + public function __get($name) + { + $getter = 'get' . ucfirst($name); + $setter = 'set' . ucfirst($name); + + if (method_exists($this, $getter)) { + return $this->$getter(); + } elseif (method_exists($this, $setter)) { + throw new InvalidCallException( + sprintf('Getting write-only property: %s::%s', get_class($this), $name) + ); + } + + throw new UnknownPropertyException( + sprintf('Getting unknown property: %s::%s', get_class($this), $name) + ); + } +} diff --git a/Library/SymbolTable.php b/Library/SymbolTable.php index 88d12b7d85..eb19b00d18 100644 --- a/Library/SymbolTable.php +++ b/Library/SymbolTable.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; @@ -296,7 +294,6 @@ public function getVariableForRead($name, CompilationContext $compilationContext case 'array': if (!$variable->isLocalOnly()) { $variable->setMustInitNull(true); - $compilationContext->codePrinter->output('ZEPHIR_CHECK_POINTER(' . $variable->getName() . ');'); } break; } diff --git a/Library/TypeAwareInterface.php b/Library/TypeAwareInterface.php index 0420e1fe72..dc81f45d6e 100644 --- a/Library/TypeAwareInterface.php +++ b/Library/TypeAwareInterface.php @@ -1,15 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Zephir; diff --git a/Library/Types.php b/Library/Types.php index 70b8ff818c..b9f0c100d0 100644 --- a/Library/Types.php +++ b/Library/Types.php @@ -1,14 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir; diff --git a/Library/Types/AbstractType.php b/Library/Types/AbstractType.php index b0ba52b4bf..672db8c2af 100644 --- a/Library/Types/AbstractType.php +++ b/Library/Types/AbstractType.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Types; diff --git a/Library/Types/ArrayType.php b/Library/Types/ArrayType.php index 105101fb8b..ee82ae03b9 100644 --- a/Library/Types/ArrayType.php +++ b/Library/Types/ArrayType.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Types; diff --git a/Library/Types/CharType.php b/Library/Types/CharType.php index 755518df21..5444b4977b 100644 --- a/Library/Types/CharType.php +++ b/Library/Types/CharType.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Types; diff --git a/Library/Types/DoubleType.php b/Library/Types/DoubleType.php index b16c3805c2..1ae8f1787c 100644 --- a/Library/Types/DoubleType.php +++ b/Library/Types/DoubleType.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Types; diff --git a/Library/Types/IntType.php b/Library/Types/IntType.php index b04e2dafd2..12ebf06ce4 100644 --- a/Library/Types/IntType.php +++ b/Library/Types/IntType.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Types; diff --git a/Library/Types/IstringType.php b/Library/Types/IstringType.php index 9f0c54eb8e..683cadb248 100644 --- a/Library/Types/IstringType.php +++ b/Library/Types/IstringType.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Types; diff --git a/Library/Types/StringType.php b/Library/Types/StringType.php index 2d68448871..0692fb1e2a 100644 --- a/Library/Types/StringType.php +++ b/Library/Types/StringType.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Types; diff --git a/Library/Utils.php b/Library/Utils.php deleted file mode 100644 index 263d56ea1b..0000000000 --- a/Library/Utils.php +++ /dev/null @@ -1,278 +0,0 @@ -isAlias($baseName)) { - return $aliasManager->getAlias($baseName) . '\\' . substr($className, $firstSepPos + 1); - } - } elseif ($aliasManager && $aliasManager->isAlias($className)) { - return $aliasManager->getAlias($className); - } - - // Relative class/interface name - if ($currentNamespace) { - return $currentNamespace . '\\' . $className; - } - - return $className; - } - - /** - * Check if the host OS is Windows - * - * @return boolean - */ - public static function isWindows() - { - return strncasecmp(PHP_OS, 'WIN', 3) == 0; - } - - /** - * Check if the host OS is BSD based - * - * @link https://en.wikipedia.org/wiki/List_of_BSD_operating_systems - * @return boolean - */ - public static function isBsd() - { - return false !== stristr(strtolower(PHP_OS), 'bsd'); - } - - /** - * Check if the host OS is MacOs - * - * @return boolean - */ - public static function isMacOs() - { - return 'darwin' === strtolower(substr(PHP_OS, 0, 6)); - } - - /** - * Remove $dir recursively - * - * @param string $dir - */ - public static function recursiveRmDir($dir) - { - try { - $it = new \RecursiveDirectoryIterator( - $dir, - \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS - ); - - $items = iterator_to_array( - new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST) - ); - - foreach ($items as $item) { - if ($item->isFile()) { - unlink($item->getRealPath()); - } elseif ($item->isDir()) { - rmdir($item->getRealPath()); - } - } - } catch (\UnexpectedValueException $e) { - // Ignore - } - } - - /** - * Resolves Windows release folder. - * - * @return string - */ - public static function resolveWindowsReleaseFolder() - { - if (self::isThreadSafe()) { - if (PHP_INT_SIZE === 4) { - // 32-bit version of PHP - return "ext\\Release_TS"; - } elseif (PHP_INT_SIZE === 8) { - // 64-bit version of PHP - return "ext\\x64\\Release_TS"; - } else { - // fallback - return "ext\\Release_TS"; - } - } else { - if (PHP_INT_SIZE === 4) { - // 32-bit version of PHP - return "ext\\Release"; - } elseif (PHP_INT_SIZE === 8) { - // 64-bit version of PHP - return "ext\\x64\\Release"; - } else { - // fallback - return "ext\\Release"; - } - } - } - - /** - * Checks if current PHP is thread safe. - * - * @return boolean true - */ - public static function isThreadSafe() - { - if (defined('PHP_ZTS') && PHP_ZTS == 1) { - return true; - } - - ob_start(); - phpinfo(INFO_GENERAL); - return (bool) preg_match('/Thread\s*Safety\s*enabled/i', strip_tags(ob_get_clean())); - } -} diff --git a/Library/Variable.php b/Library/Variable.php index 35d4d37553..d3e18a086b 100644 --- a/Library/Variable.php +++ b/Library/Variable.php @@ -1,14 +1,12 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Zephir; @@ -671,7 +669,7 @@ public function isExternal() } /** - * Set if the variable must be initialized to null + * Get if the variable must be initialized to null * * @return boolean */ diff --git a/Library/Variable/Globals.php b/Library/Variable/Globals.php index ed6a1b6475..40590555df 100644 --- a/Library/Variable/Globals.php +++ b/Library/Variable/Globals.php @@ -1,15 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Zephir\Variable; diff --git a/Library/Version.php b/Library/Version.php new file mode 100644 index 0000000000..80e1a30545 --- /dev/null +++ b/Library/Version.php @@ -0,0 +1,66 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir; + +/** + * Zephir\Version + * + * @package Zephir + */ +final class Version +{ + const VERSION = '0.11.2'; + + /** @var string */ + private $currentVersion; + + /** + * Returns the current version + the ident if available. + * + * @return string + */ + public function get() + { + $version = '$Id$'; + if (strlen($version) !== 4) { + return self::VERSION . '-' . substr($version, 0, 10); + } + + if ($this->currentVersion === null) { + if (file_exists(__DIR__ . '/../.git')) { + $command = sprintf('git --git-dir=%s/../.git log --format="%%H" -n 1', __DIR__); + exec($command, $xversion); + if (isset($xversion[0]) && strlen($xversion[0]) > 10) { + $this->currentVersion = substr($xversion[0], 0, 10); + } else { + $this->currentVersion = false; + } + } + } + + if ($this->currentVersion) { + return self::VERSION . '-' . $this->currentVersion; + } + + return self::VERSION; + } + + /** + * The alias for {@see get}. + * + * @return string + */ + public function __toString() + { + return $this->get(); + } +} diff --git a/Library/functions.php b/Library/functions.php new file mode 100644 index 0000000000..3be4c7c4c0 --- /dev/null +++ b/Library/functions.php @@ -0,0 +1,184 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Zephir; + +use Zephir\Exception\InvalidArgumentException; + +/** + * Attempts to remove recursively the directory with all subdirectories and files. + * + * A E_WARNING level error will be generated on failure. + * + * @param string $path + * @return void + */ +function unlink_recursive($path) +{ + if (\is_dir($path)) { + $objects = \array_diff(\scandir($path), ['.', '..']); + + foreach ($objects as $object) { + if (\is_dir("{$path}/{$object}")) { + unlink_recursive("{$path}/{$object}"); + } else { + \unlink("{$path}/{$object}"); + } + } + + \rmdir($path); + } +} + +/** + * Camelize a string. + * + * @param string $string + * @return string + */ +function camelize($string) +{ + return \str_replace(' ', '', \ucwords(\str_replace('_', ' ', $string))); +} + + +/** + * Prepares a class name to be used as a C-string. + * + * @param string $className + * @return string + */ +function escape_class($className) +{ + return \str_replace('\\', '\\\\', $className); +} + +/** + * Prepares a string to be used as a C-string. + * + * @param string $string + * @return string + */ +function add_slashes($string) +{ + $newstr = ""; + $after = null; + $length = \strlen($string); + + for ($i = 0; $i < $length; $i++) { + $ch = \substr($string, $i, 1); + if ($i != ($length -1)) { + $after = \substr($string, $i + 1, 1); + } else { + $after = null; + } + + switch ($ch) { + case '"': + $newstr .= "\\" . '"'; + break; + case "\n": + $newstr .= "\\" . 'n'; + break; + case "\t": + $newstr .= "\\" . 't'; + break; + case "\r": + $newstr .= "\\" . 'r'; + break; + case "\v": + $newstr .= "\\" . 'v'; + break; + case '\\': + switch ($after) { + case "n": + case "v": + case "t": + case "r": + case '"': + case "\\": + $newstr .= $ch . $after; + $i++; + break; + default: + $newstr .= "\\\\"; + break; + } + break; + default: + $newstr .= $ch; + } + } + return $newstr; +} + +/** + * Transform class/interface name to FQN format + * + * @param string $className + * @param string $currentNamespace + * @param AliasManager $aliasManager + * @return string + */ +function fqcn($className, $currentNamespace, AliasManager $aliasManager = null) +{ + if (\is_string($className) == false) { + throw new InvalidArgumentException('Class name must be a string, got ' . \gettype($className)); + } + + // Absolute class/interface name + if ($className[0] === '\\') { + return \substr($className, 1); + } + + // If class/interface name not begin with \ maybe a alias or a sub-namespace + $firstSepPos = \strpos($className, '\\'); + if (false !== $firstSepPos) { + $baseName = \substr($className, 0, $firstSepPos); + if ($aliasManager && $aliasManager->isAlias($baseName)) { + return $aliasManager->getAlias($baseName) . '\\' . \substr($className, $firstSepPos + 1); + } + } elseif ($aliasManager && $aliasManager->isAlias($className)) { + return $aliasManager->getAlias($className); + } + + // Relative class/interface name + if ($currentNamespace) { + return $currentNamespace . '\\' . $className; + } + + return $className; +} + +/** + * Checks if the content of the file on the disk is the same as the content. + * + * @param string $content + * @param string $path + * @return bool + */ +function file_put_contents_ex($content, $path) +{ + if (\file_exists($path)) { + $contentMd5 = \md5($content); + $existingMd5 = \md5_file($path); + + if ($contentMd5 != $existingMd5) { + \file_put_contents($path, $content); + return true; + } + } else { + \file_put_contents($path, $content); + return true; + } + + return false; +} diff --git a/README.md b/README.md index dfc5097d93..d66d83d23b 100644 --- a/README.md +++ b/README.md @@ -1,112 +1,26 @@ -# Zephir +

Zephir

-[![Latest Stable Version][badge-zep-version]][zep-packagist] -[![Total Downloads][badge-zep-downloads]][zep-packagist] -[![License][badge-zep-license]][zep-packagist] -[![Build on Linux][badge-zep-travisci]][zep-travisci] -[![Build on Windows][badge-zep-appveyor]][zep-appveyor] +

+Build on Linux +BBuild on Windows +Total Downloads +Latest Stable Version +License +

+ +## Introduction **Zephir** - Ze(nd Engine) Ph(p) I(nt)r(mediate) - is a high level language that eases the creation and maintainability of extensions for PHP. Zephir extensions are exported to C code that can be compiled and optimized by major C compilers such as gcc/clang/vc++. Functionality is exposed to the PHP language. -Main features: - -* Both dynamic/static typing -* Reduced execution overhead compared with full interpretation -* Restricted procedural programming, promoting OOP -* Memory safety -* Ahead-of-time (AOT) compiler to provide predictable performance - -Compiler design goals: - -* Multi-pass compilation -* Type speculation/inference -* Allow runtime profile-guided optimizations, pseudo-constant propagation and indirect/virtual function inlining - -## Requirements - -* [re2c][re2c] >= 0.13.6 -* [Zephir Parser][zephir-parser] >= 1.1.0 -* A C compiler such as `gcc` >= 4.4 or an alternative such as `clang` >= 3.0, - `Visual C++` >= 11 or `Intel C++`. It is recommended to use `gcc` 4.4 or later -* GNU `make` >= 3.81 -* `automake` -* PHP development headers and tools -* The `build-essential` package when using `gcc` on Ubuntu (and likely other distros as well) - -## Installation - -**NOTE:** The `development` branch will always contain the latest **unstable** version. -If you wish to check older versions or formal, tagged release, please switch to the relevant -[branch][zep-branches]/[tag][zep-tags]. - -### Windows - -To install Zephir on Windows [follow this guide][zep-doc-windows]. - -### Linux | macOS | BSD | Solaris - -#### Git way - -Clone Zephir repository. - -Then, install Zephir by using command `./install` from project root dir. -For global installation add `-c` flag. - -### Composer way - -You can install Zephir using composer. - -To get Zephir, run `composer require phalcon/zephir`. - -### Additional notes on Ubuntu - -The following packages are needed in Ubuntu: - -* `apt-get install re2c libpcre3-dev` - -## Usage - -Compile the extension: - -```bash -zephir compile -``` - -## External Links - -* [Documentation][zep-docs-site] -* [Official Blog][zep-blog-site] -* [Forum][zep-forum] -* [Twitter][zep-twitter] -* [Facebook Group][zep-facebook] +Official documentation [is located here](https://docs.zephir-lang.com). ## Contributing -See [CONTRIBUTING.md][zep-doc-contributting] for details about contributions to this repository. +See [CONTRIBUTING.md](https://github.com/phalcon/zephir/blob/master/CONTRIBUTING.md) for details about contributions to this repository. ## License Zephir is open-sourced software licensed under the MIT License. -See the LICENSE file for more information. - -[zep-packagist]: https://packagist.org/packages/phalcon/zephir -[zep-travisci]: https://travis-ci.org/phalcon/zephir -[zep-appveyor]: https://ci.appveyor.com/project/sergeyklay/zephir/branch/master -[re2c]: http://re2c.org/ -[zephir-parser]: https://github.com/phalcon/php-zephir-parser -[zep-branches]: https://github.com/phalcon/zephir/branches -[zep-tags]: https://github.com/phalcon/zephir/tags -[zep-doc-windows]: https://github.com/phalcon/zephir/blob/master/WINDOWS.md -[zep-doc-contributting]: https://github.com/phalcon/zephir/blob/master/CONTRIBUTING.md -[zep-docs-site]: https://docs.zephir-lang.com/ -[zep-blog-site]: https://blog.zephir-lang.com/ -[zep-forum]: https://forum.zephir-lang.com/ -[zep-twitter]: https://twitter.com/zephirlang -[zep-facebook]: https://www.facebook.com/groups/zephir.language/ -[badge-zep-version]: https://poser.pugx.org/phalcon/zephir/v/stable.png -[badge-zep-downloads]: https://poser.pugx.org/phalcon/zephir/downloads.png -[badge-zep-license]: https://poser.pugx.org/phalcon/zephir/license.svg -[badge-zep-travisci]: https://img.shields.io/travis/phalcon/zephir/master.svg -[badge-zep-appveyor]: https://ci.appveyor.com/api/projects/status/cxa1810md7v6n095?svg=true +See the [LICENSE](https://github.com/phalcon/zephir/blob/master/LICENSE) file for more information. diff --git a/appveyor.yml b/appveyor.yml index 913a5f304e..7090298893 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 0.11.1-{build} +version: 0.11.2-{build} environment: matrix: @@ -43,8 +43,8 @@ environment: NO_INTERACTION: 1 REPORT_EXIT_STATUS: 1 COMPOSER_NO_INTERACTION: 1 - PARSER_VERSION: 1.1.2 - PARSER_RELEASE: 290 + PARSER_VERSION: 1.1.3 + PARSER_RELEASE: 401 ZEPHIRDIR: c:\projects\zephir matrix: @@ -108,10 +108,3 @@ on_failure: - ps: PrintVars - ps: PrintDirectoriesContent - ps: PrintPhpInfo - -notifications: - - provider: Email - to: - - build@phalconphp.com - subject: "Build Zephir [{{status}}]" - on_build_status_changed: true diff --git a/bin/bash_completion b/bin/bash_completion index 47fa5036b5..e092e63ab1 100644 --- a/bin/bash_completion +++ b/bin/bash_completion @@ -1,7 +1,9 @@ -# Zephir Bash Completion +# This file is part of the Zephir. # -# http://zephir-lang.com/ +# (c) Zephir Team # +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. _zephir-completion() { diff --git a/bin/packer b/bin/packer new file mode 100755 index 0000000000..7fc7d43570 --- /dev/null +++ b/bin/packer @@ -0,0 +1,63 @@ +#!/usr/bin/env php + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +if (PHP_SAPI !== 'cli') { + fprintf( + STDERR, + 'Error: This script should be invoked via the CLI version of PHP, not the %s SAPI' . PHP_EOL, + PHP_SAPI + ); + + exit(1); +} + +if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + fwrite( + STDERR, + 'This script is designed to run inside a Linux/Unix terminals only.' . PHP_EOL + ); + + exit(1); +} + +$cwd = getcwd(); +chdir(dirname(__DIR__)); + +require_once 'vendor/autoload.php'; +if (!class_exists('Composer\Autoload\ClassLoader')) { + fwrite( + STDERR, + 'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . + ' composer install' . PHP_EOL . PHP_EOL . + 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL + ); + + chdir($cwd); + exit(1); +} + +$box = rtrim(shell_exec('command -v box 2>/dev/null')); +if (empty($box)) { + fwrite( + STDERR, + 'To use this script you need to install kherge/box.' . PHP_EOL . PHP_EOL . + 'You can learn all about kherge/box on https://github.com/humbug/box/.' . PHP_EOL + ); + + chdir($cwd); + exit(1); +} + +passthru("php -d phar.readonly=0 {$box} compile", $status); + +chdir($cwd); +exit($status); diff --git a/bin/zephir b/bin/zephir index 10d3f55247..17e40d6c55 100755 --- a/bin/zephir +++ b/bin/zephir @@ -1,4 +1,11 @@ #!/bin/sh +# This file is part of the Zephir. +# +# (c) Zephir Team +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. + if [ -z "$ZEPHIRDIR" ]; then ZEPHIRDIR="%ZEPHIRDIR%" if [ "$ZEPHIRDIR" = "%""ZEPHIRDIR""%" ]; then diff --git a/bootstrap.php b/bootstrap.php deleted file mode 100644 index 6d6d064f1b..0000000000 --- a/bootstrap.php +++ /dev/null @@ -1,43 +0,0 @@ -", + "", + "For the full copyright and license information, please view the LICENSE", + "file that was distributed with this source code." + ], + "directories": [ + "kernels", + "Library", + "prototypes", + "templates", + "vendor" + ], + "files": [ + "LICENSE" + ], + "blacklist": [ + "unit-tests", + "test" + ], + "finder": [ + { + "in": "kernels", + "name": "*.*" + }, + { + "in": "Library", + "name": "*.*" + }, + { + "in": "prototypes", + "name": "*.*" + }, + { + "in": "templates", + "name": "*.*" + }, + { + "name": "*.php", + "exclude": [ + "doc", + "test", + "Tests", + "tests" + ], + "in": "vendor" + } + ], + "replacement-sigil": "$", + "git-commit-short": "Id" +} diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000000..2470a84992 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,4 @@ +ignore: + - "/usr*" + - "*/.phpenv/*" + - "/home/travis/build/include/*" diff --git a/compiler.php b/compiler.php index 7ed82597c3..461695e187 100755 --- a/compiler.php +++ b/compiler.php @@ -1,17 +1,22 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ -require __DIR__ . '/bootstrap.php'; +use Zephir\Bootstrap; -$bootstrap = new Zephir\Bootstrap(getenv('ZEPHIRDIR') ?: __DIR__); -$bootstrap->boot(); +require_once __DIR__ . '/vendor/autoload.php'; + +$bootstrap = new Bootstrap( + strpos(__DIR__, 'phar://') === 0 ? + (getenv('ZEPHIRDIR') ?: __DIR__) : + __DIR__ +); + +$bootstrap->execute(); diff --git a/composer.json b/composer.json index cb4f925492..e9001b84e0 100644 --- a/composer.json +++ b/composer.json @@ -21,12 +21,13 @@ } ], "require": { - "php": ">=5.5", + "php": ">=5.6", "ext-ctype": "*", "ext-hash": "*", "ext-json": "*", + "ext-mbstring": "*", "ext-xml": "*", - "ext-mbstring": "*" + "league/container": "^2.4 || ^3.2" }, "require-dev": { "ext-gmp": "*", @@ -38,17 +39,19 @@ "autoload": { "psr-4": { "Zephir\\": "Library" - } + }, + "files": [ + "Library/functions.php" + ] }, "autoload-dev": { "psr-4": { - "Zephir\\Stubs\\": "unit-tests/Zephir/Stubs/", "Zephir\\Test\\": "unit-tests/Zephir/Test/", "Zephir\\Support\\": "unit-tests/Zephir/Support/", "Extension\\": "unit-tests/Extension/" }, "classmap": [ - "unit-tests/Data/" + "unit-tests/fixtures/mocks/" ] }, "bin": [ diff --git a/ext/.gitignore b/ext/.gitignore deleted file mode 100644 index d6b7ef32c8..0000000000 --- a/ext/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/install b/install index 3966743d62..a75e585353 100755 --- a/install +++ b/install @@ -1,4 +1,11 @@ #!/bin/bash +# +# This file is part of the Zephir. +# +# (c) Zephir Team +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. # Using the -c option will copy zephir in /usr/local/bin options='c' diff --git a/install-nosudo b/install-nosudo index 5c70a391a4..bc21ce2998 100755 --- a/install-nosudo +++ b/install-nosudo @@ -1,4 +1,11 @@ #!/bin/bash +# +# This file is part of the Zephir. +# +# (c) Zephir Team +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. ZEPHIRDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" sed "s#%ZEPHIRDIR%#$ZEPHIRDIR#g" bin/zephir > bin/zephir-cmd diff --git a/kernels/ZendEngine2/main.h b/kernels/ZendEngine2/main.h index c93510e68e..6d9e70d203 100644 --- a/kernels/ZendEngine2/main.h +++ b/kernels/ZendEngine2/main.h @@ -548,8 +548,6 @@ int zephir_fetch_parameters(int num_args TSRMLS_DC, int required_args, int optio #define ZEPHIR_DEBUG_PARAMS_DUMMY , "", 0 #endif -#define ZEPHIR_CHECK_POINTER(v) if (!v) fprintf(stderr, "%s:%d\n", __PRETTY_FUNCTION__, __LINE__); - int zephir_is_php_version(unsigned int id); void zephir_get_args(zval* return_value TSRMLS_DC); diff --git a/kernels/ZendEngine3/file.c b/kernels/ZendEngine3/file.c index 11dfe67898..78187b734b 100644 --- a/kernels/ZendEngine3/file.c +++ b/kernels/ZendEngine3/file.c @@ -271,7 +271,7 @@ void zephir_file_put_contents(zval *return_value, zval *filename, zval *data) if (Z_STRLEN_P(data)) { numbytes = php_stream_write(stream, Z_STRVAL_P(data), Z_STRLEN_P(data)); if (numbytes != Z_STRLEN_P(data)) { - php_error_docref(NULL, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", numbytes, Z_STRLEN_P(data)); + php_error_docref(NULL, E_WARNING, "Only %d of %zu bytes written, possibly out of free disk space", numbytes, Z_STRLEN_P(data)); numbytes = -1; } } diff --git a/kernels/ZendEngine3/main.h b/kernels/ZendEngine3/main.h index 971a4fccb6..db6c4c01eb 100644 --- a/kernels/ZendEngine3/main.h +++ b/kernels/ZendEngine3/main.h @@ -24,6 +24,7 @@ #include #include #include +#include extern zend_string* i_parent; extern zend_string* i_static; @@ -59,14 +60,20 @@ extern zend_string* i_self; #include #include "kernel/exception.h" -/** class/interface registering */ -#define ZEPHIR_REGISTER_CLASS(ns, class_name, lower_ns, name, methods, flags) \ - { \ - zend_class_entry ce; \ - memset(&ce, 0, sizeof(zend_class_entry)); \ - INIT_NS_CLASS_ENTRY(ce, #ns, #class_name, methods); \ - lower_ns## _ ##name## _ce = zend_register_internal_class(&ce); \ - lower_ns## _ ##name## _ce->ce_flags |= flags; \ +/* class/interface registering */ +#define ZEPHIR_REGISTER_CLASS(ns, class_name, lower_ns, name, methods, flags) \ + { \ + zend_class_entry ce; \ + memset(&ce, 0, sizeof(zend_class_entry)); \ + INIT_NS_CLASS_ENTRY(ce, #ns, #class_name, methods); \ + lower_ns## _ ##name## _ce = zend_register_internal_class(&ce); \ + if (UNEXPECTED(!lower_ns## _ ##name## _ce)) { \ + const char *_n = (#ns); \ + const char *_c = (#class_name); \ + zend_error(E_ERROR, "%s\\%s: class registration has failed.", _n, _c); \ + return FAILURE; \ + } \ + lower_ns## _ ##name## _ce->ce_flags |= flags; \ } #define ZEPHIR_REGISTER_CLASS_EX(ns, class_name, lower_ns, lcname, parent_ce, methods, flags) \ @@ -297,8 +304,6 @@ int zephir_declare_class_constant_double(zend_class_entry *ce, const char *name, int zephir_declare_class_constant_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_length); int zephir_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value); -#define ZEPHIR_CHECK_POINTER(v) - int zephir_is_php_version(unsigned int id); /** Method declaration for API generation */ diff --git a/modules/.gitkeep b/modules/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 487a98ed69..c3fd26d70c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -29,7 +29,6 @@ -