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\AssignOp; |
9
|
|
|
|
10
|
|
|
use PHPSA\CompiledExpression; |
11
|
|
|
use PHPSA\Compiler\Expression; |
12
|
|
|
use PHPSA\Compiler\Expression\AbstractExpressionCompiler; |
13
|
|
|
use PHPSA\Context; |
14
|
|
|
|
15
|
|
|
class Minus extends AbstractExpressionCompiler |
16
|
|
|
{ |
17
|
|
|
protected $name = 'PhpParser\Node\Expr\AssignOp\Minus'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {left-expr} -= {right-expr} |
21
|
|
|
* |
22
|
|
|
* @param \PhpParser\Node\Expr\AssignOp\Minus $expr |
23
|
|
|
* @param Context $context |
24
|
|
|
* @return CompiledExpression |
25
|
|
|
*/ |
26
|
3 |
|
protected function compile($expr, Context $context) |
27
|
|
|
{ |
28
|
3 |
|
$left = $context->getExpressionCompiler()->compile($expr->var); |
29
|
3 |
|
$expExpression = $context->getExpressionCompiler()->compile($expr->expr); |
30
|
|
|
|
31
|
3 |
|
switch ($left->getType()) { |
32
|
3 |
|
case CompiledExpression::INTEGER: |
33
|
3 |
|
case CompiledExpression::DOUBLE: |
34
|
3 |
|
case CompiledExpression::NUMBER: |
35
|
3 |
|
case CompiledExpression::BOOLEAN: |
36
|
2 |
|
switch ($expExpression->getType()) { |
37
|
2 |
|
case CompiledExpression::INTEGER: |
38
|
2 |
|
case CompiledExpression::DOUBLE: |
39
|
2 |
|
case CompiledExpression::NUMBER: |
40
|
2 |
|
case CompiledExpression::BOOLEAN: |
41
|
1 |
|
return CompiledExpression::fromZvalValue( |
42
|
1 |
|
$left->getValue() - $expExpression->getValue() |
43
|
1 |
|
); |
44
|
1 |
|
} |
45
|
2 |
|
} |
46
|
|
|
|
47
|
2 |
|
return new CompiledExpression(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|