diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-07 14:36:54 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-07 14:37:19 -0400 |
| commit | 423837daad6ed6ac1e7cec84829d260964a05ca4 (patch) | |
| tree | 28373cc36cd117aa775cf6800773663f930c9885 /src/server | |
| parent | 7078193117531940658d0361a0451e43ac101060 (diff) | |
Recursively resolve when statements and resolve the else statements correctly
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/ast.odin | 77 |
1 files changed, 33 insertions, 44 deletions
diff --git a/src/server/ast.odin b/src/server/ast.odin index a07f69d..e658123 100644 --- a/src/server/ast.odin +++ b/src/server/ast.odin @@ -440,28 +440,7 @@ collect_when_stmt :: proc( if resolve_when_condition(when_decl.cond) { if block, ok := when_decl.body.derived.(^ast.Block_Stmt); ok { - for stmt in block.stmts { - if when_stmt, ok := stmt.derived.(^ast.When_Stmt); ok { - } else if foreign_decl, ok := stmt.derived.(^ast.Foreign_Block_Decl); ok { - if foreign_decl.body == nil { - continue - } - - if foreign_block, ok := foreign_decl.body.derived.(^ast.Block_Stmt); ok { - for foreign_stmt in foreign_block.stmts { - collect_value_decl( - exprs, - file, - file_tags, - foreign_stmt, - foreign_decl.attributes[:], - ) - } - } - } else { - collect_value_decl(exprs, file, file_tags, stmt, {}) - } - } + collect_when_body(exprs, file, file_tags, block) } } else { else_stmt := when_decl.else_stmt @@ -470,38 +449,48 @@ collect_when_stmt :: proc( if else_when, ok := else_stmt.derived.(^ast.When_Stmt); ok { if resolve_when_condition(else_when.cond) { if block, ok := else_when.body.derived.(^ast.Block_Stmt); ok { - for stmt in block.stmts { - if when_stmt, ok := stmt.derived.(^ast.When_Stmt); ok { - collect_when_stmt(exprs, file, file_tags, when_stmt) - } else if foreign_decl, ok := stmt.derived.(^ast.Foreign_Block_Decl); ok { - if foreign_decl.body != nil { - if foreign_block, ok := foreign_decl.body.derived.(^ast.Block_Stmt); ok { - for foreign_stmt in foreign_block.stmts { - collect_value_decl( - exprs, - file, - file_tags, - foreign_stmt, - foreign_decl.attributes[:], - ) - } - } - } - } else { - collect_value_decl(exprs, file, file_tags, stmt, {}) - } - } + collect_when_body(exprs, file, file_tags, block) } return } else_stmt = else_when.else_stmt } else { + if block, ok := else_stmt.derived.(^ast.Block_Stmt); ok { + collect_when_body(exprs, file, file_tags, block) + } return } } } +} - +collect_when_body :: proc( + exprs: ^[dynamic]GlobalExpr, + file: ast.File, + file_tags: parser.File_Tags, + block: ^ast.Block_Stmt, +) { + for stmt in block.stmts { + if when_stmt, ok := stmt.derived.(^ast.When_Stmt); ok { + collect_when_stmt(exprs, file, file_tags, when_stmt) + } else if foreign_decl, ok := stmt.derived.(^ast.Foreign_Block_Decl); ok { + if foreign_decl.body != nil { + if foreign_block, ok := foreign_decl.body.derived.(^ast.Block_Stmt); ok { + for foreign_stmt in foreign_block.stmts { + collect_value_decl( + exprs, + file, + file_tags, + foreign_stmt, + foreign_decl.attributes[:], + ) + } + } + } + } else { + collect_value_decl(exprs, file, file_tags, stmt, {}) + } + } } collect_globals :: proc(file: ast.File) -> []GlobalExpr { |