@@ -90,8 +90,8 @@ public fn u32 AST.getNameIdx(const AST* a) {
9090}
9191
9292public fn SrcLoc AST.getLoc(const AST* a) {
93- ImportDecl** imports = a.imports.getDecls();
94- Decl* d = (Decl*)imports[0] ;
93+ // Note: use the first 'Import' since it is really the module statement
94+ Decl* d = (Decl*)a. imports.get(0) ;
9595 return d.getLoc();
9696}
9797
@@ -106,11 +106,9 @@ public fn void AST.addImport(AST* a, ImportDecl* d) {
106106}
107107
108108public fn ImportDecl* AST.findImport(const AST* a, u32 name) {
109- ImportDecl** imports = a.imports.getDecls();
110109 for (u32 i=1; i<a.imports.size(); i++) {
111- ImportDecl* d = imports[i] ;
110+ ImportDecl* d = a. imports.get(i) ;
112111 if (d.asDecl().getNameIdx() == name) return d;
113-
114112 }
115113 return nil;
116114}
@@ -146,10 +144,9 @@ public fn void AST.addArrayValue(AST* a, ArrayValue* v) {
146144public type ImportVisitor fn void (void* arg, ImportDecl* d);
147145
148146public fn void AST.visitImports(const AST* a, ImportVisitor visitor, void* arg) {
149- ImportDecl** imports = a.imports.getDecls();
150147 // Note: skip first 'Import' since it is really the module statement
151148 for (u32 i=1; i<a.imports.size(); i++) {
152- visitor(arg, imports[i] );
149+ visitor(arg, a. imports.get(i) );
153150 }
154151}
155152
@@ -167,36 +164,32 @@ fn void AST.visitArrayValues(AST* a, ArrayValueVisitor visitor, void* arg) {
167164public type FunctionVisitor fn void (void* arg, FunctionDecl* d);
168165
169166fn void AST.visitTypeFunctions(const AST* a, FunctionVisitor visitor, void* arg) {
170- FunctionDecl** functions = a.functions.getDecls();
171167 for (u32 i=0; i<a.functions.size(); i++) {
172- FunctionDecl* d = functions[i] ;
168+ FunctionDecl* d = a. functions.get(i) ;
173169 if (d.hasPrefix()) visitor(arg, d);
174170 }
175171}
176172
177173public fn void AST.visitFunctions(const AST* a, FunctionVisitor visitor, void* arg) {
178- FunctionDecl** functions = a.functions.getDecls();
179174 for (u32 i=0; i<a.functions.size(); i++) {
180- FunctionDecl* d = functions[i] ;
175+ FunctionDecl* d = a. functions.get(i) ;
181176 visitor(arg, d);
182177 }
183178}
184179
185180public type TypeDeclVisitor fn void (void* arg, Decl* d);
186181
187182public fn void AST.visitTypeDecls(const AST* a, TypeDeclVisitor visitor, void* arg) {
188- Decl** types = a.types.getDecls();
189183 for (u32 i=0; i<a.types.size(); i++) {
190- visitor(arg, types[i] );
184+ visitor(arg, a. types.get(i) );
191185 }
192186}
193187
194188public type VarDeclVisitor fn void (void* arg, VarDecl* d);
195189
196190public fn void AST.visitVarDecls(const AST* a, VarDeclVisitor visitor, void* arg) {
197- Decl** variables = a.variables.getDecls();
198191 for (u32 i=0; i<a.variables.size(); i++) {
199- visitor(arg, (VarDecl*)variables[i] );
192+ visitor(arg, (VarDecl*)a. variables.get(i) );
200193 }
201194}
202195
@@ -213,39 +206,33 @@ public type DeclVisitor fn void (void* arg, Decl* d);
213206
214207public fn void AST.visitDecls(const AST* a, DeclVisitor visitor, void* arg) {
215208 // imports
216- ImportDecl** imports = a.imports.getDecls();
217209 for (u32 i=0; i<a.imports.size(); i++) {
218- visitor(arg, (Decl*)imports[i] );
210+ visitor(arg, (Decl*)a. imports.get(i) );
219211 }
220212
221213 a.visitDeclsWithoutImports(visitor, arg);
222214}
223215
224216fn void AST.visitDeclsWithoutImports(const AST* a, DeclVisitor visitor, void* arg) {
225217 // types
226- Decl** types = a.types.getDecls();
227218 for (u32 i=0; i<a.types.size(); i++) {
228- visitor(arg, types[i] );
219+ visitor(arg, a. types.get(i) );
229220 }
230221
231222 // variables
232- Decl** variables = a.variables.getDecls();
233223 for (u32 i=0; i<a.variables.size(); i++) {
234- visitor(arg, variables[i] );
224+ visitor(arg, a. variables.get(i) );
235225 }
236226
237227 // functions
238- FunctionDecl** functions = a.functions.getDecls();
239228 for (u32 i=0; i<a.functions.size(); i++) {
240- FunctionDecl* d = functions[i];
241- visitor(arg, (Decl*)d);
229+ visitor(arg, (Decl*)a.functions.get(i));
242230 }
243231}
244232
245233fn Decl* AST.findType(const AST* a, u32 name_idx) {
246- Decl** types = a.types.getDecls();
247234 for (u32 i=0; i<a.types.size(); i++) {
248- Decl* d = types[i] ;
235+ Decl* d = a. types.get(i) ;
249236 if (d.getNameIdx() == name_idx) return d;
250237 }
251238 return nil;
@@ -274,28 +261,28 @@ fn void AST.print(const AST* a, string_buffer.Buf* out, bool show_funcs) {
274261 out.color(col_Normal);
275262 out.print("---- AST %s ----\n", a.getFilename());
276263
277- ImportDecl** imports = a.imports.getDecls();
278264 for (u32 i=1; i<a.imports.size(); i++) {
279- imports[i].print(out, 0);
265+ ImportDecl* d = a.imports.get(i);
266+ d.print(out, 0);
280267 }
281268 if (a.imports.size() > 1) out.newline();
282269
283- Decl** types = a.types.getDecls();
284270 for (u32 i=0; i<a.types.size(); i++) {
285- types[i].print(out, 0);
271+ Decl* d = a.types.get(i);
272+ d.print(out, 0);
286273 out.newline();
287274 }
288275
289- Decl** variables = a.variables.getDecls();
290276 for (u32 i=0; i<a.variables.size(); i++) {
291- variables[i].print(out, 0);
277+ Decl* d = a.variables.get(i);
278+ d.print(out, 0);
292279 out.newline();
293280 }
294281
295282 if (show_funcs) {
296- FunctionDecl** functions = a.functions.getDecls();
297283 for (u32 i=0; i<a.functions.size(); i++) {
298- functions[i].print(out, 0);
284+ FunctionDecl* d = a.functions.get(i);
285+ d.print(out, 0);
299286 out.newline();
300287 }
301288 }
@@ -308,21 +295,21 @@ fn void AST.print(const AST* a, string_buffer.Buf* out, bool show_funcs) {
308295
309296fn void AST.setExported(AST* a) {
310297 // types, cannot be really exported, but do mark as such (for used?)
311- Decl** types = a.types.getDecls();
312298 for (u32 i=0; i<a.types.size(); i++) {
313- types[i].setExportedIfPublic();
299+ Decl* d = a.types.get(i);
300+ d.setExportedIfPublic();
314301 }
315302
316303 // variables
317- Decl** variables = a.variables.getDecls();
318304 for (u32 i=0; i<a.variables.size(); i++) {
319- variables[i].setExportedIfPublic();
305+ Decl* d = a.variables.get(i);
306+ d.setExportedIfPublic();
320307 }
321308
322309 // functions
323- Decl** functions = (Decl**)a.functions.getDecls();
324310 for (u32 i=0; i<a.functions.size(); i++) {
325- functions[i].setExportedIfPublic();
311+ Decl* d = (Decl*)a.functions.get(i);
312+ d.setExportedIfPublic();
326313 }
327314}
328315
0 commit comments