X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/94b775009e7dd4a876db03fa631a2188a699e791..4251b4bd0087752ceddbf95a6a8c928ab2207844:/src/parse-decl.c diff --git a/src/parse-decl.c b/src/parse-decl.c index f156ba9..3137859 100644 --- a/src/parse-decl.c +++ b/src/parse-decl.c @@ -254,58 +254,52 @@ simplify_functions(struct cdecl_declarator **p, struct cdecl_declarator *d) * simplify_functions pass. */ -static int -reduce_parentheses(struct cdecl_declarator **p, struct cdecl_declarator *d) +static struct cdecl *fake_function_param(struct cdecl_declarator *d) { struct cdecl *param; if (d->type != CDECL_DECL_FUNCTION) - return 0; + return NULL; param = d->u.function.parameters; - if (param && param->specifiers == NULL) { - struct cdecl_declarator *decl; + if (!param || param->specifiers) + return NULL; - assert(!param->next); + assert(!param->next); + return param; +} - decl = param->declarators; - if (decl->type == CDECL_DECL_NULL) { - free(decl); - free(param); - d->u.function.parameters = NULL; - return 0; - } +static int +reduce_parentheses(struct cdecl_declarator **p, struct cdecl_declarator *d) +{ + struct cdecl *param; + int fake = 0; + + while ((param = fake_function_param(d))) { + struct cdecl_declarator *decl = param->declarators; + d->u.function.parameters = NULL; + + if (decl->type != CDECL_DECL_NULL) { + if (d->child->type != CDECL_DECL_NULL) { + /* Found fake parameter on real function. */ + d->u.function.parameters = param; + cdecl__errmsg(CDECL__EBADPARAM); + return -1; + } - if (d->child->type != CDECL_DECL_NULL) { - cdecl__errmsg(CDECL__EBADPARAM); - return -1; + param->declarators = d; + *p = d = decl; + fake = 1; } - free(d->child); - free(param); - free(d); - *p = decl; - - /* - * We may have replaced d with another fake function which - * also needs to be eliminated. - */ - if (reduce_parentheses(p, decl) < 0) - return -1; - - /* - * If the remaining declarator is a function, make sure it's - * valid by checking its reducibility. - */ - decl = *p; - if (decl->type == CDECL_DECL_FUNCTION - && decl->child->type == CDECL_DECL_NULL - && !function_is_reducible(decl)) { - cdecl__errmsg(CDECL__EMANYPAREN); - return -1; - } + cdecl__free(param); + } - return 0; + simplify_functions(p, d); + if (fake && (*p)->type == CDECL_DECL_FUNCTION) { + /* Started with a fake function but ended with a real one. */ + cdecl__errmsg(CDECL__EMANYPAREN); + return -1; } return 0; @@ -512,8 +506,6 @@ static int do_postprocess(struct cdecl *decl, int english_mode) if (!english_mode) { if (forall_declarators(i, reduce_parentheses) < 0) return 0; - if (forall_declarators(i, simplify_functions) < 0) - return 0; } if (forall_declarators(i, postproc_common) < 0) @@ -522,8 +514,8 @@ static int do_postprocess(struct cdecl *decl, int english_mode) if (!valid_declspecs(i, true)) return 0; - if (cdecl_is_abstract(i->declarators) - && (i != decl || i->next)) { + if (decl->next && cdecl_is_abstract(i->declarators)) { + /* Abstract full declarators: there can only be one. */ cdecl__errmsg(CDECL__EDECLTYPE); return 0; }