1 /// Author: Aziz Köksal 2 /// License: GPL3 3 /// $(Maturity high) 4 module dil.semantic.SymbolTable; 5 6 import dil.semantic.Symbol, 7 dil.lexer.Identifier; 8 import dil.String; 9 import common; 10 11 /// Maps an identifier string to a Symbol. 12 struct SymbolTable 13 { 14 Symbol[hash_t] table; /// The table data structure. 15 16 /// Looks up ident in the table. 17 /// Returns: the symbol if there, otherwise null. 18 Symbol lookup(Identifier* ident) 19 { 20 assert(ident !is null); 21 auto psym = hashOf(ident.str) in table; 22 return psym ? *psym : null; 23 } 24 25 /// Looks up a string hash in the table. 26 Symbol lookup(hash_t hash) 27 { 28 auto psym = hash in table; 29 return psym ? *psym : null; 30 } 31 32 /// Inserts a symbol into the table. 33 void insert(Symbol symbol, Identifier* ident) 34 { 35 table[hashOf(ident.str)] = symbol; 36 } 37 }