diff options
| author | grischka <grischka> | 2009-06-17 02:10:42 +0200 |
|---|---|---|
| committer | grischka <grischka> | 2009-06-17 02:10:42 +0200 |
| commit | e4ae77c7bbe01637e7164fd1420b7d8fecfe2a29 (patch) | |
| tree | 9f2ca863f6822947c24d6e2d8263bd5bbd03a8b4 | |
| parent | 956b4beec123644092c1998501412f888672a1c6 (diff) | |
| download | tinycc-e4ae77c7bbe01637e7164fd1420b7d8fecfe2a29.tar.gz tinycc-e4ae77c7bbe01637e7164fd1420b7d8fecfe2a29.tar.bz2 | |
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--
| -rw-r--r-- | tccpp.c | 29 |
1 files changed, 22 insertions, 7 deletions
@@ -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); } |
