[hackers] [scc] [cpp] add support for C99 for-loop declaration || Quentin Rameau

From: <git_AT_suckless.org>
Date: Fri, 20 Jan 2017 15:28:12 +0100 (CET)

commit f4f53c76d3704a8c458c2cc861e73fdd6f9f84ea
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Thu Jan 19 17:13:29 2017 +0100
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Fri Jan 20 15:05:19 2017 +0100

    [cpp] add support for C99 for-loop declaration

diff --git a/cc1/stmt.c b/cc1/stmt.c
index 3c7b907..095329a 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
_AT_@ -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;
_AT_@ -126,6 +139,8 @@ For(Symbol *lbreak, Symbol *lcont, Switch *lswitch)
         emit(OELOOP, NULL);
 
         emit(OLABEL, lbreak);
+
+ popctx();
 }
 
 static void
Received on Fri Jan 20 2017 - 15:28:12 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 20 2017 - 15:36:16 CET