summaryrefslogtreecommitdiff
path: root/preprocess.c
diff options
context:
space:
mode:
Diffstat (limited to 'preprocess.c')
-rw-r--r--preprocess.c11
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;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback