[hackers] [scc] Add support for k&r empty functions || Roberto E. Vargas Caballero
commit 5b666be8a5986e9d7f82d7877b9678429bfb3d55
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Sep 25 22:36:35 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Sep 25 22:38:52 2015 +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.
diff --git a/cc1/decl.c b/cc1/decl.c
index a5761d1..611873f 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -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);
_AT_@ -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
index b410489..b8ce250 100644
--- a/cc1/tests/test004.c
+++ b/cc1/tests/test004.c
_AT_@ -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
index 92f949d..0676f62 100644
--- a/cc1/tests/test005.c
+++ b/cc1/tests/test005.c
_AT_@ -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
index 110e45d..d90966c 100644
--- a/cc1/tests/test006.c
+++ b/cc1/tests/test006.c
_AT_@ -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
index 8a0946b..a8d7913 100644
--- a/cc1/tests/test007.c
+++ b/cc1/tests/test007.c
_AT_@ -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
index dd073ee..ed747bf 100644
--- a/cc1/tests/test008.c
+++ b/cc1/tests/test008.c
_AT_@ -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
index c3ee1c7..d166415 100644
--- a/cc1/tests/test009.c
+++ b/cc1/tests/test009.c
_AT_@ -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
index f5f5705..1ced38d 100644
--- a/cc1/tests/test010.c
+++ b/cc1/tests/test010.c
_AT_@ -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
index 4a511ad..62617ff 100644
--- a/cc1/tests/test011.c
+++ b/cc1/tests/test011.c
_AT_@ -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
index 32ce7c9..be311c0 100644
--- a/cc1/tests/test012.c
+++ b/cc1/tests/test012.c
_AT_@ -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
index 6667633..858a652 100644
--- a/cc1/tests/test017.c
+++ b/cc1/tests/test017.c
_AT_@ -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
index 9b3dd7b..d8afe9a 100644
--- a/cc1/tests/test018.c
+++ b/cc1/tests/test018.c
_AT_@ -2,7 +2,7 @@
name: TEST018
description: Basic test for arrays
output:
-F1
+F1 E
G2 F1 main
{
\
Received on Fri Sep 25 2015 - 22:39:12 CEST
This archive was generated by hypermail 2.3.0
: Fri Sep 25 2015 - 22:48:10 CEST