2019-10-23 00:48:59 -07:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
use crate::ast::ItemId;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub struct Location {
|
|
|
|
pub line_num: usize,
|
|
|
|
pub char_num: usize
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Location {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}:{}", self.line_num, self.char_num)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct SourceMap {
|
|
|
|
map: HashMap<ItemId, Location>
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SourceMap {
|
|
|
|
pub fn new() -> SourceMap {
|
|
|
|
SourceMap { map: HashMap::new() }
|
|
|
|
}
|
2019-10-23 02:37:42 -07:00
|
|
|
|
|
|
|
pub fn add_location(&mut self, id: &ItemId, loc: Location) {
|
|
|
|
self.map.insert(id.clone(), loc);
|
|
|
|
}
|
2019-10-23 00:48:59 -07:00
|
|
|
}
|