Data Structures
NameSymbols are internal symbol representations. NameSymbols are hashed
into a NameLookupTable using the method NameLookupTable::FindOrInsertName.
They are linked in a linear chain data structure for searching using the
field "next". The FindOrInsertName method automatically sets both the "next"
and hash_address fields.
Each NameSymbol has:
name_ a wchar string
length and it's length
hash_address this is a hash index into the symbol hash table. Searching for a
matching symbol starts with this entry and walks the chain of next pointers.
index this is the position in the symbol_pool, the list of all symbols.
next an inherited pointer to the next Symbol object
all Symbols are singly linked thru this field.
_kind an enumerated type SymbolKind from Symbol
_kind is used to determine the success of casting this
Symbol to the various subtypes.
Utf8_literal
method Name()
method NameLength()
method NameSymbol()
method Utf8Name()
method UtfNameLength()
method PackageCast()
method TypeCast()
method BlockCast()
method VariableCast()
method LabelCast()
method LiteralCast()
method NameCast()
method PathCast()
method DirectoryCast()
method FileCast()
NameLookupTable is a combination of a linear linked list and a hash table.
The hash table is stored in "base" and is an array of NameSymbol objects.
Character strings representing symbols are given to the FindOrInsertName
method which will hash into the base array and starts a linear search for the
NameSymbol. If it is found, the NameSymbol is returned, else we do two things:
we create a new NameSymbol which we chain to the end of the symbol_pool list
and we create a hash entry in the base array. The newly created NameSymbol
is returned.
A NameLookupTable consists of:
symbol_pool a Tuple of NameSymbol objects
base an array of NameSymbol objects
hash_size the current length of the base array
constructor NameLookupTable
method FindOrInsertName lookup and maybe create a NameSymbol object
method Hash returns a hash code, given a string or number
method Rehash which resizes the base array if > 50% full