scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 44882dc0000b32dc3cded163d0318995a753150e
parent 3261788e3d8b7782ff0ade7b391572c54485e644
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 24 Feb 2017 19:53:02 +0100

[cc1] Move print of #line to cpp

When cc1 is working with -E it has to control the current line
number and emit #line directives when there is a discrepancy,
and it was done directly in moreinput(), but this is a job that
is better done in a funciton located in cpp.c, specially near
of outcpp(), because both functions are going to generate the
output at the same time.

Diffstat:
Mcc1/cc1.h | 1+
Mcc1/cpp.c | 21+++++++++++++++++++++
Mcc1/lex.c | 19++-----------------
3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -456,6 +456,7 @@ extern void incdir(char *dir); extern void outcpp(void); extern void defdefine(char *macro, char *val, char *source); extern void undefmacro(char *s); +extern void ppragmaln(void); /* builtin.c */ extern void ibuilts(void); diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -781,6 +781,27 @@ error: } void +ppragmaln(void) +{ + static char file[FILENAME_MAX]; + static unsigned nline; + char *s; + int i; + + putchar('\n'); + if (strcmp(file, filenam)) { + strcpy(file, filenam); + s = "#line %u %s\n"; + } else if (nline+1 != lineno) { + s = "#line %u\n"; + } else { + s = ""; + } + nline = lineno; + printf(s, nline, file); +} + +void outcpp(void) { char c, *s, *t; diff --git a/cc1/lex.c b/cc1/lex.c @@ -304,23 +304,8 @@ repeat: } } - if (onlycpp && !wasexpand) { - static char file[FILENAME_MAX]; - static unsigned nline; - char *s; - - putchar('\n'); - if (strcmp(file, filenam)) { - strcpy(file, filenam); - s = "#line %u %s\n"; - } else if (nline+1 != lineno) { - s = "#line %u\n"; - } else { - s = ""; - } - nline = lineno; - printf(s, nline, file); - } + if (onlycpp && !wasexpand) + ppragmaln(); return 1; }