本文整理汇总了PHP中PHPSA\Context::getExpressionCompiler方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::getExpressionCompiler方法的具体用法?PHP Context::getExpressionCompiler怎么用?PHP Context::getExpressionCompiler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPSA\Context
的用法示例。
在下文中一共展示了Context::getExpressionCompiler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
/**
* {expr} + {expr}
*
* @param \PhpParser\Node\Expr\BinaryOp\Plus $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$left = $context->getExpressionCompiler()->compile($expr->left);
$right = $context->getExpressionCompiler()->compile($expr->right);
switch ($left->getType()) {
case CompiledExpression::INTEGER:
switch ($right->getType()) {
case CompiledExpression::INTEGER:
/**
* php -r "var_dump(1 + 1);" int(2)
*/
return new CompiledExpression(CompiledExpression::INTEGER, $left->getValue() + $right->getValue());
case CompiledExpression::DOUBLE:
/**
* php -r "var_dump(1 + 1.0);" double(2)
*/
return new CompiledExpression(CompiledExpression::DOUBLE, $left->getValue() + $right->getValue());
}
break;
case CompiledExpression::DOUBLE:
switch ($right->getType()) {
case CompiledExpression::INTEGER:
case CompiledExpression::DOUBLE:
/**
* php -r "var_dump(1.0 + 1);" double(2)
* php -r "var_dump(1.0 + 1.0);" double(2)
*/
return new CompiledExpression(CompiledExpression::DOUBLE, $left->getValue() + $right->getValue());
}
}
return new CompiledExpression();
}
示例2: compile
/**
* yield {value}, yield {key} => {value}
*
* @param \PhpParser\Node\Expr\Yield_ $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$key = $context->getExpressionCompiler()->compile($expr->key);
$value = $context->getExpressionCompiler()->compile($expr->value);
// @TODO implement yield
return new CompiledExpression();
}
示例3: compile
/**
* It's used in conditions
* {left-expr} !== {right-expr}
*
* @param \PhpParser\Node\Expr\BinaryOp\NotIdentical $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$left = $context->getExpressionCompiler()->compile($expr->left);
$right = $context->getExpressionCompiler()->compile($expr->right);
if ($left->isTypeKnown() && $right->isTypeKnown()) {
return CompiledExpression::fromZvalValue($left->getValue() !== $right->getValue());
}
return new CompiledExpression();
}
示例4: compile
/**
* ({expr}) ? {expr} : {expr}
*
* @param \PhpParser\Node\Expr\Ternary $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$condition = $context->getExpressionCompiler()->compile($expr->cond);
$left = $context->getExpressionCompiler()->compile($expr->if);
$right = $context->getExpressionCompiler()->compile($expr->else);
if ($condition->getValue() == true) {
return CompiledExpression::fromZvalValue($left->getValue());
} else {
return CompiledExpression::fromZvalValue($right->getValue());
}
}
示例5: compile
/**
* @param \PhpParser\Node\Stmt\Foreach_ $stmt
* @param Context $context
* @return null|boolean
*/
public function compile($stmt, Context $context)
{
$context->getExpressionCompiler()->compile($stmt->expr);
if ($stmt->keyVar) {
$context->getExpressionCompiler()->declareVariable($stmt->keyVar, null, CompiledExpression::MIXED);
}
if ($stmt->valueVar) {
$context->getExpressionCompiler()->declareVariable($stmt->valueVar, null, CompiledExpression::MIXED);
}
foreach ($stmt->stmts as $statement) {
\PHPSA\nodeVisitorFactory($statement, $context);
}
}
示例6: compile
/**
* @param \PhpParser\Node\Stmt\For_ $stmt
* @param Context $context
* @return CompiledExpression
*/
public function compile($stmt, Context $context)
{
foreach ($stmt->init as $init) {
$context->getExpressionCompiler()->compile($init);
}
foreach ($stmt->cond as $cond) {
$context->getExpressionCompiler()->compile($cond);
}
foreach ($stmt->loop as $loop) {
$context->getExpressionCompiler()->compile($loop);
}
foreach ($stmt->stmts as $statement) {
\PHPSA\nodeVisitorFactory($statement, $context);
}
}
示例7: compile
/**
* It's used in conditions
* {left-expr} <=> {right-expr}
*
* @param \PhpParser\Node\Expr\BinaryOp\Spaceship $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$left = $context->getExpressionCompiler()->compile($expr->left);
$right = $context->getExpressionCompiler()->compile($expr->right);
if ($left->isTypeKnown() && $right->isTypeKnown()) {
if ($left->getValue() == $right->getValue()) {
return new CompiledExpression(CompiledExpression::INTEGER, 0);
} elseif ($left->getValue() < $right->getValue()) {
return new CompiledExpression(CompiledExpression::INTEGER, -1);
} elseif ($left->getValue() > $right->getValue()) {
return new CompiledExpression(CompiledExpression::INTEGER, 1);
}
}
return new CompiledExpression();
}
示例8: compile
/**
* @param \PhpParser\Node\Stmt\Const_ $stmt
* @param Context $context
* @return CompiledExpression
*/
public function compile($stmt, Context $context)
{
$compiler = $context->getExpressionCompiler();
foreach ($stmt->consts as $const) {
$compiler->compile($const->value);
}
}
示例9: compile
/**
* $a &= $b;
*
* @param \PhpParser\Node\Expr\AssignRef $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$compiler = $context->getExpressionCompiler();
if ($expr->var instanceof VariableNode) {
$name = $expr->var->name;
$compiledExpression = $compiler->compile($expr->expr);
$symbol = $context->getSymbol($name);
if ($symbol) {
$symbol->modify($compiledExpression->getType(), $compiledExpression->getValue());
} else {
$symbol = new \PHPSA\Variable($name, $compiledExpression->getValue(), $compiledExpression->getType(), $context->getCurrentBranch());
$context->addVariable($symbol);
}
if ($expr->expr instanceof VariableNode) {
$rightVarName = $expr->expr->name;
$rightSymbol = $context->getSymbol($rightVarName);
if ($rightSymbol) {
$rightSymbol->incUse();
$symbol->setReferencedTo($rightSymbol);
} else {
$context->debug('Cannot fetch variable by name: ' . $rightVarName);
}
}
$symbol->incSets();
return $compiledExpression;
}
$context->debug('Unknown how to pass symbol by ref');
return new CompiledExpression();
}
示例10: compile
/**
* @param \PhpParser\Node\Stmt\Static_ $stmt
* @param Context $context
* @return CompiledExpression
*/
public function compile($stmt, Context $context)
{
$compiler = $context->getExpressionCompiler();
foreach ($stmt->vars as $var) {
$compiler->compile($var->default);
}
}
示例11: compile
/**
* classname->property
*
* @param \PhpParser\Node\Expr\PropertyFetch $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$compiler = $context->getExpressionCompiler();
$propertNameCE = $compiler->compile($expr->name);
$scopeExpression = $compiler->compile($expr->var);
if ($scopeExpression->isObject()) {
$scopeExpressionValue = $scopeExpression->getValue();
if ($scopeExpressionValue instanceof ClassDefinition) {
$propertyName = $propertNameCE->isString() ? $propertNameCE->getValue() : false;
if ($propertyName) {
if ($scopeExpressionValue->hasProperty($propertyName, true)) {
$property = $scopeExpressionValue->getProperty($propertyName, true);
return $compiler->compile($property);
} else {
$context->notice('language_error', sprintf('Property %s does not exist in %s scope', $propertyName, $scopeExpressionValue->getName()), $expr);
}
}
}
return new CompiledExpression();
} elseif ($scopeExpression->canBeObject()) {
return new CompiledExpression();
}
$context->notice('language_error', "It's not possible to fetch a property on a non-object", $expr, Check::CHECK_BETA);
return new CompiledExpression();
}
示例12: compile
/**
* @param \PhpParser\Node\Stmt\Do_ $stmt
* @param Context $context
* @return CompiledExpression
*/
public function compile($stmt, Context $context)
{
$context->getExpressionCompiler()->compile($stmt->cond);
foreach ($stmt->stmts as $statement) {
\PHPSA\nodeVisitorFactory($statement, $context);
}
}
示例13: compile
/**
* [] array()
*
* @param \PhpParser\Node\Expr\Array_ $expr
* @param Context $context
* @return CompiledExpression
*/
protected function compile($expr, Context $context)
{
$compiler = $context->getExpressionCompiler();
if ($expr->items === []) {
return new CompiledExpression(CompiledExpression::ARR, []);
}
$resultArray = [];
foreach ($expr->items as $item) {
$compiledValueResult = $compiler->compile($item->value);
if ($item->key) {
$compiledKeyResult = $compiler->compile($item->key);
switch ($compiledKeyResult->getType()) {
case CompiledExpression::INTEGER:
case CompiledExpression::DOUBLE:
case CompiledExpression::BOOLEAN:
case CompiledExpression::NULL:
case CompiledExpression::STRING:
$resultArray[$compiledKeyResult->getValue()] = $compiledValueResult->getValue();
}
} else {
$resultArray[] = $compiledValueResult->getValue();
}
}
return new CompiledExpression(CompiledExpression::ARR, $resultArray);
}
示例14: pass
/**
* @param Expr $expr
* @param Context $context
* @return bool
*/
public function pass(Expr $expr, Context $context)
{
$castType = CompiledExpression::UNKNOWN;
switch (get_class($expr)) {
case Expr\Cast\Array_::class:
$castType = CompiledExpression::ARR;
break;
case Expr\Cast\Bool_::class:
$castType = CompiledExpression::BOOLEAN;
break;
case Expr\Cast\Int_::class:
$castType = CompiledExpression::INTEGER;
break;
case Expr\Cast\Double::class:
$castType = CompiledExpression::DOUBLE;
break;
case Expr\Cast\Object_::class:
$castType = CompiledExpression::OBJECT;
break;
case Expr\Cast\String_::class:
$castType = CompiledExpression::STRING;
break;
}
$compiledExpression = $context->getExpressionCompiler()->compile($expr->expr);
$exprType = $compiledExpression->getType();
$typeName = $compiledExpression->getTypeName();
if ($castType === $exprType) {
$context->notice('stupid.cast', sprintf("You are trying to cast '%s' to '%s'", $typeName, $typeName), $expr);
return true;
} elseif (get_class($expr) == Expr\Cast\Unset_::class && $exprType === CompiledExpression::NULL) {
$context->notice('stupid.cast', "You are trying to cast 'null' to 'unset' (null)", $expr);
return true;
}
return false;
}
示例15: compile
/**
* @param \PhpParser\Node\Stmt\Echo_ $stmt
* @param Context $context
* @return CompiledExpression
*/
public function compile($stmt, Context $context)
{
$compiler = $context->getExpressionCompiler();
foreach ($stmt->exprs as $expr) {
$compiler->compile($expr);
}
}