Skip to content
← Back

src/syntax/trees/definitions/list.ghul

1
namespace Syntax.Trees.Definitions is
2
3
use Source;
4
5
class LIST: Definition, Collections.Iterable[Definition] is
6
definitions: Collections.MutableList[Definition];
7
8
// Bare statements parsed at the file root (a file with no namespace).
9
// Set only on the root list; synthesise-top-level-entry consumes it
10
// into a global entry-point function before declare-symbols. Not
11
// walked here: it carries no symbols until that synthesis.
12
top_level_statements: Statements.LIST? public;
13
14
iterator: Collections.Iterator[Definition] => definitions.iterator;
15
16
uses: Collections.List[USE] is
17
let result = Collections.LIST[USE](definitions.count);
18
19
for d in definitions do
20
let d_without_pragmas = d.without_pragmas;
21
22
if isa USE(d_without_pragmas) then
23
result.add(d_without_pragmas);
24
fi
25
od
26
27
return result;
28
si
29
30
init(location: LOCATION, definitions: Collections.Iterable[Definition]) is
31
super.init(location);
32
33
self.definitions = Collections.LIST[Definition](definitions);
34
si
35
36
add(definition: Definition) is
37
definitions.add(definition);
38
si
39
40
push(definition: Definition) is
41
let nd = Collections.LIST[Definition](definitions.count + 1);
42
43
nd.add(definition);
44
nd.add_range(definitions);
45
46
definitions = nd;
47
si
48
49
remove(definition: Definition) is
50
definitions.remove(definition);
51
si
52
53
clear_definitions() is
54
definitions.clear();
55
si
56
57
accept(visitor: Visitor) is
58
visitor.visit(self);
59
si
60
61
walk(visitor: Visitor) is
62
if !visitor.pre(self) then
63
let i mut = 0;
64
65
while i < definitions.count do
66
definitions[i].walk(visitor);
67
68
i = i + 1;
69
od
70
fi
71
72
accept(visitor);
73
si
74
si
75
si