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
1094ST_FUNC int expr_const(void);1094ST_FUNC int expr_const(void);
1095ST_FUNC void gen_inline_functions(void);1095ST_FUNC void gen_inline_functions(void);
1096ST_FUNC void decl(int l);1096ST_FUNC void decl(int l);
1097ST_FUNC void for_loop_init();
1097#if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C671098#if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
1098ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);1099ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
1099#endif1100#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
4376 next();4376 next();
4377 skip('(');4377 skip('(');
4378 if (tok != ';') {4378 if (tok != ';') {
4379 gexpr();4379 for_loop_init();
4380 vpop();
4381 }4380 }
4382 skip(';');4381 skip(';');
4383 d = ind;4382 d = ind;
@@ -5403,7 +5402,7 @@ ST_FUNC void gen_inline_functions(void) · 1019 unmodified lines
5403}5402}
5404 5403
5405/* 'l' is VT_LOCAL or VT_CONST to define default storage type */5404/* 'l' is VT_LOCAL or VT_CONST to define default storage type */
5406ST_FUNC void decl(int l)5405static void decl0(int l, int is_for_loop_init)
5407{5406{
5408 int v, has_init, r;5407 int v, has_init, r;
5409 CType type, btype;5408 CType type, btype;
@@ -5412,6 +5411,11 @@ ST_FUNC void decl(int l) · 2 unmodified lines
5412 5411
5413 while (1) {5412 while (1) {
5414 if (!parse_btype(&btype, &ad)) {5413 if (!parse_btype(&btype, &ad)) {
5414 if (is_for_loop_init) {
5415 gexpr();
5416 vpop();
5417 return;
5418 }
5415 /* skip redundant ';' */5419 /* skip redundant ';' */
5416 /* XXX: find more elegant solution */5420 /* XXX: find more elegant solution */
5417 if (tok == ';') {5421 if (tok == ';') {
@@ -5626,6 +5630,8 @@ ST_FUNC void decl(int l) · 208 unmodified lines
5626 }5630 }
5627 }5631 }
5628 if (tok != ',') {5632 if (tok != ',') {
5633 if (is_for_loop_init)
5634 return;
5629 skip(';');5635 skip(';');
5630 break;5636 break;
5631 }5637 }
@@ -5634,3 +5640,13 @@ ST_FUNC void decl(int l) · 2 unmodified lines
5634 }5640 }
5635 }5641 }
5636}5642}
5643
5644ST_FUNC void for_loop_init(void)
5645{
5646 decl0(VT_LOCAL, 1);
5647}
5648
5649ST_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
42# copy only tcclib.h so GCC's stddef and stdarg will be used42# copy only tcclib.h so GCC's stddef and stdarg will be used
43test.ref: tcctest.c43test.ref: tcctest.c
44 cp -u ../include/tcclib.h .44 cp -u ../include/tcclib.h .
45 $(CC) -o tcctest.gcc $< -I. -w $(CFLAGS)45 $(CC) -o tcctest.gcc $< -I. -w $(CFLAGS) -std=gnu99
46 ./tcctest.gcc > $@46 ./tcctest.gcc > $@
47 47
48# auto test48# auto test
tests/tcctest.c+4−0
@@ -387,6 +387,10 @@ void loop_test() · 386 unmodified lines
387 } while (i < 10);387 } while (i < 10);
388 printf("\n");388 printf("\n");
389 389
390 /* c99 for loop init test */
391 for (size_t count = 1; count < 3; count++)
392 printf("count=%d\n", count);
393
390 /* break/continue tests */394 /* break/continue tests */
391 i = 0;395 i = 0;
392 while (1) {396 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