1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Railt package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Railt\SDL\Frontend\AST\Invocation; |
11
|
|
|
|
12
|
|
|
use Railt\Parser\Ast\Rule; |
13
|
|
|
use Railt\SDL\Frontend\AST\ProvidesName; |
14
|
|
|
use Railt\SDL\Frontend\AST\ProvidesOpcode; |
15
|
|
|
use Railt\SDL\Frontend\AST\ProvidesValue; |
16
|
|
|
use Railt\SDL\Frontend\AST\Support\DependentNameProvider; |
17
|
|
|
use Railt\SDL\Frontend\AST\Value\ValueInterface; |
18
|
|
|
use Railt\SDL\Frontend\Context; |
19
|
|
|
use Railt\SDL\Frontend\IR\Opcode\CompareOpcode; |
20
|
|
|
use Railt\SDL\Frontend\IR\Opcode\CallOpcode; |
21
|
|
|
use Railt\SDL\Frontend\IR\Opcode\FetchOpcode; |
22
|
|
|
use Railt\SDL\Frontend\IR\Opcode\DefineOpcode; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class ArgumentInvocationNode |
26
|
|
|
*/ |
27
|
|
|
class ArgumentInvocationNode extends Rule implements ProvidesName, ProvidesValue, ProvidesOpcode |
28
|
|
|
{ |
29
|
|
|
use DependentNameProvider; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param Context $context |
33
|
|
|
* @return iterable |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
public function getOpcodes(Context $context): iterable |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$current = $context->create(); |
38
|
|
|
|
39
|
|
|
$definition = yield new FetchOpcode($this->getFullName(), $current, false); |
|
|
|
|
40
|
|
|
yield new CompareOpcode($this->getValue(), $definition); |
41
|
|
|
yield new CallOpcode($definition, $this->getValue()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return ValueInterface |
46
|
|
|
*/ |
47
|
|
|
public function getValue(): ValueInterface |
48
|
|
|
{ |
49
|
|
|
return $this->first('Value', 1); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.