From 50ba7cf91d107e80b545cf92df1c1f05ea91a7a0 Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Thu, 29 Jan 2026 00:38:57 +0100 Subject: [PATCH] Compiler: use size and get accessors in visitor functions * allow for array reallocation in visitor handlers --- analyser/scope.c2 | 22 ++++------ ast/ast.c2 | 67 ++++++++++++----------------- ast/call_expr.c2 | 4 ++ ast/function_decl_list.c2 | 4 ++ ast/import_decl_list.c2 | 4 +- ast/struct_type_decl.c2 | 5 +-- ast/symbol_table.c2 | 7 ++- ast/type_ref.c2 | 10 ++++- generator/c/c_generator_special.c2 | 9 ++-- generator/c2i/c2i_generator_expr.c2 | 4 +- plugins/unit_test_plugin.c2 | 12 ++---- 11 files changed, 67 insertions(+), 81 deletions(-) diff --git a/analyser/scope.c2 b/analyser/scope.c2 index 0c5c5649b..1ed429ed6 100644 --- a/analyser/scope.c2 +++ b/analyser/scope.c2 @@ -106,10 +106,8 @@ public fn void Scope.reset(Scope* s) { fn void Scope.addImports(Scope* s) { // Note: this also adds the module itself (import[0]) - u32 num_imports = s.imports.size(); - ast.ImportDecl** imports = s.imports.getDecls(); - for (u32 i=0; i 1) out.newline(); - Decl** types = a.types.getDecls(); for (u32 i=0; i const ptr-ptr is fixed in analyser - return (const FunctionDecl**)d.struct_functions; +fn FunctionDecl* StructTypeDecl.getStructFunction(const StructTypeDecl* d, u32 i) { + return d.struct_functions[i]; } fn u32 StructTypeDecl.getNumStructFunctions(const StructTypeDecl* d) { diff --git a/ast/symbol_table.c2 b/ast/symbol_table.c2 index ffec898bd..3ea9c8a16 100644 --- a/ast/symbol_table.c2 +++ b/ast/symbol_table.c2 @@ -46,8 +46,8 @@ public fn u32 SymbolTable.size(const SymbolTable* t) { return t.num_public + t.num_private; } -public fn Decl** SymbolTable.getDecls(const SymbolTable* t) { - return t.decls; +public fn Decl* SymbolTable.get(const SymbolTable* t, u32 i) { + return t.decls[i]; } fn void SymbolTable.resize(SymbolTable* t, u32 capacity) { @@ -124,9 +124,8 @@ public fn void SymbolTable.print(const SymbolTable* t, string_buffer.Buf* out) { out.newline(); if (d.isStructType()) { StructTypeDecl* std = (StructTypeDecl*)d; - const FunctionDecl** fds = std.getStructFunctions(); for (u32 j=0; j