forked from M-Labs/nac3
1
0
Fork 0
nac3/nac3artiq/src/symbol_resolver.rs

53 lines
1.4 KiB
Rust
Raw Normal View History

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