summaryrefslogtreecommitdiffstats
path: root/src/entities.rs
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2019-09-08 16:15:46 +0200
committerMinijackson <minijackson@riseup.net>2019-11-10 16:37:59 +0100
commit3301430c676e4af6b95d96b6408a66f9d2768653 (patch)
tree12810ce81a3b1d3cb23270fc5119016d5f6c325a /src/entities.rs
downloadposeidoc-3301430c676e4af6b95d96b6408a66f9d2768653.tar.gz
poseidoc-3301430c676e4af6b95d96b6408a66f9d2768653.zip
First version
Diffstat (limited to 'src/entities.rs')
-rw-r--r--src/entities.rs134
1 files changed, 134 insertions, 0 deletions
diff --git a/src/entities.rs b/src/entities.rs
new file mode 100644
index 0000000..b7368df
--- /dev/null
+++ b/src/entities.rs
@@ -0,0 +1,134 @@
1use std::collections::HashMap;
2
3#[derive(Debug, Clone, Hash, PartialEq, Eq)]
4pub(crate) struct Usr(pub(crate) String);
5
6#[derive(Debug, Clone)]
7pub(crate) struct EntitiesManager {
8 toplevel_entities: HashMap<Usr, Entity>,
9 descriptions: HashMap<Usr, Description>,
10}
11
12pub(crate) struct EntitiesManagerComponents {
13 pub(crate) toplevel_entities: HashMap<Usr, Entity>,
14 pub(crate) descriptions: HashMap<Usr, Description>,
15}
16
17impl EntitiesManager {
18 pub fn new() -> Self {
19 EntitiesManager {
20 toplevel_entities: HashMap::new(),
21 descriptions: HashMap::new(),
22 }
23 }
24
25 pub fn insert(&mut self, usr: Usr, description: Description) {
26 info!("Found entity {:?}", description.name);
27 self.descriptions.insert(usr, description);
28 }
29
30 pub fn insert_toplevel(&mut self, usr: Usr, entity: Entity) {
31 self.toplevel_entities.insert(usr, entity);
32 }
33
34 pub fn decompose(self) -> EntitiesManagerComponents {
35 EntitiesManagerComponents {
36 toplevel_entities: self.toplevel_entities,
37 descriptions: self.descriptions,
38 }
39 }
40}
41
42#[derive(Debug, Clone, Default)]
43pub(crate) struct Description {
44 pub(crate) name: String,
45 pub(crate) brief: String,
46 pub(crate) detailed: String,
47}
48
49impl Description {
50 pub(crate) fn with_name(name: String) -> Self {
51 Description {
52 name,
53 ..Default::default()
54 }
55 }
56}
57
58#[derive(Debug, Clone)]
59pub(crate) struct Described<T> {
60 pub(crate) description: Description,
61 pub(crate) entity: T,
62}
63
64#[derive(Debug, Clone)]
65pub(crate) enum Entity {
66 NameSpace(NameSpace),
67 Variable(Variable),
68 Function(Function),
69 Class(Class),
70}
71
72impl Entity {
73 fn kind_name(&self) -> &'static str {
74 match self {
75 Entity::NameSpace(_) => "namespace",
76 Entity::Variable(_) => "variable",
77 Entity::Function(_) => "function",
78 Entity::Class(_) => "class",
79 }
80 }
81}
82
83#[derive(Debug, Clone)]
84pub(crate) struct NameSpace {
85 pub(crate) members: HashMap<Usr, Entity>,
86}
87
88impl From<NameSpace> for Entity {
89 fn from(ns: NameSpace) -> Self {
90 Entity::NameSpace(ns)
91 }
92}
93
94#[derive(Debug, Clone)]
95pub(crate) struct Variable {
96 pub(crate) r#type: String,
97}
98
99impl From<Variable> for Entity {
100 fn from(var: Variable) -> Self {
101 Entity::Variable(var)
102 }
103}
104
105#[derive(Debug, Clone)]
106pub(crate) struct Function {
107 pub(crate) arguments: Vec<FunctionArgument>,
108 pub(crate) return_type: String,
109}
110
111impl From<Function> for Entity {
112 fn from(func: Function) -> Self {
113 Entity::Function(func)
114 }
115}
116
117#[derive(Debug, Clone)]
118pub(crate) struct FunctionArgument {
119 pub(crate) name: String,
120 pub(crate) r#type: String,
121}
122
123#[derive(Debug, Clone)]
124pub(crate) struct Class {
125 pub(crate) member_types: Vec<Usr>,
126 pub(crate) member_functions: HashMap<Usr, Function>,
127 pub(crate) member_variables: HashMap<Usr, Variable>,
128}
129
130impl From<Class> for Entity {
131 fn from(class: Class) -> Self {
132 Entity::Class(class)
133 }
134}