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\Reflection\Contracts\TypeInterface; |
14
|
|
|
use Railt\Reflection\Type; |
15
|
|
|
use Railt\SDL\Frontend\AST\ProvidesName; |
16
|
|
|
use Railt\SDL\Frontend\AST\ProvidesOpcode; |
17
|
|
|
use Railt\SDL\Frontend\AST\ProvidesType; |
18
|
|
|
use Railt\SDL\Frontend\AST\Support\TypeNameProvider; |
19
|
|
|
use Railt\SDL\Frontend\Context; |
20
|
|
|
use Railt\SDL\Frontend\IR\Opcode; |
21
|
|
|
use Railt\SDL\Frontend\IR\Opcode\CallOpcode; |
22
|
|
|
use Railt\SDL\Frontend\IR\Opcode\CompareOpcode; |
23
|
|
|
use Railt\SDL\Frontend\IR\Opcode\FetchOpcode; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class DirectiveInvocationNode |
27
|
|
|
*/ |
28
|
|
|
class DirectiveInvocationNode extends Rule implements ProvidesType, ProvidesName, ProvidesOpcode |
29
|
|
|
{ |
30
|
|
|
use TypeNameProvider; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param Context $context |
34
|
|
|
* @return iterable |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function getOpcodes(Context $context): iterable |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$current = $context->create(); |
39
|
|
|
|
40
|
|
|
$fetched = yield new FetchOpcode($this->getFullName(), $current, false); |
|
|
|
|
41
|
|
|
yield new CompareOpcode($fetched, $this->getType()); |
42
|
|
|
yield new CallOpcode($fetched); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return TypeInterface |
47
|
|
|
*/ |
48
|
|
|
public function getType(): TypeInterface |
49
|
|
|
{ |
50
|
|
|
return Type::of(Type::DIRECTIVE); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
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.