Start work on symbol table lookup by type name
This commit is contained in:
parent
a74027bb1f
commit
3d6447abb4
@ -28,14 +28,16 @@ enum ScopeSegmentKind {
|
||||
|
||||
//cf. p. 150 or so of Language Implementation Patterns
|
||||
pub struct SymbolTable {
|
||||
values: HashMap<PathToSymbol, Symbol>,
|
||||
symbol_path_to_symbol: HashMap<PathToSymbol, Symbol>,
|
||||
type_name_to_symbol: HashMap<Rc<String>, PathToSymbol>
|
||||
}
|
||||
|
||||
//TODO add various types of lookups here, maybe multiple hash tables internally?
|
||||
impl SymbolTable {
|
||||
pub fn new() -> SymbolTable {
|
||||
SymbolTable {
|
||||
values: HashMap::new(),
|
||||
symbol_path_to_symbol: HashMap::new(),
|
||||
type_name_to_symbol: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +46,7 @@ impl SymbolTable {
|
||||
vec.push(name.clone());
|
||||
let symbol_path = PathToSymbol(vec);
|
||||
let symbol = Symbol { name: name.clone(), scopes: scope_path.to_vec(), spec };
|
||||
self.values.insert(symbol_path, symbol);
|
||||
self.symbol_path_to_symbol.insert(symbol_path, symbol);
|
||||
}
|
||||
|
||||
pub fn lookup_by_name(&self, name: &Rc<String>) -> Option<&Symbol> {
|
||||
@ -55,7 +57,11 @@ impl SymbolTable {
|
||||
let mut vec = path.clone();
|
||||
vec.push(name.clone());
|
||||
let symbol_path = PathToSymbol(vec);
|
||||
self.values.get(&symbol_path)
|
||||
self.symbol_path_to_symbol.get(&symbol_path)
|
||||
}
|
||||
|
||||
pub fn lookup_by_type_and_tag(&self, type_name: &Rc<String>, tag: usize) -> Option<&Symbol> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +169,7 @@ impl SymbolTable {
|
||||
}
|
||||
pub fn debug_symbol_table(&self) -> String {
|
||||
let mut output = format!("Symbol table\n");
|
||||
for (name, sym) in &self.values {
|
||||
for (name, sym) in &self.symbol_path_to_symbol {
|
||||
write!(output, "{:?} -> {}\n", name, sym).unwrap();
|
||||
}
|
||||
output
|
||||
|
Loading…
Reference in New Issue
Block a user