History

c2y if declaration (std n3356)

standart is here: https://www.open-std.org/JTC1/SC22/WG14/www/docs/n3356.htm This feature should not add bug to existing features, as it is called only if there is a declaration in a switch or an if.

Matthias Gatto committed 1 year ago

Commit f52b4801 parent 80e70401 file · +34 −5Browse files

Unified · Split

tccgen.c+34−5
@@ -7051,6 +7051,31 @@ static void lblock(int *bsym, int *csym) · 7050 unmodified lines
70517051 }
70527052 }
70537053
7054+static void condition_expresion(void)
7055+{
7056+ Sym *s;
7057+ int decl_ret;
7058+
7059+ /* c2y if init decl? */
7060+ if (!(decl_ret = decl(VT_JMPI))) {
7061+ /* no, regular if init expr */
7062+ gexpr();
7063+ } else {
7064+ if (decl_ret == 1)
7065+ tcc_error("declaration in the controlling expression must have an initializer");
7066+
7067+ if (tok == ';') {
7068+ /* finish the push */
7069+ next();
7070+ gexpr();
7071+ } else {
7072+ s = sym_find(decl_ret);
7073+ vset(&s->type, s->r, s->c);
7074+ vtop->sym = s;
7075+ }
7076+ }
7077+}
7078+
70547079 static void block(int flags)
70557080 {
70567081 int a, b, c, d, e, t;
@@ -7071,7 +7096,7 @@ again: · 14 unmodified lines
70717096 if (t == TOK_IF) {
70727097 new_scope_s(&o);
70737098 skip('(');
7074− gexpr();
7099+ condition_expresion();
70757100 a = gvtst(1, 0);
70767101 skip(')');
70777102 block(0);
@@ -7240,7 +7265,7 @@ again: · 162 unmodified lines
72407265
72417266 new_scope_s(&o);
72427267 skip('(');
7243− gexpr();
7268+ condition_expresion();
72447269 if (!is_integer_btype(vtop->type.t & VT_BTYPE))
72457270 tcc_error("switch value not an integer");
72467271 skip(')');
@@ -8562,7 +8587,9 @@ static void pe_check_linkage(CType *type, AttributeDef *ad) · 1315 unmodified lines
85628587
85638588 /* 'l' is VT_LOCAL or VT_CONST to define default storage type
85648589 or VT_CMP if parsing old style parameter list
8565− or VT_JMP if parsing c99 for decl: for (int i = 0, ...) */
8590+ or VT_JMP if parsing c99 for decl: for (int i = 0, ...)
8591+ or VT_JMPI if parsing c2y if decl; if (int = 0; ...)
8592+*/
85668593 static int decl(int l)
85678594 {
85688595 int v, has_init, r, oldint;
@@ -8575,7 +8602,7 @@ static int decl(int l) · 6 unmodified lines
85758602
85768603 oldint = 0;
85778604 if (!parse_btype(&btype, &adbase, l == VT_LOCAL)) {
8578− if (l == VT_JMP)
8605+ if (l == VT_JMP || l == VT_JMPI)
85798606 return 0;
85808607 /* skip redundant ';' if not in old parameter decl scope */
85818608 if (tok == ';' && l != VT_CMP) {
@@ -8815,10 +8842,12 @@ static int decl(int l) · 233 unmodified lines
88158842 }
88168843 }
88178844 if (tok != ',') {
8818− if (l == VT_JMP)
8845+ if (l == VT_JMP || l == VT_JMPI)
88198846 return has_init ? v : 1;
88208847 skip(';');
88218848 break;
8849+ } else if (l == VT_JMPI) {
8850+ tcc_error("declaration in condition can only declare a single object");
88228851 }
88238852 next();
88248853 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t