Permalink
Browse files

Fix branching of superglobals by fetching them as soon as possible (R…

…OOT)
  • Loading branch information...
steffen
steffen committed May 25, 2015
1 parent 5fdefa5 commit 1e831725d3e99e18441a337356bfebc1f32fb1df
Showing with 18 additions and 16 deletions.
  1. +9 −0 Library/ClassMethod.php
  2. +9 −0 Library/FunctionDefinition.php
  3. +0 −16 Library/SymbolTable.php
@@ -1960,6 +1960,15 @@ public function compile(CompilationContext $compilationContext)
$code .= $initCode . $initVarCode;
$codePrinter->preOutput($code);
/**
* Fetch used superglobals
*/
foreach ($symbolTable->getVariables() as $name => $variable) {
if ($symbolTable->isSuperGlobal($name)) {
$codePrinter->preOutput("\t" . 'zephir_get_global(&' . $name . ', SS("' . $name . '") TSRMLS_CC);');
}
}
/**
* Grow the stack if needed
*/
@@ -1646,6 +1646,15 @@ public function compile(CompilationContext $compilationContext)
$code .= $initCode . $initVarCode;
$codePrinter->preOutput($code);
/**
* Fetch used superglobals
*/
foreach ($symbolTable->getVariables() as $name => $variable) {
if ($symbolTable->isSuperGlobal($name)) {
$codePrinter->preOutput("\t" . 'zephir_get_global(&' . $name . ', SS("' . $name . '") TSRMLS_CC);');
}
}
/**
* Grow the stack if needed
@@ -191,25 +191,13 @@ public function getVariableForRead($name, CompilationContext $compilationContext
/**
* @TODO, injecting globals, initialize to null and check first?
*/
$compilationContext->codePrinter->output('zephir_get_global(&' . $name . ', SS("' . $name . '") TSRMLS_CC);');
$variable = new Variable('variable', $name, $compilationContext->currentBranch);
$variable->setIsInitialized(true, $compilationContext, $statement);
$variable->setDynamicTypes('array');
$variable->setIsExternal(true);
$this->variables[$name] = $variable;
} else {
$found = false;
$variable = $this->getVariable($name);
foreach ($variable->getInitBranches() as $branch) {
if ($branch->getType() == Branch::TYPE_ROOT) {
$found = true;
}
}
if (!$found) {
$compilationContext->codePrinter->output('zephir_get_global(&' . $name . ', SS("' . $name . '") TSRMLS_CC);');
}
}
$variable->increaseUses();
return $variable;
@@ -372,8 +360,6 @@ public function getVariableForWrite($name, CompilationContext $compilationContex
/**
* @TODO, injecting globals, initialize to null and check first?
*/
$compilationContext->codePrinter->output('zephir_get_global(&' . $name . ', SS("' . $name . '") TSRMLS_CC);');
$superVar = new Variable('variable', $name, $compilationContext->currentBranch);
$superVar->setIsInitialized(true, $compilationContext, $statement);
$superVar->setDynamicTypes('array');
@@ -426,8 +412,6 @@ public function getVariableForUpdate($name, CompilationContext $compilationConte
/**
* @TODO, injecting globals, initialize to null and check first?
*/
$compilationContext->codePrinter->output('zephir_get_global(&' . $name . ', SS("' . $name . '") TSRMLS_CC);');
$superVar = new Variable('variable', $name, $compilationContext->currentBranch);
$superVar->setIsInitialized(true, $compilationContext, $statement);
$superVar->setDynamicTypes('array');

0 comments on commit 1e83172

Please sign in to comment.