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\Operators\Arithmetical; |
9
|
|
|
|
10
|
|
|
use PHPSA\CompiledExpression; |
11
|
|
|
use PHPSA\Context; |
12
|
|
|
use PHPSA\Compiler\Expression; |
13
|
|
|
use PHPSA\Compiler\Expression\AbstractExpressionCompiler; |
14
|
|
|
|
15
|
|
|
class Div extends AbstractExpressionCompiler |
16
|
|
|
{ |
17
|
|
|
protected $name = 'PhpParser\Node\Expr\BinaryOp\Div'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {expr} / {expr} |
21
|
|
|
* |
22
|
|
|
* @param \PhpParser\Node\Expr\BinaryOp\Div $expr |
23
|
|
|
* @param Context $context |
24
|
|
|
* @return CompiledExpression |
25
|
|
|
*/ |
26
|
|
|
protected function compile($expr, Context $context) |
27
|
|
|
{ |
28
|
|
|
$left = $context->getExpressionCompiler()->compile($expr->left); |
29
|
|
|
$right = $context->getExpressionCompiler()->compile($expr->right); |
30
|
|
|
|
31
|
|
|
if ($right->isEquals(0)) { |
32
|
|
|
$context->notice( |
33
|
|
|
'language_error', |
34
|
|
|
'You are trying to divide by 0.', |
35
|
|
|
$expr |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
return new CompiledExpression(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
switch ($left->getType()) { |
42
|
|
|
case CompiledExpression::INTEGER: |
43
|
|
|
case CompiledExpression::DOUBLE: |
44
|
|
|
case CompiledExpression::BOOLEAN: |
45
|
|
|
switch ($right->getType()) { |
46
|
|
|
case CompiledExpression::INTEGER: |
47
|
|
|
case CompiledExpression::DOUBLE: |
48
|
|
|
case CompiledExpression::BOOLEAN: |
49
|
|
|
return CompiledExpression::fromZvalValue($left->getValue() / $right->getValue()); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return new CompiledExpression(); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|