Add id_to_fqsn table on symbol table

This commit is contained in:
greg 2019-09-19 02:58:52 -07:00
parent c9052e0a3b
commit 6ebe893acb
2 changed files with 8 additions and 2 deletions

View File

@ -9,7 +9,7 @@ mod operators;
pub use operators::*;
/// An abstract identifier for an AST node
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct ItemId {
idx: u32,
}

View File

@ -5,7 +5,7 @@ use std::fmt;
use std::fmt::Write;
use crate::ast;
use crate::ast::{Meta, TypeBody, TypeSingletonName, Signature, Statement, StatementKind};
use crate::ast::{ItemId, Meta, TypeBody, TypeSingletonName, Signature, Statement, StatementKind};
use crate::typechecking::TypeName;
type LineNumber = u32;
@ -81,6 +81,7 @@ macro_rules! sym_path_kind {
//cf. p. 150 or so of Language Implementation Patterns
pub struct SymbolTable {
symbol_path_to_symbol: HashMap<FullyQualifiedSymbolName, Symbol>,
id_to_fqsn: HashMap<ItemId, FullyQualifiedSymbolName>,
}
//TODO add various types of lookups here, maybe multiple hash tables internally?
@ -88,9 +89,14 @@ impl SymbolTable {
pub fn new() -> SymbolTable {
SymbolTable {
symbol_path_to_symbol: HashMap::new(),
id_to_fqsn: HashMap::new(),
}
}
pub fn map_id_to_fqsn(&mut self, id: &ItemId, fqsn: FullyQualifiedSymbolName) {
self.id_to_fqsn.insert(id.clone(), fqsn);
}
fn add_new_symbol(&mut self, name: &Rc<String>, scope_path: &Vec<ScopeSegment>, spec: SymbolSpec) {
let mut vec: Vec<ScopeSegment> = scope_path.clone();
vec.push(ScopeSegment { name: name.clone(), kind: ScopeSegmentKind::Terminal });