scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit f4f53c76d3704a8c458c2cc861e73fdd6f9f84ea
parent fea243a2851d05bb1036a542e4ef1aa714a87570
Author: Quentin Rameau <quinq@fifth.space>
Date:   Thu, 19 Jan 2017 17:13:29 +0100

[cpp] add support for C99 for-loop declaration

Diffstat:
Mcc1/stmt.c | 21++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -96,17 +96,30 @@ static void For(Symbol *lbreak, Symbol *lcont, Switch *lswitch) { Symbol *begin, *cond; - Node *econd, *einc, *einit; + Node *econd, *einc, *einit = NULL; begin = newlabel(); lcont = newlabel(); 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 @@ For(Symbol *lbreak, Symbol *lcont, Switch *lswitch) emit(OELOOP, NULL); emit(OLABEL, lbreak); + + popctx(); } static void