refactor post_type() to be explicit about its recursion
This commit is contained in:
parent
772b302187
commit
89059f94c0
1 changed files with 20 additions and 5 deletions
25
tccgen.c
25
tccgen.c
|
@ -3048,7 +3048,9 @@ static void asm_label_instr(CString *astr)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void post_type(CType *type, AttributeDef *ad)
|
static void post_type_array(CType *type, AttributeDef *ad);
|
||||||
|
|
||||||
|
static void post_type_args(CType *type, AttributeDef *ad)
|
||||||
{
|
{
|
||||||
int n, l, t1, arg_size, align;
|
int n, l, t1, arg_size, align;
|
||||||
Sym **plast, *s, *first;
|
Sym **plast, *s, *first;
|
||||||
|
@ -3114,14 +3116,23 @@ static void post_type(CType *type, AttributeDef *ad)
|
||||||
/* some ancient pre-K&R C allows a function to return an array
|
/* some ancient pre-K&R C allows a function to return an array
|
||||||
and the array brackets to be put after the arguments, such
|
and the array brackets to be put after the arguments, such
|
||||||
that "int c()[]" means the same as "int[] c()" */
|
that "int c()[]" means the same as "int[] c()" */
|
||||||
post_type(type, ad);
|
if (tok == '[')
|
||||||
|
post_type_array(type, ad);
|
||||||
/* we push a anonymous symbol which will contain the function prototype */
|
/* we push a anonymous symbol which will contain the function prototype */
|
||||||
ad->func_args = arg_size;
|
ad->func_args = arg_size;
|
||||||
s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
|
s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
|
||||||
s->next = first;
|
s->next = first;
|
||||||
type->t = t1 | VT_FUNC;
|
type->t = t1 | VT_FUNC;
|
||||||
type->ref = s;
|
type->ref = s;
|
||||||
} else if (tok == '[') {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void post_type_array(CType *type, AttributeDef *ad)
|
||||||
|
{
|
||||||
|
int n, t1;
|
||||||
|
Sym *s;
|
||||||
|
|
||||||
|
if (tok == '[') {
|
||||||
/* array definition */
|
/* array definition */
|
||||||
next();
|
next();
|
||||||
if (tok == TOK_RESTRICT1)
|
if (tok == TOK_RESTRICT1)
|
||||||
|
@ -3136,7 +3147,8 @@ static void post_type(CType *type, AttributeDef *ad)
|
||||||
/* parse next post type */
|
/* parse next post type */
|
||||||
t1 = type->t & VT_STORAGE;
|
t1 = type->t & VT_STORAGE;
|
||||||
type->t &= ~VT_STORAGE;
|
type->t &= ~VT_STORAGE;
|
||||||
post_type(type, ad);
|
if (tok == '[')
|
||||||
|
post_type_array(type, ad);
|
||||||
|
|
||||||
/* we push a anonymous symbol which will contain the array
|
/* we push a anonymous symbol which will contain the array
|
||||||
element type */
|
element type */
|
||||||
|
@ -3210,7 +3222,10 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td)
|
||||||
*v = 0;
|
*v = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post_type(type, ad);
|
if (tok == '(')
|
||||||
|
post_type_args(type, ad);
|
||||||
|
else if (tok == '[')
|
||||||
|
post_type_array(type, ad);
|
||||||
if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2)
|
if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2)
|
||||||
parse_attribute(ad);
|
parse_attribute(ad);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue