diff options
Diffstat (limited to 'src/parser/clang/entities.rs')
-rw-r--r-- | src/parser/clang/entities.rs | 79 |
1 files changed, 6 insertions, 73 deletions
diff --git a/src/parser/clang/entities.rs b/src/parser/clang/entities.rs index 7b98e88..e6fe59d 100644 --- a/src/parser/clang/entities.rs +++ b/src/parser/clang/entities.rs | |||
@@ -91,13 +91,6 @@ pub(super) struct Described<T> { | |||
91 | type DescribedDynEntity = Described<DynEntity>; | 91 | type DescribedDynEntity = Described<DynEntity>; |
92 | 92 | ||
93 | impl<T: Entity> Described<T> { | 93 | impl<T: Entity> Described<T> { |
94 | fn to_dyn(&self) -> DescribedRef<DynEntityRef> { | ||
95 | DescribedRef { | ||
96 | description: &self.description, | ||
97 | entity: self.entity.to_dyn(), | ||
98 | } | ||
99 | } | ||
100 | |||
101 | #[allow(clippy::wrong_self_convention)] | 94 | #[allow(clippy::wrong_self_convention)] |
102 | fn to_dyn_mut(&mut self) -> DescribedRefMut<DynEntityRefMut> { | 95 | fn to_dyn_mut(&mut self) -> DescribedRefMut<DynEntityRefMut> { |
103 | DescribedRefMut { | 96 | DescribedRefMut { |
@@ -114,9 +107,9 @@ where | |||
114 | type Error = Error; | 107 | type Error = Error; |
115 | 108 | ||
116 | fn try_from(entity: clang::Entity<'a>) -> Result<Self, Error> { | 109 | fn try_from(entity: clang::Entity<'a>) -> Result<Self, Error> { |
117 | Ok(Described::<T> { | 110 | Ok(Described { |
118 | description: entity.try_into()?, | 111 | description: entity.try_into()?, |
119 | entity: T::try_from(entity)?, | 112 | entity: entity.try_into()?, |
120 | }) | 113 | }) |
121 | } | 114 | } |
122 | } | 115 | } |
@@ -138,21 +131,13 @@ impl<T: Entity + Into<PartialEntity>> From<Described<T>> for types::Entity { | |||
138 | } | 131 | } |
139 | } | 132 | } |
140 | 133 | ||
141 | #[derive(Debug, Clone)] | 134 | #[derive(Debug)] |
142 | pub(super) struct DescribedRef<'a, T> { | 135 | pub(super) struct DescribedRefMut<'d, T> { |
143 | pub description: &'a Description, | 136 | pub description: &'d mut Description, |
144 | pub entity: T, | ||
145 | } | ||
146 | |||
147 | type DescribedDynEntityRef<'d, 'e> = DescribedRef<'d, DynEntityRef<'e>>; | ||
148 | |||
149 | #[derive(Debug, Clone)] | ||
150 | pub(super) struct DescribedRefMut<'a, T> { | ||
151 | pub description: &'a Description, | ||
152 | pub entity: T, | 137 | pub entity: T, |
153 | } | 138 | } |
154 | 139 | ||
155 | type DescribedDynEntityRefMut<'a, 'b> = DescribedRefMut<'a, DynEntityRefMut<'b>>; | 140 | type DescribedDynEntityRefMut<'d, 'e> = DescribedRefMut<'d, DynEntityRefMut<'e>>; |
156 | 141 | ||
157 | impl<'d, 'e, T: Entity> DescribedRefMut<'d, &'e mut T> { | 142 | impl<'d, 'e, T: Entity> DescribedRefMut<'d, &'e mut T> { |
158 | fn from_dyn_mut(dyn_entity: DescribedDynEntityRefMut<'d, 'e>) -> Option<Self> { | 143 | fn from_dyn_mut(dyn_entity: DescribedDynEntityRefMut<'d, 'e>) -> Option<Self> { |
@@ -166,19 +151,13 @@ impl<'d, 'e, T: Entity> DescribedRefMut<'d, &'e mut T> { | |||
166 | pub(super) trait Entity: Traversable + KindName { | 151 | pub(super) trait Entity: Traversable + KindName { |
167 | const KIND: EntityKind; | 152 | const KIND: EntityKind; |
168 | 153 | ||
169 | fn from_dyn(dyn_entity: DynEntity) -> Option<Self> | ||
170 | where | ||
171 | Self: Sized; | ||
172 | fn from_dyn_ref(dyn_entity: DynEntityRef) -> Option<&Self>; | ||
173 | fn from_dyn_mut(dyn_entity: DynEntityRefMut) -> Option<&mut Self>; | 154 | fn from_dyn_mut(dyn_entity: DynEntityRefMut) -> Option<&mut Self>; |
174 | fn into_dyn(self) -> DynEntity; | 155 | fn into_dyn(self) -> DynEntity; |
175 | fn to_dyn(&self) -> DynEntityRef; | ||
176 | fn to_dyn_mut(&mut self) -> DynEntityRefMut; | 156 | fn to_dyn_mut(&mut self) -> DynEntityRefMut; |
177 | } | 157 | } |
178 | 158 | ||
179 | pub(super) trait Traversable { | 159 | pub(super) trait Traversable { |
180 | fn has_child_from_kind(&self, usr: &Usr, kind: EntityKind) -> bool; | 160 | fn has_child_from_kind(&self, usr: &Usr, kind: EntityKind) -> bool; |
181 | fn get_child_from_kind(&self, usr: &Usr, kind: EntityKind) -> Option<DescribedDynEntityRef>; | ||
182 | fn get_mut_child_from_kind( | 161 | fn get_mut_child_from_kind( |
183 | &mut self, | 162 | &mut self, |
184 | usr: &Usr, | 163 | usr: &Usr, |
@@ -243,20 +222,6 @@ macro_rules! entity { | |||
243 | impl Entity for $name { | 222 | impl Entity for $name { |
244 | const KIND: EntityKind = EntityKind::$name; | 223 | const KIND: EntityKind = EntityKind::$name; |
245 | 224 | ||
246 | fn from_dyn(dyn_entity: DynEntity) -> Option<Self> { | ||
247 | match dyn_entity { | ||
248 | DynEntity::$name(me) => Some(me), | ||
249 | _ => None, | ||
250 | } | ||
251 | } | ||
252 | |||
253 | fn from_dyn_ref(dyn_entity: DynEntityRef) -> Option<&Self> { | ||
254 | match dyn_entity { | ||
255 | DynEntityRef::$name(me) => Some(me), | ||
256 | _ => None, | ||
257 | } | ||
258 | } | ||
259 | |||
260 | fn from_dyn_mut(dyn_entity: DynEntityRefMut) -> Option<&mut Self> { | 225 | fn from_dyn_mut(dyn_entity: DynEntityRefMut) -> Option<&mut Self> { |
261 | match dyn_entity { | 226 | match dyn_entity { |
262 | DynEntityRefMut::$name(me) => Some(me), | 227 | DynEntityRefMut::$name(me) => Some(me), |
@@ -268,10 +233,6 @@ macro_rules! entity { | |||
268 | DynEntity::$name(self) | 233 | DynEntity::$name(self) |
269 | } | 234 | } |
270 | 235 | ||
271 | fn to_dyn(&self) -> DynEntityRef { | ||
272 | DynEntityRef::$name(self) | ||
273 | } | ||
274 | |||
275 | fn to_dyn_mut(&mut self) -> DynEntityRefMut { | 236 | fn to_dyn_mut(&mut self) -> DynEntityRefMut { |
276 | DynEntityRefMut::$name(self) | 237 | DynEntityRefMut::$name(self) |
277 | } | 238 | } |
@@ -289,22 +250,6 @@ macro_rules! entity { | |||
289 | } | 250 | } |
290 | 251 | ||
291 | #[allow(unused_variables, unreachable_patterns)] | 252 | #[allow(unused_variables, unreachable_patterns)] |
292 | fn get_child_from_kind( | ||
293 | &self, | ||
294 | usr: &Usr, | ||
295 | kind: EntityKind | ||
296 | ) -> Option<DescribedDynEntityRef> { | ||
297 | match kind { | ||
298 | $($( | ||
299 | EntityKind::$child_type => { | ||
300 | self.$child_name.get(usr).map(Described::to_dyn) | ||
301 | } | ||
302 | )*)? | ||
303 | _ => None, | ||
304 | } | ||
305 | } | ||
306 | |||
307 | #[allow(unused_variables, unreachable_patterns)] | ||
308 | fn get_mut_child_from_kind( | 253 | fn get_mut_child_from_kind( |
309 | &mut self, | 254 | &mut self, |
310 | usr: &Usr, | 255 | usr: &Usr, |
@@ -403,7 +348,6 @@ impl From<TopLevel> for types::Entity { | |||
403 | } | 348 | } |
404 | } | 349 | } |
405 | 350 | ||
406 | // TODO: Probably remove NoParent in favor of the Error variant of Result | ||
407 | #[derive(Debug)] | 351 | #[derive(Debug)] |
408 | pub(super) enum EntityEntry<'d, 'e, T> { | 352 | pub(super) enum EntityEntry<'d, 'e, T> { |
409 | Vacant { | 353 | Vacant { |
@@ -503,17 +447,6 @@ pub(super) enum DynEntity { | |||
503 | TypeAlias(TypeAlias), | 447 | TypeAlias(TypeAlias), |
504 | } | 448 | } |
505 | 449 | ||
506 | #[derive(Debug, Clone, Copy)] | ||
507 | pub(super) enum DynEntityRef<'a> { | ||
508 | Namespace(&'a Namespace), | ||
509 | Variable(&'a Variable), | ||
510 | Struct(&'a Struct), | ||
511 | Function(&'a Function), | ||
512 | Enum(&'a Enum), | ||
513 | EnumConstant(&'a EnumConstant), | ||
514 | TypeAlias(&'a TypeAlias), | ||
515 | } | ||
516 | |||
517 | #[derive(Debug)] | 450 | #[derive(Debug)] |
518 | pub(super) enum DynEntityRefMut<'a> { | 451 | pub(super) enum DynEntityRefMut<'a> { |
519 | Namespace(&'a mut Namespace), | 452 | Namespace(&'a mut Namespace), |