TSymbol / TSymTable
Sources: source/classes/tsymbol.prg, source/classes/tsymtabl.prg
Standalone classes
TSymbol and TSymTable provide runtime introspection of the Harbour symbol table. TSymbol wraps a single symbol handle (hSymbol) and exposes its name and visibility. TSymTable provides iteration over the entire symbol table, returning TSymbol objects. These classes are useful for debuggers, profilers, and tools that need to enumerate all public/static symbols in the current application.
TSymbol
TSymbol represents a single symbol entry in the Harbour symbol table.
Key DATA
| DATA | Type | Description |
|---|---|---|
hSymbol | Numeric | Handle to the internal Harbour symbol entry |
Key METHODs
| Method | Description |
|---|---|
Name() | Return the symbol name as a character string |
IsStatic() | Return .T. if the symbol is static (module-scoped) |
TSymTable
TSymTable provides indexed access to all symbols in the symbol table.
Key METHODs
| Method | Description |
|---|---|
Get( n ) | Return the TSymbol at position n (1-based) |
Len() | Return the total number of symbols in the table |
Size() | Return the total size (same as Len()) |
GetFirst() | Return the first TSymbol in the table |
GetLast() | Return the last TSymbol in the table |
Example: Iterate All Symbols
#include "FiveWin.ch"
function Main()
local oSymTable := TSymTable():New()
local oSym, n
? "Total symbols:", oSymTable:Len()
? "---"
// Print first 20 symbols
for n := 1 to Min( 20, oSymTable:Len() )
oSym := oSymTable:Get( n )
if oSym != nil
? oSym:Name(), ;
if( oSym:IsStatic(), "(static)", "(public)" )
endif
next
// Get first and last symbols
oSym := oSymTable:GetFirst()
if oSym != nil
? "First symbol:", oSym:Name()
endif
oSym := oSymTable:GetLast()
if oSym != nil
? "Last symbol:", oSym:Name()
endif
return nil
Notes
- The symbol table contains all Harbour-level symbols in the application, including FUNCTION, PROCEDURE, STATIC, and PUBLIC symbols.
Get()returnsnilif the index is out of range. Always check fornilbefore accessing the returned object.- Symbols are indexed in the order they are defined in the application. The first module's symbols appear first, followed by subsequent modules.
- These classes rely on Harbour's internal symbol table API (
hb_sym*functions) and are specific to the Harbour runtime.