@@ -837,23 +837,22 @@ func void maybe_insert_cast_from_void_pointer(struct expr *lhs, struct expr *rhs
837837
838838func struct ast_scope *parser_push_new_scope(struct context *context, struct token *token, enum scope_flags flags){
839839
840+ struct ast_scope *parent = context->current_scope;
841+
840842 struct ast_scope *scope = push_uninitialized_struct(context->arena, struct ast_scope);
841843 scope->flags = flags;
842844 scope->token = token;
845+ scope->start_offset = (u32)(arena_current(&context->ir_arena) - context->current_function->start_in_ir_arena); // kinda dumb, this is not true for function scopes. Maybe this function should not be called for function scopes.
846+ scope->parent = parent;
843847
844- struct ast_scope *parent = context->current_scope;
845- if(parent){
846- if(parent->subscopes.last){ // @note: sll_push_back does not work because of the `subscopes` member.
847- parent->subscopes.last->subscopes.next = scope;
848- parent->subscopes.last = scope;
849- }else{
850- parent->subscopes.first = scope;
851- parent->subscopes.last = scope;
852- }
853- parent->subscopes.count += 1;
854-
855- scope->parent = parent;
848+ if(parent->subscopes.last){ // @note: sll_push_back does not work because of the `subscopes` member.
849+ parent->subscopes.last->subscopes.next = scope;
850+ parent->subscopes.last = scope;
851+ }else{
852+ parent->subscopes.first = scope;
853+ parent->subscopes.last = scope;
856854 }
855+ parent->subscopes.count += 1;
857856
858857 context->current_scope = scope;
859858
@@ -862,6 +861,7 @@ func struct ast_scope *parser_push_new_scope(struct context *context, struct tok
862861
863862func void parser_scope_pop(struct context *context, struct ast_scope *scope){
864863 assert(context->current_scope == scope);
864+ scope->end_offset = (u32)(arena_current(&context->ir_arena) - context->current_function->start_in_ir_arena);
865865 context->current_scope = context->current_scope->parent;
866866}
867867
@@ -8803,8 +8803,12 @@ func struct declaration_list parse_declaration_list(struct context *context, str
88038803 return ret;
88048804 }
88058805
8806- scope = parser_push_new_scope(context, get_current_token(context), SCOPE_FLAG_is_function_scope);
8807- parser_scope_pop(context, scope);
8806+ // @note: We don't want to use the general `parser_push_new_scope` function, as it is not designed for function scopes,
8807+ // and we would not want to add this scope to the scopes of the current function anyway (if it is local).
8808+ scope = push_struct(context->arena, struct ast_scope);
8809+ scope->flags = SCOPE_FLAG_is_function_scope;
8810+ scope->parent = context->current_scope;
8811+ scope->token = get_current_token(context);
88088812
88098813 ret.is_function_definition = scope;
88108814
@@ -9821,8 +9825,6 @@ func void parse_imperative_scope(struct context *context){
98219825 struct ast_scope *scope = context->current_scope;
98229826 assert(scope);
98239827
9824- scope->start_line_index = (u32)context->current_function->line_information.size;
9825-
98269828 // Keep parsing inputs even after an error has occurred!
98279829 while(true){
98289830 // Statements only occur at function scope, so there should not be any sleeping.
@@ -9861,10 +9863,6 @@ func void parse_imperative_scope(struct context *context){
98619863 }
98629864 }
98639865
9864- scope->end_line_index = (u32)context->current_function->line_information.size;
9865- if(scope->start_line_index > scope->end_line_index){
9866- scope->start_line_index = scope->end_line_index;
9867- }
98689866}
98699867
98709868func struct declarator_return parse_declarator(struct context* context, struct ast_type *_initial_type, enum ast_kind *_initial_defined_type, enum declarator_kind_flags declarator_kind_flags){
0 commit comments