|
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
|
|
|
* {left-expr} == {right-expr} |
|
21
|
|
|
* |
|
22
|
|
|
* @param \PhpParser\Node\Expr\BinaryOp\Equal $expr |
|
23
|
|
|
* @param Context $context |
|
24
|
|
|
* @return CompiledExpression |
|
25
|
|
|
*/ |
|
26
|
34 |
|
protected function compile($expr, Context $context) |
|
27
|
|
|
{ |
|
28
|
34 |
|
$left = $context->getExpressionCompiler()->compile($expr->left); |
|
29
|
34 |
|
$right = $context->getExpressionCompiler()->compile($expr->right); |
|
30
|
|
|
|
|
31
|
34 |
|
switch ($left->getType()) { |
|
32
|
34 |
|
case CompiledExpression::INTEGER: |
|
33
|
34 |
|
case CompiledExpression::DOUBLE: |
|
34
|
34 |
|
case CompiledExpression::BOOLEAN: |
|
35
|
34 |
|
case CompiledExpression::ARR: |
|
36
|
34 |
|
case CompiledExpression::OBJECT: |
|
37
|
34 |
|
case CompiledExpression::STRING: |
|
38
|
34 |
|
case CompiledExpression::NUMBER: |
|
39
|
34 |
|
case CompiledExpression::RESOURCE: |
|
40
|
34 |
|
case CompiledExpression::CALLABLE_TYPE: |
|
41
|
34 |
|
case CompiledExpression::NULL: |
|
42
|
33 |
|
switch ($right->getType()) { |
|
43
|
33 |
|
case CompiledExpression::INTEGER: |
|
44
|
33 |
|
case CompiledExpression::DOUBLE: |
|
45
|
33 |
|
case CompiledExpression::BOOLEAN: |
|
46
|
33 |
|
case CompiledExpression::ARR: |
|
47
|
33 |
|
case CompiledExpression::OBJECT: |
|
48
|
33 |
|
case CompiledExpression::STRING: |
|
49
|
33 |
|
case CompiledExpression::NUMBER: |
|
50
|
33 |
|
case CompiledExpression::RESOURCE: |
|
51
|
33 |
|
case CompiledExpression::CALLABLE_TYPE: |
|
52
|
33 |
|
case CompiledExpression::NULL: |
|
53
|
32 |
|
return CompiledExpression::fromZvalValue( |
|
54
|
32 |
|
$left->getValue() == $right->getValue() |
|
55
|
32 |
|
); |
|
56
|
1 |
|
} |
|
57
|
2 |
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
return new CompiledExpression(); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|