Skip to content

Commit 86bac49

Browse files
committed
fbc: don't allow CONST/ENUM between any SELECT & first CASE
- previously CONST and ENUM were being allowed between SELECT and CASE - probably because SELECT opens a new SCOPE and ENUM and CONST are symbol additions to the local scope For example, SELECT CASE x: CONST y = 1 : CASE ELSE : END SELECT - this change causes fbc to throw an error if CONST of ENUM are found between SELECT and CASE
1 parent b33ce2a commit 86bac49

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Version 1.09.0
3636
- rtlib: define fb_AtomicSetThreadFlags() even in the non-multithreaded version of run time library - it is needed by thread_core.c:threadproc() - unusual but not impossible to link the non-multithreaded rtlib and call thread functions
3737
- darwin: a variety of improvements to allow compiling and linking (TeeEmCee)
3838
- gfxlib2: fix d2d scaling issues for high dpi (adeyblue)
39-
- fbc: improve error message on statement between SELECT and first CASE inside a subroutine
39+
- fbc: improve error message on statement between SELECT and first CASE inside a subroutine and don't allow CONST/ENUM between any SELECT & first CASE.
4040

4141

4242
Version 1.08.0

src/compiler/parser-compound.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ function cCompStmtIsAllowed( byval allowmask as FB_CMPSTMT_MASK ) as integer
748748
end if
749749
end if
750750

751-
errReport( errmsg )
751+
errReportEx( errmsg, "" )
752752

753753
function = FALSE
754754
end function

src/compiler/parser-decl-const.bas

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'' constant (CONST) declarations
22
''
33
'' chng: sep/2004 written [v1ctor]
4+
'' chng: jul/2021 don't allow CONST between SELECT and CASE [jeffm]
45

56
#include once "fb.bi"
67
#include once "fbint.bi"
@@ -43,11 +44,11 @@ private sub cConstAssign _
4344
byval attrib as FB_SYMBATTRIB _
4445
)
4546

46-
static as zstring * FB_MAXNAMELEN+1 id
47+
static as zstring * FB_MAXNAMELEN+1 id
4748
dim as integer doskip = any, suffix = any
48-
dim as ASTNODE ptr expr = any
49-
dim as FBSYMBOL ptr litsym = any
50-
dim as FBVALUE value = any
49+
dim as ASTNODE ptr expr = any
50+
dim as FBSYMBOL ptr litsym = any
51+
dim as FBVALUE value = any
5152

5253
'' Namespace identifier if it matches the current namespace
5354
cCurrentParentId()
@@ -204,7 +205,7 @@ private sub cConstAssign _
204205
if( symbReuseOrAddConst( @id, dtype, subtype, astConstGetVal( expr ), attrib ) = NULL ) then
205206
errReportEx( FB_ERRMSG_DUPDEFINITION, id )
206207
end if
207-
end if
208+
end if
208209

209210
astDelNode( expr )
210211

@@ -216,10 +217,16 @@ end sub
216217

217218
'' ConstDecl = CONST (AS SymbolType)? ConstAssign (DECL_SEPARATOR ConstAssign)* .
218219
sub cConstDecl( byval attrib as FB_SYMBATTRIB )
219-
dim as integer dtype = any
220-
dim as FBSYMBOL ptr subtype = any
220+
dim as integer dtype = any
221+
dim as FBSYMBOL ptr subtype = any
222+
223+
'' CONST doesn't generate any code, but should not be allowed between SELECT and CASE
224+
if( cCompStmtIsAllowed( FB_CMPSTMT_MASK_DECL or FB_CMPSTMT_MASK_CODE ) = FALSE ) then
225+
hSkipStmt( )
226+
exit sub
227+
end if
221228

222-
'' CONST
229+
'' CONST
223230
lexSkipToken( LEXCHECK_POST_SUFFIX )
224231

225232
'' (AS SymbolType)?

src/compiler/parser-decl-enum.bas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'' enumerator (ENUM) declarations
22
''
33
'' chng: sep/2004 written [v1ctor]
4+
'' chng: jul/2021 don't allow ENUM between SELECT and CASE [jeffm]
45

56

67
#include once "fb.bi"
@@ -144,6 +145,13 @@ sub cEnumDecl( byval attrib as FB_SYMBATTRIB )
144145
static as zstring * FB_MAXNAMELEN+1 id
145146
dim as FBSYMBOL ptr e = any
146147

148+
'' ENUM doesn't generate any code, but should not be allowed between SELECT and CASE
149+
if( cCompStmtIsAllowed( FB_CMPSTMT_MASK_DECL or FB_CMPSTMT_MASK_CODE ) = FALSE ) then
150+
'' error recovery: skip the whole compound stmt
151+
hSkipCompound( FB_TK_ENUM )
152+
exit sub
153+
end if
154+
147155
'' ENUM
148156
lexSkipToken( LEXCHECK_POST_SUFFIX )
149157

0 commit comments

Comments
 (0)