-
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 5 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 | ||||
---|---|---|---|---|---|---|
|
@@ -56,6 +56,67 @@ impl ControlPoint { | |||||
false | ||||||
} | ||||||
} | ||||||
|
||||||
/// Returns a string showing the path from the root node to input node. | ||||||
/// How to get context? | ||||||
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. remove |
||||||
pub fn string_path(&self, ctx: &Context) -> String { | ||||||
// Does it matter if it takes ownership? | ||||||
let path = SearchPath::find_path_from_root(self.control_node_idx, ctx); | ||||||
let control_map = &ctx.primary.control; | ||||||
let mut string_path = String::from(""); | ||||||
let mut count = -1; | ||||||
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. Prefer
Suggested change
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 guess my suggestion thing is just cursed, this also belongs on the line above |
||||||
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.path { | ||||||
// 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; | ||||||
} | ||||||
_ => {} | ||||||
}; | ||||||
// At root, at end to process logic above. | ||||||
if string_path.is_empty() { | ||||||
string_path += "."; | ||||||
continue; | ||||||
} | ||||||
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. Hoist this out of the for loop and use in initialization of the |
||||||
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.
This
&
is unnecessaryThere 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 have no idea why this ended up on the wrong line