support c99 for-loop init decls (2nd attempt)
This commit is contained in:
parent
7fc2eee55c
commit
5eb82755db
1 changed files with 18 additions and 3 deletions
17
tccgen.c
17
tccgen.c
|
@ -76,6 +76,7 @@ static void parse_expr_type(CType *type);
|
||||||
static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only);
|
static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only);
|
||||||
static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr);
|
static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr);
|
||||||
static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope);
|
static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope);
|
||||||
|
static int decl0(int l, int is_for_loop_init);
|
||||||
static void expr_eq(void);
|
static void expr_eq(void);
|
||||||
static void unary_type(CType *type);
|
static void unary_type(CType *type);
|
||||||
static int is_compatible_parameter_types(CType *type1, CType *type2);
|
static int is_compatible_parameter_types(CType *type1, CType *type2);
|
||||||
|
@ -4379,9 +4380,13 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
|
||||||
next();
|
next();
|
||||||
skip('(');
|
skip('(');
|
||||||
if (tok != ';') {
|
if (tok != ';') {
|
||||||
|
/* c99 for-loop init decl? */
|
||||||
|
if (!decl0(VT_LOCAL, 1)) {
|
||||||
|
/* no, regular for-loop init expr */
|
||||||
gexpr();
|
gexpr();
|
||||||
vpop();
|
vpop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
skip(';');
|
skip(';');
|
||||||
d = ind;
|
d = ind;
|
||||||
c = ind;
|
c = ind;
|
||||||
|
@ -5406,7 +5411,7 @@ ST_FUNC void gen_inline_functions(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 'l' is VT_LOCAL or VT_CONST to define default storage type */
|
/* 'l' is VT_LOCAL or VT_CONST to define default storage type */
|
||||||
ST_FUNC void decl(int l)
|
static int decl0(int l, int is_for_loop_init)
|
||||||
{
|
{
|
||||||
int v, has_init, r;
|
int v, has_init, r;
|
||||||
CType type, btype;
|
CType type, btype;
|
||||||
|
@ -5415,6 +5420,8 @@ ST_FUNC void decl(int l)
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!parse_btype(&btype, &ad)) {
|
if (!parse_btype(&btype, &ad)) {
|
||||||
|
if (is_for_loop_init)
|
||||||
|
return 0;
|
||||||
/* skip redundant ';' */
|
/* skip redundant ';' */
|
||||||
/* XXX: find more elegant solution */
|
/* XXX: find more elegant solution */
|
||||||
if (tok == ';') {
|
if (tok == ';') {
|
||||||
|
@ -5629,6 +5636,8 @@ ST_FUNC void decl(int l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tok != ',') {
|
if (tok != ',') {
|
||||||
|
if (is_for_loop_init)
|
||||||
|
return 1;
|
||||||
skip(';');
|
skip(';');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -5636,4 +5645,10 @@ ST_FUNC void decl(int l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ST_FUNC void decl(int l)
|
||||||
|
{
|
||||||
|
decl0(l, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue