From 62c5a5466ab19ef2c9ce3d88289549f19ae8fcb8 Mon Sep 17 00:00:00 2001 From: bellard Date: Sat, 3 Sep 2005 22:51:34 +0000 Subject: [PATCH] fixed parsing of function parameters --- tcc.c | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/tcc.c b/tcc.c index dd8d9f7b..76c19a56 100644 --- a/tcc.c +++ b/tcc.c @@ -6853,35 +6853,39 @@ static void post_type(CType *type, AttributeDef *ad) l = 0; first = NULL; plast = &first; - while (tok != ')') { - /* read param name and compute offset */ - if (l != FUNC_OLD) { - if (!parse_btype(&pt, &ad1)) { - if (l) { - error("invalid type"); - } else { - l = FUNC_OLD; - goto old_proto; + if (tok != ')') { + for(;;) { + /* read param name and compute offset */ + if (l != FUNC_OLD) { + if (!parse_btype(&pt, &ad1)) { + if (l) { + error("invalid type"); + } else { + l = FUNC_OLD; + goto old_proto; + } } + l = FUNC_NEW; + if ((pt.t & VT_BTYPE) == VT_VOID && tok == ')') + break; + type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT); + if ((pt.t & VT_BTYPE) == VT_VOID) + error("parameter declared as void"); + } else { + old_proto: + n = tok; + if (n < TOK_UIDENT) + expect("identifier"); + pt.t = VT_INT; + next(); } - l = FUNC_NEW; - if ((pt.t & VT_BTYPE) == VT_VOID && tok == ')') + convert_parameter_type(&pt); + s = sym_push(n | SYM_FIELD, &pt, 0, 0); + *plast = s; + plast = &s->next; + if (tok == ')') break; - type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT); - if ((pt.t & VT_BTYPE) == VT_VOID) - error("parameter declared as void"); - } else { - old_proto: - n = tok; - pt.t = VT_INT; - next(); - } - convert_parameter_type(&pt); - s = sym_push(n | SYM_FIELD, &pt, 0, 0); - *plast = s; - plast = &s->next; - if (tok == ',') { - next(); + skip(','); if (l == FUNC_NEW && tok == TOK_DOTS) { l = FUNC_ELLIPSIS; next(); -- 2.11.4.GIT