History

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

grischka committed 17 years ago

Commit e4ae77c1 parent 956b4be1 file · +22 −7Browse files

Unified · Split

tccpp.c+22−7
@@ -2895,8 +2895,9 @@ void preprocess_new() · 2894 unmodified lines
28952895 static int tcc_preprocess(TCCState *s1)
28962896 {
28972897 Sym *define_start;
2898− BufferedFile *file_ref;
2899− int token_seen, line_ref;
2898+ BufferedFile *file_ref, **iptr, **iptr_new;
2899+ int token_seen, line_ref, d;
2900+ const char *s;
29002901
29012902 preprocess_init(s1);
29022903 define_start = define_stack;
@@ -2908,24 +2909,38 @@ static int tcc_preprocess(TCCState *s1) · 5 unmodified lines
29082909 line_ref = 0;
29092910 file_ref = NULL;
29102911
2912+ iptr = s1->include_stack_ptr;
29112913 for (;;) {
29122914 next();
29132915 if (tok == TOK_EOF) {
29142916 break;
2917+ } else if (file != file_ref) {
2918+ goto print_line;
29152919 } else if (tok == TOK_LINEFEED) {
29162920 if (!token_seen)
29172921 continue;
29182922 ++line_ref;
29192923 token_seen = 0;
29202924 } else if (!token_seen) {
2921− int d = file->line_num - line_ref;
2922− if (file != file_ref || d < 0 || d >= 8)
2923− fprintf(s1->outfile, "# %d \"%s\"\n", file->line_num, file->filename);
2924− else
2925+ d = file->line_num - line_ref;
2926+ if (file != file_ref || d < 0 || d >= 8) {
2927+print_line:
2928+ iptr_new = s1->include_stack_ptr;
2929+ s = iptr_new > iptr ? " 1"
2930+ : iptr_new < iptr ? " 2"
2931+ : iptr_new > s1->include_stack ? " 3"
2932+ : ""
2933+ ;
2934+ iptr = iptr_new;
2935+ fprintf(s1->outfile, "# %d \"%s\"%s\n", file->line_num, file->filename, s);
2936+ } else {
29252937 while (d)
29262938 fputs("\n", s1->outfile), --d;
2939+ }
29272940 line_ref = (file_ref = file)->line_num;
2928− token_seen = 1;
2941+ token_seen = tok != TOK_LINEFEED;
2942+ if (!token_seen)
2943+ continue;
29292944 }
29302945 fputs(get_tok_str(tok, &tokc), s1->outfile);
29312946 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t