mirror of
https://github.com/mirror/tinycc.git
synced 2025-02-04 06:30:10 +08:00
revert last 3 commits. will find better way.
This commit is contained in:
parent
2d292e69a1
commit
b3a8eed49e
181
tccgen.c
181
tccgen.c
@ -3048,112 +3048,104 @@ static void asm_label_instr(CString *astr)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void post_type_array(CType *type, AttributeDef *ad);
|
static void post_type(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;
|
||||||
AttributeDef ad1;
|
AttributeDef ad1;
|
||||||
CType pt;
|
CType pt;
|
||||||
|
|
||||||
/* function declaration */
|
if (tok == '(') {
|
||||||
skip('(');
|
/* function declaration */
|
||||||
l = 0;
|
next();
|
||||||
first = NULL;
|
l = 0;
|
||||||
plast = &first;
|
first = NULL;
|
||||||
arg_size = 0;
|
plast = &first;
|
||||||
if (tok != ')') {
|
arg_size = 0;
|
||||||
for(;;) {
|
if (tok != ')') {
|
||||||
/* read param name and compute offset */
|
for(;;) {
|
||||||
if (l != FUNC_OLD) {
|
/* read param name and compute offset */
|
||||||
if (!parse_btype(&pt, &ad1)) {
|
if (l != FUNC_OLD) {
|
||||||
if (l) {
|
if (!parse_btype(&pt, &ad1)) {
|
||||||
error("invalid type");
|
if (l) {
|
||||||
} else {
|
error("invalid type");
|
||||||
l = FUNC_OLD;
|
} else {
|
||||||
goto old_proto;
|
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();
|
||||||
}
|
}
|
||||||
l = FUNC_NEW;
|
convert_parameter_type(&pt);
|
||||||
if ((pt.t & VT_BTYPE) == VT_VOID && tok == ')')
|
s = sym_push(n | SYM_FIELD, &pt, 0, 0);
|
||||||
|
*plast = s;
|
||||||
|
plast = &s->next;
|
||||||
|
if (tok == ')')
|
||||||
break;
|
break;
|
||||||
type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT);
|
skip(',');
|
||||||
if ((pt.t & VT_BTYPE) == VT_VOID)
|
if (l == FUNC_NEW && tok == TOK_DOTS) {
|
||||||
error("parameter declared as void");
|
l = FUNC_ELLIPSIS;
|
||||||
arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE;
|
next();
|
||||||
} else {
|
break;
|
||||||
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 no parameters, then old type prototype */
|
if (l == 0)
|
||||||
if (l == 0)
|
l = FUNC_OLD;
|
||||||
l = FUNC_OLD;
|
skip(')');
|
||||||
skip(')');
|
t1 = type->t & VT_STORAGE;
|
||||||
t1 = type->t & VT_STORAGE;
|
/* NOTE: const is ignored in returned type as it has a special
|
||||||
/* NOTE: const is ignored in returned type as it has a special
|
meaning in gcc / C++ */
|
||||||
meaning in gcc / C++ */
|
type->t &= ~(VT_STORAGE | VT_CONSTANT);
|
||||||
type->t &= ~(VT_STORAGE | VT_CONSTANT);
|
/* 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 == '[')
|
/* we push a anonymous symbol which will contain the function prototype */
|
||||||
post_type_array(type, ad);
|
ad->func_args = arg_size;
|
||||||
/* we push a anonymous symbol which will contain the function prototype */
|
s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
|
||||||
ad->func_args = arg_size;
|
s->next = first;
|
||||||
s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
|
type->t = t1 | VT_FUNC;
|
||||||
s->next = first;
|
type->ref = s;
|
||||||
type->t = t1 | VT_FUNC;
|
} else if (tok == '[') {
|
||||||
type->ref = s;
|
/* array definition */
|
||||||
}
|
|
||||||
|
|
||||||
static void post_type_array(CType *type, AttributeDef *ad)
|
|
||||||
{
|
|
||||||
int n, t1;
|
|
||||||
Sym *s;
|
|
||||||
|
|
||||||
/* array definition */
|
|
||||||
skip('[');
|
|
||||||
if (tok == TOK_RESTRICT1)
|
|
||||||
next();
|
next();
|
||||||
n = -1;
|
if (tok == TOK_RESTRICT1)
|
||||||
if (tok != ']') {
|
next();
|
||||||
n = expr_const();
|
n = -1;
|
||||||
if (n < 0)
|
if (tok != ']') {
|
||||||
error("invalid array size");
|
n = expr_const();
|
||||||
}
|
if (n < 0)
|
||||||
skip(']');
|
error("invalid array size");
|
||||||
/* parse next post type */
|
}
|
||||||
t1 = type->t & VT_STORAGE;
|
skip(']');
|
||||||
type->t &= ~VT_STORAGE;
|
/* parse next post type */
|
||||||
if (tok == '[')
|
t1 = type->t & VT_STORAGE;
|
||||||
post_type_array(type, ad);
|
type->t &= ~VT_STORAGE;
|
||||||
|
post_type(type, ad);
|
||||||
/* we push a anonymous symbol which will contain the array
|
|
||||||
element type */
|
/* we push a anonymous symbol which will contain the array
|
||||||
s = sym_push(SYM_FIELD, type, 0, n);
|
element type */
|
||||||
|
s = sym_push(SYM_FIELD, type, 0, n);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
ARRAY_RESIZE(s->r) = 1;
|
ARRAY_RESIZE(s->r) = 1;
|
||||||
type->t = t1 | VT_ARRAY | VT_PTR;
|
type->t = t1 | VT_ARRAY | VT_PTR;
|
||||||
type->ref = s;
|
type->ref = s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse a type declaration (except basic type), and return the type
|
/* Parse a type declaration (except basic type), and return the type
|
||||||
@ -3218,10 +3210,7 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td)
|
|||||||
*v = 0;
|
*v = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tok == '(')
|
post_type(type, ad);
|
||||||
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 New Issue
Block a user