aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-02-17 12:10:10 -0800
committerMichael Forney <mforney@mforney.org>2019-02-17 12:10:10 -0800
commit8f75d2840daf36870bee142709530586d138ce63 (patch)
treeacbc29590e8982a62b2ad5206a79f0694d5197f8
parent6e457e2a7da38bf5ea9779f30deb21dbb78f2ebd (diff)
downloadcproc-8f75d2840daf36870bee142709530586d138ce63.tar.xz
Only parse function definitions for function declarations
-rw-r--r--decl.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/decl.c b/decl.c
index 0e9c776..6fb74fc 100644
--- a/decl.c
+++ b/decl.c
@@ -849,21 +849,22 @@ decl(struct scope *s, struct function *f)
d->value = mkglobal(name, false);
scopeputdecl(s, name, d);
}
+ if (tok.kind == TLBRACE) {
+ if (!allowfunc)
+ error(&tok.loc, "function declaration not allowed");
+ if (d->defined)
+ error(&tok.loc, "function '%s' redefined", name);
+ s = mkscope(&filescope);
+ f = mkfunc(name, t, s);
+ stmt(f, s);
+ emitfunc(f, d->linkage == LINKEXTERN);
+ s = delscope(s);
+ d->defined = true;
+ return true;
+ }
break;
}
switch (tok.kind) {
- case TLBRACE:
- if (!allowfunc)
- error(&tok.loc, "function declaration not allowed");
- if (d->defined)
- error(&tok.loc, "function '%s' redefined", name);
- s = mkscope(&filescope);
- f = mkfunc(name, t, s);
- stmt(f, s);
- emitfunc(f, d->linkage == LINKEXTERN);
- s = delscope(s);
- d->defined = true;
- return true;
case TCOMMA:
next();
allowfunc = 0;