30 declare function hDoCppMangling(
byval sym
as FBSYMBOL
ptr )
as integer
31 declare sub hMangleProc(
byval sym
as FBSYMBOL
ptr )
35 byref mangled
as string, _
36 byval sym
as FBSYMBOL
ptr _
40 byref mangled
as string, _
41 byval ns
as FBSYMBOL
ptr, _
42 byval dohashing
as integer, _
43 byval isconst
as integer _
47 #define hIsNested(s) (symbGetNamespace( s ) <> @symbGetGlobalNamespc( ))
65 if( env.clopt.backend = FB_BACKEND_GCC )
then
79 if( env.clopt.backend = FB_BACKEND_GCC )
then
101 select case as const symbGetClass( sym )
103 case FB_SYMBCLASS_ENUM, FB_SYMBCLASS_STRUCT, _
104 FB_SYMBCLASS_CLASS, FB_SYMBCLASS_NAMESPACE
107 dim as zstring ptr res = sym->id.
alias
108 if( res = NULL )
then
120 function = sym->id.
name
123 sub symbSetName(
byval s
as FBSYMBOL
ptr,
byval name_
as zstring ptr )
124 dim as integer slen =
any
128 if( s->id.
name <> NULL )
then
136 s->id.
name =
poolNewItem( @symb.namepool, slen + 1 )
142 assert( sym->id.mangled = NULL )
143 sym->id.mangled = ZStrAllocate(
len( mangled ) )
144 *sym->id.mangled = mangled
149 if( sym->id.
alias )
then
150 mangled +=
str(
len( *sym->id.
alias ) )
151 mangled += *sym->id.
alias
153 mangled +=
str(
len( *sym->id.
name ) )
154 mangled += *sym->id.
name
159 if( sym->id.mangled )
then
160 return sym->id.mangled
163 select case as const( symbGetClass( sym ) )
164 case FB_SYMBCLASS_PROC
166 case FB_SYMBCLASS_ENUM, FB_SYMBCLASS_STRUCT, FB_SYMBCLASS_FWDREF, _
167 FB_SYMBCLASS_CLASS, FB_SYMBCLASS_NAMESPACE
168 dim as string mangled
171 if( hIsNested( sym ) )
then
175 case FB_SYMBCLASS_VAR
182 if( env.clopt.backend = FB_BACKEND_GCC )
then
183 if( fbLangOptIsSet( FB_LANG_OPT_PERIODS ) )
then
188 function = sym->id.mangled
203 byval dtype as integer, _
204 byval subtype as FBSYMBOL
ptr _
215 if( typeIsPtr(
dtype ) = FALSE )
then
216 if( typeGet(
dtype ) <> FB_DATATYPE_STRING )
then
224 do while( n <> NULL )
227 if( astGetFullType( n ) =
dtype )
then
240 byval dtype as integer, _
241 byval subtype as FBSYMBOL
ptr _
249 astGetFullType( n ) =
dtype
262 mangled +=
chr(
asc(
"0" ) + (
idx - 1) )
263 elseif(
idx <= 33 )
then
264 mangled +=
chr(
asc(
"A" ) + (
idx - 11) )
267 mangled +=
chr(
idx \ 33 )
270 mangled +=
chr(
asc(
"0" ) + (
idx - 1) )
271 elseif(
idx <= 33 )
then
272 mangled +=
chr(
asc(
"A" ) + (
idx - 11) )
286 if(
dtype = FB_DATATYPE_STRING )
then
290 if( fbCpuTypeIs64bit( ) )
then
315 if( env.target.options
and FB_TARGETOPT_UNIX )
then
317 case FB_DATATYPE_INTEGER :
return @
"l"
318 case FB_DATATYPE_UINT :
return @
"m"
322 case FB_DATATYPE_INTEGER :
return @
"u7INTEGER"
323 case FB_DATATYPE_UINT :
return @
"u8UINTEGER"
328 case FB_DATATYPE_LONG :
return @
"i"
329 case FB_DATATYPE_ULONG :
return @
"j"
333 case FB_DATATYPE_INTEGER :
return @
"i"
334 case FB_DATATYPE_UINT :
return @
"j"
335 case FB_DATATYPE_LONG :
return @
"l"
336 case FB_DATATYPE_ULONG :
return @
"m"
340 static as zstring ptr typecodes(0
to FB_DATATYPES-1) => _
368 assert( typecodes(
dtype) <> NULL )
369 function = typecodes(
dtype)
374 byref mangled
as string, _
375 byval dtype as integer, _
376 byval subtype as FBSYMBOL
ptr _
379 dim as FBSYMBOL
ptr ns =
any
391 if( typeGet(
dtype ) = FB_DATATYPE_FWDREF )
then
392 dtype = typeJoin(
dtype and (
not FB_DATATYPE_INVALID), FB_DATATYPE_STRUCT )
395 select case as const(
dtype )
396 case FB_DATATYPE_STRUCT, FB_DATATYPE_ENUM
397 ns = symbGetNamespace(
subtype )
398 if( ns = @symbGetGlobalNamespc( ) )
then
407 case FB_DATATYPE_NAMESPC
408 if(
subtype = @symbGetGlobalNamespc( ) )
then
412 ns = symbGetNamespace(
subtype )
418 case FB_DATATYPE_FUNCTION
423 if( symbProcReturnsByref(
subtype ) )
then
425 if( typeIsConst( symbGetFullType(
subtype ) ) )
then
432 if( typeIsConst( symbGetFullType(
subtype ) ) )
then
450 if( typeIsRef(
dtype ) )
then
452 if( typeIsConst(
dtype ) )
then
460 elseif( typeIsArray(
dtype ) )
then
465 elseif( typeIsPtr(
dtype ) )
then
467 if( typeIsConstAt(
dtype, 1 ) )
then
487 dim as integer dtype =
any
489 dtype = symbGetFullType( param )
491 select case as const( symbGetParamMode( param ) )
493 case FB_PARAMMODE_BYREF
496 case FB_PARAMMODE_BYDESC
500 case FB_PARAMMODE_VARARG
511 if( env.clopt.backend = FB_BACKEND_GCC )
then
515 function = ((env.target.options
and FB_TARGETOPT_UNDERSCORE) <> 0)
521 if( symbGetMangling( sym ) = FB_MANGLING_CPP )
then
526 if( (symbGetStats( sym )
and (FB_SYMBSTATS_RTL
or _
527 FB_SYMBSTATS_EXCLPARENT)) <> 0 )
then
532 if( symbGetNamespace( sym ) <> @symbGetGlobalNamespc( ) )
then
536 if( sym->
class = FB_SYMBCLASS_PROC )
then
538 if( symbIsOverloaded( sym ) )
then
548 byref mangled
as string, _
549 byval ns
as FBSYMBOL
ptr, _
550 byval dohashing
as integer, _
551 byval isconst
as integer _
554 static as FBSYMBOL
ptr nsStk(0
to FB_MAXNAMESPCRECLEVEL-1)
555 dim as integer tos =
any
561 if( ns = @symbGetGlobalNamespc( ) )
then
567 if(
hAbbrevFind( symbGetFullType( ns ), ns ) = -1 )
then
577 ns = symbGetNamespace( ns )
578 loop until( ns = @symbGetGlobalNamespc( ) )
589 loop until( tos < 0 )
594 static as integer varcounter
595 dim as string mangled
596 dim as zstring ptr p =
any
597 dim as integer docpp =
any, isglobal =
any
600 if( sym->
scope > FB_MAINSCOPE )
then
608 if( sym->attrib
and (FB_SYMBATTRIB_PUBLIC
or FB_SYMBATTRIB_EXTERN
or _
609 FB_SYMBATTRIB_SHARED
or FB_SYMBATTRIB_COMMON
or _
610 FB_SYMBATTRIB_STATIC) )
then
612 if( env.clopt.backend = FB_BACKEND_LLVM )
then
616 select case( env.clopt.target )
617 case FB_COMPTARGET_WIN32, FB_COMPTARGET_CYGWIN
620 if( (env.clopt.backend = FB_BACKEND_GAS)
and symbIsImport( sym ) )
then
636 if( sym->stats
and FB_SYMBSTATS_RTTITABLE )
then
638 elseif( sym->stats
and FB_SYMBSTATS_VTABLE )
then
644 if( env.clopt.backend = FB_BACKEND_LLVM )
then
658 if( sym->stats
and (FB_SYMBSTATS_RTTITABLE
or FB_SYMBSTATS_VTABLE) )
then
661 elseif( sym->stats
and FB_SYMBSTATS_HASALIAS )
then
666 isglobal = ((sym->attrib
and (FB_SYMBATTRIB_PUBLIC
or FB_SYMBATTRIB_EXTERN
or _
667 FB_SYMBATTRIB_SHARED
or FB_SYMBATTRIB_COMMON)) <> 0)
669 if( isglobal
or docpp )
then
671 if( symbGetMangling( sym ) = FB_MANGLING_BASIC )
then
673 if( env.clopt.backend = FB_BACKEND_GCC )
then
682 if( symbIsSuffixed( sym ) )
then
684 if( env.clopt.backend = FB_BACKEND_GCC )
then
689 select case( env.clopt.backend )
695 if( symbIsStatic( sym )
and symbHasDtor( sym ) )
then
698 if( symbGetMangling( sym ) = FB_MANGLING_BASIC )
then
707 if( symbIsSuffixed( sym ) )
then
720 id +=
str( sym->
scope )
727 if( symbGetMangling( sym ) = FB_MANGLING_BASIC )
then
732 if( symbIsSuffixed( sym ) )
then
739 id +=
"." +
str( varcounter )
746 if( symbIsStatic( sym ) )
then
749 id = *irProcGetFrameRegName( )
755 if(
len( id ) > 0 )
then
758 mangled +=
str(
len( id ) )
765 if( hIsNested( sym ) )
then
775 byref mangled
as string, _
776 byval sym
as FBSYMBOL
ptr _
779 dim as FBSYMBOL
ptr param =
any
780 dim as integer dtype =
any
782 param = symbGetProcHeadParam( sym )
783 if( param <> NULL )
then
785 if( symbIsParamInstance( param ) )
then
786 param = symbGetParamNext( param )
791 if( param = NULL )
then
800 param = symbGetParamNext( param )
816 select case as const symbGetProcOpOvl(
proc )
845 function = @
"v24idiv"
847 case AST_OP_INTDIV_SELF
848 function = @
"v28selfidiv"
873 case AST_OP_ANDALSO_SELF
879 case AST_OP_ORELSE_SELF
892 function = @
"v27selfeqv"
898 function = @
"v27selfimp"
916 function = @
"v27selfpow"
921 case AST_OP_CONCAT_SELF
922 function = @
"v27selfcat"
958 function = @
"v14frac"
976 function = @
"v14asin"
982 function = @
"v14acos"
990 case AST_OP_NEW, AST_OP_NEW_SELF
993 case AST_OP_NEW_VEC, AST_OP_NEW_VEC_SELF
996 case AST_OP_DEL, AST_OP_DEL_SELF
999 case AST_OP_DEL_VEC, AST_OP_DEL_VEC_SELF
1005 case AST_OP_FLDDEREF
1008 case AST_OP_PTRINDEX
1016 if( symbGetProcParams(
proc ) = 2 )
then
1017 function = @
"v13for"
1019 assert( symbGetProcParams(
proc ) = 1 )
1020 function = @
"v03for"
1025 if( symbGetProcParams(
proc ) = 2 )
then
1026 function = @
"v14step"
1028 assert( symbGetProcParams(
proc ) = 1 )
1029 function = @
"v04step"
1034 if( symbGetProcParams(
proc ) = 3 )
then
1035 function = @
"v24next"
1037 assert( symbGetProcParams(
proc ) = 2 )
1038 function = @
"v14next"
1045 dim as string mangled
1046 dim as integer length =
any, docpp =
any
1047 dim as zstring ptr id =
any
1054 if( env.clopt.backend = FB_BACKEND_LLVM )
then
1058 if( sym->
proc.mode = FB_FUNCMODE_STDCALL )
then
1076 hMangleNamespace( mangled, symbGetNamespace( sym ), TRUE, symbIsConstant( sym ) )
1080 if( (sym->stats
and FB_SYMBSTATS_HASALIAS) <> 0 )
then
1085 mangled +=
str(
len( *sym->id.
alias ) )
1088 mangled += *sym->id.
alias
1089 elseif( symbIsOperator( sym ) )
then
1090 if( symbGetProcOpOvl( sym ) = AST_OP_CAST )
then
1093 symbMangleType( mangled, symbGetFullType( sym ), symbGetSubtype( sym ) )
1097 elseif( symbIsConstructor( sym ) )
then
1099 elseif( symbIsDestructor( sym ) )
then
1102 if( symbGetMangling( sym ) = FB_MANGLING_BASIC )
then
1113 if( symbIsProperty( sym ) )
then
1116 mangled +=
str( length )
1121 if( symbIsProperty( sym ) )
then
1125 if( symbGetType( sym ) = FB_DATATYPE_VOID )
then
1126 mangled +=
"__set__"
1128 mangled +=
"__get__"
1136 if( hIsNested( sym ) )
then
1143 if( sym->
proc.mode = FB_FUNCMODE_STDCALL )
then
1145 if( env.clopt.backend <> FB_BACKEND_GCC )
then
1149 if( env.clopt.backend = FB_BACKEND_LLVM )
then