Skip to content
← Back

src/syntax/trees/modifiers/modifier.ghul

1
namespace Syntax.Trees.Modifiers is
2
use System.NotImplementedException
3
4
use IO.Std
5
6
use Source
7
8
class Modifier(location: LOCATION): Trees.Node abstract is
9
is_public: bool => false
10
is_protected: bool => false
11
is_private: bool => false
12
is_static: bool => false
13
is_field: bool => false
14
is_init: bool => false
15
is_open: bool => false
16
is_abstract: bool => false
17
is_pure: bool => false
18
is_stable: bool => false
19
is_hide_in_derived: bool => false
20
21
super(location)
22
23
name: string => throw NotImplementedException("{self} does not implement name")
24
accept(visitor: Visitor) is
25
visitor.visit(self)
26
si
27
si
28
29
class AccessModifier(location: LOCATION): Modifier abstract is
30
super(location)
31
32
copy() -> AccessModifier =>
33
cast AccessModifier?(clone())!
34
si
35
36
class StorageClass(location: LOCATION): Modifier abstract is
37
super(location)
38
39
copy() -> StorageClass =>
40
cast StorageClass?(clone())!
41
si
42
43
class PUBLIC(location: LOCATION): AccessModifier is
44
is_public: bool => true
45
name: string => "public"
46
47
super(location)
48
si
49
50
class PROTECTED(location: LOCATION): AccessModifier is
51
is_protected: bool => true
52
name: string => "protected"
53
54
super(location)
55
si
56
57
class PRIVATE(location: LOCATION): AccessModifier is
58
is_private: bool => true
59
name: string => "private"
60
61
super(location)
62
si
63
64
class STATIC(location: LOCATION): StorageClass is
65
is_static: bool => true
66
name: string => "static"
67
68
super(location)
69
si
70
71
class FIELD(location: LOCATION): StorageClass is
72
is_field: bool => true
73
name: string => "field"
74
75
super(location)
76
si
77
78
class HIDE_IN_DERIVED(location: LOCATION): StorageClass is
79
is_hide_in_derived: bool => true
80
name: string => "hide_in_derived"
81
82
super(location)
83
si
84
85
// Marks a primary-ctor parameter as init-scoped: no field auto-generates;
86
// the param is in scope inside the synthesised primary init only. Rejected
87
// anywhere else by `REWRITE_PRIMARY_CONSTRUCTORS`. Not a reserved keyword;
88
// recognised contextually by the modifier list parser via name match on
89
// the IDENTIFIER token.
90
class INIT(location: LOCATION): StorageClass is
91
is_init: bool => true
92
name: string => "init"
93
94
super(location)
95
si
96
97
// Opts a class out of the default closed-to-assembly hierarchy rule.
98
// Without `open`, subclassing from another assembly is rejected and the
99
// type system treats the root's subclass set as enumerable for narrowing.
100
// Not a reserved keyword; recognised contextually by the modifier list
101
// parser via name match on the IDENTIFIER token. Shares the storage-class
102
// slot with FIELD/STATIC/INIT — none of those apply to classes anyway.
103
class OPEN(location: LOCATION): StorageClass is
104
is_open: bool => true
105
name: string => "open"
106
107
super(location)
108
si
109
110
// Marks a class as abstract. Calling its constructor directly is
111
// rejected at compile time; subclasses can still call `super.init()`
112
// to share base initialisation. The closed-narrowing path treats an
113
// abstract root as not-itself-a-runtime-type, so the complement
114
// universe is just the direct subclasses (no widening to include
115
// the root). Independent of `open` — abstract+open is the
116
// open-hierarchy abstract base; abstract alone is the closed
117
// abstract base.
118
class ABSTRACT(location: LOCATION): Modifier is
119
is_abstract: bool => true
120
name: string => "abstract"
121
122
super(location)
123
si
124
125
// Declares a function or method effectively store-free: callers
126
// keep flow-narrowing facts across calls to it without the body
127
// being provable, and every override or trait implementation
128
// must itself be pure — declared or proven. Not a reserved
129
// keyword; recognised contextually by the modifier list parser
130
// via name match on the IDENTIFIER token. Stands alone like
131
// `abstract` so it can coexist with a storage class
132
// (`static pure`).
133
class PURE(location: LOCATION): Modifier is
134
is_pure: bool => true
135
name: string => "pure"
136
137
super(location)
138
si
139
140
// Declares a property stable: two adjacent reads with nothing
141
// between them agree on presence and runtime type. Trusted, not
142
// verified — the same standing as `pure` — and binding on every
143
// override. Orthogonal to purity: a memoiser is impure and
144
// stable; a getter is stable when the classifier cannot prove it
145
// from the body. Not a reserved keyword; recognised contextually
146
// by the modifier list parser via name match on the IDENTIFIER
147
// token.
148
class STABLE(location: LOCATION): Modifier is
149
is_stable: bool => true
150
name: string => "stable"
151
152
super(location)
153
si
154
si