cc: do not expand function-like macros for non-function invocations
It is a bit of a annoyance that kenc will try to expand function like macros on any symbol with the same name and then complain when it doesnt see the '(' in the invocation. test case below: void foo(int) { } struct Bar { int baz; /* <- should not conflict */ }; void main(void) { baz(123); }
This commit is contained in:
parent
1656782f79
commit
b3c3c3e63d
13 changed files with 50 additions and 39 deletions
|
@ -156,7 +156,7 @@ Sym* getsym(void);
|
||||||
void domacro(void);
|
void domacro(void);
|
||||||
void macund(void);
|
void macund(void);
|
||||||
void macdef(void);
|
void macdef(void);
|
||||||
void macexpand(Sym*, char*, int);
|
int macexpand(Sym*, char*, int);
|
||||||
void macinc(void);
|
void macinc(void);
|
||||||
void macprag(void);
|
void macprag(void);
|
||||||
void maclin(void);
|
void maclin(void);
|
||||||
|
|
|
@ -157,7 +157,7 @@ Sym* getsym(void);
|
||||||
void domacro(void);
|
void domacro(void);
|
||||||
void macund(void);
|
void macund(void);
|
||||||
void macdef(void);
|
void macdef(void);
|
||||||
void macexpand(Sym*, char*, int);
|
int macexpand(Sym*, char*, int);
|
||||||
void macinc(void);
|
void macinc(void);
|
||||||
void macprag(void);
|
void macprag(void);
|
||||||
void maclin(void);
|
void maclin(void);
|
||||||
|
|
|
@ -137,7 +137,7 @@ Sym* getsym(void);
|
||||||
void domacro(void);
|
void domacro(void);
|
||||||
void macund(void);
|
void macund(void);
|
||||||
void macdef(void);
|
void macdef(void);
|
||||||
void macexpand(Sym*, char*, int);
|
int macexpand(Sym*, char*, int);
|
||||||
void macinc(void);
|
void macinc(void);
|
||||||
void maclin(void);
|
void maclin(void);
|
||||||
void macprag(void);
|
void macprag(void);
|
||||||
|
|
|
@ -151,7 +151,7 @@ Sym* getsym(void);
|
||||||
void domacro(void);
|
void domacro(void);
|
||||||
void macund(void);
|
void macund(void);
|
||||||
void macdef(void);
|
void macdef(void);
|
||||||
void macexpand(Sym*, char*, int);
|
int macexpand(Sym*, char*, int);
|
||||||
void macinc(void);
|
void macinc(void);
|
||||||
void macprag(void);
|
void macprag(void);
|
||||||
void maclin(void);
|
void maclin(void);
|
||||||
|
|
|
@ -143,7 +143,7 @@ Sym* getsym(void);
|
||||||
void domacro(void);
|
void domacro(void);
|
||||||
void macund(void);
|
void macund(void);
|
||||||
void macdef(void);
|
void macdef(void);
|
||||||
void macexpand(Sym*, char*, int);
|
int macexpand(Sym*, char*, int);
|
||||||
void macinc(void);
|
void macinc(void);
|
||||||
void maclin(void);
|
void maclin(void);
|
||||||
void macprag(void);
|
void macprag(void);
|
||||||
|
|
|
@ -152,7 +152,7 @@ Sym* getsym(void);
|
||||||
void domacro(void);
|
void domacro(void);
|
||||||
void macund(void);
|
void macund(void);
|
||||||
void macdef(void);
|
void macdef(void);
|
||||||
void macexpand(Sym*, char*, int);
|
int macexpand(Sym*, char*, int);
|
||||||
void macinc(void);
|
void macinc(void);
|
||||||
void macprag(void);
|
void macprag(void);
|
||||||
void maclin(void);
|
void maclin(void);
|
||||||
|
|
|
@ -556,7 +556,7 @@ void linehist(char*, int);
|
||||||
void macdef(void);
|
void macdef(void);
|
||||||
void macprag(void);
|
void macprag(void);
|
||||||
void macend(void);
|
void macend(void);
|
||||||
void macexpand(Sym*, char*, int);
|
int macexpand(Sym*, char*, int);
|
||||||
void macif(int);
|
void macif(int);
|
||||||
void macinc(void);
|
void macinc(void);
|
||||||
void maclin(void);
|
void maclin(void);
|
||||||
|
|
|
@ -755,18 +755,22 @@ talph:
|
||||||
if(s->macro) {
|
if(s->macro) {
|
||||||
newio();
|
newio();
|
||||||
cp = ionext->b;
|
cp = ionext->b;
|
||||||
macexpand(s, cp, sizeof(ionext->b)-1);
|
if(macexpand(s, cp, sizeof(ionext->b)-1)){
|
||||||
pushio();
|
pushio();
|
||||||
ionext->link = iostack;
|
ionext->link = iostack;
|
||||||
iostack = ionext;
|
iostack = ionext;
|
||||||
fi.p = cp;
|
fi.p = cp;
|
||||||
fi.c = strlen(cp);
|
fi.c = strlen(cp);
|
||||||
if(peekc != IGN) {
|
if(peekc != IGN) {
|
||||||
cp[fi.c++] = peekc;
|
cp[fi.c++] = peekc;
|
||||||
cp[fi.c] = 0;
|
cp[fi.c] = 0;
|
||||||
peekc = IGN;
|
peekc = IGN;
|
||||||
|
}
|
||||||
|
goto l0;
|
||||||
|
} else {
|
||||||
|
ionext->link = iofree;
|
||||||
|
iofree = ionext;
|
||||||
}
|
}
|
||||||
goto l0;
|
|
||||||
}
|
}
|
||||||
yylval.sym = s;
|
yylval.sym = s;
|
||||||
if(s->class == CTYPEDEF || s->class == CTYPESTR)
|
if(s->class == CTYPEDEF || s->class == CTYPESTR)
|
||||||
|
|
|
@ -238,18 +238,22 @@ l1:
|
||||||
if(s->macro) {
|
if(s->macro) {
|
||||||
newio();
|
newio();
|
||||||
cp = ionext->b;
|
cp = ionext->b;
|
||||||
macexpand(s, cp, sizeof(ionext->b)-1);
|
if(macexpand(s, cp, sizeof(ionext->b)-1)){
|
||||||
pushio();
|
pushio();
|
||||||
ionext->link = iostack;
|
ionext->link = iostack;
|
||||||
iostack = ionext;
|
iostack = ionext;
|
||||||
fi.p = cp;
|
fi.p = cp;
|
||||||
fi.c = strlen(cp);
|
fi.c = strlen(cp);
|
||||||
if(peekc != IGN) {
|
if(peekc != IGN) {
|
||||||
cp[fi.c++] = peekc;
|
cp[fi.c++] = peekc;
|
||||||
cp[fi.c] = 0;
|
cp[fi.c] = 0;
|
||||||
peekc = IGN;
|
peekc = IGN;
|
||||||
|
}
|
||||||
|
goto l0;
|
||||||
|
} else {
|
||||||
|
ionext->link = iofree;
|
||||||
|
iofree = ionext;
|
||||||
}
|
}
|
||||||
goto l0;
|
|
||||||
}
|
}
|
||||||
if(s->type == 0)
|
if(s->type == 0)
|
||||||
s->type = LNAME;
|
s->type = LNAME;
|
||||||
|
|
|
@ -372,7 +372,7 @@ bad:
|
||||||
macend();
|
macend();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
macexpand(Sym *s, char *b, int blen)
|
macexpand(Sym *s, char *b, int blen)
|
||||||
{
|
{
|
||||||
char buf[2000];
|
char buf[2000];
|
||||||
|
@ -386,15 +386,17 @@ macexpand(Sym *s, char *b, int blen)
|
||||||
goto toobig;
|
goto toobig;
|
||||||
if(debug['m'])
|
if(debug['m'])
|
||||||
print("#expand %s %s\n", s->name, b);
|
print("#expand %s %s\n", s->name, b);
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
nargs = (char)(*s->macro & ~VARMAC) - 1;
|
nargs = (char)(*s->macro & ~VARMAC) - 1;
|
||||||
dots = *s->macro & VARMAC;
|
dots = *s->macro & VARMAC;
|
||||||
|
|
||||||
c = getnsc();
|
c = getnsc();
|
||||||
if(c != '(')
|
if(c != '('){
|
||||||
goto bad;
|
unget(c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
n = 0;
|
n = 0;
|
||||||
c = getc();
|
c = getc();
|
||||||
if(c != ')') {
|
if(c != ')') {
|
||||||
|
@ -490,7 +492,7 @@ macexpand(Sym *s, char *b, int blen)
|
||||||
if(n != nargs) {
|
if(n != nargs) {
|
||||||
yyerror("argument mismatch expanding: %s", s->name);
|
yyerror("argument mismatch expanding: %s", s->name);
|
||||||
*b = 0;
|
*b = 0;
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
ob = b;
|
ob = b;
|
||||||
eb = b + blen-1;
|
eb = b + blen-1;
|
||||||
|
@ -526,16 +528,17 @@ macexpand(Sym *s, char *b, int blen)
|
||||||
*b = 0;
|
*b = 0;
|
||||||
if(debug['m'])
|
if(debug['m'])
|
||||||
print("#expand %s %s\n", s->name, ob);
|
print("#expand %s %s\n", s->name, ob);
|
||||||
return;
|
return 1;
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
yyerror("syntax in macro expansion: %s", s->name);
|
yyerror("syntax in macro expansion: %s", s->name);
|
||||||
*b = 0;
|
*b = 0;
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
toobig:
|
toobig:
|
||||||
yyerror("too much text in macro expansion: %s", s->name);
|
yyerror("too much text in macro expansion: %s", s->name);
|
||||||
*b = 0;
|
*b = 0;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -136,7 +136,7 @@ Sym* getsym(void);
|
||||||
void domacro(void);
|
void domacro(void);
|
||||||
void macund(void);
|
void macund(void);
|
||||||
void macdef(void);
|
void macdef(void);
|
||||||
void macexpand(Sym*, char*, int);
|
int macexpand(Sym*, char*, int);
|
||||||
void macinc(void);
|
void macinc(void);
|
||||||
void macprag(void);
|
void macprag(void);
|
||||||
void maclin(void);
|
void maclin(void);
|
||||||
|
|
|
@ -138,7 +138,7 @@ Sym* getsym(void);
|
||||||
void domacro(void);
|
void domacro(void);
|
||||||
void macund(void);
|
void macund(void);
|
||||||
void macdef(void);
|
void macdef(void);
|
||||||
void macexpand(Sym*, char*, int);
|
int macexpand(Sym*, char*, int);
|
||||||
void macinc(void);
|
void macinc(void);
|
||||||
void macprag(void);
|
void macprag(void);
|
||||||
void maclin(void);
|
void maclin(void);
|
||||||
|
|
|
@ -136,7 +136,7 @@ Sym* getsym(void);
|
||||||
void domacro(void);
|
void domacro(void);
|
||||||
void macund(void);
|
void macund(void);
|
||||||
void macdef(void);
|
void macdef(void);
|
||||||
void macexpand(Sym*, char*, int);
|
int macexpand(Sym*, char*, int);
|
||||||
void macinc(void);
|
void macinc(void);
|
||||||
void maclin(void);
|
void maclin(void);
|
||||||
void macprag(void);
|
void macprag(void);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue