[hackers] [scc] [cc1] Remove allocinput() || Roberto E. Vargas Caballero
commit 89bb136a4e5fc5a942f34ff2d0e284c783f8b771
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Jan 11 16:51:57 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Jan 11 16:51:57 2017 +0100
[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.
diff --git a/cc1/cc1.h b/cc1/cc1.h
index c8095d6..a199cca 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -395,7 +395,6 @@ extern int moreinput(void);
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);
diff --git a/cc1/cpp.c b/cc1/cpp.c
index 79d57b2..2aa29ae 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -26,13 +26,14 @@ void
defdefine(char *macro, char *val, char *source)
{
char *def, *fmt = "#define %s %s";
+ Symbol dummy = {.flags = SDECLARED};
if (!val)
val = "";
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();
_AT_@ -268,7 +269,7 @@ expand(char *begin, Symbol *sym)
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;
}
diff --git a/cc1/lex.c b/cc1/lex.c
index fd55f1b..d861be6 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -24,23 +24,6 @@ static int safe, eof;
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[] = {
_AT_@ -90,12 +73,13 @@ addinput(char *fname, Symbol *hide, char *buffer)
{
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;
_AT_@ -108,9 +92,21 @@ addinput(char *fname, Symbol *hide, char *buffer)
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;
}
Received on Wed Jan 11 2017 - 16:53:20 CET
This archive was generated by hypermail 2.3.0
: Wed Jan 11 2017 - 17:00:24 CET