1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHPSA\Compiler\Expression\BinaryOp; |
4
|
|
|
|
5
|
|
|
use PHPSA\CompiledExpression; |
6
|
|
|
use PHPSA\Context; |
7
|
|
|
use PHPSA\Compiler\Expression; |
8
|
|
|
use PHPSA\Compiler\Expression\AbstractExpressionCompiler; |
9
|
|
|
|
10
|
|
|
class Identical extends AbstractExpressionCompiler |
11
|
|
|
{ |
12
|
|
|
protected $name = 'PhpParser\Node\Expr\BinaryOp\Identical'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* It's used in conditions |
16
|
|
|
* {left-expr} === {right-expr} |
17
|
|
|
* |
18
|
|
|
* @param \PhpParser\Node\Expr\BinaryOp\Identical $expr |
19
|
|
|
* @param Context $context |
20
|
|
|
* @return CompiledExpression |
21
|
|
|
*/ |
22
|
|
|
protected function compile($expr, Context $context) |
23
|
|
|
{ |
24
|
|
|
$expression = new Expression($context); |
25
|
|
|
$left = $expression->compile($expr->left); |
26
|
|
|
|
27
|
|
|
$expression = new Expression($context); |
28
|
|
|
$right = $expression->compile($expr->right); |
29
|
|
|
|
30
|
|
|
switch ($left->getType()) { |
31
|
|
|
case CompiledExpression::INTEGER: |
32
|
|
|
case CompiledExpression::DOUBLE: |
33
|
|
|
case CompiledExpression::BOOLEAN: |
34
|
|
|
case CompiledExpression::NUMBER: |
35
|
|
|
case CompiledExpression::NULL: |
36
|
|
|
switch ($right->getType()) { |
37
|
|
|
case CompiledExpression::INTEGER: |
38
|
|
|
case CompiledExpression::DOUBLE: |
39
|
|
|
case CompiledExpression::BOOLEAN: |
40
|
|
|
case CompiledExpression::NUMBER: |
41
|
|
|
case CompiledExpression::NULL: |
42
|
|
|
return new CompiledExpression(CompiledExpression::BOOLEAN, $left->getValue() === $right->getValue()); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return new CompiledExpression(CompiledExpression::BOOLEAN); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|