schala/schala-lang/language/src/symbol_table/tables.rs

29 lines
623 B
Rust

use std::collections::HashMap;
use crate::ast::ItemId;
use crate::tokenizing::Location;
/// Maps top-level declarations to Locations in source code, to detect
/// multiply-defined top level items.
pub struct DeclLocations {
map: HashMap<ItemId, Location>
}
impl DeclLocations {
pub fn new() -> Self {
Self { map: HashMap::new() }
}
pub(crate) fn add_location(&mut self, id: &ItemId, loc: Location) {
self.map.insert(id.clone(), loc);
}
pub(crate) fn lookup(&self, id: &ItemId) -> Option<Location> {
match self.map.get(id) {
Some(loc) => Some(loc.clone()),
None => None
}
}
}