当前位置: 首页>>代码示例>>PHP>>正文


PHP Context::getExpressionCompiler方法代码示例

本文整理汇总了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();
 }
开发者ID:ovr,项目名称:phpsa,代码行数:39,代码来源:Plus.php

示例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();
 }
开发者ID:ovr,项目名称:phpsa,代码行数:14,代码来源:YieldOp.php

示例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();
 }
开发者ID:ovr,项目名称:phpsa,代码行数:17,代码来源:NotIdentical.php

示例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());
     }
 }
开发者ID:ovr,项目名称:phpsa,代码行数:18,代码来源:Ternary.php

示例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);
     }
 }
开发者ID:ovr,项目名称:phpsa,代码行数:18,代码来源:ForeachSt.php

示例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);
     }
 }
开发者ID:ovr,项目名称:phpsa,代码行数:20,代码来源:ForSt.php

示例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();
 }
开发者ID:ovr,项目名称:phpsa,代码行数:23,代码来源:SpaceShip.php

示例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);
     }
 }
开发者ID:ovr,项目名称:phpsa,代码行数:12,代码来源:ConstSt.php

示例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();
 }
开发者ID:ovr,项目名称:phpsa,代码行数:36,代码来源:AssignRef.php

示例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);
     }
 }
开发者ID:ovr,项目名称:phpsa,代码行数:12,代码来源:StaticSt.php

示例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();
 }
开发者ID:ovr,项目名称:phpsa,代码行数:32,代码来源:PropertyFetch.php

示例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);
     }
 }
开发者ID:ovr,项目名称:phpsa,代码行数:12,代码来源:DoSt.php

示例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);
 }
开发者ID:ovr,项目名称:phpsa,代码行数:32,代码来源:ArrayOp.php

示例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;
 }
开发者ID:ovr,项目名称:phpsa,代码行数:40,代码来源:Casts.php

示例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);
     }
 }
开发者ID:ovr,项目名称:phpsa,代码行数:12,代码来源:EchoSt.php


注:本文中的PHPSA\Context::getExpressionCompiler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。