1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Railt package. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Railt\SDL\Backend\Context; |
13
|
|
|
|
14
|
|
|
use Phplrt\Visitor\Traverser; |
15
|
|
|
use Railt\SDL\Backend\Context\Support\DescriptionReaderTrait; |
16
|
|
|
use Railt\SDL\Backend\Context\Support\TypeReferenceTrait; |
17
|
|
|
use Railt\SDL\Backend\Context\Support\ValueTrait; |
18
|
|
|
use Railt\SDL\Backend\HashTable\VariablesVisitor; |
19
|
|
|
use Railt\SDL\Backend\HashTableInterface; |
20
|
|
|
use Railt\SDL\Frontend\Ast\DefinitionNode; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class DefinitionContext |
24
|
|
|
*/ |
25
|
|
|
abstract class DefinitionContext implements DefinitionContextInterface |
26
|
|
|
{ |
27
|
|
|
use ValueTrait; |
28
|
|
|
use TypeReferenceTrait; |
|
|
|
|
29
|
|
|
use DescriptionReaderTrait; |
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var DefinitionNode |
33
|
|
|
*/ |
34
|
|
|
protected DefinitionNode $ast; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Factory |
38
|
|
|
*/ |
39
|
|
|
private Factory $factory; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* DefinitionContext constructor. |
43
|
|
|
* |
44
|
|
|
* @param HashTableInterface $vars |
45
|
|
|
* @param Factory $factory |
46
|
|
|
* @param DefinitionNode $ast |
47
|
|
|
*/ |
48
|
|
|
public function __construct(HashTableInterface $vars, Factory $factory, DefinitionNode $ast) |
49
|
|
|
{ |
50
|
|
|
$this->factory = $factory; |
51
|
|
|
$this->ast = $this->prebuild($vars, $ast); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param HashTableInterface $vars |
56
|
|
|
* @param DefinitionNode $ast |
57
|
|
|
* @return DefinitionNode|iterable |
58
|
|
|
*/ |
59
|
|
|
private function prebuild(HashTableInterface $vars, DefinitionNode $ast): DefinitionNode |
60
|
|
|
{ |
61
|
|
|
$traverser = new Traverser([ |
62
|
|
|
new VariablesVisitor($vars), |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
return $traverser->traverse($ast); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return Factory |
70
|
|
|
*/ |
71
|
|
|
protected function getFactory(): Factory |
72
|
|
|
{ |
73
|
|
|
return $this->factory; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|