scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 946ce5f09e298d5bbcc1f7f099aa79041cdd94b6
parent a2305b12133a41577a844ad42ae22c5b1ac9663c
Author: Quentin Rameau <quinq@fifth.space>
Date:   Wed, 29 Jun 2016 12:42:10 +0200

[cpp] keep count of command-line macros

This way we can print a pseudo line number corresponding to the
parameter number.

Diffstat:
cc1/cc1.h | 2+-
cc1/cpp.c | 4++++
cc1/lex.c | 14++++++--------
3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -382,7 +382,7 @@ extern int moreinput(void); extern void expect(unsigned tok); extern void discard(void); extern int addinput(char *fname); -extern void allocinput(char *fname, FILE *fp, char *s); +extern void allocinput(char *fname, FILE *fp, char *line); extern void delinput(void); extern void setsafe(int type); extern void ilex(void); diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -13,6 +13,7 @@ static char *argp, *macroname; static unsigned arglen; +static unsigned ncmdlines; static Symbol *symline, *symfile; static unsigned char ifstatus[NR_COND]; static int ninclude; @@ -32,6 +33,7 @@ defdefine(char *macro, char *val) sprintf(def, fmt, macro, val); allocinput("command-line", NULL, def); + input->nline = ++ncmdlines; cpp(); delinput(); } @@ -87,6 +89,8 @@ icpp(void) for (bp = list; *bp; ++bp) defdefine(*bp, NULL); + + ncmdlines = 0; } static void diff --git a/cc1/lex.c b/cc1/lex.c @@ -23,18 +23,16 @@ static int safe, eof; Input *input; void -allocinput(char *fname, FILE *fp, char *s) +allocinput(char *fname, FILE *fp, char *line) { Input *ip = xmalloc(sizeof(Input)); - if (s) { - ip->p = ip->begin = ip->line = s; - ip->nline = 1; - } else { - ip->p = ip->begin = ip->line = xmalloc(INPUTSIZ); - ip->p[0] = '\0'; - ip->nline = 0; + if (!line) { + line = xmalloc(INPUTSIZ); + line[0] = '\0'; } + ip->p = ip->begin = ip->line = line; + ip->nline = 0; ip->fname = xstrdup(fname); ip->next = input; ip->fp = fp;