2021-08-19 15:30:52 +08:00
|
|
|
use nac3core::{
|
|
|
|
location::Location,
|
|
|
|
symbol_resolver::{SymbolResolver, SymbolValue},
|
2021-08-24 17:14:34 +08:00
|
|
|
toplevel::DefinitionId,
|
2021-08-19 15:30:52 +08:00
|
|
|
typecheck::{
|
|
|
|
type_inferencer::PrimitiveStore,
|
|
|
|
typedef::{Type, Unifier},
|
|
|
|
},
|
|
|
|
};
|
2021-09-19 16:19:16 +08:00
|
|
|
use parking_lot::Mutex;
|
|
|
|
use std::{collections::HashMap, sync::Arc};
|
2021-08-19 15:30:52 +08:00
|
|
|
|
2021-09-19 16:19:16 +08:00
|
|
|
pub struct ResolverInternal {
|
|
|
|
pub id_to_type: Mutex<HashMap<String, Type>>,
|
|
|
|
pub id_to_def: Mutex<HashMap<String, DefinitionId>>,
|
|
|
|
pub class_names: Mutex<HashMap<String, Type>>,
|
2021-08-19 15:30:52 +08:00
|
|
|
}
|
|
|
|
|
2021-09-19 16:19:16 +08:00
|
|
|
impl ResolverInternal {
|
|
|
|
pub fn add_id_def(&self, id: String, def: DefinitionId) {
|
|
|
|
self.id_to_def.lock().insert(id, def);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_id_type(&self, id: String, ty: Type) {
|
|
|
|
self.id_to_type.lock().insert(id, ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Resolver(pub Arc<ResolverInternal>);
|
|
|
|
|
2021-08-19 15:30:52 +08:00
|
|
|
impl SymbolResolver for Resolver {
|
|
|
|
fn get_symbol_type(&self, _: &mut Unifier, _: &PrimitiveStore, str: &str) -> Option<Type> {
|
2021-09-19 16:19:16 +08:00
|
|
|
let ret = self.0.id_to_type.lock().get(str).cloned();
|
|
|
|
if ret.is_none() {
|
|
|
|
// println!("unknown here resolver {}", str);
|
|
|
|
}
|
|
|
|
ret
|
2021-08-19 15:30:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_symbol_value(&self, _: &str) -> Option<SymbolValue> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_symbol_location(&self, _: &str) -> Option<Location> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_identifier_def(&self, id: &str) -> Option<DefinitionId> {
|
2021-09-19 16:19:16 +08:00
|
|
|
self.0.id_to_def.lock().get(id).cloned()
|
2021-08-19 15:30:52 +08:00
|
|
|
}
|
|
|
|
}
|