示例#1
0
 public function compile(Compiler $compiler, OperatorNode $node)
 {
     $operand = $node->getChild(OperatorNode::OPERAND_LEFT);
     if ($this->isPropertyAccessOperator($operand)) {
         $root = $operand;
         while ($this->isPropertyAccessOperator($root)) {
             $root = $root->getChild(OperatorNode::OPERAND_LEFT);
         }
         if ($root instanceof VariableNode) {
             $compiler->add('isset(')->compileNode($root)->add(') && ');
         }
         $operand->addData('mode', 'has');
         $operand->compile($compiler);
     } elseif ($operand instanceof ArrayIndexNode) {
         $variable = $operand->getChild('identifier');
         $keys = [$operand->getChild('key')];
         while ($variable instanceof ArrayIndexNode) {
             /** @var $right OperatorNode */
             $keys[] = $variable->getChild('key');
             $variable = $variable->getChild('identifier');
         }
         $arguments = [$variable, array_reverse($keys)];
         $compiler->add('isset(')->compileNode($variable)->add(') && $context->hasProperty')->compileArgumentList($arguments);
     } else {
         $compiler->add('isset(')->compileNode($operand)->add(')');
     }
 }
示例#2
0
 public function compile(Compiler $compiler, OperatorNode $node)
 {
     //if(sign($left) != sign($right))
     $compiler->add('((')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(' < 0 && ')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(' > 0) || (')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(' < 0 && ')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(' > 0)');
     //then $right + $left % right
     $compiler->add(' ? (')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(' + ')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(' % ')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(')');
     //else $left % $right
     $compiler->add(': (')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(' % ')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add('))');
 }
示例#3
0
 public function createNode(Node $left = null, Node $right = null, Node $middle = null)
 {
     $node = new OperatorNode($this);
     if ($left) {
         $node->addChild($left, OperatorNode::OPERAND_LEFT);
     }
     if ($middle) {
         $node->addChild($middle, OperatorNode::OPERAND_MIDDLE);
     }
     if ($right) {
         $node->addChild($right, OperatorNode::OPERAND_RIGHT);
     }
     return $node;
 }
示例#4
0
 public function compile(Compiler $compiler, OperatorNode $node)
 {
     $data = $node->getChild(OperatorNode::OPERAND_LEFT);
     $filter = $node->getChild(OperatorNode::OPERAND_RIGHT);
     if ($filter instanceof FunctionNode) {
         $arguments = $filter->getArguments();
         array_unshift($arguments, $data);
         $filter->setArguments($arguments);
     } elseif ($filter instanceof IdentifierNode && !$filter instanceof VariableNode) {
         $filter = new FunctionNode($filter->getData('name'), [$data]);
     } else {
         throw new ParseException('Invalid filter node.');
     }
     $filter->compile($compiler);
 }
示例#5
0
 /**
  * @param OperatorNode $node
  *
  * @return string
  */
 private function getMethodName(OperatorNode $node)
 {
     if ($node->hasData('mode')) {
         $mode = $node->getData('mode');
     } else {
         $mode = 'get';
     }
     switch ($mode) {
         case 'has':
             return 'hasProperty';
         default:
         case 'get':
             return 'getProperty';
         case 'set':
             return 'setProperty';
     }
 }
示例#6
0
 public function compile(Compiler $compiler, OperatorNode $node)
 {
     $compiler->compileNode(new FunctionNode($this->getFunctionName(), $node->getChildren()));
 }
示例#7
0
 public function compile(Compiler $compiler, OperatorNode $node)
 {
     $compiler->add('(--')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(')');
 }
示例#8
0
 public function compile(Compiler $compiler, OperatorNode $node)
 {
     $compiler->add('(')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(' % 2 == 0)');
 }
示例#9
0
 /**
  * @param OperatorNode $node
  *
  * @return bool
  */
 private function isFilterSafe(OperatorNode $node)
 {
     if ($this->functionLevel++ === 0) {
         return $this->isFunctionSafe($node->getChild(OperatorNode::OPERAND_RIGHT));
     }
     return true;
 }
示例#10
0
 public function compile(Compiler $compiler, OperatorNode $node)
 {
     $compiler->add('range(')->compileNode($node->getChild(OperatorNode::OPERAND_LEFT))->add(', ')->compileNode($node->getChild(OperatorNode::OPERAND_RIGHT))->add(' - 1)');
 }