Skip to content

Commit 9c00c59

Browse files
committed
Add mangling modifier 'as long|ulong alias "long"' for Win64
- minor code & whitespace clean-up, plus comments for this change
1 parent 8dade18 commit 9c00c59

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

src/compiler/parser-decl-symbtype.bas

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,26 +397,36 @@ private function cMangleModifier _
397397
( _
398398
) as integer
399399

400-
static as zstring * FB_MAXNAMELEN+1 aliasid
401400
function = FALSE
402401

402+
'' currently, cMangleModifier() returns true/false, because
403+
'' we are checking for one case only. And the FB_DATATYPE
404+
'' stored in the upper bits of the dtype in FB_DT_MANGLEMASK
405+
'' was selected for convenience. In future, it might be
406+
'' better to have a new FB_MANGLE_DATATYPE enum for tracking
407+
'' the desired mapping stored in the upper bits of the
408+
'' dtype, especially if there are some mappings that can't
409+
'' be found in existing FB_DATATYPE. To support additional
410+
'' checks and mappings, should probably pass a dtype
411+
'' parameter in to this procedure to be updated or returned.
412+
403413
'' ALIAS?
404414
if( lexGetToken( ) = FB_TK_ALIAS ) then
405415
lexSkipToken( )
406416

407-
'' "long"
417+
'' "long"?
408418
if( lexGetClass( ) = FB_TKCLASS_STRLITERAL ) then
409-
aliasid = *lexGetText( )
410-
lexSkipToken( )
411-
412-
select case lcase( aliasid )
419+
select case lcase( *lexGetText( ) )
413420
case "long"
421+
'' only Win64 is affected by ths modifer
414422
function = fbIs64bit( ) and ((env.target.options and FB_TARGETOPT_UNIX) = 0)
415423
case ""
416424
errReport( FB_ERRMSG_EMPTYALIASSTRING )
417425
case else
418426
errReport( FB_ERRMSG_SYNTAXERROR )
419427
end select
428+
429+
lexSkipToken( )
420430
else
421431
errReport( FB_ERRMSG_SYNTAXERROR )
422432
end if
@@ -706,7 +716,7 @@ function cSymbolType _
706716
dtype = FB_DATATYPE_UINT
707717

708718
case FB_DATATYPE_LONG
709-
if( typeIsMangleDt( dtype ) ) then
719+
if( typeHasMangleDt( dtype ) ) then
710720
dtype = typeSetMangleDt( FB_DATATYPE_ULONG, FB_DATATYPE_UINT )
711721
else
712722
dtype = FB_DATATYPE_ULONG

src/compiler/symb-mangling.bas

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ function hMangleBuiltInType _
366366
'' Windows 64bit
367367

368368
'' check for remapping of dtype mangling
369-
if( typeIsMangleDt( dtype ) ) then
369+
if( typeHasMangleDt( dtype ) ) then
370370
dtype = typeGetMangleDt( dtype )
371371
'' Windows 64bit
372372
select case( dtype )
@@ -390,6 +390,9 @@ function hMangleBuiltInType _
390390
end select
391391
end if
392392

393+
'' dtype should be a FB_DATATYPE by now
394+
assert( dtype = typeGetDtOnly( dtype ) )
395+
393396
static as zstring ptr typecodes(0 to FB_DATATYPES-1) => _
394397
{ _
395398
@"v", _ '' void

src/compiler/symb.bi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ const FB_DT_TYPEMASK = &b00000000000000000000000000011111 '' max 32 built-in d
5757
const FB_DT_PTRMASK = &b00000000000000000000000111100000 '' level of pointer indirection
5858
const FB_DT_CONSTMASK = &b00000000000000111111111000000000 '' PTRLEVELS + 1 bit-masks
5959
const FB_DATATYPE_REFERENCE = &b00000000000010000000000000000000 '' used for mangling BYREF parameters
60-
const FB_DT_MANGLEMASK = &b00000001111100000000000000000000 '' used to modify mangling for builtin types
60+
const FB_DT_MANGLEMASK = &b00000001111100000000000000000000 '' used to modify mangling for builtin types
6161
const FB_DATATYPE_INVALID = &b10000000000000000000000000000000
6262

6363
const FB_DT_PTRLEVELS = 8 '' max levels of pointer indirection
6464

6565
const FB_DT_PTRPOS = 5
6666
const FB_DT_CONSTPOS = FB_DT_PTRPOS + 4
6767

68-
const FB_DT_MANGLEPOS = 20
68+
const FB_DT_MANGLEPOS = 20
6969

7070
enum FB_OVLPROC_MATCH_SCORE
7171
FB_OVLPROC_NO_MATCH = 0
@@ -2495,7 +2495,7 @@ declare sub symbProcRecalcRealType( byval proc as FBSYMBOL ptr )
24952495
#define typeSetIsRef( dt ) (dt or FB_DATATYPE_REFERENCE)
24962496
#define typeUnsetIsRef( dt ) (dt and not FB_DATATYPE_REFERENCE)
24972497

2498-
#define typeIsMangleDt( dt ) (((dt and FB_DT_MANGLEMASK) <> 0))
2498+
#define typeHasMangleDt( dt ) (((dt and FB_DT_MANGLEMASK) <> 0))
24992499
#define typeGetMangleDt( dt ) ((dt and FB_DT_MANGLEMASK) shr FB_DT_MANGLEPOS)
25002500
#define typeSetMangleDt( dt, mangle_dt ) ((dt and not FB_DT_MANGLEMASK) or ((mangle_dt shl FB_DT_MANGLEPOS) and FB_DT_MANGLEMASK ))
25012501

tests/cpp/fbc-mangle.bas

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
'' by default, fbc's Long/ULong data type maps to c's int type, and since
77
'' Integer/Uinteger are meant to be (consistently) 64bits in fbc-64bit,
8-
'' there is no other type that (by default) that can map to c's long int,
8+
'' there is no other type that (by default) that can map to c's long int,
99
'' which is 32bit even on Win64.
1010

1111
'' So, in Win64, to allow calling an external library that needs a 'long int'
@@ -149,7 +149,7 @@ end scope
149149
scope
150150

151151
'' c = signed|unsigned int
152-
'' fb = [unsigned] long|integer
152+
'' fb = [unsigned] long
153153

154154
ASSERT( cpp_byval_uint(0) = 0 )
155155
ASSERT( cpp_byval_sint(0) = 0 )
@@ -170,7 +170,8 @@ end scope
170170
scope
171171

172172
'' c = signed|unsigned long int
173-
'' fb = [unsigned] long alias "long"
173+
'' fb = [unsigned] long alias "long" on Win64
174+
'' fb = [unsigned] integer on everything else
174175

175176
ASSERT( cpp_byval_ulongint(0) = 0 )
176177
ASSERT( cpp_byval_slongint(0) = 0 )

0 commit comments

Comments
 (0)