Skip to content

Commit 9c0a15f

Browse files
committed
fbc: #pragma push( lookup108 ) for fbc-1.08.x unqualified symbol look ups
- this #pragma allows using an older method of symbol lookups - no guarantee that all lookups are identical to 1.08.x and earlier as they are several bugs fixed relating to symbol lookups and there may be related changes - this should allow users to compile older code a little easier - symbol lookup (with respect to namespaces and extended types) are continuing to be developed - the intent is to remove this #pragma in a future version
1 parent 012deb6 commit 9c0a15f

File tree

6 files changed

+102
-2
lines changed

6 files changed

+102
-2
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Version 1.09.0
5757
- sf.net #945, #948: improve error message for ambiguous symbol access to list all of the conflicted symbols
5858
- ./inc/fbc-int/array.bi - add fb.ArrayLen( array ) function to return total number of elements in an array
5959
- ./inc/fbc-int/array.bi - add fb.ArraySize( array ) function to return total size of an array in bytes
60+
- fbc: #pragma push( lookup108 ) to use symbol lookup method from fbc-1.08.x and earlier on unqualified symbol names
6061

6162
[fixed]
6263
- github #315: set parameters when calling SCREENCONTROL (was broken in fbc 1.08.0 due to new LONG/LONGINT SCREENCONTROL API's)

src/compiler/fb.bas

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ sub fbGlobalInit()
557557
env.clopt.gfx = FALSE
558558
env.clopt.pic = FALSE
559559
env.clopt.msbitfields = FALSE
560+
env.clopt.lookup108 = FALSE
560561
env.clopt.stacksize = 0 '' default will be set by fbSetOption() called from hParseArgs()
561562
env.clopt.objinfo = TRUE
562563
env.clopt.showincludes = FALSE
@@ -657,6 +658,8 @@ sub fbSetOption( byval opt as integer, byval value as integer )
657658
env.clopt.export = value
658659
case FB_COMPOPT_MSBITFIELDS
659660
env.clopt.msbitfields = value
661+
case FB_COMPOPT_LOOKUP108
662+
env.clopt.lookup108 = value
660663
case FB_COMPOPT_MULTITHREADED
661664
env.clopt.multithreaded = value
662665
case FB_COMPOPT_GFX
@@ -759,6 +762,8 @@ function fbGetOption( byval opt as integer ) as integer
759762
function = env.clopt.export
760763
case FB_COMPOPT_MSBITFIELDS
761764
function = env.clopt.msbitfields
765+
case FB_COMPOPT_LOOKUP108
766+
function = env.clopt.lookup108
762767
case FB_COMPOPT_MULTITHREADED
763768
function = env.clopt.multithreaded
764769
case FB_COMPOPT_GFX
@@ -784,7 +789,7 @@ end function
784789
'':::::
785790
sub fbChangeOption(byval opt as integer, byval value as integer)
786791
select case as const opt
787-
case FB_COMPOPT_MSBITFIELDS
792+
case FB_COMPOPT_MSBITFIELDS, FB_COMPOPT_LOOKUP108
788793
fbSetOption( opt, value )
789794

790795
case FB_COMPOPT_LANG

src/compiler/fb.bi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ enum FB_COMPOPT
100100
FB_COMPOPT_FBRT '' boolean: we are building or linking the fbrt library
101101
FB_COMPOPT_EXPORT '' boolean: export all symbols declared as EXPORT?
102102
FB_COMPOPT_MSBITFIELDS '' boolean: use M$'s bitfields packing?
103+
FB_COMPOPT_LOOKUP108 '' boolean: use old lookup rules fbc 1.08.x and earlier
103104
FB_COMPOPT_MULTITHREADED '' boolean: -mt
104105
FB_COMPOPT_GFX '' boolean: -gfx (whether gfxlib should be linked)
105106
FB_COMPOPT_PIC '' boolean: -pic (whether to use position-independent code)
@@ -303,6 +304,7 @@ type FBCMMLINEOPT
303304
fbrt as integer '' we are building or linking fbrt (default = false)
304305
export as integer '' export all symbols declared as EXPORT (default = true)
305306
msbitfields as integer '' use M$'s bitfields packing
307+
lookup108 as integer '' use old lookup rules fbc 1.08.x and earlier
306308
multithreaded as integer '' link against thread-safe runtime library (default = false)
307309
gfx as integer '' Link against gfx library (default = false)
308310
pic as integer '' Whether to use position-independent code (default = false)

src/compiler/pp-pragma.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ end type
3030

3131
enum LEXPP_PRAGMAOPT_ENUM
3232
LEXPP_PRAGMAOPT_BITFIELD
33+
LEXPP_PRAGMAOPT_LOOKUP108
3334
LEXPP_PRAGMAOPT_ONCE
3435
LEXPP_PRAGMAOPT_WARNCONSTNESS
3536
LEXPP_PRAGMAOPT_RESERVE
@@ -49,6 +50,7 @@ end type
4950
dim shared pragmaOpt(0 to LEXPP_PRAGMAS-1) as LEXPP_PRAGMAOPT => _
5051
{ _
5152
("msbitfields", FB_COMPOPT_MSBITFIELDS, LEXPP_PRAGMAFLAG_DEFAULT ), _
53+
("lookup108" , FB_COMPOPT_LOOKUP108 , LEXPP_PRAGMAFLAG_DEFAULT ), _
5254
("once" , 0 , LEXPP_PRAGMAFLAG_HAS_CALLBACK ), _
5355
("constness" , FB_PDCHECK_CONSTNESS , LEXPP_PRAGMAFLAG_PDCHECK or LEXPP_PRAGMAFLAG_DEFAULT ), _
5456
("reserve" , 0 , LEXPP_PRAGMAFLAG_HAS_CALLBACK ) _

src/compiler/symb.bas

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,79 @@ function symbNewChainpool _
869869

870870
end function
871871

872+
'':::::
873+
function symbLookup108 _
874+
( _
875+
byval id as zstring ptr, _
876+
byref tk as FB_TOKEN, _
877+
byref tk_class as FB_TKCLASS _
878+
) as FBSYMCHAIN ptr
879+
880+
static as zstring * FB_MAXNAMELEN+1 sname
881+
882+
'' assume it's an unknown identifier
883+
tk = FB_TK_ID
884+
tk_class = FB_TKCLASS_IDENTIFIER
885+
886+
hUcase( *id, sname )
887+
id = @sname
888+
889+
dim as uinteger index = hashHash( id )
890+
dim as FBSYMCHAIN ptr chain_ = NULL
891+
892+
'' for each nested hash tb, starting from last
893+
dim as FBHASHTB ptr hashtb = symb.hashlist.tail
894+
895+
do
896+
dim as FBSYMBOL ptr sym = hashLookupEx( @hashtb->tb, id, index )
897+
if( sym <> NULL ) then
898+
chain_ = chainpoolNext()
899+
900+
chain_->sym = sym
901+
chain_->next = NULL
902+
chain_->isimport = FALSE
903+
904+
if( sym->class = FB_SYMBCLASS_KEYWORD ) then
905+
tk = sym->key.id
906+
tk_class = sym->key.tkclass
907+
'' return if it's a KEYWORD or a OPERATOR token, they
908+
'' can't never be redefined, even inside namespaces
909+
if( tk_class <> FB_TKCLASS_QUIRKWD ) then
910+
return chain_
911+
end if
912+
end if
913+
914+
'' return if it's not the global ns (as in C++, any nested
915+
'' symbol has precedence over any imported one, even if the
916+
'' latter was imported in the current ns)
917+
if( hashtb->owner <> @symbGetGlobalNamespc( ) ) then
918+
return chain_
919+
else
920+
'' also if we are at the global ns, no need to check the imports
921+
if( symbGetCurrentNamespc( ) = @symbGetGlobalNamespc( ) ) then
922+
return chain_
923+
end if
924+
925+
'' check (and add) the imports..
926+
exit do
927+
end if
928+
end if
929+
930+
hashtb = hashtb->prev
931+
loop while( hashtb <> NULL )
932+
933+
'' now try the imported namespaces..
934+
dim as FBSYMCHAIN ptr imp_chain = hashLookupEx( @symb.imphashtb, id, index )
935+
if( chain_ = NULL ) then
936+
return imp_chain
937+
end if
938+
939+
chain_->next = imp_chain
940+
941+
return chain_
942+
943+
end function
944+
872945
'':::::
873946
function symbLookup _
874947
( _
@@ -918,6 +991,10 @@ function symbLookup _
918991
hashtb = hashtb->prev
919992
loop while( hashtb <> NULL )
920993

994+
'' use old lookup method from fbc 1.08.x and earlier?
995+
if( env.clopt.lookup108 ) then
996+
return symbLookup108( id, tk, tk_class )
997+
end if
921998
'' any symbol not in the global namespace or we are already in the global namespace?
922999
'' check the whole list before we check the imports
9231000
hashtb = symb.hashlist.tail
@@ -949,7 +1026,7 @@ function symbLookup _
9491026
if( imp_chain <> NULL ) then
9501027

9511028
if( firstglobal ) then
952-
'' If we have found both imports and a global, then check the import.
1029+
'' If we have found both imports and a global, then check the imports.
9531030
'' If the import is actually a member of an enum, then we'd prefer to
9541031
'' return the global instead. If the anonymous enum is not the first
9551032
'' listed in the chain, then assume that the symbFindBy*() calls will

tests/pp/pragma-lookup108.bas

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
' TEST_MODE : COMPILE_ONLY_OK
2+
3+
'' syntax check
4+
5+
#pragma push( lookup108 )
6+
#pragma push( lookup108, FALSE )
7+
#pragma push( lookup108, TRUE )
8+
#pragma pop( lookup108 )
9+
#pragma pop( lookup108 )
10+
#pragma pop( lookup108 )
11+
#pragma lookup108
12+
#pragma lookup108 = FALSE
13+
#pragma lookup108 = TRUE

0 commit comments

Comments
 (0)