Add types necessary for refactor of Symbol table
This commit is contained in:
parent
d4ad97b39a
commit
2490aaf3f4
@ -13,14 +13,23 @@ type LineNumber = u32;
|
|||||||
type SymbolTrackTable = HashMap<Rc<String>, LineNumber>;
|
type SymbolTrackTable = HashMap<Rc<String>, LineNumber>;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, Debug)]
|
#[derive(PartialEq, Eq, Hash, Debug)]
|
||||||
struct SymbolPath {
|
struct PathToSymbol(Vec<Rc<String>>);
|
||||||
name: Rc<String>,
|
|
||||||
enclosing_scopes: Vec<Rc<String>>
|
#[derive(Debug)]
|
||||||
|
struct SymbolPathSegment {
|
||||||
|
segment_name: Rc<String>,
|
||||||
|
segment_type: SymbolPathSegmentKind
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum SymbolPathSegmentKind {
|
||||||
|
NamedScope,
|
||||||
|
TypeVariant
|
||||||
}
|
}
|
||||||
|
|
||||||
//cf. p. 150 or so of Language Implementation Patterns
|
//cf. p. 150 or so of Language Implementation Patterns
|
||||||
pub struct SymbolTable {
|
pub struct SymbolTable {
|
||||||
values: HashMap<SymbolPath, Symbol>,
|
values: HashMap<PathToSymbol, Symbol>,
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO add various types of lookups here, maybe multiple hash tables internally?
|
//TODO add various types of lookups here, maybe multiple hash tables internally?
|
||||||
@ -32,10 +41,9 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_new_symbol(&mut self, name: &Rc<String>, path: &Vec<Rc<String>>, symbol: Symbol) {
|
fn add_new_symbol(&mut self, name: &Rc<String>, path: &Vec<Rc<String>>, symbol: Symbol) {
|
||||||
let symbol_path = SymbolPath {
|
let mut vec = path.clone();
|
||||||
name: name.clone(),
|
vec.push(name.clone());
|
||||||
enclosing_scopes: path.clone(),
|
let symbol_path = PathToSymbol(vec);
|
||||||
};
|
|
||||||
self.values.insert(symbol_path, symbol);
|
self.values.insert(symbol_path, symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +52,9 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookup_by_path(&self, name: &Rc<String>, path: &Vec<Rc<String>>) -> Option<&Symbol> {
|
pub fn lookup_by_path(&self, name: &Rc<String>, path: &Vec<Rc<String>>) -> Option<&Symbol> {
|
||||||
let symbol_path = SymbolPath { name: name.clone(), enclosing_scopes: path.clone() };
|
let mut vec = path.clone();
|
||||||
|
vec.push(name.clone());
|
||||||
|
let symbol_path = PathToSymbol(vec);
|
||||||
self.values.get(&symbol_path)
|
self.values.get(&symbol_path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user