1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP Smart Analysis project 2015-2016 |
4
|
|
|
* |
5
|
|
|
* @author Patsura Dmitry https://github.com/ovr <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace PHPSA\Compiler\Expression\BinaryOp; |
9
|
|
|
|
10
|
|
|
use PHPSA\CompiledExpression; |
11
|
|
|
use PHPSA\Context; |
12
|
|
|
use PHPSA\Compiler\Expression; |
13
|
|
|
use PHPSA\Compiler\Expression\AbstractExpressionCompiler; |
14
|
|
|
|
15
|
|
|
class Equal extends AbstractExpressionCompiler |
16
|
|
|
{ |
17
|
|
|
protected $name = 'PhpParser\Node\Expr\BinaryOp\Equal'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* It's used in conditions |
21
|
|
|
* {left-expr} == {right-expr} |
22
|
|
|
* |
23
|
|
|
* @param \PhpParser\Node\Expr\BinaryOp\Equal $expr |
24
|
|
|
* @param Context $context |
25
|
|
|
* @return CompiledExpression |
26
|
|
|
*/ |
27
|
34 |
|
protected function compile($expr, Context $context) |
28
|
|
|
{ |
29
|
34 |
|
$left = $context->getExpressionCompiler()->compile($expr->left); |
30
|
34 |
|
$right = $context->getExpressionCompiler()->compile($expr->right); |
31
|
|
|
|
32
|
34 |
|
switch ($left->getType()) { |
33
|
34 |
|
case CompiledExpression::INTEGER: |
34
|
34 |
|
case CompiledExpression::DOUBLE: |
35
|
34 |
|
case CompiledExpression::BOOLEAN: |
36
|
34 |
|
case CompiledExpression::ARR: |
37
|
34 |
|
case CompiledExpression::OBJECT: |
38
|
33 |
|
switch ($right->getType()) { |
39
|
33 |
|
case CompiledExpression::INTEGER: |
40
|
33 |
|
case CompiledExpression::DOUBLE: |
41
|
33 |
|
case CompiledExpression::BOOLEAN: |
42
|
33 |
|
case CompiledExpression::ARR: |
43
|
33 |
|
case CompiledExpression::OBJECT: |
44
|
32 |
|
return new CompiledExpression(CompiledExpression::BOOLEAN, $left->getValue() == $right->getValue()); |
45
|
1 |
|
} |
46
|
1 |
|
break; |
47
|
2 |
|
} |
48
|
|
|
|
49
|
2 |
|
return new CompiledExpression(CompiledExpression::BOOLEAN); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|