diff options
author | Matthew Sotoudeh <matthew@masot.net> | 2023-07-30 18:09:52 -0700 |
---|---|---|
committer | Matthew Sotoudeh <matthew@masot.net> | 2023-07-30 18:09:52 -0700 |
commit | f2297c20b69d942fd1e8fdcdd8f4d142c71de662 (patch) | |
tree | 5072f8f11eea2d8265e48d6c3bce533e124f016f /preprocess.c | |
parent | c84bbdc2a296f4b818fa8ec05a6dbe2dd46fc4f1 (diff) |
bad line numbers support
Diffstat (limited to 'preprocess.c')
-rw-r--r-- | preprocess.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/preprocess.c b/preprocess.c index abc095f..e3a3455 100644 --- a/preprocess.c +++ b/preprocess.c @@ -24,6 +24,10 @@ #include "chibicc.h" +static char *CURR_FILE; +static unsigned long LINE_SUB, + LINE_ADD; + typedef struct MacroParam MacroParam; struct MacroParam { MacroParam *next; @@ -807,6 +811,9 @@ static void read_line_marker(Token **rest, Token *tok) { if (tok->kind != TK_STR) error_tok(tok, "filename expected"); start->file->display_name = tok->str; + CURR_FILE = tok->str; + LINE_SUB = tok->line_no; + LINE_ADD = tok->val; } // Visit all tokens in `tok` while evaluating preprocessing @@ -823,7 +830,9 @@ static Token *preprocess2(Token *tok) { // Pass through if it is not a "#". if (!is_hash(tok)) { tok->line_delta = tok->file->line_delta; - tok->filename = tok->file->display_name; + tok->line_no -= LINE_SUB; + tok->line_no += LINE_ADD; + tok->filename = CURR_FILE ? CURR_FILE : tok->file->display_name; cur = cur->next = tok; tok = tok->next; continue; |