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\Dependent; |
11
|
|
|
|
12
|
|
|
use Railt\Parser\Ast\Rule; |
13
|
|
|
use Railt\Parser\Ast\RuleInterface; |
14
|
|
|
use Railt\SDL\Frontend\AST\ProvidesDescription; |
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\DependentNameProvider; |
19
|
|
|
use Railt\SDL\Frontend\AST\Support\DescriptionProvider; |
20
|
|
|
use Railt\SDL\Frontend\Context; |
21
|
|
|
use Railt\SDL\Frontend\IR\Opcode; |
22
|
|
|
use Railt\SDL\Frontend\IR\Opcode\DefineOpcode; |
23
|
|
|
use Railt\SDL\Frontend\IR\OpcodeHeap; |
24
|
|
|
use Railt\SDL\Frontend\IR\OpcodeInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class DependentTypeDefinitionNode |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
abstract class DependentTypeDefinitionNode extends Rule implements |
|
|
|
|
30
|
|
|
ProvidesType, |
31
|
|
|
ProvidesName, |
32
|
|
|
ProvidesOpcode, |
33
|
|
|
ProvidesDescription |
34
|
|
|
{ |
35
|
|
|
use DependentNameProvider; |
36
|
|
|
use DescriptionProvider; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return int |
40
|
|
|
*/ |
41
|
|
|
public function getOffset(): int |
42
|
|
|
{ |
43
|
|
|
$node = $this->getNameNode(); |
44
|
|
|
|
45
|
|
|
if ($node instanceof RuleInterface) { |
46
|
|
|
return $node->getOffset(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return parent::getOffset(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Context $context |
54
|
|
|
* @return iterable |
55
|
|
|
*/ |
56
|
|
|
public function getOpcodes(Context $context): iterable |
57
|
|
|
{ |
58
|
|
|
$current = $context->create(); |
59
|
|
|
|
60
|
|
|
$joinable = yield new DefineOpcode($this->getFullName(), $this->getType(), $current); |
|
|
|
|
61
|
|
|
|
62
|
|
|
if ($description = $this->getDescriptionNode()) { |
63
|
|
|
yield $description => new Opcode(Opcode::RL_DESCRIPTION, $joinable, $this->getDescription()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
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.