1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP Static Analysis project 2015 |
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 NotEqual extends AbstractExpressionCompiler |
16
|
|
|
{ |
17
|
|
|
protected $name = 'PhpParser\Node\Expr\BinaryOp\NotEqual'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* It's used in conditions |
21
|
|
|
* {left-expr} != {right-expr} |
22
|
|
|
* |
23
|
|
|
* @param \PhpParser\Node\Expr\BinaryOp\NotEqual $expr |
24
|
|
|
* @param Context $context |
25
|
|
|
* @return CompiledExpression |
26
|
|
|
*/ |
27
|
17 |
|
protected function compile($expr, Context $context) |
28
|
|
|
{ |
29
|
17 |
|
$expression = new Expression($context); |
30
|
17 |
|
$left = $expression->compile($expr->left); |
31
|
|
|
|
32
|
17 |
|
$expression = new Expression($context); |
33
|
17 |
|
$right = $expression->compile($expr->right); |
34
|
|
|
|
35
|
17 |
|
switch ($left->getType()) { |
36
|
17 |
|
case CompiledExpression::INTEGER: |
37
|
17 |
|
case CompiledExpression::DOUBLE: |
38
|
17 |
|
case CompiledExpression::BOOLEAN: |
39
|
17 |
|
case CompiledExpression::ARR: |
40
|
17 |
|
case CompiledExpression::OBJECT: |
41
|
16 |
|
switch ($right->getType()) { |
42
|
16 |
|
case CompiledExpression::INTEGER: |
43
|
16 |
|
case CompiledExpression::DOUBLE: |
44
|
16 |
|
case CompiledExpression::BOOLEAN: |
45
|
16 |
|
case CompiledExpression::ARR: |
46
|
16 |
|
case CompiledExpression::OBJECT: |
47
|
15 |
|
return new CompiledExpression(CompiledExpression::BOOLEAN, $left->getValue() != $right->getValue()); |
48
|
1 |
|
} |
49
|
1 |
|
break; |
50
|
2 |
|
} |
51
|
|
|
|
52
|
2 |
|
return new CompiledExpression(CompiledExpression::BOOLEAN); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|