commit f080d87e480ee8914ffa45203d52e1da5612be57
parent 715c783aec3e86d3c00aa93d4439113479acd393
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 24 Oct 2022 19:28:12 +0200
cc1: Simplify logic of funbody
Diffstat:
1 file changed, 25 insertions(+), 18 deletions(-)
diff --git a/src/cmd/cc/cc1/decl.c b/src/cmd/cc/cc1/decl.c
@@ -490,6 +490,20 @@ ansifun(struct declarators *dp)
}
static int
+isfunbody(int tok)
+{
+ switch (tok) {
+ case '{':
+ case TYPE:
+ case SCLASS:
+ case TYPEIDEN:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static int
funbody(Symbol *sym, Symbol *pars[])
{
Type *tp;
@@ -502,29 +516,22 @@ funbody(Symbol *sym, Symbol *pars[])
if (tp->op != FTN)
return 0;
- switch (yytoken) {
- case '{':
- case TYPE:
- case SCLASS:
- case TYPEIDEN:
- if (curctx < PARAMCTX) {
- assert(!pars);
- errorp("typedef'ed function type cannot be instantiated");
- curctx = PARAMCTX;
- pars = emptypars;
- }
-
- if (curctx != PARAMCTX)
- errorp("nested function declaration");
-
- if (sym && sym->ns == NS_IDEN)
- break;
- default:
+ if (!isfunbody(yytoken) || sym->ns != NS_IDEN) {
emit(ODECL, sym);
endfundcl(tp, pars);
return 0;
}
+ if (curctx < PARAMCTX) {
+ assert(!pars);
+ errorp("typedef'ed function type cannot be instantiated");
+ curctx = PARAMCTX;
+ pars = emptypars;
+ }
+
+ if (curctx != PARAMCTX)
+ errorp("nested function declaration");
+
tp->prop |= TFUNDEF;
curfun = sym;
if (sym->type->prop & TK_R) {