ref: 35572b0d6f214a181ae63671c909935e1b0914a4
parent: 5d7ab730e604765f4ac4327d05dce79d257030d3
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jan 11 11:51:57 EST 2017
[cc1] Remove allocinput() This function was used only to avoid some code in addinput(), but since we added the support for macro expansion using push up buffers we could unify both functions in only one.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -395,7 +395,6 @@
extern void expect(unsigned tok);
extern void discard(void);
extern int addinput(char *fname, Symbol *hide, char *buffer);
-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
@@ -26,6 +26,7 @@
defdefine(char *macro, char *val, char *source)
{
char *def, *fmt = "#define %s %s";
+ Symbol dummy = {.flags = SDECLARED};
if (!val)
val = "";
@@ -32,7 +33,7 @@
def = xmalloc(strlen(fmt) + strlen(macro) + strlen(val));
sprintf(def, fmt, macro, val);
- allocinput(source, NULL, def);
+ addinput(source, &dummy, def);
input->nline = ++ncmdlines;
cpp();
delinput();
@@ -268,7 +269,7 @@
substitute:
DBG("MACRO '%s' expanded to :'%s'", macroname, buffer);
buffer[elen] = '\0';
- addinput(NULL, sym, xstrdup(buffer));
+ addinput(input->fname, sym, xstrdup(buffer));
return 1;
}
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -24,23 +24,6 @@
Input *input;
void
-allocinput(char *fname, FILE *fp, char *line)
-{
- Input *ip = xmalloc(sizeof(Input));
-
- 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;
- input = ip;
-}
-
-void
ilex(void)
{
static struct keyword keys[] = {
@@ -90,12 +73,13 @@
{
FILE *fp;
unsigned nline = 0;
+ Input *ip;
if (hide) {
/* this is a macro expansion */
fp = NULL;
- fname = xstrdup(input->fname);
- nline = input->nline;
+ if (input)
+ nline = input->nline;
if (hide->hide == UCHAR_MAX)
die("Too many macro expansions");
++hide->hide;
@@ -108,9 +92,21 @@
fp = stdin;
fname = "<stdin>";
}
- allocinput(fname, fp, buffer);
- input->hide = hide;
- input->nline = nline;
+
+ ip = xmalloc(sizeof(*ip));
+
+ if (!buffer) {
+ buffer = xmalloc(INPUTSIZ);
+ buffer[0] = '\0';
+ }
+
+ ip->p = ip->begin = ip->line = buffer;
+ ip->fname = xstrdup(fname);
+ ip->next = input;
+ ip->fp = fp;
+ ip->hide = hide;
+ ip->nline = nline;
+ input = ip;
return 1;
}