aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
diff options
context:
space:
mode:
authorJoe Soroka <gits@joesoroka.com>2011-03-07 11:28:31 -0800
committerJoe Soroka <gits@joesoroka.com>2011-03-07 11:28:31 -0800
commite23194a1fa2ca176c9151964a2e035f36736e650 (patch)
tree69b7a5897b862211e76bff41e104ac421d188b87 /tccgen.c
parent4fbe3cda330e6ac307c37888777145e7526a7078 (diff)
downloadtinycc-e23194a1fa2ca176c9151964a2e035f36736e650.tar.gz
tinycc-e23194a1fa2ca176c9151964a2e035f36736e650.tar.bz2
support c99 for-loop init decls
Diffstat (limited to 'tccgen.c')
-rw-r--r--tccgen.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/tccgen.c b/tccgen.c
index 8a50832..32a2060 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -4376,8 +4376,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
next();
skip('(');
if (tok != ';') {
- gexpr();
- vpop();
+ for_loop_init();
}
skip(';');
d = ind;
@@ -5403,7 +5402,7 @@ ST_FUNC void gen_inline_functions(void)
}
/* 'l' is VT_LOCAL or VT_CONST to define default storage type */
-ST_FUNC void decl(int l)
+static void decl0(int l, int is_for_loop_init)
{
int v, has_init, r;
CType type, btype;
@@ -5412,6 +5411,11 @@ ST_FUNC void decl(int l)
while (1) {
if (!parse_btype(&btype, &ad)) {
+ if (is_for_loop_init) {
+ gexpr();
+ vpop();
+ return;
+ }
/* skip redundant ';' */
/* XXX: find more elegant solution */
if (tok == ';') {
@@ -5626,6 +5630,8 @@ ST_FUNC void decl(int l)
}
}
if (tok != ',') {
+ if (is_for_loop_init)
+ return;
skip(';');
break;
}
@@ -5634,3 +5640,13 @@ ST_FUNC void decl(int l)
}
}
}
+
+ST_FUNC void for_loop_init(void)
+{
+ decl0(VT_LOCAL, 1);
+}
+
+ST_FUNC void decl(int l)
+{
+ decl0(l, 0);
+}