mirror of
https://github.com/frida/tinycc
synced 2024-11-24 08:39:37 +03:00
some indentation made prev patch pretty; removed it
This commit is contained in:
parent
89059f94c0
commit
545a37b306
166
tccgen.c
166
tccgen.c
@ -3057,74 +3057,72 @@ static void post_type_args(CType *type, AttributeDef *ad)
|
||||
AttributeDef ad1;
|
||||
CType pt;
|
||||
|
||||
if (tok == '(') {
|
||||
/* function declaration */
|
||||
next();
|
||||
l = 0;
|
||||
first = NULL;
|
||||
plast = &first;
|
||||
arg_size = 0;
|
||||
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;
|
||||
}
|
||||
/* function declaration */
|
||||
next();
|
||||
l = 0;
|
||||
first = NULL;
|
||||
plast = &first;
|
||||
arg_size = 0;
|
||||
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");
|
||||
arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE;
|
||||
} else {
|
||||
old_proto:
|
||||
n = tok;
|
||||
if (n < TOK_UIDENT)
|
||||
expect("identifier");
|
||||
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 == ')')
|
||||
l = FUNC_NEW;
|
||||
if ((pt.t & VT_BTYPE) == VT_VOID && tok == ')')
|
||||
break;
|
||||
skip(',');
|
||||
if (l == FUNC_NEW && tok == TOK_DOTS) {
|
||||
l = FUNC_ELLIPSIS;
|
||||
next();
|
||||
break;
|
||||
}
|
||||
type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT);
|
||||
if ((pt.t & VT_BTYPE) == VT_VOID)
|
||||
error("parameter declared as void");
|
||||
arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE;
|
||||
} else {
|
||||
old_proto:
|
||||
n = tok;
|
||||
if (n < TOK_UIDENT)
|
||||
expect("identifier");
|
||||
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 == ')')
|
||||
break;
|
||||
skip(',');
|
||||
if (l == FUNC_NEW && tok == TOK_DOTS) {
|
||||
l = FUNC_ELLIPSIS;
|
||||
next();
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* if no parameters, then old type prototype */
|
||||
if (l == 0)
|
||||
l = FUNC_OLD;
|
||||
skip(')');
|
||||
t1 = type->t & VT_STORAGE;
|
||||
/* NOTE: const is ignored in returned type as it has a special
|
||||
meaning in gcc / C++ */
|
||||
type->t &= ~(VT_STORAGE | VT_CONSTANT);
|
||||
/* some ancient pre-K&R C allows a function to return an array
|
||||
and the array brackets to be put after the arguments, such
|
||||
that "int c()[]" means the same as "int[] c()" */
|
||||
if (tok == '[')
|
||||
post_type_array(type, ad);
|
||||
/* we push a anonymous symbol which will contain the function prototype */
|
||||
ad->func_args = arg_size;
|
||||
s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
|
||||
s->next = first;
|
||||
type->t = t1 | VT_FUNC;
|
||||
type->ref = s;
|
||||
}
|
||||
/* if no parameters, then old type prototype */
|
||||
if (l == 0)
|
||||
l = FUNC_OLD;
|
||||
skip(')');
|
||||
t1 = type->t & VT_STORAGE;
|
||||
/* NOTE: const is ignored in returned type as it has a special
|
||||
meaning in gcc / C++ */
|
||||
type->t &= ~(VT_STORAGE | VT_CONSTANT);
|
||||
/* some ancient pre-K&R C allows a function to return an array
|
||||
and the array brackets to be put after the arguments, such
|
||||
that "int c()[]" means the same as "int[] c()" */
|
||||
if (tok == '[')
|
||||
post_type_array(type, ad);
|
||||
/* we push a anonymous symbol which will contain the function prototype */
|
||||
ad->func_args = arg_size;
|
||||
s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
|
||||
s->next = first;
|
||||
type->t = t1 | VT_FUNC;
|
||||
type->ref = s;
|
||||
}
|
||||
|
||||
static void post_type_array(CType *type, AttributeDef *ad)
|
||||
@ -3132,32 +3130,30 @@ static void post_type_array(CType *type, AttributeDef *ad)
|
||||
int n, t1;
|
||||
Sym *s;
|
||||
|
||||
if (tok == '[') {
|
||||
/* array definition */
|
||||
/* array definition */
|
||||
next();
|
||||
if (tok == TOK_RESTRICT1)
|
||||
next();
|
||||
if (tok == TOK_RESTRICT1)
|
||||
next();
|
||||
n = -1;
|
||||
if (tok != ']') {
|
||||
n = expr_const();
|
||||
if (n < 0)
|
||||
error("invalid array size");
|
||||
}
|
||||
skip(']');
|
||||
/* parse next post type */
|
||||
t1 = type->t & VT_STORAGE;
|
||||
type->t &= ~VT_STORAGE;
|
||||
if (tok == '[')
|
||||
post_type_array(type, ad);
|
||||
|
||||
/* we push a anonymous symbol which will contain the array
|
||||
element type */
|
||||
s = sym_push(SYM_FIELD, type, 0, n);
|
||||
n = -1;
|
||||
if (tok != ']') {
|
||||
n = expr_const();
|
||||
if (n < 0)
|
||||
error("invalid array size");
|
||||
}
|
||||
skip(']');
|
||||
/* parse next post type */
|
||||
t1 = type->t & VT_STORAGE;
|
||||
type->t &= ~VT_STORAGE;
|
||||
if (tok == '[')
|
||||
post_type_array(type, ad);
|
||||
|
||||
/* we push a anonymous symbol which will contain the array
|
||||
element type */
|
||||
s = sym_push(SYM_FIELD, type, 0, n);
|
||||
if (n < 0)
|
||||
ARRAY_RESIZE(s->r) = 1;
|
||||
type->t = t1 | VT_ARRAY | VT_PTR;
|
||||
type->ref = s;
|
||||
}
|
||||
type->t = t1 | VT_ARRAY | VT_PTR;
|
||||
type->ref = s;
|
||||
}
|
||||
|
||||
/* Parse a type declaration (except basic type), and return the type
|
||||
|
Loading…
Reference in New Issue
Block a user