message: Add while/do-while in CCFG
diff: @@ -24,6 +24,8 @@ pub enum ActionNode {
  Call(String),
  Return,
  If,
  + While,
  + DoWhile,
  Goto,
  Dummy(String),
  DummyGoto,
  @@ -242,7 +244,8 @@ impl CCFG {
  }
  }
  - /// Add ActionNode of if statement
  + /// Add ActionNode of if statement,
  + /// `if_then`, `if_else` is the NodeIndex of first node of ActionNode
  pub fn conditional(&mut self, condition: NodeIndex, if_then: NodeIndex,
  if_else: Option<NodeIndex>, prev_action: NodeIndex) -> NodeIndex {
  let node = self.ast.add_node(CCFGNode::Action(ActionNode::If));
  @@ -257,6 +260,28 @@ impl CCFG {
  node
  }
  + pub fn add_while(&mut self, condition: NodeIndex, body: NodeIndex,
  + prev_action: NodeIndex) -> NodeIndex {
  + let node = self.ast.add_node(CCFGNode::Action(ActionNode::While));
  + self.remove_incoming_actions(body);
  + // TODO replace ActionEdge::IfThen with proper Edge
  + self.ast.add_edge(node, body, CCFGEdge::Action(ActionEdge::IfThen));
  + self.ast.add_edge(node, condition, CCFGEdge::Value(ValueEdge::Conditional));
  + self.ast.add_edge(prev_action, node, CCFGEdge::Action(ActionEdge::Normal));
  + node
  + }
  +
  + pub fn add_do_while(&mut self, condition: NodeIndex, body: NodeIndex,
  + prev_action: NodeIndex) -> NodeIndex {
  + let node = self.ast.add_node(CCFGNode::Action(ActionNode::DoWhile));
  + self.remove_incoming_actions(body);
  + // TODO replace ActionEdge::IfThen with proper Edge
  + self.ast.add_edge(node, body, CCFGEdge::Action(ActionEdge::IfThen));
  + self.ast.add_edge(node, condition, CCFGEdge::Value(ValueEdge::Conditional));
  + self.ast.add_edge(prev_action, node, CCFGEdge::Action(ActionEdge::Normal));
  + node
  + }
  +
  pub fn conditional_insert(&mut self, condition: NodeIndex, if_then: NodeIndex,
  if_else: Option<NodeIndex>, prev: NodeIndex) -> NodeIndex {
  let es = self.ast.edges_directed(prev, Direction::Outgoing)
  @@ -826,6 +851,12 @@ impl<'a> CASTConverter<'a> {
  Some(CCFGNode::Action(ActionNode::DummyGoto)) => {
  // fallthrough
  },
  + Some(CCFGNode::Action(ActionNode::While)) => {
  + unimplemented!()
  + },
  + Some(CCFGNode::Action(ActionNode::DoWhile)) => {
  + unimplemented!()
  + },
  _ => {
  radeco_err!("Unreachable node {:?}", idx);
  unreachable!()
  @@ -1098,4 +1129,24 @@ mod test {
  let output = ast.to_c_ast().print();
  println!("{}", output);
  }
  +
  + #[test]
  + fn simple_c_ast_while_test() {
  + let mut ast = CCFG::new("main");
  + let entry = ast.entry;
  + unimplemented!();
  + CCFGVerifier::verify(&ast).expect("CCFG verification failed");
  + let output = ast.to_c_ast().print();
  + println!("{}", output);
  + }
  +
  + #[test]
  + fn simple_c_ast_do_while_test() {
  + let mut ast = CCFG::new("main");
  + let entry = ast.entry;
  + unimplemented!();
  + CCFGVerifier::verify(&ast).expect("CCFG verification failed");
  + let output = ast.to_c_ast().print();
  + println!("{}", output);
  + }
  }
  