repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
phalcon/zephir | Library/SymbolTable.php | SymbolTable.getVariableForWrite | public function getVariableForWrite($name, CompilationContext $compilationContext, array $statement = null)
{
/*
* Create superglobals just in time
*/
if ($this->globalsManager->isSuperGlobal($name)) {
if (!$this->hasVariable($name)) {
/**
* @TODO, injecting globals, initialize to null and check first?
*/
$superVar = new Variable('variable', $name, $compilationContext->branchManager->getCurrentBranch());
$superVar->setIsInitialized(true, $compilationContext);
$superVar->setDynamicTypes('array');
$superVar->increaseMutates();
$superVar->increaseUses();
$superVar->setIsExternal(true);
$superVar->setUsed(true, $statement);
$this->addRawVariable($superVar);
return $superVar;
}
}
if (!$this->hasVariable($name)) {
throw new CompilerException("Cannot mutate variable '".$name."' because it wasn't defined", $statement);
}
$variable = $this->getVariable($name);
$variable->increaseUses();
$variable->increaseMutates();
/*
* Saves the last place where the variable was mutated
* We discard mutations inside loops because iterations could use the value
* and Zephir only provides top-down compilation
*/
if (!$compilationContext->insideCycle) {
$variable->setUsed(false, $statement);
} else {
$variable->setUsed(true, $statement);
}
return $variable;
} | php | public function getVariableForWrite($name, CompilationContext $compilationContext, array $statement = null)
{
/*
* Create superglobals just in time
*/
if ($this->globalsManager->isSuperGlobal($name)) {
if (!$this->hasVariable($name)) {
/**
* @TODO, injecting globals, initialize to null and check first?
*/
$superVar = new Variable('variable', $name, $compilationContext->branchManager->getCurrentBranch());
$superVar->setIsInitialized(true, $compilationContext);
$superVar->setDynamicTypes('array');
$superVar->increaseMutates();
$superVar->increaseUses();
$superVar->setIsExternal(true);
$superVar->setUsed(true, $statement);
$this->addRawVariable($superVar);
return $superVar;
}
}
if (!$this->hasVariable($name)) {
throw new CompilerException("Cannot mutate variable '".$name."' because it wasn't defined", $statement);
}
$variable = $this->getVariable($name);
$variable->increaseUses();
$variable->increaseMutates();
/*
* Saves the last place where the variable was mutated
* We discard mutations inside loops because iterations could use the value
* and Zephir only provides top-down compilation
*/
if (!$compilationContext->insideCycle) {
$variable->setUsed(false, $statement);
} else {
$variable->setUsed(true, $statement);
}
return $variable;
} | [
"public",
"function",
"getVariableForWrite",
"(",
"$",
"name",
",",
"CompilationContext",
"$",
"compilationContext",
",",
"array",
"$",
"statement",
"=",
"null",
")",
"{",
"/*\n * Create superglobals just in time\n */",
"if",
"(",
"$",
"this",
"->",
"globalsManager",
"->",
"isSuperGlobal",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasVariable",
"(",
"$",
"name",
")",
")",
"{",
"/**\n * @TODO, injecting globals, initialize to null and check first?\n */",
"$",
"superVar",
"=",
"new",
"Variable",
"(",
"'variable'",
",",
"$",
"name",
",",
"$",
"compilationContext",
"->",
"branchManager",
"->",
"getCurrentBranch",
"(",
")",
")",
";",
"$",
"superVar",
"->",
"setIsInitialized",
"(",
"true",
",",
"$",
"compilationContext",
")",
";",
"$",
"superVar",
"->",
"setDynamicTypes",
"(",
"'array'",
")",
";",
"$",
"superVar",
"->",
"increaseMutates",
"(",
")",
";",
"$",
"superVar",
"->",
"increaseUses",
"(",
")",
";",
"$",
"superVar",
"->",
"setIsExternal",
"(",
"true",
")",
";",
"$",
"superVar",
"->",
"setUsed",
"(",
"true",
",",
"$",
"statement",
")",
";",
"$",
"this",
"->",
"addRawVariable",
"(",
"$",
"superVar",
")",
";",
"return",
"$",
"superVar",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasVariable",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"\"Cannot mutate variable '\"",
".",
"$",
"name",
".",
"\"' because it wasn't defined\"",
",",
"$",
"statement",
")",
";",
"}",
"$",
"variable",
"=",
"$",
"this",
"->",
"getVariable",
"(",
"$",
"name",
")",
";",
"$",
"variable",
"->",
"increaseUses",
"(",
")",
";",
"$",
"variable",
"->",
"increaseMutates",
"(",
")",
";",
"/*\n * Saves the last place where the variable was mutated\n * We discard mutations inside loops because iterations could use the value\n * and Zephir only provides top-down compilation\n */",
"if",
"(",
"!",
"$",
"compilationContext",
"->",
"insideCycle",
")",
"{",
"$",
"variable",
"->",
"setUsed",
"(",
"false",
",",
"$",
"statement",
")",
";",
"}",
"else",
"{",
"$",
"variable",
"->",
"setUsed",
"(",
"true",
",",
"$",
"statement",
")",
";",
"}",
"return",
"$",
"variable",
";",
"}"
] | Return a variable in the symbol table, it will be used for a write operation
Some variables aren't writable themselves but their members do.
@param string $name
@param CompilationContext $compilationContext
@param array $statement
@throws CompilerException
@return bool|\Zephir\Variable | [
"Return",
"a",
"variable",
"in",
"the",
"symbol",
"table",
"it",
"will",
"be",
"used",
"for",
"a",
"write",
"operation",
"Some",
"variables",
"aren",
"t",
"writable",
"themselves",
"but",
"their",
"members",
"do",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/SymbolTable.php#L438-L481 | train |
phalcon/zephir | Library/SymbolTable.php | SymbolTable.getTempVariable | public function getTempVariable($type, CompilationContext $compilationContext)
{
$compilationContext = $compilationContext ?: $this->compilationContext;
$tempVar = $this->getNextTempVar();
$variable = $this->addVariable($type, '_'.$tempVar, $compilationContext);
$variable->setTemporal(true);
return $variable;
} | php | public function getTempVariable($type, CompilationContext $compilationContext)
{
$compilationContext = $compilationContext ?: $this->compilationContext;
$tempVar = $this->getNextTempVar();
$variable = $this->addVariable($type, '_'.$tempVar, $compilationContext);
$variable->setTemporal(true);
return $variable;
} | [
"public",
"function",
"getTempVariable",
"(",
"$",
"type",
",",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"$",
"compilationContext",
"=",
"$",
"compilationContext",
"?",
":",
"$",
"this",
"->",
"compilationContext",
";",
"$",
"tempVar",
"=",
"$",
"this",
"->",
"getNextTempVar",
"(",
")",
";",
"$",
"variable",
"=",
"$",
"this",
"->",
"addVariable",
"(",
"$",
"type",
",",
"'_'",
".",
"$",
"tempVar",
",",
"$",
"compilationContext",
")",
";",
"$",
"variable",
"->",
"setTemporal",
"(",
"true",
")",
";",
"return",
"$",
"variable",
";",
"}"
] | Returns a temporal variable.
@param string $type
@param CompilationContext $compilationContext
@return Variable | [
"Returns",
"a",
"temporal",
"variable",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/SymbolTable.php#L572-L581 | train |
phalcon/zephir | Library/SymbolTable.php | SymbolTable.getTempVariableForWrite | public function getTempVariableForWrite($type, CompilationContext $context, $init = true)
{
$variable = $this->reuseTempVariable($type, 'heap');
if (\is_object($variable)) {
$variable->increaseUses();
$variable->increaseMutates();
if ($init && ('variable' == $type || 'string' == $type || 'array' == $type)) {
$variable->initVariant($context);
}
return $variable;
}
$tempVar = $this->getNextTempVar();
$variable = $this->addVariable($type, '_'.$tempVar, $context);
$variable->setIsInitialized(true, $context);
$variable->setTemporal(true);
$variable->increaseUses();
$variable->increaseMutates();
if ('variable' == $type || 'string' == $type || 'array' == $type) {
$variable->initVariant($context);
}
$this->registerTempVariable($type, 'heap', $variable);
return $variable;
} | php | public function getTempVariableForWrite($type, CompilationContext $context, $init = true)
{
$variable = $this->reuseTempVariable($type, 'heap');
if (\is_object($variable)) {
$variable->increaseUses();
$variable->increaseMutates();
if ($init && ('variable' == $type || 'string' == $type || 'array' == $type)) {
$variable->initVariant($context);
}
return $variable;
}
$tempVar = $this->getNextTempVar();
$variable = $this->addVariable($type, '_'.$tempVar, $context);
$variable->setIsInitialized(true, $context);
$variable->setTemporal(true);
$variable->increaseUses();
$variable->increaseMutates();
if ('variable' == $type || 'string' == $type || 'array' == $type) {
$variable->initVariant($context);
}
$this->registerTempVariable($type, 'heap', $variable);
return $variable;
} | [
"public",
"function",
"getTempVariableForWrite",
"(",
"$",
"type",
",",
"CompilationContext",
"$",
"context",
",",
"$",
"init",
"=",
"true",
")",
"{",
"$",
"variable",
"=",
"$",
"this",
"->",
"reuseTempVariable",
"(",
"$",
"type",
",",
"'heap'",
")",
";",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"variable",
")",
")",
"{",
"$",
"variable",
"->",
"increaseUses",
"(",
")",
";",
"$",
"variable",
"->",
"increaseMutates",
"(",
")",
";",
"if",
"(",
"$",
"init",
"&&",
"(",
"'variable'",
"==",
"$",
"type",
"||",
"'string'",
"==",
"$",
"type",
"||",
"'array'",
"==",
"$",
"type",
")",
")",
"{",
"$",
"variable",
"->",
"initVariant",
"(",
"$",
"context",
")",
";",
"}",
"return",
"$",
"variable",
";",
"}",
"$",
"tempVar",
"=",
"$",
"this",
"->",
"getNextTempVar",
"(",
")",
";",
"$",
"variable",
"=",
"$",
"this",
"->",
"addVariable",
"(",
"$",
"type",
",",
"'_'",
".",
"$",
"tempVar",
",",
"$",
"context",
")",
";",
"$",
"variable",
"->",
"setIsInitialized",
"(",
"true",
",",
"$",
"context",
")",
";",
"$",
"variable",
"->",
"setTemporal",
"(",
"true",
")",
";",
"$",
"variable",
"->",
"increaseUses",
"(",
")",
";",
"$",
"variable",
"->",
"increaseMutates",
"(",
")",
";",
"if",
"(",
"'variable'",
"==",
"$",
"type",
"||",
"'string'",
"==",
"$",
"type",
"||",
"'array'",
"==",
"$",
"type",
")",
"{",
"$",
"variable",
"->",
"initVariant",
"(",
"$",
"context",
")",
";",
"}",
"$",
"this",
"->",
"registerTempVariable",
"(",
"$",
"type",
",",
"'heap'",
",",
"$",
"variable",
")",
";",
"return",
"$",
"variable",
";",
"}"
] | Creates a temporary variable to be used in a write operation.
@param string $type
@param CompilationContext $context
@param mixed $init
@return Variable | [
"Creates",
"a",
"temporary",
"variable",
"to",
"be",
"used",
"in",
"a",
"write",
"operation",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/SymbolTable.php#L592-L618 | train |
phalcon/zephir | Library/SymbolTable.php | SymbolTable.getTempNonTrackedVariable | public function getTempNonTrackedVariable($type, CompilationContext $context, $initNonReferenced = false)
{
$variable = $this->reuseTempVariable($type, 'non-tracked');
if (\is_object($variable)) {
$variable->increaseUses();
$variable->increaseMutates();
if ($initNonReferenced) {
$variable->initNonReferenced($context);
}
return $variable;
}
$tempVar = $this->getNextTempVar();
$variable = $this->addVariable($type, '_'.$tempVar, $context);
$variable->setIsInitialized(true, $context);
$variable->setTemporal(true);
$variable->setMemoryTracked(false);
$variable->increaseUses();
$variable->increaseMutates();
$this->registerTempVariable($type, 'non-tracked', $variable);
if ($initNonReferenced) {
$variable->initNonReferenced($context);
}
return $variable;
} | php | public function getTempNonTrackedVariable($type, CompilationContext $context, $initNonReferenced = false)
{
$variable = $this->reuseTempVariable($type, 'non-tracked');
if (\is_object($variable)) {
$variable->increaseUses();
$variable->increaseMutates();
if ($initNonReferenced) {
$variable->initNonReferenced($context);
}
return $variable;
}
$tempVar = $this->getNextTempVar();
$variable = $this->addVariable($type, '_'.$tempVar, $context);
$variable->setIsInitialized(true, $context);
$variable->setTemporal(true);
$variable->setMemoryTracked(false);
$variable->increaseUses();
$variable->increaseMutates();
$this->registerTempVariable($type, 'non-tracked', $variable);
if ($initNonReferenced) {
$variable->initNonReferenced($context);
}
return $variable;
} | [
"public",
"function",
"getTempNonTrackedVariable",
"(",
"$",
"type",
",",
"CompilationContext",
"$",
"context",
",",
"$",
"initNonReferenced",
"=",
"false",
")",
"{",
"$",
"variable",
"=",
"$",
"this",
"->",
"reuseTempVariable",
"(",
"$",
"type",
",",
"'non-tracked'",
")",
";",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"variable",
")",
")",
"{",
"$",
"variable",
"->",
"increaseUses",
"(",
")",
";",
"$",
"variable",
"->",
"increaseMutates",
"(",
")",
";",
"if",
"(",
"$",
"initNonReferenced",
")",
"{",
"$",
"variable",
"->",
"initNonReferenced",
"(",
"$",
"context",
")",
";",
"}",
"return",
"$",
"variable",
";",
"}",
"$",
"tempVar",
"=",
"$",
"this",
"->",
"getNextTempVar",
"(",
")",
";",
"$",
"variable",
"=",
"$",
"this",
"->",
"addVariable",
"(",
"$",
"type",
",",
"'_'",
".",
"$",
"tempVar",
",",
"$",
"context",
")",
";",
"$",
"variable",
"->",
"setIsInitialized",
"(",
"true",
",",
"$",
"context",
")",
";",
"$",
"variable",
"->",
"setTemporal",
"(",
"true",
")",
";",
"$",
"variable",
"->",
"setMemoryTracked",
"(",
"false",
")",
";",
"$",
"variable",
"->",
"increaseUses",
"(",
")",
";",
"$",
"variable",
"->",
"increaseMutates",
"(",
")",
";",
"$",
"this",
"->",
"registerTempVariable",
"(",
"$",
"type",
",",
"'non-tracked'",
",",
"$",
"variable",
")",
";",
"if",
"(",
"$",
"initNonReferenced",
")",
"{",
"$",
"variable",
"->",
"initNonReferenced",
"(",
"$",
"context",
")",
";",
"}",
"return",
"$",
"variable",
";",
"}"
] | Creates a temporary variable to be used to point to a heap variable
These kind of variables MUST not be tracked by the Zephir memory manager.
@param $type
@param CompilationContext $context
@param bool $initNonReferenced
@return Variable | [
"Creates",
"a",
"temporary",
"variable",
"to",
"be",
"used",
"to",
"point",
"to",
"a",
"heap",
"variable",
"These",
"kind",
"of",
"variables",
"MUST",
"not",
"be",
"tracked",
"by",
"the",
"Zephir",
"memory",
"manager",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/SymbolTable.php#L630-L659 | train |
phalcon/zephir | Library/SymbolTable.php | SymbolTable.addTemp | public function addTemp($type, CompilationContext $context)
{
$tempVar = $this->getNextTempVar();
$variable = $this->addVariable($type, '_'.$tempVar, $context);
$variable->setIsInitialized(true, $context);
$variable->setTemporal(true);
$variable->increaseUses();
$variable->increaseMutates();
return $variable;
} | php | public function addTemp($type, CompilationContext $context)
{
$tempVar = $this->getNextTempVar();
$variable = $this->addVariable($type, '_'.$tempVar, $context);
$variable->setIsInitialized(true, $context);
$variable->setTemporal(true);
$variable->increaseUses();
$variable->increaseMutates();
return $variable;
} | [
"public",
"function",
"addTemp",
"(",
"$",
"type",
",",
"CompilationContext",
"$",
"context",
")",
"{",
"$",
"tempVar",
"=",
"$",
"this",
"->",
"getNextTempVar",
"(",
")",
";",
"$",
"variable",
"=",
"$",
"this",
"->",
"addVariable",
"(",
"$",
"type",
",",
"'_'",
".",
"$",
"tempVar",
",",
"$",
"context",
")",
";",
"$",
"variable",
"->",
"setIsInitialized",
"(",
"true",
",",
"$",
"context",
")",
";",
"$",
"variable",
"->",
"setTemporal",
"(",
"true",
")",
";",
"$",
"variable",
"->",
"increaseUses",
"(",
")",
";",
"$",
"variable",
"->",
"increaseMutates",
"(",
")",
";",
"return",
"$",
"variable",
";",
"}"
] | Creates a temporary variable.
@param string $type
@param CompilationContext $context
@return Variable | [
"Creates",
"a",
"temporary",
"variable",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/SymbolTable.php#L777-L787 | train |
phalcon/zephir | Library/SymbolTable.php | SymbolTable.getTempVariableForObserve | public function getTempVariableForObserve($type, CompilationContext $context)
{
$variable = $this->reuseTempVariable($type, 'observe');
if (\is_object($variable)) {
$variable->increaseUses();
$variable->increaseMutates();
$variable->observeVariant($context);
return $variable;
}
$tempVar = $this->getNextTempVar();
$variable = $this->addVariable($type, '_'.$tempVar, $context);
$variable->setIsInitialized(true, $context);
$variable->setTemporal(true);
$variable->increaseUses();
$variable->increaseMutates();
$variable->observeVariant($context);
$this->registerTempVariable($type, 'observe', $variable);
return $variable;
} | php | public function getTempVariableForObserve($type, CompilationContext $context)
{
$variable = $this->reuseTempVariable($type, 'observe');
if (\is_object($variable)) {
$variable->increaseUses();
$variable->increaseMutates();
$variable->observeVariant($context);
return $variable;
}
$tempVar = $this->getNextTempVar();
$variable = $this->addVariable($type, '_'.$tempVar, $context);
$variable->setIsInitialized(true, $context);
$variable->setTemporal(true);
$variable->increaseUses();
$variable->increaseMutates();
$variable->observeVariant($context);
$this->registerTempVariable($type, 'observe', $variable);
return $variable;
} | [
"public",
"function",
"getTempVariableForObserve",
"(",
"$",
"type",
",",
"CompilationContext",
"$",
"context",
")",
"{",
"$",
"variable",
"=",
"$",
"this",
"->",
"reuseTempVariable",
"(",
"$",
"type",
",",
"'observe'",
")",
";",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"variable",
")",
")",
"{",
"$",
"variable",
"->",
"increaseUses",
"(",
")",
";",
"$",
"variable",
"->",
"increaseMutates",
"(",
")",
";",
"$",
"variable",
"->",
"observeVariant",
"(",
"$",
"context",
")",
";",
"return",
"$",
"variable",
";",
"}",
"$",
"tempVar",
"=",
"$",
"this",
"->",
"getNextTempVar",
"(",
")",
";",
"$",
"variable",
"=",
"$",
"this",
"->",
"addVariable",
"(",
"$",
"type",
",",
"'_'",
".",
"$",
"tempVar",
",",
"$",
"context",
")",
";",
"$",
"variable",
"->",
"setIsInitialized",
"(",
"true",
",",
"$",
"context",
")",
";",
"$",
"variable",
"->",
"setTemporal",
"(",
"true",
")",
";",
"$",
"variable",
"->",
"increaseUses",
"(",
")",
";",
"$",
"variable",
"->",
"increaseMutates",
"(",
")",
";",
"$",
"variable",
"->",
"observeVariant",
"(",
"$",
"context",
")",
";",
"$",
"this",
"->",
"registerTempVariable",
"(",
"$",
"type",
",",
"'observe'",
",",
"$",
"variable",
")",
";",
"return",
"$",
"variable",
";",
"}"
] | Creates a temporary variable to be used as intermediate variable of a read operation
Variables are automatically tracked by the memory manager.
@param string $type
@param CompilationContext $context
@return Variable | [
"Creates",
"a",
"temporary",
"variable",
"to",
"be",
"used",
"as",
"intermediate",
"variable",
"of",
"a",
"read",
"operation",
"Variables",
"are",
"automatically",
"tracked",
"by",
"the",
"memory",
"manager",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/SymbolTable.php#L798-L820 | train |
phalcon/zephir | Library/SymbolTable.php | SymbolTable.markTemporalVariablesIdle | public function markTemporalVariablesIdle(CompilationContext $compilationContext)
{
$compilationContext = $compilationContext ?: $this->compilationContext;
$branchId = $compilationContext->branchManager->getCurrentBranchId();
if (!isset($this->branchTempVariables[$branchId])) {
return;
}
foreach ($this->branchTempVariables[$branchId] as $location => $typeVariables) {
foreach ($typeVariables as $type => $variables) {
foreach ($variables as $variable) {
$pos = strpos($variable->getName(), Variable::BRANCH_MAGIC);
$otherBranchId = 1;
if ($pos > -1) {
$otherBranchId = (int) (substr($variable->getName(), $pos + \strlen(Variable::BRANCH_MAGIC)));
}
if ($branchId == $otherBranchId) {
$variable->setIdle(true);
}
}
}
}
} | php | public function markTemporalVariablesIdle(CompilationContext $compilationContext)
{
$compilationContext = $compilationContext ?: $this->compilationContext;
$branchId = $compilationContext->branchManager->getCurrentBranchId();
if (!isset($this->branchTempVariables[$branchId])) {
return;
}
foreach ($this->branchTempVariables[$branchId] as $location => $typeVariables) {
foreach ($typeVariables as $type => $variables) {
foreach ($variables as $variable) {
$pos = strpos($variable->getName(), Variable::BRANCH_MAGIC);
$otherBranchId = 1;
if ($pos > -1) {
$otherBranchId = (int) (substr($variable->getName(), $pos + \strlen(Variable::BRANCH_MAGIC)));
}
if ($branchId == $otherBranchId) {
$variable->setIdle(true);
}
}
}
}
} | [
"public",
"function",
"markTemporalVariablesIdle",
"(",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"$",
"compilationContext",
"=",
"$",
"compilationContext",
"?",
":",
"$",
"this",
"->",
"compilationContext",
";",
"$",
"branchId",
"=",
"$",
"compilationContext",
"->",
"branchManager",
"->",
"getCurrentBranchId",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"branchTempVariables",
"[",
"$",
"branchId",
"]",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"branchTempVariables",
"[",
"$",
"branchId",
"]",
"as",
"$",
"location",
"=>",
"$",
"typeVariables",
")",
"{",
"foreach",
"(",
"$",
"typeVariables",
"as",
"$",
"type",
"=>",
"$",
"variables",
")",
"{",
"foreach",
"(",
"$",
"variables",
"as",
"$",
"variable",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"variable",
"->",
"getName",
"(",
")",
",",
"Variable",
"::",
"BRANCH_MAGIC",
")",
";",
"$",
"otherBranchId",
"=",
"1",
";",
"if",
"(",
"$",
"pos",
">",
"-",
"1",
")",
"{",
"$",
"otherBranchId",
"=",
"(",
"int",
")",
"(",
"substr",
"(",
"$",
"variable",
"->",
"getName",
"(",
")",
",",
"$",
"pos",
"+",
"\\",
"strlen",
"(",
"Variable",
"::",
"BRANCH_MAGIC",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"branchId",
"==",
"$",
"otherBranchId",
")",
"{",
"$",
"variable",
"->",
"setIdle",
"(",
"true",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Traverses temporal variables created in a specific branch
marking them as idle.
@param CompilationContext $compilationContext | [
"Traverses",
"temporal",
"variables",
"created",
"in",
"a",
"specific",
"branch",
"marking",
"them",
"as",
"idle",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/SymbolTable.php#L861-L884 | train |
phalcon/zephir | Library/SymbolTable.php | SymbolTable.registerTempVariable | protected function registerTempVariable($type, $location, Variable $variable, CompilationContext $compilationContext = null)
{
$compilationContext = $compilationContext ?: $this->compilationContext;
$branchId = $compilationContext->branchManager->getCurrentBranchId();
if (!isset($this->branchTempVariables[$branchId][$location][$type])) {
$this->branchTempVariables[$branchId][$location][$type] = [];
}
$this->branchTempVariables[$branchId][$location][$type][] = $variable;
} | php | protected function registerTempVariable($type, $location, Variable $variable, CompilationContext $compilationContext = null)
{
$compilationContext = $compilationContext ?: $this->compilationContext;
$branchId = $compilationContext->branchManager->getCurrentBranchId();
if (!isset($this->branchTempVariables[$branchId][$location][$type])) {
$this->branchTempVariables[$branchId][$location][$type] = [];
}
$this->branchTempVariables[$branchId][$location][$type][] = $variable;
} | [
"protected",
"function",
"registerTempVariable",
"(",
"$",
"type",
",",
"$",
"location",
",",
"Variable",
"$",
"variable",
",",
"CompilationContext",
"$",
"compilationContext",
"=",
"null",
")",
"{",
"$",
"compilationContext",
"=",
"$",
"compilationContext",
"?",
":",
"$",
"this",
"->",
"compilationContext",
";",
"$",
"branchId",
"=",
"$",
"compilationContext",
"->",
"branchManager",
"->",
"getCurrentBranchId",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"branchTempVariables",
"[",
"$",
"branchId",
"]",
"[",
"$",
"location",
"]",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"this",
"->",
"branchTempVariables",
"[",
"$",
"branchId",
"]",
"[",
"$",
"location",
"]",
"[",
"$",
"type",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"branchTempVariables",
"[",
"$",
"branchId",
"]",
"[",
"$",
"location",
"]",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"variable",
";",
"}"
] | Register a variable as temporal.
@param string $type
@param string $location
@param Variable $variable
@param CompilationContext $compilationContext | [
"Register",
"a",
"variable",
"as",
"temporal",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/SymbolTable.php#L942-L951 | train |
phalcon/zephir | Library/SymbolTable.php | SymbolTable.reuseTempVariable | protected function reuseTempVariable($type, $location, CompilationContext $compilationContext = null)
{
$compilationContext = $compilationContext ?: $this->compilationContext;
$branchId = $compilationContext->branchManager->getCurrentBranchId();
if (isset($this->branchTempVariables[$branchId][$location][$type])) {
foreach ($this->branchTempVariables[$branchId][$location][$type] as $variable) {
if (!$variable->isDoublePointer()) {
if ($variable->isIdle()) {
$variable->setIdle(false);
return $variable;
}
}
}
}
return null;
} | php | protected function reuseTempVariable($type, $location, CompilationContext $compilationContext = null)
{
$compilationContext = $compilationContext ?: $this->compilationContext;
$branchId = $compilationContext->branchManager->getCurrentBranchId();
if (isset($this->branchTempVariables[$branchId][$location][$type])) {
foreach ($this->branchTempVariables[$branchId][$location][$type] as $variable) {
if (!$variable->isDoublePointer()) {
if ($variable->isIdle()) {
$variable->setIdle(false);
return $variable;
}
}
}
}
return null;
} | [
"protected",
"function",
"reuseTempVariable",
"(",
"$",
"type",
",",
"$",
"location",
",",
"CompilationContext",
"$",
"compilationContext",
"=",
"null",
")",
"{",
"$",
"compilationContext",
"=",
"$",
"compilationContext",
"?",
":",
"$",
"this",
"->",
"compilationContext",
";",
"$",
"branchId",
"=",
"$",
"compilationContext",
"->",
"branchManager",
"->",
"getCurrentBranchId",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"branchTempVariables",
"[",
"$",
"branchId",
"]",
"[",
"$",
"location",
"]",
"[",
"$",
"type",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"branchTempVariables",
"[",
"$",
"branchId",
"]",
"[",
"$",
"location",
"]",
"[",
"$",
"type",
"]",
"as",
"$",
"variable",
")",
"{",
"if",
"(",
"!",
"$",
"variable",
"->",
"isDoublePointer",
"(",
")",
")",
"{",
"if",
"(",
"$",
"variable",
"->",
"isIdle",
"(",
")",
")",
"{",
"$",
"variable",
"->",
"setIdle",
"(",
"false",
")",
";",
"return",
"$",
"variable",
";",
"}",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Reuse variables marked as idle after leave a branch.
@param string $type
@param string $location
@param CompilationContext $compilationContext
@return Variable | [
"Reuse",
"variables",
"marked",
"as",
"idle",
"after",
"leave",
"a",
"branch",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/SymbolTable.php#L962-L980 | train |
phalcon/zephir | Library/Passes/MutateGathererPass.php | MutateGathererPass.increaseMutations | public function increaseMutations($variable)
{
if (isset($this->mutations[$variable])) {
++$this->mutations[$variable];
} else {
$this->mutations[$variable] = 1;
}
return $this;
} | php | public function increaseMutations($variable)
{
if (isset($this->mutations[$variable])) {
++$this->mutations[$variable];
} else {
$this->mutations[$variable] = 1;
}
return $this;
} | [
"public",
"function",
"increaseMutations",
"(",
"$",
"variable",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"mutations",
"[",
"$",
"variable",
"]",
")",
")",
"{",
"++",
"$",
"this",
"->",
"mutations",
"[",
"$",
"variable",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"mutations",
"[",
"$",
"variable",
"]",
"=",
"1",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Increase the number of mutations a variable has inside a statement block.
@param string $variable
@return MutateGathererPass | [
"Increase",
"the",
"number",
"of",
"mutations",
"a",
"variable",
"has",
"inside",
"a",
"statement",
"block",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Passes/MutateGathererPass.php#L54-L63 | train |
phalcon/zephir | Library/Passes/MutateGathererPass.php | MutateGathererPass.passExpression | public function passExpression(array $expression)
{
switch ($expression['type']) {
case 'bool':
case 'double':
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'string':
case 'istring':
case 'null':
case 'char':
case 'uchar':
case 'empty-array':
case 'variable':
case 'constant':
case 'static-constant-access':
case 'closure':
case 'closure-arrow':
case 'reference':
break;
case 'sub':
case 'add':
case 'div':
case 'mul':
case 'mod':
case 'and':
case 'or':
case 'concat':
case 'equals':
case 'identical':
case 'not-identical':
case 'not-equals':
case 'less':
case 'greater':
case 'greater-equal':
case 'less-equal':
case 'bitwise_and':
case 'bitwise_or':
case 'bitwise_xor':
case 'bitwise_shiftleft':
case 'bitwise_shiftright':
case 'irange':
case 'erange':
$this->passExpression($expression['left']);
$this->passExpression($expression['right']);
break;
case 'typeof':
case 'not':
$this->passExpression($expression['left']);
break;
case 'mcall':
case 'fcall':
case 'scall':
$this->passCall($expression);
break;
case 'array':
$this->passArray($expression);
break;
case 'new':
$this->passNew($expression);
break;
case 'property-access':
case 'property-dynamic-access':
case 'property-string-access':
case 'static-property-access':
case 'array-access':
$this->passExpression($expression['left']);
break;
case 'isset':
case 'empty':
case 'instanceof':
case 'require':
case 'clone':
case 'likely':
case 'unlikely':
case 'ternary':
/* do special pass later */
$this->passExpression($expression['left']);
break;
case 'fetch':
$this->increaseMutations($expression['left']['value']);
$this->passExpression($expression['right']);
break;
case 'minus':
$this->passExpression($expression['left']);
break;
case 'list':
$this->passExpression($expression['left']);
break;
case 'cast':
case 'type-hint':
$this->passExpression($expression['right']);
break;
default:
echo 'MutateGathererPassType=', $expression['type'], PHP_EOL;
break;
}
} | php | public function passExpression(array $expression)
{
switch ($expression['type']) {
case 'bool':
case 'double':
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'string':
case 'istring':
case 'null':
case 'char':
case 'uchar':
case 'empty-array':
case 'variable':
case 'constant':
case 'static-constant-access':
case 'closure':
case 'closure-arrow':
case 'reference':
break;
case 'sub':
case 'add':
case 'div':
case 'mul':
case 'mod':
case 'and':
case 'or':
case 'concat':
case 'equals':
case 'identical':
case 'not-identical':
case 'not-equals':
case 'less':
case 'greater':
case 'greater-equal':
case 'less-equal':
case 'bitwise_and':
case 'bitwise_or':
case 'bitwise_xor':
case 'bitwise_shiftleft':
case 'bitwise_shiftright':
case 'irange':
case 'erange':
$this->passExpression($expression['left']);
$this->passExpression($expression['right']);
break;
case 'typeof':
case 'not':
$this->passExpression($expression['left']);
break;
case 'mcall':
case 'fcall':
case 'scall':
$this->passCall($expression);
break;
case 'array':
$this->passArray($expression);
break;
case 'new':
$this->passNew($expression);
break;
case 'property-access':
case 'property-dynamic-access':
case 'property-string-access':
case 'static-property-access':
case 'array-access':
$this->passExpression($expression['left']);
break;
case 'isset':
case 'empty':
case 'instanceof':
case 'require':
case 'clone':
case 'likely':
case 'unlikely':
case 'ternary':
/* do special pass later */
$this->passExpression($expression['left']);
break;
case 'fetch':
$this->increaseMutations($expression['left']['value']);
$this->passExpression($expression['right']);
break;
case 'minus':
$this->passExpression($expression['left']);
break;
case 'list':
$this->passExpression($expression['left']);
break;
case 'cast':
case 'type-hint':
$this->passExpression($expression['right']);
break;
default:
echo 'MutateGathererPassType=', $expression['type'], PHP_EOL;
break;
}
} | [
"public",
"function",
"passExpression",
"(",
"array",
"$",
"expression",
")",
"{",
"switch",
"(",
"$",
"expression",
"[",
"'type'",
"]",
")",
"{",
"case",
"'bool'",
":",
"case",
"'double'",
":",
"case",
"'int'",
":",
"case",
"'uint'",
":",
"case",
"'long'",
":",
"case",
"'ulong'",
":",
"case",
"'string'",
":",
"case",
"'istring'",
":",
"case",
"'null'",
":",
"case",
"'char'",
":",
"case",
"'uchar'",
":",
"case",
"'empty-array'",
":",
"case",
"'variable'",
":",
"case",
"'constant'",
":",
"case",
"'static-constant-access'",
":",
"case",
"'closure'",
":",
"case",
"'closure-arrow'",
":",
"case",
"'reference'",
":",
"break",
";",
"case",
"'sub'",
":",
"case",
"'add'",
":",
"case",
"'div'",
":",
"case",
"'mul'",
":",
"case",
"'mod'",
":",
"case",
"'and'",
":",
"case",
"'or'",
":",
"case",
"'concat'",
":",
"case",
"'equals'",
":",
"case",
"'identical'",
":",
"case",
"'not-identical'",
":",
"case",
"'not-equals'",
":",
"case",
"'less'",
":",
"case",
"'greater'",
":",
"case",
"'greater-equal'",
":",
"case",
"'less-equal'",
":",
"case",
"'bitwise_and'",
":",
"case",
"'bitwise_or'",
":",
"case",
"'bitwise_xor'",
":",
"case",
"'bitwise_shiftleft'",
":",
"case",
"'bitwise_shiftright'",
":",
"case",
"'irange'",
":",
"case",
"'erange'",
":",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"expression",
"[",
"'left'",
"]",
")",
";",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"expression",
"[",
"'right'",
"]",
")",
";",
"break",
";",
"case",
"'typeof'",
":",
"case",
"'not'",
":",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"expression",
"[",
"'left'",
"]",
")",
";",
"break",
";",
"case",
"'mcall'",
":",
"case",
"'fcall'",
":",
"case",
"'scall'",
":",
"$",
"this",
"->",
"passCall",
"(",
"$",
"expression",
")",
";",
"break",
";",
"case",
"'array'",
":",
"$",
"this",
"->",
"passArray",
"(",
"$",
"expression",
")",
";",
"break",
";",
"case",
"'new'",
":",
"$",
"this",
"->",
"passNew",
"(",
"$",
"expression",
")",
";",
"break",
";",
"case",
"'property-access'",
":",
"case",
"'property-dynamic-access'",
":",
"case",
"'property-string-access'",
":",
"case",
"'static-property-access'",
":",
"case",
"'array-access'",
":",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"expression",
"[",
"'left'",
"]",
")",
";",
"break",
";",
"case",
"'isset'",
":",
"case",
"'empty'",
":",
"case",
"'instanceof'",
":",
"case",
"'require'",
":",
"case",
"'clone'",
":",
"case",
"'likely'",
":",
"case",
"'unlikely'",
":",
"case",
"'ternary'",
":",
"/* do special pass later */",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"expression",
"[",
"'left'",
"]",
")",
";",
"break",
";",
"case",
"'fetch'",
":",
"$",
"this",
"->",
"increaseMutations",
"(",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'value'",
"]",
")",
";",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"expression",
"[",
"'right'",
"]",
")",
";",
"break",
";",
"case",
"'minus'",
":",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"expression",
"[",
"'left'",
"]",
")",
";",
"break",
";",
"case",
"'list'",
":",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"expression",
"[",
"'left'",
"]",
")",
";",
"break",
";",
"case",
"'cast'",
":",
"case",
"'type-hint'",
":",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"expression",
"[",
"'right'",
"]",
")",
";",
"break",
";",
"default",
":",
"echo",
"'MutateGathererPassType='",
",",
"$",
"expression",
"[",
"'type'",
"]",
",",
"PHP_EOL",
";",
"break",
";",
"}",
"}"
] | Pass expressions.
@param array $expression | [
"Pass",
"expressions",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Passes/MutateGathererPass.php#L149-L260 | train |
phalcon/zephir | Library/Compiler.php | Compiler.reslovePrototypesPath | private function reslovePrototypesPath()
{
$prototypesPath = $this->prototypesPath;
// fallback
if (empty($prototypesPath)) {
$prototypesPath = \dirname(__DIR__).'/prototypes';
}
if (!is_dir($prototypesPath) || !is_readable($prototypesPath)) {
throw new IllegalStateException('Unable to resolve internal prototypes directory.');
}
return $prototypesPath;
} | php | private function reslovePrototypesPath()
{
$prototypesPath = $this->prototypesPath;
// fallback
if (empty($prototypesPath)) {
$prototypesPath = \dirname(__DIR__).'/prototypes';
}
if (!is_dir($prototypesPath) || !is_readable($prototypesPath)) {
throw new IllegalStateException('Unable to resolve internal prototypes directory.');
}
return $prototypesPath;
} | [
"private",
"function",
"reslovePrototypesPath",
"(",
")",
"{",
"$",
"prototypesPath",
"=",
"$",
"this",
"->",
"prototypesPath",
";",
"// fallback",
"if",
"(",
"empty",
"(",
"$",
"prototypesPath",
")",
")",
"{",
"$",
"prototypesPath",
"=",
"\\",
"dirname",
"(",
"__DIR__",
")",
".",
"'/prototypes'",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"prototypesPath",
")",
"||",
"!",
"is_readable",
"(",
"$",
"prototypesPath",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"'Unable to resolve internal prototypes directory.'",
")",
";",
"}",
"return",
"$",
"prototypesPath",
";",
"}"
] | Resolves path to the internal prototypes.
@return string
@throws IllegalStateException in case of absence internal prototypes directory | [
"Resolves",
"path",
"to",
"the",
"internal",
"prototypes",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L144-L158 | train |
phalcon/zephir | Library/Compiler.php | Compiler.resolveOptimizersPath | private function resolveOptimizersPath()
{
$optimizersPath = $this->optimizersPath;
// fallback
if (empty($optimizersPath)) {
$optimizersPath = __DIR__.'/Optimizers';
}
if (!is_dir($optimizersPath) || !is_readable($optimizersPath)) {
throw new IllegalStateException('Unable to resolve internal optimizers directory.');
}
return $optimizersPath;
} | php | private function resolveOptimizersPath()
{
$optimizersPath = $this->optimizersPath;
// fallback
if (empty($optimizersPath)) {
$optimizersPath = __DIR__.'/Optimizers';
}
if (!is_dir($optimizersPath) || !is_readable($optimizersPath)) {
throw new IllegalStateException('Unable to resolve internal optimizers directory.');
}
return $optimizersPath;
} | [
"private",
"function",
"resolveOptimizersPath",
"(",
")",
"{",
"$",
"optimizersPath",
"=",
"$",
"this",
"->",
"optimizersPath",
";",
"// fallback",
"if",
"(",
"empty",
"(",
"$",
"optimizersPath",
")",
")",
"{",
"$",
"optimizersPath",
"=",
"__DIR__",
".",
"'/Optimizers'",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"optimizersPath",
")",
"||",
"!",
"is_readable",
"(",
"$",
"optimizersPath",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"'Unable to resolve internal optimizers directory.'",
")",
";",
"}",
"return",
"$",
"optimizersPath",
";",
"}"
] | Resolves path to the internal optimizers.
@return string
@throws IllegalStateException in case of absence internal optimizers directory | [
"Resolves",
"path",
"to",
"the",
"internal",
"optimizers",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L177-L191 | train |
phalcon/zephir | Library/Compiler.php | Compiler.loadExternalClass | public function loadExternalClass($className, $location)
{
$filePath = $location.\DIRECTORY_SEPARATOR.
strtolower(str_replace('\\', \DIRECTORY_SEPARATOR, $className)).'.zep';
/**
* Fix the class name.
*/
$className = implode('\\', array_map('ucfirst', explode('\\', $className)));
if (isset($this->files[$className])) {
return true;
}
if (!file_exists($filePath)) {
return false;
}
/** @var CompilerFile|CompilerFileAnonymous $compilerFile */
$compilerFile = $this->compilerFileFactory->create($className, $filePath);
$compilerFile->setIsExternal(true);
$compilerFile->preCompile($this);
$this->files[$className] = $compilerFile;
$this->definitions[$className] = $compilerFile->getClassDefinition();
return true;
} | php | public function loadExternalClass($className, $location)
{
$filePath = $location.\DIRECTORY_SEPARATOR.
strtolower(str_replace('\\', \DIRECTORY_SEPARATOR, $className)).'.zep';
/**
* Fix the class name.
*/
$className = implode('\\', array_map('ucfirst', explode('\\', $className)));
if (isset($this->files[$className])) {
return true;
}
if (!file_exists($filePath)) {
return false;
}
/** @var CompilerFile|CompilerFileAnonymous $compilerFile */
$compilerFile = $this->compilerFileFactory->create($className, $filePath);
$compilerFile->setIsExternal(true);
$compilerFile->preCompile($this);
$this->files[$className] = $compilerFile;
$this->definitions[$className] = $compilerFile->getClassDefinition();
return true;
} | [
"public",
"function",
"loadExternalClass",
"(",
"$",
"className",
",",
"$",
"location",
")",
"{",
"$",
"filePath",
"=",
"$",
"location",
".",
"\\",
"DIRECTORY_SEPARATOR",
".",
"strtolower",
"(",
"str_replace",
"(",
"'\\\\'",
",",
"\\",
"DIRECTORY_SEPARATOR",
",",
"$",
"className",
")",
")",
".",
"'.zep'",
";",
"/**\n * Fix the class name.\n */",
"$",
"className",
"=",
"implode",
"(",
"'\\\\'",
",",
"array_map",
"(",
"'ucfirst'",
",",
"explode",
"(",
"'\\\\'",
",",
"$",
"className",
")",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"files",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"return",
"false",
";",
"}",
"/** @var CompilerFile|CompilerFileAnonymous $compilerFile */",
"$",
"compilerFile",
"=",
"$",
"this",
"->",
"compilerFileFactory",
"->",
"create",
"(",
"$",
"className",
",",
"$",
"filePath",
")",
";",
"$",
"compilerFile",
"->",
"setIsExternal",
"(",
"true",
")",
";",
"$",
"compilerFile",
"->",
"preCompile",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"files",
"[",
"$",
"className",
"]",
"=",
"$",
"compilerFile",
";",
"$",
"this",
"->",
"definitions",
"[",
"$",
"className",
"]",
"=",
"$",
"compilerFile",
"->",
"getClassDefinition",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Loads a class definition in an external dependency.
@param string $className
@param string $location
@return bool
@throws CompilerException
@throws IllegalStateException
@throws ParseException | [
"Loads",
"a",
"class",
"definition",
"in",
"an",
"external",
"dependency",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L249-L276 | train |
phalcon/zephir | Library/Compiler.php | Compiler.isClass | public function isClass($className)
{
foreach ($this->definitions as $key => $value) {
if (!strcasecmp($key, $className) && 'class' === $value->getType()) {
return true;
}
}
/*
* Try to autoload the class from an external dependency
*/
if (\count($this->externalDependencies)) {
foreach ($this->externalDependencies as $namespace => $location) {
if (preg_match('#^'.$namespace.'\\\\#i', $className)) {
return $this->loadExternalClass($className, $location);
}
}
}
return false;
} | php | public function isClass($className)
{
foreach ($this->definitions as $key => $value) {
if (!strcasecmp($key, $className) && 'class' === $value->getType()) {
return true;
}
}
/*
* Try to autoload the class from an external dependency
*/
if (\count($this->externalDependencies)) {
foreach ($this->externalDependencies as $namespace => $location) {
if (preg_match('#^'.$namespace.'\\\\#i', $className)) {
return $this->loadExternalClass($className, $location);
}
}
}
return false;
} | [
"public",
"function",
"isClass",
"(",
"$",
"className",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"definitions",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"strcasecmp",
"(",
"$",
"key",
",",
"$",
"className",
")",
"&&",
"'class'",
"===",
"$",
"value",
"->",
"getType",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"/*\n * Try to autoload the class from an external dependency\n */",
"if",
"(",
"\\",
"count",
"(",
"$",
"this",
"->",
"externalDependencies",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"externalDependencies",
"as",
"$",
"namespace",
"=>",
"$",
"location",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#^'",
".",
"$",
"namespace",
".",
"'\\\\\\\\#i'",
",",
"$",
"className",
")",
")",
"{",
"return",
"$",
"this",
"->",
"loadExternalClass",
"(",
"$",
"className",
",",
"$",
"location",
")",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Allows to check if a class is part of the compiled extension.
@param string $className
@return bool | [
"Allows",
"to",
"check",
"if",
"a",
"class",
"is",
"part",
"of",
"the",
"compiled",
"extension",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L285-L305 | train |
phalcon/zephir | Library/Compiler.php | Compiler.addClassDefinition | public function addClassDefinition(CompilerFileAnonymous $file, ClassDefinition $classDefinition)
{
$this->definitions[$classDefinition->getCompleteName()] = $classDefinition;
$this->anonymousFiles[$classDefinition->getCompleteName()] = $file;
} | php | public function addClassDefinition(CompilerFileAnonymous $file, ClassDefinition $classDefinition)
{
$this->definitions[$classDefinition->getCompleteName()] = $classDefinition;
$this->anonymousFiles[$classDefinition->getCompleteName()] = $file;
} | [
"public",
"function",
"addClassDefinition",
"(",
"CompilerFileAnonymous",
"$",
"file",
",",
"ClassDefinition",
"$",
"classDefinition",
")",
"{",
"$",
"this",
"->",
"definitions",
"[",
"$",
"classDefinition",
"->",
"getCompleteName",
"(",
")",
"]",
"=",
"$",
"classDefinition",
";",
"$",
"this",
"->",
"anonymousFiles",
"[",
"$",
"classDefinition",
"->",
"getCompleteName",
"(",
")",
"]",
"=",
"$",
"file",
";",
"}"
] | Inserts an anonymous class definition in the compiler.
@param CompilerFileAnonymous $file
@param ClassDefinition $classDefinition | [
"Inserts",
"an",
"anonymous",
"class",
"definition",
"in",
"the",
"compiler",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L388-L392 | train |
phalcon/zephir | Library/Compiler.php | Compiler.setExtensionGlobals | public function setExtensionGlobals(array $globals)
{
foreach ($globals as $key => $value) {
$this->globals[$key] = $value;
}
} | php | public function setExtensionGlobals(array $globals)
{
foreach ($globals as $key => $value) {
$this->globals[$key] = $value;
}
} | [
"public",
"function",
"setExtensionGlobals",
"(",
"array",
"$",
"globals",
")",
"{",
"foreach",
"(",
"$",
"globals",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"globals",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | Sets extensions globals.
@param array $globals | [
"Sets",
"extensions",
"globals",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L440-L445 | train |
phalcon/zephir | Library/Compiler.php | Compiler.getGccFlags | public function getGccFlags($development = false)
{
if (is_windows()) {
// TODO
return '';
}
$gccFlags = getenv('CFLAGS');
if (!\is_string($gccFlags)) {
if (false === $development) {
$gccVersion = $this->getGccVersion();
if (version_compare($gccVersion, '4.6.0', '>=')) {
$gccFlags = '-O2 -fvisibility=hidden -Wparentheses -flto -DZEPHIR_RELEASE=1';
} else {
$gccFlags = '-O2 -fvisibility=hidden -Wparentheses -DZEPHIR_RELEASE=1';
}
} else {
$gccFlags = '-O0 -g3';
}
}
return $gccFlags;
} | php | public function getGccFlags($development = false)
{
if (is_windows()) {
// TODO
return '';
}
$gccFlags = getenv('CFLAGS');
if (!\is_string($gccFlags)) {
if (false === $development) {
$gccVersion = $this->getGccVersion();
if (version_compare($gccVersion, '4.6.0', '>=')) {
$gccFlags = '-O2 -fvisibility=hidden -Wparentheses -flto -DZEPHIR_RELEASE=1';
} else {
$gccFlags = '-O2 -fvisibility=hidden -Wparentheses -DZEPHIR_RELEASE=1';
}
} else {
$gccFlags = '-O0 -g3';
}
}
return $gccFlags;
} | [
"public",
"function",
"getGccFlags",
"(",
"$",
"development",
"=",
"false",
")",
"{",
"if",
"(",
"is_windows",
"(",
")",
")",
"{",
"// TODO",
"return",
"''",
";",
"}",
"$",
"gccFlags",
"=",
"getenv",
"(",
"'CFLAGS'",
")",
";",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"gccFlags",
")",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"development",
")",
"{",
"$",
"gccVersion",
"=",
"$",
"this",
"->",
"getGccVersion",
"(",
")",
";",
"if",
"(",
"version_compare",
"(",
"$",
"gccVersion",
",",
"'4.6.0'",
",",
"'>='",
")",
")",
"{",
"$",
"gccFlags",
"=",
"'-O2 -fvisibility=hidden -Wparentheses -flto -DZEPHIR_RELEASE=1'",
";",
"}",
"else",
"{",
"$",
"gccFlags",
"=",
"'-O2 -fvisibility=hidden -Wparentheses -DZEPHIR_RELEASE=1'",
";",
"}",
"}",
"else",
"{",
"$",
"gccFlags",
"=",
"'-O0 -g3'",
";",
"}",
"}",
"return",
"$",
"gccFlags",
";",
"}"
] | Returns GCC flags for current compilation.
@param bool $development
@return string | [
"Returns",
"GCC",
"flags",
"for",
"current",
"compilation",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L478-L501 | train |
phalcon/zephir | Library/Compiler.php | Compiler.preCompileHeaders | public function preCompileHeaders()
{
if (is_windows()) {
// TODO: Add Windows support
return;
}
$phpIncludes = $this->getPhpIncludeDirs();
foreach (new \DirectoryIterator('ext/kernel') as $file) {
if ($file->isDir()) {
continue;
}
if (preg_match('/\.h$/', $file)) {
$path = $file->getRealPath();
$command = sprintf(
'cd ext && gcc -c kernel/%s -I. %s -o kernel/%s.gch',
$file->getBaseName(),
$phpIncludes,
$file->getBaseName()
);
if (!file_exists($path.'.gch') || filemtime($path) > filemtime($path.'.gch')) {
$this->filesystem->system($command, 'stdout', 'compile-header');
}
}
}
} | php | public function preCompileHeaders()
{
if (is_windows()) {
// TODO: Add Windows support
return;
}
$phpIncludes = $this->getPhpIncludeDirs();
foreach (new \DirectoryIterator('ext/kernel') as $file) {
if ($file->isDir()) {
continue;
}
if (preg_match('/\.h$/', $file)) {
$path = $file->getRealPath();
$command = sprintf(
'cd ext && gcc -c kernel/%s -I. %s -o kernel/%s.gch',
$file->getBaseName(),
$phpIncludes,
$file->getBaseName()
);
if (!file_exists($path.'.gch') || filemtime($path) > filemtime($path.'.gch')) {
$this->filesystem->system($command, 'stdout', 'compile-header');
}
}
}
} | [
"public",
"function",
"preCompileHeaders",
"(",
")",
"{",
"if",
"(",
"is_windows",
"(",
")",
")",
"{",
"// TODO: Add Windows support",
"return",
";",
"}",
"$",
"phpIncludes",
"=",
"$",
"this",
"->",
"getPhpIncludeDirs",
"(",
")",
";",
"foreach",
"(",
"new",
"\\",
"DirectoryIterator",
"(",
"'ext/kernel'",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/\\.h$/'",
",",
"$",
"file",
")",
")",
"{",
"$",
"path",
"=",
"$",
"file",
"->",
"getRealPath",
"(",
")",
";",
"$",
"command",
"=",
"sprintf",
"(",
"'cd ext && gcc -c kernel/%s -I. %s -o kernel/%s.gch'",
",",
"$",
"file",
"->",
"getBaseName",
"(",
")",
",",
"$",
"phpIncludes",
",",
"$",
"file",
"->",
"getBaseName",
"(",
")",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
".",
"'.gch'",
")",
"||",
"filemtime",
"(",
"$",
"path",
")",
">",
"filemtime",
"(",
"$",
"path",
".",
"'.gch'",
")",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"system",
"(",
"$",
"command",
",",
"'stdout'",
",",
"'compile-header'",
")",
";",
"}",
"}",
"}",
"}"
] | Pre-compile headers to speed up compilation. | [
"Pre",
"-",
"compile",
"headers",
"to",
"speed",
"up",
"compilation",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L518-L547 | train |
phalcon/zephir | Library/Compiler.php | Compiler.api | public function api(array $options = [], $fromGenerate = false)
{
if (!$fromGenerate) {
$this->generate();
}
$templatesPath = $this->templatesPath;
if (null === $templatesPath) {
// fallback
$templatesPath = \dirname(__DIR__).'/templates';
}
$documentator = new Documentation($this->files, $this->config, $templatesPath, $options);
$documentator->setLogger($this->logger);
$this->logger->info('Generating API into '.$documentator->getOutputDirectory());
$documentator->build();
} | php | public function api(array $options = [], $fromGenerate = false)
{
if (!$fromGenerate) {
$this->generate();
}
$templatesPath = $this->templatesPath;
if (null === $templatesPath) {
// fallback
$templatesPath = \dirname(__DIR__).'/templates';
}
$documentator = new Documentation($this->files, $this->config, $templatesPath, $options);
$documentator->setLogger($this->logger);
$this->logger->info('Generating API into '.$documentator->getOutputDirectory());
$documentator->build();
} | [
"public",
"function",
"api",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"fromGenerate",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"fromGenerate",
")",
"{",
"$",
"this",
"->",
"generate",
"(",
")",
";",
"}",
"$",
"templatesPath",
"=",
"$",
"this",
"->",
"templatesPath",
";",
"if",
"(",
"null",
"===",
"$",
"templatesPath",
")",
"{",
"// fallback",
"$",
"templatesPath",
"=",
"\\",
"dirname",
"(",
"__DIR__",
")",
".",
"'/templates'",
";",
"}",
"$",
"documentator",
"=",
"new",
"Documentation",
"(",
"$",
"this",
"->",
"files",
",",
"$",
"this",
"->",
"config",
",",
"$",
"templatesPath",
",",
"$",
"options",
")",
";",
"$",
"documentator",
"->",
"setLogger",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Generating API into '",
".",
"$",
"documentator",
"->",
"getOutputDirectory",
"(",
")",
")",
";",
"$",
"documentator",
"->",
"build",
"(",
")",
";",
"}"
] | Generate a HTML API.
@param array $options
@param bool $fromGenerate
@throws ConfigException
@throws Exception | [
"Generate",
"a",
"HTML",
"API",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L928-L945 | train |
phalcon/zephir | Library/Compiler.php | Compiler.stubs | public function stubs($fromGenerate = false)
{
if (!$fromGenerate) {
$this->generate();
}
$this->logger->info('Generating stubs...');
$stubsGenerator = new Stubs\Generator($this->files, $this->config);
$path = $this->config->get('path', 'stubs');
$path = str_replace('%version%', $this->config->get('version'), $path);
$path = str_replace('%namespace%', ucfirst($this->config->get('namespace')), $path);
$stubsGenerator->generate($path);
} | php | public function stubs($fromGenerate = false)
{
if (!$fromGenerate) {
$this->generate();
}
$this->logger->info('Generating stubs...');
$stubsGenerator = new Stubs\Generator($this->files, $this->config);
$path = $this->config->get('path', 'stubs');
$path = str_replace('%version%', $this->config->get('version'), $path);
$path = str_replace('%namespace%', ucfirst($this->config->get('namespace')), $path);
$stubsGenerator->generate($path);
} | [
"public",
"function",
"stubs",
"(",
"$",
"fromGenerate",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"fromGenerate",
")",
"{",
"$",
"this",
"->",
"generate",
"(",
")",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Generating stubs...'",
")",
";",
"$",
"stubsGenerator",
"=",
"new",
"Stubs",
"\\",
"Generator",
"(",
"$",
"this",
"->",
"files",
",",
"$",
"this",
"->",
"config",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'path'",
",",
"'stubs'",
")",
";",
"$",
"path",
"=",
"str_replace",
"(",
"'%version%'",
",",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'version'",
")",
",",
"$",
"path",
")",
";",
"$",
"path",
"=",
"str_replace",
"(",
"'%namespace%'",
",",
"ucfirst",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'namespace'",
")",
")",
",",
"$",
"path",
")",
";",
"$",
"stubsGenerator",
"->",
"generate",
"(",
"$",
"path",
")",
";",
"}"
] | Generate IDE stubs.
@param bool $fromGenerate
@throws Exception | [
"Generate",
"IDE",
"stubs",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L954-L968 | train |
phalcon/zephir | Library/Compiler.php | Compiler.processCodeInjection | public function processCodeInjection(array $entries, $section = 'request')
{
$codes = [];
$includes = [];
if (isset($entries[$section])) {
foreach ($entries[$section] as $entry) {
if (isset($entry['code']) && !empty($entry['code'])) {
$codes[] = $entry['code'].';';
}
if (isset($entry['include']) && !empty($entry['include'])) {
$includes[] = '#include "'.$entry['include'].'"';
}
}
}
return [implode(PHP_EOL, $includes), implode("\n\t", $codes)];
} | php | public function processCodeInjection(array $entries, $section = 'request')
{
$codes = [];
$includes = [];
if (isset($entries[$section])) {
foreach ($entries[$section] as $entry) {
if (isset($entry['code']) && !empty($entry['code'])) {
$codes[] = $entry['code'].';';
}
if (isset($entry['include']) && !empty($entry['include'])) {
$includes[] = '#include "'.$entry['include'].'"';
}
}
}
return [implode(PHP_EOL, $includes), implode("\n\t", $codes)];
} | [
"public",
"function",
"processCodeInjection",
"(",
"array",
"$",
"entries",
",",
"$",
"section",
"=",
"'request'",
")",
"{",
"$",
"codes",
"=",
"[",
"]",
";",
"$",
"includes",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"entries",
"[",
"$",
"section",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"entries",
"[",
"$",
"section",
"]",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"entry",
"[",
"'code'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"entry",
"[",
"'code'",
"]",
")",
")",
"{",
"$",
"codes",
"[",
"]",
"=",
"$",
"entry",
"[",
"'code'",
"]",
".",
"';'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"entry",
"[",
"'include'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"entry",
"[",
"'include'",
"]",
")",
")",
"{",
"$",
"includes",
"[",
"]",
"=",
"'#include \"'",
".",
"$",
"entry",
"[",
"'include'",
"]",
".",
"'\"'",
";",
"}",
"}",
"}",
"return",
"[",
"implode",
"(",
"PHP_EOL",
",",
"$",
"includes",
")",
",",
"implode",
"(",
"\"\\n\\t\"",
",",
"$",
"codes",
")",
"]",
";",
"}"
] | Process extension code injection.
@param array $entries
@param string $section
@return array | [
"Process",
"extension",
"code",
"injection",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L1422-L1439 | train |
phalcon/zephir | Library/Compiler.php | Compiler.generatePackageDependenciesM4 | public function generatePackageDependenciesM4($contentM4)
{
$packageDependencies = $this->config->get('package-dependencies');
if (\is_array($packageDependencies)) {
$pkgconfigM4 = $this->backend->getTemplateFileContents('pkg-config.m4');
$pkgconfigCheckM4 = $this->backend->getTemplateFileContents('pkg-config-check.m4');
$extraCFlags = '';
foreach ($packageDependencies as $pkg => $version) {
$pkgM4Buf = $pkgconfigCheckM4;
$operator = '=';
$operatorCmd = '--exact-version';
$ar = explode('=', $version);
if (1 == \count($ar)) {
if ('*' == $version) {
$version = '0.0.0';
$operator = '>=';
$operatorCmd = '--atleast-version';
}
} else {
switch ($ar[0]) {
case '<':
$operator = '<=';
$operatorCmd = '--max-version';
$version = trim($ar[1]);
break;
case '>':
$operator = '>=';
$operatorCmd = '--atleast-version';
$version = trim($ar[1]);
break;
default:
$version = trim($ar[1]);
break;
}
}
$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);
}
$pkgconfigM4 .= $pkgM4Buf;
$extraCFlags .= '$PHP_'.strtoupper($pkg).'_INCS ';
}
$contentM4 = str_replace('%PROJECT_EXTRA_CFLAGS%', '%PROJECT_EXTRA_CFLAGS% '.$extraCFlags, $contentM4);
$contentM4 = str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', $pkgconfigM4, $contentM4);
return $contentM4;
}
$contentM4 = str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', '', $contentM4);
return $contentM4;
} | php | public function generatePackageDependenciesM4($contentM4)
{
$packageDependencies = $this->config->get('package-dependencies');
if (\is_array($packageDependencies)) {
$pkgconfigM4 = $this->backend->getTemplateFileContents('pkg-config.m4');
$pkgconfigCheckM4 = $this->backend->getTemplateFileContents('pkg-config-check.m4');
$extraCFlags = '';
foreach ($packageDependencies as $pkg => $version) {
$pkgM4Buf = $pkgconfigCheckM4;
$operator = '=';
$operatorCmd = '--exact-version';
$ar = explode('=', $version);
if (1 == \count($ar)) {
if ('*' == $version) {
$version = '0.0.0';
$operator = '>=';
$operatorCmd = '--atleast-version';
}
} else {
switch ($ar[0]) {
case '<':
$operator = '<=';
$operatorCmd = '--max-version';
$version = trim($ar[1]);
break;
case '>':
$operator = '>=';
$operatorCmd = '--atleast-version';
$version = trim($ar[1]);
break;
default:
$version = trim($ar[1]);
break;
}
}
$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);
}
$pkgconfigM4 .= $pkgM4Buf;
$extraCFlags .= '$PHP_'.strtoupper($pkg).'_INCS ';
}
$contentM4 = str_replace('%PROJECT_EXTRA_CFLAGS%', '%PROJECT_EXTRA_CFLAGS% '.$extraCFlags, $contentM4);
$contentM4 = str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', $pkgconfigM4, $contentM4);
return $contentM4;
}
$contentM4 = str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', '', $contentM4);
return $contentM4;
} | [
"public",
"function",
"generatePackageDependenciesM4",
"(",
"$",
"contentM4",
")",
"{",
"$",
"packageDependencies",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'package-dependencies'",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"packageDependencies",
")",
")",
"{",
"$",
"pkgconfigM4",
"=",
"$",
"this",
"->",
"backend",
"->",
"getTemplateFileContents",
"(",
"'pkg-config.m4'",
")",
";",
"$",
"pkgconfigCheckM4",
"=",
"$",
"this",
"->",
"backend",
"->",
"getTemplateFileContents",
"(",
"'pkg-config-check.m4'",
")",
";",
"$",
"extraCFlags",
"=",
"''",
";",
"foreach",
"(",
"$",
"packageDependencies",
"as",
"$",
"pkg",
"=>",
"$",
"version",
")",
"{",
"$",
"pkgM4Buf",
"=",
"$",
"pkgconfigCheckM4",
";",
"$",
"operator",
"=",
"'='",
";",
"$",
"operatorCmd",
"=",
"'--exact-version'",
";",
"$",
"ar",
"=",
"explode",
"(",
"'='",
",",
"$",
"version",
")",
";",
"if",
"(",
"1",
"==",
"\\",
"count",
"(",
"$",
"ar",
")",
")",
"{",
"if",
"(",
"'*'",
"==",
"$",
"version",
")",
"{",
"$",
"version",
"=",
"'0.0.0'",
";",
"$",
"operator",
"=",
"'>='",
";",
"$",
"operatorCmd",
"=",
"'--atleast-version'",
";",
"}",
"}",
"else",
"{",
"switch",
"(",
"$",
"ar",
"[",
"0",
"]",
")",
"{",
"case",
"'<'",
":",
"$",
"operator",
"=",
"'<='",
";",
"$",
"operatorCmd",
"=",
"'--max-version'",
";",
"$",
"version",
"=",
"trim",
"(",
"$",
"ar",
"[",
"1",
"]",
")",
";",
"break",
";",
"case",
"'>'",
":",
"$",
"operator",
"=",
"'>='",
";",
"$",
"operatorCmd",
"=",
"'--atleast-version'",
";",
"$",
"version",
"=",
"trim",
"(",
"$",
"ar",
"[",
"1",
"]",
")",
";",
"break",
";",
"default",
":",
"$",
"version",
"=",
"trim",
"(",
"$",
"ar",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"}",
"$",
"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",
")",
";",
"}",
"$",
"pkgconfigM4",
".=",
"$",
"pkgM4Buf",
";",
"$",
"extraCFlags",
".=",
"'$PHP_'",
".",
"strtoupper",
"(",
"$",
"pkg",
")",
".",
"'_INCS '",
";",
"}",
"$",
"contentM4",
"=",
"str_replace",
"(",
"'%PROJECT_EXTRA_CFLAGS%'",
",",
"'%PROJECT_EXTRA_CFLAGS% '",
".",
"$",
"extraCFlags",
",",
"$",
"contentM4",
")",
";",
"$",
"contentM4",
"=",
"str_replace",
"(",
"'%PROJECT_PACKAGE_DEPENDENCIES%'",
",",
"$",
"pkgconfigM4",
",",
"$",
"contentM4",
")",
";",
"return",
"$",
"contentM4",
";",
"}",
"$",
"contentM4",
"=",
"str_replace",
"(",
"'%PROJECT_PACKAGE_DEPENDENCIES%'",
",",
"''",
",",
"$",
"contentM4",
")",
";",
"return",
"$",
"contentM4",
";",
"}"
] | Generate package-dependencies config for m4.
TODO: Move the template depending part to backend?
@param string $contentM4
@return string | [
"Generate",
"package",
"-",
"dependencies",
"config",
"for",
"m4",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L1892-L1954 | train |
phalcon/zephir | Library/Compiler.php | Compiler.preCompile | private function preCompile($filePath)
{
if (!$this->parserManager->isAvailable()) {
throw new IllegalStateException($this->parserManager->requirements());
}
if (preg_match('#\.zep$#', $filePath)) {
$className = str_replace(\DIRECTORY_SEPARATOR, '\\', $filePath);
$className = preg_replace('#.zep$#', '', $className);
$className = implode('\\', array_map('ucfirst', explode('\\', $className)));
$compilerFile = $this->compilerFileFactory->create($className, $filePath);
$compilerFile->preCompile($this);
$this->files[$className] = $compilerFile;
$this->definitions[$className] = $compilerFile->getClassDefinition();
}
} | php | private function preCompile($filePath)
{
if (!$this->parserManager->isAvailable()) {
throw new IllegalStateException($this->parserManager->requirements());
}
if (preg_match('#\.zep$#', $filePath)) {
$className = str_replace(\DIRECTORY_SEPARATOR, '\\', $filePath);
$className = preg_replace('#.zep$#', '', $className);
$className = implode('\\', array_map('ucfirst', explode('\\', $className)));
$compilerFile = $this->compilerFileFactory->create($className, $filePath);
$compilerFile->preCompile($this);
$this->files[$className] = $compilerFile;
$this->definitions[$className] = $compilerFile->getClassDefinition();
}
} | [
"private",
"function",
"preCompile",
"(",
"$",
"filePath",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parserManager",
"->",
"isAvailable",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"$",
"this",
"->",
"parserManager",
"->",
"requirements",
"(",
")",
")",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'#\\.zep$#'",
",",
"$",
"filePath",
")",
")",
"{",
"$",
"className",
"=",
"str_replace",
"(",
"\\",
"DIRECTORY_SEPARATOR",
",",
"'\\\\'",
",",
"$",
"filePath",
")",
";",
"$",
"className",
"=",
"preg_replace",
"(",
"'#.zep$#'",
",",
"''",
",",
"$",
"className",
")",
";",
"$",
"className",
"=",
"implode",
"(",
"'\\\\'",
",",
"array_map",
"(",
"'ucfirst'",
",",
"explode",
"(",
"'\\\\'",
",",
"$",
"className",
")",
")",
")",
";",
"$",
"compilerFile",
"=",
"$",
"this",
"->",
"compilerFileFactory",
"->",
"create",
"(",
"$",
"className",
",",
"$",
"filePath",
")",
";",
"$",
"compilerFile",
"->",
"preCompile",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"files",
"[",
"$",
"className",
"]",
"=",
"$",
"compilerFile",
";",
"$",
"this",
"->",
"definitions",
"[",
"$",
"className",
"]",
"=",
"$",
"compilerFile",
"->",
"getClassDefinition",
"(",
")",
";",
"}",
"}"
] | Pre-compiles classes creating a CompilerFile definition.
@param string $filePath
@throws IllegalStateException | [
"Pre",
"-",
"compiles",
"classes",
"creating",
"a",
"CompilerFile",
"definition",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L1963-L1981 | train |
phalcon/zephir | Library/Compiler.php | Compiler.recursivePreCompile | private function recursivePreCompile($path)
{
if (!is_dir($path)) {
throw new InvalidArgumentException(
sprintf(
"An invalid path was passed to the compiler. Unable to obtain the '%s%s%s' directory.",
getcwd(),
\DIRECTORY_SEPARATOR,
$path
)
);
}
/*
* Pre compile all files.
*/
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path),
\RecursiveIteratorIterator::SELF_FIRST
);
$files = [];
foreach ($iterator as $item) {
if (!$item->isDir()) {
$files[] = $item->getPathname();
}
}
sort($files, SORT_STRING);
foreach ($files as $file) {
$this->preCompile($file);
}
} | php | private function recursivePreCompile($path)
{
if (!is_dir($path)) {
throw new InvalidArgumentException(
sprintf(
"An invalid path was passed to the compiler. Unable to obtain the '%s%s%s' directory.",
getcwd(),
\DIRECTORY_SEPARATOR,
$path
)
);
}
/*
* Pre compile all files.
*/
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path),
\RecursiveIteratorIterator::SELF_FIRST
);
$files = [];
foreach ($iterator as $item) {
if (!$item->isDir()) {
$files[] = $item->getPathname();
}
}
sort($files, SORT_STRING);
foreach ($files as $file) {
$this->preCompile($file);
}
} | [
"private",
"function",
"recursivePreCompile",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"An invalid path was passed to the compiler. Unable to obtain the '%s%s%s' directory.\"",
",",
"getcwd",
"(",
")",
",",
"\\",
"DIRECTORY_SEPARATOR",
",",
"$",
"path",
")",
")",
";",
"}",
"/*\n * Pre compile all files.\n */",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"SELF_FIRST",
")",
";",
"$",
"files",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"item",
"->",
"getPathname",
"(",
")",
";",
"}",
"}",
"sort",
"(",
"$",
"files",
",",
"SORT_STRING",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"preCompile",
"(",
"$",
"file",
")",
";",
"}",
"}"
] | Recursively pre-compiles all sources found in the given path.
@param string $path
@throws IllegalStateException
@throws InvalidArgumentException | [
"Recursively",
"pre",
"-",
"compiles",
"all",
"sources",
"found",
"in",
"the",
"given",
"path",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L1991-L2023 | train |
phalcon/zephir | Library/Compiler.php | Compiler.recursiveDeletePath | private function recursiveDeletePath($path, $mask)
{
if (!file_exists($path) || !is_dir($path) || !is_readable($path)) {
$this->logger->warning("Directory '{$path}' is not readable. Skip...");
return;
}
$objects = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path),
\RecursiveIteratorIterator::SELF_FIRST
);
foreach ($objects as $name => $object) {
if (preg_match($mask, $name)) {
@unlink($name);
}
}
} | php | private function recursiveDeletePath($path, $mask)
{
if (!file_exists($path) || !is_dir($path) || !is_readable($path)) {
$this->logger->warning("Directory '{$path}' is not readable. Skip...");
return;
}
$objects = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path),
\RecursiveIteratorIterator::SELF_FIRST
);
foreach ($objects as $name => $object) {
if (preg_match($mask, $name)) {
@unlink($name);
}
}
} | [
"private",
"function",
"recursiveDeletePath",
"(",
"$",
"path",
",",
"$",
"mask",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
"||",
"!",
"is_dir",
"(",
"$",
"path",
")",
"||",
"!",
"is_readable",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"warning",
"(",
"\"Directory '{$path}' is not readable. Skip...\"",
")",
";",
"return",
";",
"}",
"$",
"objects",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"SELF_FIRST",
")",
";",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"name",
"=>",
"$",
"object",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"mask",
",",
"$",
"name",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"name",
")",
";",
"}",
"}",
"}"
] | Recursively deletes files in a specified location.
@deprecated
@param string $path Directory to deletes files
@param string $mask Regular expression to deletes files | [
"Recursively",
"deletes",
"files",
"in",
"a",
"specified",
"location",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L2076-L2094 | train |
phalcon/zephir | Library/Compiler.php | Compiler.loadConstantsSources | private function loadConstantsSources($constantsSources)
{
foreach ($constantsSources as $constantsSource) {
if (!file_exists($constantsSource)) {
throw new Exception("File '".$constantsSource."' with constants definitions");
}
foreach (file($constantsSource) as $line) {
if (preg_match('/^\#define[ \t]+([A-Z0-9\_]+)[ \t]+([0-9]+)/', $line, $matches)) {
$this->constants[$matches[1]] = ['int', $matches[2]];
continue;
}
if (preg_match('/^\#define[ \t]+([A-Z0-9\_]+)[ \t]+(\'(.){1}\')/', $line, $matches)) {
$this->constants[$matches[1]] = ['char', $matches[3]];
}
}
}
} | php | private function loadConstantsSources($constantsSources)
{
foreach ($constantsSources as $constantsSource) {
if (!file_exists($constantsSource)) {
throw new Exception("File '".$constantsSource."' with constants definitions");
}
foreach (file($constantsSource) as $line) {
if (preg_match('/^\#define[ \t]+([A-Z0-9\_]+)[ \t]+([0-9]+)/', $line, $matches)) {
$this->constants[$matches[1]] = ['int', $matches[2]];
continue;
}
if (preg_match('/^\#define[ \t]+([A-Z0-9\_]+)[ \t]+(\'(.){1}\')/', $line, $matches)) {
$this->constants[$matches[1]] = ['char', $matches[3]];
}
}
}
} | [
"private",
"function",
"loadConstantsSources",
"(",
"$",
"constantsSources",
")",
"{",
"foreach",
"(",
"$",
"constantsSources",
"as",
"$",
"constantsSource",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"constantsSource",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"File '\"",
".",
"$",
"constantsSource",
".",
"\"' with constants definitions\"",
")",
";",
"}",
"foreach",
"(",
"file",
"(",
"$",
"constantsSource",
")",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^\\#define[ \\t]+([A-Z0-9\\_]+)[ \\t]+([0-9]+)/'",
",",
"$",
"line",
",",
"$",
"matches",
")",
")",
"{",
"$",
"this",
"->",
"constants",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
"=",
"[",
"'int'",
",",
"$",
"matches",
"[",
"2",
"]",
"]",
";",
"continue",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^\\#define[ \\t]+([A-Z0-9\\_]+)[ \\t]+(\\'(.){1}\\')/'",
",",
"$",
"line",
",",
"$",
"matches",
")",
")",
"{",
"$",
"this",
"->",
"constants",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
"=",
"[",
"'char'",
",",
"$",
"matches",
"[",
"3",
"]",
"]",
";",
"}",
"}",
"}",
"}"
] | Registers C-constants as PHP constants from a C-file.
@param array $constantsSources
@throws Exception | [
"Registers",
"C",
"-",
"constants",
"as",
"PHP",
"constants",
"from",
"a",
"C",
"-",
"file",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L2103-L2120 | train |
phalcon/zephir | Library/Compiler.php | Compiler.processAddSources | private function processAddSources($sources, $project)
{
$groupSources = [];
foreach ($sources as $source) {
$dirName = str_replace(\DIRECTORY_SEPARATOR, '/', \dirname($source));
if (!isset($groupSources[$dirName])) {
$groupSources[$dirName] = [];
}
$groupSources[$dirName][] = basename($source);
}
$groups = [];
foreach ($groupSources as $dirname => $files) {
$groups[] = 'ADD_SOURCES(configure_module_dirname + "/'.$dirname.'", "'.
implode(' ', $files).'", "'.$project.'");';
}
return $groups;
} | php | private function processAddSources($sources, $project)
{
$groupSources = [];
foreach ($sources as $source) {
$dirName = str_replace(\DIRECTORY_SEPARATOR, '/', \dirname($source));
if (!isset($groupSources[$dirName])) {
$groupSources[$dirName] = [];
}
$groupSources[$dirName][] = basename($source);
}
$groups = [];
foreach ($groupSources as $dirname => $files) {
$groups[] = 'ADD_SOURCES(configure_module_dirname + "/'.$dirname.'", "'.
implode(' ', $files).'", "'.$project.'");';
}
return $groups;
} | [
"private",
"function",
"processAddSources",
"(",
"$",
"sources",
",",
"$",
"project",
")",
"{",
"$",
"groupSources",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sources",
"as",
"$",
"source",
")",
"{",
"$",
"dirName",
"=",
"str_replace",
"(",
"\\",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"\\",
"dirname",
"(",
"$",
"source",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"groupSources",
"[",
"$",
"dirName",
"]",
")",
")",
"{",
"$",
"groupSources",
"[",
"$",
"dirName",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"groupSources",
"[",
"$",
"dirName",
"]",
"[",
"]",
"=",
"basename",
"(",
"$",
"source",
")",
";",
"}",
"$",
"groups",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"groupSources",
"as",
"$",
"dirname",
"=>",
"$",
"files",
")",
"{",
"$",
"groups",
"[",
"]",
"=",
"'ADD_SOURCES(configure_module_dirname + \"/'",
".",
"$",
"dirname",
".",
"'\", \"'",
".",
"implode",
"(",
"' '",
",",
"$",
"files",
")",
".",
"'\", \"'",
".",
"$",
"project",
".",
"'\");'",
";",
"}",
"return",
"$",
"groups",
";",
"}"
] | Process config.w32 sections.
@param array $sources
@param string $project
@return array | [
"Process",
"config",
".",
"w32",
"sections",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L2130-L2147 | train |
phalcon/zephir | Library/Compiler.php | Compiler.assertRequiredExtensionsIsPresent | private function assertRequiredExtensionsIsPresent()
{
$extensionRequires = $this->config->get('extensions', 'requires');
if (true === empty($extensionRequires)) {
return;
}
$extensions = [];
foreach ($extensionRequires as $key => $value) {
if (false === \extension_loaded($value)) {
$extensions[] = $value;
}
}
if (false === empty($extensions)) {
throw new RuntimeException(
sprintf(
'Could not load extension: %s. You must add extensions above before build this extension.',
implode(', ', $extensions)
)
);
}
} | php | private function assertRequiredExtensionsIsPresent()
{
$extensionRequires = $this->config->get('extensions', 'requires');
if (true === empty($extensionRequires)) {
return;
}
$extensions = [];
foreach ($extensionRequires as $key => $value) {
if (false === \extension_loaded($value)) {
$extensions[] = $value;
}
}
if (false === empty($extensions)) {
throw new RuntimeException(
sprintf(
'Could not load extension: %s. You must add extensions above before build this extension.',
implode(', ', $extensions)
)
);
}
} | [
"private",
"function",
"assertRequiredExtensionsIsPresent",
"(",
")",
"{",
"$",
"extensionRequires",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'extensions'",
",",
"'requires'",
")",
";",
"if",
"(",
"true",
"===",
"empty",
"(",
"$",
"extensionRequires",
")",
")",
"{",
"return",
";",
"}",
"$",
"extensions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"extensionRequires",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"false",
"===",
"\\",
"extension_loaded",
"(",
"$",
"value",
")",
")",
"{",
"$",
"extensions",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"false",
"===",
"empty",
"(",
"$",
"extensions",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Could not load extension: %s. You must add extensions above before build this extension.'",
",",
"implode",
"(",
"', '",
",",
"$",
"extensions",
")",
")",
")",
";",
"}",
"}"
] | Ensure that required extensions is present.
@throws RuntimeException | [
"Ensure",
"that",
"required",
"extensions",
"is",
"present",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L2154-L2176 | train |
phalcon/zephir | Library/Compiler.php | Compiler.checkKernelFile | private function checkKernelFile($src, $dst)
{
if (preg_match('#kernels/ZendEngine[2-9]/concat\.#', $src)) {
return true;
}
if (!file_exists($dst)) {
return false;
}
return md5_file($src) == md5_file($dst);
} | php | private function checkKernelFile($src, $dst)
{
if (preg_match('#kernels/ZendEngine[2-9]/concat\.#', $src)) {
return true;
}
if (!file_exists($dst)) {
return false;
}
return md5_file($src) == md5_file($dst);
} | [
"private",
"function",
"checkKernelFile",
"(",
"$",
"src",
",",
"$",
"dst",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#kernels/ZendEngine[2-9]/concat\\.#'",
",",
"$",
"src",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dst",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"md5_file",
"(",
"$",
"src",
")",
"==",
"md5_file",
"(",
"$",
"dst",
")",
";",
"}"
] | Checks if a file must be copied.
@param string $src
@param string $dst
@return bool | [
"Checks",
"if",
"a",
"file",
"must",
"be",
"copied",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L2186-L2197 | train |
phalcon/zephir | Library/Compiler.php | Compiler.checkKernelFiles | private function checkKernelFiles()
{
$kernelPath = 'ext'.\DIRECTORY_SEPARATOR.'kernel';
if (!file_exists($kernelPath)) {
if (!mkdir($kernelPath, 0775, true)) {
throw new Exception("Cannot create kernel directory: {$kernelPath}");
}
}
$kernelPath = realpath($kernelPath);
$sourceKernelPath = $this->backend->getInternalKernelPath();
$configured = $this->recursiveProcess(
$sourceKernelPath,
$kernelPath,
'@.*\.[ch]$@',
[$this, 'checkKernelFile']
);
if (!$configured) {
$this->logger->info('Cleaning old kernel files...');
$this->recursiveDeletePath($kernelPath, '@^.*\.[lcho]$@');
@mkdir($kernelPath);
$this->logger->info('Copying new kernel files...');
$this->recursiveProcess($sourceKernelPath, $kernelPath, '@^.*\.[ch]$@');
}
return !$configured;
} | php | private function checkKernelFiles()
{
$kernelPath = 'ext'.\DIRECTORY_SEPARATOR.'kernel';
if (!file_exists($kernelPath)) {
if (!mkdir($kernelPath, 0775, true)) {
throw new Exception("Cannot create kernel directory: {$kernelPath}");
}
}
$kernelPath = realpath($kernelPath);
$sourceKernelPath = $this->backend->getInternalKernelPath();
$configured = $this->recursiveProcess(
$sourceKernelPath,
$kernelPath,
'@.*\.[ch]$@',
[$this, 'checkKernelFile']
);
if (!$configured) {
$this->logger->info('Cleaning old kernel files...');
$this->recursiveDeletePath($kernelPath, '@^.*\.[lcho]$@');
@mkdir($kernelPath);
$this->logger->info('Copying new kernel files...');
$this->recursiveProcess($sourceKernelPath, $kernelPath, '@^.*\.[ch]$@');
}
return !$configured;
} | [
"private",
"function",
"checkKernelFiles",
"(",
")",
"{",
"$",
"kernelPath",
"=",
"'ext'",
".",
"\\",
"DIRECTORY_SEPARATOR",
".",
"'kernel'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"kernelPath",
")",
")",
"{",
"if",
"(",
"!",
"mkdir",
"(",
"$",
"kernelPath",
",",
"0775",
",",
"true",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Cannot create kernel directory: {$kernelPath}\"",
")",
";",
"}",
"}",
"$",
"kernelPath",
"=",
"realpath",
"(",
"$",
"kernelPath",
")",
";",
"$",
"sourceKernelPath",
"=",
"$",
"this",
"->",
"backend",
"->",
"getInternalKernelPath",
"(",
")",
";",
"$",
"configured",
"=",
"$",
"this",
"->",
"recursiveProcess",
"(",
"$",
"sourceKernelPath",
",",
"$",
"kernelPath",
",",
"'@.*\\.[ch]$@'",
",",
"[",
"$",
"this",
",",
"'checkKernelFile'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"configured",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Cleaning old kernel files...'",
")",
";",
"$",
"this",
"->",
"recursiveDeletePath",
"(",
"$",
"kernelPath",
",",
"'@^.*\\.[lcho]$@'",
")",
";",
"@",
"mkdir",
"(",
"$",
"kernelPath",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Copying new kernel files...'",
")",
";",
"$",
"this",
"->",
"recursiveProcess",
"(",
"$",
"sourceKernelPath",
",",
"$",
"kernelPath",
",",
"'@^.*\\.[ch]$@'",
")",
";",
"}",
"return",
"!",
"$",
"configured",
";",
"}"
] | Checks which files in the base kernel must be copied.
@throws Exception
@return bool | [
"Checks",
"which",
"files",
"in",
"the",
"base",
"kernel",
"must",
"be",
"copied",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L2206-L2237 | train |
phalcon/zephir | Library/Compiler.php | Compiler.checkDirectory | private function checkDirectory()
{
$namespace = $this->config->get('namespace');
if (!$namespace) {
// TODO: Add more user friendly message.
// For example assume if the user call the command from the wrong dir
throw new Exception('Extension namespace cannot be loaded');
}
if (!\is_string($namespace)) {
throw new Exception('Extension namespace is invalid');
}
if (!$this->filesystem->isInitialized()) {
$this->filesystem->initialize();
}
if (!$this->filesystem->exists('.')) {
if (!$this->checkIfPhpized()) {
$this->logger->info(
'Zephir version has changed, use "zephir fullclean" to perform a full clean of the project'
);
}
$this->filesystem->makeDirectory('.');
}
return $namespace;
} | php | private function checkDirectory()
{
$namespace = $this->config->get('namespace');
if (!$namespace) {
// TODO: Add more user friendly message.
// For example assume if the user call the command from the wrong dir
throw new Exception('Extension namespace cannot be loaded');
}
if (!\is_string($namespace)) {
throw new Exception('Extension namespace is invalid');
}
if (!$this->filesystem->isInitialized()) {
$this->filesystem->initialize();
}
if (!$this->filesystem->exists('.')) {
if (!$this->checkIfPhpized()) {
$this->logger->info(
'Zephir version has changed, use "zephir fullclean" to perform a full clean of the project'
);
}
$this->filesystem->makeDirectory('.');
}
return $namespace;
} | [
"private",
"function",
"checkDirectory",
"(",
")",
"{",
"$",
"namespace",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'namespace'",
")",
";",
"if",
"(",
"!",
"$",
"namespace",
")",
"{",
"// TODO: Add more user friendly message.",
"// For example assume if the user call the command from the wrong dir",
"throw",
"new",
"Exception",
"(",
"'Extension namespace cannot be loaded'",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"namespace",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Extension namespace is invalid'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"filesystem",
"->",
"isInitialized",
"(",
")",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"initialize",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"filesystem",
"->",
"exists",
"(",
"'.'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"checkIfPhpized",
"(",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Zephir version has changed, use \"zephir fullclean\" to perform a full clean of the project'",
")",
";",
"}",
"$",
"this",
"->",
"filesystem",
"->",
"makeDirectory",
"(",
"'.'",
")",
";",
"}",
"return",
"$",
"namespace",
";",
"}"
] | Checks if the current directory is a valid Zephir project.
@throws Exception
@return string | [
"Checks",
"if",
"the",
"current",
"directory",
"is",
"a",
"valid",
"Zephir",
"project",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L2246-L2274 | train |
phalcon/zephir | Library/Compiler.php | Compiler.getGccVersion | private function getGccVersion()
{
if (is_windows()) {
return '0.0.0';
}
if ($this->filesystem->exists('gcc-version')) {
return $this->filesystem->read('gcc-version');
}
$this->filesystem->system('gcc -dumpversion', 'stdout', 'gcc-version');
$lines = $this->filesystem->file('gcc-version');
$lines = array_filter($lines);
$lastLine = $lines[\count($lines) - 1];
if (preg_match('/\d+\.\d+\.\d+/', $lastLine, $matches)) {
return $matches[0];
}
return '0.0.0';
} | php | private function getGccVersion()
{
if (is_windows()) {
return '0.0.0';
}
if ($this->filesystem->exists('gcc-version')) {
return $this->filesystem->read('gcc-version');
}
$this->filesystem->system('gcc -dumpversion', 'stdout', 'gcc-version');
$lines = $this->filesystem->file('gcc-version');
$lines = array_filter($lines);
$lastLine = $lines[\count($lines) - 1];
if (preg_match('/\d+\.\d+\.\d+/', $lastLine, $matches)) {
return $matches[0];
}
return '0.0.0';
} | [
"private",
"function",
"getGccVersion",
"(",
")",
"{",
"if",
"(",
"is_windows",
"(",
")",
")",
"{",
"return",
"'0.0.0'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"filesystem",
"->",
"exists",
"(",
"'gcc-version'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"filesystem",
"->",
"read",
"(",
"'gcc-version'",
")",
";",
"}",
"$",
"this",
"->",
"filesystem",
"->",
"system",
"(",
"'gcc -dumpversion'",
",",
"'stdout'",
",",
"'gcc-version'",
")",
";",
"$",
"lines",
"=",
"$",
"this",
"->",
"filesystem",
"->",
"file",
"(",
"'gcc-version'",
")",
";",
"$",
"lines",
"=",
"array_filter",
"(",
"$",
"lines",
")",
";",
"$",
"lastLine",
"=",
"$",
"lines",
"[",
"\\",
"count",
"(",
"$",
"lines",
")",
"-",
"1",
"]",
";",
"if",
"(",
"preg_match",
"(",
"'/\\d+\\.\\d+\\.\\d+/'",
",",
"$",
"lastLine",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"return",
"'0.0.0'",
";",
"}"
] | Returns current GCC version.
@return string | [
"Returns",
"current",
"GCC",
"version",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Compiler.php#L2281-L2301 | train |
phalcon/zephir | Library/CacheManager.php | CacheManager.getFunctionCache | public function getFunctionCache()
{
if (!$this->functionCache) {
$this->functionCache = new FunctionCache($this->gatherer);
}
return $this->functionCache;
} | php | public function getFunctionCache()
{
if (!$this->functionCache) {
$this->functionCache = new FunctionCache($this->gatherer);
}
return $this->functionCache;
} | [
"public",
"function",
"getFunctionCache",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"functionCache",
")",
"{",
"$",
"this",
"->",
"functionCache",
"=",
"new",
"FunctionCache",
"(",
"$",
"this",
"->",
"gatherer",
")",
";",
"}",
"return",
"$",
"this",
"->",
"functionCache",
";",
"}"
] | Creates or returns an existing function cache.
@return FunctionCache | [
"Creates",
"or",
"returns",
"an",
"existing",
"function",
"cache",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/CacheManager.php#L81-L88 | train |
phalcon/zephir | Library/Parser/Manager.php | Manager.isAvailable | public function isAvailable()
{
return $this->parser->isAvailable() &&
version_compare(self::MINIMUM_PARSER_VERSION, $this->parser->getVersion(), '<=');
} | php | public function isAvailable()
{
return $this->parser->isAvailable() &&
version_compare(self::MINIMUM_PARSER_VERSION, $this->parser->getVersion(), '<=');
} | [
"public",
"function",
"isAvailable",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"parser",
"->",
"isAvailable",
"(",
")",
"&&",
"version_compare",
"(",
"self",
"::",
"MINIMUM_PARSER_VERSION",
",",
"$",
"this",
"->",
"parser",
"->",
"getVersion",
"(",
")",
",",
"'<='",
")",
";",
"}"
] | Check if Zephir Parser available.
@return bool | [
"Check",
"if",
"Zephir",
"Parser",
"available",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Parser/Manager.php#L51-L55 | train |
phalcon/zephir | Library/ArgInfoDefinition.php | ArgInfoDefinition.render | public function render()
{
if ($this->richFormat &&
$this->functionLike->isReturnTypesHintDetermined() &&
$this->functionLike->areReturnTypesCompatible()
) {
$this->richRenderStart();
if (false == $this->hasParameters()) {
$this->codePrinter->output('ZEND_END_ARG_INFO()');
$this->codePrinter->outputBlankLine();
}
} elseif (true == $this->hasParameters()) {
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters()
)
);
}
if (true == $this->hasParameters()) {
$this->renderEnd();
$this->codePrinter->output('ZEND_END_ARG_INFO()');
$this->codePrinter->outputBlankLine();
}
} | php | public function render()
{
if ($this->richFormat &&
$this->functionLike->isReturnTypesHintDetermined() &&
$this->functionLike->areReturnTypesCompatible()
) {
$this->richRenderStart();
if (false == $this->hasParameters()) {
$this->codePrinter->output('ZEND_END_ARG_INFO()');
$this->codePrinter->outputBlankLine();
}
} elseif (true == $this->hasParameters()) {
$this->codePrinter->output(
sprintf(
'ZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)',
$this->name,
(int) $this->returnByRef,
$this->functionLike->getNumberOfRequiredParameters()
)
);
}
if (true == $this->hasParameters()) {
$this->renderEnd();
$this->codePrinter->output('ZEND_END_ARG_INFO()');
$this->codePrinter->outputBlankLine();
}
} | [
"public",
"function",
"render",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"richFormat",
"&&",
"$",
"this",
"->",
"functionLike",
"->",
"isReturnTypesHintDetermined",
"(",
")",
"&&",
"$",
"this",
"->",
"functionLike",
"->",
"areReturnTypesCompatible",
"(",
")",
")",
"{",
"$",
"this",
"->",
"richRenderStart",
"(",
")",
";",
"if",
"(",
"false",
"==",
"$",
"this",
"->",
"hasParameters",
"(",
")",
")",
"{",
"$",
"this",
"->",
"codePrinter",
"->",
"output",
"(",
"'ZEND_END_ARG_INFO()'",
")",
";",
"$",
"this",
"->",
"codePrinter",
"->",
"outputBlankLine",
"(",
")",
";",
"}",
"}",
"elseif",
"(",
"true",
"==",
"$",
"this",
"->",
"hasParameters",
"(",
")",
")",
"{",
"$",
"this",
"->",
"codePrinter",
"->",
"output",
"(",
"sprintf",
"(",
"'ZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)'",
",",
"$",
"this",
"->",
"name",
",",
"(",
"int",
")",
"$",
"this",
"->",
"returnByRef",
",",
"$",
"this",
"->",
"functionLike",
"->",
"getNumberOfRequiredParameters",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"true",
"==",
"$",
"this",
"->",
"hasParameters",
"(",
")",
")",
"{",
"$",
"this",
"->",
"renderEnd",
"(",
")",
";",
"$",
"this",
"->",
"codePrinter",
"->",
"output",
"(",
"'ZEND_END_ARG_INFO()'",
")",
";",
"$",
"this",
"->",
"codePrinter",
"->",
"outputBlankLine",
"(",
")",
";",
"}",
"}"
] | Render argument information.
@throws Exception | [
"Render",
"argument",
"information",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ArgInfoDefinition.php#L91-L120 | train |
phalcon/zephir | Library/FunctionCall.php | FunctionCall.getReflector | public function getReflector($funcName)
{
/*
* Check if the optimizer is already cached
*/
if (!isset(self::$functionReflection[$funcName])) {
try {
$reflectionFunction = new \ReflectionFunction($funcName);
} catch (\ReflectionException $e) {
$reflectionFunction = null;
}
self::$functionReflection[$funcName] = $reflectionFunction;
$this->reflection = $reflectionFunction;
return $reflectionFunction;
}
$reflectionFunction = self::$functionReflection[$funcName];
$this->reflection = $reflectionFunction;
return $reflectionFunction;
} | php | public function getReflector($funcName)
{
/*
* Check if the optimizer is already cached
*/
if (!isset(self::$functionReflection[$funcName])) {
try {
$reflectionFunction = new \ReflectionFunction($funcName);
} catch (\ReflectionException $e) {
$reflectionFunction = null;
}
self::$functionReflection[$funcName] = $reflectionFunction;
$this->reflection = $reflectionFunction;
return $reflectionFunction;
}
$reflectionFunction = self::$functionReflection[$funcName];
$this->reflection = $reflectionFunction;
return $reflectionFunction;
} | [
"public",
"function",
"getReflector",
"(",
"$",
"funcName",
")",
"{",
"/*\n * Check if the optimizer is already cached\n */",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"functionReflection",
"[",
"$",
"funcName",
"]",
")",
")",
"{",
"try",
"{",
"$",
"reflectionFunction",
"=",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"funcName",
")",
";",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"e",
")",
"{",
"$",
"reflectionFunction",
"=",
"null",
";",
"}",
"self",
"::",
"$",
"functionReflection",
"[",
"$",
"funcName",
"]",
"=",
"$",
"reflectionFunction",
";",
"$",
"this",
"->",
"reflection",
"=",
"$",
"reflectionFunction",
";",
"return",
"$",
"reflectionFunction",
";",
"}",
"$",
"reflectionFunction",
"=",
"self",
"::",
"$",
"functionReflection",
"[",
"$",
"funcName",
"]",
";",
"$",
"this",
"->",
"reflection",
"=",
"$",
"reflectionFunction",
";",
"return",
"$",
"reflectionFunction",
";",
"}"
] | Process the ReflectionFunction for the specified function name.
@param string $funcName
@return \ReflectionFunction|null | [
"Process",
"the",
"ReflectionFunction",
"for",
"the",
"specified",
"function",
"name",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/FunctionCall.php#L53-L73 | train |
phalcon/zephir | Library/FunctionCall.php | FunctionCall.functionExists | public function functionExists($functionName, CompilationContext $context)
{
if (\function_exists($functionName)) {
return true;
}
if ($this->isBuiltInFunction($functionName)) {
return true;
}
$internalName = ['f__'.$functionName];
if (isset($context->classDefinition)) {
$lowerNamespace = strtolower($context->classDefinition->getNamespace());
$prefix = 'f_'.str_replace('\\', '_', $lowerNamespace);
$internalName[] = $prefix.'_'.$functionName;
}
foreach ($internalName as $name) {
if (isset($context->compiler->functionDefinitions[$name])) {
return true;
}
}
return false;
} | php | public function functionExists($functionName, CompilationContext $context)
{
if (\function_exists($functionName)) {
return true;
}
if ($this->isBuiltInFunction($functionName)) {
return true;
}
$internalName = ['f__'.$functionName];
if (isset($context->classDefinition)) {
$lowerNamespace = strtolower($context->classDefinition->getNamespace());
$prefix = 'f_'.str_replace('\\', '_', $lowerNamespace);
$internalName[] = $prefix.'_'.$functionName;
}
foreach ($internalName as $name) {
if (isset($context->compiler->functionDefinitions[$name])) {
return true;
}
}
return false;
} | [
"public",
"function",
"functionExists",
"(",
"$",
"functionName",
",",
"CompilationContext",
"$",
"context",
")",
"{",
"if",
"(",
"\\",
"function_exists",
"(",
"$",
"functionName",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isBuiltInFunction",
"(",
"$",
"functionName",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"internalName",
"=",
"[",
"'f__'",
".",
"$",
"functionName",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"context",
"->",
"classDefinition",
")",
")",
"{",
"$",
"lowerNamespace",
"=",
"strtolower",
"(",
"$",
"context",
"->",
"classDefinition",
"->",
"getNamespace",
"(",
")",
")",
";",
"$",
"prefix",
"=",
"'f_'",
".",
"str_replace",
"(",
"'\\\\'",
",",
"'_'",
",",
"$",
"lowerNamespace",
")",
";",
"$",
"internalName",
"[",
"]",
"=",
"$",
"prefix",
".",
"'_'",
".",
"$",
"functionName",
";",
"}",
"foreach",
"(",
"$",
"internalName",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"context",
"->",
"compiler",
"->",
"functionDefinitions",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if a function exists or is a built-in Zephir function.
@param string $functionName
@param CompilationContext $context
@return bool | [
"Checks",
"if",
"a",
"function",
"exists",
"or",
"is",
"a",
"built",
"-",
"in",
"Zephir",
"function",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/FunctionCall.php#L114-L138 | train |
phalcon/zephir | Library/FunctionCall.php | FunctionCall.isReadOnly | protected function isReadOnly($funcName, array $expression)
{
if ($this->isBuiltInFunction($funcName)) {
return false;
}
/*
* These functions are supposed to be read-only but they change parameters ref-count
*/
switch ($funcName) {
case 'min':
case 'max':
case 'array_fill':
case 'array_pad':
case 'call_user_func':
case 'call_user_func_array':
return false;
}
$reflector = $this->getReflector($funcName);
if (!$reflector instanceof \ReflectionFunction) {
return false;
}
$messageFormat = "The number of parameters passed is lesser than the number of required parameters by '%s'";
if (isset($expression['parameters'])) {
/**
* Check if the number of parameters.
*/
$numberParameters = \count($expression['parameters']);
if ('unpack' == $funcName &&
(0 == version_compare(PHP_VERSION, '7.1.0') ||
0 == version_compare(PHP_VERSION, '7.1.1'))
) {
if ($numberParameters < 2) {
throw new CompilerException(sprintf($messageFormat, $funcName), $expression);
}
} else {
if ($numberParameters < $reflector->getNumberOfRequiredParameters()) {
throw new CompilerException(sprintf($messageFormat, $funcName), $expression);
}
}
} else {
if ($reflector->getNumberOfRequiredParameters() > 0) {
throw new CompilerException(sprintf($messageFormat, $funcName), $expression);
}
}
if ($reflector->getNumberOfParameters() > 0) {
foreach ($reflector->getParameters() as $parameter) {
if ($parameter->isPassedByReference()) {
return false;
}
}
}
return true;
} | php | protected function isReadOnly($funcName, array $expression)
{
if ($this->isBuiltInFunction($funcName)) {
return false;
}
/*
* These functions are supposed to be read-only but they change parameters ref-count
*/
switch ($funcName) {
case 'min':
case 'max':
case 'array_fill':
case 'array_pad':
case 'call_user_func':
case 'call_user_func_array':
return false;
}
$reflector = $this->getReflector($funcName);
if (!$reflector instanceof \ReflectionFunction) {
return false;
}
$messageFormat = "The number of parameters passed is lesser than the number of required parameters by '%s'";
if (isset($expression['parameters'])) {
/**
* Check if the number of parameters.
*/
$numberParameters = \count($expression['parameters']);
if ('unpack' == $funcName &&
(0 == version_compare(PHP_VERSION, '7.1.0') ||
0 == version_compare(PHP_VERSION, '7.1.1'))
) {
if ($numberParameters < 2) {
throw new CompilerException(sprintf($messageFormat, $funcName), $expression);
}
} else {
if ($numberParameters < $reflector->getNumberOfRequiredParameters()) {
throw new CompilerException(sprintf($messageFormat, $funcName), $expression);
}
}
} else {
if ($reflector->getNumberOfRequiredParameters() > 0) {
throw new CompilerException(sprintf($messageFormat, $funcName), $expression);
}
}
if ($reflector->getNumberOfParameters() > 0) {
foreach ($reflector->getParameters() as $parameter) {
if ($parameter->isPassedByReference()) {
return false;
}
}
}
return true;
} | [
"protected",
"function",
"isReadOnly",
"(",
"$",
"funcName",
",",
"array",
"$",
"expression",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isBuiltInFunction",
"(",
"$",
"funcName",
")",
")",
"{",
"return",
"false",
";",
"}",
"/*\n * These functions are supposed to be read-only but they change parameters ref-count\n */",
"switch",
"(",
"$",
"funcName",
")",
"{",
"case",
"'min'",
":",
"case",
"'max'",
":",
"case",
"'array_fill'",
":",
"case",
"'array_pad'",
":",
"case",
"'call_user_func'",
":",
"case",
"'call_user_func_array'",
":",
"return",
"false",
";",
"}",
"$",
"reflector",
"=",
"$",
"this",
"->",
"getReflector",
"(",
"$",
"funcName",
")",
";",
"if",
"(",
"!",
"$",
"reflector",
"instanceof",
"\\",
"ReflectionFunction",
")",
"{",
"return",
"false",
";",
"}",
"$",
"messageFormat",
"=",
"\"The number of parameters passed is lesser than the number of required parameters by '%s'\"",
";",
"if",
"(",
"isset",
"(",
"$",
"expression",
"[",
"'parameters'",
"]",
")",
")",
"{",
"/**\n * Check if the number of parameters.\n */",
"$",
"numberParameters",
"=",
"\\",
"count",
"(",
"$",
"expression",
"[",
"'parameters'",
"]",
")",
";",
"if",
"(",
"'unpack'",
"==",
"$",
"funcName",
"&&",
"(",
"0",
"==",
"version_compare",
"(",
"PHP_VERSION",
",",
"'7.1.0'",
")",
"||",
"0",
"==",
"version_compare",
"(",
"PHP_VERSION",
",",
"'7.1.1'",
")",
")",
")",
"{",
"if",
"(",
"$",
"numberParameters",
"<",
"2",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"sprintf",
"(",
"$",
"messageFormat",
",",
"$",
"funcName",
")",
",",
"$",
"expression",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"numberParameters",
"<",
"$",
"reflector",
"->",
"getNumberOfRequiredParameters",
"(",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"sprintf",
"(",
"$",
"messageFormat",
",",
"$",
"funcName",
")",
",",
"$",
"expression",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"reflector",
"->",
"getNumberOfRequiredParameters",
"(",
")",
">",
"0",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"sprintf",
"(",
"$",
"messageFormat",
",",
"$",
"funcName",
")",
",",
"$",
"expression",
")",
";",
"}",
"}",
"if",
"(",
"$",
"reflector",
"->",
"getNumberOfParameters",
"(",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"reflector",
"->",
"getParameters",
"(",
")",
"as",
"$",
"parameter",
")",
"{",
"if",
"(",
"$",
"parameter",
"->",
"isPassedByReference",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | This method gets the reflection of a function
to check if any of their parameters are passed by reference
Built-in functions rarely change the parameters if they aren't passed by reference.
@param string $funcName
@param array $expression
@throws CompilerException
@return bool | [
"This",
"method",
"gets",
"the",
"reflection",
"of",
"a",
"function",
"to",
"check",
"if",
"any",
"of",
"their",
"parameters",
"are",
"passed",
"by",
"reference",
"Built",
"-",
"in",
"functions",
"rarely",
"change",
"the",
"parameters",
"if",
"they",
"aren",
"t",
"passed",
"by",
"reference",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/FunctionCall.php#L187-L245 | train |
phalcon/zephir | Library/FunctionCall.php | FunctionCall.markReferences | protected function markReferences(
$funcName,
$parameters,
CompilationContext $compilationContext,
&$references,
$expression
) {
if ($this->isBuiltInFunction($funcName)) {
return;
}
$reflector = $this->getReflector($funcName);
if ($reflector) {
$numberParameters = \count($parameters);
if ($numberParameters > 0) {
$n = 1;
$funcParameters = $reflector->getParameters();
$isZendEngine3 = $compilationContext->backend->isZE3();
foreach ($funcParameters as $parameter) {
if ($numberParameters >= $n) {
if ($parameter->isPassedByReference()) {
/* TODO hack, fix this better */
if ($isZendEngine3 && '&' == $parameters[$n - 1][0]) {
$parameters[$n - 1] = substr($parameters[$n - 1], 1);
}
if (!preg_match('/^[a-zA-Z0-9$\_]+$/', $parameters[$n - 1])) {
$compilationContext->logger->warning(
'Cannot mark complex expression as reference',
['invalid-reference', $expression]
);
continue;
}
$variable = $compilationContext->symbolTable->getVariable($parameters[$n - 1]);
if ($variable) {
$variable->setDynamicTypes('undefined');
$referenceSymbol = $compilationContext->backend->getVariableCode($variable);
$compilationContext->codePrinter->output('ZEPHIR_MAKE_REF('.$referenceSymbol.');');
$references[] = $parameters[$n - 1];
}
}
}
++$n;
}
}
}
} | php | protected function markReferences(
$funcName,
$parameters,
CompilationContext $compilationContext,
&$references,
$expression
) {
if ($this->isBuiltInFunction($funcName)) {
return;
}
$reflector = $this->getReflector($funcName);
if ($reflector) {
$numberParameters = \count($parameters);
if ($numberParameters > 0) {
$n = 1;
$funcParameters = $reflector->getParameters();
$isZendEngine3 = $compilationContext->backend->isZE3();
foreach ($funcParameters as $parameter) {
if ($numberParameters >= $n) {
if ($parameter->isPassedByReference()) {
/* TODO hack, fix this better */
if ($isZendEngine3 && '&' == $parameters[$n - 1][0]) {
$parameters[$n - 1] = substr($parameters[$n - 1], 1);
}
if (!preg_match('/^[a-zA-Z0-9$\_]+$/', $parameters[$n - 1])) {
$compilationContext->logger->warning(
'Cannot mark complex expression as reference',
['invalid-reference', $expression]
);
continue;
}
$variable = $compilationContext->symbolTable->getVariable($parameters[$n - 1]);
if ($variable) {
$variable->setDynamicTypes('undefined');
$referenceSymbol = $compilationContext->backend->getVariableCode($variable);
$compilationContext->codePrinter->output('ZEPHIR_MAKE_REF('.$referenceSymbol.');');
$references[] = $parameters[$n - 1];
}
}
}
++$n;
}
}
}
} | [
"protected",
"function",
"markReferences",
"(",
"$",
"funcName",
",",
"$",
"parameters",
",",
"CompilationContext",
"$",
"compilationContext",
",",
"&",
"$",
"references",
",",
"$",
"expression",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isBuiltInFunction",
"(",
"$",
"funcName",
")",
")",
"{",
"return",
";",
"}",
"$",
"reflector",
"=",
"$",
"this",
"->",
"getReflector",
"(",
"$",
"funcName",
")",
";",
"if",
"(",
"$",
"reflector",
")",
"{",
"$",
"numberParameters",
"=",
"\\",
"count",
"(",
"$",
"parameters",
")",
";",
"if",
"(",
"$",
"numberParameters",
">",
"0",
")",
"{",
"$",
"n",
"=",
"1",
";",
"$",
"funcParameters",
"=",
"$",
"reflector",
"->",
"getParameters",
"(",
")",
";",
"$",
"isZendEngine3",
"=",
"$",
"compilationContext",
"->",
"backend",
"->",
"isZE3",
"(",
")",
";",
"foreach",
"(",
"$",
"funcParameters",
"as",
"$",
"parameter",
")",
"{",
"if",
"(",
"$",
"numberParameters",
">=",
"$",
"n",
")",
"{",
"if",
"(",
"$",
"parameter",
"->",
"isPassedByReference",
"(",
")",
")",
"{",
"/* TODO hack, fix this better */",
"if",
"(",
"$",
"isZendEngine3",
"&&",
"'&'",
"==",
"$",
"parameters",
"[",
"$",
"n",
"-",
"1",
"]",
"[",
"0",
"]",
")",
"{",
"$",
"parameters",
"[",
"$",
"n",
"-",
"1",
"]",
"=",
"substr",
"(",
"$",
"parameters",
"[",
"$",
"n",
"-",
"1",
"]",
",",
"1",
")",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[a-zA-Z0-9$\\_]+$/'",
",",
"$",
"parameters",
"[",
"$",
"n",
"-",
"1",
"]",
")",
")",
"{",
"$",
"compilationContext",
"->",
"logger",
"->",
"warning",
"(",
"'Cannot mark complex expression as reference'",
",",
"[",
"'invalid-reference'",
",",
"$",
"expression",
"]",
")",
";",
"continue",
";",
"}",
"$",
"variable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getVariable",
"(",
"$",
"parameters",
"[",
"$",
"n",
"-",
"1",
"]",
")",
";",
"if",
"(",
"$",
"variable",
")",
"{",
"$",
"variable",
"->",
"setDynamicTypes",
"(",
"'undefined'",
")",
";",
"$",
"referenceSymbol",
"=",
"$",
"compilationContext",
"->",
"backend",
"->",
"getVariableCode",
"(",
"$",
"variable",
")",
";",
"$",
"compilationContext",
"->",
"codePrinter",
"->",
"output",
"(",
"'ZEPHIR_MAKE_REF('",
".",
"$",
"referenceSymbol",
".",
"');'",
")",
";",
"$",
"references",
"[",
"]",
"=",
"$",
"parameters",
"[",
"$",
"n",
"-",
"1",
"]",
";",
"}",
"}",
"}",
"++",
"$",
"n",
";",
"}",
"}",
"}",
"}"
] | Once the function processes the parameters we should mark
specific parameters to be passed by reference.
@param string $funcName
@param array $parameters
@param CompilationContext $compilationContext
@param array $references
@param array $expression | [
"Once",
"the",
"function",
"processes",
"the",
"parameters",
"we",
"should",
"mark",
"specific",
"parameters",
"to",
"be",
"passed",
"by",
"reference",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/FunctionCall.php#L257-L304 | train |
phalcon/zephir | Library/FunctionCall.php | FunctionCall.optimize | protected function optimize($funcName, array $expression, Call $call, CompilationContext $compilationContext)
{
$optimizer = false;
/*
* Check if the optimizer is already cached
*/
if (!isset(self::$optimizers[$funcName])) {
$camelizeFunctionName = camelize($funcName);
/*
* Check every optimizer directory for an optimizer
*/
foreach (self::$optimizerDirectories as $directory) {
$path = $directory.\DIRECTORY_SEPARATOR.$camelizeFunctionName.'Optimizer.php';
$className = 'Zephir\Optimizers\FunctionCall\\'.$camelizeFunctionName.'Optimizer';
if (file_exists($path)) {
if (!class_exists($className, false)) {
require_once $path;
}
if (!class_exists($className, false)) {
throw new Exception("Class {$className} cannot be loaded");
}
$optimizer = new $className();
if (!($optimizer instanceof OptimizerAbstract)) {
throw new Exception("Class {$className} must be instance of OptimizerAbstract");
}
break;
}
}
self::$optimizers[$funcName] = $optimizer;
} else {
$optimizer = self::$optimizers[$funcName];
}
if ($optimizer) {
return $optimizer->optimize($expression, $call, $compilationContext);
}
return false;
} | php | protected function optimize($funcName, array $expression, Call $call, CompilationContext $compilationContext)
{
$optimizer = false;
/*
* Check if the optimizer is already cached
*/
if (!isset(self::$optimizers[$funcName])) {
$camelizeFunctionName = camelize($funcName);
/*
* Check every optimizer directory for an optimizer
*/
foreach (self::$optimizerDirectories as $directory) {
$path = $directory.\DIRECTORY_SEPARATOR.$camelizeFunctionName.'Optimizer.php';
$className = 'Zephir\Optimizers\FunctionCall\\'.$camelizeFunctionName.'Optimizer';
if (file_exists($path)) {
if (!class_exists($className, false)) {
require_once $path;
}
if (!class_exists($className, false)) {
throw new Exception("Class {$className} cannot be loaded");
}
$optimizer = new $className();
if (!($optimizer instanceof OptimizerAbstract)) {
throw new Exception("Class {$className} must be instance of OptimizerAbstract");
}
break;
}
}
self::$optimizers[$funcName] = $optimizer;
} else {
$optimizer = self::$optimizers[$funcName];
}
if ($optimizer) {
return $optimizer->optimize($expression, $call, $compilationContext);
}
return false;
} | [
"protected",
"function",
"optimize",
"(",
"$",
"funcName",
",",
"array",
"$",
"expression",
",",
"Call",
"$",
"call",
",",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"$",
"optimizer",
"=",
"false",
";",
"/*\n * Check if the optimizer is already cached\n */",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"optimizers",
"[",
"$",
"funcName",
"]",
")",
")",
"{",
"$",
"camelizeFunctionName",
"=",
"camelize",
"(",
"$",
"funcName",
")",
";",
"/*\n * Check every optimizer directory for an optimizer\n */",
"foreach",
"(",
"self",
"::",
"$",
"optimizerDirectories",
"as",
"$",
"directory",
")",
"{",
"$",
"path",
"=",
"$",
"directory",
".",
"\\",
"DIRECTORY_SEPARATOR",
".",
"$",
"camelizeFunctionName",
".",
"'Optimizer.php'",
";",
"$",
"className",
"=",
"'Zephir\\Optimizers\\FunctionCall\\\\'",
".",
"$",
"camelizeFunctionName",
".",
"'Optimizer'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
",",
"false",
")",
")",
"{",
"require_once",
"$",
"path",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
",",
"false",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Class {$className} cannot be loaded\"",
")",
";",
"}",
"$",
"optimizer",
"=",
"new",
"$",
"className",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"optimizer",
"instanceof",
"OptimizerAbstract",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Class {$className} must be instance of OptimizerAbstract\"",
")",
";",
"}",
"break",
";",
"}",
"}",
"self",
"::",
"$",
"optimizers",
"[",
"$",
"funcName",
"]",
"=",
"$",
"optimizer",
";",
"}",
"else",
"{",
"$",
"optimizer",
"=",
"self",
"::",
"$",
"optimizers",
"[",
"$",
"funcName",
"]",
";",
"}",
"if",
"(",
"$",
"optimizer",
")",
"{",
"return",
"$",
"optimizer",
"->",
"optimize",
"(",
"$",
"expression",
",",
"$",
"call",
",",
"$",
"compilationContext",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Tries to find specific an specialized optimizer for function calls.
@param string $funcName
@param array $expression
@param Call $call
@param CompilationContext $compilationContext
@throws Exception
@return bool|mixed | [
"Tries",
"to",
"find",
"specific",
"an",
"specialized",
"optimizer",
"for",
"function",
"calls",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/FunctionCall.php#L318-L364 | train |
phalcon/zephir | Library/CodePrinter.php | CodePrinter.preOutput | public function preOutput($code)
{
$this->lastLine = $code;
$this->code = str_repeat("\t", $this->level).$code.PHP_EOL.$this->code;
++$this->currentPrints;
} | php | public function preOutput($code)
{
$this->lastLine = $code;
$this->code = str_repeat("\t", $this->level).$code.PHP_EOL.$this->code;
++$this->currentPrints;
} | [
"public",
"function",
"preOutput",
"(",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"lastLine",
"=",
"$",
"code",
";",
"$",
"this",
"->",
"code",
"=",
"str_repeat",
"(",
"\"\\t\"",
",",
"$",
"this",
"->",
"level",
")",
".",
"$",
"code",
".",
"PHP_EOL",
".",
"$",
"this",
"->",
"code",
";",
"++",
"$",
"this",
"->",
"currentPrints",
";",
"}"
] | Add code to the output at the beginning.
@param string $code | [
"Add",
"code",
"to",
"the",
"output",
"at",
"the",
"beginning",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/CodePrinter.php#L45-L50 | train |
phalcon/zephir | Library/CodePrinter.php | CodePrinter.outputNoIndent | public function outputNoIndent($code)
{
$this->lastLine = $code;
$this->code .= $code.PHP_EOL;
++$this->currentPrints;
} | php | public function outputNoIndent($code)
{
$this->lastLine = $code;
$this->code .= $code.PHP_EOL;
++$this->currentPrints;
} | [
"public",
"function",
"outputNoIndent",
"(",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"lastLine",
"=",
"$",
"code",
";",
"$",
"this",
"->",
"code",
".=",
"$",
"code",
".",
"PHP_EOL",
";",
"++",
"$",
"this",
"->",
"currentPrints",
";",
"}"
] | Add code to the output without indentation.
@param string $code | [
"Add",
"code",
"to",
"the",
"output",
"without",
"indentation",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/CodePrinter.php#L80-L85 | train |
phalcon/zephir | Library/CodePrinter.php | CodePrinter.output | public function output($code)
{
$this->lastLine = $code;
$this->code .= str_repeat("\t", $this->level).$code.PHP_EOL;
++$this->currentPrints;
} | php | public function output($code)
{
$this->lastLine = $code;
$this->code .= str_repeat("\t", $this->level).$code.PHP_EOL;
++$this->currentPrints;
} | [
"public",
"function",
"output",
"(",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"lastLine",
"=",
"$",
"code",
";",
"$",
"this",
"->",
"code",
".=",
"str_repeat",
"(",
"\"\\t\"",
",",
"$",
"this",
"->",
"level",
")",
".",
"$",
"code",
".",
"PHP_EOL",
";",
"++",
"$",
"this",
"->",
"currentPrints",
";",
"}"
] | Add code to the output.
@param string $code | [
"Add",
"code",
"to",
"the",
"output",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/CodePrinter.php#L92-L97 | train |
phalcon/zephir | Library/CodePrinter.php | CodePrinter.outputDocBlock | public function outputDocBlock($docblock, $replaceTab = true)
{
$code = '';
$docblock = '/'.$docblock.'/';
foreach (explode("\n", $docblock) as $line) {
if ($replaceTab) {
$code .= str_repeat("\t", $this->level).preg_replace('/^[ \t]+/', ' ', $line).PHP_EOL;
} else {
$code .= $line.PHP_EOL;
}
}
$this->lastLine = $code;
$this->code .= $code;
++$this->currentPrints;
} | php | public function outputDocBlock($docblock, $replaceTab = true)
{
$code = '';
$docblock = '/'.$docblock.'/';
foreach (explode("\n", $docblock) as $line) {
if ($replaceTab) {
$code .= str_repeat("\t", $this->level).preg_replace('/^[ \t]+/', ' ', $line).PHP_EOL;
} else {
$code .= $line.PHP_EOL;
}
}
$this->lastLine = $code;
$this->code .= $code;
++$this->currentPrints;
} | [
"public",
"function",
"outputDocBlock",
"(",
"$",
"docblock",
",",
"$",
"replaceTab",
"=",
"true",
")",
"{",
"$",
"code",
"=",
"''",
";",
"$",
"docblock",
"=",
"'/'",
".",
"$",
"docblock",
".",
"'/'",
";",
"foreach",
"(",
"explode",
"(",
"\"\\n\"",
",",
"$",
"docblock",
")",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"$",
"replaceTab",
")",
"{",
"$",
"code",
".=",
"str_repeat",
"(",
"\"\\t\"",
",",
"$",
"this",
"->",
"level",
")",
".",
"preg_replace",
"(",
"'/^[ \\t]+/'",
",",
"' '",
",",
"$",
"line",
")",
".",
"PHP_EOL",
";",
"}",
"else",
"{",
"$",
"code",
".=",
"$",
"line",
".",
"PHP_EOL",
";",
"}",
"}",
"$",
"this",
"->",
"lastLine",
"=",
"$",
"code",
";",
"$",
"this",
"->",
"code",
".=",
"$",
"code",
";",
"++",
"$",
"this",
"->",
"currentPrints",
";",
"}"
] | Adds a comment to the output with indentation level.
@param $docblock
@param bool $replaceTab | [
"Adds",
"a",
"comment",
"to",
"the",
"output",
"with",
"indentation",
"level",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/CodePrinter.php#L105-L121 | train |
phalcon/zephir | Library/CodePrinter.php | CodePrinter.preOutputBlankLine | public function preOutputBlankLine($ifPrevNotBlank = false)
{
if (!$ifPrevNotBlank) {
$this->code = PHP_EOL.$this->code;
$this->lastLine = PHP_EOL;
++$this->currentPrints;
} else {
if (trim($this->lastLine)) {
$this->code = PHP_EOL.$this->code;
$this->lastLine = PHP_EOL;
++$this->currentPrints;
}
}
} | php | public function preOutputBlankLine($ifPrevNotBlank = false)
{
if (!$ifPrevNotBlank) {
$this->code = PHP_EOL.$this->code;
$this->lastLine = PHP_EOL;
++$this->currentPrints;
} else {
if (trim($this->lastLine)) {
$this->code = PHP_EOL.$this->code;
$this->lastLine = PHP_EOL;
++$this->currentPrints;
}
}
} | [
"public",
"function",
"preOutputBlankLine",
"(",
"$",
"ifPrevNotBlank",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"ifPrevNotBlank",
")",
"{",
"$",
"this",
"->",
"code",
"=",
"PHP_EOL",
".",
"$",
"this",
"->",
"code",
";",
"$",
"this",
"->",
"lastLine",
"=",
"PHP_EOL",
";",
"++",
"$",
"this",
"->",
"currentPrints",
";",
"}",
"else",
"{",
"if",
"(",
"trim",
"(",
"$",
"this",
"->",
"lastLine",
")",
")",
"{",
"$",
"this",
"->",
"code",
"=",
"PHP_EOL",
".",
"$",
"this",
"->",
"code",
";",
"$",
"this",
"->",
"lastLine",
"=",
"PHP_EOL",
";",
"++",
"$",
"this",
"->",
"currentPrints",
";",
"}",
"}",
"}"
] | Adds a blank line to the output
Optionally controlling if the blank link must be added if the
previous line added isn't one blank line too.
@param bool $ifPrevNotBlank | [
"Adds",
"a",
"blank",
"line",
"to",
"the",
"output",
"Optionally",
"controlling",
"if",
"the",
"blank",
"link",
"must",
"be",
"added",
"if",
"the",
"previous",
"line",
"added",
"isn",
"t",
"one",
"blank",
"line",
"too",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/CodePrinter.php#L142-L155 | train |
phalcon/zephir | Library/Config.php | Config.get | public function get($key, $namespace = null)
{
return null !== $namespace ? $this->offsetGet([$namespace => $key]) : $this->offsetGet($key);
} | php | public function get($key, $namespace = null)
{
return null !== $namespace ? $this->offsetGet([$namespace => $key]) : $this->offsetGet($key);
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"namespace",
"=",
"null",
")",
"{",
"return",
"null",
"!==",
"$",
"namespace",
"?",
"$",
"this",
"->",
"offsetGet",
"(",
"[",
"$",
"namespace",
"=>",
"$",
"key",
"]",
")",
":",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"key",
")",
";",
"}"
] | Retrieves a configuration setting.
@param mixed $key
@param mixed $namespace
@return mixed|null | [
"Retrieves",
"a",
"configuration",
"setting",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Config.php#L293-L296 | train |
phalcon/zephir | Library/Config.php | Config.populate | protected function populate()
{
if (!file_exists('config.json')) {
return;
}
$config = json_decode(file_get_contents('config.json'), true);
if (!\is_array($config)) {
throw new Exception(
'The config.json file is not valid or there is no Zephir extension initialized in this directory.'
);
}
foreach ($config as $key => $configSection) {
$this->offsetSet($key, $configSection);
}
} | php | protected function populate()
{
if (!file_exists('config.json')) {
return;
}
$config = json_decode(file_get_contents('config.json'), true);
if (!\is_array($config)) {
throw new Exception(
'The config.json file is not valid or there is no Zephir extension initialized in this directory.'
);
}
foreach ($config as $key => $configSection) {
$this->offsetSet($key, $configSection);
}
} | [
"protected",
"function",
"populate",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"'config.json'",
")",
")",
"{",
"return",
";",
"}",
"$",
"config",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"'config.json'",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'The config.json file is not valid or there is no Zephir extension initialized in this directory.'",
")",
";",
"}",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"configSection",
")",
"{",
"$",
"this",
"->",
"offsetSet",
"(",
"$",
"key",
",",
"$",
"configSection",
")",
";",
"}",
"}"
] | Populate project configuration.
@throws Exception | [
"Populate",
"project",
"configuration",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Config.php#L343-L359 | train |
phalcon/zephir | Library/Stubs/Generator.php | Generator.generate | public function generate($path)
{
if ('tabs' === $this->config->get('indent', 'extra')) {
$indent = "\t";
} else {
$indent = ' ';
}
$namespace = $this->config->get('namespace');
foreach ($this->files as $file) {
$class = $file->getClassDefinition();
$source = $this->buildClass($class, $indent);
$filename = ucfirst($class->getName()).'.zep.php';
$filePath = $path.str_replace(
$namespace,
'',
str_replace($namespace.'\\\\', \DIRECTORY_SEPARATOR, strtolower($class->getNamespace()))
);
$filePath = str_replace('\\', \DIRECTORY_SEPARATOR, $filePath);
$filePath = str_replace(\DIRECTORY_SEPARATOR.\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR, $filePath);
if (!is_dir($filePath)) {
mkdir($filePath, 0777, true);
}
$filePath = realpath($filePath).'/';
file_put_contents($filePath.$filename, $source);
}
} | php | public function generate($path)
{
if ('tabs' === $this->config->get('indent', 'extra')) {
$indent = "\t";
} else {
$indent = ' ';
}
$namespace = $this->config->get('namespace');
foreach ($this->files as $file) {
$class = $file->getClassDefinition();
$source = $this->buildClass($class, $indent);
$filename = ucfirst($class->getName()).'.zep.php';
$filePath = $path.str_replace(
$namespace,
'',
str_replace($namespace.'\\\\', \DIRECTORY_SEPARATOR, strtolower($class->getNamespace()))
);
$filePath = str_replace('\\', \DIRECTORY_SEPARATOR, $filePath);
$filePath = str_replace(\DIRECTORY_SEPARATOR.\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR, $filePath);
if (!is_dir($filePath)) {
mkdir($filePath, 0777, true);
}
$filePath = realpath($filePath).'/';
file_put_contents($filePath.$filename, $source);
}
} | [
"public",
"function",
"generate",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"'tabs'",
"===",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'indent'",
",",
"'extra'",
")",
")",
"{",
"$",
"indent",
"=",
"\"\\t\"",
";",
"}",
"else",
"{",
"$",
"indent",
"=",
"' '",
";",
"}",
"$",
"namespace",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'namespace'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"class",
"=",
"$",
"file",
"->",
"getClassDefinition",
"(",
")",
";",
"$",
"source",
"=",
"$",
"this",
"->",
"buildClass",
"(",
"$",
"class",
",",
"$",
"indent",
")",
";",
"$",
"filename",
"=",
"ucfirst",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
")",
".",
"'.zep.php'",
";",
"$",
"filePath",
"=",
"$",
"path",
".",
"str_replace",
"(",
"$",
"namespace",
",",
"''",
",",
"str_replace",
"(",
"$",
"namespace",
".",
"'\\\\\\\\'",
",",
"\\",
"DIRECTORY_SEPARATOR",
",",
"strtolower",
"(",
"$",
"class",
"->",
"getNamespace",
"(",
")",
")",
")",
")",
";",
"$",
"filePath",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"\\",
"DIRECTORY_SEPARATOR",
",",
"$",
"filePath",
")",
";",
"$",
"filePath",
"=",
"str_replace",
"(",
"\\",
"DIRECTORY_SEPARATOR",
".",
"\\",
"DIRECTORY_SEPARATOR",
",",
"\\",
"DIRECTORY_SEPARATOR",
",",
"$",
"filePath",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"filePath",
")",
")",
"{",
"mkdir",
"(",
"$",
"filePath",
",",
"0777",
",",
"true",
")",
";",
"}",
"$",
"filePath",
"=",
"realpath",
"(",
"$",
"filePath",
")",
".",
"'/'",
";",
"file_put_contents",
"(",
"$",
"filePath",
".",
"$",
"filename",
",",
"$",
"source",
")",
";",
"}",
"}"
] | Generates stubs.
@param string $path | [
"Generates",
"stubs",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Stubs/Generator.php#L64-L94 | train |
phalcon/zephir | Library/Stubs/Generator.php | Generator.buildClass | protected function buildClass(ClassDefinition $class, $indent)
{
$source = <<<EOF
<?php
namespace {$class->getNamespace()};
EOF;
$source .= (new DocBlock($class->getDocBlock(), ''))."\n";
if ($class->isFinal()) {
$source .= 'final ';
} elseif ($class->isAbstract()) {
$source .= 'abstract ';
}
$source .= $class->getType().' '.$class->getName();
if ($class->getExtendsClass()) {
$extendsClassDefinition = $class->getExtendsClassDefinition();
if (!$extendsClassDefinition) {
throw new \RuntimeException('Class "'.$class->getName().'" does not have a extendsClassDefinition');
}
$source .= ' extends '.($extendsClassDefinition->isBundled() ? '' : '\\').trim($extendsClassDefinition->getCompleteName(), '\\');
}
if ($implementedInterfaces = $class->getImplementedInterfaces()) {
$interfaces = array_map(function ($val) {
return '\\'.trim($val, '\\');
}, $implementedInterfaces);
$keyword = 'interface' == $class->getType() ? ' extends ' : ' implements ';
$source .= $keyword.implode(', ', $interfaces);
}
$source .= PHP_EOL.'{'.PHP_EOL;
foreach ($class->getConstants() as $constant) {
$source .= $this->buildConstant($constant, $indent).PHP_EOL.PHP_EOL;
}
foreach ($class->getProperties() as $property) {
$source .= $this->buildProperty($property, $indent).PHP_EOL.PHP_EOL;
}
$source .= PHP_EOL;
foreach ($class->getMethods() as $method) {
if ($method->isInternal()) {
continue;
}
$source .= $this->buildMethod($method, 'interface' === $class->getType(), $indent)."\n\n";
}
return $source.'}'.PHP_EOL;
} | php | protected function buildClass(ClassDefinition $class, $indent)
{
$source = <<<EOF
<?php
namespace {$class->getNamespace()};
EOF;
$source .= (new DocBlock($class->getDocBlock(), ''))."\n";
if ($class->isFinal()) {
$source .= 'final ';
} elseif ($class->isAbstract()) {
$source .= 'abstract ';
}
$source .= $class->getType().' '.$class->getName();
if ($class->getExtendsClass()) {
$extendsClassDefinition = $class->getExtendsClassDefinition();
if (!$extendsClassDefinition) {
throw new \RuntimeException('Class "'.$class->getName().'" does not have a extendsClassDefinition');
}
$source .= ' extends '.($extendsClassDefinition->isBundled() ? '' : '\\').trim($extendsClassDefinition->getCompleteName(), '\\');
}
if ($implementedInterfaces = $class->getImplementedInterfaces()) {
$interfaces = array_map(function ($val) {
return '\\'.trim($val, '\\');
}, $implementedInterfaces);
$keyword = 'interface' == $class->getType() ? ' extends ' : ' implements ';
$source .= $keyword.implode(', ', $interfaces);
}
$source .= PHP_EOL.'{'.PHP_EOL;
foreach ($class->getConstants() as $constant) {
$source .= $this->buildConstant($constant, $indent).PHP_EOL.PHP_EOL;
}
foreach ($class->getProperties() as $property) {
$source .= $this->buildProperty($property, $indent).PHP_EOL.PHP_EOL;
}
$source .= PHP_EOL;
foreach ($class->getMethods() as $method) {
if ($method->isInternal()) {
continue;
}
$source .= $this->buildMethod($method, 'interface' === $class->getType(), $indent)."\n\n";
}
return $source.'}'.PHP_EOL;
} | [
"protected",
"function",
"buildClass",
"(",
"ClassDefinition",
"$",
"class",
",",
"$",
"indent",
")",
"{",
"$",
"source",
"=",
" <<<EOF\n<?php\n\nnamespace {$class->getNamespace()};\n\n\nEOF",
";",
"$",
"source",
".=",
"(",
"new",
"DocBlock",
"(",
"$",
"class",
"->",
"getDocBlock",
"(",
")",
",",
"''",
")",
")",
".",
"\"\\n\"",
";",
"if",
"(",
"$",
"class",
"->",
"isFinal",
"(",
")",
")",
"{",
"$",
"source",
".=",
"'final '",
";",
"}",
"elseif",
"(",
"$",
"class",
"->",
"isAbstract",
"(",
")",
")",
"{",
"$",
"source",
".=",
"'abstract '",
";",
"}",
"$",
"source",
".=",
"$",
"class",
"->",
"getType",
"(",
")",
".",
"' '",
".",
"$",
"class",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"class",
"->",
"getExtendsClass",
"(",
")",
")",
"{",
"$",
"extendsClassDefinition",
"=",
"$",
"class",
"->",
"getExtendsClassDefinition",
"(",
")",
";",
"if",
"(",
"!",
"$",
"extendsClassDefinition",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Class \"'",
".",
"$",
"class",
"->",
"getName",
"(",
")",
".",
"'\" does not have a extendsClassDefinition'",
")",
";",
"}",
"$",
"source",
".=",
"' extends '",
".",
"(",
"$",
"extendsClassDefinition",
"->",
"isBundled",
"(",
")",
"?",
"''",
":",
"'\\\\'",
")",
".",
"trim",
"(",
"$",
"extendsClassDefinition",
"->",
"getCompleteName",
"(",
")",
",",
"'\\\\'",
")",
";",
"}",
"if",
"(",
"$",
"implementedInterfaces",
"=",
"$",
"class",
"->",
"getImplementedInterfaces",
"(",
")",
")",
"{",
"$",
"interfaces",
"=",
"array_map",
"(",
"function",
"(",
"$",
"val",
")",
"{",
"return",
"'\\\\'",
".",
"trim",
"(",
"$",
"val",
",",
"'\\\\'",
")",
";",
"}",
",",
"$",
"implementedInterfaces",
")",
";",
"$",
"keyword",
"=",
"'interface'",
"==",
"$",
"class",
"->",
"getType",
"(",
")",
"?",
"' extends '",
":",
"' implements '",
";",
"$",
"source",
".=",
"$",
"keyword",
".",
"implode",
"(",
"', '",
",",
"$",
"interfaces",
")",
";",
"}",
"$",
"source",
".=",
"PHP_EOL",
".",
"'{'",
".",
"PHP_EOL",
";",
"foreach",
"(",
"$",
"class",
"->",
"getConstants",
"(",
")",
"as",
"$",
"constant",
")",
"{",
"$",
"source",
".=",
"$",
"this",
"->",
"buildConstant",
"(",
"$",
"constant",
",",
"$",
"indent",
")",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"}",
"foreach",
"(",
"$",
"class",
"->",
"getProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"$",
"source",
".=",
"$",
"this",
"->",
"buildProperty",
"(",
"$",
"property",
",",
"$",
"indent",
")",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"}",
"$",
"source",
".=",
"PHP_EOL",
";",
"foreach",
"(",
"$",
"class",
"->",
"getMethods",
"(",
")",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"$",
"method",
"->",
"isInternal",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"source",
".=",
"$",
"this",
"->",
"buildMethod",
"(",
"$",
"method",
",",
"'interface'",
"===",
"$",
"class",
"->",
"getType",
"(",
")",
",",
"$",
"indent",
")",
".",
"\"\\n\\n\"",
";",
"}",
"return",
"$",
"source",
".",
"'}'",
".",
"PHP_EOL",
";",
"}"
] | Build class.
@param ClassDefinition $class
@param string $indent
@return string | [
"Build",
"class",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Stubs/Generator.php#L104-L163 | train |
phalcon/zephir | Library/Stubs/Generator.php | Generator.buildProperty | protected function buildProperty(ClassProperty $property, $indent)
{
$visibility = 'public';
if (false === $property->isPublic()) {
$visibility = $property->isProtected() ? 'protected' : 'private';
}
if ($property->isStatic()) {
$visibility = 'static '.$visibility;
}
$source = $visibility.' $'.$property->getName();
$original = $property->getOriginal();
if (isset($original['default'])) {
$source .= ' = '.$this->wrapPHPValue([
'default' => $original['default'],
]);
}
$docBlock = new DocBlock($property->getDocBlock(), $indent);
return $docBlock."\n".$indent.$source.';';
} | php | protected function buildProperty(ClassProperty $property, $indent)
{
$visibility = 'public';
if (false === $property->isPublic()) {
$visibility = $property->isProtected() ? 'protected' : 'private';
}
if ($property->isStatic()) {
$visibility = 'static '.$visibility;
}
$source = $visibility.' $'.$property->getName();
$original = $property->getOriginal();
if (isset($original['default'])) {
$source .= ' = '.$this->wrapPHPValue([
'default' => $original['default'],
]);
}
$docBlock = new DocBlock($property->getDocBlock(), $indent);
return $docBlock."\n".$indent.$source.';';
} | [
"protected",
"function",
"buildProperty",
"(",
"ClassProperty",
"$",
"property",
",",
"$",
"indent",
")",
"{",
"$",
"visibility",
"=",
"'public'",
";",
"if",
"(",
"false",
"===",
"$",
"property",
"->",
"isPublic",
"(",
")",
")",
"{",
"$",
"visibility",
"=",
"$",
"property",
"->",
"isProtected",
"(",
")",
"?",
"'protected'",
":",
"'private'",
";",
"}",
"if",
"(",
"$",
"property",
"->",
"isStatic",
"(",
")",
")",
"{",
"$",
"visibility",
"=",
"'static '",
".",
"$",
"visibility",
";",
"}",
"$",
"source",
"=",
"$",
"visibility",
".",
"' $'",
".",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"$",
"original",
"=",
"$",
"property",
"->",
"getOriginal",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"original",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"source",
".=",
"' = '",
".",
"$",
"this",
"->",
"wrapPHPValue",
"(",
"[",
"'default'",
"=>",
"$",
"original",
"[",
"'default'",
"]",
",",
"]",
")",
";",
"}",
"$",
"docBlock",
"=",
"new",
"DocBlock",
"(",
"$",
"property",
"->",
"getDocBlock",
"(",
")",
",",
"$",
"indent",
")",
";",
"return",
"$",
"docBlock",
".",
"\"\\n\"",
".",
"$",
"indent",
".",
"$",
"source",
".",
"';'",
";",
"}"
] | Build property.
@param ClassProperty $property
@param string $indent
@return string | [
"Build",
"property",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Stubs/Generator.php#L173-L197 | train |
phalcon/zephir | Library/Stubs/Generator.php | Generator.wrapPHPValue | protected function wrapPHPValue($parameter)
{
switch ($parameter['default']['type']) {
case 'null':
return 'null';
break;
case 'string':
case 'char':
return '\''.addslashes($parameter['default']['value']).'\'';
break;
case 'empty-array':
return 'array()';
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'],
]);
}
return 'array('.implode(', ', $parameters).')';
break;
case 'static-constant-access':
return $parameter['default']['left']['value'].'::'.$parameter['default']['right']['value'];
break;
case 'int':
case 'double':
case 'bool':
return $parameter['default']['value'];
break;
default:
throw new Exception('Stubs - value with type: '.$parameter['default']['type'].' is not supported');
break;
}
} | php | protected function wrapPHPValue($parameter)
{
switch ($parameter['default']['type']) {
case 'null':
return 'null';
break;
case 'string':
case 'char':
return '\''.addslashes($parameter['default']['value']).'\'';
break;
case 'empty-array':
return 'array()';
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'],
]);
}
return 'array('.implode(', ', $parameters).')';
break;
case 'static-constant-access':
return $parameter['default']['left']['value'].'::'.$parameter['default']['right']['value'];
break;
case 'int':
case 'double':
case 'bool':
return $parameter['default']['value'];
break;
default:
throw new Exception('Stubs - value with type: '.$parameter['default']['type'].' is not supported');
break;
}
} | [
"protected",
"function",
"wrapPHPValue",
"(",
"$",
"parameter",
")",
"{",
"switch",
"(",
"$",
"parameter",
"[",
"'default'",
"]",
"[",
"'type'",
"]",
")",
"{",
"case",
"'null'",
":",
"return",
"'null'",
";",
"break",
";",
"case",
"'string'",
":",
"case",
"'char'",
":",
"return",
"'\\''",
".",
"addslashes",
"(",
"$",
"parameter",
"[",
"'default'",
"]",
"[",
"'value'",
"]",
")",
".",
"'\\''",
";",
"break",
";",
"case",
"'empty-array'",
":",
"return",
"'array()'",
";",
"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'",
"]",
",",
"]",
")",
";",
"}",
"return",
"'array('",
".",
"implode",
"(",
"', '",
",",
"$",
"parameters",
")",
".",
"')'",
";",
"break",
";",
"case",
"'static-constant-access'",
":",
"return",
"$",
"parameter",
"[",
"'default'",
"]",
"[",
"'left'",
"]",
"[",
"'value'",
"]",
".",
"'::'",
".",
"$",
"parameter",
"[",
"'default'",
"]",
"[",
"'right'",
"]",
"[",
"'value'",
"]",
";",
"break",
";",
"case",
"'int'",
":",
"case",
"'double'",
":",
"case",
"'bool'",
":",
"return",
"$",
"parameter",
"[",
"'default'",
"]",
"[",
"'value'",
"]",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"'Stubs - value with type: '",
".",
"$",
"parameter",
"[",
"'default'",
"]",
"[",
"'type'",
"]",
".",
"' is not supported'",
")",
";",
"break",
";",
"}",
"}"
] | Prepare AST default value to PHP code print.
@param $parameter
@throws Exception
@return string | [
"Prepare",
"AST",
"default",
"value",
"to",
"PHP",
"code",
"print",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Stubs/Generator.php#L337-L389 | train |
phalcon/zephir | Library/Passes/StaticTypeInference.php | StaticTypeInference.markVariableIfUnknown | public function markVariableIfUnknown($variable, $type)
{
$this->variables[$variable] = $type;
$this->infered[$variable] = $type;
} | php | public function markVariableIfUnknown($variable, $type)
{
$this->variables[$variable] = $type;
$this->infered[$variable] = $type;
} | [
"public",
"function",
"markVariableIfUnknown",
"(",
"$",
"variable",
",",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"variables",
"[",
"$",
"variable",
"]",
"=",
"$",
"type",
";",
"$",
"this",
"->",
"infered",
"[",
"$",
"variable",
"]",
"=",
"$",
"type",
";",
"}"
] | Marks a variable to mandatory be stored in the heap if a type has not been defined for it.
@param string $variable
@param string $type | [
"Marks",
"a",
"variable",
"to",
"mandatory",
"be",
"stored",
"in",
"the",
"heap",
"if",
"a",
"type",
"has",
"not",
"been",
"defined",
"for",
"it",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Passes/StaticTypeInference.php#L59-L63 | train |
phalcon/zephir | Library/Passes/StaticTypeInference.php | StaticTypeInference.reduce | public function reduce()
{
$pass = false;
foreach ($this->variables as $variable => $type) {
if ('variable' == $type || 'string' == $type || 'istring' == $type || 'array' == $type || 'null' == $type || 'numeric' == $type) {
unset($this->variables[$variable]);
} else {
$pass = true;
$this->infered[$variable] = $type;
}
}
return $pass;
} | php | public function reduce()
{
$pass = false;
foreach ($this->variables as $variable => $type) {
if ('variable' == $type || 'string' == $type || 'istring' == $type || 'array' == $type || 'null' == $type || 'numeric' == $type) {
unset($this->variables[$variable]);
} else {
$pass = true;
$this->infered[$variable] = $type;
}
}
return $pass;
} | [
"public",
"function",
"reduce",
"(",
")",
"{",
"$",
"pass",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"variables",
"as",
"$",
"variable",
"=>",
"$",
"type",
")",
"{",
"if",
"(",
"'variable'",
"==",
"$",
"type",
"||",
"'string'",
"==",
"$",
"type",
"||",
"'istring'",
"==",
"$",
"type",
"||",
"'array'",
"==",
"$",
"type",
"||",
"'null'",
"==",
"$",
"type",
"||",
"'numeric'",
"==",
"$",
"type",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"variables",
"[",
"$",
"variable",
"]",
")",
";",
"}",
"else",
"{",
"$",
"pass",
"=",
"true",
";",
"$",
"this",
"->",
"infered",
"[",
"$",
"variable",
"]",
"=",
"$",
"type",
";",
"}",
"}",
"return",
"$",
"pass",
";",
"}"
] | Process the found infered types and schedule a new pass.
@return bool | [
"Process",
"the",
"found",
"infered",
"types",
"and",
"schedule",
"a",
"new",
"pass",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Passes/StaticTypeInference.php#L178-L191 | train |
phalcon/zephir | Library/Operators/Arithmetical/ArithmeticalBaseOperator.php | ArithmeticalBaseOperator.optimizeConstantFolding | public function optimizeConstantFolding(array $expression, CompilationContext $compilationContext)
{
if ('int' != $expression['left']['type'] && 'double' != $expression['left']['type']) {
return false;
}
if ($compilationContext->config->get('constant-folding', 'optimizations')) {
if ('int' == $expression['left']['type'] && 'int' == $expression['right']['type']) {
switch ($this->operator) {
case '+':
return new CompiledExpression('int', $expression['left']['value'] + $expression['right']['value'], $expression);
case '-':
return new CompiledExpression('int', $expression['left']['value'] - $expression['right']['value'], $expression);
case '*':
return new CompiledExpression('int', $expression['left']['value'] * $expression['right']['value'], $expression);
}
}
if (('double' == $expression['left']['type'] && 'double' == $expression['right']['type']) || ('double' == $expression['left']['type'] && 'int' == $expression['right']['type']) || ('int' == $expression['left']['type'] && 'double' == $expression['right']['type'])) {
switch ($this->operator) {
case '+':
return new CompiledExpression('double', $expression['left']['value'] + $expression['right']['value'], $expression);
case '-':
return new CompiledExpression('double', $expression['left']['value'] - $expression['right']['value'], $expression);
case '*':
return new CompiledExpression('double', $expression['left']['value'] * $expression['right']['value'], $expression);
}
}
}
return false;
} | php | public function optimizeConstantFolding(array $expression, CompilationContext $compilationContext)
{
if ('int' != $expression['left']['type'] && 'double' != $expression['left']['type']) {
return false;
}
if ($compilationContext->config->get('constant-folding', 'optimizations')) {
if ('int' == $expression['left']['type'] && 'int' == $expression['right']['type']) {
switch ($this->operator) {
case '+':
return new CompiledExpression('int', $expression['left']['value'] + $expression['right']['value'], $expression);
case '-':
return new CompiledExpression('int', $expression['left']['value'] - $expression['right']['value'], $expression);
case '*':
return new CompiledExpression('int', $expression['left']['value'] * $expression['right']['value'], $expression);
}
}
if (('double' == $expression['left']['type'] && 'double' == $expression['right']['type']) || ('double' == $expression['left']['type'] && 'int' == $expression['right']['type']) || ('int' == $expression['left']['type'] && 'double' == $expression['right']['type'])) {
switch ($this->operator) {
case '+':
return new CompiledExpression('double', $expression['left']['value'] + $expression['right']['value'], $expression);
case '-':
return new CompiledExpression('double', $expression['left']['value'] - $expression['right']['value'], $expression);
case '*':
return new CompiledExpression('double', $expression['left']['value'] * $expression['right']['value'], $expression);
}
}
}
return false;
} | [
"public",
"function",
"optimizeConstantFolding",
"(",
"array",
"$",
"expression",
",",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"if",
"(",
"'int'",
"!=",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'type'",
"]",
"&&",
"'double'",
"!=",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'type'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"compilationContext",
"->",
"config",
"->",
"get",
"(",
"'constant-folding'",
",",
"'optimizations'",
")",
")",
"{",
"if",
"(",
"'int'",
"==",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'type'",
"]",
"&&",
"'int'",
"==",
"$",
"expression",
"[",
"'right'",
"]",
"[",
"'type'",
"]",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"operator",
")",
"{",
"case",
"'+'",
":",
"return",
"new",
"CompiledExpression",
"(",
"'int'",
",",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'value'",
"]",
"+",
"$",
"expression",
"[",
"'right'",
"]",
"[",
"'value'",
"]",
",",
"$",
"expression",
")",
";",
"case",
"'-'",
":",
"return",
"new",
"CompiledExpression",
"(",
"'int'",
",",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'value'",
"]",
"-",
"$",
"expression",
"[",
"'right'",
"]",
"[",
"'value'",
"]",
",",
"$",
"expression",
")",
";",
"case",
"'*'",
":",
"return",
"new",
"CompiledExpression",
"(",
"'int'",
",",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'value'",
"]",
"*",
"$",
"expression",
"[",
"'right'",
"]",
"[",
"'value'",
"]",
",",
"$",
"expression",
")",
";",
"}",
"}",
"if",
"(",
"(",
"'double'",
"==",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'type'",
"]",
"&&",
"'double'",
"==",
"$",
"expression",
"[",
"'right'",
"]",
"[",
"'type'",
"]",
")",
"||",
"(",
"'double'",
"==",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'type'",
"]",
"&&",
"'int'",
"==",
"$",
"expression",
"[",
"'right'",
"]",
"[",
"'type'",
"]",
")",
"||",
"(",
"'int'",
"==",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'type'",
"]",
"&&",
"'double'",
"==",
"$",
"expression",
"[",
"'right'",
"]",
"[",
"'type'",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"operator",
")",
"{",
"case",
"'+'",
":",
"return",
"new",
"CompiledExpression",
"(",
"'double'",
",",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'value'",
"]",
"+",
"$",
"expression",
"[",
"'right'",
"]",
"[",
"'value'",
"]",
",",
"$",
"expression",
")",
";",
"case",
"'-'",
":",
"return",
"new",
"CompiledExpression",
"(",
"'double'",
",",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'value'",
"]",
"-",
"$",
"expression",
"[",
"'right'",
"]",
"[",
"'value'",
"]",
",",
"$",
"expression",
")",
";",
"case",
"'*'",
":",
"return",
"new",
"CompiledExpression",
"(",
"'double'",
",",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'value'",
"]",
"*",
"$",
"expression",
"[",
"'right'",
"]",
"[",
"'value'",
"]",
",",
"$",
"expression",
")",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | 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
@return bool|CompiledExpression | [
"This",
"tries",
"to",
"perform",
"arithmetical",
"operations",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Operators/Arithmetical/ArithmeticalBaseOperator.php#L44-L79 | train |
phalcon/zephir | Library/Operators/Arithmetical/ArithmeticalBaseOperator.php | ArithmeticalBaseOperator.getDynamicTypes | private function getDynamicTypes(Variable $left, Variable $right)
{
if ('/' == $this->operator) {
return 'double';
}
switch ($left->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
switch ($right->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
return 'int';
}
break;
}
return 'double';
} | php | private function getDynamicTypes(Variable $left, Variable $right)
{
if ('/' == $this->operator) {
return 'double';
}
switch ($left->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
switch ($right->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
return 'int';
}
break;
}
return 'double';
} | [
"private",
"function",
"getDynamicTypes",
"(",
"Variable",
"$",
"left",
",",
"Variable",
"$",
"right",
")",
"{",
"if",
"(",
"'/'",
"==",
"$",
"this",
"->",
"operator",
")",
"{",
"return",
"'double'",
";",
"}",
"switch",
"(",
"$",
"left",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'int'",
":",
"case",
"'uint'",
":",
"case",
"'long'",
":",
"case",
"'ulong'",
":",
"switch",
"(",
"$",
"right",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'int'",
":",
"case",
"'uint'",
":",
"case",
"'long'",
":",
"case",
"'ulong'",
":",
"return",
"'int'",
";",
"}",
"break",
";",
"}",
"return",
"'double'",
";",
"}"
] | Returns proper dynamic types.
@param Variable $left
@param Variable $right
@return string | [
"Returns",
"proper",
"dynamic",
"types",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Operators/Arithmetical/ArithmeticalBaseOperator.php#L518-L540 | train |
phalcon/zephir | Library/EventsManager.php | EventsManager.listen | public function listen($event, $callback)
{
if (!isset($this->listeners[$event])) {
$this->listeners[$event] = [];
}
$this->listeners[$event][] = $callback;
} | php | public function listen($event, $callback)
{
if (!isset($this->listeners[$event])) {
$this->listeners[$event] = [];
}
$this->listeners[$event][] = $callback;
} | [
"public",
"function",
"listen",
"(",
"$",
"event",
",",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"listeners",
"[",
"$",
"event",
"]",
")",
")",
"{",
"$",
"this",
"->",
"listeners",
"[",
"$",
"event",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"listeners",
"[",
"$",
"event",
"]",
"[",
"]",
"=",
"$",
"callback",
";",
"}"
] | Attaches a listener to a specific event type.
@param $event
@param $callback | [
"Attaches",
"a",
"listener",
"to",
"a",
"specific",
"event",
"type",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/EventsManager.php#L30-L37 | train |
phalcon/zephir | Library/EventsManager.php | EventsManager.dispatch | public function dispatch($event, array $param = [])
{
foreach ($this->listeners[$event] as $listener) {
\call_user_func_array($listener, $param);
}
} | php | public function dispatch($event, array $param = [])
{
foreach ($this->listeners[$event] as $listener) {
\call_user_func_array($listener, $param);
}
} | [
"public",
"function",
"dispatch",
"(",
"$",
"event",
",",
"array",
"$",
"param",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"listeners",
"[",
"$",
"event",
"]",
"as",
"$",
"listener",
")",
"{",
"\\",
"call_user_func_array",
"(",
"$",
"listener",
",",
"$",
"param",
")",
";",
"}",
"}"
] | Triggers an event for the specified event type.
@param $event
@param array $param | [
"Triggers",
"an",
"event",
"for",
"the",
"specified",
"event",
"type",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/EventsManager.php#L45-L50 | train |
phalcon/zephir | Library/Statements/Let/ObjectPropertyIncr.php | ObjectPropertyIncr.assign | public function assign($variable, $property, ZephirVariable $symbolVariable, CompilationContext $compilationContext, $statement)
{
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '".$variable."' because it is not initialized", $statement);
}
/*
* Arrays must be stored in the HEAP
*/
if ($symbolVariable->isLocalOnly()) {
throw new CompilerException("Cannot mutate variable '".$variable."' because it is local only", $statement);
}
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '".$variable."' because it is not initialized", $statement);
}
/*
* Only dynamic variables can be used as arrays
*/
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Cannot use variable type: '".$symbolVariable->getType()."' as array", $statement);
}
if ($symbolVariable->hasAnyDynamicType('unknown')) {
throw new CompilerException('Cannot use non-initialized variable as an object', $statement);
}
/*
* Trying to use a non-object dynamic variable as object
*/
if ($symbolVariable->hasDifferentDynamicType(['undefined', 'object', 'null'])) {
$compilationContext->logger->warning(
'Possible attempt to increment non-object dynamic variable',
['non-object-update', $statement]
);
}
/*
* Check if the variable to update is defined
*/
if ('this' == $symbolVariable->getRealName()) {
$classDefinition = $compilationContext->classDefinition;
if (!$classDefinition->hasProperty($property)) {
throw new CompilerException("Class '".$classDefinition->getCompleteName()."' does not have a property called: '".$property."'", $statement);
}
} else {
/*
* If we know the class related to a variable we could check if the property
* is defined on that class
*/
if ($symbolVariable->hasAnyDynamicType('object')) {
$classType = current($symbolVariable->getClassTypes());
$compiler = $compilationContext->compiler;
if ($compiler->isClass($classType)) {
$classDefinition = $compiler->getClassDefinition($classType);
if (!$classDefinition) {
throw new CompilerException('Cannot locate class definition for class: '.$classType, $statement);
}
if (!$classDefinition->hasProperty($property)) {
throw new CompilerException("Class '".$classType."' does not have a property called: '".$property."'", $statement);
}
}
}
}
$compilationContext->headersManager->add('kernel/object');
$compilationContext->codePrinter->output('RETURN_ON_FAILURE(zephir_property_incr('.$symbolVariable->getName().', SL("'.$property.'") TSRMLS_CC));');
} | php | public function assign($variable, $property, ZephirVariable $symbolVariable, CompilationContext $compilationContext, $statement)
{
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '".$variable."' because it is not initialized", $statement);
}
/*
* Arrays must be stored in the HEAP
*/
if ($symbolVariable->isLocalOnly()) {
throw new CompilerException("Cannot mutate variable '".$variable."' because it is local only", $statement);
}
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '".$variable."' because it is not initialized", $statement);
}
/*
* Only dynamic variables can be used as arrays
*/
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Cannot use variable type: '".$symbolVariable->getType()."' as array", $statement);
}
if ($symbolVariable->hasAnyDynamicType('unknown')) {
throw new CompilerException('Cannot use non-initialized variable as an object', $statement);
}
/*
* Trying to use a non-object dynamic variable as object
*/
if ($symbolVariable->hasDifferentDynamicType(['undefined', 'object', 'null'])) {
$compilationContext->logger->warning(
'Possible attempt to increment non-object dynamic variable',
['non-object-update', $statement]
);
}
/*
* Check if the variable to update is defined
*/
if ('this' == $symbolVariable->getRealName()) {
$classDefinition = $compilationContext->classDefinition;
if (!$classDefinition->hasProperty($property)) {
throw new CompilerException("Class '".$classDefinition->getCompleteName()."' does not have a property called: '".$property."'", $statement);
}
} else {
/*
* If we know the class related to a variable we could check if the property
* is defined on that class
*/
if ($symbolVariable->hasAnyDynamicType('object')) {
$classType = current($symbolVariable->getClassTypes());
$compiler = $compilationContext->compiler;
if ($compiler->isClass($classType)) {
$classDefinition = $compiler->getClassDefinition($classType);
if (!$classDefinition) {
throw new CompilerException('Cannot locate class definition for class: '.$classType, $statement);
}
if (!$classDefinition->hasProperty($property)) {
throw new CompilerException("Class '".$classType."' does not have a property called: '".$property."'", $statement);
}
}
}
}
$compilationContext->headersManager->add('kernel/object');
$compilationContext->codePrinter->output('RETURN_ON_FAILURE(zephir_property_incr('.$symbolVariable->getName().', SL("'.$property.'") TSRMLS_CC));');
} | [
"public",
"function",
"assign",
"(",
"$",
"variable",
",",
"$",
"property",
",",
"ZephirVariable",
"$",
"symbolVariable",
",",
"CompilationContext",
"$",
"compilationContext",
",",
"$",
"statement",
")",
"{",
"if",
"(",
"!",
"$",
"symbolVariable",
"->",
"isInitialized",
"(",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"\"Cannot mutate variable '\"",
".",
"$",
"variable",
".",
"\"' because it is not initialized\"",
",",
"$",
"statement",
")",
";",
"}",
"/*\n * Arrays must be stored in the HEAP\n */",
"if",
"(",
"$",
"symbolVariable",
"->",
"isLocalOnly",
"(",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"\"Cannot mutate variable '\"",
".",
"$",
"variable",
".",
"\"' because it is local only\"",
",",
"$",
"statement",
")",
";",
"}",
"if",
"(",
"!",
"$",
"symbolVariable",
"->",
"isInitialized",
"(",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"\"Cannot mutate variable '\"",
".",
"$",
"variable",
".",
"\"' because it is not initialized\"",
",",
"$",
"statement",
")",
";",
"}",
"/*\n * Only dynamic variables can be used as arrays\n */",
"if",
"(",
"!",
"$",
"symbolVariable",
"->",
"isVariable",
"(",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"\"Cannot use variable type: '\"",
".",
"$",
"symbolVariable",
"->",
"getType",
"(",
")",
".",
"\"' as array\"",
",",
"$",
"statement",
")",
";",
"}",
"if",
"(",
"$",
"symbolVariable",
"->",
"hasAnyDynamicType",
"(",
"'unknown'",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"'Cannot use non-initialized variable as an object'",
",",
"$",
"statement",
")",
";",
"}",
"/*\n * Trying to use a non-object dynamic variable as object\n */",
"if",
"(",
"$",
"symbolVariable",
"->",
"hasDifferentDynamicType",
"(",
"[",
"'undefined'",
",",
"'object'",
",",
"'null'",
"]",
")",
")",
"{",
"$",
"compilationContext",
"->",
"logger",
"->",
"warning",
"(",
"'Possible attempt to increment non-object dynamic variable'",
",",
"[",
"'non-object-update'",
",",
"$",
"statement",
"]",
")",
";",
"}",
"/*\n * Check if the variable to update is defined\n */",
"if",
"(",
"'this'",
"==",
"$",
"symbolVariable",
"->",
"getRealName",
"(",
")",
")",
"{",
"$",
"classDefinition",
"=",
"$",
"compilationContext",
"->",
"classDefinition",
";",
"if",
"(",
"!",
"$",
"classDefinition",
"->",
"hasProperty",
"(",
"$",
"property",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"\"Class '\"",
".",
"$",
"classDefinition",
"->",
"getCompleteName",
"(",
")",
".",
"\"' does not have a property called: '\"",
".",
"$",
"property",
".",
"\"'\"",
",",
"$",
"statement",
")",
";",
"}",
"}",
"else",
"{",
"/*\n * If we know the class related to a variable we could check if the property\n * is defined on that class\n */",
"if",
"(",
"$",
"symbolVariable",
"->",
"hasAnyDynamicType",
"(",
"'object'",
")",
")",
"{",
"$",
"classType",
"=",
"current",
"(",
"$",
"symbolVariable",
"->",
"getClassTypes",
"(",
")",
")",
";",
"$",
"compiler",
"=",
"$",
"compilationContext",
"->",
"compiler",
";",
"if",
"(",
"$",
"compiler",
"->",
"isClass",
"(",
"$",
"classType",
")",
")",
"{",
"$",
"classDefinition",
"=",
"$",
"compiler",
"->",
"getClassDefinition",
"(",
"$",
"classType",
")",
";",
"if",
"(",
"!",
"$",
"classDefinition",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"'Cannot locate class definition for class: '",
".",
"$",
"classType",
",",
"$",
"statement",
")",
";",
"}",
"if",
"(",
"!",
"$",
"classDefinition",
"->",
"hasProperty",
"(",
"$",
"property",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"\"Class '\"",
".",
"$",
"classType",
".",
"\"' does not have a property called: '\"",
".",
"$",
"property",
".",
"\"'\"",
",",
"$",
"statement",
")",
";",
"}",
"}",
"}",
"}",
"$",
"compilationContext",
"->",
"headersManager",
"->",
"add",
"(",
"'kernel/object'",
")",
";",
"$",
"compilationContext",
"->",
"codePrinter",
"->",
"output",
"(",
"'RETURN_ON_FAILURE(zephir_property_incr('",
".",
"$",
"symbolVariable",
"->",
"getName",
"(",
")",
".",
"', SL(\"'",
".",
"$",
"property",
".",
"'\") TSRMLS_CC));'",
")",
";",
"}"
] | Compiles obj->x++.
@param string $variable
@param string $property
@param ZephirVariable $symbolVariable
@param CompilationContext $compilationContext
@param array $statement | [
"Compiles",
"obj",
"-",
">",
"x",
"++",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Statements/Let/ObjectPropertyIncr.php#L34-L104 | train |
phalcon/zephir | Library/Detectors/WriteDetector.php | WriteDetector.passLetStatement | public function passLetStatement(array $statement)
{
foreach ($statement['assignments'] as $assignment) {
if (isset($assignment['expr'])) {
$this->passExpression($assignment['expr']);
}
$this->increaseMutations($assignment['variable']);
if (self::DETECT_VALUE_IN_ASSIGNMENT == ($this->detectionFlags & self::DETECT_VALUE_IN_ASSIGNMENT)) {
if (isset($assignment['expr'])) {
if ('variable' == $assignment['expr']['type']) {
$this->increaseMutations($assignment['expr']['value']);
break;
}
}
}
}
} | php | public function passLetStatement(array $statement)
{
foreach ($statement['assignments'] as $assignment) {
if (isset($assignment['expr'])) {
$this->passExpression($assignment['expr']);
}
$this->increaseMutations($assignment['variable']);
if (self::DETECT_VALUE_IN_ASSIGNMENT == ($this->detectionFlags & self::DETECT_VALUE_IN_ASSIGNMENT)) {
if (isset($assignment['expr'])) {
if ('variable' == $assignment['expr']['type']) {
$this->increaseMutations($assignment['expr']['value']);
break;
}
}
}
}
} | [
"public",
"function",
"passLetStatement",
"(",
"array",
"$",
"statement",
")",
"{",
"foreach",
"(",
"$",
"statement",
"[",
"'assignments'",
"]",
"as",
"$",
"assignment",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"assignment",
"[",
"'expr'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"assignment",
"[",
"'expr'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"increaseMutations",
"(",
"$",
"assignment",
"[",
"'variable'",
"]",
")",
";",
"if",
"(",
"self",
"::",
"DETECT_VALUE_IN_ASSIGNMENT",
"==",
"(",
"$",
"this",
"->",
"detectionFlags",
"&",
"self",
"::",
"DETECT_VALUE_IN_ASSIGNMENT",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"assignment",
"[",
"'expr'",
"]",
")",
")",
"{",
"if",
"(",
"'variable'",
"==",
"$",
"assignment",
"[",
"'expr'",
"]",
"[",
"'type'",
"]",
")",
"{",
"$",
"this",
"->",
"increaseMutations",
"(",
"$",
"assignment",
"[",
"'expr'",
"]",
"[",
"'value'",
"]",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}"
] | Pass let statements.
@param array $statement | [
"Pass",
"let",
"statements",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Detectors/WriteDetector.php#L102-L118 | train |
phalcon/zephir | Library/Detectors/WriteDetector.php | WriteDetector.passArray | public function passArray(array $expression)
{
foreach ($expression['left'] as $item) {
$usePass = self::DETECT_ARRAY_USE == ($this->detectionFlags & self::DETECT_ARRAY_USE);
if ($usePass && 'variable' == $item['value']['type']) {
$this->increaseMutations($item['value']['value']);
} else {
$this->passExpression($item['value']);
}
}
} | php | public function passArray(array $expression)
{
foreach ($expression['left'] as $item) {
$usePass = self::DETECT_ARRAY_USE == ($this->detectionFlags & self::DETECT_ARRAY_USE);
if ($usePass && 'variable' == $item['value']['type']) {
$this->increaseMutations($item['value']['value']);
} else {
$this->passExpression($item['value']);
}
}
} | [
"public",
"function",
"passArray",
"(",
"array",
"$",
"expression",
")",
"{",
"foreach",
"(",
"$",
"expression",
"[",
"'left'",
"]",
"as",
"$",
"item",
")",
"{",
"$",
"usePass",
"=",
"self",
"::",
"DETECT_ARRAY_USE",
"==",
"(",
"$",
"this",
"->",
"detectionFlags",
"&",
"self",
"::",
"DETECT_ARRAY_USE",
")",
";",
"if",
"(",
"$",
"usePass",
"&&",
"'variable'",
"==",
"$",
"item",
"[",
"'value'",
"]",
"[",
"'type'",
"]",
")",
"{",
"$",
"this",
"->",
"increaseMutations",
"(",
"$",
"item",
"[",
"'value'",
"]",
"[",
"'value'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"item",
"[",
"'value'",
"]",
")",
";",
"}",
"}",
"}"
] | Pass array expressions.
@param array $expression | [
"Pass",
"array",
"expressions",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Detectors/WriteDetector.php#L144-L154 | train |
phalcon/zephir | Library/Detectors/WriteDetector.php | WriteDetector.passNew | public function passNew(array $expression)
{
if (isset($expression['parameters'])) {
foreach ($expression['parameters'] as $parameter) {
$usePass = self::DETECT_PARAM_PASS == ($this->detectionFlags & self::DETECT_PARAM_PASS);
if ($usePass && 'variable' == $parameter['parameter']['type']) {
$this->increaseMutations($parameter['parameter']['value']);
} else {
$this->passExpression($parameter['parameter']);
}
}
}
} | php | public function passNew(array $expression)
{
if (isset($expression['parameters'])) {
foreach ($expression['parameters'] as $parameter) {
$usePass = self::DETECT_PARAM_PASS == ($this->detectionFlags & self::DETECT_PARAM_PASS);
if ($usePass && 'variable' == $parameter['parameter']['type']) {
$this->increaseMutations($parameter['parameter']['value']);
} else {
$this->passExpression($parameter['parameter']);
}
}
}
} | [
"public",
"function",
"passNew",
"(",
"array",
"$",
"expression",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"expression",
"[",
"'parameters'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"expression",
"[",
"'parameters'",
"]",
"as",
"$",
"parameter",
")",
"{",
"$",
"usePass",
"=",
"self",
"::",
"DETECT_PARAM_PASS",
"==",
"(",
"$",
"this",
"->",
"detectionFlags",
"&",
"self",
"::",
"DETECT_PARAM_PASS",
")",
";",
"if",
"(",
"$",
"usePass",
"&&",
"'variable'",
"==",
"$",
"parameter",
"[",
"'parameter'",
"]",
"[",
"'type'",
"]",
")",
"{",
"$",
"this",
"->",
"increaseMutations",
"(",
"$",
"parameter",
"[",
"'parameter'",
"]",
"[",
"'value'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"passExpression",
"(",
"$",
"parameter",
"[",
"'parameter'",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Pass "new" expressions.
@param array $expression | [
"Pass",
"new",
"expressions",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Detectors/WriteDetector.php#L161-L173 | train |
phalcon/zephir | Library/Detectors/WriteDetector.php | WriteDetector.declareVariables | public function declareVariables(array $statement)
{
if (isset($statement['data-type'])) {
if ('variable' != $statement['data-type']) {
return;
}
}
foreach ($statement['variables'] as $variable) {
if (isset($variable['expr'])) {
if ('string' == $variable['expr']['type'] || 'empty-array' == $variable['expr']['type'] || 'array' == $variable['expr']['type']) {
continue;
}
}
$this->increaseMutations($variable['variable']);
}
} | php | public function declareVariables(array $statement)
{
if (isset($statement['data-type'])) {
if ('variable' != $statement['data-type']) {
return;
}
}
foreach ($statement['variables'] as $variable) {
if (isset($variable['expr'])) {
if ('string' == $variable['expr']['type'] || 'empty-array' == $variable['expr']['type'] || 'array' == $variable['expr']['type']) {
continue;
}
}
$this->increaseMutations($variable['variable']);
}
} | [
"public",
"function",
"declareVariables",
"(",
"array",
"$",
"statement",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"statement",
"[",
"'data-type'",
"]",
")",
")",
"{",
"if",
"(",
"'variable'",
"!=",
"$",
"statement",
"[",
"'data-type'",
"]",
")",
"{",
"return",
";",
"}",
"}",
"foreach",
"(",
"$",
"statement",
"[",
"'variables'",
"]",
"as",
"$",
"variable",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"variable",
"[",
"'expr'",
"]",
")",
")",
"{",
"if",
"(",
"'string'",
"==",
"$",
"variable",
"[",
"'expr'",
"]",
"[",
"'type'",
"]",
"||",
"'empty-array'",
"==",
"$",
"variable",
"[",
"'expr'",
"]",
"[",
"'type'",
"]",
"||",
"'array'",
"==",
"$",
"variable",
"[",
"'expr'",
"]",
"[",
"'type'",
"]",
")",
"{",
"continue",
";",
"}",
"}",
"$",
"this",
"->",
"increaseMutations",
"(",
"$",
"variable",
"[",
"'variable'",
"]",
")",
";",
"}",
"}"
] | Pass "declare" statement.
@param array $statement | [
"Pass",
"declare",
"statement",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Detectors/WriteDetector.php#L180-L197 | train |
phalcon/zephir | Library/Operators/BaseOperator.php | BaseOperator.getExpectedNonLiteral | public function getExpectedNonLiteral(CompilationContext $compilationContext, $expression, $init = true)
{
$isExpecting = $this->expecting;
$symbolVariable = $this->expectingVariable;
if ($isExpecting) {
if (\is_object($symbolVariable)) {
if ('variable' == $symbolVariable->getType() && !$symbolVariable->isLocalOnly()) {
if (!$init) {
return $symbolVariable;
}
$symbolVariable->initVariant($compilationContext);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
}
}
return $symbolVariable;
} | php | public function getExpectedNonLiteral(CompilationContext $compilationContext, $expression, $init = true)
{
$isExpecting = $this->expecting;
$symbolVariable = $this->expectingVariable;
if ($isExpecting) {
if (\is_object($symbolVariable)) {
if ('variable' == $symbolVariable->getType() && !$symbolVariable->isLocalOnly()) {
if (!$init) {
return $symbolVariable;
}
$symbolVariable->initVariant($compilationContext);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
}
}
return $symbolVariable;
} | [
"public",
"function",
"getExpectedNonLiteral",
"(",
"CompilationContext",
"$",
"compilationContext",
",",
"$",
"expression",
",",
"$",
"init",
"=",
"true",
")",
"{",
"$",
"isExpecting",
"=",
"$",
"this",
"->",
"expecting",
";",
"$",
"symbolVariable",
"=",
"$",
"this",
"->",
"expectingVariable",
";",
"if",
"(",
"$",
"isExpecting",
")",
"{",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"symbolVariable",
")",
")",
"{",
"if",
"(",
"'variable'",
"==",
"$",
"symbolVariable",
"->",
"getType",
"(",
")",
"&&",
"!",
"$",
"symbolVariable",
"->",
"isLocalOnly",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"init",
")",
"{",
"return",
"$",
"symbolVariable",
";",
"}",
"$",
"symbolVariable",
"->",
"initVariant",
"(",
"$",
"compilationContext",
")",
";",
"}",
"else",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempVariableForWrite",
"(",
"'variable'",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"}",
"else",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempVariableForWrite",
"(",
"'variable'",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"}",
"return",
"$",
"symbolVariable",
";",
"}"
] | Returns the expected variable for assignment or creates a temporary variable to
store the result. This method returns a variable that is always stored in the heap.
@param CompilationContext $compilationContext
@param array $expression
@param bool $init
@return Variable | [
"Returns",
"the",
"expected",
"variable",
"for",
"assignment",
"or",
"creates",
"a",
"temporary",
"variable",
"to",
"store",
"the",
"result",
".",
"This",
"method",
"returns",
"a",
"variable",
"that",
"is",
"always",
"stored",
"in",
"the",
"heap",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Operators/BaseOperator.php#L53-L74 | train |
phalcon/zephir | Library/Operators/BaseOperator.php | BaseOperator.getExpected | public function getExpected(CompilationContext $compilationContext, $expression, $init = true)
{
$isExpecting = $this->expecting;
$symbolVariable = $this->expectingVariable;
if ($isExpecting) {
if (\is_object($symbolVariable)) {
if ('variable' == $symbolVariable->getType()) {
if (!$init) {
return $symbolVariable;
}
$symbolVariable->initVariant($compilationContext);
} else {
if (!$this->readOnly) {
if (!$this->literalOnly) {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite('variable', $compilationContext, $expression);
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
}
}
} else {
if (!$this->readOnly) {
if (!$this->literalOnly) {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite('variable', $compilationContext, $expression);
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
}
}
}
return $symbolVariable;
} | php | public function getExpected(CompilationContext $compilationContext, $expression, $init = true)
{
$isExpecting = $this->expecting;
$symbolVariable = $this->expectingVariable;
if ($isExpecting) {
if (\is_object($symbolVariable)) {
if ('variable' == $symbolVariable->getType()) {
if (!$init) {
return $symbolVariable;
}
$symbolVariable->initVariant($compilationContext);
} else {
if (!$this->readOnly) {
if (!$this->literalOnly) {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite('variable', $compilationContext, $expression);
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
}
}
} else {
if (!$this->readOnly) {
if (!$this->literalOnly) {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite('variable', $compilationContext, $expression);
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
}
}
}
return $symbolVariable;
} | [
"public",
"function",
"getExpected",
"(",
"CompilationContext",
"$",
"compilationContext",
",",
"$",
"expression",
",",
"$",
"init",
"=",
"true",
")",
"{",
"$",
"isExpecting",
"=",
"$",
"this",
"->",
"expecting",
";",
"$",
"symbolVariable",
"=",
"$",
"this",
"->",
"expectingVariable",
";",
"if",
"(",
"$",
"isExpecting",
")",
"{",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"symbolVariable",
")",
")",
"{",
"if",
"(",
"'variable'",
"==",
"$",
"symbolVariable",
"->",
"getType",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"init",
")",
"{",
"return",
"$",
"symbolVariable",
";",
"}",
"$",
"symbolVariable",
"->",
"initVariant",
"(",
"$",
"compilationContext",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"readOnly",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"literalOnly",
")",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempVariableForWrite",
"(",
"'variable'",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"else",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempComplexLiteralVariableForWrite",
"(",
"'variable'",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"}",
"else",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempLocalVariableForWrite",
"(",
"'variable'",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"readOnly",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"literalOnly",
")",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempVariableForWrite",
"(",
"'variable'",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"else",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempComplexLiteralVariableForWrite",
"(",
"'variable'",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"}",
"else",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempLocalVariableForWrite",
"(",
"'variable'",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"}",
"}",
"return",
"$",
"symbolVariable",
";",
"}"
] | Returns the expected variable for assignment or creates a temporary variable to
store the result.
@param CompilationContext $compilationContext
@param array $expression
@param bool $init
@return Variable | [
"Returns",
"the",
"expected",
"variable",
"for",
"assignment",
"or",
"creates",
"a",
"temporary",
"variable",
"to",
"store",
"the",
"result",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Operators/BaseOperator.php#L86-L123 | train |
phalcon/zephir | Library/Operators/BaseOperator.php | BaseOperator.getExpectedComplexLiteral | public function getExpectedComplexLiteral(CompilationContext $compilationContext, $expression, $type = 'variable')
{
$isExpecting = $this->expecting;
$symbolVariable = $this->expectingVariable;
if ($isExpecting) {
if (\is_object($symbolVariable)) {
if ($symbolVariable->getType() == $type || 'return_value' == $symbolVariable->getName()) {
$symbolVariable->initVariant($compilationContext);
} else {
if (!$this->readOnly) {
$symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite($type, $compilationContext, $expression);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite($type, $compilationContext, $expression);
}
}
} else {
if (!$this->readOnly) {
$symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite($type, $compilationContext, $expression);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite($type, $compilationContext, $expression);
}
}
}
return $symbolVariable;
} | php | public function getExpectedComplexLiteral(CompilationContext $compilationContext, $expression, $type = 'variable')
{
$isExpecting = $this->expecting;
$symbolVariable = $this->expectingVariable;
if ($isExpecting) {
if (\is_object($symbolVariable)) {
if ($symbolVariable->getType() == $type || 'return_value' == $symbolVariable->getName()) {
$symbolVariable->initVariant($compilationContext);
} else {
if (!$this->readOnly) {
$symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite($type, $compilationContext, $expression);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite($type, $compilationContext, $expression);
}
}
} else {
if (!$this->readOnly) {
$symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite($type, $compilationContext, $expression);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite($type, $compilationContext, $expression);
}
}
}
return $symbolVariable;
} | [
"public",
"function",
"getExpectedComplexLiteral",
"(",
"CompilationContext",
"$",
"compilationContext",
",",
"$",
"expression",
",",
"$",
"type",
"=",
"'variable'",
")",
"{",
"$",
"isExpecting",
"=",
"$",
"this",
"->",
"expecting",
";",
"$",
"symbolVariable",
"=",
"$",
"this",
"->",
"expectingVariable",
";",
"if",
"(",
"$",
"isExpecting",
")",
"{",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"symbolVariable",
")",
")",
"{",
"if",
"(",
"$",
"symbolVariable",
"->",
"getType",
"(",
")",
"==",
"$",
"type",
"||",
"'return_value'",
"==",
"$",
"symbolVariable",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"symbolVariable",
"->",
"initVariant",
"(",
"$",
"compilationContext",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"readOnly",
")",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempComplexLiteralVariableForWrite",
"(",
"$",
"type",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"else",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempLocalVariableForWrite",
"(",
"$",
"type",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"readOnly",
")",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempComplexLiteralVariableForWrite",
"(",
"$",
"type",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"else",
"{",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getTempLocalVariableForWrite",
"(",
"$",
"type",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"}",
"}",
"}",
"return",
"$",
"symbolVariable",
";",
"}"
] | Returns the expected variable for assignment or creates a temporary variable to
store the result, if a temporary variable is created it use whose body is only freed
on every iteration.
@param CompilationContext $compilationContext
@param array $expression
@param string $type
@return Variable | [
"Returns",
"the",
"expected",
"variable",
"for",
"assignment",
"or",
"creates",
"a",
"temporary",
"variable",
"to",
"store",
"the",
"result",
"if",
"a",
"temporary",
"variable",
"is",
"created",
"it",
"use",
"whose",
"body",
"is",
"only",
"freed",
"on",
"every",
"iteration",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Operators/BaseOperator.php#L136-L162 | train |
phalcon/zephir | Library/Operators/Other/NewInstanceTypeOperator.php | NewInstanceTypeOperator.compile | public function compile(array $expression, CompilationContext $compilationContext)
{
if (!isset($expression['parameters'])) {
throw new CompilerException("Invalid 'parameters' for new-type", $expression);
}
switch ($expression['internal-type']) {
case 'array':
$compilationContext->headersManager->add('kernel/array');
$functionName = 'create_array';
break;
case 'string':
$compilationContext->headersManager->add('kernel/string');
$functionName = 'create_string';
break;
default:
throw new CompilerException('Cannot build instance of type', $expression);
}
$builder = new FunctionCallBuilder(
$functionName,
$expression['parameters'],
1,
$expression['file'],
$expression['line'],
$expression['char']
);
/**
* Implicit type coercing.
*/
$castBuilder = new CastOperatorBuilder($expression['internal-type'], $builder);
$expression = new Expression($castBuilder->get());
$expression->setReadOnly($this->readOnly);
try {
return $expression->compile($compilationContext);
} catch (Exception $e) {
throw new CompilerException($e->getMessage(), $expression, $e->getCode(), $e);
}
} | php | public function compile(array $expression, CompilationContext $compilationContext)
{
if (!isset($expression['parameters'])) {
throw new CompilerException("Invalid 'parameters' for new-type", $expression);
}
switch ($expression['internal-type']) {
case 'array':
$compilationContext->headersManager->add('kernel/array');
$functionName = 'create_array';
break;
case 'string':
$compilationContext->headersManager->add('kernel/string');
$functionName = 'create_string';
break;
default:
throw new CompilerException('Cannot build instance of type', $expression);
}
$builder = new FunctionCallBuilder(
$functionName,
$expression['parameters'],
1,
$expression['file'],
$expression['line'],
$expression['char']
);
/**
* Implicit type coercing.
*/
$castBuilder = new CastOperatorBuilder($expression['internal-type'], $builder);
$expression = new Expression($castBuilder->get());
$expression->setReadOnly($this->readOnly);
try {
return $expression->compile($compilationContext);
} catch (Exception $e) {
throw new CompilerException($e->getMessage(), $expression, $e->getCode(), $e);
}
} | [
"public",
"function",
"compile",
"(",
"array",
"$",
"expression",
",",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"expression",
"[",
"'parameters'",
"]",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"\"Invalid 'parameters' for new-type\"",
",",
"$",
"expression",
")",
";",
"}",
"switch",
"(",
"$",
"expression",
"[",
"'internal-type'",
"]",
")",
"{",
"case",
"'array'",
":",
"$",
"compilationContext",
"->",
"headersManager",
"->",
"add",
"(",
"'kernel/array'",
")",
";",
"$",
"functionName",
"=",
"'create_array'",
";",
"break",
";",
"case",
"'string'",
":",
"$",
"compilationContext",
"->",
"headersManager",
"->",
"add",
"(",
"'kernel/string'",
")",
";",
"$",
"functionName",
"=",
"'create_string'",
";",
"break",
";",
"default",
":",
"throw",
"new",
"CompilerException",
"(",
"'Cannot build instance of type'",
",",
"$",
"expression",
")",
";",
"}",
"$",
"builder",
"=",
"new",
"FunctionCallBuilder",
"(",
"$",
"functionName",
",",
"$",
"expression",
"[",
"'parameters'",
"]",
",",
"1",
",",
"$",
"expression",
"[",
"'file'",
"]",
",",
"$",
"expression",
"[",
"'line'",
"]",
",",
"$",
"expression",
"[",
"'char'",
"]",
")",
";",
"/**\n * Implicit type coercing.\n */",
"$",
"castBuilder",
"=",
"new",
"CastOperatorBuilder",
"(",
"$",
"expression",
"[",
"'internal-type'",
"]",
",",
"$",
"builder",
")",
";",
"$",
"expression",
"=",
"new",
"Expression",
"(",
"$",
"castBuilder",
"->",
"get",
"(",
")",
")",
";",
"$",
"expression",
"->",
"setReadOnly",
"(",
"$",
"this",
"->",
"readOnly",
")",
";",
"try",
"{",
"return",
"$",
"expression",
"->",
"compile",
"(",
"$",
"compilationContext",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"expression",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Executes the operator.
@param array $expression
@param CompilationContext $compilationContext
@throws CompilerException
@return CompiledExpression | [
"Executes",
"the",
"operator",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Operators/Other/NewInstanceTypeOperator.php#L42-L85 | train |
phalcon/zephir | Library/Operators/Other/TypeHintOperator.php | TypeHintOperator.compile | public function compile(array $expression, CompilationContext $compilationContext)
{
$expr = new Expression($expression['right']);
$expr->setReadOnly(true);
$resolved = $expr->compile($compilationContext);
if ('variable' != $resolved->getType()) {
throw new CompilerException('Type-Hints only can be applied to dynamic variables.', $expression);
}
$symbolVariable = $compilationContext->symbolTable->getVariableForRead(
$resolved->getCode(),
$compilationContext,
$expression
);
if (!$symbolVariable->isVariable()) {
throw new CompilerException('Type-Hints only can be applied to dynamic variables.', $expression);
}
$symbolVariable->setDynamicTypes('object');
$symbolVariable->setClassTypes($compilationContext->getFullName($expression['left']['value']));
return $resolved;
} | php | public function compile(array $expression, CompilationContext $compilationContext)
{
$expr = new Expression($expression['right']);
$expr->setReadOnly(true);
$resolved = $expr->compile($compilationContext);
if ('variable' != $resolved->getType()) {
throw new CompilerException('Type-Hints only can be applied to dynamic variables.', $expression);
}
$symbolVariable = $compilationContext->symbolTable->getVariableForRead(
$resolved->getCode(),
$compilationContext,
$expression
);
if (!$symbolVariable->isVariable()) {
throw new CompilerException('Type-Hints only can be applied to dynamic variables.', $expression);
}
$symbolVariable->setDynamicTypes('object');
$symbolVariable->setClassTypes($compilationContext->getFullName($expression['left']['value']));
return $resolved;
} | [
"public",
"function",
"compile",
"(",
"array",
"$",
"expression",
",",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"$",
"expr",
"=",
"new",
"Expression",
"(",
"$",
"expression",
"[",
"'right'",
"]",
")",
";",
"$",
"expr",
"->",
"setReadOnly",
"(",
"true",
")",
";",
"$",
"resolved",
"=",
"$",
"expr",
"->",
"compile",
"(",
"$",
"compilationContext",
")",
";",
"if",
"(",
"'variable'",
"!=",
"$",
"resolved",
"->",
"getType",
"(",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"'Type-Hints only can be applied to dynamic variables.'",
",",
"$",
"expression",
")",
";",
"}",
"$",
"symbolVariable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getVariableForRead",
"(",
"$",
"resolved",
"->",
"getCode",
"(",
")",
",",
"$",
"compilationContext",
",",
"$",
"expression",
")",
";",
"if",
"(",
"!",
"$",
"symbolVariable",
"->",
"isVariable",
"(",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"'Type-Hints only can be applied to dynamic variables.'",
",",
"$",
"expression",
")",
";",
"}",
"$",
"symbolVariable",
"->",
"setDynamicTypes",
"(",
"'object'",
")",
";",
"$",
"symbolVariable",
"->",
"setClassTypes",
"(",
"$",
"compilationContext",
"->",
"getFullName",
"(",
"$",
"expression",
"[",
"'left'",
"]",
"[",
"'value'",
"]",
")",
")",
";",
"return",
"$",
"resolved",
";",
"}"
] | Performs type-hint compilation.
@param array $expression
@param CompilationContext $compilationContext
@throws CompilerException
@return CompiledExpression | [
"Performs",
"type",
"-",
"hint",
"compilation",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Operators/Other/TypeHintOperator.php#L47-L71 | train |
phalcon/zephir | Library/Documentation/Template.php | Template.themeOption | public function themeOption($name)
{
return isset($this->themeOptions[$name]) ? $this->themeOptions[$name] : null;
} | php | public function themeOption($name)
{
return isset($this->themeOptions[$name]) ? $this->themeOptions[$name] : null;
} | [
"public",
"function",
"themeOption",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"themeOptions",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"themeOptions",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | find the value of an option of the theme.
@param string $name the name of the option to get | [
"find",
"the",
"value",
"of",
"an",
"option",
"of",
"the",
"theme",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Documentation/Template.php#L103-L106 | train |
phalcon/zephir | Library/Documentation/Template.php | Template.url | public function url($url)
{
if (\is_string($url)) {
if ('/' == $url[0]) {
return $this->getPathToRoot().ltrim($url, '/');
} elseif (\is_string($url)) {
return $url;
}
} elseif ($url instanceof ClassDefinition) {
return $this->url(Documentation::classUrl($url));
} elseif ($url instanceof CompilerFile) {
return $this->url(Documentation::classUrl($url->getClassDefinition()));
}
return '';
} | php | public function url($url)
{
if (\is_string($url)) {
if ('/' == $url[0]) {
return $this->getPathToRoot().ltrim($url, '/');
} elseif (\is_string($url)) {
return $url;
}
} elseif ($url instanceof ClassDefinition) {
return $this->url(Documentation::classUrl($url));
} elseif ($url instanceof CompilerFile) {
return $this->url(Documentation::classUrl($url->getClassDefinition()));
}
return '';
} | [
"public",
"function",
"url",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"url",
")",
")",
"{",
"if",
"(",
"'/'",
"==",
"$",
"url",
"[",
"0",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"getPathToRoot",
"(",
")",
".",
"ltrim",
"(",
"$",
"url",
",",
"'/'",
")",
";",
"}",
"elseif",
"(",
"\\",
"is_string",
"(",
"$",
"url",
")",
")",
"{",
"return",
"$",
"url",
";",
"}",
"}",
"elseif",
"(",
"$",
"url",
"instanceof",
"ClassDefinition",
")",
"{",
"return",
"$",
"this",
"->",
"url",
"(",
"Documentation",
"::",
"classUrl",
"(",
"$",
"url",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"url",
"instanceof",
"CompilerFile",
")",
"{",
"return",
"$",
"this",
"->",
"url",
"(",
"Documentation",
"::",
"classUrl",
"(",
"$",
"url",
"->",
"getClassDefinition",
"(",
")",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
] | Generate an url relative to the current directory.
@param string $url the url we want to reach
@return string the relative path to the url | [
"Generate",
"an",
"url",
"relative",
"to",
"the",
"current",
"directory",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Documentation/Template.php#L159-L174 | train |
phalcon/zephir | Library/Cache/MethodCache.php | MethodCache.isClassCacheable | private function isClassCacheable($classDefinition)
{
if ($classDefinition instanceof ClassDefinition) {
return true;
}
if ($classDefinition instanceof \ReflectionClass) {
if ($classDefinition->isInternal() && $classDefinition->isInstantiable()) {
$extension = $classDefinition->getExtension();
switch ($extension->getName()) {
case 'Reflection':
case 'Core':
case 'SPL':
return true;
}
}
}
return false;
} | php | private function isClassCacheable($classDefinition)
{
if ($classDefinition instanceof ClassDefinition) {
return true;
}
if ($classDefinition instanceof \ReflectionClass) {
if ($classDefinition->isInternal() && $classDefinition->isInstantiable()) {
$extension = $classDefinition->getExtension();
switch ($extension->getName()) {
case 'Reflection':
case 'Core':
case 'SPL':
return true;
}
}
}
return false;
} | [
"private",
"function",
"isClassCacheable",
"(",
"$",
"classDefinition",
")",
"{",
"if",
"(",
"$",
"classDefinition",
"instanceof",
"ClassDefinition",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"classDefinition",
"instanceof",
"\\",
"ReflectionClass",
")",
"{",
"if",
"(",
"$",
"classDefinition",
"->",
"isInternal",
"(",
")",
"&&",
"$",
"classDefinition",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"$",
"extension",
"=",
"$",
"classDefinition",
"->",
"getExtension",
"(",
")",
";",
"switch",
"(",
"$",
"extension",
"->",
"getName",
"(",
")",
")",
"{",
"case",
"'Reflection'",
":",
"case",
"'Core'",
":",
"case",
"'SPL'",
":",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if the class is suitable for caching.
@param ClassDefinition $classDefinition
@return bool | [
"Checks",
"if",
"the",
"class",
"is",
"suitable",
"for",
"caching",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Cache/MethodCache.php#L192-L210 | train |
phalcon/zephir | Library/Cache/SlotsCache.php | SlotsCache.getFunctionSlot | public static function getFunctionSlot($functionName)
{
if (isset(self::$cacheFunctionSlots[$functionName])) {
return self::$cacheFunctionSlots[$functionName];
}
$slot = self::$slot++;
if ($slot >= self::MAX_SLOTS_NUMBER) {
return 0;
}
self::$cacheFunctionSlots[$functionName] = $slot;
return $slot;
} | php | public static function getFunctionSlot($functionName)
{
if (isset(self::$cacheFunctionSlots[$functionName])) {
return self::$cacheFunctionSlots[$functionName];
}
$slot = self::$slot++;
if ($slot >= self::MAX_SLOTS_NUMBER) {
return 0;
}
self::$cacheFunctionSlots[$functionName] = $slot;
return $slot;
} | [
"public",
"static",
"function",
"getFunctionSlot",
"(",
"$",
"functionName",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"cacheFunctionSlots",
"[",
"$",
"functionName",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"cacheFunctionSlots",
"[",
"$",
"functionName",
"]",
";",
"}",
"$",
"slot",
"=",
"self",
"::",
"$",
"slot",
"++",
";",
"if",
"(",
"$",
"slot",
">=",
"self",
"::",
"MAX_SLOTS_NUMBER",
")",
"{",
"return",
"0",
";",
"}",
"self",
"::",
"$",
"cacheFunctionSlots",
"[",
"$",
"functionName",
"]",
"=",
"$",
"slot",
";",
"return",
"$",
"slot",
";",
"}"
] | Returns or creates a cache slot for a function.
@param string $functionName
@return int | [
"Returns",
"or",
"creates",
"a",
"cache",
"slot",
"for",
"a",
"function",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Cache/SlotsCache.php#L39-L53 | train |
phalcon/zephir | Library/Cache/SlotsCache.php | SlotsCache.getMethodSlot | public static function getMethodSlot(ClassMethod $method)
{
$className = $method->getClassDefinition()->getCompleteName();
$methodName = $method->getName();
if (isset(self::$cacheMethodSlots[$className][$methodName])) {
return self::$cacheMethodSlots[$className][$methodName];
}
$slot = self::$slot++;
if ($slot >= self::MAX_SLOTS_NUMBER) {
return 0;
}
self::$cacheMethodSlots[$className][$methodName] = $slot;
return $slot;
} | php | public static function getMethodSlot(ClassMethod $method)
{
$className = $method->getClassDefinition()->getCompleteName();
$methodName = $method->getName();
if (isset(self::$cacheMethodSlots[$className][$methodName])) {
return self::$cacheMethodSlots[$className][$methodName];
}
$slot = self::$slot++;
if ($slot >= self::MAX_SLOTS_NUMBER) {
return 0;
}
self::$cacheMethodSlots[$className][$methodName] = $slot;
return $slot;
} | [
"public",
"static",
"function",
"getMethodSlot",
"(",
"ClassMethod",
"$",
"method",
")",
"{",
"$",
"className",
"=",
"$",
"method",
"->",
"getClassDefinition",
"(",
")",
"->",
"getCompleteName",
"(",
")",
";",
"$",
"methodName",
"=",
"$",
"method",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"cacheMethodSlots",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"cacheMethodSlots",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
";",
"}",
"$",
"slot",
"=",
"self",
"::",
"$",
"slot",
"++",
";",
"if",
"(",
"$",
"slot",
">=",
"self",
"::",
"MAX_SLOTS_NUMBER",
")",
"{",
"return",
"0",
";",
"}",
"self",
"::",
"$",
"cacheMethodSlots",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
"=",
"$",
"slot",
";",
"return",
"$",
"slot",
";",
"}"
] | Returns or creates a cache slot for a method.
@param ClassMethod $method
@return int | [
"Returns",
"or",
"creates",
"a",
"cache",
"slot",
"for",
"a",
"method",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Cache/SlotsCache.php#L78-L95 | train |
phalcon/zephir | Library/Cache/SlotsCache.php | SlotsCache.getExistingMethodSlot | public static function getExistingMethodSlot(ClassMethod $method)
{
$className = $method->getClassDefinition()->getCompleteName();
$methodName = $method->getName();
if (isset(self::$cacheMethodSlots[$className][$methodName])) {
return self::$cacheMethodSlots[$className][$methodName];
}
return 0;
} | php | public static function getExistingMethodSlot(ClassMethod $method)
{
$className = $method->getClassDefinition()->getCompleteName();
$methodName = $method->getName();
if (isset(self::$cacheMethodSlots[$className][$methodName])) {
return self::$cacheMethodSlots[$className][$methodName];
}
return 0;
} | [
"public",
"static",
"function",
"getExistingMethodSlot",
"(",
"ClassMethod",
"$",
"method",
")",
"{",
"$",
"className",
"=",
"$",
"method",
"->",
"getClassDefinition",
"(",
")",
"->",
"getCompleteName",
"(",
")",
";",
"$",
"methodName",
"=",
"$",
"method",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"cacheMethodSlots",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"cacheMethodSlots",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
";",
"}",
"return",
"0",
";",
"}"
] | Returns a cache slot for a method.
@param ClassMethod $method
@return int | [
"Returns",
"a",
"cache",
"slot",
"for",
"a",
"method",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Cache/SlotsCache.php#L104-L114 | train |
phalcon/zephir | Library/Types/AbstractType.php | AbstractType.invokeMethod | public function invokeMethod(
$methodName,
$caller,
CompilationContext
$compilationContext,
Call $call,
array $expression
) {
/*
* 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
);
} | php | public function invokeMethod(
$methodName,
$caller,
CompilationContext
$compilationContext,
Call $call,
array $expression
) {
/*
* 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
);
} | [
"public",
"function",
"invokeMethod",
"(",
"$",
"methodName",
",",
"$",
"caller",
",",
"CompilationContext",
"$",
"compilationContext",
",",
"Call",
"$",
"call",
",",
"array",
"$",
"expression",
")",
"{",
"/*\n * Checks first whether the method exist in the array type definition\n */",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"methodName",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"$",
"methodName",
"}",
"(",
"$",
"caller",
",",
"$",
"compilationContext",
",",
"$",
"call",
",",
"$",
"expression",
")",
";",
"}",
"/*\n * Check the method map\n */",
"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.
@param string $methodName
@param object $caller
@param CompilationContext $compilationContext
@param Call $call
@param array $expression
@throws CompilerException
@return bool|\Zephir\CompiledExpression | [
"Intercepts",
"calls",
"to",
"built",
"-",
"in",
"methods",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Types/AbstractType.php#L42-L99 | train |
phalcon/zephir | Library/Operators/Unary/MinusOperator.php | MinusOperator.compile | public function compile($expression, CompilationContext $compilationContext)
{
if (!isset($expression['left'])) {
throw new CompilerException('Missing left part of the expression');
}
$leftExpr = new Expression($expression['left']);
$leftExpr->setReadOnly($this->readOnly);
$left = $leftExpr->compile($compilationContext);
switch ($left->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
return new CompiledExpression($left->getType(), '-'.$left->getCode(), $expression);
case 'variable':
$variable = $compilationContext->symbolTable->getVariable($left->getCode());
switch ($variable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
return new CompiledExpression($variable->getType(), '-'.$variable->getName(), $expression);
case 'variable':
$compilationContext->headersManager->add('kernel/operators');
$compilationContext->codePrinter->output('zephir_negate('.$compilationContext->backend->getVariableCode($variable).' TSRMLS_CC);');
return new CompiledExpression('variable', $variable->getName(), $expression);
default:
throw new CompilerException("Cannot operate minus with variable of '".$left->getType()."' type");
}
break;
default:
throw new CompilerException("Cannot operate minus with '".$left->getType()."' type");
}
} | php | public function compile($expression, CompilationContext $compilationContext)
{
if (!isset($expression['left'])) {
throw new CompilerException('Missing left part of the expression');
}
$leftExpr = new Expression($expression['left']);
$leftExpr->setReadOnly($this->readOnly);
$left = $leftExpr->compile($compilationContext);
switch ($left->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
return new CompiledExpression($left->getType(), '-'.$left->getCode(), $expression);
case 'variable':
$variable = $compilationContext->symbolTable->getVariable($left->getCode());
switch ($variable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
return new CompiledExpression($variable->getType(), '-'.$variable->getName(), $expression);
case 'variable':
$compilationContext->headersManager->add('kernel/operators');
$compilationContext->codePrinter->output('zephir_negate('.$compilationContext->backend->getVariableCode($variable).' TSRMLS_CC);');
return new CompiledExpression('variable', $variable->getName(), $expression);
default:
throw new CompilerException("Cannot operate minus with variable of '".$left->getType()."' type");
}
break;
default:
throw new CompilerException("Cannot operate minus with '".$left->getType()."' type");
}
} | [
"public",
"function",
"compile",
"(",
"$",
"expression",
",",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"expression",
"[",
"'left'",
"]",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"'Missing left part of the expression'",
")",
";",
"}",
"$",
"leftExpr",
"=",
"new",
"Expression",
"(",
"$",
"expression",
"[",
"'left'",
"]",
")",
";",
"$",
"leftExpr",
"->",
"setReadOnly",
"(",
"$",
"this",
"->",
"readOnly",
")",
";",
"$",
"left",
"=",
"$",
"leftExpr",
"->",
"compile",
"(",
"$",
"compilationContext",
")",
";",
"switch",
"(",
"$",
"left",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'int'",
":",
"case",
"'uint'",
":",
"case",
"'long'",
":",
"case",
"'ulong'",
":",
"case",
"'double'",
":",
"return",
"new",
"CompiledExpression",
"(",
"$",
"left",
"->",
"getType",
"(",
")",
",",
"'-'",
".",
"$",
"left",
"->",
"getCode",
"(",
")",
",",
"$",
"expression",
")",
";",
"case",
"'variable'",
":",
"$",
"variable",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getVariable",
"(",
"$",
"left",
"->",
"getCode",
"(",
")",
")",
";",
"switch",
"(",
"$",
"variable",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'int'",
":",
"case",
"'uint'",
":",
"case",
"'long'",
":",
"case",
"'ulong'",
":",
"case",
"'double'",
":",
"return",
"new",
"CompiledExpression",
"(",
"$",
"variable",
"->",
"getType",
"(",
")",
",",
"'-'",
".",
"$",
"variable",
"->",
"getName",
"(",
")",
",",
"$",
"expression",
")",
";",
"case",
"'variable'",
":",
"$",
"compilationContext",
"->",
"headersManager",
"->",
"add",
"(",
"'kernel/operators'",
")",
";",
"$",
"compilationContext",
"->",
"codePrinter",
"->",
"output",
"(",
"'zephir_negate('",
".",
"$",
"compilationContext",
"->",
"backend",
"->",
"getVariableCode",
"(",
"$",
"variable",
")",
".",
"' TSRMLS_CC);'",
")",
";",
"return",
"new",
"CompiledExpression",
"(",
"'variable'",
",",
"$",
"variable",
"->",
"getName",
"(",
")",
",",
"$",
"expression",
")",
";",
"default",
":",
"throw",
"new",
"CompilerException",
"(",
"\"Cannot operate minus with variable of '\"",
".",
"$",
"left",
"->",
"getType",
"(",
")",
".",
"\"' type\"",
")",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"CompilerException",
"(",
"\"Cannot operate minus with '\"",
".",
"$",
"left",
"->",
"getType",
"(",
")",
".",
"\"' type\"",
")",
";",
"}",
"}"
] | Compile expression.
@param $expression
@param CompilationContext $compilationContext
@throws CompilerException
@return CompiledExpression | [
"Compile",
"expression",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Operators/Unary/MinusOperator.php#L32-L74 | train |
phalcon/zephir | Library/HeadersManager.php | HeadersManager.add | public function add($path, $position = 0)
{
if (!\is_string($path)) {
throw new \InvalidArgumentException('$path must be only string type');
}
if (!$position) {
$this->headers[$path] = $path;
} else {
switch ($position) {
case self::POSITION_FIRST:
$this->headersFirst[$path] = $path;
break;
case self::POSITION_LAST:
$this->headersLast[$path] = $path;
break;
default:
break;
}
}
} | php | public function add($path, $position = 0)
{
if (!\is_string($path)) {
throw new \InvalidArgumentException('$path must be only string type');
}
if (!$position) {
$this->headers[$path] = $path;
} else {
switch ($position) {
case self::POSITION_FIRST:
$this->headersFirst[$path] = $path;
break;
case self::POSITION_LAST:
$this->headersLast[$path] = $path;
break;
default:
break;
}
}
} | [
"public",
"function",
"add",
"(",
"$",
"path",
",",
"$",
"position",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$path must be only string type'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"position",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"$",
"path",
"]",
"=",
"$",
"path",
";",
"}",
"else",
"{",
"switch",
"(",
"$",
"position",
")",
"{",
"case",
"self",
"::",
"POSITION_FIRST",
":",
"$",
"this",
"->",
"headersFirst",
"[",
"$",
"path",
"]",
"=",
"$",
"path",
";",
"break",
";",
"case",
"self",
"::",
"POSITION_LAST",
":",
"$",
"this",
"->",
"headersLast",
"[",
"$",
"path",
"]",
"=",
"$",
"path",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"}",
"}"
] | Adds a header path to the manager.
@param string $path
@param int $position
@throws \InvalidArgumentException | [
"Adds",
"a",
"header",
"path",
"to",
"the",
"manager",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/HeadersManager.php#L60-L80 | train |
phalcon/zephir | Library/ClassConstant.php | ClassConstant.processValue | public function processValue(CompilationContext $compilationContext)
{
if ('constant' == $this->value['type']) {
$constant = new Constants();
$compiledExpression = $constant->compile($this->value, $compilationContext);
$this->value = [
'type' => $compiledExpression->getType(),
'value' => $compiledExpression->getCode(),
];
return;
}
if ('static-constant-access' == $this->value['type']) {
$staticConstantAccess = new StaticConstantAccess();
$compiledExpression = $staticConstantAccess->compile($this->value, $compilationContext);
$this->value = [
'type' => $compiledExpression->getType(),
'value' => $compiledExpression->getCode(),
];
return;
}
} | php | public function processValue(CompilationContext $compilationContext)
{
if ('constant' == $this->value['type']) {
$constant = new Constants();
$compiledExpression = $constant->compile($this->value, $compilationContext);
$this->value = [
'type' => $compiledExpression->getType(),
'value' => $compiledExpression->getCode(),
];
return;
}
if ('static-constant-access' == $this->value['type']) {
$staticConstantAccess = new StaticConstantAccess();
$compiledExpression = $staticConstantAccess->compile($this->value, $compilationContext);
$this->value = [
'type' => $compiledExpression->getType(),
'value' => $compiledExpression->getCode(),
];
return;
}
} | [
"public",
"function",
"processValue",
"(",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"if",
"(",
"'constant'",
"==",
"$",
"this",
"->",
"value",
"[",
"'type'",
"]",
")",
"{",
"$",
"constant",
"=",
"new",
"Constants",
"(",
")",
";",
"$",
"compiledExpression",
"=",
"$",
"constant",
"->",
"compile",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"compilationContext",
")",
";",
"$",
"this",
"->",
"value",
"=",
"[",
"'type'",
"=>",
"$",
"compiledExpression",
"->",
"getType",
"(",
")",
",",
"'value'",
"=>",
"$",
"compiledExpression",
"->",
"getCode",
"(",
")",
",",
"]",
";",
"return",
";",
"}",
"if",
"(",
"'static-constant-access'",
"==",
"$",
"this",
"->",
"value",
"[",
"'type'",
"]",
")",
"{",
"$",
"staticConstantAccess",
"=",
"new",
"StaticConstantAccess",
"(",
")",
";",
"$",
"compiledExpression",
"=",
"$",
"staticConstantAccess",
"->",
"compile",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"compilationContext",
")",
";",
"$",
"this",
"->",
"value",
"=",
"[",
"'type'",
"=>",
"$",
"compiledExpression",
"->",
"getType",
"(",
")",
",",
"'value'",
"=>",
"$",
"compiledExpression",
"->",
"getCode",
"(",
")",
",",
"]",
";",
"return",
";",
"}",
"}"
] | Process the value of the class constant if needed.
@param CompilationContext $compilationContext
@throws Exception | [
"Process",
"the",
"value",
"of",
"the",
"class",
"constant",
"if",
"needed",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassConstant.php#L127-L152 | train |
phalcon/zephir | Library/ClassConstant.php | ClassConstant.compile | public function compile(CompilationContext $compilationContext)
{
$this->processValue($compilationContext);
$constanValue = isset($this->value['value']) ? $this->value['value'] : null;
$compilationContext->backend->declareConstant(
$this->value['type'],
$this->getName(),
$constanValue,
$compilationContext
);
} | php | public function compile(CompilationContext $compilationContext)
{
$this->processValue($compilationContext);
$constanValue = isset($this->value['value']) ? $this->value['value'] : null;
$compilationContext->backend->declareConstant(
$this->value['type'],
$this->getName(),
$constanValue,
$compilationContext
);
} | [
"public",
"function",
"compile",
"(",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"$",
"this",
"->",
"processValue",
"(",
"$",
"compilationContext",
")",
";",
"$",
"constanValue",
"=",
"isset",
"(",
"$",
"this",
"->",
"value",
"[",
"'value'",
"]",
")",
"?",
"$",
"this",
"->",
"value",
"[",
"'value'",
"]",
":",
"null",
";",
"$",
"compilationContext",
"->",
"backend",
"->",
"declareConstant",
"(",
"$",
"this",
"->",
"value",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"constanValue",
",",
"$",
"compilationContext",
")",
";",
"}"
] | Produce the code to register a class constant.
@param CompilationContext $compilationContext
@throws CompilerException
@throws Exception | [
"Produce",
"the",
"code",
"to",
"register",
"a",
"class",
"constant",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassConstant.php#L162-L174 | train |
phalcon/zephir | Library/Console/Command/DevelopmentModeAwareTrait.php | DevelopmentModeAwareTrait.isDevelopmentModeEnabled | protected function isDevelopmentModeEnabled(InputInterface $input)
{
if (false == $input->getOption('no-dev')) {
return $input->getOption('dev') || PHP_DEBUG;
}
return false;
} | php | protected function isDevelopmentModeEnabled(InputInterface $input)
{
if (false == $input->getOption('no-dev')) {
return $input->getOption('dev') || PHP_DEBUG;
}
return false;
} | [
"protected",
"function",
"isDevelopmentModeEnabled",
"(",
"InputInterface",
"$",
"input",
")",
"{",
"if",
"(",
"false",
"==",
"$",
"input",
"->",
"getOption",
"(",
"'no-dev'",
")",
")",
"{",
"return",
"$",
"input",
"->",
"getOption",
"(",
"'dev'",
")",
"||",
"PHP_DEBUG",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if the development mode is enabled.
@param InputInterface $input
@return bool | [
"Checks",
"if",
"the",
"development",
"mode",
"is",
"enabled",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Console/Command/DevelopmentModeAwareTrait.php#L28-L35 | train |
phalcon/zephir | Library/AliasManager.php | AliasManager.add | public function add(array $useStatement)
{
foreach ($useStatement['aliases'] as $alias) {
if (isset($alias['alias'])) {
$this->aliases[$alias['alias']] = $alias['name'];
} else {
$parts = explode('\\', $alias['name']);
$implicitAlias = $parts[\count($parts) - 1];
$this->aliases[$implicitAlias] = $alias['name'];
}
}
} | php | public function add(array $useStatement)
{
foreach ($useStatement['aliases'] as $alias) {
if (isset($alias['alias'])) {
$this->aliases[$alias['alias']] = $alias['name'];
} else {
$parts = explode('\\', $alias['name']);
$implicitAlias = $parts[\count($parts) - 1];
$this->aliases[$implicitAlias] = $alias['name'];
}
}
} | [
"public",
"function",
"add",
"(",
"array",
"$",
"useStatement",
")",
"{",
"foreach",
"(",
"$",
"useStatement",
"[",
"'aliases'",
"]",
"as",
"$",
"alias",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"alias",
"[",
"'alias'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"[",
"'alias'",
"]",
"]",
"=",
"$",
"alias",
"[",
"'name'",
"]",
";",
"}",
"else",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"alias",
"[",
"'name'",
"]",
")",
";",
"$",
"implicitAlias",
"=",
"$",
"parts",
"[",
"\\",
"count",
"(",
"$",
"parts",
")",
"-",
"1",
"]",
";",
"$",
"this",
"->",
"aliases",
"[",
"$",
"implicitAlias",
"]",
"=",
"$",
"alias",
"[",
"'name'",
"]",
";",
"}",
"}",
"}"
] | Adds a renaming in a "use" to the alias manager.
@param array $useStatement | [
"Adds",
"a",
"renaming",
"in",
"a",
"use",
"to",
"the",
"alias",
"manager",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/AliasManager.php#L28-L39 | train |
phalcon/zephir | Library/ClassProperty.php | ClassProperty.getVisibilityAccessor | public function getVisibilityAccessor()
{
$modifiers = [];
foreach ($this->visibility as $visibility) {
switch ($visibility) {
case 'protected':
$modifiers['ZEND_ACC_PROTECTED'] = true;
break;
case 'private':
$modifiers['ZEND_ACC_PRIVATE'] = true;
break;
case 'public':
$modifiers['ZEND_ACC_PUBLIC'] = true;
break;
case 'static':
$modifiers['ZEND_ACC_STATIC'] = true;
break;
default:
throw new Exception('Unknown modifier '.$visibility);
}
}
return implode('|', array_keys($modifiers));
} | php | public function getVisibilityAccessor()
{
$modifiers = [];
foreach ($this->visibility as $visibility) {
switch ($visibility) {
case 'protected':
$modifiers['ZEND_ACC_PROTECTED'] = true;
break;
case 'private':
$modifiers['ZEND_ACC_PRIVATE'] = true;
break;
case 'public':
$modifiers['ZEND_ACC_PUBLIC'] = true;
break;
case 'static':
$modifiers['ZEND_ACC_STATIC'] = true;
break;
default:
throw new Exception('Unknown modifier '.$visibility);
}
}
return implode('|', array_keys($modifiers));
} | [
"public",
"function",
"getVisibilityAccessor",
"(",
")",
"{",
"$",
"modifiers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"visibility",
"as",
"$",
"visibility",
")",
"{",
"switch",
"(",
"$",
"visibility",
")",
"{",
"case",
"'protected'",
":",
"$",
"modifiers",
"[",
"'ZEND_ACC_PROTECTED'",
"]",
"=",
"true",
";",
"break",
";",
"case",
"'private'",
":",
"$",
"modifiers",
"[",
"'ZEND_ACC_PRIVATE'",
"]",
"=",
"true",
";",
"break",
";",
"case",
"'public'",
":",
"$",
"modifiers",
"[",
"'ZEND_ACC_PUBLIC'",
"]",
"=",
"true",
";",
"break",
";",
"case",
"'static'",
":",
"$",
"modifiers",
"[",
"'ZEND_ACC_STATIC'",
"]",
"=",
"true",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"'Unknown modifier '",
".",
"$",
"visibility",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"'|'",
",",
"array_keys",
"(",
"$",
"modifiers",
")",
")",
";",
"}"
] | Returns the C-visibility accessors for the model.
@throws Exception
@return string | [
"Returns",
"the",
"C",
"-",
"visibility",
"accessors",
"for",
"the",
"model",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassProperty.php#L147-L175 | train |
phalcon/zephir | Library/ClassProperty.php | ClassProperty.compile | public function compile(CompilationContext $compilationContext)
{
switch ($this->defaultValue['type']) {
case 'long':
case 'int':
case 'string':
case 'double':
case 'bool':
$this->declareProperty($compilationContext, $this->defaultValue['type'], $this->defaultValue['value']);
break;
case 'array':
case 'empty-array':
$this->initializeArray($compilationContext);
// no break
case 'null':
$this->declareProperty($compilationContext, $this->defaultValue['type'], null);
break;
case 'static-constant-access':
$expression = new Expression($this->defaultValue);
$compiledExpression = $expression->compile($compilationContext);
$this->declareProperty($compilationContext, $compiledExpression->getType(), $compiledExpression->getCode());
break;
default:
throw new CompilerException('Unknown default type: '.$this->defaultValue['type'], $this->original);
}
} | php | public function compile(CompilationContext $compilationContext)
{
switch ($this->defaultValue['type']) {
case 'long':
case 'int':
case 'string':
case 'double':
case 'bool':
$this->declareProperty($compilationContext, $this->defaultValue['type'], $this->defaultValue['value']);
break;
case 'array':
case 'empty-array':
$this->initializeArray($compilationContext);
// no break
case 'null':
$this->declareProperty($compilationContext, $this->defaultValue['type'], null);
break;
case 'static-constant-access':
$expression = new Expression($this->defaultValue);
$compiledExpression = $expression->compile($compilationContext);
$this->declareProperty($compilationContext, $compiledExpression->getType(), $compiledExpression->getCode());
break;
default:
throw new CompilerException('Unknown default type: '.$this->defaultValue['type'], $this->original);
}
} | [
"public",
"function",
"compile",
"(",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"defaultValue",
"[",
"'type'",
"]",
")",
"{",
"case",
"'long'",
":",
"case",
"'int'",
":",
"case",
"'string'",
":",
"case",
"'double'",
":",
"case",
"'bool'",
":",
"$",
"this",
"->",
"declareProperty",
"(",
"$",
"compilationContext",
",",
"$",
"this",
"->",
"defaultValue",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"defaultValue",
"[",
"'value'",
"]",
")",
";",
"break",
";",
"case",
"'array'",
":",
"case",
"'empty-array'",
":",
"$",
"this",
"->",
"initializeArray",
"(",
"$",
"compilationContext",
")",
";",
"// no break",
"case",
"'null'",
":",
"$",
"this",
"->",
"declareProperty",
"(",
"$",
"compilationContext",
",",
"$",
"this",
"->",
"defaultValue",
"[",
"'type'",
"]",
",",
"null",
")",
";",
"break",
";",
"case",
"'static-constant-access'",
":",
"$",
"expression",
"=",
"new",
"Expression",
"(",
"$",
"this",
"->",
"defaultValue",
")",
";",
"$",
"compiledExpression",
"=",
"$",
"expression",
"->",
"compile",
"(",
"$",
"compilationContext",
")",
";",
"$",
"this",
"->",
"declareProperty",
"(",
"$",
"compilationContext",
",",
"$",
"compiledExpression",
"->",
"getType",
"(",
")",
",",
"$",
"compiledExpression",
"->",
"getCode",
"(",
")",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"CompilerException",
"(",
"'Unknown default type: '",
".",
"$",
"this",
"->",
"defaultValue",
"[",
"'type'",
"]",
",",
"$",
"this",
"->",
"original",
")",
";",
"}",
"}"
] | Produce the code to register a property.
@param CompilationContext $compilationContext
@throws CompilerException | [
"Produce",
"the",
"code",
"to",
"register",
"a",
"property",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassProperty.php#L234-L263 | train |
phalcon/zephir | Library/ClassProperty.php | ClassProperty.removeInitializationStatements | protected function removeInitializationStatements(&$statements)
{
foreach ($statements as $index => $statement) {
if (!$this->isStatic()) {
if ($statement['expr']['left']['right']['value'] == $this->name) {
unset($statements[$index]);
}
} else {
if ($statement['assignments'][0]['property'] == $this->name) {
unset($statements[$index]);
}
}
}
} | php | protected function removeInitializationStatements(&$statements)
{
foreach ($statements as $index => $statement) {
if (!$this->isStatic()) {
if ($statement['expr']['left']['right']['value'] == $this->name) {
unset($statements[$index]);
}
} else {
if ($statement['assignments'][0]['property'] == $this->name) {
unset($statements[$index]);
}
}
}
} | [
"protected",
"function",
"removeInitializationStatements",
"(",
"&",
"$",
"statements",
")",
"{",
"foreach",
"(",
"$",
"statements",
"as",
"$",
"index",
"=>",
"$",
"statement",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isStatic",
"(",
")",
")",
"{",
"if",
"(",
"$",
"statement",
"[",
"'expr'",
"]",
"[",
"'left'",
"]",
"[",
"'right'",
"]",
"[",
"'value'",
"]",
"==",
"$",
"this",
"->",
"name",
")",
"{",
"unset",
"(",
"$",
"statements",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"statement",
"[",
"'assignments'",
"]",
"[",
"0",
"]",
"[",
"'property'",
"]",
"==",
"$",
"this",
"->",
"name",
")",
"{",
"unset",
"(",
"$",
"statements",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Removes all initialization statements related to this property.
@param array $statements | [
"Removes",
"all",
"initialization",
"statements",
"related",
"to",
"this",
"property",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassProperty.php#L270-L283 | train |
phalcon/zephir | Library/ClassProperty.php | ClassProperty.declareProperty | protected function declareProperty(CompilationContext $compilationContext, $type, $value)
{
$codePrinter = $compilationContext->codePrinter;
if (\is_object($value)) {
return;
}
$classEntry = $compilationContext->classDefinition->getClassEntry();
switch ($type) {
case 'long':
case 'int':
$codePrinter->output('zend_declare_property_long('.$classEntry.', SL("'.$this->getName().'"), '.$value.', '.$this->getVisibilityAccessor().' TSRMLS_CC);');
break;
case 'double':
$codePrinter->output('zend_declare_property_double('.$classEntry.', SL("'.$this->getName().'"), '.$value.', '.$this->getVisibilityAccessor().' TSRMLS_CC);');
break;
case 'bool':
$codePrinter->output('zend_declare_property_bool('.$classEntry.', SL("'.$this->getName().'"), '.$this->getBooleanCode($value).', '.$this->getVisibilityAccessor().' TSRMLS_CC);');
break;
case Types::T_CHAR:
case Types::T_STRING:
$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':
case 'empty-array':
case 'null':
$codePrinter->output('zend_declare_property_null('.$classEntry.', SL("'.$this->getName().'"), '.$this->getVisibilityAccessor().' TSRMLS_CC);');
break;
default:
throw new CompilerException('Unknown default type: '.$type, $this->original);
}
} | php | protected function declareProperty(CompilationContext $compilationContext, $type, $value)
{
$codePrinter = $compilationContext->codePrinter;
if (\is_object($value)) {
return;
}
$classEntry = $compilationContext->classDefinition->getClassEntry();
switch ($type) {
case 'long':
case 'int':
$codePrinter->output('zend_declare_property_long('.$classEntry.', SL("'.$this->getName().'"), '.$value.', '.$this->getVisibilityAccessor().' TSRMLS_CC);');
break;
case 'double':
$codePrinter->output('zend_declare_property_double('.$classEntry.', SL("'.$this->getName().'"), '.$value.', '.$this->getVisibilityAccessor().' TSRMLS_CC);');
break;
case 'bool':
$codePrinter->output('zend_declare_property_bool('.$classEntry.', SL("'.$this->getName().'"), '.$this->getBooleanCode($value).', '.$this->getVisibilityAccessor().' TSRMLS_CC);');
break;
case Types::T_CHAR:
case Types::T_STRING:
$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':
case 'empty-array':
case 'null':
$codePrinter->output('zend_declare_property_null('.$classEntry.', SL("'.$this->getName().'"), '.$this->getVisibilityAccessor().' TSRMLS_CC);');
break;
default:
throw new CompilerException('Unknown default type: '.$type, $this->original);
}
} | [
"protected",
"function",
"declareProperty",
"(",
"CompilationContext",
"$",
"compilationContext",
",",
"$",
"type",
",",
"$",
"value",
")",
"{",
"$",
"codePrinter",
"=",
"$",
"compilationContext",
"->",
"codePrinter",
";",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
";",
"}",
"$",
"classEntry",
"=",
"$",
"compilationContext",
"->",
"classDefinition",
"->",
"getClassEntry",
"(",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'long'",
":",
"case",
"'int'",
":",
"$",
"codePrinter",
"->",
"output",
"(",
"'zend_declare_property_long('",
".",
"$",
"classEntry",
".",
"', SL(\"'",
".",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'\"), '",
".",
"$",
"value",
".",
"', '",
".",
"$",
"this",
"->",
"getVisibilityAccessor",
"(",
")",
".",
"' TSRMLS_CC);'",
")",
";",
"break",
";",
"case",
"'double'",
":",
"$",
"codePrinter",
"->",
"output",
"(",
"'zend_declare_property_double('",
".",
"$",
"classEntry",
".",
"', SL(\"'",
".",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'\"), '",
".",
"$",
"value",
".",
"', '",
".",
"$",
"this",
"->",
"getVisibilityAccessor",
"(",
")",
".",
"' TSRMLS_CC);'",
")",
";",
"break",
";",
"case",
"'bool'",
":",
"$",
"codePrinter",
"->",
"output",
"(",
"'zend_declare_property_bool('",
".",
"$",
"classEntry",
".",
"', SL(\"'",
".",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'\"), '",
".",
"$",
"this",
"->",
"getBooleanCode",
"(",
"$",
"value",
")",
".",
"', '",
".",
"$",
"this",
"->",
"getVisibilityAccessor",
"(",
")",
".",
"' TSRMLS_CC);'",
")",
";",
"break",
";",
"case",
"Types",
"::",
"T_CHAR",
":",
"case",
"Types",
"::",
"T_STRING",
":",
"$",
"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'",
":",
"case",
"'empty-array'",
":",
"case",
"'null'",
":",
"$",
"codePrinter",
"->",
"output",
"(",
"'zend_declare_property_null('",
".",
"$",
"classEntry",
".",
"', SL(\"'",
".",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'\"), '",
".",
"$",
"this",
"->",
"getVisibilityAccessor",
"(",
")",
".",
"' TSRMLS_CC);'",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"CompilerException",
"(",
"'Unknown default type: '",
".",
"$",
"type",
",",
"$",
"this",
"->",
"original",
")",
";",
"}",
"}"
] | Declare class property with default value.
@param CompilationContext $compilationContext
@param string $type
@param $value
@throws CompilerException | [
"Declare",
"class",
"property",
"with",
"default",
"value",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassProperty.php#L355-L401 | train |
phalcon/zephir | Library/Backends/ZendEngine3/Backend.php | Backend.assignZval | public function assignZval(Variable $variable, $code, CompilationContext $context)
{
$code = $this->resolveValue($code, $context);
if (!$variable->isDoublePointer()) {
$context->symbolTable->mustGrownStack(true);
$symbolVariable = $this->getVariableCode($variable);
$context->codePrinter->output('ZEPHIR_OBS_COPY_OR_DUP('.$symbolVariable.', '.$code.');');
} else {
$context->codePrinter->output($variable->getName().' = '.$code.';');
}
} | php | public function assignZval(Variable $variable, $code, CompilationContext $context)
{
$code = $this->resolveValue($code, $context);
if (!$variable->isDoublePointer()) {
$context->symbolTable->mustGrownStack(true);
$symbolVariable = $this->getVariableCode($variable);
$context->codePrinter->output('ZEPHIR_OBS_COPY_OR_DUP('.$symbolVariable.', '.$code.');');
} else {
$context->codePrinter->output($variable->getName().' = '.$code.';');
}
} | [
"public",
"function",
"assignZval",
"(",
"Variable",
"$",
"variable",
",",
"$",
"code",
",",
"CompilationContext",
"$",
"context",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"resolveValue",
"(",
"$",
"code",
",",
"$",
"context",
")",
";",
"if",
"(",
"!",
"$",
"variable",
"->",
"isDoublePointer",
"(",
")",
")",
"{",
"$",
"context",
"->",
"symbolTable",
"->",
"mustGrownStack",
"(",
"true",
")",
";",
"$",
"symbolVariable",
"=",
"$",
"this",
"->",
"getVariableCode",
"(",
"$",
"variable",
")",
";",
"$",
"context",
"->",
"codePrinter",
"->",
"output",
"(",
"'ZEPHIR_OBS_COPY_OR_DUP('",
".",
"$",
"symbolVariable",
".",
"', '",
".",
"$",
"code",
".",
"');'",
")",
";",
"}",
"else",
"{",
"$",
"context",
"->",
"codePrinter",
"->",
"output",
"(",
"$",
"variable",
"->",
"getName",
"(",
")",
".",
"' = '",
".",
"$",
"code",
".",
"';'",
")",
";",
"}",
"}"
] | Assigns a zval to another.
@param Variable $variable
@param string $code
@param CompilationContext $context | [
"Assigns",
"a",
"zval",
"to",
"another",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Backends/ZendEngine3/Backend.php#L392-L402 | train |
phalcon/zephir | Library/FunctionLike/ReturnType/Collection.php | Collection.getTypesBySpecification | public function getTypesBySpecification(SpecificationInterface $spec)
{
$types = [];
foreach ($this as $type) {
/** @var TypeInterface $type */
if ($spec->isSatisfiedBy($type)) {
$types[] = $type;
}
}
return $types;
} | php | public function getTypesBySpecification(SpecificationInterface $spec)
{
$types = [];
foreach ($this as $type) {
/** @var TypeInterface $type */
if ($spec->isSatisfiedBy($type)) {
$types[] = $type;
}
}
return $types;
} | [
"public",
"function",
"getTypesBySpecification",
"(",
"SpecificationInterface",
"$",
"spec",
")",
"{",
"$",
"types",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"type",
")",
"{",
"/** @var TypeInterface $type */",
"if",
"(",
"$",
"spec",
"->",
"isSatisfiedBy",
"(",
"$",
"type",
")",
")",
"{",
"$",
"types",
"[",
"]",
"=",
"$",
"type",
";",
"}",
"}",
"return",
"$",
"types",
";",
"}"
] | Gets all return types satisfied by specification.
@param SpecificationInterface $spec
@return TypeInterface[] | [
"Gets",
"all",
"return",
"types",
"satisfied",
"by",
"specification",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/FunctionLike/ReturnType/Collection.php#L81-L93 | train |
phalcon/zephir | Library/FunctionLike/ReturnType/Collection.php | Collection.onlySpecial | public function onlySpecial()
{
if (0 == $this->count()) {
return false;
}
$found = $this->getTypesBySpecification(new Specification\IsSpecial());
return \count($found) == $this->count();
} | php | public function onlySpecial()
{
if (0 == $this->count()) {
return false;
}
$found = $this->getTypesBySpecification(new Specification\IsSpecial());
return \count($found) == $this->count();
} | [
"public",
"function",
"onlySpecial",
"(",
")",
"{",
"if",
"(",
"0",
"==",
"$",
"this",
"->",
"count",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"found",
"=",
"$",
"this",
"->",
"getTypesBySpecification",
"(",
"new",
"Specification",
"\\",
"IsSpecial",
"(",
")",
")",
";",
"return",
"\\",
"count",
"(",
"$",
"found",
")",
"==",
"$",
"this",
"->",
"count",
"(",
")",
";",
"}"
] | Checks if the collection has only special types. | [
"Checks",
"if",
"the",
"collection",
"has",
"only",
"special",
"types",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/FunctionLike/ReturnType/Collection.php#L186-L195 | train |
phalcon/zephir | Library/FunctionLike/ReturnType/Collection.php | Collection.areReturnTypesWellKnown | public function areReturnTypesWellKnown()
{
if (0 == $this->count() || $this->isSatisfiedByTypeSpec(new Specification\IsSpecial())) {
return false;
}
$spec =
(new Specification\ObjectLike())
->either(new Specification\ArrayCompatible())
->either(new Specification\IntCompatible())
->either(new Specification\StringCompatible())
->either(new Specification\IsBool())
->either(new Specification\IsDouble())
->either(new Specification\IsNull())
// TODO: Please double check this
->either(new Specification\IsVoid());
$found = $this->getTypesBySpecification($spec);
return \count($found) == $this->count();
} | php | public function areReturnTypesWellKnown()
{
if (0 == $this->count() || $this->isSatisfiedByTypeSpec(new Specification\IsSpecial())) {
return false;
}
$spec =
(new Specification\ObjectLike())
->either(new Specification\ArrayCompatible())
->either(new Specification\IntCompatible())
->either(new Specification\StringCompatible())
->either(new Specification\IsBool())
->either(new Specification\IsDouble())
->either(new Specification\IsNull())
// TODO: Please double check this
->either(new Specification\IsVoid());
$found = $this->getTypesBySpecification($spec);
return \count($found) == $this->count();
} | [
"public",
"function",
"areReturnTypesWellKnown",
"(",
")",
"{",
"if",
"(",
"0",
"==",
"$",
"this",
"->",
"count",
"(",
")",
"||",
"$",
"this",
"->",
"isSatisfiedByTypeSpec",
"(",
"new",
"Specification",
"\\",
"IsSpecial",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"spec",
"=",
"(",
"new",
"Specification",
"\\",
"ObjectLike",
"(",
")",
")",
"->",
"either",
"(",
"new",
"Specification",
"\\",
"ArrayCompatible",
"(",
")",
")",
"->",
"either",
"(",
"new",
"Specification",
"\\",
"IntCompatible",
"(",
")",
")",
"->",
"either",
"(",
"new",
"Specification",
"\\",
"StringCompatible",
"(",
")",
")",
"->",
"either",
"(",
"new",
"Specification",
"\\",
"IsBool",
"(",
")",
")",
"->",
"either",
"(",
"new",
"Specification",
"\\",
"IsDouble",
"(",
")",
")",
"->",
"either",
"(",
"new",
"Specification",
"\\",
"IsNull",
"(",
")",
")",
"// TODO: Please double check this",
"->",
"either",
"(",
"new",
"Specification",
"\\",
"IsVoid",
"(",
")",
")",
";",
"$",
"found",
"=",
"$",
"this",
"->",
"getTypesBySpecification",
"(",
"$",
"spec",
")",
";",
"return",
"\\",
"count",
"(",
"$",
"found",
")",
"==",
"$",
"this",
"->",
"count",
"(",
")",
";",
"}"
] | Checks whether all return types hint are well known.
@return bool | [
"Checks",
"whether",
"all",
"return",
"types",
"hint",
"are",
"well",
"known",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/FunctionLike/ReturnType/Collection.php#L202-L222 | train |
phalcon/zephir | Library/FunctionLike/ReturnType/Collection.php | Collection.areReturnTypesCompatible | public function areReturnTypesCompatible()
{
$numberOfReturnTypes = $this->count();
if (0 == $numberOfReturnTypes || 1 == $numberOfReturnTypes) {
return true;
}
// <Class_1> | <Class_2> | ... | <Class_n>
$classes = $this->getObjectLikeReturnTypes();
// <Class> | <Class_1[]> | <Class_1[]> | ... | <Class_n[]>
$collections = $this->getTypesBySpecification(new Specification\IsCollection());
if (\count($collections) > 0 && $this->areReturnTypesObjectCompatible()) {
return false;
}
$summ =
// array | <Class_1[]> | <Class_2[]> | ... | <Class_n[]>
(int) $this->areReturnTypesArrayCompatible() +
// char | uchar | int | uint | long | ulong
(int) $this->areReturnTypesIntCompatible() +
// bool
(int) $this->areReturnTypesBoolCompatible() +
// istring | string
(int) $this->areReturnTypesStringCompatible() +
// double
(int) $this->areReturnTypesDoubleCompatible();
// T1 | T2 | ... | Tn
if ($summ > 1) {
return false;
}
// <Class_1> | <T1>
if ($this->areReturnTypesObjectCompatible() && $summ > 0) {
return false;
}
// null
$null = (int) $this->areReturnTypesNullCompatible();
// <T1> | null
// <Class_1> | null
// <Class_1[]> | null
if (1 == $null && 2 == $this->count()) {
return true;
}
// T1 | T2 | ... | Tn | null
if (1 == $null && $null + $summ != $this->count()) {
return false;
}
return 1 == $summ;
} | php | public function areReturnTypesCompatible()
{
$numberOfReturnTypes = $this->count();
if (0 == $numberOfReturnTypes || 1 == $numberOfReturnTypes) {
return true;
}
// <Class_1> | <Class_2> | ... | <Class_n>
$classes = $this->getObjectLikeReturnTypes();
// <Class> | <Class_1[]> | <Class_1[]> | ... | <Class_n[]>
$collections = $this->getTypesBySpecification(new Specification\IsCollection());
if (\count($collections) > 0 && $this->areReturnTypesObjectCompatible()) {
return false;
}
$summ =
// array | <Class_1[]> | <Class_2[]> | ... | <Class_n[]>
(int) $this->areReturnTypesArrayCompatible() +
// char | uchar | int | uint | long | ulong
(int) $this->areReturnTypesIntCompatible() +
// bool
(int) $this->areReturnTypesBoolCompatible() +
// istring | string
(int) $this->areReturnTypesStringCompatible() +
// double
(int) $this->areReturnTypesDoubleCompatible();
// T1 | T2 | ... | Tn
if ($summ > 1) {
return false;
}
// <Class_1> | <T1>
if ($this->areReturnTypesObjectCompatible() && $summ > 0) {
return false;
}
// null
$null = (int) $this->areReturnTypesNullCompatible();
// <T1> | null
// <Class_1> | null
// <Class_1[]> | null
if (1 == $null && 2 == $this->count()) {
return true;
}
// T1 | T2 | ... | Tn | null
if (1 == $null && $null + $summ != $this->count()) {
return false;
}
return 1 == $summ;
} | [
"public",
"function",
"areReturnTypesCompatible",
"(",
")",
"{",
"$",
"numberOfReturnTypes",
"=",
"$",
"this",
"->",
"count",
"(",
")",
";",
"if",
"(",
"0",
"==",
"$",
"numberOfReturnTypes",
"||",
"1",
"==",
"$",
"numberOfReturnTypes",
")",
"{",
"return",
"true",
";",
"}",
"// <Class_1> | <Class_2> | ... | <Class_n>",
"$",
"classes",
"=",
"$",
"this",
"->",
"getObjectLikeReturnTypes",
"(",
")",
";",
"// <Class> | <Class_1[]> | <Class_1[]> | ... | <Class_n[]>",
"$",
"collections",
"=",
"$",
"this",
"->",
"getTypesBySpecification",
"(",
"new",
"Specification",
"\\",
"IsCollection",
"(",
")",
")",
";",
"if",
"(",
"\\",
"count",
"(",
"$",
"collections",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"areReturnTypesObjectCompatible",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"summ",
"=",
"// array | <Class_1[]> | <Class_2[]> | ... | <Class_n[]>",
"(",
"int",
")",
"$",
"this",
"->",
"areReturnTypesArrayCompatible",
"(",
")",
"+",
"// char | uchar | int | uint | long | ulong",
"(",
"int",
")",
"$",
"this",
"->",
"areReturnTypesIntCompatible",
"(",
")",
"+",
"// bool",
"(",
"int",
")",
"$",
"this",
"->",
"areReturnTypesBoolCompatible",
"(",
")",
"+",
"// istring | string",
"(",
"int",
")",
"$",
"this",
"->",
"areReturnTypesStringCompatible",
"(",
")",
"+",
"// double",
"(",
"int",
")",
"$",
"this",
"->",
"areReturnTypesDoubleCompatible",
"(",
")",
";",
"// T1 | T2 | ... | Tn",
"if",
"(",
"$",
"summ",
">",
"1",
")",
"{",
"return",
"false",
";",
"}",
"// <Class_1> | <T1>",
"if",
"(",
"$",
"this",
"->",
"areReturnTypesObjectCompatible",
"(",
")",
"&&",
"$",
"summ",
">",
"0",
")",
"{",
"return",
"false",
";",
"}",
"// null",
"$",
"null",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"areReturnTypesNullCompatible",
"(",
")",
";",
"// <T1> | null",
"// <Class_1> | null",
"// <Class_1[]> | null",
"if",
"(",
"1",
"==",
"$",
"null",
"&&",
"2",
"==",
"$",
"this",
"->",
"count",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"// T1 | T2 | ... | Tn | null",
"if",
"(",
"1",
"==",
"$",
"null",
"&&",
"$",
"null",
"+",
"$",
"summ",
"!=",
"$",
"this",
"->",
"count",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"1",
"==",
"$",
"summ",
";",
"}"
] | Checks if the collection have compatible return types.
@return bool | [
"Checks",
"if",
"the",
"collection",
"have",
"compatible",
"return",
"types",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/FunctionLike/ReturnType/Collection.php#L229-L288 | train |
phalcon/zephir | Library/Statements/Let/Variable.php | Variable.doArrayAssignment | private function doArrayAssignment(
CodePrinter $codePrinter,
CompiledExpression $resolvedExpr,
ZephirVariable $symbolVariable,
$variable,
array $statement,
CompilationContext $compilationContext
) {
switch ($resolvedExpr->getType()) {
case 'variable':
case 'array':
switch ($statement['operator']) {
case 'assign':
if ($variable != $resolvedExpr->getCode()) {
$symbolVariable->setMustInitNull(true);
$compilationContext->symbolTable->mustGrownStack(true);
/* Inherit the dynamic type data from the assigned value */
$symbolVariable->setDynamicTypes('array');
$symbolVariable->increaseVariantIfNull();
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
$codePrinter->output('ZEPHIR_CPY_WRT('.$symbol.', '.$compilationContext->backend->resolveValue($resolvedExpr, $compilationContext).');');
}
break;
default:
throw new IllegalOperationException($statement, $resolvedExpr, $resolvedExpr->getOriginal());
}
break;
default:
throw new CompilerException("Cannot '".$statement['operator']."' ".$resolvedExpr->getType().' for array type', $resolvedExpr->getOriginal());
}
} | php | private function doArrayAssignment(
CodePrinter $codePrinter,
CompiledExpression $resolvedExpr,
ZephirVariable $symbolVariable,
$variable,
array $statement,
CompilationContext $compilationContext
) {
switch ($resolvedExpr->getType()) {
case 'variable':
case 'array':
switch ($statement['operator']) {
case 'assign':
if ($variable != $resolvedExpr->getCode()) {
$symbolVariable->setMustInitNull(true);
$compilationContext->symbolTable->mustGrownStack(true);
/* Inherit the dynamic type data from the assigned value */
$symbolVariable->setDynamicTypes('array');
$symbolVariable->increaseVariantIfNull();
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
$codePrinter->output('ZEPHIR_CPY_WRT('.$symbol.', '.$compilationContext->backend->resolveValue($resolvedExpr, $compilationContext).');');
}
break;
default:
throw new IllegalOperationException($statement, $resolvedExpr, $resolvedExpr->getOriginal());
}
break;
default:
throw new CompilerException("Cannot '".$statement['operator']."' ".$resolvedExpr->getType().' for array type', $resolvedExpr->getOriginal());
}
} | [
"private",
"function",
"doArrayAssignment",
"(",
"CodePrinter",
"$",
"codePrinter",
",",
"CompiledExpression",
"$",
"resolvedExpr",
",",
"ZephirVariable",
"$",
"symbolVariable",
",",
"$",
"variable",
",",
"array",
"$",
"statement",
",",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"switch",
"(",
"$",
"resolvedExpr",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'variable'",
":",
"case",
"'array'",
":",
"switch",
"(",
"$",
"statement",
"[",
"'operator'",
"]",
")",
"{",
"case",
"'assign'",
":",
"if",
"(",
"$",
"variable",
"!=",
"$",
"resolvedExpr",
"->",
"getCode",
"(",
")",
")",
"{",
"$",
"symbolVariable",
"->",
"setMustInitNull",
"(",
"true",
")",
";",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"mustGrownStack",
"(",
"true",
")",
";",
"/* Inherit the dynamic type data from the assigned value */",
"$",
"symbolVariable",
"->",
"setDynamicTypes",
"(",
"'array'",
")",
";",
"$",
"symbolVariable",
"->",
"increaseVariantIfNull",
"(",
")",
";",
"$",
"symbol",
"=",
"$",
"compilationContext",
"->",
"backend",
"->",
"getVariableCode",
"(",
"$",
"symbolVariable",
")",
";",
"$",
"codePrinter",
"->",
"output",
"(",
"'ZEPHIR_CPY_WRT('",
".",
"$",
"symbol",
".",
"', '",
".",
"$",
"compilationContext",
"->",
"backend",
"->",
"resolveValue",
"(",
"$",
"resolvedExpr",
",",
"$",
"compilationContext",
")",
".",
"');'",
")",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"IllegalOperationException",
"(",
"$",
"statement",
",",
"$",
"resolvedExpr",
",",
"$",
"resolvedExpr",
"->",
"getOriginal",
"(",
")",
")",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"CompilerException",
"(",
"\"Cannot '\"",
".",
"$",
"statement",
"[",
"'operator'",
"]",
".",
"\"' \"",
".",
"$",
"resolvedExpr",
"->",
"getType",
"(",
")",
".",
"' for array type'",
",",
"$",
"resolvedExpr",
"->",
"getOriginal",
"(",
")",
")",
";",
"}",
"}"
] | Performs array assignment.
@param CodePrinter $codePrinter
@param CompiledExpression $resolvedExpr
@param ZephirVariable $symbolVariable
@param string $variable
@param array $statement
@param CompilationContext $compilationContext
@throws CompilerException
@throws IllegalOperationException | [
"Performs",
"array",
"assignment",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Statements/Let/Variable.php#L730-L764 | train |
phalcon/zephir | Library/Backends/ZendEngine2/Backend.php | Backend.getTypeofCondition | public function getTypeofCondition(Variable $variableVariable, $operator, $value, CompilationContext $context)
{
$variableName = $this->getVariableCode($variableVariable);
switch ($value) {
case 'array':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_ARRAY';
break;
case 'object':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_OBJECT';
break;
case 'null':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_NULL';
break;
case 'string':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_STRING';
break;
case 'int':
case 'long':
case 'integer':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_LONG';
break;
case 'double':
case 'float':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_DOUBLE';
break;
case 'boolean':
case 'bool':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_BOOL';
break;
case 'resource':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_RESOURCE';
break;
case 'callable':
$condition = 'zephir_is_callable('.$variableName.' TSRMLS_CC) '.$operator.' 1';
break;
default:
throw new CompilerException(sprintf('Unknown type: "%s" in typeof comparison', $value));
}
return $condition;
} | php | public function getTypeofCondition(Variable $variableVariable, $operator, $value, CompilationContext $context)
{
$variableName = $this->getVariableCode($variableVariable);
switch ($value) {
case 'array':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_ARRAY';
break;
case 'object':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_OBJECT';
break;
case 'null':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_NULL';
break;
case 'string':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_STRING';
break;
case 'int':
case 'long':
case 'integer':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_LONG';
break;
case 'double':
case 'float':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_DOUBLE';
break;
case 'boolean':
case 'bool':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_BOOL';
break;
case 'resource':
$condition = 'Z_TYPE_P('.$variableName.') '.$operator.' IS_RESOURCE';
break;
case 'callable':
$condition = 'zephir_is_callable('.$variableName.' TSRMLS_CC) '.$operator.' 1';
break;
default:
throw new CompilerException(sprintf('Unknown type: "%s" in typeof comparison', $value));
}
return $condition;
} | [
"public",
"function",
"getTypeofCondition",
"(",
"Variable",
"$",
"variableVariable",
",",
"$",
"operator",
",",
"$",
"value",
",",
"CompilationContext",
"$",
"context",
")",
"{",
"$",
"variableName",
"=",
"$",
"this",
"->",
"getVariableCode",
"(",
"$",
"variableVariable",
")",
";",
"switch",
"(",
"$",
"value",
")",
"{",
"case",
"'array'",
":",
"$",
"condition",
"=",
"'Z_TYPE_P('",
".",
"$",
"variableName",
".",
"') '",
".",
"$",
"operator",
".",
"' IS_ARRAY'",
";",
"break",
";",
"case",
"'object'",
":",
"$",
"condition",
"=",
"'Z_TYPE_P('",
".",
"$",
"variableName",
".",
"') '",
".",
"$",
"operator",
".",
"' IS_OBJECT'",
";",
"break",
";",
"case",
"'null'",
":",
"$",
"condition",
"=",
"'Z_TYPE_P('",
".",
"$",
"variableName",
".",
"') '",
".",
"$",
"operator",
".",
"' IS_NULL'",
";",
"break",
";",
"case",
"'string'",
":",
"$",
"condition",
"=",
"'Z_TYPE_P('",
".",
"$",
"variableName",
".",
"') '",
".",
"$",
"operator",
".",
"' IS_STRING'",
";",
"break",
";",
"case",
"'int'",
":",
"case",
"'long'",
":",
"case",
"'integer'",
":",
"$",
"condition",
"=",
"'Z_TYPE_P('",
".",
"$",
"variableName",
".",
"') '",
".",
"$",
"operator",
".",
"' IS_LONG'",
";",
"break",
";",
"case",
"'double'",
":",
"case",
"'float'",
":",
"$",
"condition",
"=",
"'Z_TYPE_P('",
".",
"$",
"variableName",
".",
"') '",
".",
"$",
"operator",
".",
"' IS_DOUBLE'",
";",
"break",
";",
"case",
"'boolean'",
":",
"case",
"'bool'",
":",
"$",
"condition",
"=",
"'Z_TYPE_P('",
".",
"$",
"variableName",
".",
"') '",
".",
"$",
"operator",
".",
"' IS_BOOL'",
";",
"break",
";",
"case",
"'resource'",
":",
"$",
"condition",
"=",
"'Z_TYPE_P('",
".",
"$",
"variableName",
".",
"') '",
".",
"$",
"operator",
".",
"' IS_RESOURCE'",
";",
"break",
";",
"case",
"'callable'",
":",
"$",
"condition",
"=",
"'zephir_is_callable('",
".",
"$",
"variableName",
".",
"' TSRMLS_CC) '",
".",
"$",
"operator",
".",
"' 1'",
";",
"break",
";",
"default",
":",
"throw",
"new",
"CompilerException",
"(",
"sprintf",
"(",
"'Unknown type: \"%s\" in typeof comparison'",
",",
"$",
"value",
")",
")",
";",
"}",
"return",
"$",
"condition",
";",
"}"
] | Checks the type of a variable using the ZendEngine constants.
@param Variable $variableVariable
@param string $operator
@param string $value
@param CompilationContext $context
@throws CompilerException
@return string | [
"Checks",
"the",
"type",
"of",
"a",
"variable",
"using",
"the",
"ZendEngine",
"constants",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Backends/ZendEngine2/Backend.php#L211-L260 | train |
phalcon/zephir | Library/Backends/ZendEngine2/Backend.php | Backend.getInternalSignature | public function getInternalSignature(ClassMethod $method, CompilationContext $context)
{
if ($method->isInitializer() && !$method->isStatic()) {
return 'zend_object_value '.$method->getName().'(zend_class_entry *class_type TSRMLS_DC)';
}
if ($method->isInitializer() && $method->isStatic()) {
return 'void '.$method->getName().'(TSRMLS_D)';
}
$signatureParameters = [];
$parameters = $method->getParameters();
if (\is_object($parameters)) {
foreach ($parameters->getParameters() as $parameter) {
switch ($parameter['data-type']) {
case 'int':
case 'uint':
case 'long':
case 'double':
case 'bool':
case 'char':
case 'uchar':
case 'string':
case 'array':
$signatureParameters[] = 'zval *'.$parameter['name'].'_param_ext';
break;
default:
$signatureParameters[] = 'zval *'.$parameter['name'].'_ext';
break;
}
}
}
if (\count($signatureParameters)) {
return 'void '.$method->getInternalName().'(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used, '.implode(', ', $signatureParameters).' TSRMLS_DC)';
}
return 'void '.$method->getInternalName().'(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC)';
} | php | public function getInternalSignature(ClassMethod $method, CompilationContext $context)
{
if ($method->isInitializer() && !$method->isStatic()) {
return 'zend_object_value '.$method->getName().'(zend_class_entry *class_type TSRMLS_DC)';
}
if ($method->isInitializer() && $method->isStatic()) {
return 'void '.$method->getName().'(TSRMLS_D)';
}
$signatureParameters = [];
$parameters = $method->getParameters();
if (\is_object($parameters)) {
foreach ($parameters->getParameters() as $parameter) {
switch ($parameter['data-type']) {
case 'int':
case 'uint':
case 'long':
case 'double':
case 'bool':
case 'char':
case 'uchar':
case 'string':
case 'array':
$signatureParameters[] = 'zval *'.$parameter['name'].'_param_ext';
break;
default:
$signatureParameters[] = 'zval *'.$parameter['name'].'_ext';
break;
}
}
}
if (\count($signatureParameters)) {
return 'void '.$method->getInternalName().'(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used, '.implode(', ', $signatureParameters).' TSRMLS_DC)';
}
return 'void '.$method->getInternalName().'(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC)';
} | [
"public",
"function",
"getInternalSignature",
"(",
"ClassMethod",
"$",
"method",
",",
"CompilationContext",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"method",
"->",
"isInitializer",
"(",
")",
"&&",
"!",
"$",
"method",
"->",
"isStatic",
"(",
")",
")",
"{",
"return",
"'zend_object_value '",
".",
"$",
"method",
"->",
"getName",
"(",
")",
".",
"'(zend_class_entry *class_type TSRMLS_DC)'",
";",
"}",
"if",
"(",
"$",
"method",
"->",
"isInitializer",
"(",
")",
"&&",
"$",
"method",
"->",
"isStatic",
"(",
")",
")",
"{",
"return",
"'void '",
".",
"$",
"method",
"->",
"getName",
"(",
")",
".",
"'(TSRMLS_D)'",
";",
"}",
"$",
"signatureParameters",
"=",
"[",
"]",
";",
"$",
"parameters",
"=",
"$",
"method",
"->",
"getParameters",
"(",
")",
";",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"parameters",
")",
")",
"{",
"foreach",
"(",
"$",
"parameters",
"->",
"getParameters",
"(",
")",
"as",
"$",
"parameter",
")",
"{",
"switch",
"(",
"$",
"parameter",
"[",
"'data-type'",
"]",
")",
"{",
"case",
"'int'",
":",
"case",
"'uint'",
":",
"case",
"'long'",
":",
"case",
"'double'",
":",
"case",
"'bool'",
":",
"case",
"'char'",
":",
"case",
"'uchar'",
":",
"case",
"'string'",
":",
"case",
"'array'",
":",
"$",
"signatureParameters",
"[",
"]",
"=",
"'zval *'",
".",
"$",
"parameter",
"[",
"'name'",
"]",
".",
"'_param_ext'",
";",
"break",
";",
"default",
":",
"$",
"signatureParameters",
"[",
"]",
"=",
"'zval *'",
".",
"$",
"parameter",
"[",
"'name'",
"]",
".",
"'_ext'",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"signatureParameters",
")",
")",
"{",
"return",
"'void '",
".",
"$",
"method",
"->",
"getInternalName",
"(",
")",
".",
"'(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used, '",
".",
"implode",
"(",
"', '",
",",
"$",
"signatureParameters",
")",
".",
"' TSRMLS_DC)'",
";",
"}",
"return",
"'void '",
".",
"$",
"method",
"->",
"getInternalName",
"(",
")",
".",
"'(int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC)'",
";",
"}"
] | Returns the signature of an internal method. | [
"Returns",
"the",
"signature",
"of",
"an",
"internal",
"method",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Backends/ZendEngine2/Backend.php#L559-L598 | train |
phalcon/zephir | Library/Backends/ZendEngine2/Backend.php | Backend.resolveOffsetExprs | private function resolveOffsetExprs($offsetExprs, CompilationContext $compilationContext)
{
$keys = '';
$offsetItems = [];
$numberParams = 0;
foreach ($offsetExprs as $offsetExpr) {
if ('a' == $offsetExpr) {
$keys .= 'a';
++$numberParams;
continue;
}
switch ($offsetExpr->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
$keys .= 'l';
$offsetItems[] = $offsetExpr->getCode();
++$numberParams;
break;
case 'string':
$keys .= 's';
$offsetItems[] = 'SL("'.$offsetExpr->getCode().'")';
$numberParams += 2;
break;
case 'variable':
$variableIndex = $compilationContext->symbolTable->getVariableForRead(
$offsetExpr->getCode(),
$compilationContext,
null
);
switch ($variableIndex->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
$keys .= 'l';
$offsetItems[] = $this->getVariableCode($variableIndex);
++$numberParams;
break;
case 'string':
case 'variable':
$keys .= 'z';
$offsetItems[] = $this->getVariableCode($variableIndex);
++$numberParams;
break;
default:
throw new CompilerException(
sprintf('Variable: %s cannot be used as array index', $variableIndex->getType()),
$offsetExpr->getOriginal()
);
}
break;
default:
throw new CompilerException(
sprintf('Value: %s cannot be used as array index', $offsetExpr->getType()),
$offsetExpr->getOriginal()
);
}
}
return [$keys, $offsetItems, $numberParams];
} | php | private function resolveOffsetExprs($offsetExprs, CompilationContext $compilationContext)
{
$keys = '';
$offsetItems = [];
$numberParams = 0;
foreach ($offsetExprs as $offsetExpr) {
if ('a' == $offsetExpr) {
$keys .= 'a';
++$numberParams;
continue;
}
switch ($offsetExpr->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
$keys .= 'l';
$offsetItems[] = $offsetExpr->getCode();
++$numberParams;
break;
case 'string':
$keys .= 's';
$offsetItems[] = 'SL("'.$offsetExpr->getCode().'")';
$numberParams += 2;
break;
case 'variable':
$variableIndex = $compilationContext->symbolTable->getVariableForRead(
$offsetExpr->getCode(),
$compilationContext,
null
);
switch ($variableIndex->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
$keys .= 'l';
$offsetItems[] = $this->getVariableCode($variableIndex);
++$numberParams;
break;
case 'string':
case 'variable':
$keys .= 'z';
$offsetItems[] = $this->getVariableCode($variableIndex);
++$numberParams;
break;
default:
throw new CompilerException(
sprintf('Variable: %s cannot be used as array index', $variableIndex->getType()),
$offsetExpr->getOriginal()
);
}
break;
default:
throw new CompilerException(
sprintf('Value: %s cannot be used as array index', $offsetExpr->getType()),
$offsetExpr->getOriginal()
);
}
}
return [$keys, $offsetItems, $numberParams];
} | [
"private",
"function",
"resolveOffsetExprs",
"(",
"$",
"offsetExprs",
",",
"CompilationContext",
"$",
"compilationContext",
")",
"{",
"$",
"keys",
"=",
"''",
";",
"$",
"offsetItems",
"=",
"[",
"]",
";",
"$",
"numberParams",
"=",
"0",
";",
"foreach",
"(",
"$",
"offsetExprs",
"as",
"$",
"offsetExpr",
")",
"{",
"if",
"(",
"'a'",
"==",
"$",
"offsetExpr",
")",
"{",
"$",
"keys",
".=",
"'a'",
";",
"++",
"$",
"numberParams",
";",
"continue",
";",
"}",
"switch",
"(",
"$",
"offsetExpr",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'int'",
":",
"case",
"'uint'",
":",
"case",
"'long'",
":",
"case",
"'ulong'",
":",
"$",
"keys",
".=",
"'l'",
";",
"$",
"offsetItems",
"[",
"]",
"=",
"$",
"offsetExpr",
"->",
"getCode",
"(",
")",
";",
"++",
"$",
"numberParams",
";",
"break",
";",
"case",
"'string'",
":",
"$",
"keys",
".=",
"'s'",
";",
"$",
"offsetItems",
"[",
"]",
"=",
"'SL(\"'",
".",
"$",
"offsetExpr",
"->",
"getCode",
"(",
")",
".",
"'\")'",
";",
"$",
"numberParams",
"+=",
"2",
";",
"break",
";",
"case",
"'variable'",
":",
"$",
"variableIndex",
"=",
"$",
"compilationContext",
"->",
"symbolTable",
"->",
"getVariableForRead",
"(",
"$",
"offsetExpr",
"->",
"getCode",
"(",
")",
",",
"$",
"compilationContext",
",",
"null",
")",
";",
"switch",
"(",
"$",
"variableIndex",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'int'",
":",
"case",
"'uint'",
":",
"case",
"'long'",
":",
"case",
"'ulong'",
":",
"$",
"keys",
".=",
"'l'",
";",
"$",
"offsetItems",
"[",
"]",
"=",
"$",
"this",
"->",
"getVariableCode",
"(",
"$",
"variableIndex",
")",
";",
"++",
"$",
"numberParams",
";",
"break",
";",
"case",
"'string'",
":",
"case",
"'variable'",
":",
"$",
"keys",
".=",
"'z'",
";",
"$",
"offsetItems",
"[",
"]",
"=",
"$",
"this",
"->",
"getVariableCode",
"(",
"$",
"variableIndex",
")",
";",
"++",
"$",
"numberParams",
";",
"break",
";",
"default",
":",
"throw",
"new",
"CompilerException",
"(",
"sprintf",
"(",
"'Variable: %s cannot be used as array index'",
",",
"$",
"variableIndex",
"->",
"getType",
"(",
")",
")",
",",
"$",
"offsetExpr",
"->",
"getOriginal",
"(",
")",
")",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"CompilerException",
"(",
"sprintf",
"(",
"'Value: %s cannot be used as array index'",
",",
"$",
"offsetExpr",
"->",
"getType",
"(",
")",
")",
",",
"$",
"offsetExpr",
"->",
"getOriginal",
"(",
")",
")",
";",
"}",
"}",
"return",
"[",
"$",
"keys",
",",
"$",
"offsetItems",
",",
"$",
"numberParams",
"]",
";",
"}"
] | Resolve expressions.
@param CompiledExpression[]|string[] $offsetExprs
@param CompilationContext $compilationContext
@throws CompilerException
@return array | [
"Resolve",
"expressions",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/Backends/ZendEngine2/Backend.php#L1518-L1585 | train |
phalcon/zephir | Library/StatementsBlock.php | StatementsBlock.getLastLine | public function getLastLine()
{
if (!$this->lastStatement) {
$this->lastStatement = $this->statements[\count($this->statements) - 1];
}
} | php | public function getLastLine()
{
if (!$this->lastStatement) {
$this->lastStatement = $this->statements[\count($this->statements) - 1];
}
} | [
"public",
"function",
"getLastLine",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"lastStatement",
")",
"{",
"$",
"this",
"->",
"lastStatement",
"=",
"$",
"this",
"->",
"statements",
"[",
"\\",
"count",
"(",
"$",
"this",
"->",
"statements",
")",
"-",
"1",
"]",
";",
"}",
"}"
] | Returns the last line in the last statement. | [
"Returns",
"the",
"last",
"line",
"in",
"the",
"last",
"statement",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/StatementsBlock.php#L393-L398 | train |
phalcon/zephir | Library/ClassDefinition.php | ClassDefinition.setImplementsInterfaces | public function setImplementsInterfaces(array $implementedInterfaces)
{
$interfaces = [];
foreach ($implementedInterfaces as $implementedInterface) {
$interfaces[] = $implementedInterface['value'];
}
$this->interfaces = $interfaces;
} | php | public function setImplementsInterfaces(array $implementedInterfaces)
{
$interfaces = [];
foreach ($implementedInterfaces as $implementedInterface) {
$interfaces[] = $implementedInterface['value'];
}
$this->interfaces = $interfaces;
} | [
"public",
"function",
"setImplementsInterfaces",
"(",
"array",
"$",
"implementedInterfaces",
")",
"{",
"$",
"interfaces",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"implementedInterfaces",
"as",
"$",
"implementedInterface",
")",
"{",
"$",
"interfaces",
"[",
"]",
"=",
"$",
"implementedInterface",
"[",
"'value'",
"]",
";",
"}",
"$",
"this",
"->",
"interfaces",
"=",
"$",
"interfaces",
";",
"}"
] | Sets the implemented interfaces.
@param array $implementedInterfaces | [
"Sets",
"the",
"implemented",
"interfaces",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassDefinition.php#L321-L329 | train |
phalcon/zephir | Library/ClassDefinition.php | ClassDefinition.getExtendsClassDefinition | public function getExtendsClassDefinition()
{
if (!$this->extendsClassDefinition && $this->extendsClass) {
if ($this->compiler) {
$this->setExtendsClassDefinition($this->compiler->getClassDefinition($this->extendsClass));
}
}
return $this->extendsClassDefinition;
} | php | public function getExtendsClassDefinition()
{
if (!$this->extendsClassDefinition && $this->extendsClass) {
if ($this->compiler) {
$this->setExtendsClassDefinition($this->compiler->getClassDefinition($this->extendsClass));
}
}
return $this->extendsClassDefinition;
} | [
"public",
"function",
"getExtendsClassDefinition",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"extendsClassDefinition",
"&&",
"$",
"this",
"->",
"extendsClass",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"compiler",
")",
"{",
"$",
"this",
"->",
"setExtendsClassDefinition",
"(",
"$",
"this",
"->",
"compiler",
"->",
"getClassDefinition",
"(",
"$",
"this",
"->",
"extendsClass",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"extendsClassDefinition",
";",
"}"
] | Returns the class definition related to the extended class.
@return ClassDefinition|ClassDefinitionRuntime | [
"Returns",
"the",
"class",
"definition",
"related",
"to",
"the",
"extended",
"class",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassDefinition.php#L366-L375 | train |
phalcon/zephir | Library/ClassDefinition.php | ClassDefinition.getDependencies | public function getDependencies()
{
$dependencies = [];
if ($this->extendsClassDefinition && $this->extendsClassDefinition instanceof self) {
$dependencies[] = $this->extendsClassDefinition;
}
foreach ($this->implementedInterfaceDefinitions as $interfaceDefinition) {
if ($interfaceDefinition instanceof self) {
$dependencies[] = $interfaceDefinition;
}
}
return $dependencies;
} | php | public function getDependencies()
{
$dependencies = [];
if ($this->extendsClassDefinition && $this->extendsClassDefinition instanceof self) {
$dependencies[] = $this->extendsClassDefinition;
}
foreach ($this->implementedInterfaceDefinitions as $interfaceDefinition) {
if ($interfaceDefinition instanceof self) {
$dependencies[] = $interfaceDefinition;
}
}
return $dependencies;
} | [
"public",
"function",
"getDependencies",
"(",
")",
"{",
"$",
"dependencies",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"extendsClassDefinition",
"&&",
"$",
"this",
"->",
"extendsClassDefinition",
"instanceof",
"self",
")",
"{",
"$",
"dependencies",
"[",
"]",
"=",
"$",
"this",
"->",
"extendsClassDefinition",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"implementedInterfaceDefinitions",
"as",
"$",
"interfaceDefinition",
")",
"{",
"if",
"(",
"$",
"interfaceDefinition",
"instanceof",
"self",
")",
"{",
"$",
"dependencies",
"[",
"]",
"=",
"$",
"interfaceDefinition",
";",
"}",
"}",
"return",
"$",
"dependencies",
";",
"}"
] | Calculate the dependency rank of the class based on its dependencies.
@return ClassDefinition[] | [
"Calculate",
"the",
"dependency",
"rank",
"of",
"the",
"class",
"based",
"on",
"its",
"dependencies",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassDefinition.php#L402-L416 | train |
phalcon/zephir | Library/ClassDefinition.php | ClassDefinition.getParsedDocBlock | public function getParsedDocBlock()
{
if (!$this->parsedDocblock) {
if (\strlen($this->docBlock) > 0) {
$parser = new DocblockParser('/'.$this->docBlock.'/');
$this->parsedDocblock = $parser->parse();
} else {
return null;
}
}
return $this->parsedDocblock;
} | php | public function getParsedDocBlock()
{
if (!$this->parsedDocblock) {
if (\strlen($this->docBlock) > 0) {
$parser = new DocblockParser('/'.$this->docBlock.'/');
$this->parsedDocblock = $parser->parse();
} else {
return null;
}
}
return $this->parsedDocblock;
} | [
"public",
"function",
"getParsedDocBlock",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parsedDocblock",
")",
"{",
"if",
"(",
"\\",
"strlen",
"(",
"$",
"this",
"->",
"docBlock",
")",
">",
"0",
")",
"{",
"$",
"parser",
"=",
"new",
"DocblockParser",
"(",
"'/'",
".",
"$",
"this",
"->",
"docBlock",
".",
"'/'",
")",
";",
"$",
"this",
"->",
"parsedDocblock",
"=",
"$",
"parser",
"->",
"parse",
"(",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"parsedDocblock",
";",
"}"
] | Returns the parsed docBlock.
@return DocBlock|null | [
"Returns",
"the",
"parsed",
"docBlock",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassDefinition.php#L463-L475 | train |
phalcon/zephir | Library/ClassDefinition.php | ClassDefinition.addProperty | public function addProperty(ClassProperty $property)
{
if (isset($this->properties[$property->getName()])) {
throw new CompilerException("Property '".$property->getName()."' was defined more than one time", $property->getOriginal());
}
$this->properties[$property->getName()] = $property;
} | php | public function addProperty(ClassProperty $property)
{
if (isset($this->properties[$property->getName()])) {
throw new CompilerException("Property '".$property->getName()."' was defined more than one time", $property->getOriginal());
}
$this->properties[$property->getName()] = $property;
} | [
"public",
"function",
"addProperty",
"(",
"ClassProperty",
"$",
"property",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"properties",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"throw",
"new",
"CompilerException",
"(",
"\"Property '\"",
".",
"$",
"property",
"->",
"getName",
"(",
")",
".",
"\"' was defined more than one time\"",
",",
"$",
"property",
"->",
"getOriginal",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"properties",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"property",
";",
"}"
] | Adds a property to the definition.
@param ClassProperty $property
@throws CompilerException | [
"Adds",
"a",
"property",
"to",
"the",
"definition",
"."
] | 2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773 | https://github.com/phalcon/zephir/blob/2a5b0f3c9d936a0a7d8477adda6cb8aa0fe28773/Library/ClassDefinition.php#L484-L491 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.