Skip to content

Commit

Permalink
fbc: internal: rename three symbGet*() functions
Browse files Browse the repository at this point in the history
- Rename symbGenLen() to symbGetSizeOf() since this is clearer as
  to the intent of the function giving the size of the container
  including null terminators if it's a string
- rename symbGetStrLen() to symbGetStrLength() to help ensure that
  all instance of use are reviewed and convert the #define to a
  function since we will want to have some logic on this calculation
  in a future commit
- rename symbGetWstrLength() to symbGetWstrLength(), to help ensure that
  all instance of use are reviewed and convert the #define to a
  function since we may want to have some logic on this calculation

Removed:
  #define symbGetLen( s )
  #define symbGetStrLen(s)
  #define symbGetWstrLen(s)

Added:
  #define symbGetSizeOf( s )
  declare function symbGetStrLength( byval sym as FBSYMBOL ptr ) as longint
  declare function symbGetWstrLength( byval sym as FBSYMBOL ptr ) as longint
  • Loading branch information
jayrm committed Feb 24, 2024
1 parent 5defea5 commit 427a659
Show file tree
Hide file tree
Showing 33 changed files with 116 additions and 95 deletions.
6 changes: 3 additions & 3 deletions src/compiler/ast-helper.bas
Expand Up @@ -278,7 +278,7 @@ function astBuildTempVarClear( byval sym as FBSYMBOL ptr ) as ASTNODE ptr

'' Clear variable's memory
function = astNewMEM( AST_OP_MEMCLEAR, astNewVAR( sym ), _
astNewCONSTi( symbGetLen( sym ) ) )
astNewCONSTi( symbGetSizeOf( sym ) ) )
end function

''
Expand Down Expand Up @@ -889,7 +889,7 @@ function astBuildArrayDescIniTree _
elm = symbGetNext( elm )

'' .element_len = len( array )
astTypeIniAddAssign( tree, astNewCONSTi( symbGetLen( array ) ), elm )
astTypeIniAddAssign( tree, astNewCONSTi( symbGetSizeOf( array ) ), elm )

elm = symbGetNext( elm )

Expand Down Expand Up @@ -957,7 +957,7 @@ function astBuildArrayDescIniTree _
end if
assert( dimensions > 0 )
assert( symbDescriptorHasRoomFor( desc, dimensions ) )
astTypeIniAddPad( tree, dimensions * symbGetLen( symb.fbarraydim ) )
astTypeIniAddPad( tree, dimensions * symbGetSizeOf( symb.fbarraydim ) )
end if

astTypeIniScopeEnd( tree, dimtbfield )
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ast-misc.bas
Expand Up @@ -1291,7 +1291,7 @@ function astSizeOf( byval n as ASTNODE ptr, byref is_fixlenstr as integer ) as l
case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR, FB_DATATYPE_FIXSTR
if( n->sym ) then
is_fixlenstr = TRUE
function = symbGetLen( n->sym )
function = symbGetSizeOf( n->sym )
end if
end select
end function
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ast-node-arg.bas
Expand Up @@ -619,7 +619,7 @@ private sub hByteByByte( byval param as FBSYMBOL ptr, byval n as ASTNODE ptr )
'' UDT in memory, push byte-by-byte, by setting ASTNODE.arg.lgt,
'' telling irEmitPUSHARG() to push this arg to stack byte-by-byte.
'' Note: No rounding, to prevent overruns in the ASM
n->arg.lgt = symbGetLen( symbGetSubtype( param ) )
n->arg.lgt = symbGetSizeOf( symbGetSubtype( param ) )
end sub

private sub hUDTPassByval _
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/ast-node-assign.bas
Expand Up @@ -413,7 +413,7 @@ private function hShallowCopy _

'' How much to copy must depend on the possibly-casted lhs, since that's
'' what we're writing into, and we don't want a buffer overflow.
bytestocopy = symbGetLen( l->subtype )
bytestocopy = symbGetSizeOf( l->subtype )
has_vptr = symbGetHasRTTI( l->subtype )

'' Need to remove casts before doing ADDROF or passing to astNewMEM().
Expand Down Expand Up @@ -538,7 +538,7 @@ function astNewASSIGN _
else
result = astNewMEM( AST_OP_MEMCLEAR, _
astCloneTree( l ), _
astNewCONSTi( symbGetLen( l->subtype ) ) )
astNewCONSTi( symbGetSizeOf( l->subtype ) ) )
end if
else
result = NULL
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/ast-node-bop.bas
Expand Up @@ -23,9 +23,9 @@ private function hStrLiteralConcat _
ls = astGetSymbol( l )
rs = astGetSymbol( r )

'' new len = both strings' len less the 2 null-chars
'' new len = both strings - symbGetStrLength() handles the null terminator chars
s = symbAllocStrConst( *symbGetVarLitText( ls ) + *symbGetVarLitText( rs ), _
symbGetStrLen( ls ) - 1 + symbGetStrLen( rs ) - 1 )
symbGetStrLength( ls ) + symbGetStrLength( rs ) )

function = astNewVAR( s )

Expand All @@ -49,15 +49,15 @@ private function hWstrLiteralConcat _
if( symbGetType( ls ) <> FB_DATATYPE_WCHAR ) then
'' new len = both strings' len less the 2 null-chars
s = symbAllocWstrConst( wstr( *symbGetVarLitText( ls ) ) + *symbGetVarLitTextW( rs ), _
symbGetStrLen( ls ) - 1 + symbGetWstrLen( rs ) - 1 )
symbGetStrLength( ls ) + symbGetWstrLength( rs ) )

elseif( symbGetType( rs ) <> FB_DATATYPE_WCHAR ) then
s = symbAllocWstrConst( *symbGetVarLitTextW( ls ) + wstr( *symbGetVarLitText( rs ) ), _
symbGetWstrLen( ls ) - 1 + symbGetStrLen( rs ) - 1 )
symbGetWstrLength( ls ) + symbGetStrLength( rs ) )

else
s = symbAllocWstrConst( *symbGetVarLitTextW( ls ) + *symbGetVarLitTextW( rs ), _
symbGetWstrLen( ls ) - 1 + symbGetWstrLen( rs ) - 1 )
symbGetWstrLength( ls ) + symbGetWstrLength( rs ) )
end if

function = astNewVAR( s )
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/ast-node-data.bas
Expand Up @@ -123,12 +123,12 @@ sub astDataStmtEnd( byval tree as ASTNODE ptr )

select case n->data.id
case FB_DATASTMT_ID_ZSTR
id = symbGetStrLen( astGetStrLitSymbol( expr ) ) - 1
id = symbGetStrLength( astGetStrLitSymbol( expr ) )
expr = astNewADDROF( expr )

case FB_DATASTMT_ID_WSTR
id = FB_DATASTMT_ID_WSTR + _
(symbGetWstrLen( astGetStrLitSymbol( expr ) ) - 1)
(symbGetWstrLength( astGetStrLitSymbol( expr ) ) )
expr = astNewADDROF( expr )

case FB_DATASTMT_ID_CONST
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ast-node-decl.bas
Expand Up @@ -79,7 +79,7 @@ private function hDefaultInit( byval sym as FBSYMBOL ptr ) as ASTNODE ptr
end if

function = astNewMEM( AST_OP_MEMCLEAR, astNewVAR( sym ), _
astNewCONSTi( symbGetLen( sym ) * symbGetArrayElements( sym ) ) )
astNewCONSTi( symbGetSizeOf( sym ) * symbGetArrayElements( sym ) ) )
end function

function astNewDECL _
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ast-node-misc.bas
Expand Up @@ -346,7 +346,7 @@ function astNewFIELD _
if( typeGetDtAndPtrOnly( dtype ) = FB_DATATYPE_BOOLEAN ) then
'' !!!TODO!!! check for other sizes of BOOLEAN bitfield containers?
'' final type is always a signed int
select case symbGetLen( sym )
select case symbGetSizeOf( sym )
case 1
dtype = typeJoin( dtype, FB_DATATYPE_BYTE )
case else
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/ast-node-proc.bas
Expand Up @@ -922,15 +922,15 @@ private function hCallCtorList _
fldexpr = astBuildVarField( this_, fld )
else
'' iter = @this.field(elements-1)
fldexpr = astBuildVarField( this_, fld, (elements - 1) * symbGetLen( fld ) )
fldexpr = astBuildVarField( this_, fld, (elements - 1) * symbGetSizeOf( fld ) )
end if
else
if( is_ctor ) then
'' iter = @symbol(0)
fldexpr = astBuildVarField( this_, NULL, 0 )
else
'' iter = @symbol(0) + (elements - 1)
fldexpr = astBuildVarField( this_, NULL, (elements - 1) * symbGetLen( subtype ) )
fldexpr = astBuildVarField( this_, NULL, (elements - 1) * symbGetSizeOf( subtype ) )
end if
end if
tree = astBuildVarAssign( iter, astNewADDROF( fldexpr ), AST_OPOPT_ISINI )
Expand Down
28 changes: 14 additions & 14 deletions src/compiler/ast-node-typeini.bas
Expand Up @@ -75,7 +75,7 @@ private sub hAstTypeIniMaybeConvertUpcast _
'' we want the size of the elements (type) not the whole array
'' !!!TODO!!! byrefs? with symbGetRealSize( sym )?

maxsize = symbGetLen( sym )
maxsize = symbGetSizeOf( sym )

'' This should only be true if astTypeIniAddAssign()
'' determined that the initree was constant
Expand Down Expand Up @@ -386,7 +386,7 @@ private sub hAstTypeIniTreeMergeUpcast _
dim as integer maxsize = any

'' maxsize = symbGetRealSize( sym )
maxsize = symbGetLen( sym )
maxsize = symbGetSizeOf( sym )

'' too big for target?
if( tree->typeini.ofs + expr->typeini.bytes > maxsize ) then
Expand Down Expand Up @@ -492,7 +492,7 @@ function astTypeIniAddAssign _
if( symbIsRef( sym ) ) then
n->typeini.bytes = env.pointersize
else
n->typeini.bytes = symbGetLen( sym )
n->typeini.bytes = symbGetSizeOf( sym )
end if
end if

Expand All @@ -519,7 +519,7 @@ function astTypeIniAddCtorCall _

n->sym = sym
n->typeini.ofs = tree->typeini.ofs
n->typeini.bytes = symbGetLen( sym )
n->typeini.bytes = symbGetSizeOf( sym )

n->l = procexpr

Expand Down Expand Up @@ -552,8 +552,8 @@ function astTypeIniAddCtorList _

n->typeini.elements = elements

tree->typeini.ofs += symbGetLen( sym ) * elements
tree->typeini.bytes += symbGetLen( sym ) * elements
tree->typeini.ofs += symbGetSizeOf( sym ) * elements
tree->typeini.bytes += symbGetSizeOf( sym ) * elements

function = n
end function
Expand Down Expand Up @@ -943,28 +943,28 @@ private sub hFlushExprStatic( byval n as ASTNODE ptr, byval basesym as FBSYMBOL
'' convert?
if( edtype <> FB_DATATYPE_WCHAR ) then
'' less the null-char
irEmitVARINISTR( symbGetStrLen( sym ) - 1, _
irEmitVARINISTR( symbGetStrLength( sym ), _
symbGetVarLitText( litsym ), _
symbGetStrLen( litsym ) - 1 )
symbGetStrLength( litsym ) )
else
'' ditto
irEmitVARINISTR( symbGetStrLen( sym ) - 1, _
irEmitVARINISTR( symbGetStrLength( sym ), _
str( *symbGetVarLitTextW( litsym ) ), _
symbGetWstrLen( litsym ) - 1 )
symbGetWstrLength( litsym ) )
end if
'' wstring..
else
'' convert?
if( edtype <> FB_DATATYPE_WCHAR ) then
'' less the null-char
irEmitVARINIWSTR( symbGetWstrLen( sym ) - 1, _
irEmitVARINIWSTR( symbGetWstrLength( sym ), _
wstr( *symbGetVarLitText( litsym ) ), _
symbGetStrLen( litsym ) - 1 )
symbGetStrLength( litsym ) )
else
'' ditto
irEmitVARINIWSTR( symbGetWstrLen( sym ) - 1, _
irEmitVARINIWSTR( symbGetWstrLength( sym ), _
symbGetVarLitTextW( litsym ), _
symbGetWstrLen( litsym ) - 1 )
symbGetWstrLength( litsym ) )
end if
end if
end if
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/edbg_stab.bas
Expand Up @@ -830,7 +830,7 @@ private sub hDeclUDT _

desc = *symbGetDBGName( sym )

desc += ":Tt" + str( sym->udt.dbg.typenum ) + "=s" + str( symbGetLen( sym ) )
desc += ":Tt" + str( sym->udt.dbg.typenum ) + "=s" + str( symbGetSizeOf( sym ) )

fld = symbUdtGetFirstField( sym )
while( fld )
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/emit_x86.bas
Expand Up @@ -7787,7 +7787,7 @@ private sub _procAllocArg _
assert( symbIsParamVar( sym ) )

if( symbIsParamVarByVal( sym ) ) then
lgt = symbGetLen( sym )
lgt = symbGetSizeOf( sym )
else
'' Bydesc/byref
lgt = env.pointersize
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/ir-gas64.bas
Expand Up @@ -1274,7 +1274,7 @@ private sub hdecludt_asm64 _

desc = *symbGetDBGName( sym )

desc += ":Tt" + str( sym->udt.dbg.typenum ) + "=s" + str( symbGetlen( sym ) )
desc += ":Tt" + str( sym->udt.dbg.typenum ) + "=s" + str( symbGetSizeOf( sym ) )

fld = symbUdtGetFirstField( sym )
while( fld )
Expand Down Expand Up @@ -2800,7 +2800,7 @@ private sub _procallocarg( byval proc as FBSYMBOL ptr, byval sym as FBSYMBOL ptr

symbGetRealType( sym, dtype, subtype )

asm_info("paramvar="+*symbGetMangledName( sym )+" real typ="+ typedumpToStr( dtype, subtype )+" symbgetlen="+Str(symbGetlen( sym )))
asm_info("paramvar="+*symbGetMangledName( sym )+" real typ="+ typedumpToStr( dtype, subtype )+" symbgetsizeof="+Str(symbGetSizeOf( sym )))
asm_info(symbdumpToStr(sym))

asm_info("lgt="+Str(sym->lgt)+" real="+Str(symbGetRealSize( sym )))
Expand Down Expand Up @@ -2853,7 +2853,7 @@ private sub _procallocarg( byval proc as FBSYMBOL ptr, byval sym as FBSYMBOL ptr
else
''byval structure passed directly in a register
asm_info("Copying byval parameter directly from register")
lgt = symbGetlen( sym )
lgt = symbGetSizeOf( sym )
asm_info("stk="+Str(ctx.stk))
ctx.stk=(lgt+ctx.stk+lgt-1) And (Not(lgt-1))
'ctx.stk+=8-(ctx.stk mod 8)
Expand Down Expand Up @@ -2896,7 +2896,7 @@ private sub _procallocarg( byval proc as FBSYMBOL ptr, byval sym as FBSYMBOL ptr
end if
else
''byval simple datatype
lgt = symbGetlen( sym )
lgt = symbGetSizeOf( sym )
if typegetclass(dtype)=FB_DATACLASS_FPOINT then
ctx.argfloat+=1
if ctx.argfloat<=8 then
Expand Down Expand Up @@ -2992,7 +2992,7 @@ private sub _procallocarg( byval proc as FBSYMBOL ptr, byval sym as FBSYMBOL ptr
sym->ofs=ctx.ofs
'if ctx.arginteg<=4 and ctx.variadic=false then
if ctx.variadic=false then
lgt = symbGetlen( sym )
lgt = symbGetSizeOf( sym )
''otherwise already in memory
if paramtype=KPARAMX1 then
if lgt=4 then
Expand All @@ -3018,7 +3018,7 @@ private sub _procallocarg( byval proc as FBSYMBOL ptr, byval sym as FBSYMBOL ptr
end select
else
''byval simple datatype
lgt = symbGetlen( sym )
lgt = symbGetSizeOf( sym )
sym->ofs=ctx.ofs
ctx.arginteg+=1
if ctx.arginteg<=4 and ctx.variadic=false then
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/ir-hlc.bas
Expand Up @@ -807,9 +807,9 @@ private function hEmitArrayDecl( byval sym as FBSYMBOL ptr ) as string
dim as longint length = 0
select case( symbGetType( sym ) )
case FB_DATATYPE_FIXSTR, FB_DATATYPE_CHAR
length = symbGetStrLen( sym )
length = symbGetStrLength( sym ) + 1
case FB_DATATYPE_WCHAR
length = symbGetWstrLen( sym )
length = symbGetWstrLength( sym ) + 1
end select
if( length > 0 ) then
s += "[" + str( length ) + "]"
Expand Down Expand Up @@ -1179,7 +1179,7 @@ private sub hEmitStruct( byval s as FBSYMBOL ptr, byval is_ptr as integer )
if( emit_fields ) then
hEmitStructWithFields( s )
else
hWriteLine( "uint8 __fb_struct_body[" & symbGetLen( s ) & "];", TRUE )
hWriteLine( "uint8 __fb_struct_body[" & symbGetSizeOf( s ) & "];", TRUE )
end if

'' Close UDT body
Expand All @@ -1192,7 +1192,7 @@ private sub hEmitStruct( byval s as FBSYMBOL ptr, byval is_ptr as integer )
'' at least with the correct sizeof(), because if it'd be too small,
'' that could easily cause stack trashing etc., because local vars
'' allocated by gcc would be smaller than expected, etc.
hWriteStaticAssert( "sizeof( " + hGetUdtTag( s ) + hGetUdtId( s ) + " ) == " + str( culngint( symbGetLen( s ) ) ) )
hWriteStaticAssert( "sizeof( " + hGetUdtTag( s ) + hGetUdtId( s ) + " ) == " + str( culngint( symbGetSizeOf( s ) ) ) )
end sub

private sub hWriteX86F2I _
Expand Down Expand Up @@ -2370,9 +2370,9 @@ private sub hSym2Text( byref s as string, byval sym as FBSYMBOL ptr )
'' String literal?
if( symbGetIsLiteral( sym ) ) then
if( symbGetType( sym ) = FB_DATATYPE_WCHAR ) then
hBuildWstrLit( s, hUnescapeW( symbGetVarLitTextW( sym ) ), symbGetWstrLen( sym ) )
hBuildWstrLit( s, hUnescapeW( symbGetVarLitTextW( sym ) ), symbGetWstrLength( sym ) + 1 )
else
hBuildStrLit( s, hUnescape( symbGetVarLitText( sym ) ), symbGetStrLen( sym ) )
hBuildStrLit( s, hUnescape( symbGetVarLitText( sym ) ), symbGetStrLength( sym ) + 1 )
end if
else
if( symbIsLabel( sym ) ) then
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/ir-llvm.bas
Expand Up @@ -670,10 +670,10 @@ private sub hEmitVariable( byval sym as FBSYMBOL ptr )
ln += hEmitSymType( sym )
ln += " c"""
if( symbGetType( sym ) = FB_DATATYPE_WCHAR ) then
length = symbGetWstrLen( sym )
length = symbGetWstrLength( sym ) + 1
hBuildWstrLit( ln, length, hUnescapeW( symbGetVarLitTextW( sym ) ), length )
else
length = symbGetStrLen( sym )
length = symbGetStrLength( sym ) + 1
hBuildStrLit( ln, length, hUnescape( symbGetVarLitText( sym ) ), length )
end if
ln += """"
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/parser-decl-proc-params.bas
Expand Up @@ -61,7 +61,7 @@ sub cParameters _
exit do
end if

length += symbGetLen( param )
length += symbGetSizeOf( param )

'' vararg?
if( param->param.mode = FB_PARAMMODE_VARARG ) then
Expand Down Expand Up @@ -486,7 +486,7 @@ private function hParamDecl _
end if

if( isproto = FALSE ) then
if( symbGetLen( param ) > (env.pointersize * 4) ) then
if( symbGetSizeOf( param ) > (env.pointersize * 4) ) then
if( fbPdCheckIsSet( FB_PDCHECK_PARAMSIZE ) ) then
hParamWarning( proc, id, FB_WARNINGMSG_PARAMSIZETOOBIG, 0 )
end if
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/parser-decl-symb-init.bas
Expand Up @@ -332,7 +332,7 @@ private function hArrayInit _
select case as const( typeGetDtAndPtrOnly( ctx.dtype ) )
case FB_DATATYPE_FIXSTR, FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
'' Fixed-length strings
pad_lgt = symbGetLen( ctx.sym )
pad_lgt = symbGetSizeOf( ctx.sym )
case else
pad_lgt = symbCalcLen( ctx.dtype, ctx.subtype )
end select
Expand Down

0 comments on commit 427a659

Please sign in to comment.