|
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\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 Minus extends AbstractExpressionCompiler |
|
16
|
|
|
{ |
|
17
|
|
|
protected $name = 'PhpParser\Node\Expr\BinaryOp\Minus'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* {expr} - {expr} |
|
21
|
|
|
* |
|
22
|
|
|
* @param \PhpParser\Node\Expr\BinaryOp\Minus $expr |
|
23
|
|
|
* @param Context $context |
|
24
|
|
|
* @return CompiledExpression |
|
25
|
|
|
*/ |
|
26
|
18 |
|
protected function compile($expr, Context $context) |
|
27
|
|
|
{ |
|
28
|
18 |
|
$expression = new Expression($context); |
|
29
|
18 |
|
$left = $expression->compile($expr->left); |
|
30
|
|
|
|
|
31
|
18 |
|
$expression = new Expression($context); |
|
32
|
18 |
|
$right = $expression->compile($expr->right); |
|
33
|
|
|
|
|
34
|
18 |
|
switch ($left->getType()) { |
|
35
|
18 |
|
case CompiledExpression::LNUMBER: |
|
36
|
17 |
|
switch ($right->getType()) { |
|
37
|
17 |
|
case CompiledExpression::LNUMBER: |
|
38
|
16 |
|
return new CompiledExpression(CompiledExpression::LNUMBER, $left->getValue() - $right->getValue()); |
|
39
|
1 |
|
case CompiledExpression::DNUMBER: |
|
40
|
|
|
return new CompiledExpression(CompiledExpression::DNUMBER, $left->getValue() - $right->getValue()); |
|
41
|
1 |
|
} |
|
42
|
1 |
|
break; |
|
43
|
1 |
|
case CompiledExpression::DNUMBER: |
|
44
|
|
|
switch ($right->getType()) { |
|
45
|
|
|
case CompiledExpression::LNUMBER: |
|
46
|
|
|
case CompiledExpression::DNUMBER: |
|
47
|
|
|
return new CompiledExpression(CompiledExpression::DNUMBER, $left->getValue() - $right->getValue()); |
|
48
|
|
|
} |
|
49
|
|
|
break; |
|
50
|
2 |
|
} |
|
51
|
|
|
|
|
52
|
2 |
|
return new CompiledExpression(CompiledExpression::UNKNOWN); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|