diff options
| author | Claudio Bley <b_l_e_y@ml1.net> | 2010-06-21 11:57:32 +0200 |
|---|---|---|
| committer | Claudio Bley <b_l_e_y@ml1.net> | 2010-06-21 11:57:32 +0200 |
| commit | 433ecdfc9d1402ecf03e710de481e2063ad6de90 (patch) | |
| tree | ea1e05c5cd0194a7736ef4e94eaf2a7ae1b3cac3 | |
| parent | 632ee5a54076d417971ae7fa8a0c154441a71499 (diff) | |
| download | tinycc-433ecdfc9d1402ecf03e710de481e2063ad6de90.tar.gz tinycc-433ecdfc9d1402ecf03e710de481e2063ad6de90.tar.bz2 | |
implemented C99 for loop with variable declaration
| -rw-r--r-- | tccgen.c | 41 |
1 files changed, 37 insertions, 4 deletions
@@ -4291,14 +4291,28 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, next(); skip(';'); } else if (tok == TOK_FOR) { - int e; + int e, c99_for_decl = 0; next(); skip('('); if (tok != ';') { - gexpr(); - vpop(); + if (tok < TOK_UIDENT) { + // handle C99 for loop construct + c99_for_decl = 1; + + /* record local declaration stack position */ + s = local_stack; + + decl(VT_LOCAL); + if (is_expr) + vpop(); + } else { + gexpr(); + vpop(); + skip(';'); + } + } else { + skip(';'); } - skip(';'); d = ind; c = ind; a = 0; @@ -4321,6 +4335,25 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, gjmp_addr(c); gsym(a); gsym_addr(b, c); + + if (c99_for_decl) { + /* pop locally defined symbols */ + if(is_expr) { + /* XXX: this solution makes only valgrind happy... + triggered by gcc.c-torture/execute/20000917-1.c */ + Sym *p; + switch(vtop->type.t & VT_BTYPE) { + case VT_PTR: + case VT_STRUCT: + case VT_ENUM: + case VT_FUNC: + for(p=vtop->type.ref;p;p=p->prev) + if(p->prev==s) + error("unsupported expression type"); + } + } + sym_pop(&local_stack, s); + } } else if (tok == TOK_DO) { next(); |
