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--
This commit is contained in:
parent
956b4beec1
commit
e4ae77c7bb
1 changed files with 22 additions and 7 deletions
29
tccpp.c
29
tccpp.c
|
@ -2895,8 +2895,9 @@ void preprocess_new()
|
||||||
static int tcc_preprocess(TCCState *s1)
|
static int tcc_preprocess(TCCState *s1)
|
||||||
{
|
{
|
||||||
Sym *define_start;
|
Sym *define_start;
|
||||||
BufferedFile *file_ref;
|
BufferedFile *file_ref, **iptr, **iptr_new;
|
||||||
int token_seen, line_ref;
|
int token_seen, line_ref, d;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
preprocess_init(s1);
|
preprocess_init(s1);
|
||||||
define_start = define_stack;
|
define_start = define_stack;
|
||||||
|
@ -2908,24 +2909,38 @@ static int tcc_preprocess(TCCState *s1)
|
||||||
line_ref = 0;
|
line_ref = 0;
|
||||||
file_ref = NULL;
|
file_ref = NULL;
|
||||||
|
|
||||||
|
iptr = s1->include_stack_ptr;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
next();
|
next();
|
||||||
if (tok == TOK_EOF) {
|
if (tok == TOK_EOF) {
|
||||||
break;
|
break;
|
||||||
|
} else if (file != file_ref) {
|
||||||
|
goto print_line;
|
||||||
} else if (tok == TOK_LINEFEED) {
|
} else if (tok == TOK_LINEFEED) {
|
||||||
if (!token_seen)
|
if (!token_seen)
|
||||||
continue;
|
continue;
|
||||||
++line_ref;
|
++line_ref;
|
||||||
token_seen = 0;
|
token_seen = 0;
|
||||||
} else if (!token_seen) {
|
} else if (!token_seen) {
|
||||||
int d = file->line_num - line_ref;
|
d = file->line_num - line_ref;
|
||||||
if (file != file_ref || d < 0 || d >= 8)
|
if (file != file_ref || d < 0 || d >= 8) {
|
||||||
fprintf(s1->outfile, "# %d \"%s\"\n", file->line_num, file->filename);
|
print_line:
|
||||||
else
|
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)
|
while (d)
|
||||||
fputs("\n", s1->outfile), --d;
|
fputs("\n", s1->outfile), --d;
|
||||||
|
}
|
||||||
line_ref = (file_ref = file)->line_num;
|
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);
|
fputs(get_tok_str(tok, &tokc), s1->outfile);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue