2021-10-06 16:07:42 +08:00
|
|
|
use inkwell::values::BasicValueEnum;
|
2021-10-16 18:08:13 +08:00
|
|
|
use nac3core::{
|
|
|
|
codegen::CodeGenContext,
|
|
|
|
location::Location,
|
|
|
|
symbol_resolver::SymbolResolver,
|
|
|
|
toplevel::{DefinitionId, TopLevelDef},
|
|
|
|
typecheck::{
|
2021-08-19 15:30:52 +08:00
|
|
|
type_inferencer::PrimitiveStore,
|
|
|
|
typedef::{Type, Unifier},
|
2021-10-16 18:08:13 +08:00
|
|
|
},
|
|
|
|
};
|
2021-10-06 16:07:42 +08:00
|
|
|
use parking_lot::{Mutex, RwLock};
|
2021-11-03 17:11:00 +08:00
|
|
|
use nac3parser::ast::StrRef;
|
2021-09-19 16:19:16 +08:00
|
|
|
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 {
|
2021-09-22 17:19:27 +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-08-19 15:30:52 +08:00
|
|
|
}
|
|
|
|
|
2021-09-19 16:19:16 +08:00
|
|
|
impl ResolverInternal {
|
2021-09-22 17:19:27 +08:00
|
|
|
pub fn add_id_def(&self, id: StrRef, def: DefinitionId) {
|
2021-09-19 16:19:16 +08:00
|
|
|
self.id_to_def.lock().insert(id, def);
|
|
|
|
}
|
|
|
|
|
2021-09-22 17:19:27 +08:00
|
|
|
pub fn add_id_type(&self, id: StrRef, ty: Type) {
|
2021-09-19 16:19:16 +08:00
|
|
|
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 {
|
2021-10-16 18:08:13 +08:00
|
|
|
fn get_symbol_type(
|
|
|
|
&self,
|
|
|
|
_: &mut Unifier,
|
|
|
|
_: &[Arc<RwLock<TopLevelDef>>],
|
|
|
|
_: &PrimitiveStore,
|
|
|
|
str: StrRef,
|
|
|
|
) -> Option<Type> {
|
2021-09-22 17:19:27 +08:00
|
|
|
let ret = self.0.id_to_type.lock().get(&str).cloned();
|
2021-09-19 16:19:16 +08:00
|
|
|
if ret.is_none() {
|
|
|
|
// println!("unknown here resolver {}", str);
|
|
|
|
}
|
|
|
|
ret
|
2021-08-19 15:30:52 +08:00
|
|
|
}
|
|
|
|
|
2021-10-16 18:08:13 +08:00
|
|
|
fn get_symbol_value<'ctx, 'a>(
|
|
|
|
&self,
|
|
|
|
_: StrRef,
|
|
|
|
_: &mut CodeGenContext<'ctx, 'a>,
|
|
|
|
) -> Option<BasicValueEnum<'ctx>> {
|
2021-08-19 15:30:52 +08:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2021-09-22 17:19:27 +08:00
|
|
|
fn get_symbol_location(&self, _: StrRef) -> Option<Location> {
|
2021-08-19 15:30:52 +08:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2021-09-22 17:19:27 +08:00
|
|
|
fn get_identifier_def(&self, id: StrRef) -> Option<DefinitionId> {
|
|
|
|
self.0.id_to_def.lock().get(&id).cloned()
|
2021-08-19 15:30:52 +08:00
|
|
|
}
|
|
|
|
}
|