@@ -20,10 +20,18 @@ public struct AST {
20
20
/// The module containing Hylo's core library, if any.
21
21
public var coreLibrary : ModuleDecl . ID ?
22
22
23
+ /// Information about the compiler processing `self`.
24
+ public let compiler : CompilerConfiguration
25
+
26
+ /// Creates an empty AST for given compiler.
27
+ public init ( for compiler: CompilerConfiguration ) {
28
+ self . compiler = compiler
29
+ }
30
+
23
31
}
24
32
25
33
/// The notional stored properties of `self`; distinguished for encoding/decoding purposes.
26
- private var storage = Storage ( )
34
+ private var storage : Storage
27
35
28
36
/// The traits in Hylo's standard library that are known by the compiler.
29
37
public var coreTraits : CoreTraits ?
@@ -50,8 +58,15 @@ public struct AST {
50
58
set { storage. coreLibrary = newValue }
51
59
}
52
60
61
+ /// Information about the compiler processing `self`.
62
+ public var compiler : CompilerConfiguration {
63
+ return storage. compiler
64
+ }
65
+
53
66
/// Creates an empty AST.
54
- public init ( ) { }
67
+ public init ( for compiler: CompilerConfiguration ) {
68
+ self . storage = Storage ( for: compiler)
69
+ }
55
70
56
71
/// Inserts `n` into `self`, updating `diagnostics` if `n` is ill-formed.
57
72
public mutating func insert< T: Node > ( _ n: T , diagnostics: inout DiagnosticSet ) -> T . ID {
@@ -121,10 +136,10 @@ public struct AST {
121
136
public func coreType( _ name: String ) -> ProductType ? {
122
137
precondition ( isCoreModuleLoaded, " Core library is not loaded " )
123
138
124
- for id in topLevelDecls ( coreLibrary!) where id . kind == ProductTypeDecl . self {
125
- let id = ProductTypeDecl . ID ( id ) !
126
- if self [ id ] . baseName == name {
127
- return ProductType ( id , ast: self )
139
+ for d in topLevelDecls ( coreLibrary!) where d . kind == ProductTypeDecl . self {
140
+ let d = ProductTypeDecl . ID ( d ) !
141
+ if self [ d ] . baseName == name {
142
+ return ProductType ( d , ast: self )
128
143
}
129
144
}
130
145
@@ -169,8 +184,8 @@ public struct AST {
169
184
modules. first ( where: { self [ $0] . baseName == n } )
170
185
}
171
186
172
- /// Returns the IDs of the top-level declarations in the lexical scope of `module`.
173
- public func topLevelDecls( _ module: ModuleDecl . ID ) -> some Collection < AnyDeclID > {
187
+ /// Returns the top-level declarations in the lexical scope of `module`.
188
+ private func topLevelDecls( _ module: ModuleDecl . ID ) -> some Collection < AnyDeclID > {
174
189
self [ self [ module] . sources] . map ( \. decls) . joined ( )
175
190
}
176
191
0 commit comments