-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Seq #2346
Seq #2346
Changes from all commits
28d9af4
17fed18
e75a717
a9791c4
5378330
8aab634
0616f94
7dcc195
eb8e4f7
accc1d7
5f8200a
f9bd15f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,67 @@ impl ControlPoint { | |
false | ||
} | ||
} | ||
|
||
/// Returns a string showing the path from the root node to input node. This | ||
/// path is displayed in the minimal metadata path syntax. | ||
pub fn string_path(&self, ctx: &Context) -> String { | ||
let path = SearchPath::find_path_from_root(self.control_node_idx, ctx); | ||
let mut path_vec = path.path; | ||
|
||
// Remove first element since we know it is a root | ||
path_vec.remove(0); | ||
let mut string_path = String::new(); | ||
string_path.push('.'); | ||
let control_map = &ctx.primary.control; | ||
let mut count = -1; | ||
let mut body = false; | ||
let mut if_branches: HashMap<ControlIdx, String> = HashMap::new(); | ||
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this approach is fine and there's no need to change it here, but wanted |
||
for search_node in path_vec { | ||
// The control_idx should exist in the map, so we shouldn't worry about it | ||
// exploding. First SearchNode is root, hence "." | ||
let control_idx = search_node.node; | ||
let control_node = control_map.get(control_idx).unwrap(); | ||
match control_node { | ||
// These are terminal nodes | ||
// ControlNode::Empty(_) => "empty", | ||
// ControlNode::Invoke(_) => "invoke", | ||
// ControlNode::Enable(_) => "enable", | ||
|
||
// These have unbounded children | ||
// ControlNode::Seq(_) => "seq", | ||
// ControlNode::Par(_) => "par", | ||
|
||
// Special cases | ||
ControlNode::If(if_node) => { | ||
if_branches.insert(if_node.tbranch(), String::from("t")); | ||
if_branches.insert(if_node.tbranch(), String::from("f")); | ||
} | ||
ControlNode::While(_) => { | ||
body = true; | ||
} | ||
ControlNode::Repeat(_) => { | ||
body = true; | ||
} | ||
_ => {} | ||
}; | ||
|
||
let control_type = if body { | ||
body = false; | ||
count = -1; | ||
String::from("b") | ||
} else if if_branches.contains_key(&control_idx) { | ||
let (_, branch) = | ||
if_branches.get_key_value(&control_idx).unwrap(); | ||
branch.clone() | ||
} else { | ||
count += 1; | ||
count.to_string() | ||
}; | ||
|
||
string_path = string_path + "-" + &control_type; | ||
} | ||
string_path | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer
new
overfrom
with an empty&str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess my suggestion thing is just cursed, this also belongs on the line above