// ***************************************************************************** // public methods // ***************************************************************************** public static Statement IsHead2Block(Statement head) { if (head.GetLastBasicType() != Statement.Lastbasictype_General) { return(null); } // at most one outgoing edge StatEdge edge = null; List <StatEdge> lstSuccs = head.GetSuccessorEdges(Statedge_Direct_All); if (!(lstSuccs.Count == 0)) { edge = lstSuccs[0]; } if (edge != null && edge.GetType() == StatEdge.Type_Regular) { Statement stat = edge.GetDestination(); if (stat != head && stat.GetPredecessorEdges(StatEdge.Type_Regular).Count == 1 && !stat.IsMonitorEnter()) { if (stat.GetLastBasicType() == Statement.Lastbasictype_General) { if (DecHelper.CheckStatementExceptions(Sharpen.Arrays.AsList(head, stat))) { return(new SequenceStatement(head, stat)); } } } } return(null); }
// ***************************************************************************** // public methods // ***************************************************************************** public static Statement IsHead(Statement head) { if (head.type == Type_Basicblock && head.GetLastBasicType() == Lastbasictype_If) { int regsize = head.GetSuccessorEdges(StatEdge.Type_Regular).Count; Statement p = null; bool ok = (regsize < 2); if (!ok) { List <Statement> lst = new List <Statement>(); if (DecHelper.IsChoiceStatement(head, lst)) { p = lst.RemoveAtReturningValue(0); foreach (Statement st in lst) { if (st.IsMonitorEnter()) { return(null); } } ok = DecHelper.CheckStatementExceptions(lst); } } if (ok) { return(new IfStatement(head, regsize, p)); } } return(null); }
// ***************************************************************************** // public methods // ***************************************************************************** public static Statement IsHead(Statement head) { if (head.GetLastBasicType() != Statement.Lastbasictype_General) { return(null); } HashSet <Statement> setHandlers = DecHelper.GetUniquePredExceptions(head); if (setHandlers.Count != 1) { return(null); } foreach (StatEdge edge in head.GetSuccessorEdges(StatEdge.Type_Exception)) { Statement exc = edge.GetDestination(); if (edge.GetExceptions() == null && exc.GetLastBasicType() == Lastbasictype_General && setHandlers.Contains(exc)) { List <StatEdge> lstSuccs = exc.GetSuccessorEdges(Statedge_Direct_All); if ((lstSuccs.Count == 0) || lstSuccs[0].GetType() != StatEdge.Type_Regular) { if (head.IsMonitorEnter() || exc.IsMonitorEnter()) { return(null); } if (DecHelper.CheckStatementExceptions(Sharpen.Arrays.AsList(head, exc))) { return(new CatchAllStatement(head, exc)); } } } } return(null); }
// post is always null! // ***************************************************************************** // public methods // ***************************************************************************** public static Statement IsHead(Statement head) { if (head.GetLastBasicType() == Lastbasictype_General && !head.IsMonitorEnter()) { // at most one outgoing edge StatEdge edge = null; List <StatEdge> lstSuccs = head.GetSuccessorEdges(Statedge_Direct_All); if (!(lstSuccs.Count == 0)) { edge = lstSuccs[0]; } // regular loop if (edge != null && edge.GetType() == StatEdge.Type_Regular && edge.GetDestination () == head) { return(new DoStatement(head)); } // continues if (head.type != Type_Do && (edge == null || edge.GetType() != StatEdge.Type_Regular ) && head.GetContinueSet().Contains(head.GetBasichead())) { return(new DoStatement(head)); } } return(null); }
private SequenceStatement(Statement head, Statement tail) : this(Sharpen.Arrays.AsList(head, tail)) { List <StatEdge> lstSuccs = tail.GetSuccessorEdges(Statedge_Direct_All); if (!(lstSuccs.Count == 0)) { StatEdge edge = lstSuccs[0]; if (edge.GetType() == StatEdge.Type_Regular && edge.GetDestination() != head) { post = edge.GetDestination(); } } }
public SynchronizedStatement(Statement head, Statement body, Statement exc) : this() { first = head; stats.AddWithKey(head, head.id); this.body = body; stats.AddWithKey(body, body.id); stats.AddWithKey(exc, exc.id); List <StatEdge> lstSuccs = body.GetSuccessorEdges(Statedge_Direct_All); if (!(lstSuccs.Count == 0)) { StatEdge edge = lstSuccs[0]; if (edge.GetType() == StatEdge.Type_Regular) { post = edge.GetDestination(); } } }
private SwitchStatement(Statement head, Statement poststat) : this() { first = head; stats.AddWithKey(head, head.id); // find post node HashSet <Statement> lstNodes = new HashSet <Statement>(head.GetNeighbours(StatEdge. Type_Regular, Direction_Forward)); // cluster nodes if (poststat != null) { post = poststat; lstNodes.Remove(post); } default_edge = head.GetSuccessorEdges(Statement.Statedge_Direct_All)[0]; foreach (Statement st in lstNodes) { stats.AddWithKey(st, st.id); } }
private CatchAllStatement(Statement head, Statement handler) : this() { first = head; stats.AddWithKey(head, head.id); this.handler = handler; stats.AddWithKey(handler, handler.id); List <StatEdge> lstSuccs = head.GetSuccessorEdges(Statedge_Direct_All); if (!(lstSuccs.Count == 0)) { StatEdge edge = lstSuccs[0]; if (edge.GetType() == StatEdge.Type_Regular) { post = edge.GetDestination(); } } vars.Add(new VarExprent(DecompilerContext.GetCounterContainer().GetCounterAndIncrement (CounterContainer.Var_Counter), new VarType(ICodeConstants.Type_Object, 0, "java/lang/Throwable" ), DecompilerContext.GetVarProcessor())); }
private CatchStatement(Statement head, Statement next, HashSet <Statement> setHandlers ) : this() { first = head; stats.AddWithKey(first, first.id); foreach (StatEdge edge in head.GetSuccessorEdges(StatEdge.Type_Exception)) { Statement stat = edge.GetDestination(); if (setHandlers.Contains(stat)) { stats.AddWithKey(stat, stat.id); exctstrings.Add(new List <string>(edge.GetExceptions())); vars.Add(new VarExprent(DecompilerContext.GetCounterContainer().GetCounterAndIncrement (CounterContainer.Var_Counter), new VarType(ICodeConstants.Type_Object, 0, edge. GetExceptions()[0]), DecompilerContext.GetVarProcessor())); } } // FIXME: for now simply the first type. Should get the first common superclass when possible. if (next != null) { post = next; } }
// ***************************************************************************** // public methods // ***************************************************************************** public static Statement IsHead(Statement head) { if (head.GetLastBasicType() != Lastbasictype_General) { return(null); } HashSet <Statement> setHandlers = DecHelper.GetUniquePredExceptions(head); if (!(setHandlers.Count == 0)) { int hnextcount = 0; // either no statements with connection to next, or more than 1 Statement next = null; List <StatEdge> lstHeadSuccs = head.GetSuccessorEdges(Statedge_Direct_All); if (!(lstHeadSuccs.Count == 0) && lstHeadSuccs[0].GetType() == StatEdge.Type_Regular) { next = lstHeadSuccs[0].GetDestination(); hnextcount = 2; } foreach (StatEdge edge in head.GetSuccessorEdges(StatEdge.Type_Exception)) { Statement stat = edge.GetDestination(); bool handlerok = true; if (edge.GetExceptions() != null && setHandlers.Contains(stat)) { if (stat.GetLastBasicType() != Lastbasictype_General) { handlerok = false; } else { List <StatEdge> lstStatSuccs = stat.GetSuccessorEdges(Statedge_Direct_All); if (!(lstStatSuccs.Count == 0) && lstStatSuccs[0].GetType() == StatEdge.Type_Regular) { Statement statn = lstStatSuccs[0].GetDestination(); if (next == null) { next = statn; } else if (next != statn) { handlerok = false; } if (handlerok) { hnextcount++; } } } } else { handlerok = false; } if (!handlerok) { setHandlers.Remove(stat); } } if (hnextcount != 1 && !(setHandlers.Count == 0)) { List <Statement> lst = new List <Statement>(); lst.Add(head); Sharpen.Collections.AddAll(lst, setHandlers); foreach (Statement st in lst) { if (st.IsMonitorEnter()) { return(null); } } if (DecHelper.CheckStatementExceptions(lst)) { return(new CatchStatement(head, next, setHandlers)); } } } return(null); }
private IfStatement(Statement head, int regedges, Statement postst) : this() { first = head; stats.AddWithKey(head, head.id); List <StatEdge> lstHeadSuccs = head.GetSuccessorEdges(Statedge_Direct_All); switch (regedges) { case 0: { ifstat = null; elsestat = null; break; } case 1: { ifstat = null; elsestat = null; StatEdge edgeif = lstHeadSuccs[1]; if (edgeif.GetType() != StatEdge.Type_Regular) { post = lstHeadSuccs[0].GetDestination(); } else { post = edgeif.GetDestination(); negated = true; } break; } case 2: { elsestat = lstHeadSuccs[0].GetDestination(); ifstat = lstHeadSuccs[1].GetDestination(); List <StatEdge> lstSucc = ifstat.GetSuccessorEdges(StatEdge.Type_Regular); List <StatEdge> lstSucc1 = elsestat.GetSuccessorEdges(StatEdge.Type_Regular); if (ifstat.GetPredecessorEdges(StatEdge.Type_Regular).Count > 1 || lstSucc.Count > 1) { post = ifstat; } else if (elsestat.GetPredecessorEdges(StatEdge.Type_Regular).Count > 1 || lstSucc1 .Count > 1) { post = elsestat; } else if (lstSucc.Count == 0) { post = elsestat; } else if (lstSucc1.Count == 0) { post = ifstat; } if (ifstat == post) { if (elsestat != post) { ifstat = elsestat; negated = true; } else { ifstat = null; } elsestat = null; } else if (elsestat == post) { elsestat = null; } else { post = postst; } if (elsestat == null) { regedges = 1; } break; } } // if without else ifedge = lstHeadSuccs[negated ? 0 : 1]; elseedge = (regedges == 2) ? lstHeadSuccs[negated ? 1 : 0] : null; iftype = (regedges == 2) ? Iftype_Ifelse : Iftype_If; if (iftype == Iftype_If) { if (regedges == 0) { StatEdge edge = lstHeadSuccs[0]; head.RemoveSuccessor(edge); edge.SetSource(this); this.AddSuccessor(edge); } else if (regedges == 1) { StatEdge edge = lstHeadSuccs[negated ? 1 : 0]; head.RemoveSuccessor(edge); } } if (ifstat != null) { stats.AddWithKey(ifstat, ifstat.id); } if (elsestat != null) { stats.AddWithKey(elsestat, elsestat.id); } if (post == head) { post = this; } }
public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buf = new TextBuffer(); buf.Append(ExprProcessor.ListToJava(varDefinitions, indent, tracer)); buf.Append(first.ToJava(indent, tracer)); if (IsLabeled()) { buf.AppendIndent(indent).Append("label").Append(this.id.ToString()).Append(":").AppendLineSeparator (); tracer.IncrementCurrentSourceLine(); } buf.AppendIndent(indent).Append(headexprent[0].ToJava(indent, tracer)).Append(" {" ).AppendLineSeparator(); tracer.IncrementCurrentSourceLine(); if (ifstat == null) { bool semicolon = false; if (ifedge.@explicit) { semicolon = true; if (ifedge.GetType() == StatEdge.Type_Break) { // break buf.AppendIndent(indent + 1).Append("break"); } else { // continue buf.AppendIndent(indent + 1).Append("continue"); } if (ifedge.labeled) { buf.Append(" label").Append(ifedge.closure.id.ToString()); } } if (semicolon) { buf.Append(";").AppendLineSeparator(); tracer.IncrementCurrentSourceLine(); } } else { buf.Append(ExprProcessor.JmpWrapper(ifstat, indent + 1, true, tracer)); } bool elseif = false; if (elsestat != null) { if (elsestat.type == Statement.Type_If && (elsestat.varDefinitions.Count == 0) && (elsestat.GetFirst().GetExprents().Count == 0) && !elsestat.IsLabeled() && ((elsestat .GetSuccessorEdges(Statedge_Direct_All).Count == 0) || !elsestat.GetSuccessorEdges (Statedge_Direct_All)[0].@explicit)) { // else if buf.AppendIndent(indent).Append("} else "); TextBuffer content = ExprProcessor.JmpWrapper(elsestat, indent, false, tracer); content.SetStart(TextUtil.GetIndentString(indent).Length); buf.Append(content); elseif = true; } else { BytecodeMappingTracer else_tracer = new BytecodeMappingTracer(tracer.GetCurrentSourceLine () + 1); TextBuffer content = ExprProcessor.JmpWrapper(elsestat, indent + 1, false, else_tracer ); if (content.Length() > 0) { buf.AppendIndent(indent).Append("} else {").AppendLineSeparator(); tracer.SetCurrentSourceLine(else_tracer.GetCurrentSourceLine()); tracer.AddTracer(else_tracer); buf.Append(content); } } } if (!elseif) { buf.AppendIndent(indent).Append("}").AppendLineSeparator(); tracer.IncrementCurrentSourceLine(); } return(buf); }