aboutsummaryrefslogtreecommitdiff
path: root/src/server/analysis.odin
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-06-28 12:25:45 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-06-28 12:25:45 -0400
commitffb24d236028a1ee74b6044ed4fe8b49d938dbba (patch)
tree85464157e3691b127fc240d4614d88cd5c14458c /src/server/analysis.odin
parent8d065f76999d771d8d3747a066cdf044953d7bfa (diff)
Remove unused local id from the AstContext
Diffstat (limited to 'src/server/analysis.odin')
-rw-r--r--src/server/analysis.odin46
1 files changed, 15 insertions, 31 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 64e526d..b487c76 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -81,8 +81,10 @@ DocumentLocal :: struct {
DeferredDepth :: 35
+LocalGroup :: map[string][dynamic]DocumentLocal
+
AstContext :: struct {
- locals: [dynamic]map[string][dynamic]DocumentLocal, //locals all the way to the document position
+ locals: [dynamic]LocalGroup, //locals all the way to the document position
globals: map[string]GlobalExpr,
recursion_map: map[rawptr]bool,
usings: [dynamic]string,
@@ -94,7 +96,6 @@ AstContext :: struct {
deferred_package: [DeferredDepth]string, //When a package change happens when resolving
deferred_count: int,
use_locals: bool,
- local_id: int,
call: ^ast.Call_Expr, //used to determine the types for generics and the correct function for overloaded functions
value_decl: ^ast.Value_Decl,
field_name: ast.Ident,
@@ -1192,19 +1193,18 @@ store_local :: proc(
rhs: ^ast.Expr,
offset: int,
name: string,
- id: int,
local_global: bool,
resolved_global: bool,
variable: bool,
pkg: string,
parameter: bool,
) {
- local_stack := &ast_context.locals[len(ast_context.locals) - 1][name]
+ local_group := get_local_group(ast_context)
+ local_stack := &local_group[name]
if local_stack == nil {
- locals := &ast_context.locals[len(ast_context.locals) - 1]
- locals[name] = make([dynamic]DocumentLocal, ast_context.allocator)
- local_stack = &locals[name]
+ local_group[name] = make([dynamic]DocumentLocal, ast_context.allocator)
+ local_stack = &local_group[name]
}
append(
@@ -1223,13 +1223,20 @@ store_local :: proc(
}
add_local_group :: proc(ast_context: ^AstContext) {
- append(&ast_context.locals, make(map[string][dynamic]DocumentLocal, 100, ast_context.allocator))
+ append(&ast_context.locals, make(LocalGroup, 100, ast_context.allocator))
}
pop_local_group :: proc(ast_context: ^AstContext) {
pop(&ast_context.locals)
}
+get_local_group :: proc(ast_context: ^AstContext) -> ^LocalGroup {
+ if len(ast_context.locals) == 0 {
+ add_local_group(ast_context)
+ }
+ return &ast_context.locals[len(ast_context.locals) - 1]
+}
+
get_local :: proc(ast_context: AstContext, ident: ast.Ident) -> (DocumentLocal, bool) {
#reverse for locals in ast_context.locals {
local_stack := locals[ident.name] or_continue
@@ -2971,7 +2978,6 @@ get_locals_value_decl :: proc(file: ast.File, value_decl: ast.Value_Decl, ast_co
value_decl.type,
value_decl.end.offset,
str,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
value_decl.is_mutable,
@@ -3011,7 +3017,6 @@ get_locals_value_decl :: proc(file: ast.File, value_decl: ast.Value_Decl, ast_co
results[result_i],
value_decl.end.offset,
str,
- ast_context.local_id,
ast_context.non_mutable_only,
calls[result_i] or_else false,
value_decl.is_mutable,
@@ -3155,7 +3160,6 @@ get_locals_using :: proc(expr: ^ast.Expr, ast_context: ^AstContext) {
selector,
0,
name,
- ast_context.local_id,
false,
ast_context.non_mutable_only,
true,
@@ -3175,7 +3179,6 @@ get_locals_using :: proc(expr: ^ast.Expr, ast_context: ^AstContext) {
selector,
0,
name,
- ast_context.local_id,
false,
ast_context.non_mutable_only,
true,
@@ -3219,7 +3222,6 @@ get_locals_assign_stmt :: proc(file: ast.File, stmt: ast.Assign_Stmt, ast_contex
results[i],
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3273,7 +3275,6 @@ get_locals_for_range_stmt :: proc(
make_int_ast(ast_context, ident.pos, ident.end),
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3319,7 +3320,6 @@ get_locals_for_range_stmt :: proc(
expr,
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3339,7 +3339,6 @@ get_locals_for_range_stmt :: proc(
make_rune_ast(ast_context, ident.pos, ident.end),
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3359,7 +3358,6 @@ get_locals_for_range_stmt :: proc(
make_rune_ast(ast_context, ident.pos, ident.end),
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3378,7 +3376,6 @@ get_locals_for_range_stmt :: proc(
v.key,
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3395,7 +3392,6 @@ get_locals_for_range_stmt :: proc(
v.value,
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3413,7 +3409,6 @@ get_locals_for_range_stmt :: proc(
v.expr,
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3430,7 +3425,6 @@ get_locals_for_range_stmt :: proc(
make_int_ast(ast_context, ident.pos, ident.end),
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3448,7 +3442,6 @@ get_locals_for_range_stmt :: proc(
v.expr,
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3469,7 +3462,6 @@ get_locals_for_range_stmt :: proc(
v.len,
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3484,7 +3476,6 @@ get_locals_for_range_stmt :: proc(
make_int_ast(ast_context, ident.pos, ident.end),
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3503,7 +3494,6 @@ get_locals_for_range_stmt :: proc(
v.expr,
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3520,7 +3510,6 @@ get_locals_for_range_stmt :: proc(
make_int_ast(ast_context, ident.pos, ident.end),
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3592,7 +3581,6 @@ get_locals_type_switch_stmt :: proc(
cause.list[0],
ident.pos.offset,
ident.name,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3632,7 +3620,6 @@ get_locals_proc_param_and_results :: proc(
arg.type,
name.pos.offset,
str,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3654,7 +3641,6 @@ get_locals_proc_param_and_results :: proc(
arg.default_value,
name.pos.offset,
str,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3677,7 +3663,6 @@ get_locals_proc_param_and_results :: proc(
result.type,
name.pos.offset,
str,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,
@@ -3692,7 +3677,6 @@ get_locals_proc_param_and_results :: proc(
result.default_value,
name.pos.offset,
str,
- ast_context.local_id,
ast_context.non_mutable_only,
false,
true,