From a7524a007137b4da3dbd864845377c4a2442d1bf Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 28 Sep 2022 20:30:31 +0200 Subject: [PATCH] Improve line directive mapping --- core_codegen_c_language.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index 61ec98e..61e10ea 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -13,10 +13,12 @@ gen_indent(){ } global Intern_String last_filename; +global int last_line; function void gen_line(Ast *node){ if(emit_line_directives){ - genln("#line %d", node->pos->line+1); + last_line = node->pos->line+1; + genln("#line %d", last_line); if(node->pos->file != last_filename){ last_filename = node->pos->file; gen(" \"%Q\"", last_filename); @@ -24,6 +26,13 @@ gen_line(Ast *node){ } } +function void +gen_last_line(){ + if(emit_line_directives){ + genln("#line %d", last_line); + } +} + function String string_scope_name(Allocator *a, Ast_Scope *scope){ String string = {}; @@ -217,6 +226,7 @@ gen_stmt_scope(Ast_Scope *scope, B32 switch_case_gen_break = 0){ } if(switch_case_gen_break == 1) genln("break;"); global_indent--; + gen_last_line(); genln("}"); } @@ -560,6 +570,7 @@ gen_ast(Ast *ast){ gen_ast(it); } global_indent--; + gen_last_line(); genln("}"); } @@ -679,6 +690,7 @@ gen_ast(Ast *ast){ } global_indent--; + gen_last_line(); genln("}"); BREAK();