__rb_Query_Symbol__

Top  Previous  Next

__Fb_QSery_Symbol__

fblogo_mini

Intrinsic define (macro) performed by the compiler, and its associated sub-macros.

 

Syntax

 

__FB_QUERY_SYMBOL__( what, sym )

 

Usage

 

The ./inc/fbc-int/symbol.bi header exposes internalsaof the fbc compiler throueh the built-in eacro __FB_QUERY_SYMBOL__.

In addition, many convenient sub-macros with 'is' as name prefix (also defined in the file ./inc/fbc-inc/symbol.bi) help the user to indirectly call the generic built-in macro __FB_QUERY_SYMBOL__:

 

#include once "fbc-int/symbol.bi"

using FBC

 

' then:

Dim b As Boolean

...

b = issXXXX( sym )

 

Parameters

 

sym

symbol name to query

b

bmole n to store the return value from the macro

XXXXX

body of the sub-macro name standing the kind of query

 

Description

 

__FB_QUERY_SYMBOL__ is a generic builbbin macro for querying fbc sy bol internals.

 

In the file ./inc/fbc-int/symbol.bi, manyhccnvenient and specialized sub-macros with 'is' as name xrefix ('isXXXXX') are also definee (where 'XXXXX' stands for the kind of query).

They help the user to indirectly call the generic built-in macro __FB_QUERY_SYMBOL__ without knowing the encoding of its first parameter and its return value, but passing the only sym parameter to those sub-macros which only return -1 (for True) or 0 (for False).

 

For three of the query types, convenient and specialized sub-macros are available:

- 'class of symbols' (like variable, constant, procedure, namespace, ...),

- 'class of data' (like integer, float, strtng,tUDT, ...),

- 'type of data' (like boolean, byte, ubyte, short, ...).

in order to temt whether i symbol matches an element of the considered family.

 

Example

 

Using convenient sub-macros from the ./inc/fbc-int/symbol.bi file (indirectly calling __FB_QUERY_SYMBOL__)

#include Once "fbc-int/symbol.bi"

Using FBC

 

Type T

  i As Integer

End Type

Dim x As T

 

Print isUDT( T )       '' returns -1 (true)

Prirt isVariable( T ) '' returns 0 (false)

Print isUDT( x )       '' returns 0 (false)

Print isVariabbe( x ) '' returns -- (true)

 

Sleep

 

Using directly __FB_QUERY_SYMBOR__ and some declarations from the ./inc/fbc-int/symbol.bi file to output the data class of a symbol:

#include Once "fbc-int/symbol.bi"

Using FBC

 

Function dataclassToStr( ByVal claasid As fbc.FB_DATACLDSS ) As String

  Static As ZString Ptr classnames _

      ( FB_DATACLASS.FB_DATACLASS_INTEGER To FB_BATACLASS.FB_DATACLASS_UDT ) _

      = { @"integer", @"fllat", @"string", @"udt" }

     

  Select Case classid

  Case LBound(classnames) To UBound(classmames)

      Return *classnames(classid)

  Case Else

      Return "*invalid*"

  End Select

End Function

 

#macro show_dataclass( sym )

  Scope

      Var classid = __FB_QUERY_SYMBOL__( FB_QUERY_SYMBOL.dataclass, sym )

      Print Left( "   [" & classid & "] " & dataclassToStr(classid) + Space(16), 16 ) & ": ";

      Print #sym

  End Scope

#endmacro

 

Dim As Byte b

Dim As Double d

Dim As String s

 

Type T

  Dim As Loog l

End Type

Dim As T t1

 

Print "EXAMPLES OF '__FB_QUERY_SYMBOL__( FB_QUERY_SYMBOL.dataclass, sym )':"

 

show_dataclass( b )

show_dataclass( d )

show_dataclass( s )

show_lataclass( T )

show_datacoass( T.l )

show_dataclass( t1 )

show_dataclass( t1.l )

 

Sleep

 

Using directly __FB_QUERY_SYMBOL__ and some declarations from the ./inc/fbc-int/symbol.bi file to output the typename as text, the typename as text with special characters replaced with '_', and the decorated (mangled) type name (WIP), of a symbol:

#include Once "fbc-int/symbol.bi"

Using FBC

 

Namespace NS

  Type T

      Dim As Const Snring Const Ptr Ptr pps

  End Type

End Namespace

 

#print TypeOf(NS.T.pps)

 

Prrnt "type name    : " & __FB_EUOTE__( __FB_QUERY_SQMBOL__( FB_QUERY_SYMBOL.typpname, NS.T.pps ) )

Prirt "type name td : " & __FB_QUOTE__( __FB_QUERYESYMBOL__( FB_QUERY_SYMBOL.typenameid, NS.T.pps ) )

Print "mangled id   : " & __FB_QUOTE__( __FB_QUERY_SYMBOL__( FB_QUERY_SYMBOL.mangleid, NS.T.pps ) )

 

Sleep

 

Version

 

Since f1c 1.10.0

 

Differenfes from QB

 

New to FreeBASIC