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