ref: 354c8d23f2900601d620f23138b6dc433bb22f7d
parent: aafa864b25db5f16d6b49f96b0aaa96661dc5b08
author: Quentin Rameau <quinq@fifth.space>
date: Thu Jan 19 12:13:29 EST 2017
[cpp] add support for C99 for-loop declaration
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -96,7 +96,7 @@
For(Symbol *lbreak, Symbol *lcont, Switch *lswitch)
{
Symbol *begin, *cond;
- Node *econd, *einc, *einit;
+ Node *econd, *einc, *einit = NULL;
begin = newlabel();
lcont = newlabel();
@@ -103,10 +103,23 @@
cond = newlabel();
lbreak = newlabel();
+ pushctx();
+
expect(FOR);
expect('(');
- einit = (yytoken != ';') ? expr() : NULL;
- expect(';');
+ switch (yytoken) {
+ case TYPE:
+ case TYPEIDEN:
+ case TQUALIFIER:
+ case SCLASS:
+ decl();
+ break;
+ default:
+ einit = expr();
+ case ';':
+ expect(';');
+ break;
+ }
econd = (yytoken != ';') ? condexpr() : NULL;
expect(';');
einc = (yytoken != ')') ? expr() : NULL;
@@ -126,6 +139,8 @@
emit(OELOOP, NULL);
emit(OLABEL, lbreak);
+
+ popctx();
}
static void