History

support c99 for-loop init decls

Joe Soroka committed 15 years ago

Commit e23194a1 parent 4fbe3cd4 files · +25 −4Browse files

Unified · Split

4 files
  1. tcc.h +1 −0
  2. tccgen.c +19 −3
  3. tests/Makefile +1 −1
  4. tests/tcctest.c +4 −0
tcc.h+1−0
@@ -1094,6 +1094,7 @@ ST_FUNC void gexpr(void); · 1093 unmodified lines
10941094 ST_FUNC int expr_const(void);
10951095 ST_FUNC void gen_inline_functions(void);
10961096 ST_FUNC void decl(int l);
1097+ST_FUNC void for_loop_init();
10971098 #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
10981099 ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
10991100 #endif
tccgen.c+19−3
@@ -4376,8 +4376,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 4375 unmodified lines
43764376 next();
43774377 skip('(');
43784378 if (tok != ';') {
4379− gexpr();
4380− vpop();
4379+ for_loop_init();
43814380 }
43824381 skip(';');
43834382 d = ind;
@@ -5403,7 +5402,7 @@ ST_FUNC void gen_inline_functions(void) · 1019 unmodified lines
54035402 }
54045403
54055404 /* 'l' is VT_LOCAL or VT_CONST to define default storage type */
5406−ST_FUNC void decl(int l)
5405+static void decl0(int l, int is_for_loop_init)
54075406 {
54085407 int v, has_init, r;
54095408 CType type, btype;
@@ -5412,6 +5411,11 @@ ST_FUNC void decl(int l) · 2 unmodified lines
54125411
54135412 while (1) {
54145413 if (!parse_btype(&btype, &ad)) {
5414+ if (is_for_loop_init) {
5415+ gexpr();
5416+ vpop();
5417+ return;
5418+ }
54155419 /* skip redundant ';' */
54165420 /* XXX: find more elegant solution */
54175421 if (tok == ';') {
@@ -5626,6 +5630,8 @@ ST_FUNC void decl(int l) · 208 unmodified lines
56265630 }
56275631 }
56285632 if (tok != ',') {
5633+ if (is_for_loop_init)
5634+ return;
56295635 skip(';');
56305636 break;
56315637 }
@@ -5634,3 +5640,13 @@ ST_FUNC void decl(int l) · 2 unmodified lines
56345640 }
56355641 }
56365642 }
5643+
5644+ST_FUNC void for_loop_init(void)
5645+{
5646+ decl0(VT_LOCAL, 1);
5647+}
5648+
5649+ST_FUNC void decl(int l)
5650+{
5651+ decl0(l, 0);
5652+}
tests/Makefile+1−1
@@ -42,7 +42,7 @@ libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC) · 41 unmodified lines
4242 # copy only tcclib.h so GCC's stddef and stdarg will be used
4343 test.ref: tcctest.c
4444 cp -u ../include/tcclib.h .
45− $(CC) -o tcctest.gcc $< -I. -w $(CFLAGS)
45+ $(CC) -o tcctest.gcc $< -I. -w $(CFLAGS) -std=gnu99
4646 ./tcctest.gcc > $@
4747
4848 # auto test
tests/tcctest.c+4−0
@@ -387,6 +387,10 @@ void loop_test() · 386 unmodified lines
387387 } while (i < 10);
388388 printf("\n");
389389
390+ /* c99 for loop init test */
391+ for (size_t count = 1; count < 3; count++)
392+ printf("count=%d\n", count);
393+
390394 /* break/continue tests */
391395 i = 0;
392396 while (1) {

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