From e4ae77c7bbe01637e7164fd1420b7d8fecfe2a29 Mon Sep 17 00:00:00 2001 From: grischka Date: Wed, 17 Jun 2009 02:10:42 +0200 Subject: [PATCH] tcc_preprocess: add gcc-style include-depth flags # 1 "main.c" # 1 "include/stdio.h" 1 # 123 "include/stdio.h" 3 # 10 "main.c" 2 flags: 1: level++; 3: same-level 2: level-- --- tccpp.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tccpp.c b/tccpp.c index ff17d8b..7074343 100644 --- a/tccpp.c +++ b/tccpp.c @@ -2895,8 +2895,9 @@ void preprocess_new() static int tcc_preprocess(TCCState *s1) { Sym *define_start; - BufferedFile *file_ref; - int token_seen, line_ref; + BufferedFile *file_ref, **iptr, **iptr_new; + int token_seen, line_ref, d; + const char *s; preprocess_init(s1); define_start = define_stack; @@ -2908,24 +2909,38 @@ static int tcc_preprocess(TCCState *s1) line_ref = 0; file_ref = NULL; + iptr = s1->include_stack_ptr; for (;;) { next(); if (tok == TOK_EOF) { break; + } else if (file != file_ref) { + goto print_line; } else if (tok == TOK_LINEFEED) { if (!token_seen) continue; ++line_ref; token_seen = 0; } else if (!token_seen) { - int d = file->line_num - line_ref; - if (file != file_ref || d < 0 || d >= 8) - fprintf(s1->outfile, "# %d \"%s\"\n", file->line_num, file->filename); - else + d = file->line_num - line_ref; + if (file != file_ref || d < 0 || d >= 8) { +print_line: + iptr_new = s1->include_stack_ptr; + s = iptr_new > iptr ? " 1" + : iptr_new < iptr ? " 2" + : iptr_new > s1->include_stack ? " 3" + : "" + ; + iptr = iptr_new; + fprintf(s1->outfile, "# %d \"%s\"%s\n", file->line_num, file->filename, s); + } else { while (d) fputs("\n", s1->outfile), --d; + } line_ref = (file_ref = file)->line_num; - token_seen = 1; + token_seen = tok != TOK_LINEFEED; + if (!token_seen) + continue; } fputs(get_tok_str(tok, &tokc), s1->outfile); }