-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor how superclasses and superprotocols are stored
We need to know their "spatial" layout to do further analysis, i.e. need to know the entire tree of which protocol needs which superprotocol.
- Loading branch information
Showing
7 changed files
with
302 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::iter; | ||
|
||
use clang::{Entity, EntityKind}; | ||
|
||
use crate::{immediate_children, Context, ItemIdentifier}; | ||
|
||
/// Parse the directly referenced protocols of a declaration. | ||
pub(crate) fn parse_direct_protocols<'clang>( | ||
entity: &Entity<'clang>, | ||
_context: &Context<'_>, | ||
) -> Vec<Entity<'clang>> { | ||
let mut protocols = Vec::new(); | ||
|
||
#[allow(clippy::single_match)] | ||
immediate_children(entity, |child, _span| match child.get_kind() { | ||
EntityKind::ObjCProtocolRef => { | ||
let child = child | ||
.get_reference() | ||
.expect("ObjCProtocolRef to reference entity"); | ||
if child == *entity { | ||
error!(?entity, "recursive protocol"); | ||
} else { | ||
protocols.push(child); | ||
} | ||
} | ||
_ => {} | ||
}); | ||
|
||
protocols | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct ProtocolRef { | ||
pub(crate) id: ItemIdentifier, | ||
pub(crate) super_protocols: Vec<ProtocolRef>, | ||
} | ||
|
||
impl ProtocolRef { | ||
pub(crate) fn super_protocols(entity: &Entity<'_>, context: &Context<'_>) -> Vec<Self> { | ||
let mut super_protocols = Vec::new(); | ||
|
||
for entity in parse_direct_protocols(entity, context) { | ||
super_protocols.push(ProtocolRef::from_entity(&entity, context)); | ||
} | ||
|
||
super_protocols | ||
} | ||
|
||
pub(crate) fn from_entity(entity: &Entity<'_>, context: &Context<'_>) -> Self { | ||
let mut super_protocols = Vec::new(); | ||
|
||
for entity in parse_direct_protocols(entity, context) { | ||
super_protocols.push(ProtocolRef::from_entity(&entity, context)); | ||
} | ||
|
||
Self { | ||
id: context.replace_protocol_name(ItemIdentifier::new(&entity, context)), | ||
super_protocols, | ||
} | ||
} | ||
|
||
pub(crate) fn required_items(&self) -> Vec<ItemIdentifier> { | ||
self.super_protocols | ||
.iter() | ||
.flat_map(|super_protocol| super_protocol.required_items()) | ||
.chain(iter::once(self.id.clone())) | ||
.chain(iter::once(ItemIdentifier::objc("__macros__"))) | ||
.collect() | ||
} | ||
} |
Oops, something went wrong.