Skip to content

Commit 16b8e94

Browse files
committed
fbc/emscripten: allow wchar conversion on win32 for development
- add 'enum FB_WCHARCONV' - replace 'env.wchar_doconv' with 'env.wcharconv as FB_WCHARCONV' - when compiler is built with __FB_DEBUG__<>0 then allow wstring conversions even though the host wchar size and target wchar size are different - purpose of this is to allow some building and testing with the test-suite on a win32 host while also not having deal with all unicode/wchar issues
1 parent c9fcb5d commit 16b8e94

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Version 1.10.1
22

33
[changed]
4+
- emscripten/fbc: in debug version of fbc (__FB_DEBUG__<>0) allow wchar conversion on win32 host to allow building and testing of the test-suite
45

56
[added]
67
- fbc: '-fbgfx' command line option to link against correct libfbgfx variant, for platforms (emscripten) where it's not automatic due to missing objinfo support

src/compiler/ast-node-bop.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ function astNewBOP _
869869
if( litsym <> NULL ) then
870870
'' ok to convert at compile-time?
871871
if( (typeGetDtAndPtrOnly( ldtype ) = typeGetDtAndPtrOnly( rdtype )) or _
872-
env.wchar_doconv ) then
872+
(env.wcharconv <> FB_WCHARCONV_NEVER) ) then
873873
return hWstrLiteralConcat( l, r )
874874
end if
875875
end if

src/compiler/fb.bas

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,22 @@ sub fbInit _
474474
irInit( )
475475

476476
'' After symbInit(), we can use typeGetSize()
477-
env.wchar_doconv = (sizeof( wstring ) = typeGetSize( env.target.wchar ))
477+
if( sizeof( wstring ) = typeGetSize( env.target.wchar ) ) then
478+
env.wcharconv = FB_WCHARCONV_ALWAYS
479+
else
480+
env.wcharconv = FB_WCHARCONV_NEVER
481+
end if
482+
483+
#if ( __FB_DEBUG__ <> 0 ) andalso defined( __FB_WIN32__ )
484+
select case( env.clopt.target )
485+
case FB_COMPTARGET_JS
486+
'' !!!TODO!!! - FB_WCHARCONV_WARNING needs to show warnings on conversions
487+
'' !!!TODO!!! - FB_WCHARCONV_WARNING probably not correct to force a value
488+
'' but setting it helps with development and testing
489+
'' where sizeof(host-wstring) <> sizeof(target-wstring)
490+
env.wcharconv = FB_WCHARCONV_WARNING
491+
end select
492+
#endif
478493

479494
hashInit( @env.filenamehash, FB_INITINCFILES )
480495
hashInit( @env.incfilehash, FB_INITINCFILES, FALSE )

src/compiler/fbint.bi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,12 @@ enum FB_TARGETOPT
571571
FB_TARGETOPT_MACHO = &h00000200
572572
end enum
573573

574+
enum FB_WCHARCONV
575+
FB_WCHARCONV_NEVER = 0
576+
FB_WCHARCONV_WARNING = 1
577+
FB_WCHARCONV_ALWAYS = 2
578+
end enum
579+
574580
type FBTARGET
575581
id as zstring ptr
576582
wchar as FB_DATATYPE '' Real wstring data type
@@ -614,7 +620,7 @@ type FBENV
614620

615621
clopt as FBCMMLINEOPT '' cmm-line options
616622
target as FBTARGET '' target specific
617-
wchar_doconv as integer '' ok to convert literals at compile-time?
623+
wcharconv as FB_WCHARCONV '' ok to convert literals at compile-time?
618624
underscoreprefix as integer '' Whether ASM symbols need a leading underscore on the current target
619625
pointersize as integer
620626

src/compiler/parser-quirk-string.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ private function cStrASC() as ASTNODE ptr
288288
if( litsym <> NULL ) then
289289
'' if wstring, check if compile-time conversion can be done
290290
if( (astGetDataType( expr1 ) = FB_DATATYPE_WCHAR) and _
291-
(env.wchar_doconv = FALSE) ) then
291+
(env.wcharconv = FB_WCHARCONV_NEVER) ) then
292292
p = -1
293293
else
294294
'' pos is an constant too?

src/compiler/rtl-string.bas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,9 +2873,9 @@ function rtlToStr _
28732873
if( dtype = FB_DATATYPE_WCHAR ) then
28742874
litsym = astGetStrLitSymbol( expr )
28752875
if( litsym <> NULL ) then
2876-
if( env.wchar_doconv ) then
2876+
if( env.wcharconv <> FB_WCHARCONV_NEVER ) then
28772877
litsym = symbAllocStrConst( str( *symbGetVarLitTextW( litsym ) ), _
2878-
symbGetWstrLen( litsym ) - 1 )
2878+
symbGetWstrLen( litsym ) - 1 )
28792879

28802880
return astNewVAR( litsym )
28812881
end if
@@ -2978,9 +2978,9 @@ function rtlToWstr _
29782978
if( dtype = FB_DATATYPE_CHAR ) then
29792979
litsym = astGetStrLitSymbol( expr )
29802980
if( litsym <> NULL ) then
2981-
if( env.wchar_doconv ) then
2981+
if( env.wcharconv <> FB_WCHARCONV_NEVER ) then
29822982
litsym = symbAllocWstrConst( wstr( *symbGetVarLitText( litsym ) ), _
2983-
symbGetStrLen( litsym ) - 1 )
2983+
symbGetStrLen( litsym ) - 1 )
29842984
return astNewVAR( litsym )
29852985
end if
29862986
end if

0 commit comments

Comments
 (0)