From 6ebe893acb7c44688acf71fd0909a1279723747d Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 19 Sep 2019 02:58:52 -0700 Subject: [PATCH] Add id_to_fqsn table on symbol table --- schala-lang/language/src/ast.rs | 2 +- schala-lang/language/src/symbol_table.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index 3a9b1c5..63f752a 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -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, } diff --git a/schala-lang/language/src/symbol_table.rs b/schala-lang/language/src/symbol_table.rs index 3c61723..c6c0775 100644 --- a/schala-lang/language/src/symbol_table.rs +++ b/schala-lang/language/src/symbol_table.rs @@ -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, + id_to_fqsn: HashMap, } //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, scope_path: &Vec, spec: SymbolSpec) { let mut vec: Vec = scope_path.clone(); vec.push(ScopeSegment { name: name.clone(), kind: ScopeSegmentKind::Terminal });