Skip to content

Commit

Permalink
convenience fns
Browse files Browse the repository at this point in the history
  • Loading branch information
livia01px2019 committed Oct 24, 2023
1 parent b32935c commit 6d7433f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
7 changes: 1 addition & 6 deletions crates/paralegal-flow/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,7 @@ where
S: AsRef<std::ffi::OsStr>,
{
paralegal_flow_command(dir)
.args([
"--abort-after-analysis",
"--dump",
"serialized-flow-graph",
"--eager-local-markers",
])
.args(["--abort-after-analysis", "--dump", "serialized-flow-graph"])
.args(extra)
.status()
.unwrap()
Expand Down
26 changes: 16 additions & 10 deletions crates/paralegal-policy/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,24 @@ impl Context {
.flat_map(|v| v.iter())
}

/// Get the type(s) of a Node.
pub fn get_node_types(&self, node: &Node) -> Option<&HashSet<DefId>> {
match node.typ.as_data_source() {
None => None,
Some(src) => self.desc.controllers[&node.ctrl_id].types.get(&src),
}
}

/// Returns whether the given Node has the marker applied to it directly or via its type.
pub fn has_marker(&self, marker: Marker, node: Node) -> bool {
if let Some(src) = node.typ.as_data_source() {
if let Some(typ) = &self.desc.controllers[&node.ctrl_id].types.get(&src) {
if typ.iter().any(|t| {
self.marker_to_ids
.get(&marker)
.map(|markers| markers.iter().any(|(id, _)| id == t))
.unwrap_or(false)
}) {
return true;
}
if let Some(types) = self.get_node_types(&node) {
if types.iter().any(|t| {
self.marker_to_ids
.get(&marker)
.map(|markers| markers.iter().any(|(id, _)| id == t))
.unwrap_or(false)
}) {
return true;
}
}

Expand Down

0 comments on commit 6d7433f

Please sign in to comment.