/*public override void CaseAValueReturnStm(AValueReturnStm node) * { * GetNode(node); * PStm stm = GetNext(whileStm); * if (stm != null) * graphNode.AddSucc(GetNode(stm)); * }*/ public override void CaseAIfThenStm(AIfThenStm node) { //Create graph node Node graphNode = GetNode(node); //Process inner if node.GetBody().Apply(this); //Add successor and predessors PStm stm = GetFirst(node.GetBody()); if (stm != null) { graphNode.AddSucc(GetNode(stm)); } stm = GetNext(node); if (stm != null) { Node nextGraphNode = GetNode(stm); graphNode.AddSucc(nextGraphNode); List <PStm> stms = GetLast(node.GetBody()); foreach (PStm pStm in stms) { nextGraphNode.AddPred(GetNode(pStm)); } } }
public override void CaseAIfThenStm(AIfThenStm node) { Write("if("); node.GetCondition().Apply(this); Write(")\n"); node.GetBody().Apply(this); }
public override void OutAIfThenStm(AIfThenStm node) { bool value; if (IsConst(node.GetCondition(), out value)) { if (value) { node.ReplaceBy(node.GetBody()); } else { node.Parent().RemoveChild(node); } changedSomething = true; } }
//Returns true if execution cannot continue after the stm private bool removeDeadCode(PStm stm) { if (stm is ABreakStm || stm is AContinueStm || stm is AVoidReturnStm || stm is AValueReturnStm) { return(true); } if (stm is AIfThenStm) { AIfThenStm aStm = (AIfThenStm)stm; bool stopped = removeDeadCode(aStm.GetBody()); if (IsBoolConst(aStm.GetCondition(), true)) { return(stopped); } return(false); } if (stm is AIfThenElseStm) { AIfThenElseStm aStm = (AIfThenElseStm)stm; bool stopped1 = removeDeadCode(aStm.GetThenBody()); if (IsBoolConst(aStm.GetCondition(), true)) { return(stopped1); } bool stopped2 = removeDeadCode(aStm.GetElseBody()); if (IsBoolConst(aStm.GetCondition(), false)) { return(stopped2); } return(stopped1 && stopped2); } if (stm is AWhileStm) { AWhileStm aStm = (AWhileStm)stm; removeDeadCode(aStm.GetBody()); return(false); } if (stm is ABlockStm) { ABlockStm aStm = (ABlockStm)stm; return(removeDeadCode((AABlock)aStm.GetBlock())); } return(false); }
public override void CaseAIfThenStm(AIfThenStm node) { node.GetBody().Apply(this); }