mirror of
git://repo.or.cz/tinycc.git
synced 2026-06-17 15:44:18 +08:00
No more ; needed
This commit is contained in:
parent
898f496dc9
commit
6547ea47d6
14
AGENTS.md
14
AGENTS.md
@ -38,3 +38,17 @@
|
||||
- Some tests need special flags (see `FLAGS =` assignments in `tests/tests2/Makefile`).
|
||||
- Bound-check tests (`-b` flag) are skipped when `CONFIG_bcheck=no`.
|
||||
- `.expect` files are generated with gcc by default; some use TCC (flagged with `GEN-TCC`).
|
||||
|
||||
## Language Extension: Optional Semicolons
|
||||
|
||||
Semicolons are optional after most statements and declarations:
|
||||
- `return`, `break`, `continue`, `goto`, expression statements
|
||||
- `do-while` trailing semicolon
|
||||
- Variable declarations
|
||||
|
||||
Semicolons are still **required** for:
|
||||
- `for()` loop init/condition/increment sections (e.g., `for(i=0; i<n; i++)`)
|
||||
- Old-style function parameter declarations
|
||||
- Struct/enum member declarations
|
||||
|
||||
The `skip(';')` function in `tccpp.c:100` errors if token doesn't match. Use `if (tok == ';') next();` instead to make semicolons optional.
|
||||
|
||||
22
tccgen.c
22
tccgen.c
@ -7205,7 +7205,7 @@ again:
|
||||
label_push(&local_label_stack, tok, LABEL_DECLARED);
|
||||
next();
|
||||
} while (tok == ',');
|
||||
skip(';');
|
||||
if (tok == ';') next();
|
||||
}
|
||||
|
||||
while (tok != '}') {
|
||||
@ -7241,7 +7241,7 @@ again:
|
||||
leave_scope(root_scope);
|
||||
if (b)
|
||||
gfunc_return(&func_vt);
|
||||
skip(';');
|
||||
if (tok == ';') next();
|
||||
/* jump unless last stmt in top-level block */
|
||||
if (tok != '}' || local_scope != 1)
|
||||
rsym = gjmp(rsym);
|
||||
@ -7258,7 +7258,7 @@ again:
|
||||
else
|
||||
leave_scope(loop_scope);
|
||||
*cur_scope->bsym = gjmp(*cur_scope->bsym);
|
||||
skip(';');
|
||||
if (tok == ';') next();
|
||||
|
||||
} else if (t == TOK_CONTINUE) {
|
||||
/* compute jump */
|
||||
@ -7266,7 +7266,7 @@ again:
|
||||
tcc_error("cannot continue");
|
||||
leave_scope(loop_scope);
|
||||
*cur_scope->csym = gjmp(*cur_scope->csym);
|
||||
skip(';');
|
||||
if (tok == ';') next();
|
||||
|
||||
} else if (t == TOK_FOR) {
|
||||
new_scope(&o);
|
||||
@ -7314,7 +7314,7 @@ again:
|
||||
gexpr();
|
||||
c = gvtst(0, 0);
|
||||
skip(')');
|
||||
skip(';');
|
||||
if (tok == ';') next();
|
||||
gsym_addr(c, d);
|
||||
gsym(a);
|
||||
prev_scope_s(&o);
|
||||
@ -7426,7 +7426,7 @@ again:
|
||||
} else {
|
||||
expect("label identifier");
|
||||
}
|
||||
skip(';');
|
||||
if (tok == ';') next();
|
||||
|
||||
} else if (t == TOK_ASM1 || t == TOK_ASM2 || t == TOK_ASM3) {
|
||||
asm_instr();
|
||||
@ -7481,7 +7481,7 @@ again:
|
||||
gexpr();
|
||||
vpop();
|
||||
}
|
||||
skip(';');
|
||||
if (tok == ';') next();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8637,7 +8637,7 @@ static void do_Static_assert(void)
|
||||
skip(')');
|
||||
if (c == 0)
|
||||
tcc_error("%s", msg);
|
||||
skip(';');
|
||||
if (tok == ';') next();
|
||||
}
|
||||
|
||||
#ifdef TCC_TARGET_PE
|
||||
@ -8718,6 +8718,10 @@ static int decl(int l)
|
||||
return 1;
|
||||
next();
|
||||
continue;
|
||||
} else if (l != VT_JMP && l != VT_CMP) {
|
||||
/* no semicolon - let caller handle it */
|
||||
} else {
|
||||
expect(";");
|
||||
}
|
||||
|
||||
while (1) { /* iterate thru each declaration */
|
||||
@ -8904,7 +8908,7 @@ static int decl(int l)
|
||||
if (tok != ',') {
|
||||
if (l == VT_JMP)
|
||||
return has_init ? v : 1;
|
||||
skip(';');
|
||||
if (tok == ';') next();
|
||||
break;
|
||||
}
|
||||
next();
|
||||
|
||||
@ -179,7 +179,7 @@ bar : 3 ; 3
|
||||
60_errors_and_warnings.c:372: error: statement expression outside of function
|
||||
|
||||
[test_invalid_tokckill]
|
||||
60_errors_and_warnings.c:375: error: ';' expected (got '3')
|
||||
60_errors_and_warnings.c:375: warning: function might return no value: 'f'
|
||||
|
||||
[test_duplicate_member]
|
||||
60_errors_and_warnings.c:381: error: duplicate member 'a'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user