commit 5b666be8a5986e9d7f82d7877b9678429bfb3d55
parent bab40c3565755c5caadec881f259947dd0dbafa2
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 25 Sep 2015 22:36:35 +0200
Add support for k&r empty functions
Functions without any parameter in a prototype are k&r
functions, or with other words, they are varargs functions.
Diffstat:
12 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/cc1/decl.c b/cc1/decl.c
@@ -189,17 +189,20 @@ static Symbol *dodcl(int rep,
static void
fundcl(struct declarators *dp)
{
- Type type = {.n = {.elem = -1}, .p = {.pars= NULL}};
- Symbol *syms[NR_FUNPARAM], **sp;
+ Type type;
+ Symbol *syms[NR_FUNPARAM], **sp = syms;
TINT size;
Symbol *pars = NULL;
pushctx();
expect('(');
+ type.n.elem = 0;
+ type.p.pars = NULL;
- if (!accept(')')) {
- type.n.elem = 0;
- sp = syms;
+ if (accept(')')) {
+ newpar(&type, ellipsistype);
+ *sp++ = NULL;
+ } else {
do {
if (!accept(ELLIPSIS)) {
*sp++ = dodcl(0, parameter, NS_IDEN, &type);
@@ -211,11 +214,10 @@ fundcl(struct declarators *dp)
} while (accept(','));
expect(')');
-
- if (type.n.elem != -1) {
- size = type.n.elem * sizeof(Symbol *);
- pars = memcpy(xmalloc(size), syms, size);
- }
+ }
+ if (type.n.elem != -1) {
+ size = type.n.elem * sizeof(Symbol *);
+ pars = memcpy(xmalloc(size), syms, size);
}
push(dp, FTN, type.n.elem, type.p.pars, pars);
}
diff --git a/cc1/tests/test004.c b/cc1/tests/test004.c
@@ -2,7 +2,7 @@
name: TEST004
description: Test integer operations
output:
-F1
+F1 E
G2 F1 main
{
\
diff --git a/cc1/tests/test005.c b/cc1/tests/test005.c
@@ -2,7 +2,7 @@
name: TEST005
description: Test unary integer operations
output:
-F1
+F1 E
G2 F1 main
{
\
diff --git a/cc1/tests/test006.c b/cc1/tests/test006.c
@@ -6,7 +6,7 @@ test006.c:6: warning: conditional expression is constant
test006.c:8: warning: conditional expression is constant
test006.c:11: warning: conditional expression is constant
G1 K c
-F2
+F2 E
G3 F2 main
{
\
diff --git a/cc1/tests/test007.c b/cc1/tests/test007.c
@@ -2,7 +2,7 @@
name: TEST007
description: basic while test
output:
-F1
+F1 E
G2 F1 main
{
\
diff --git a/cc1/tests/test008.c b/cc1/tests/test008.c
@@ -2,7 +2,7 @@
name: TEST008
description: Basic do while loop
output:
-F1
+F1 E
G2 F1 main
{
\
diff --git a/cc1/tests/test009.c b/cc1/tests/test009.c
@@ -2,7 +2,7 @@
name: TEST009
description: Basic test for loops
output:
-F1
+F1 E
G2 F1 main
{
\
diff --git a/cc1/tests/test010.c b/cc1/tests/test010.c
@@ -5,7 +5,7 @@ output:
test010.c:9: warning: conditional expression is constant
test010.c:11: warning: conditional expression is constant
test010.c:31: warning: conditional expression is constant
-F1
+F1 E
G2 F1 main
{
\
diff --git a/cc1/tests/test011.c b/cc1/tests/test011.c
@@ -4,7 +4,7 @@ description: Basic test for goto
output:
test011.c:14: warning: 'foo' defined but not used
test011.c:14: warning: 'start' defined but not used
-F1
+F1 E
G2 F1 main
{
\
diff --git a/cc1/tests/test012.c b/cc1/tests/test012.c
@@ -3,7 +3,7 @@ name: TEST012
description: Basic switch test
output:
test012.c:39: warning: 'foo' defined but not used
-F1
+F1 E
G2 F1 main
{
\
diff --git a/cc1/tests/test017.c b/cc1/tests/test017.c
@@ -2,7 +2,7 @@
name: TEST017
description: Basic test about pointers and structs
output:
-F9
+F9 E
G10 F9 main
{
\
diff --git a/cc1/tests/test018.c b/cc1/tests/test018.c
@@ -2,7 +2,7 @@
name: TEST018
description: Basic test for arrays
output:
-F1
+F1 E
G2 F1 main
{
\