|
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; |
|
9
|
|
|
|
|
10
|
|
|
use PhpParser\Node\Name; |
|
11
|
|
|
use PHPSA\CompiledExpression; |
|
12
|
|
|
use PHPSA\Context; |
|
13
|
|
|
use PHPSA\Compiler\Expression; |
|
14
|
|
|
use PHPSA\Compiler\Expression\AbstractExpressionCompiler; |
|
15
|
|
|
|
|
16
|
|
|
class PostDec extends AbstractExpressionCompiler |
|
17
|
|
|
{ |
|
18
|
|
|
protected $name = 'PhpParser\Node\Expr\PostDec'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* {expr}-- |
|
22
|
|
|
* |
|
23
|
|
|
* @param \PhpParser\Node\Expr\PostDec $expr |
|
24
|
|
|
* @param Context $context |
|
25
|
|
|
* @return CompiledExpression |
|
26
|
|
|
*/ |
|
27
|
8 |
|
protected function compile($expr, Context $context) |
|
28
|
|
|
{ |
|
29
|
8 |
|
if ($expr->var instanceof \PHPParser\Node\Expr\Variable) { |
|
30
|
8 |
|
$variableName = $expr->var->name; |
|
31
|
8 |
|
if ($variableName instanceof Name) { |
|
32
|
8 |
|
$variableName = $variableName->parts[0]; |
|
33
|
8 |
|
} |
|
34
|
|
|
|
|
35
|
8 |
|
$variable = $context->getSymbol($variableName); |
|
36
|
8 |
|
if ($variable) { |
|
37
|
8 |
|
$variable->incUse(); |
|
38
|
|
|
|
|
39
|
8 |
|
switch ($variable->getType()) { |
|
40
|
8 |
|
case CompiledExpression::INTEGER: |
|
41
|
8 |
|
case CompiledExpression::DOUBLE: |
|
42
|
8 |
|
case CompiledExpression::NUMBER: |
|
43
|
8 |
|
$variable->dec(); |
|
44
|
8 |
|
return CompiledExpression::fromZvalValue($variable->getValue()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$context->notice( |
|
48
|
|
|
'postdec.variable.wrong-type', |
|
49
|
|
|
'You are trying to use post decrement operator on variable $' . $variableName . |
|
50
|
|
|
' with type: ' . $variable->getTypeName(), |
|
51
|
|
|
$expr |
|
52
|
|
|
); |
|
53
|
|
|
} else { |
|
54
|
|
|
$context->notice( |
|
55
|
|
|
'postdec.undefined-variable', |
|
56
|
|
|
'You are trying to use post decrement operator on undefined variable: ' . $variableName, |
|
57
|
|
|
$expr |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return new CompiledExpression(); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|