Skip to content

Commit

Permalink
Merge pull request #1540 from phalcon/development
Browse files Browse the repository at this point in the history
0.9.8
  • Loading branch information
sergeyklay authored May 21, 2017
2 parents a5f5854 + 00bb6f7 commit 63a35e1
Show file tree
Hide file tree
Showing 22 changed files with 449 additions and 145 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
- LIBRARY_PATH="$TRAVIS_BUILD_DIR/build/lib":$LIBRARY_PATH
- C_INCLUDE_PATH="$TRAVIS_BUILD_DIR/build/include"
- CFLAGS="-g3 -O0 -Wall -fvisibility=hidden"
- ZEPHIR_PARSER_VERSION="v1.0.2"
- ZEPHIR_PARSER_VERSION="v1.0.3"
matrix:
- CC="ccache gcc"
- CC="clang"
Expand Down Expand Up @@ -62,6 +62,7 @@ before_script:
- $CC --version

script:
- echo 'variables_order=EGPCS' >> "$(phpenv root)/versions/$(phpenv version-name)/etc/php.ini"
- vendor/bin/phpcs --standard=PSR2 --report=emacs --extensions=php --warning-severity=0 Library/ unit-tests/Extension/ unit-tests/Zephir/
- valgrind --read-var-info=yes --error-exitcode=1 --fullpath-after= --track-origins=yes --leak-check=full ./unit-tests/phpunit --not-exit -c phpunit.xml.dist --debug unit-tests/
- $(phpenv which php) unit-tests/microbench.php
Expand Down
22 changes: 14 additions & 8 deletions Library/Backends/ZendEngine3/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Zephir\ClassMethod;
use Zephir\FunctionDefinition;
use Zephir\Backends\ZendEngine2\Backend as BackendZendEngine2;
use Zephir\BaseBackend;
use Zephir\GlobalConstant;
use Zephir\Utils;

Expand All @@ -29,6 +28,7 @@ public function isZE3()
public function getVariableCode(Variable $variable)
{
if ($variable->isDoublePointer() ||
$variable->isSuperGlobal() ||
in_array($variable->getName(), array('this_ptr', 'return_value')) ||
in_array($variable->getType(), array('int', 'long'))) {
return $variable->getName();
Expand Down Expand Up @@ -189,7 +189,7 @@ public function generateInitCode(&$groupVariables, $type, $pointer, Variable $va

$isComplex = ($type == 'variable' || $type == 'string' || $type == 'array' || $type == 'resource' || $type == 'callable' || $type == 'object');

if ($isComplex && !$variable->isDoublePointer()) { /* && $variable->mustInitNull() */
if ($isComplex && !$variable->isDoublePointer() && !$variable->isSuperGlobal()) { /* && $variable->mustInitNull() */
$groupVariables[] = $variable->getName();
if ($variable->getRealname() == '__$null') {
return "\t" . 'ZVAL_NULL(&' . $variable->getName() . ');';
Expand All @@ -206,7 +206,7 @@ public function generateInitCode(&$groupVariables, $type, $pointer, Variable $va
return;
}

if ($variable->isDoublePointer()) {
if ($variable->isDoublePointer() || $variable->isSuperGlobal()) {
/* Double pointers for ZE3 are used as zval * */
$ptr = $isComplex ? $pointer : $pointer . $pointer;
if ($variable->mustInitNull()) {
Expand Down Expand Up @@ -499,13 +499,19 @@ public function arrayUnset(Variable $variable, $exprIndex, $flags, CompilationCo

public function fetchGlobal(Variable $globalVar, CompilationContext $compilationContext, $useCodePrinter = true)
{
$name = $globalVar->getName();
$compilationContext->symbolTable->mustGrownStack(true);
$output = 'zephir_get_global(&' . $name . ', SL("' . $name . '"));';
$name = $globalVar->getName();
$lines = array();
$lines[] = 'zephir_get_global(&' . $name . ', SL("' . $name . '"));';
$lines[] = 'if (!' . $name . ') {';
$lines[] = "\t" . 'ZEPHIR_THROW_EXCEPTION_STR(zend_exception_get_default(), "Invalid superglobal");';
$lines[] = "\t" . 'return;';
$lines[] = '}';
if ($useCodePrinter) {
$codePrinter->output($output);
foreach ($lines as $line) {
$compilationContext->codePrinter->output($line);
}
}
return $output;
return join("\n\t", $lines);
}

public function fetchClass(Variable $zendClassEntry, $className, $guarded, CompilationContext $context)
Expand Down
2 changes: 0 additions & 2 deletions Library/BaseBackend.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace Zephir;

use Zephir\Config;

abstract class BaseBackend
{
/**
Expand Down
2 changes: 1 addition & 1 deletion Library/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ public function compile(CompilationContext $compilationContext)
* Fetch used superglobals
*/
foreach ($symbolTable->getVariables() as $name => $variable) {
if ($symbolTable->isSuperGlobal($name)) {
if ($variable->isSuperGlobal()) {
$globalVar = $symbolTable->getVariable($name);
$codePrinter->preOutput("\t" . $compilationContext->backend->fetchGlobal($globalVar, $compilationContext, false));
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class Compiler
{
const VERSION = '0.9.7';
const VERSION = '0.9.8';

public $parserCompiled = false;

Expand Down
1 change: 1 addition & 0 deletions Library/CompilerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ public function checkDependencies(Compiler $compiler)
*
* @param Compiler $compiler
* @param StringsManager $stringsManager
* @throws CompilerException
*/
public function compile(Compiler $compiler, StringsManager $stringsManager)
{
Expand Down
5 changes: 0 additions & 5 deletions Library/Statements/Let/ArrayIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,9 @@ protected function _assignArrayIndexSingle($variable, ZephirVariable $symbolVari
$symbolVariable = $this->_getResolvedArrayItem($resolvedExpr, $compilationContext);

$flags = 'PH_COPY | PH_SEPARATE';
$isGlobalVariable = $compilationContext->symbolTable->isSuperGlobal($variable);

$compilationContext->headersManager->add('kernel/array');

if ($isGlobalVariable) {
$flags = 'PH_COPY';
}

switch ($exprIndex->getType()) {
case 'int':
case 'uint':
Expand Down
8 changes: 4 additions & 4 deletions Library/Statements/ReturnStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function compile(CompilationContext $compilationContext)

case 'string':
case 'array':
$codePrinter->output('RETURN_CTOR(' . $resolvedExpr->getCode() . ');');
$codePrinter->output('RETURN_CTOR(' . $compilationContext->backend->getVariableCode($symbolVariable) . ');');
break;

case 'bool':
Expand All @@ -232,12 +232,12 @@ public function compile(CompilationContext $compilationContext)
if ($symbolVariable->getName() != 'return_value') {
if (!$symbolVariable->isExternal()) {
if ($symbolVariable->isLocalOnly()) {
$codePrinter->output('RETURN_LCTOR(' . $symbolVariable->getName() . ');');
$codePrinter->output('RETURN_LCTOR(' . $compilationContext->backend->getVariableCode($symbolVariable) . ');');
} else {
if (!$symbolVariable->isMemoryTracked()) {
$codePrinter->output('RETURN_CTOR(' . $symbolVariable->getName() . ');');
$codePrinter->output('RETURN_CTOR(' . $compilationContext->backend->getVariableCode($symbolVariable) . ');');
} else {
$codePrinter->output('RETURN_CCTOR(' . $symbolVariable->getName() . ');');
$codePrinter->output('RETURN_CCTOR(' . $compilationContext->backend->getVariableCode($symbolVariable) . ');');
}
}
} else {
Expand Down
5 changes: 0 additions & 5 deletions Library/Statements/UnsetStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ public function compile(CompilationContext $compilationContext)
$expr = new Expression($expression['right']);
$expr->setReadOnly(true);
$exprIndex = $expr->compile($compilationContext);

if ($compilationContext->symbolTable->isSuperGlobal($variable)) {
$flags = 0;
}

break;

case 'property-access':
Expand Down
62 changes: 29 additions & 33 deletions Library/SymbolTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| This source file is subject the MIT license, that is bundled with |
| this package in the file LICENSE, and is available through the |
| world-wide-web at the following url: |
| http://zephir-lang.com/license.html |
| https://zephir-lang.com/license.html |
| |
| If you did not receive a copy of the MIT license and are unable |
| to obtain it through the world-wide-web, please send a note to |
Expand All @@ -19,9 +19,8 @@

namespace Zephir;

use Zephir\Variable;
use Zephir\Variable\Globals;
use Zephir\Passes\LocalContextPass;
use Zephir\Passes\StaticTypeInference;

/**
* SymbolTable
Expand All @@ -45,18 +44,10 @@ class SymbolTable

protected $compilationContext;

public function resolveVariableToBranch($name, $compilationContext)
{
$currentBranch = $compilationContext->branchManager->getCurrentBranch();
do {
$currentId = $currentBranch->getUniqueId();
if (isset($this->branchVariables[$currentId]) && isset($this->branchVariables[$currentId][$name])) {
return $currentBranch;
}
$currentBranch = $currentBranch->getParentBranch();
} while ($currentBranch != null);
return null;
}
/**
* @var Globals
*/
protected $globalsManager;

/**
* SymbolTable
Expand All @@ -65,6 +56,8 @@ public function resolveVariableToBranch($name, $compilationContext)
*/
public function __construct(CompilationContext $compilationContext)
{
$this->globalsManager = new Globals();

/* The variables are registered in branch 1, which is the external branch */
$this->compilationContext = $compilationContext;
$this->branchVariables[1] = array();
Expand All @@ -88,6 +81,19 @@ public function __construct(CompilationContext $compilationContext)
$this->branchVariables[1]['return_value_ptr'] = $returnValue;
}

public function resolveVariableToBranch($name, $compilationContext)
{
$currentBranch = $compilationContext->branchManager->getCurrentBranch();
do {
$currentId = $currentBranch->getUniqueId();
if (isset($this->branchVariables[$currentId]) && isset($this->branchVariables[$currentId][$name])) {
return $currentBranch;
}
$currentBranch = $currentBranch->getParentBranch();
} while ($currentBranch != null);
return null;
}

/**
* Sets the local context information
*
Expand Down Expand Up @@ -132,7 +138,7 @@ public function addVariable($type, $name, CompilationContext $compilationContext
{
$currentBranch = $compilationContext->branchManager->getCurrentBranch();
$branchId = $currentBranch->getUniqueId();
if ($this->isSuperGlobal($name) || $type == 'zephir_fcall_cache_entry') {
if ($this->globalsManager->isSuperGlobal($name) || $type == 'zephir_fcall_cache_entry') {
$branchId = 1;
}
$varName = $name;
Expand All @@ -152,7 +158,6 @@ public function addVariable($type, $name, CompilationContext $compilationContext
}
}


if (!isset($this->branchVariables[$branchId])) {
$this->branchVariables[$branchId] = array();
}
Expand Down Expand Up @@ -204,7 +209,7 @@ public function getVariable($name, $compilationContext = null)
/**
* Returns all the variables defined in the symbol table
*
* @return array
* @return \Zephir\Variable[]
*/
public function getVariables()
{
Expand All @@ -224,25 +229,14 @@ public function getVariablesByBranch($branchId)
}
return null;
}

/**
* Checks if a variable is a superglobal
*
* @param string $name
* @return boolean
*/
public function isSuperGlobal($name)
{
return $name == '_GET' || $name == '_POST' || $name == '_COOKIE' || $name == '_SERVER' || $name == '_SESSION' || $name == '_REQUEST' || $name == '_FILES';
}

/**
* Return a variable in the symbol table, it will be used for a read operation
*
* @param string $name
* @param CompilationContext $compilationContext
* @param array $statement
* @return Variable
* @throws CompilerException
*/
public function getVariableForRead($name, CompilationContext $compilationContext = null, array $statement = null)
{
Expand All @@ -258,7 +252,7 @@ public function getVariableForRead($name, CompilationContext $compilationContext
/**
* Create superglobals just in time
*/
if ($this->isSuperGlobal($name)) {
if ($this->globalsManager->isSuperGlobal($name)) {
if (!$this->hasVariable($name)) {
/**
* @TODO, injecting globals, initialize to null and check first?
Expand Down Expand Up @@ -429,7 +423,7 @@ public function getVariableForWrite($name, CompilationContext $compilationContex
/**
* Create superglobals just in time
*/
if ($this->isSuperGlobal($name)) {
if ($this->globalsManager->isSuperGlobal($name)) {
if (!$this->hasVariable($name)) {
/**
* @TODO, injecting globals, initialize to null and check first?
Expand All @@ -439,6 +433,7 @@ public function getVariableForWrite($name, CompilationContext $compilationContex
$superVar->setDynamicTypes('array');
$superVar->increaseMutates();
$superVar->increaseUses();
$superVar->setIsExternal(true);
$superVar->setUsed(true, $statement);
$this->addRawVariable($superVar);
return $superVar;
Expand Down Expand Up @@ -475,13 +470,14 @@ public function getVariableForWrite($name, CompilationContext $compilationContex
* @param CompilationContext $compilationContext
* @param array $statement
* @return Variable
* @throws CompilerException
*/
public function getVariableForUpdate($name, CompilationContext $compilationContext, array $statement = null)
{
/**
* Create superglobals just in time
*/
if ($this->isSuperGlobal($name)) {
if ($this->globalsManager->isSuperGlobal($name)) {
if (!$this->hasVariable($name)) {
/**
* @TODO, injecting globals, initialize to null and check first?
Expand Down
Loading

0 comments on commit 63a35e1

Please sign in to comment.