ref: 9f1312826dfbb23fa3f620cc606389515e7375e7
parent: f2ae22aa87dc060247db5f9a14db068eed12f96b
author: Quentin Rameau <quinq@fifth.space>
date: Wed Jun 29 08:42:10 EDT 2016
[cpp] keep count of command-line macros This way we can print a pseudo line number corresponding to the parameter number.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -382,7 +382,7 @@
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);
--- 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 @@
sprintf(def, fmt, macro, val);
allocinput("command-line", NULL, def);
+ input->nline = ++ncmdlines;
cpp();
delinput();
}
@@ -87,6 +89,8 @@
for (bp = list; *bp; ++bp)
defdefine(*bp, NULL);
+
+ ncmdlines = 0;
}
static void
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -23,18 +23,16 @@
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;