public function getResolvedParams($parameters, CompilationContext $compilationContext, array $expression, $calleeDefinition = null)
{
$codePrinter = $compilationContext->codePrinter;
$exprParams = $this->getResolvedParamsAsExpr($parameters, $compilationContext, $expression);
/**
* 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']) {
case 'int':
case 'uint':
case 'double':
case 'long':
case 'char':
case 'uchar':
case 'boolean':
case 'bool':
$readOnlyParameters[$position] = true;
break;
}
}
}
}
}
}
$params = array();
$types = array();
$dynamicTypes = array();
$mustCheck = array();
foreach ($exprParams as $position => $compiledExpression) {
$expression = $compiledExpression->getOriginal();
switch ($compiledExpression->getType()) {
case 'null':
$parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
$params[] = $compilationContext->backend->getVariableCode($parameterVariable);
$compilationContext->backend->assignNull($parameterVariable, $compilationContext);
$this->_temporalVariables[] = $parameterVariable;
$types[] = $compiledExpression->getType();
$dynamicTypes[] = $compiledExpression->getType();
break;
case 'int':
case 'uint':
case 'long':
$parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
$params[] = $compilationContext->backend->getVariableCode($parameterVariable);
$compilationContext->backend->assignLong($parameterVariable, $compiledExpression->getCode(), $compilationContext);
$this->_temporalVariables[] = $parameterVariable;
$types[] = $compiledExpression->getType();
$dynamicTypes[] = $compiledExpression->getType();
break;
case 'double':
$parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
$params[] = $compilationContext->backend->getVariableCode($parameterVariable);
$compilationContext->backend->assignDouble($parameterVariable, $compiledExpression->getCode(), $compilationContext);
$this->_temporalVariables[] = $parameterVariable;
$types[] = $compiledExpression->getType();
break;
case 'bool':
$value = $compiledExpression->getCode();
if ($value == 'true') {
$value = '1';
} else {
if ($value == 'false') {
$value = '0';
}
}
$parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
$params[] = $compilationContext->backend->getVariableCode($parameterVariable);
$compilationContext->backend->assignBool($parameterVariable, $value, $compilationContext);
$this->_temporalVariables[] = $parameterVariable;
$types[] = $compiledExpression->getType();
$dynamicTypes[] = $compiledExpression->getType();
break;
case 'ulong':
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;
/* ZE3 copies strings */
if ($compilationContext->backend->getName() == 'ZendEngine2') {
$mustCheck[] = $parameterVariable->getName();
}
$params[] = $compilationContext->backend->getVariableCode($parameterVariable);
$types[] = $compiledExpression->getType();
$dynamicTypes[] = $compiledExpression->getType();
break;
case 'array':
$parameterVariable = $compilationContext->symbolTable->getVariableForRead($compiledExpression->getCode(), $compilationContext, $expression);
$params[] = $compilationContext->backend->getVariableCode($parameterVariable);
$types[] = $compiledExpression->getType();
$dynamicTypes[] = $compiledExpression->getType();
break;
case 'variable':
$parameterVariable = $compilationContext->symbolTable->getVariableForRead($compiledExpression->getCode(), $compilationContext, $expression);
switch ($parameterVariable->getType()) {
case 'int':
case 'uint':
case 'long':
/* ulong must be stored in string */
/* ulong must be stored in string */
case 'ulong':
$parameterTempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
$params[] = $compilationContext->backend->getVariableCode($parameterTempVariable);
$compilationContext->backend->assignLong($parameterTempVariable, $parameterVariable, $compilationContext);
$this->_temporalVariables[] = $parameterTempVariable;
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'double':
$parameterTempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
$compilationContext->backend->assignDouble($parameterTempVariable, $parameterVariable, $compilationContext);
$params[] = $compilationContext->backend->getVariableCode($parameterTempVariable);
$this->_temporalVariables[] = $parameterTempVariable;
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'bool':
$tempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext);
$codePrinter->output('if (' . $parameterVariable->getName() . ') {');
$codePrinter->increaseLevel();
$compilationContext->backend->assignBool($tempVariable, '1', $compilationContext);
$codePrinter->decreaseLevel();
$codePrinter->output('} else {');
$codePrinter->increaseLevel();
$compilationContext->backend->assignBool($tempVariable, '0', $compilationContext);
$codePrinter->decreaseLevel();
$codePrinter->output('}');
$params[] = $compilationContext->backend->getVariableCode($tempVariable);
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'string':
case 'array':
$params[] = $compilationContext->backend->getVariableCode($parameterVariable);
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'variable':
$params[] = $compilationContext->backend->getVariableCode($parameterVariable);
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getDynamicTypes();
break;
default:
throw new CompilerException("Cannot use variable type: " . $parameterVariable->getType() . " as parameter", $expression);
}
break;
default:
throw new CompilerException("Cannot use value type: " . $compiledExpression->getType() . " as parameter", $expression);
}
}
$this->_resolvedTypes = $types;
$this->_resolvedDynamicTypes = $dynamicTypes;
$this->_mustCheckForCopy = $mustCheck;
return $params;
}