code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
private function doVariableAssignment(
Printer $codePrinter,
CompiledExpression $resolvedExpr,
ZephirVariable $symbolVariable,
string $variable,
array $statement,
CompilationContext $compilationContext,
ReadDetector $readDetector
): void {
switch ($resolvedExpr->getType()) {
case 'null':
if ($statement['operator'] == 'assign') {
$symbolVariable->initVariant($compilationContext);
$symbolVariable->setDynamicTypes('null');
$compilationContext->backend->assignNull($symbolVariable, $compilationContext);
}
break;
case 'int':
case 'uint':
case 'long':
case 'ulong':
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
switch ($statement['operator']) {
case 'mul-assign':
case 'sub-assign':
case 'add-assign':
switch ($statement['operator']) {
case 'mul-assign':
$functionName = 'ZEPHIR_MUL_ASSIGN';
break;
case 'sub-assign':
$functionName = 'ZEPHIR_SUB_ASSIGN';
break;
case 'add-assign':
$functionName = 'ZEPHIR_ADD_ASSIGN';
break;
}
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite(
'variable',
$compilationContext
);
$compilationContext->backend->assignLong(
$tempVariable,
$resolvedExpr->getCode(),
$compilationContext
);
$compilationContext->symbolTable->mustGrownStack(true);
$compilationContext->headersManager->add('kernel/operators');
$codePrinter->output(
$functionName . '(' . $symbol . ', ' . $compilationContext->backend->getVariableCode(
$tempVariable
) . ');'
);
break;
case 'assign':
$symbolVariable->setDynamicTypes('long');
if ($readDetector->detect($variable, $resolvedExpr->getOriginal())) {
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite(
'int',
$compilationContext
);
$codePrinter->output($tempVariable->getName() . ' = ' . $resolvedExpr->getCode() . ';');
$symbolVariable->initVariant($compilationContext);
$compilationContext->backend->assignLong(
$symbolVariable,
$tempVariable,
$compilationContext
);
} else {
$symbolVariable->initVariant($compilationContext);
$compilationContext->backend->assignLong(
$symbolVariable,
$resolvedExpr->getCode(),
$compilationContext
);
}
break;
case 'div-assign':
$this->processDoVariableAssignmentAssign(
$symbolVariable,
$readDetector,
$variable,
$resolvedExpr,
$compilationContext,
$codePrinter
);
break;
default:
throw new IllegalOperationException($statement, $resolvedExpr, $resolvedExpr->getOriginal());
}
break;
case 'char':
case 'uchar':
switch ($statement['operator']) {
case 'assign':
$symbolVariable->setDynamicTypes('long');
if ($readDetector->detect($variable, $resolvedExpr->getOriginal())) {
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite(
'char',
$compilationContext
);
$codePrinter->output($tempVariable->getName() . ' = ' . $resolvedExpr->getCode() . ';');
$symbolVariable->initVariant($compilationContext);
$compilationContext->backend->assignLong(
$symbolVariable,
$tempVariable,
$compilationContext
);
} else {
$symbolVariable->initVariant($compilationContext);
$compilationContext->backend->assignLong(
$symbolVariable,
'\'' . $resolvedExpr->getCode() . '\'',
$compilationContext
);
}
break;
default:
throw new IllegalOperationException($statement, $resolvedExpr, $resolvedExpr->getOriginal());
}
break;
case 'double':
switch ($statement['operator']) {
case 'mul-assign':
case 'sub-assign':
case 'add-assign':
switch ($statement['operator']) {
case 'mul-assign':
$functionName = 'ZEPHIR_MUL_ASSIGN';
break;
case 'sub-assign':
$functionName = 'ZEPHIR_SUB_ASSIGN';
break;
case 'add-assign':
$functionName = 'ZEPHIR_ADD_ASSIGN';
break;
}
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite(
'variable',
$compilationContext
);
$tempVariable->setDynamicTypes('double');
$compilationContext->backend->assignDouble(
$tempVariable,
$resolvedExpr->getCode(),
$compilationContext
);
$compilationContext->symbolTable->mustGrownStack(true);
$compilationContext->headersManager->add('kernel/operators');
$codePrinter->output(
$functionName . '(' . $compilationContext->backend->getVariableCode(
$symbolVariable
) . ', ' . $compilationContext->backend->getVariableCode($tempVariable) . ');'
);
break;
case 'assign':
$this->processDoVariableAssignmentAssign(
$symbolVariable,
$readDetector,
$variable,
$resolvedExpr,
$compilationContext,
$codePrinter
);
break;
default:
throw new IllegalOperationException($statement, $resolvedExpr, $resolvedExpr->getOriginal());
}
break;
case 'bool':
switch ($statement['operator']) {
case 'assign':
$symbolVariable->setDynamicTypes('bool');
if ('true' == $resolvedExpr->getCode()) {
$symbolVariable->initVariant($compilationContext);
$compilationContext->backend->assignBool($symbolVariable, '1', $compilationContext);
} else {
if ('false' == $resolvedExpr->getCode()) {
$symbolVariable->initVariant($compilationContext);
$compilationContext->backend->assignBool($symbolVariable, '0', $compilationContext);
} else {
if ($readDetector->detect($variable, $resolvedExpr->getOriginal())) {
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite(
'double',
$compilationContext
);
$codePrinter->output(
$tempVariable->getName() . ' = ' . $resolvedExpr->getBooleanCode() . ';'
);
$symbolVariable->initVariant($compilationContext);
$compilationContext->backend->assignBool(
$symbolVariable,
$tempVariable,
$compilationContext
);
} else {
$symbolVariable->initVariant($compilationContext);
$compilationContext->backend->assignBool(
$symbolVariable,
$resolvedExpr->getBooleanCode(),
$compilationContext
);
}
}
}
break;
default:
throw new IllegalOperationException($statement, $resolvedExpr, $resolvedExpr->getOriginal());
}
break;
case 'string':
switch ($statement['operator']) {
case 'assign':
$symbolVariable->initVariant($compilationContext);
$symbolVariable->setDynamicTypes('string');
$compilationContext->backend->assignString(
$symbolVariable,
Name::addSlashes($resolvedExpr->getCode()),
$compilationContext
);
break;
case 'concat-assign':
$compilationContext->headersManager->add('kernel/operators');
$codePrinter->output(
'zephir_concat_self_str(&' . $variable . ', SL("' . $resolvedExpr->getCode() . '"));'
);
break;
default:
throw new IllegalOperationException($statement, $resolvedExpr, $resolvedExpr->getOriginal());
}
break;
case 'array':
$this->doArrayAssignmentProcess(
$statement,
$resolvedExpr,
$variable,
$symbolVariable,
$compilationContext,
$codePrinter
);
break;
case 'variable':
$itemVariable = $compilationContext->symbolTable->getVariableForRead(
$resolvedExpr->getCode(),
$compilationContext,
$resolvedExpr->getOriginal()
);
switch ($itemVariable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'char':
case 'uchar':
switch ($statement['operator']) {
case 'assign':
$symbolVariable->initVariant($compilationContext);
$symbolVariable->setDynamicTypes('long');
$compilationContext->backend->assignLong(
$symbolVariable,
$itemVariable,
$compilationContext
);
break;
case 'add-assign':
$compilationContext->headersManager->add('kernel/operators');
$symbolVariable->initVariant($compilationContext);
$symbolVariable->setDynamicTypes('long');
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite(
$itemVariable->getType(),
$compilationContext
);
$codePrinter->output(
$tempVariable->getName(
) . ' = zephir_get_numberval(' . $compilationContext->backend->getVariableCode(
$symbolVariable
) . ') + ' . $itemVariable->getName() . ';'
);
$compilationContext->backend->assignLong(
$symbolVariable,
$tempVariable,
$compilationContext
);
break;
case 'sub-assign':
$compilationContext->headersManager->add('kernel/operators');
$symbolVariable->initVariant($compilationContext);
$symbolVariable->setDynamicTypes('long');
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite(
$itemVariable->getType(),
$compilationContext
);
$codePrinter->output(
$tempVariable->getName(
) . ' = zephir_get_numberval(' . $compilationContext->backend->getVariableCode(
$symbolVariable
) . ');'
);
$compilationContext->backend->assignLong(
$symbolVariable,
$tempVariable->getName() . ' - ' . $itemVariable->getName(),
$compilationContext
);
break;
default:
throw new IllegalOperationException($statement, $itemVariable);
}
break;
case 'double':
switch ($statement['operator']) {
case 'assign':
$symbolVariable->initVariant($compilationContext);
$symbolVariable->setDynamicTypes('double');
$compilationContext->backend->assignDouble(
$symbolVariable,
$itemVariable,
$compilationContext
);
break;
default:
throw new IllegalOperationException($statement, $itemVariable);
}
break;
case 'bool':
switch ($statement['operator']) {
case 'assign':
$symbolVariable->initVariant($compilationContext);
$symbolVariable->setDynamicTypes('bool');
$compilationContext->backend->assignBool(
$symbolVariable,
$itemVariable,
$compilationContext
);
break;
default:
throw new IllegalOperationException($statement, $itemVariable);
}
break;
case 'array':
$this->doArrayAssignmentProcess(
$statement,
$resolvedExpr,
$variable,
$symbolVariable,
$compilationContext,
$codePrinter
);
break;
case 'variable':
switch ($statement['operator']) {
case 'assign':
$this->processDoVariableAssignmentVariableString(
$itemVariable,
$variable,
$symbolVariable,
$compilationContext
);
break;
case 'concat-assign':
$compilationContext->headersManager->add('kernel/operators');
$compilationContext->backend->concatSelf(
$symbolVariable,
$itemVariable,
$compilationContext
);
break;
case 'add-assign':
$compilationContext->symbolTable->mustGrownStack(true);
$compilationContext->headersManager->add('kernel/operators');
$codePrinter->output(
'ZEPHIR_ADD_ASSIGN(' . $compilationContext->backend->getVariableCode(
$symbolVariable
) . ', ' . $compilationContext->backend->getVariableCode($itemVariable) . ');'
);
break;
case 'sub-assign':
$compilationContext->symbolTable->mustGrownStack(true);
$compilationContext->headersManager->add('kernel/operators');
$codePrinter->output(
'ZEPHIR_SUB_ASSIGN(' . $compilationContext->backend->getVariableCode(
$symbolVariable
) . ', ' . $compilationContext->backend->getVariableCode($itemVariable) . ');'
);
break;
default:
throw new IllegalOperationException($statement, $itemVariable);
}
break;
case 'string':
switch ($statement['operator']) {
case 'assign':
$this->processDoVariableAssignmentVariableString(
$itemVariable,
$variable,
$symbolVariable,
$compilationContext
);
break;
case 'concat-assign':
$compilationContext->headersManager->add('kernel/operators');
$compilationContext->backend->concatSelf(
$symbolVariable,
$itemVariable,
$compilationContext
);
break;
default:
throw new IllegalOperationException($statement, $itemVariable);
}
break;
default:
throw new CompilerException(
'Unknown type: ' . $itemVariable->getType(),
$resolvedExpr->getOriginal()
);
}
break;
default:
throw new CompilerException('Unknown type: ' . $resolvedExpr->getType(), $resolvedExpr->getOriginal());
}
}
|
Performs variable assignment.
@throws CompilerException
@throws IllegalOperationException
|
doVariableAssignment
|
php
|
zephir-lang/zephir
|
src/Statements/Let/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Statements/Let/Variable.php
|
MIT
|
protected function wrapPHPValue(array $parameter): string
{
switch ($parameter['default']['type']) {
case 'null':
$returnValue = 'null';
break;
case 'string':
case 'char':
$returnValue = '\'' . addslashes($parameter['default']['value']) . '\'';
break;
case 'empty-array':
$returnValue = '[]';
break;
case 'array':
$parameters = [];
foreach ($parameter['default']['left'] as $value) {
$source = '';
if (isset($value['key'])) {
$source .= $this->wrapPHPValue([
'default' => $value['key'],
'type' => $value['key']['type'],
]) . ' => ';
}
$parameters[] = $source . $this->wrapPHPValue([
'default' => $value['value'],
'type' => $value['value']['type'],
]);
}
$returnValue = '[' . implode(', ', $parameters) . ']';
break;
case 'static-constant-access':
$returnValue = $parameter['default']['left']['value'] . '::' . $parameter['default']['right']['value'];
break;
case 'int':
case 'double':
case 'bool':
$returnValue = $parameter['default']['value'];
break;
default:
throw new Exception\LogicException(
sprintf(
'Stubs - value with type: %s is not supported',
$parameter['default']['type']
)
);
}
return (string)$returnValue;
}
|
Prepare AST default value to PHP code print.
@throws Exception\NotImplementedException
|
wrapPHPValue
|
php
|
zephir-lang/zephir
|
src/Stubs/Generator.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Stubs/Generator.php
|
MIT
|
protected function parseDocBlockParam(string $line): array
{
$pattern = '~
@(?P<doctype>param|return|var)\s+
(?P<type>[\\\\\w]+(:?\s*\|\s*[\\\\\w]+|\s*\[]+)*)\s*
(?P<dollar>\$)?
(?P<name>[a-z_][a-z0-9_]*)?\s*
(?P<description>(.|\s)*)?
~xi';
preg_match($pattern, $line, $matched);
return $matched;
}
|
Parse DocBlock and returns extracted groups.
|
parseDocBlockParam
|
php
|
zephir-lang/zephir
|
src/Stubs/MethodDocBlock.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Stubs/MethodDocBlock.php
|
MIT
|
public function invokeMethod(
string $methodName,
$caller,
CompilationContext $compilationContext,
Call $call,
array $expression
): CompiledExpression|bool {
/**
* Checks first whether the method exist in the array type definition
*/
if (method_exists($this, $methodName)) {
return $this->{$methodName}($caller, $compilationContext, $call, $expression);
}
/**
* Check the method map
*/
if (isset($this->methodMap[$methodName])) {
$paramNumber = $this->getNumberParam($methodName);
if (0 === $paramNumber) {
if (isset($expression['parameters'])) {
$parameters = $expression['parameters'];
array_unshift($parameters, ['parameter' => $caller]);
} else {
$parameters = [['parameter' => $caller]];
}
} else {
if (isset($expression['parameters'])) {
$parameters = [];
foreach ($expression['parameters'] as $number => $parameter) {
if ($number === $paramNumber) {
$parameters[] = null;
}
$parameters[] = $parameter;
}
$parameters[$paramNumber] = ['parameter' => $caller];
} else {
$parameters = [['parameter' => $caller]];
}
}
$functionCall = BuilderFactory::getInstance()->statements()
->functionCall($this->methodMap[$methodName], $parameters)
->setFile($expression['file'])
->setLine($expression['line'])
->setChar($expression['char'])
;
$expression = new Expression($functionCall->build());
return $expression->compile($compilationContext);
}
throw new CompilerException(
sprintf('Method "%s" is not a built-in method of type "%s"', $methodName, $this->getTypeName()),
$expression
);
}
|
Intercepts calls to built-in methods.
@throws Exception
@throws ReflectionException
|
invokeMethod
|
php
|
zephir-lang/zephir
|
src/Types/AbstractType.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/AbstractType.php
|
MIT
|
protected function getNumberParam(string $methodName): int
{
return 0;
}
|
Returns the number of the parameter where the object must be bound.
|
getNumberParam
|
php
|
zephir-lang/zephir
|
src/Types/AbstractType.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/AbstractType.php
|
MIT
|
public function join($caller, CompilationContext $compilationContext, Call $call, array $expression)
{
$functionCall = BuilderFactory::getInstance()->statements()
->functionCall('join', $expression['parameters'])
->addArgument($caller)
->setFile($expression['file'])
->setLine($expression['line'])
->setChar($expression['char'])
;
$expression = new Expression($functionCall->build());
return $expression->compile($compilationContext);
}
|
Transforms calls to method "join" to function calls to "join".
@param object $caller
@param CompilationContext $compilationContext
@param Call $call
@param array $expression
@return bool|CompiledExpression
@throws ReflectionException
@throws Exception
|
join
|
php
|
zephir-lang/zephir
|
src/Types/ArrayType.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/ArrayType.php
|
MIT
|
public function toHex($caller, CompilationContext $compilationContext, Call $call, array $expression)
{
$exprBuilder = BuilderFactory::getInstance();
$functionCall = $exprBuilder->statements()
->functionCall('zephir_string_to_hex', [$caller])
->setFile($expression['file'])
->setLine($expression['line'])
->setChar($expression['char'])
;
$expression = new Expression($functionCall->build());
return $expression->compile($compilationContext);
}
|
Transforms calls to method "toHex" to sprintf('%X') call.
@param object $caller
@param CompilationContext $compilationContext
@param Call $call
@param array $expression
@return bool|mixed|CompiledExpression
@throws ReflectionException
@throws Exception
|
toHex
|
php
|
zephir-lang/zephir
|
src/Types/CharType.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/CharType.php
|
MIT
|
public function getReturnTypeAnnotation(Method $method, ?array $returnTypes = null): string
{
if (!$method->hasReturnTypes() && !$method->isVoid()) {
return '';
}
$isProcessedReturnType = null !== $returnTypes;
$returnTypes ??= $method->getReturnTypes();
$typesCount = count($returnTypes);
$isDynamic = in_array('var', array_keys($returnTypes));
$isNullable = $this->isNullable($returnTypes);
$isBool = $this->areReturnTypesBoolCompatible($returnTypes);
$isNull = $this->areReturnTypesNullCompatible($returnTypes);
$isVoid = $this->areReturnTypesVoidCompatible($returnTypes);
$isArray = $this->areReturnTypesArrayCompatible($returnTypes);
$isDouble = $this->areReturnTypesFloatCompatible($returnTypes);
$isString = $this->areReturnTypesStringCompatible($returnTypes);
$isObject = $this->areReturnTypesObjectCompatible($returnTypes);
$isInteger = $this->areReturnTypesIntegerCompatible($returnTypes);
$isNumeric = $this->isNumeric($returnTypes);
$isIterable = $this->areReturnTypesIterableCompatible($returnTypes);
$isResource = $this->areReturnTypesResourceCompatible($returnTypes);
$isCollection = $this->areReturnTypesCollectionCompatible($returnTypes);
$isTypeHinted = $method->isReturnTypesHintDetermined();
$isBasicTypes = $isArray || $isBool || $isDouble || $isInteger || $isResource || $isString || $isVoid || $isNumeric;
$nullableType = $isNullable ? '|null' : '';
if ($method->isVoid() || $isVoid) {
return self::T_VOID;
}
if ($isInteger) {
return self::T_INT . $nullableType;
}
if ($isDouble) {
return self::T_FLOAT . $nullableType;
}
if ($isBool) {
return self::T_BOOL . $nullableType;
}
if ($isString) {
return self::T_STRING . $nullableType;
}
if ($isNull && 1 === $typesCount) {
return self::T_NULL;
}
if ($isArray) {
return self::T_ARRAY;
}
if ($isObject) {
return self::T_OBJECT;
}
if ($isIterable) {
return self::T_ITERABLE;
}
if ($isResource) {
return self::T_RESOURCE;
}
if ($method->areReturnTypesCompatible() && !$isTypeHinted) {
return self::T_MIXED . $nullableType;
}
if ($isTypeHinted && !$isBasicTypes && !$isDynamic && !$isNullable) {
return implode('|', array_keys($returnTypes));
}
if ($isTypeHinted && $isProcessedReturnType) {
$withoutNullable = array_filter(array_keys($returnTypes), static function ($ret) {
if ($ret !== self::T_NULL) {
return $ret;
}
});
return implode('|', array_values($withoutNullable)) . $nullableType;
}
if ($isCollection) {
return implode('|', array_values($returnTypes));
}
return self::T_MIXED . $nullableType;
}
|
Gets PHP compatible return type from class method.
|
getReturnTypeAnnotation
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesArrayCompatible(array $types): bool
{
return $this->areReturnTypesCompatible($types, [self::T_ARRAY]);
}
|
Match Zephir types with Array type.
|
areReturnTypesArrayCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesBoolCompatible(array $types): bool
{
return $this->areReturnTypesCompatible($types, [self::T_BOOL, self::T_BOOLEAN]);
}
|
Match Zephir types with Boolean type.
|
areReturnTypesBoolCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesCompatible(array $types, array $allowedTypes, bool $isNullable = false): bool
{
$result = null;
if ($isNullable) {
$allowedTypes[] = self::T_NULL;
}
foreach ($types as $type => $data) {
$areEquals = in_array($type, $allowedTypes);
$result = isset($result)
? ($areEquals && $result)
: $areEquals;
}
return $result ?? false;
}
|
Match if return types from Zephir are compatible
with allowed return types from PHP.
Examples:
$types = [
'variable' => [
'type' => 'return-type-parameter',
'data-type' => 'variable',
'mandatory' => 0,
'file' => '../path-to-file/stubs.zep',
'line' => 21,
'char' => 48,
]
]
|
areReturnTypesCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesFloatCompatible(array $types): bool
{
return $this->areReturnTypesCompatible(
$types,
[
self::T_FLOAT,
self::T_DOUBLE,
]
);
}
|
Match Zephir types with Float type.
|
areReturnTypesFloatCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesIntegerCompatible(array $types): bool
{
return $this->areReturnTypesCompatible(
$types,
[
self::T_INT,
self::T_INTEGER,
self::T_UINT,
self::T_CHAR,
self::T_UCHAR,
self::T_LONG,
self::T_ULONG,
]
);
}
|
Match Zephir types with Integer type.
|
areReturnTypesIntegerCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesIterableCompatible(array $types): bool
{
return $this->areReturnTypesCompatible($types, [self::T_ITERABLE]);
}
|
Match Zephir types with Iterable type.
|
areReturnTypesIterableCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesNullCompatible(array $types): bool
{
return $this->areReturnTypesCompatible($types, [self::T_NULL]);
}
|
Match Zephir types with Null type.
|
areReturnTypesNullCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesObjectCompatible(array $types): bool
{
return $this->areReturnTypesCompatible($types, [self::T_OBJECT]);
}
|
Match Zephir types with Object type.
|
areReturnTypesObjectCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesResourceCompatible(array $types): bool
{
return $this->areReturnTypesCompatible($types, [self::T_RESOURCE]);
}
|
Match Zephir types with Resource type.
|
areReturnTypesResourceCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesStringCompatible(array $types): bool
{
return $this->areReturnTypesCompatible(
$types,
[
self::T_STRING,
self::T_ISTRING,
],
$this->isNullable($types)
);
}
|
Match Zephir types with String type.
|
areReturnTypesStringCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function areReturnTypesVoidCompatible(array $types): bool
{
return $this->areReturnTypesCompatible($types, [self::T_VOID]);
}
|
Match Zephir types with Void type.
|
areReturnTypesVoidCompatible
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function isNullable(array $types): bool
{
return (array_key_exists(self::T_NULL, $types)
|| in_array(self::T_NULL, $types))
&& 1 !== count($types);
}
|
Check if Zephir types can be Nullable.
|
isNullable
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
private function isNumeric(array $types): bool
{
return $this->areReturnTypesCompatible($types, [self::T_NUMBER]);
}
|
Check if Zephir types is a Numeric type compatible.
|
isNumeric
|
php
|
zephir-lang/zephir
|
src/Types/Types.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Types/Types.php
|
MIT
|
public function isSuperGlobal(string $name): bool
{
return in_array($name, $this->superGlobals, true);
}
|
Checks if a variable is a super global.
|
isSuperGlobal
|
php
|
zephir-lang/zephir
|
src/Variable/Globals.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Globals.php
|
MIT
|
public function enableDefaultAutoInitValue(): void
{
switch ($this->type) {
case 'char':
case 'boolean':
case 'bool':
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
case 'zephir_ce_guard':
$this->defaultInitValue = 0;
break;
case 'variable':
case 'string':
case 'array':
$this->defaultInitValue = null;
$this->setDynamicTypes('null');
$this->setMustInitNull(true);
$this->setLocalOnly(false);
break;
default:
throw new CompilerException(
'Cannot create an automatic safe default value for variable type: ' . $this->type
);
}
}
|
Sets an automatic safe default init value according to its type.
|
enableDefaultAutoInitValue
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getAssociatedClass(): Definition | ReflectionClass | null
{
return $this->associatedClass;
}
|
Returns the class related to the variable.
|
getAssociatedClass
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getBranch(): ?Branch
{
return $this->branch;
}
|
Get the branch where the variable was declared.
|
getBranch
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getClassTypes(): array
{
return $this->classTypes;
}
|
Returns the PHP classes associated to the variable.
|
getClassTypes
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getDynamicTypes(): array
{
return $this->dynamicTypes;
}
|
Returns the current dynamic type in a polymorphic variable.
|
getDynamicTypes
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getInitBranches(): array
{
return $this->initBranches;
}
|
Get init marked branch.
@return Branch[]
|
getInitBranches
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getLastUsedNode(): ?array
{
return $this->usedNode;
}
|
Returns the last node where the variable was assigned or used.
|
getLastUsedNode
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getNumberMutations(): int
{
return $this->numberMutates;
}
|
Returns the number of mutations performed over the variable.
|
getNumberMutations
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getOriginal(): array
{
if ($this->node) {
return $this->node;
}
return ['file' => 'unknown', 'line' => 0, 'char' => 0];
}
|
Returns the original AST node where the variable was declared.
|
getOriginal
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getPossibleValue(): mixed
{
return $this->possibleValue;
}
|
Returns the latest CompiledExpression assigned to a variable.
|
getPossibleValue
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getPossibleValueBranch(): ?Branch
{
return $this->possibleValueBranch;
}
|
Returns the branch where the variable was assigned for the last time.
|
getPossibleValueBranch
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getSkipVariant(): int
{
return $this->numberSkips;
}
|
Get the number of initializations remaining to skip.
|
getSkipVariant
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function getVariantInits(): int
{
return $this->variantInits;
}
|
Get the number of times the variable has been initialized.
|
getVariantInits
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function hasAnyDynamicType(array | string $types): bool
{
if (is_string($types)) {
$types = [$types];
}
foreach ($types as $type) {
if (isset($this->dynamicTypes[$type])) {
return true;
}
}
return false;
}
|
Checks if the variable has any of the passed dynamic.
|
hasAnyDynamicType
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function hasDifferentDynamicType(array $types): bool
{
$number = 0;
foreach ($types as $type) {
if (isset($this->dynamicTypes[$type])) {
++$number;
}
}
return 0 === $number;
}
|
Check if the variable has at least one dynamic type to the ones passed in the list.
|
hasDifferentDynamicType
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function increaseMutates(): void
{
++$this->numberMutates;
}
|
Increase the number of mutations a variable may have.
|
increaseMutates
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function increaseUses(): void
{
++$this->numberUses;
}
|
Increase the number of uses a variable may have.
|
increaseUses
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function increaseVariantIfNull(): void
{
++$this->variantInits;
}
|
Increase the number of times the variable has been initialized.
|
increaseVariantIfNull
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function initComplexLiteralVariant(CompilationContext $compilationContext): void
{
if ($this->numberSkips) {
--$this->numberSkips;
return;
}
if (self::VAR_THIS_POINTER != $this->getName() && self::VAR_RETURN_VALUE != $this->getName()) {
if (!$this->initBranch) {
$this->initBranch = $compilationContext->currentBranch === 0;
}
$compilationContext->headersManager->add('kernel/memory');
$compilationContext->symbolTable->mustGrownStack(true);
if (!$this->isLocalOnly()) {
if ($this->variantInits > 0 || $compilationContext->insideCycle) {
$this->mustInitNull = true;
$compilationContext->codePrinter->output('ZEPHIR_INIT_NVAR(&' . $this->getName() . ');');
} else {
$compilationContext->backend->initVar($this, $compilationContext);
}
} else {
if ($this->variantInits > 0 || $compilationContext->insideCycle) {
$this->mustInitNull = true;
$compilationContext->codePrinter->output('ZEPHIR_INIT_NVAR(&' . $this->getName() . ');');
} else {
$compilationContext->codePrinter->output('ZEPHIR_INIT_VAR(&' . $this->getName() . ');');
}
}
++$this->variantInits;
}
}
|
Initializes a variant variable that is intended to have the special
behavior of only freed its body value instead of the full variable.
|
initComplexLiteralVariant
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function initNonReferenced(CompilationContext $compilationContext): void
{
$compilationContext->codePrinter->output('ZVAL_UNDEF(&' . $this->getName() . ');');
}
|
Allocate memory for variable and init it null val
|
initNonReferenced
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isExternal(): bool
{
return $this->isExternal;
}
|
Check if the variable is a parameter.
|
isExternal
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isIdle(): bool
{
return $this->idle;
}
|
Checks if the variable is idle.
|
isIdle
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isInitialized(): bool
{
return $this->initialized;
}
|
Check if the variable is initialized or not.
|
isInitialized
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isLocalOnly(): bool
{
return $this->localOnly;
}
|
Checks if the variable is local-only scoped.
|
isLocalOnly
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isLocalStatic(): bool
{
return $this->isExternal && $this->localOnly;
}
|
Checks if a variable is a local static.
|
isLocalStatic
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isMemoryTracked(): bool
{
return $this->memoryTracked;
}
|
Checks if the variable is tracked by the memory manager.
|
isMemoryTracked
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isNotVariable(): bool
{
return !$this->isVariable();
}
|
Shortcut is type variable or string?
|
isNotVariable
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isNotVariableAndArray(): bool
{
return !$this->isVariable() && !$this->isArray();
}
|
Shortcut is type variable or array?
|
isNotVariableAndArray
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isNotVariableAndMixedAndString(): bool
{
return !$this->isVariable() && !$this->isMixed() && !$this->isString();
}
|
Shortcut is type variable or mixed or string?
|
isNotVariableAndMixedAndString
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isNotVariableAndString(): bool
{
return !$this->isVariable() && !$this->isString();
}
|
Shortcut is type variable or string?
|
isNotVariableAndString
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isReadOnly(): bool
{
return $this->readOnly;
}
|
Returns if the variable is read only.
|
isReadOnly
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isReusable(): bool
{
return $this->reusable;
}
|
Checks if the temporary variable is reusable.
|
isReusable
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isSuperGlobal(): bool
{
return $this->isExternal && $this->globalsManager->isSuperGlobal($this->name);
}
|
Checks if a variable is a super global.
|
isSuperGlobal
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isTemporal(): bool
{
return $this->temporal;
}
|
Returns whether the variable is temporal or not.
|
isTemporal
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function isUsed(): bool
{
return $this->used;
}
|
Checks whether the last value assigned was used.
|
isUsed
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function mustInitNull(): bool
{
return $this->mustInitNull;
}
|
Get if the variable must be initialized to null.
|
mustInitNull
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function observeOrNullifyVariant(CompilationContext $compilationContext): void
{
if ($this->numberSkips) {
--$this->numberSkips;
return;
}
if (in_array($this->getName(), [self::VAR_THIS_POINTER, self::VAR_RETURN_VALUE], true)) {
return;
}
if (!$this->initBranch) {
$this->initBranch = $compilationContext->currentBranch === 0;
}
$compilationContext->headersManager->add('kernel/memory');
$compilationContext->symbolTable->mustGrownStack(true);
if ($this->variantInits > 0 || $compilationContext->insideCycle) {
$this->mustInitNull = true;
}
++$this->variantInits;
$this->setMustInitNull(true);
}
|
Observes a variable in the memory frame without initialization or nullify
an existing allocated variable.
|
observeOrNullifyVariant
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function observeVariant(CompilationContext $compilationContext): void
{
if ($this->numberSkips) {
--$this->numberSkips;
return;
}
$name = $this->getName();
if (self::VAR_THIS_POINTER != $name && self::VAR_RETURN_VALUE != $name) {
if (!$this->initBranch) {
$this->initBranch = $compilationContext->currentBranch === 0;
}
$compilationContext->headersManager->add('kernel/memory');
$compilationContext->symbolTable->mustGrownStack(true);
$symbol = $compilationContext->backend->getVariableCode($this);
if ($this->variantInits > 0 || $compilationContext->insideCycle) {
$this->mustInitNull = true;
$compilationContext->codePrinter->output('ZEPHIR_OBS_NVAR(' . $symbol . ');');
} else {
$compilationContext->codePrinter->output('zephir_memory_observe(' . $symbol . ');');
}
++$this->variantInits;
}
}
|
Observes a variable in the memory frame without initialization.
|
observeVariant
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setAssociatedClass(ReflectionClass | Definition $associatedClass): void
{
$this->associatedClass = $associatedClass;
}
|
Sets the PHP class related to variable.
|
setAssociatedClass
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setClassTypes(array | string $classTypes): void
{
if (is_string($classTypes)) {
if (!in_array($classTypes, $this->classTypes)) {
$this->classTypes[] = $classTypes;
}
return;
}
foreach ($classTypes as $classType) {
if (!in_array($classType, $this->classTypes)) {
$this->classTypes[] = $classType;
}
}
}
|
Sets the PHP class related to variable.
|
setClassTypes
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setDynamicTypes(array | string $types): void
{
unset($this->dynamicTypes['unknown']);
if (is_string($types)) {
$types = [$types];
}
foreach ($types as $type) {
if (!isset($this->dynamicTypes[$type])) {
$this->dynamicTypes[$type] = true;
}
}
}
|
Sets the current dynamic type in a polymorphic variable.
|
setDynamicTypes
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setIdle(bool $idle): void
{
$this->idle = false;
if ($this->reusable) {
$this->classTypes = [];
$this->dynamicTypes = ['unknown' => true];
$this->idle = $idle;
}
}
|
Once a temporal variable is unused in a specific branch it is marked as idle.
|
setIdle
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setIsDoublePointer(bool $doublePointer): void
{
$this->doublePointer = $doublePointer;
}
|
Marks the variable to be defined as a double pointer.
|
setIsDoublePointer
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setIsExternal(bool $isExternal): void
{
$this->isExternal = $isExternal;
$this->variantInits = 1;
}
|
Set if the symbol is a parameter of the method or not.
|
setIsExternal
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setIsInitialized(bool $initialized, CompilationContext $compilationContext): void
{
$this->initialized = $initialized;
if (!$initialized || !$compilationContext->branchManager instanceof BranchManager) {
return;
}
$currentBranch = $compilationContext->branchManager->getCurrentBranch();
if ($currentBranch instanceof Branch) {
$this->initBranches[] = $currentBranch;
}
}
|
Sets if the variable is initialized
This allow to throw an exception if the variable is being read without prior initialization.
|
setIsInitialized
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setLocalOnly(bool $localOnly): void
{
$this->localOnly = $localOnly;
}
|
Sets if the variable is local-only scoped.
|
setLocalOnly
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setMemoryTracked(bool $memoryTracked): void
{
$this->memoryTracked = $memoryTracked;
}
|
Sets if the variable is not tracked by the memory manager.
|
setMemoryTracked
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setMustInitNull(bool $mustInitNull): void
{
$this->mustInitNull = $mustInitNull;
}
|
Set if the variable must be initialized to null.
|
setMustInitNull
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setOriginal(array $node): void
{
$this->node = $node;
}
|
Set the original AST node where the variable was declared.
|
setOriginal
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setPossibleValue(
CompiledExpression $possibleValue,
CompilationContext $compilationContext,
): void {
$this->possibleValue = $possibleValue;
$this->possibleValueBranch = $compilationContext->branchManager->getCurrentBranch();
}
|
Sets the latest CompiledExpression assigned to a variable.
|
setPossibleValue
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setReadOnly(bool $readOnly): void
{
$this->readOnly = $readOnly;
}
|
Sets if the variable is read only.
|
setReadOnly
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setReusable(bool $reusable): void
{
$this->reusable = $reusable;
}
|
Some temporary variables can't be reused.
|
setReusable
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setTemporal(bool $temporal): void
{
$this->temporal = $temporal;
}
|
Sets whether the variable is temporal or not.
|
setTemporal
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function setUsed(bool $used, ?array $node = null): void
{
$this->used = $used;
$this->usedNode = $node;
}
|
Sets the latest node where a variable was used.
|
setUsed
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function trackVariant(CompilationContext $compilationContext): void
{
if ($this->numberSkips) {
--$this->numberSkips;
return;
}
/**
* Variables are allocated for the first time using ZEPHIR_INIT_VAR
* the second, third, etc. times are allocated using ZEPHIR_INIT_NVAR
* Variables initialized for the first time in a cycle are always initialized using ZEPHIR_INIT_NVAR
*/
if (self::VAR_THIS_POINTER !== $this->getName() && self::VAR_RETURN_VALUE !== $this->getName()) {
if (!$this->initBranch) {
$this->initBranch = $compilationContext->currentBranch === 0;
}
if (!$this->isLocalOnly()) {
$compilationContext->symbolTable->mustGrownStack(true);
if ($compilationContext->insideCycle) {
$this->mustInitNull = true;
} else {
if ($this->variantInits > 0) {
if (!$this->initBranch) {
$this->mustInitNull = true;
}
}
}
} else {
if ($this->variantInits > 0 || $compilationContext->insideCycle) {
$this->mustInitNull = true;
}
}
++$this->variantInits;
}
}
|
Tells the compiler a generated code will track the variable.
|
trackVariant
|
php
|
zephir-lang/zephir
|
src/Variable/Variable.php
|
https://github.com/zephir-lang/zephir/blob/master/src/Variable/Variable.php
|
MIT
|
public function testIssue645(): void
{
$class = new \Stub\ArrayAccessTest();
$this->assertSame([], $class->issue645());
}
|
@issue https://github.com/zephir-lang/zephir/issues/645
|
testIssue645
|
php
|
zephir-lang/zephir
|
tests/Extension/ArrayAccessTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ArrayAccessTest.php
|
MIT
|
public function testIssue1155(): void
{
$class = new \Stub\ArrayAccessTest();
$this->assertFalse($class->issue1155());
}
|
@issue https://github.com/zephir-lang/zephir/issues/1155
|
testIssue1155
|
php
|
zephir-lang/zephir
|
tests/Extension/ArrayAccessTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ArrayAccessTest.php
|
MIT
|
public function testIssue1086StaticallyCalledFunctionWithArrayAsArgMustReturnArray(): void
{
if (version_compare(PHP_VERSION, '8.2.0', '>=')) {
$this->markTestSkipped('Deprecated Callable Patterns');
}
$class = new \Stub\ArrayAccessTest();
$actual = $class->issue1086WontNullArrayAfterPassViaStaticWithStrictParams();
$this->assertSame(['test' => 123], $actual);
$actual = $class->issue1086WontNullArrayAfterPassViaStaticWithoutStrictParams();
$this->assertSame(['test' => 123], $actual);
}
|
@issue https://github.com/zephir-lang/zephir/issues/1086
|
testIssue1086StaticallyCalledFunctionWithArrayAsArgMustReturnArray
|
php
|
zephir-lang/zephir
|
tests/Extension/ArrayAccessTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ArrayAccessTest.php
|
MIT
|
public function testIssue1259CheckUnsetKeyFromArray(): void
{
$class = new \Stub\ArrayAccessTest();
$expected = [
['key_a' => 'marcin', 'key_b' => 'paula'],
['key_b' => 'paula'],
];
$this->assertSame($expected, $class->issue1259UnsetKeyFromArrayInternalVariable());
}
|
@issue https://github.com/zephir-lang/zephir/issues/1259
|
testIssue1259CheckUnsetKeyFromArray
|
php
|
zephir-lang/zephir
|
tests/Extension/ArrayAccessTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ArrayAccessTest.php
|
MIT
|
public function testIssue1259CheckUnsetStringKeyFromArrayProperty(): void
{
$class = new \Stub\ArrayAccessTest();
$this->assertSame(
[
$this->defaultUnsetData,
[
'key_b' => 'paula',
3 => 'long value',
],
],
$class->issue1259UnsetStringKeyFromArrayProperty()
);
}
|
@issue https://github.com/zephir-lang/zephir/issues/1259
|
testIssue1259CheckUnsetStringKeyFromArrayProperty
|
php
|
zephir-lang/zephir
|
tests/Extension/ArrayAccessTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ArrayAccessTest.php
|
MIT
|
public function testIssue1259CheckUnsetLongKeyFromArrayProperty(): void
{
$class = new \Stub\ArrayAccessTest();
$this->assertSame(
[
$this->defaultUnsetData,
[
'key_a' => 'marcin',
'key_b' => 'paula',
],
],
$class->issue1259UnsetLongKeyFromArrayProperty()
);
}
|
@issue https://github.com/zephir-lang/zephir/issues/1259
|
testIssue1259CheckUnsetLongKeyFromArrayProperty
|
php
|
zephir-lang/zephir
|
tests/Extension/ArrayAccessTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ArrayAccessTest.php
|
MIT
|
public function testIssue774(): void
{
$class = new ArrayManipulation();
$this->assertSame(['prop0' => 0, 'prop1' => 1], $class->issue774());
}
|
@issue https://github.com/zephir-lang/zephir/issues/774
|
testIssue774
|
php
|
zephir-lang/zephir
|
tests/Extension/ArrayManipulationTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ArrayManipulationTest.php
|
MIT
|
public function testShouldSearchInTheExternalArrayForAGivenValueAndReturnTheFirstCorrespondingKey(): void
{
$needle = 'value';
$haystack = ['.', '/', '0', '1', '2', '3', '4', 'value', 'OtherValue'];
$this->assertEquals(7, $this->test->simpleSearch($needle, $haystack));
}
|
@issue https://github.com/zephir-lang/zephir/issues/1609
|
testShouldSearchInTheExternalArrayForAGivenValueAndReturnTheFirstCorrespondingKey
|
php
|
zephir-lang/zephir
|
tests/Extension/ArraySearchTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ArraySearchTest.php
|
MIT
|
public function testShouldSearchInTheInternalArrayForAGivenValueAndReturnTheFirstCorrespondingKey(): void
{
$this->assertEquals(7, $this->test->searchUsingArrayInsideZephir());
}
|
@issue https://github.com/zephir-lang/zephir/issues/1609
|
testShouldSearchInTheInternalArrayForAGivenValueAndReturnTheFirstCorrespondingKey
|
php
|
zephir-lang/zephir
|
tests/Extension/ArraySearchTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ArraySearchTest.php
|
MIT
|
public function testShouldPerformAssignment($expected, $test, $testParams = null): void
{
$this->assertSame($expected, \call_user_func([$this->test, $test], $testParams));
}
|
@dataProvider variableAssignProvider
@param mixed $expected
@param string $test
@param mixed $testParams
|
testShouldPerformAssignment
|
php
|
zephir-lang/zephir
|
tests/Extension/AssignTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/AssignTest.php
|
MIT
|
public function testShouldPerformAssignmentForProperties($expected, $test, $testParams = null): void
{
if ('array' === \gettype($testParams)) {
$this->assertSame($expected, \call_user_func_array([$this->test, $test], $testParams));
} else {
$this->assertSame($expected, \call_user_func([$this->test, $test], $testParams));
}
}
|
@dataProvider propertyAssignProvider
@param mixed $expected
@param string $test
@param mixed $testParams
|
testShouldPerformAssignmentForProperties
|
php
|
zephir-lang/zephir
|
tests/Extension/AssignTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/AssignTest.php
|
MIT
|
public function testCharCast(): void
{
/**
* Value
*/
$this->assertSame(97, $this->test->testCharCastFromChar());
/**
* Variable types
*/
$this->assertSame(65, $this->test->testCharCastFromVariableChar());
}
|
@see https://github.com/zephir-lang/zephir/issues/1988
|
testCharCast
|
php
|
zephir-lang/zephir
|
tests/Extension/CastTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/CastTest.php
|
MIT
|
public function testStringCast(): void
{
/**
* Value
*/
$this->assertSame('z', $this->test->testStringCastChar());
/**
* Variable types
*/
$this->assertSame('X', $this->test->testStringCastVariableChar());
/**
* Null
*/
$this->assertSame('', $this->test->testStringCastFromNull());
}
|
@issue https://github.com/zephir-lang/zephir/issues/1988
|
testStringCast
|
php
|
zephir-lang/zephir
|
tests/Extension/CastTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/CastTest.php
|
MIT
|
public function testLongCast(): void
{
/**
* Value
*/
$this->assertSame(97, $this->test->testLongCastFromChar());
/**
* Variable types
*/
$this->assertSame(65, $this->test->testLongCastFromVariableChar());
}
|
@issue https://github.com/zephir-lang/zephir/issues/1988
|
testLongCast
|
php
|
zephir-lang/zephir
|
tests/Extension/CastTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/CastTest.php
|
MIT
|
public function testDoubleCast(): void
{
/**
* Value
*/
$this->assertSame(97.0, $this->test->testDoubleCastFromVChar());
/**
* Variable types
*/
$this->assertSame(65.0, $this->test->testDoubleCastFromVariableChar());
}
|
@issue https://github.com/zephir-lang/zephir/issues/1988
|
testDoubleCast
|
php
|
zephir-lang/zephir
|
tests/Extension/CastTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/CastTest.php
|
MIT
|
public function testIssue1036(): void
{
$test = new Closures();
$test->issue1036SetArgument(true);
$test->issue1036SetFunction(fn ($argument) => $argument);
$this->assertTrue($test->issue1036Call());
}
|
@issue https://github.com/zephir-lang/zephir/issues/1036
|
testIssue1036
|
php
|
zephir-lang/zephir
|
tests/Extension/ClosureTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ClosureTest.php
|
MIT
|
public function testShouldConcatenateStringsSimilarToIntegersNumbers(): void
{
$this->assertSame('21', $this->test->testConcat3());
}
|
@issue https://github.com/zephir-lang/zephir/issues/1573
|
testShouldConcatenateStringsSimilarToIntegersNumbers
|
php
|
zephir-lang/zephir
|
tests/Extension/ConcatTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ConcatTest.php
|
MIT
|
public function testShouldConcatenateStringWithVarDouble(): void
{
$this->assertSame(
'SELECT * FROM TEST WHERE value <= 946.5 AND value >= 473.25',
$this->test->testConcat4(1893)
);
}
|
@issue https://github.com/zephir-lang/zephir/issues/1893
|
testShouldConcatenateStringWithVarDouble
|
php
|
zephir-lang/zephir
|
tests/Extension/ConcatTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ConcatTest.php
|
MIT
|
public function testShouldConcatenateStringWithDouble(): void
{
$this->assertSame(
'Concatenated string with number 18.93000001',
$this->test->testConcat5(18.93000001)
);
}
|
@issue https://github.com/zephir-lang/zephir/issues/1893
|
testShouldConcatenateStringWithDouble
|
php
|
zephir-lang/zephir
|
tests/Extension/ConcatTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ConcatTest.php
|
MIT
|
public function testStringDelimiterAsConstDoubleQuoted(): void
{
$this->assertSame($this->test->testStringDelimiterConstantDoubleQuoted(), self::EXPECTED_DOUBLE_DELIMITER);
}
|
@issue https://github.com/zephir-lang/zephir/issues/1571
|
testStringDelimiterAsConstDoubleQuoted
|
php
|
zephir-lang/zephir
|
tests/Extension/ConstantsTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ConstantsTest.php
|
MIT
|
public function directiveProvider(): array
{
return [
['Test Extension => enabled', true],
['Test Extension support => Value', true],
['Test variable => Value', true],
['extension.test_ini_variable => On => On', true],
['ini-entry.my_setting_1', true],
['stub.db.my_setting_1', true],
['stub.orm.cache_enable', true],
['stub.test.my_setting_1', false],
['stub.test.test_setting_1', false],
['stub.test.', false],
];
}
|
@see config.json for Directive keys
@return array
|
directiveProvider
|
php
|
zephir-lang/zephir
|
tests/Extension/ExtensionInfoTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ExtensionInfoTest.php
|
MIT
|
public function testShouldBeWithoutDuplicatesNamespace(string $var, bool $contains): void
{
ob_start();
phpinfo(INFO_MODULES);
$phpinfo = ob_get_contents();
ob_end_clean();
if ($contains) {
$this->assertStringContainsString($var, $phpinfo);
} else {
$this->assertStringNotContainsString($var, $phpinfo);
}
}
|
@dataProvider directiveProvider()
@param string $var
@param bool $contains
|
testShouldBeWithoutDuplicatesNamespace
|
php
|
zephir-lang/zephir
|
tests/Extension/ExtensionInfoTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/ExtensionInfoTest.php
|
MIT
|
public function testFunctionGetArgs($param1, $param2): void
{
$this->assertSame([$param1, $param2], $this->test->testFunctionGetArgs($param1, $param2));
}
|
@dataProvider getArgsDataProvider
@param mixed $param1
@param mixed $param2
|
testFunctionGetArgs
|
php
|
zephir-lang/zephir
|
tests/Extension/FcallTest.php
|
https://github.com/zephir-lang/zephir/blob/master/tests/Extension/FcallTest.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.