summaryrefslogtreecommitdiff
path: root/sys/src
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2021-10-12 03:06:20 +0000
committercinap_lenrek <cinap_lenrek@felloff.net>2021-10-12 03:06:20 +0000
commitb3c3c3e63df2958dfc3f972abefa8f892d8345d3 (patch)
tree8aaa6f73989ef8dc84b0cb598aa7540aa4fb3066 /sys/src
parent1656782f7919856b6a627a5f15a4209ee853f7f1 (diff)
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); }
Diffstat (limited to 'sys/src')
-rw-r--r--sys/src/cmd/1a/a.h2
-rw-r--r--sys/src/cmd/2a/a.h2
-rw-r--r--sys/src/cmd/5a/a.h2
-rw-r--r--sys/src/cmd/6a/a.h2
-rw-r--r--sys/src/cmd/7a/a.h2
-rw-r--r--sys/src/cmd/8a/a.h2
-rw-r--r--sys/src/cmd/cc/cc.h2
-rw-r--r--sys/src/cmd/cc/lex.c26
-rw-r--r--sys/src/cmd/cc/lexbody26
-rw-r--r--sys/src/cmd/cc/macbody17
-rw-r--r--sys/src/cmd/ka/a.h2
-rw-r--r--sys/src/cmd/qa/a.h2
-rw-r--r--sys/src/cmd/va/a.h2
13 files changed, 50 insertions, 39 deletions
diff --git a/sys/src/cmd/1a/a.h b/sys/src/cmd/1a/a.h
index ff8f11ca3..99b894572 100644
--- a/sys/src/cmd/1a/a.h
+++ b/sys/src/cmd/1a/a.h
@@ -156,7 +156,7 @@ Sym* getsym(void);
void domacro(void);
void macund(void);
void macdef(void);
-void macexpand(Sym*, char*, int);
+int macexpand(Sym*, char*, int);
void macinc(void);
void macprag(void);
void maclin(void);
diff --git a/sys/src/cmd/2a/a.h b/sys/src/cmd/2a/a.h
index 65549baf9..52eae9cf3 100644
--- a/sys/src/cmd/2a/a.h
+++ b/sys/src/cmd/2a/a.h
@@ -157,7 +157,7 @@ Sym* getsym(void);
void domacro(void);
void macund(void);
void macdef(void);
-void macexpand(Sym*, char*, int);
+int macexpand(Sym*, char*, int);
void macinc(void);
void macprag(void);
void maclin(void);
diff --git a/sys/src/cmd/5a/a.h b/sys/src/cmd/5a/a.h
index 5585b5f59..beb7f0c93 100644
--- a/sys/src/cmd/5a/a.h
+++ b/sys/src/cmd/5a/a.h
@@ -137,7 +137,7 @@ Sym* getsym(void);
void domacro(void);
void macund(void);
void macdef(void);
-void macexpand(Sym*, char*, int);
+int macexpand(Sym*, char*, int);
void macinc(void);
void maclin(void);
void macprag(void);
diff --git a/sys/src/cmd/6a/a.h b/sys/src/cmd/6a/a.h
index 08c23ee0d..f4b0cc90e 100644
--- a/sys/src/cmd/6a/a.h
+++ b/sys/src/cmd/6a/a.h
@@ -151,7 +151,7 @@ Sym* getsym(void);
void domacro(void);
void macund(void);
void macdef(void);
-void macexpand(Sym*, char*, int);
+int macexpand(Sym*, char*, int);
void macinc(void);
void macprag(void);
void maclin(void);
diff --git a/sys/src/cmd/7a/a.h b/sys/src/cmd/7a/a.h
index f60e7dac1..a0c3fa69f 100644
--- a/sys/src/cmd/7a/a.h
+++ b/sys/src/cmd/7a/a.h
@@ -143,7 +143,7 @@ Sym* getsym(void);
void domacro(void);
void macund(void);
void macdef(void);
-void macexpand(Sym*, char*, int);
+int macexpand(Sym*, char*, int);
void macinc(void);
void maclin(void);
void macprag(void);
diff --git a/sys/src/cmd/8a/a.h b/sys/src/cmd/8a/a.h
index 0bd5cbaf2..9a0124b7d 100644
--- a/sys/src/cmd/8a/a.h
+++ b/sys/src/cmd/8a/a.h
@@ -152,7 +152,7 @@ Sym* getsym(void);
void domacro(void);
void macund(void);
void macdef(void);
-void macexpand(Sym*, char*, int);
+int macexpand(Sym*, char*, int);
void macinc(void);
void macprag(void);
void maclin(void);
diff --git a/sys/src/cmd/cc/cc.h b/sys/src/cmd/cc/cc.h
index 357de549d..043719efe 100644
--- a/sys/src/cmd/cc/cc.h
+++ b/sys/src/cmd/cc/cc.h
@@ -556,7 +556,7 @@ void linehist(char*, int);
void macdef(void);
void macprag(void);
void macend(void);
-void macexpand(Sym*, char*, int);
+int macexpand(Sym*, char*, int);
void macif(int);
void macinc(void);
void maclin(void);
diff --git a/sys/src/cmd/cc/lex.c b/sys/src/cmd/cc/lex.c
index 7e9b11d3e..707fb0bac 100644
--- a/sys/src/cmd/cc/lex.c
+++ b/sys/src/cmd/cc/lex.c
@@ -755,18 +755,22 @@ talph:
if(s->macro) {
newio();
cp = ionext->b;
- macexpand(s, cp, sizeof(ionext->b)-1);
- pushio();
- ionext->link = iostack;
- iostack = ionext;
- fi.p = cp;
- fi.c = strlen(cp);
- if(peekc != IGN) {
- cp[fi.c++] = peekc;
- cp[fi.c] = 0;
- peekc = IGN;
+ if(macexpand(s, cp, sizeof(ionext->b)-1)){
+ pushio();
+ ionext->link = iostack;
+ iostack = ionext;
+ fi.p = cp;
+ fi.c = strlen(cp);
+ if(peekc != IGN) {
+ cp[fi.c++] = peekc;
+ cp[fi.c] = 0;
+ peekc = IGN;
+ }
+ goto l0;
+ } else {
+ ionext->link = iofree;
+ iofree = ionext;
}
- goto l0;
}
yylval.sym = s;
if(s->class == CTYPEDEF || s->class == CTYPESTR)
diff --git a/sys/src/cmd/cc/lexbody b/sys/src/cmd/cc/lexbody
index 7996c8ba1..0969c3c80 100644
--- a/sys/src/cmd/cc/lexbody
+++ b/sys/src/cmd/cc/lexbody
@@ -238,18 +238,22 @@ l1:
if(s->macro) {
newio();
cp = ionext->b;
- macexpand(s, cp, sizeof(ionext->b)-1);
- pushio();
- ionext->link = iostack;
- iostack = ionext;
- fi.p = cp;
- fi.c = strlen(cp);
- if(peekc != IGN) {
- cp[fi.c++] = peekc;
- cp[fi.c] = 0;
- peekc = IGN;
+ if(macexpand(s, cp, sizeof(ionext->b)-1)){
+ pushio();
+ ionext->link = iostack;
+ iostack = ionext;
+ fi.p = cp;
+ fi.c = strlen(cp);
+ if(peekc != IGN) {
+ cp[fi.c++] = peekc;
+ cp[fi.c] = 0;
+ peekc = IGN;
+ }
+ goto l0;
+ } else {
+ ionext->link = iofree;
+ iofree = ionext;
}
- goto l0;
}
if(s->type == 0)
s->type = LNAME;
diff --git a/sys/src/cmd/cc/macbody b/sys/src/cmd/cc/macbody
index 290660c22..5caf5b2c0 100644
--- a/sys/src/cmd/cc/macbody
+++ b/sys/src/cmd/cc/macbody
@@ -372,7 +372,7 @@ bad:
macend();
}
-void
+int
macexpand(Sym *s, char *b, int blen)
{
char buf[2000];
@@ -386,15 +386,17 @@ macexpand(Sym *s, char *b, int blen)
goto toobig;
if(debug['m'])
print("#expand %s %s\n", s->name, b);
- return;
+ return 1;
}
nargs = (char)(*s->macro & ~VARMAC) - 1;
dots = *s->macro & VARMAC;
c = getnsc();
- if(c != '(')
- goto bad;
+ if(c != '('){
+ unget(c);
+ return 0;
+ }
n = 0;
c = getc();
if(c != ')') {
@@ -490,7 +492,7 @@ macexpand(Sym *s, char *b, int blen)
if(n != nargs) {
yyerror("argument mismatch expanding: %s", s->name);
*b = 0;
- return;
+ return 0;
}
ob = b;
eb = b + blen-1;
@@ -526,16 +528,17 @@ macexpand(Sym *s, char *b, int blen)
*b = 0;
if(debug['m'])
print("#expand %s %s\n", s->name, ob);
- return;
+ return 1;
bad:
yyerror("syntax in macro expansion: %s", s->name);
*b = 0;
- return;
+ return 0;
toobig:
yyerror("too much text in macro expansion: %s", s->name);
*b = 0;
+ return 0;
}
void
diff --git a/sys/src/cmd/ka/a.h b/sys/src/cmd/ka/a.h
index cbac168d7..59f0e22dd 100644
--- a/sys/src/cmd/ka/a.h
+++ b/sys/src/cmd/ka/a.h
@@ -136,7 +136,7 @@ Sym* getsym(void);
void domacro(void);
void macund(void);
void macdef(void);
-void macexpand(Sym*, char*, int);
+int macexpand(Sym*, char*, int);
void macinc(void);
void macprag(void);
void maclin(void);
diff --git a/sys/src/cmd/qa/a.h b/sys/src/cmd/qa/a.h
index 24c3a1766..b92263900 100644
--- a/sys/src/cmd/qa/a.h
+++ b/sys/src/cmd/qa/a.h
@@ -138,7 +138,7 @@ Sym* getsym(void);
void domacro(void);
void macund(void);
void macdef(void);
-void macexpand(Sym*, char*, int);
+int macexpand(Sym*, char*, int);
void macinc(void);
void macprag(void);
void maclin(void);
diff --git a/sys/src/cmd/va/a.h b/sys/src/cmd/va/a.h
index 63bec8038..1c2b7c223 100644
--- a/sys/src/cmd/va/a.h
+++ b/sys/src/cmd/va/a.h
@@ -136,7 +136,7 @@ Sym* getsym(void);
void domacro(void);
void macund(void);
void macdef(void);
-void macexpand(Sym*, char*, int);
+int macexpand(Sym*, char*, int);
void macinc(void);
void maclin(void);
void macprag(void);