summaryrefslogtreecommitdiffhomepage
path: root/src/checkauto.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/checkauto.l')
-rw-r--r--src/checkauto.l42
1 files changed, 15 insertions, 27 deletions
diff --git a/src/checkauto.l b/src/checkauto.l
index c42d97cf..b61c7cb3 100644
--- a/src/checkauto.l
+++ b/src/checkauto.l
@@ -1,4 +1,4 @@
-/* Check for illegal return/break/continue usage inside a STC-lib c_auto* block (RAII).
+/* Check for illegal return/break/continue usage inside a STC-lib c_AUTO* block (RAII).
* Copyright Tyge Løvset, (c) 2022.
*/
%{
@@ -53,7 +53,12 @@ c_with |
c_scope |
c_defer |
c_autodrop |
-c_auto { block_type = AUTO; state = BRACES; }
+c_auto |
+c_WITH |
+c_SCOPE |
+c_DEFER |
+c_AUTODROP |
+c_AUTO { block_type = AUTO; state = BRACES; }
\( { if (state == BRACES) ++braces_lev; }
\) { if (state == BRACES && --braces_lev == 0) {
state = BRACESDONE;
@@ -61,8 +66,8 @@ c_auto { block_type = AUTO; state = BRACES; }
}
if { if (state == BRACESDONE) {
if (block_type == AUTO) {
- printf("%s:%d: warning: 'if' after c_auto* not enclosed in curly braces.\n"
- " Make sure to enclose 'if - else' statement in { } after c_auto*.\n",
+ printf("%s:%d: warning: 'if' after c_AUTO* not enclosed in curly braces.\n"
+ " Make sure to enclose 'if - else' statement in { } after c_AUTO*.\n",
fname, yylineno);
++warnings;
}
@@ -78,41 +83,24 @@ if { if (state == BRACESDONE) {
\{ { if (state != BRACES) { block[++block_lev] = block_type; state = NORMAL; } }
\} { if (state != BRACES) block_type = block[--block_lev]; }
return { if (block_type == AUTO) {
- printf("%s:%d: error: 'return' used inside a c_auto* scope.\n"
- //" Use 'c_breakauto' to exit the current c_auto* scope.\n"
+ printf("%s:%d: error: 'return' used inside a c_AUTO* scope.\n"
+ " Use 'continue' to exit the current c_AUTO* scope before return.\n"
, fname, yylineno);
++errors;
} else if (block_type & AUTO) {
- printf("%s:%d: error: 'return' used in a loop inside a c_auto* scope.\n"
- //" Use 'break' to exit loops, then 'c_breakauto' to exit c_auto*.\n"
+ printf("%s:%d: error: 'return' used in a loop inside a c_AUTO* scope.\n"
+ " Use 'break' to exit loop, then 'continue' to exit c_AUTO*.\n"
, fname, yylineno);
++errors;
}
}
break { if (block_type == AUTO) {
- printf("%s:%d: error: 'break' used inside a c_auto* scope.\n"
- //" Use 'c_breakauto' to exit the current c_auto* scope.\n"
+ printf("%s:%d: error: 'break' used inside a c_AUTO* scope.\n"
+ " Use 'continue' to exit the current c_AUTO* scope.\n"
, fname, yylineno);
++errors;
}
}
-continue { if (block_type == AUTO) {
- printf("%s:%d: warning: 'continue' used inside a c_auto* scope.\n"
- " It will only break out of the current c_auto* scope.\n"
- //" Use 'c_breakauto' instead to make it explicit.\n"
- , fname, yylineno);
- ++warnings;
- }
- }
-c_breakauto { if (block_type != AUTO) {
- /*
- printf("%s:%d: warning: 'c_breakauto' used outside a c_auto* scope.\n"
- " Did you mean 'continue' instead?"
- , fname, yylineno);
- ++warnings;
- */
- }
- }
{ID} ;
\n ++yylineno;
. ;