diff options
Diffstat (limited to 'src/parser/clang/entities.rs')
-rw-r--r-- | src/parser/clang/entities.rs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/parser/clang/entities.rs b/src/parser/clang/entities.rs index 8da85d9..0e9305b 100644 --- a/src/parser/clang/entities.rs +++ b/src/parser/clang/entities.rs | |||
@@ -16,6 +16,8 @@ pub(super) enum ClangEntityKind { | |||
16 | Struct(StructKind), | 16 | Struct(StructKind), |
17 | Function(FunctionKind), | 17 | Function(FunctionKind), |
18 | Typedef, | 18 | Typedef, |
19 | Enum, | ||
20 | EnumConstant, | ||
19 | } | 21 | } |
20 | 22 | ||
21 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 23 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
@@ -47,6 +49,8 @@ impl ClangEntityKind { | |||
47 | ClangEntityKind::Function(FunctionKind::Function) => "function", | 49 | ClangEntityKind::Function(FunctionKind::Function) => "function", |
48 | ClangEntityKind::Function(FunctionKind::Method) => "method", | 50 | ClangEntityKind::Function(FunctionKind::Method) => "method", |
49 | ClangEntityKind::Typedef => "typedef", | 51 | ClangEntityKind::Typedef => "typedef", |
52 | ClangEntityKind::Enum => "enum", | ||
53 | ClangEntityKind::EnumConstant => "enum-constant", | ||
50 | } | 54 | } |
51 | } | 55 | } |
52 | 56 | ||
@@ -60,6 +64,8 @@ impl ClangEntityKind { | |||
60 | ClangEntityKind::Function(FunctionKind::Function) => "functions", | 64 | ClangEntityKind::Function(FunctionKind::Function) => "functions", |
61 | ClangEntityKind::Function(FunctionKind::Method) => "methods", | 65 | ClangEntityKind::Function(FunctionKind::Method) => "methods", |
62 | ClangEntityKind::Typedef => "typedefs", | 66 | ClangEntityKind::Typedef => "typedefs", |
67 | ClangEntityKind::Enum => "enums", | ||
68 | ClangEntityKind::EnumConstant => "enum-constants", | ||
63 | } | 69 | } |
64 | } | 70 | } |
65 | } | 71 | } |
@@ -89,6 +95,8 @@ impl TryFrom<EntityKind> for ClangEntityKind { | |||
89 | EntityKind::TypedefDecl | 95 | EntityKind::TypedefDecl |
90 | | EntityKind::TypeAliasDecl | 96 | | EntityKind::TypeAliasDecl |
91 | | EntityKind::TypeAliasTemplateDecl => ClangEntityKind::Typedef, | 97 | | EntityKind::TypeAliasTemplateDecl => ClangEntityKind::Typedef, |
98 | EntityKind::EnumDecl => ClangEntityKind::Enum, | ||
99 | EntityKind::EnumConstantDecl => ClangEntityKind::EnumConstant, | ||
92 | kind => return Err(TryFromEntityKindError(format!("{:?}", kind))), | 100 | kind => return Err(TryFromEntityKindError(format!("{:?}", kind))), |
93 | }) | 101 | }) |
94 | } | 102 | } |
@@ -118,6 +126,9 @@ pub(super) trait ClangEntity { | |||
118 | fn get_member_typedefs(&mut self) -> Option<&mut BTreeMap<Usr, Described<Typedef>>> { | 126 | fn get_member_typedefs(&mut self) -> Option<&mut BTreeMap<Usr, Described<Typedef>>> { |
119 | None | 127 | None |
120 | } | 128 | } |
129 | fn get_member_enums(&mut self) -> Option<&mut BTreeMap<Usr, Described<Enum>>> { | ||
130 | None | ||
131 | } | ||
121 | } | 132 | } |
122 | 133 | ||
123 | /* | 134 | /* |
@@ -178,6 +189,15 @@ where | |||
178 | } | 189 | } |
179 | } | 190 | } |
180 | 191 | ||
192 | impl<U> NamespaceParentManipulation<Enum> for U | ||
193 | where | ||
194 | U: ClangEntity, | ||
195 | { | ||
196 | fn get_members_mut(&mut self) -> Option<&mut BTreeMap<Usr, Described<Enum>>> { | ||
197 | self.get_member_enums() | ||
198 | } | ||
199 | } | ||
200 | |||
181 | fn entity_id(usr: Usr) -> EntityId { | 201 | fn entity_id(usr: Usr) -> EntityId { |
182 | // This is a somewhat ugly workaround, because Pandoc parses markdown identifiers as alphanum | 202 | // This is a somewhat ugly workaround, because Pandoc parses markdown identifiers as alphanum |
183 | // or one of "-_:.", which means Pandoc can't parse libclang's USRs in title ids and related. | 203 | // or one of "-_:.", which means Pandoc can't parse libclang's USRs in title ids and related. |
@@ -236,6 +256,7 @@ pub(super) struct Namespace { | |||
236 | pub(super) member_structs: BTreeMap<Usr, Described<Struct>>, | 256 | pub(super) member_structs: BTreeMap<Usr, Described<Struct>>, |
237 | pub(super) member_functions: BTreeMap<Usr, Described<Function>>, | 257 | pub(super) member_functions: BTreeMap<Usr, Described<Function>>, |
238 | pub(super) member_typedefs: BTreeMap<Usr, Described<Typedef>>, | 258 | pub(super) member_typedefs: BTreeMap<Usr, Described<Typedef>>, |
259 | pub(super) member_enums: BTreeMap<Usr, Described<Enum>>, | ||
239 | } | 260 | } |
240 | 261 | ||
241 | impl ClangEntity for Namespace { | 262 | impl ClangEntity for Namespace { |
@@ -258,6 +279,9 @@ impl ClangEntity for Namespace { | |||
258 | fn get_member_typedefs(&mut self) -> Option<&mut BTreeMap<Usr, Described<Typedef>>> { | 279 | fn get_member_typedefs(&mut self) -> Option<&mut BTreeMap<Usr, Described<Typedef>>> { |
259 | Some(&mut self.member_typedefs) | 280 | Some(&mut self.member_typedefs) |
260 | } | 281 | } |
282 | fn get_member_enums(&mut self) -> Option<&mut BTreeMap<Usr, Described<Enum>>> { | ||
283 | Some(&mut self.member_enums) | ||
284 | } | ||
261 | } | 285 | } |
262 | 286 | ||
263 | /* | 287 | /* |
@@ -279,6 +303,8 @@ impl From<Namespace> for PartialEntity { | |||
279 | append_children(&mut children, entity.member_structs); | 303 | append_children(&mut children, entity.member_structs); |
280 | append_children(&mut children, entity.member_functions); | 304 | append_children(&mut children, entity.member_functions); |
281 | append_children(&mut children, entity.member_typedefs); | 305 | append_children(&mut children, entity.member_typedefs); |
306 | append_children(&mut children, entity.member_enums); | ||
307 | |||
282 | PartialEntity { | 308 | PartialEntity { |
283 | properties: Default::default(), | 309 | properties: Default::default(), |
284 | children, | 310 | children, |
@@ -328,6 +354,7 @@ pub(super) struct Struct { | |||
328 | pub(super) member_structs: BTreeMap<Usr, Described<Struct>>, | 354 | pub(super) member_structs: BTreeMap<Usr, Described<Struct>>, |
329 | pub(super) member_functions: BTreeMap<Usr, Described<Function>>, | 355 | pub(super) member_functions: BTreeMap<Usr, Described<Function>>, |
330 | pub(super) member_typedefs: BTreeMap<Usr, Described<Typedef>>, | 356 | pub(super) member_typedefs: BTreeMap<Usr, Described<Typedef>>, |
357 | pub(super) member_enums: BTreeMap<Usr, Described<Enum>>, | ||
331 | } | 358 | } |
332 | 359 | ||
333 | impl ClangEntity for Struct { | 360 | impl ClangEntity for Struct { |
@@ -347,6 +374,9 @@ impl ClangEntity for Struct { | |||
347 | fn get_member_typedefs(&mut self) -> Option<&mut BTreeMap<Usr, Described<Typedef>>> { | 374 | fn get_member_typedefs(&mut self) -> Option<&mut BTreeMap<Usr, Described<Typedef>>> { |
348 | Some(&mut self.member_typedefs) | 375 | Some(&mut self.member_typedefs) |
349 | } | 376 | } |
377 | fn get_member_enums(&mut self) -> Option<&mut BTreeMap<Usr, Described<Enum>>> { | ||
378 | Some(&mut self.member_enums) | ||
379 | } | ||
350 | } | 380 | } |
351 | 381 | ||
352 | impl From<Struct> for PartialEntity { | 382 | impl From<Struct> for PartialEntity { |
@@ -356,6 +386,7 @@ impl From<Struct> for PartialEntity { | |||
356 | append_children(&mut children, entity.member_structs); | 386 | append_children(&mut children, entity.member_structs); |
357 | append_children(&mut children, entity.member_functions); | 387 | append_children(&mut children, entity.member_functions); |
358 | append_children(&mut children, entity.member_typedefs); | 388 | append_children(&mut children, entity.member_typedefs); |
389 | append_children(&mut children, entity.member_enums); | ||
359 | 390 | ||
360 | PartialEntity { | 391 | PartialEntity { |
361 | properties: Default::default(), | 392 | properties: Default::default(), |
@@ -455,3 +486,56 @@ impl From<Typedef> for PartialEntity { | |||
455 | } | 486 | } |
456 | } | 487 | } |
457 | } | 488 | } |
489 | |||
490 | #[derive(Debug, Clone)] | ||
491 | pub(super) struct Enum { | ||
492 | pub(super) underlying_type: String, | ||
493 | pub(super) constants: BTreeMap<Usr, Described<EnumConstant>>, | ||
494 | } | ||
495 | |||
496 | impl ClangEntity for Enum { | ||
497 | fn kind(&self) -> ClangEntityKind { | ||
498 | ClangEntityKind::Enum | ||
499 | } | ||
500 | } | ||
501 | |||
502 | impl From<Enum> for PartialEntity { | ||
503 | fn from(entity: Enum) -> Self { | ||
504 | let mut properties = Map::with_capacity(1); | ||
505 | properties.insert( | ||
506 | String::from("underlying-type"), | ||
507 | JSONValue::String(entity.underlying_type), | ||
508 | ); | ||
509 | |||
510 | let mut children = Default::default(); | ||
511 | append_children(&mut children, entity.constants); | ||
512 | |||
513 | PartialEntity { | ||
514 | properties, | ||
515 | children, | ||
516 | } | ||
517 | } | ||
518 | } | ||
519 | |||
520 | #[derive(Debug, Clone)] | ||
521 | pub(super) struct EnumConstant { | ||
522 | pub(super) value: String, | ||
523 | } | ||
524 | |||
525 | impl ClangEntity for EnumConstant { | ||
526 | fn kind(&self) -> ClangEntityKind { | ||
527 | ClangEntityKind::EnumConstant | ||
528 | } | ||
529 | } | ||
530 | |||
531 | impl From<EnumConstant> for PartialEntity { | ||
532 | fn from(entity: EnumConstant) -> Self { | ||
533 | let mut properties = Map::with_capacity(1); | ||
534 | properties.insert(String::from("value"), JSONValue::String(entity.value)); | ||
535 | |||
536 | PartialEntity { | ||
537 | properties, | ||
538 | children: Default::default(), | ||
539 | } | ||
540 | } | ||
541 | } | ||