use std::collections::HashMap; #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub(crate) struct Usr(pub(crate) String); #[derive(Debug, Clone)] pub(crate) struct EntitiesManager { toplevel_entities: HashMap, descriptions: HashMap, } pub(crate) struct EntitiesManagerComponents { pub(crate) toplevel_entities: HashMap, pub(crate) descriptions: HashMap, } impl EntitiesManager { pub fn new() -> Self { EntitiesManager { toplevel_entities: HashMap::new(), descriptions: HashMap::new(), } } pub fn insert(&mut self, usr: Usr, description: Description) { info!("Found entity {:?}", description.name); self.descriptions.insert(usr, description); } pub fn insert_toplevel(&mut self, usr: Usr, entity: Entity) { self.toplevel_entities.insert(usr, entity); } pub fn decompose(self) -> EntitiesManagerComponents { EntitiesManagerComponents { toplevel_entities: self.toplevel_entities, descriptions: self.descriptions, } } } #[derive(Debug, Clone, Default)] pub(crate) struct Description { pub(crate) name: String, pub(crate) brief: String, pub(crate) detailed: String, } impl Description { pub(crate) fn with_name(name: String) -> Self { Description { name, ..Default::default() } } } #[derive(Debug, Clone)] pub(crate) struct Described { pub(crate) description: Description, pub(crate) entity: T, } #[derive(Debug, Clone)] pub(crate) enum Entity { NameSpace(NameSpace), Variable(Variable), Function(Function), Class(Class), } impl Entity { fn kind_name(&self) -> &'static str { match self { Entity::NameSpace(_) => "namespace", Entity::Variable(_) => "variable", Entity::Function(_) => "function", Entity::Class(_) => "class", } } } #[derive(Debug, Clone)] pub(crate) struct NameSpace { pub(crate) members: HashMap, } impl From for Entity { fn from(ns: NameSpace) -> Self { Entity::NameSpace(ns) } } #[derive(Debug, Clone)] pub(crate) struct Variable { pub(crate) r#type: String, } impl From for Entity { fn from(var: Variable) -> Self { Entity::Variable(var) } } #[derive(Debug, Clone)] pub(crate) struct Function { pub(crate) arguments: Vec, pub(crate) return_type: String, } impl From for Entity { fn from(func: Function) -> Self { Entity::Function(func) } } #[derive(Debug, Clone)] pub(crate) struct FunctionArgument { pub(crate) name: String, pub(crate) r#type: String, } #[derive(Debug, Clone)] pub(crate) struct Class { pub(crate) member_types: Vec, pub(crate) member_functions: HashMap, pub(crate) member_variables: HashMap, } impl From for Entity { fn from(class: Class) -> Self { Entity::Class(class) } }