summaryrefslogtreecommitdiffstats
path: root/src/parser/clang/entities.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/clang/entities.rs')
-rw-r--r--src/parser/clang/entities.rs55
1 files changed, 51 insertions, 4 deletions
diff --git a/src/parser/clang/entities.rs b/src/parser/clang/entities.rs
index cbc17b7..a5b6462 100644
--- a/src/parser/clang/entities.rs
+++ b/src/parser/clang/entities.rs
@@ -14,6 +14,7 @@ pub(super) struct Children {
14 variables: Option<BTreeMap<Usr, Described<Variable>>>, 14 variables: Option<BTreeMap<Usr, Described<Variable>>>,
15 structs: Option<BTreeMap<Usr, Described<Struct>>>, 15 structs: Option<BTreeMap<Usr, Described<Struct>>>,
16 functions: Option<BTreeMap<Usr, Described<Function>>>, 16 functions: Option<BTreeMap<Usr, Described<Function>>>,
17 typedefs: Option<BTreeMap<Usr, Described<Typedef>>>,
17} 18}
18 19
19#[derive(Debug, Clone, Copy, PartialEq, Eq)] 20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -22,6 +23,7 @@ pub(super) enum ClangEntityKind {
22 Variable(VariableKind), 23 Variable(VariableKind),
23 Struct(StructKind), 24 Struct(StructKind),
24 Function(FunctionKind), 25 Function(FunctionKind),
26 Typedef,
25} 27}
26 28
27#[derive(Debug, Clone, Copy, PartialEq, Eq)] 29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -52,6 +54,7 @@ impl ClangEntityKind {
52 ClangEntityKind::Struct(StructKind::Class) => "class", 54 ClangEntityKind::Struct(StructKind::Class) => "class",
53 ClangEntityKind::Function(FunctionKind::Function) => "function", 55 ClangEntityKind::Function(FunctionKind::Function) => "function",
54 ClangEntityKind::Function(FunctionKind::Method) => "method", 56 ClangEntityKind::Function(FunctionKind::Method) => "method",
57 ClangEntityKind::Typedef => "typedef",
55 } 58 }
56 } 59 }
57 60
@@ -64,6 +67,7 @@ impl ClangEntityKind {
64 ClangEntityKind::Struct(StructKind::Class) => "classes", 67 ClangEntityKind::Struct(StructKind::Class) => "classes",
65 ClangEntityKind::Function(FunctionKind::Function) => "functions", 68 ClangEntityKind::Function(FunctionKind::Function) => "functions",
66 ClangEntityKind::Function(FunctionKind::Method) => "methods", 69 ClangEntityKind::Function(FunctionKind::Method) => "methods",
70 ClangEntityKind::Typedef => "typedefs",
67 } 71 }
68 } 72 }
69} 73}
@@ -80,12 +84,19 @@ impl TryFrom<EntityKind> for ClangEntityKind {
80 EntityKind::Namespace => ClangEntityKind::Namespace, 84 EntityKind::Namespace => ClangEntityKind::Namespace,
81 EntityKind::VarDecl => ClangEntityKind::Variable(VariableKind::Variable), 85 EntityKind::VarDecl => ClangEntityKind::Variable(VariableKind::Variable),
82 EntityKind::FieldDecl => ClangEntityKind::Variable(VariableKind::Field), 86 EntityKind::FieldDecl => ClangEntityKind::Variable(VariableKind::Field),
83 EntityKind::FunctionDecl => ClangEntityKind::Function(FunctionKind::Function), 87 EntityKind::FunctionDecl | EntityKind::FunctionTemplate => {
84 EntityKind::Method | EntityKind::Constructor => { 88 ClangEntityKind::Function(FunctionKind::Function)
89 }
90 EntityKind::Method | EntityKind::Constructor | EntityKind::Destructor => {
85 ClangEntityKind::Function(FunctionKind::Method) 91 ClangEntityKind::Function(FunctionKind::Method)
86 } 92 }
87 EntityKind::StructDecl => ClangEntityKind::Struct(StructKind::Struct), 93 EntityKind::StructDecl => ClangEntityKind::Struct(StructKind::Struct),
88 EntityKind::ClassDecl => ClangEntityKind::Struct(StructKind::Class), 94 EntityKind::ClassDecl | EntityKind::ClassTemplate => {
95 ClangEntityKind::Struct(StructKind::Class)
96 }
97 EntityKind::TypedefDecl
98 | EntityKind::TypeAliasDecl
99 | EntityKind::TypeAliasTemplateDecl => ClangEntityKind::Typedef,
89 kind => return Err(TryFromEntityKindError(format!("{:?}", kind))), 100 kind => return Err(TryFromEntityKindError(format!("{:?}", kind))),
90 }) 101 })
91 } 102 }
@@ -106,6 +117,9 @@ pub(super) trait ClangEntity {
106 fn get_member_functions(&mut self) -> Option<&mut BTreeMap<Usr, Described<Function>>> { 117 fn get_member_functions(&mut self) -> Option<&mut BTreeMap<Usr, Described<Function>>> {
107 None 118 None
108 } 119 }
120 fn get_member_typedefs(&mut self) -> Option<&mut BTreeMap<Usr, Described<Typedef>>> {
121 None
122 }
109 123
110 fn into_children(self) -> Children 124 fn into_children(self) -> Children
111 where 125 where
@@ -116,6 +130,7 @@ pub(super) trait ClangEntity {
116 variables: None, 130 variables: None,
117 structs: None, 131 structs: None,
118 functions: None, 132 functions: None,
133 typedefs: None,
119 } 134 }
120 } 135 }
121} 136}
@@ -169,12 +184,23 @@ where
169 } 184 }
170} 185}
171 186
187impl<U> NamespaceParentManipulation<Typedef> for U
188where
189 U: ClangEntity,
190{
191 fn get_members_mut(&mut self) -> Option<&mut BTreeMap<Usr, Described<Typedef>>> {
192 self.get_member_typedefs()
193 }
194}
195
172fn entity_id(usr: Usr) -> EntityId { 196fn entity_id(usr: Usr) -> EntityId {
173 // This is a somewhat ugly workaround, because Pandoc parses markdown identifiers as alphanum 197 // This is a somewhat ugly workaround, because Pandoc parses markdown identifiers as alphanum
174 // or one of "-_:.", which means Pandoc can't parse libclang's USRs in title ids and related. 198 // or one of "-_:.", which means Pandoc can't parse libclang's USRs in title ids and related.
175 // 199 //
176 // <https://github.com/jgm/pandoc/blob/2.9/src/Text/Pandoc/Readers/Markdown.hs#L581> 200 // <https://github.com/jgm/pandoc/blob/2.9/src/Text/Pandoc/Readers/Markdown.hs#L581>
177 EntityId(usr.0.replace("@", "::").replace("#", ".").replace("$", "-")) 201 EntityId(
202 usr.0.replace("@", "::").replace("#", ".").replace("$", "-")
203 )
178} 204}
179 205
180fn append_children<T: ClangEntity>( 206fn append_children<T: ClangEntity>(
@@ -243,6 +269,7 @@ pub(super) struct Namespace {
243 pub(super) member_variables: BTreeMap<Usr, Described<Variable>>, 269 pub(super) member_variables: BTreeMap<Usr, Described<Variable>>,
244 pub(super) member_structs: BTreeMap<Usr, Described<Struct>>, 270 pub(super) member_structs: BTreeMap<Usr, Described<Struct>>,
245 pub(super) member_functions: BTreeMap<Usr, Described<Function>>, 271 pub(super) member_functions: BTreeMap<Usr, Described<Function>>,
272 pub(super) member_typedefs: BTreeMap<Usr, Described<Typedef>>,
246} 273}
247 274
248impl ClangEntity for Namespace { 275impl ClangEntity for Namespace {
@@ -262,6 +289,9 @@ impl ClangEntity for Namespace {
262 fn get_member_functions(&mut self) -> Option<&mut BTreeMap<Usr, Described<Function>>> { 289 fn get_member_functions(&mut self) -> Option<&mut BTreeMap<Usr, Described<Function>>> {
263 Some(&mut self.member_functions) 290 Some(&mut self.member_functions)
264 } 291 }
292 fn get_member_typedefs(&mut self) -> Option<&mut BTreeMap<Usr, Described<Typedef>>> {
293 Some(&mut self.member_typedefs)
294 }
265 295
266 fn into_children(self) -> Children { 296 fn into_children(self) -> Children {
267 Children { 297 Children {
@@ -269,6 +299,7 @@ impl ClangEntity for Namespace {
269 variables: Some(self.member_variables), 299 variables: Some(self.member_variables),
270 structs: Some(self.member_structs), 300 structs: Some(self.member_structs),
271 functions: Some(self.member_functions), 301 functions: Some(self.member_functions),
302 typedefs: Some(self.member_typedefs),
272 } 303 }
273 } 304 }
274} 305}
@@ -314,6 +345,7 @@ pub(super) struct Struct {
314 pub(super) member_variables: BTreeMap<Usr, Described<Variable>>, 345 pub(super) member_variables: BTreeMap<Usr, Described<Variable>>,
315 pub(super) member_structs: BTreeMap<Usr, Described<Struct>>, 346 pub(super) member_structs: BTreeMap<Usr, Described<Struct>>,
316 pub(super) member_functions: BTreeMap<Usr, Described<Function>>, 347 pub(super) member_functions: BTreeMap<Usr, Described<Function>>,
348 pub(super) member_typedefs: BTreeMap<Usr, Described<Typedef>>,
317} 349}
318 350
319impl ClangEntity for Struct { 351impl ClangEntity for Struct {
@@ -330,6 +362,9 @@ impl ClangEntity for Struct {
330 fn get_member_functions(&mut self) -> Option<&mut BTreeMap<Usr, Described<Function>>> { 362 fn get_member_functions(&mut self) -> Option<&mut BTreeMap<Usr, Described<Function>>> {
331 Some(&mut self.member_functions) 363 Some(&mut self.member_functions)
332 } 364 }
365 fn get_member_typedefs(&mut self) -> Option<&mut BTreeMap<Usr, Described<Typedef>>> {
366 Some(&mut self.member_typedefs)
367 }
333 368
334 fn into_children(self) -> Children { 369 fn into_children(self) -> Children {
335 Children { 370 Children {
@@ -337,6 +372,7 @@ impl ClangEntity for Struct {
337 variables: Some(self.member_variables), 372 variables: Some(self.member_variables),
338 structs: Some(self.member_structs), 373 structs: Some(self.member_structs),
339 functions: Some(self.member_functions), 374 functions: Some(self.member_functions),
375 typedefs: Some(self.member_typedefs),
340 } 376 }
341 } 377 }
342} 378}
@@ -381,3 +417,14 @@ pub(super) struct FunctionArgument {
381 pub(super) name: String, 417 pub(super) name: String,
382 pub(super) r#type: String, 418 pub(super) r#type: String,
383} 419}
420
421#[derive(Debug, Clone)]
422pub(super) struct Typedef {
423 pub(super) referee: String,
424}
425
426impl ClangEntity for Typedef {
427 fn kind(&self) -> ClangEntityKind {
428 ClangEntityKind::Typedef
429 }
430}