History

support c99 for-loop init decls (2nd attempt)

Joe Soroka committed 15 years ago

Commit 5eb82751 parent 7fc2eee1 file · +18 −3Browse files

Unified · Split

tccgen.c+18−3
@@ -76,6 +76,7 @@ static void parse_expr_type(CType *type); · 75 unmodified lines
7676 static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only);
7777 static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr);
7878 static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope);
79+static int decl0(int l, int is_for_loop_init);
7980 static void expr_eq(void);
8081 static void unary_type(CType *type);
8182 static int is_compatible_parameter_types(CType *type1, CType *type2);
@@ -4379,8 +4380,12 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 4297 unmodified lines
43794380 next();
43804381 skip('(');
43814382 if (tok != ';') {
4382− gexpr();
4383− vpop();
4383+ /* c99 for-loop init decl? */
4384+ if (!decl0(VT_LOCAL, 1)) {
4385+ /* no, regular for-loop init expr */
4386+ gexpr();
4387+ vpop();
4388+ }
43844389 }
43854390 skip(';');
43864391 d = ind;
@@ -5406,7 +5411,7 @@ ST_FUNC void gen_inline_functions(void) · 1019 unmodified lines
54065411 }
54075412
54085413 /* 'l' is VT_LOCAL or VT_CONST to define default storage type */
5409−ST_FUNC void decl(int l)
5414+static int decl0(int l, int is_for_loop_init)
54105415 {
54115416 int v, has_init, r;
54125417 CType type, btype;
@@ -5415,6 +5420,8 @@ ST_FUNC void decl(int l) · 2 unmodified lines
54155420
54165421 while (1) {
54175422 if (!parse_btype(&btype, &ad)) {
5423+ if (is_for_loop_init)
5424+ return 0;
54185425 /* skip redundant ';' */
54195426 /* XXX: find more elegant solution */
54205427 if (tok == ';') {
@@ -5629,6 +5636,8 @@ ST_FUNC void decl(int l) · 208 unmodified lines
56295636 }
56305637 }
56315638 if (tok != ',') {
5639+ if (is_for_loop_init)
5640+ return 1;
56325641 skip(';');
56335642 break;
56345643 }
@@ -5636,4 +5645,10 @@ ST_FUNC void decl(int l) · 1 unmodified line
56365645 }
56375646 }
56385647 }
5648+ return 0;
5649+}
5650+
5651+ST_FUNC void decl(int l)
5652+{
5653+ decl0(l, 0);
56395654 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t