Skip to content

Commit 64d32f5

Browse files
committed
cast const ptr: refactor/remove unneeded code
- hSymbCheckConstAssignFuncPtr() can be private, and only checks the function pointer sub type. The top level check is called by symbCheckConstAssign() - only symbCheckConstAssign() now clears the error/warning message - symbCheckConstAssignTopLevel() still needed for now otherwise const warnings related to function pointer data types become errors
1 parent ca3a246 commit 64d32f5

File tree

3 files changed

+21
-43
lines changed

3 files changed

+21
-43
lines changed

src/compiler/symb-proc.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,7 @@ private function hCalcTypesDiff _
16761676
'' it's a DEREF or not (it can all be treated as string)
16771677
'' - disallow other args (passing BYVAL explicitly
16781678
'' should be handled by caller already)
1679-
select case( typeGetDtAndPtrOnly( param_dtype ) )
1679+
select case( param_dtype )
16801680
case FB_DATATYPE_CHAR
16811681
select case( arg_dtype )
16821682
case FB_DATATYPE_CHAR
@@ -2383,7 +2383,7 @@ private function hCheckCastOvl _
23832383
if( proc_subtype = to_subtype ) then
23842384

23852385
'' same const?
2386-
if( proc_subtype = to_subtype ) then
2386+
if( proc_dtype = to_dtype ) then
23872387
return FB_OVLPROC_FULLMATCH
23882388
end if
23892389

src/compiler/symb.bas

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,9 +1885,6 @@ function symbCheckConstAssignTopLevel _
18851885
dim as integer i = any, lcount = any, rcount = any, rmatches = any
18861886
dim as integer lconst = any, rconst = any
18871887

1888-
errmsg = 0
1889-
wrnmsg = 0
1890-
18911888
''
18921889
'' Toplevel const:
18931890
''
@@ -1925,14 +1922,9 @@ function symbCheckConstAssignTopLevel _
19251922
function = FALSE
19261923
matches = 0
19271924

1928-
'' neither is a function pointer?
1929-
if( ( typeGetDtOnly( ldType ) <> FB_DATATYPE_FUNCTION ) and ( typeGetDtOnly( rdType ) <> FB_DATATYPE_FUNCTION ) ) then
1930-
1931-
'' no consts? short-circuit
1932-
if( (typeGetConstMask( ldtype ) or typeGetConstMask( rdtype )) = 0 ) then
1933-
return TRUE
1934-
end if
1935-
1925+
'' no consts? short-circuit
1926+
if( (typeGetConstMask( ldtype ) or typeGetConstMask( rdtype )) = 0 ) then
1927+
return TRUE
19361928
end if
19371929

19381930
'' vararg? they aren't type safe anyway
@@ -1987,7 +1979,7 @@ function symbCheckConstAssignTopLevel _
19871979
function = TRUE
19881980
end function
19891981

1990-
function symbCheckConstAssignFuncPtr _
1982+
function hSymbCheckConstAssignFuncPtr _
19911983
( _
19921984
byval ldtype as FB_DATATYPE, _
19931985
byval rdtype as FB_DATATYPE, _
@@ -2005,19 +1997,12 @@ function symbCheckConstAssignFuncPtr _
20051997

20061998
function = FALSE
20071999

2008-
errmsg = FB_ERRMSG_OK '' FB_ERRMSG
2009-
wrnmsg = 0 '' FB_WARNINGMSG
20102000

20112001
assert( typeGetDtOnly( ldType ) = FB_DATATYPE_FUNCTION )
20122002
assert( typeGetDtOnly( rdType ) = FB_DATATYPE_FUNCTION )
20132003
assert( symbIsProc( lsubtype ) )
20142004
assert( symbIsProc( rsubtype ) )
20152005

2016-
'' not a function pointer?
2017-
if( ( typeGetDtOnly( ldType ) <> FB_DATATYPE_FUNCTION ) or ( typeGetDtOnly( rdType ) <> FB_DATATYPE_FUNCTION ) ) then
2018-
exit function
2019-
end if
2020-
20212006
'' Return warnings even though some checks are not CONSTness releated. We could
20222007
'' promote them to errors, but that will cause many tests to break, and really, we are
20232008
'' not specifically checking the assignment, but rather the function pointer compatibility.
@@ -2052,11 +2037,6 @@ function symbCheckConstAssignFuncPtr _
20522037
exit function
20532038
end if
20542039

2055-
'' check top level
2056-
if( symbCheckConstAssignTopLevel( ldtype, rdtype, lsubtype, rsubtype, mode, matches, errmsg, wrnmsg ) = FALSE ) then
2057-
exit function
2058-
end if
2059-
20602040
'' Check each parameter
20612041
var lparam = symbGetProcHeadParam( lsubtype )
20622042
var rparam = symbGetProcHeadParam( rsubtype )
@@ -2096,13 +2076,23 @@ function symbCheckConstAssign _
20962076
byref wrnmsg as FB_WARNINGMSG = 0 _
20972077
) as integer
20982078

2099-
'' both types function pointer?
2100-
if( ( typeGetDtOnly( ldType ) = FB_DATATYPE_FUNCTION ) and ( typeGetDtOnly( rdType ) = FB_DATATYPE_FUNCTION ) ) then
2101-
return symbCheckConstAssignFuncPtr( ldtype, rdtype, lsubtype, rsubtype, mode, matches, errmsg, wrnmsg )
2102-
else
2103-
return symbCheckConstAssignTopLevel( ldtype, rdtype, lsubtype, rsubtype, mode, matches, errmsg, wrnmsg )
2079+
dim ret as integer = any
2080+
2081+
errmsg = FB_ERRMSG_OK '' FB_ERRMSG
2082+
wrnmsg = 0 '' FB_WARNINGMSG
2083+
2084+
'' check top-level const
2085+
ret = symbCheckConstAssignTopLevel( ldtype, rdtype, lsubtype, rsubtype, mode, matches, errmsg, wrnmsg )
2086+
2087+
if( ret ) then
2088+
'' both types function pointer?
2089+
if( ( typeGetDtOnly( ldType ) = FB_DATATYPE_FUNCTION ) and ( typeGetDtOnly( rdType ) = FB_DATATYPE_FUNCTION ) ) then
2090+
ret and= hSymbCheckConstAssignFuncPtr( ldtype, rdtype, lsubtype, rsubtype, mode, matches, errmsg, wrnmsg )
2091+
end if
21042092
end if
21052093

2094+
function = ret
2095+
21062096
end function
21072097

21082098
private sub hForEachGlobal _

src/compiler/symb.bi

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,18 +1883,6 @@ declare function symbCheckConstAssignTopLevel _
18831883
byref wrnmsg as FB_WARNINGMSG = 0 _
18841884
) as integer
18851885

1886-
declare function symbCheckConstAssignFuncPtr _
1887-
( _
1888-
byval ldtype as FB_DATATYPE, _
1889-
byval rdtype as FB_DATATYPE, _
1890-
byval lsubtype as FBSYMBOL ptr, _
1891-
byval rsubtype as FBSYMBOL ptr, _
1892-
byval mode as FB_PARAMMODE = 0, _
1893-
byref matches as integer = 0, _
1894-
byref errmsg as FB_ERRMSG = 0, _
1895-
byref wrnmsg as FB_WARNINGMSG = 0 _
1896-
) as integer
1897-
18981886
declare function symbCheckConstAssign _
18991887
( _
19001888
byval ldtype as FB_DATATYPE, _

0 commit comments

Comments
 (0)