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