private void IdentifyWildCardDecreases(LoopStmt loop, ref WildCardDecreases wildCardParent, Expression expr) { var newWildCard = new WildCardDecreases(expr, loop.Decreases, wildCardParent); wildCardParent.SubDecreases.Add(newWildCard); wildCardParent = newWildCard; }
private int CountWildCards(WildCardDecreases wildCard) { var count = 1; //1 is THIS wildcard foreach (var subWildCard in wildCard.SubDecreases) { count += CountWildCards(subWildCard); } return(count); }
private void FindRemovableTypesInMatchStmt(MatchStmt match, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { foreach (var matchCase in match.Cases) { foreach (var stmt in matchCase.Body) { FindRemovableTypesInStatement(stmt, match, method, wildCardParent, classDecl); } } }
private void IdentifyDecreasesExpression(LoopStmt loop, Method method, ref WildCardDecreases wildCardParent, Expression expr) { if (expr is WildcardExpr) { IdentifyWildCardDecreases(loop, ref wildCardParent, expr); } else { _allRemovableTypes.AddDecreases(new Wrap <Expression>(expr, loop.Decreases.Expressions), method); } }
private void FindRemovableTypesInLoopStmt(LoopStmt loopStmt, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { GetLoopInvariants(loopStmt, method); IdentifyRemovableDecreasesTypesInLoop(loopStmt, method, ref wildCardParent); if (!(loopStmt is WhileStmt)) { return; } var whileStmt = (WhileStmt)loopStmt; FindRemovableTypesInStatement(whileStmt.Body, loopStmt, method, wildCardParent, classDecl); }
public void RemoveWildCardDecreases(WildCardDecreases wildCardDecreases) { foreach (var removableTypesInMethods in RemovableTypesInMethods) { if (!removableTypesInMethods.Value.WildCardDecreaseses.Contains(wildCardDecreases)) { continue; } removableTypesInMethods.Value.WildCardDecreaseses.Remove(wildCardDecreases); return; } }
private void FindDecreasesTypesInMethodFunction(Specification <Expression> decreases, ref WildCardDecreases wildCardParent, MemberDecl member) { foreach (var expression in decreases.Expressions) { if (expression is WildcardExpr) { wildCardParent = new WildCardDecreases(expression, decreases, null); _allRemovableTypes.AddWildCardDecreases(wildCardParent, (Method)member); continue; } _allRemovableTypes.AddDecreases(new Wrap <Expression>(expression, decreases.Expressions), member); } }
private void FindRemovableTypesInMethod(Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { if (method.Body == null) { return; } var block = method.Body; foreach (var statement in block.Body) { FindRemovableTypesInStatement(statement, block, method, wildCardParent, classDecl); } }
private void FindRemovableTypesInMember(MemberDecl member, ClassDecl classDecl) { if (member is Tactic) { return; } WildCardDecreases wildCardParent = null; // The parent of the current wildCard we are tracking FindDecreasesTypesInMember(member, ref wildCardParent); var method = member as Method; if (method != null) { FindRemovableTypesInMethod(method, wildCardParent, classDecl); } }
private void FindDecreasesTypesInMember(MemberDecl member, ref WildCardDecreases wildCardParent) { Specification <Expression> decreases = null; if (member is Method) { var method = (Method)member; decreases = method.Decreases; } else if (member is Function) { var function = (Function)member; decreases = function.Decreases; } if (decreases != null) { FindDecreasesTypesInMethodFunction(decreases, ref wildCardParent, member); } }
public void RemoveWildCardDecreases(WildCardDecreases wildCardDecreases) { foreach (var removableTypesInMethods in RemovableTypesInMethods) { if (!removableTypesInMethods.Value.WildCardDecreaseses.Contains(wildCardDecreases)) continue; removableTypesInMethods.Value.WildCardDecreaseses.Remove(wildCardDecreases); return; } }
private void FindRemovableTypesInIfStmt(IfStmt ifstmt, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { FindRemovableTypesInStatement(ifstmt.Thn, ifstmt, method, wildCardParent, classDecl); FindRemovableTypesInStatement(ifstmt.Els, ifstmt, method, wildCardParent, classDecl); }
private void FindRemovableTypesInStatement(Statement statement, Statement parent, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { if (statement is AssertStmt) FindRemovableTypesInAssertStmt((AssertStmt) statement, parent, method); else if (statement is BlockStmt) FindRemovableTypesInBlockStmt((BlockStmt) statement, method, wildCardParent, classDecl); else if (statement is IfStmt) FindRemovableTypesInIfStmt((IfStmt) statement, method, wildCardParent, classDecl); else if (statement is LoopStmt) FindRemovableTypesInLoopStmt((LoopStmt) statement, method, wildCardParent, classDecl); else if (statement is MatchStmt) FindRemovableTypesInMatchStmt((MatchStmt) statement, method, wildCardParent, classDecl); else if (statement is ForallStmt) FindRemovableTypesInForallStmt((ForallStmt) statement, method, wildCardParent, classDecl); else if (statement is CalcStmt) FindRemovableTypesInCalcStmt((CalcStmt) statement, parent, method, wildCardParent, classDecl); else if (statement is UpdateStmt) FindRemovableTypesInUpdateStmt((UpdateStmt) statement, parent, method, classDecl); }
private void FindRemovableTypesInStatement(Statement statement, Statement parent, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { if (statement is AssertStmt) { FindRemovableTypesInAssertStmt((AssertStmt)statement, parent, method); } else if (statement is BlockStmt) { FindRemovableTypesInBlockStmt((BlockStmt)statement, method, wildCardParent, classDecl); } else if (statement is IfStmt) { FindRemovableTypesInIfStmt((IfStmt)statement, method, wildCardParent, classDecl); } else if (statement is LoopStmt) { FindRemovableTypesInLoopStmt((LoopStmt)statement, method, wildCardParent, classDecl); } else if (statement is MatchStmt) { FindRemovableTypesInMatchStmt((MatchStmt)statement, method, wildCardParent, classDecl); } else if (statement is ForallStmt) { FindRemovableTypesInForallStmt((ForallStmt)statement, method, wildCardParent, classDecl); } else if (statement is CalcStmt) { FindRemovableTypesInCalcStmt((CalcStmt)statement, parent, method, wildCardParent, classDecl); } else if (statement is UpdateStmt) { FindRemovableTypesInUpdateStmt((UpdateStmt)statement, parent, method, classDecl); } }
private void IdentifyDecreasesExpression(LoopStmt loop, Method method, ref WildCardDecreases wildCardParent, Expression expr) { if (expr is WildcardExpr) IdentifyWildCardDecreases(loop, ref wildCardParent, expr); else _allRemovableTypes.AddDecreases(new Wrap<Expression>(expr, loop.Decreases.Expressions), method); }
private void IdentifyRemovableDecreasesTypesInLoop(LoopStmt loop, Method method, ref WildCardDecreases wildCardParent) { foreach (var expr in loop.Decreases.Expressions) { IdentifyDecreasesExpression(loop, method, ref wildCardParent, expr); } }
private void FindRemovableTypesInLoopStmt(LoopStmt loopStmt, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { GetLoopInvariants(loopStmt, method); IdentifyRemovableDecreasesTypesInLoop(loopStmt, method, ref wildCardParent); if (!(loopStmt is WhileStmt)) return; var whileStmt = (WhileStmt) loopStmt; FindRemovableTypesInStatement(whileStmt.Body, loopStmt, method, wildCardParent, classDecl); }
private void FindRemovableTypesInMatchStmt(MatchStmt match, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { foreach (var matchCase in match.Cases) foreach (var stmt in matchCase.Body) FindRemovableTypesInStatement(stmt, match, method, wildCardParent, classDecl); }
private void FindRemovableTypesInForallStmt(ForallStmt forall, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { FindRemovableTypesInStatement(forall.Body, forall, method, wildCardParent, classDecl); }
private void FindRemovableTypesInCalcStmt(CalcStmt calc, Statement parent, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { Wrap<Statement> calcWrap = null; if (parent is BlockStmt) calcWrap = new Wrap<Statement>(calc, ((BlockStmt)parent).Body); else if (parent is MatchStmt) { var matchStmt = (MatchStmt) parent; foreach (var matchCase in matchStmt.Cases) { if (!matchCase.Body.Contains(calc)) continue; calcWrap = new Wrap<Statement>(calc, matchCase.Body); break; } if (calcWrap == null) throw new Exception("Calc not found!"); } else { throw new Exception("Calc not found!"); } _allRemovableTypes.AddCalc(calcWrap, method); foreach (var hint in calc.Hints) { FindRemovableTypesInStatement(hint, calc, method, wildCardParent, classDecl); // This will check the inside of the hint - it will ID anything that can be shortened inside it. } }
private void FindDecreasesTypesInMethodFunction(Specification<Expression> decreases, ref WildCardDecreases wildCardParent, MemberDecl member) { foreach (var expression in decreases.Expressions) { if (expression is WildcardExpr) { wildCardParent = new WildCardDecreases(expression, decreases, null); _allRemovableTypes.AddWildCardDecreases(wildCardParent, (Method) member); continue; } _allRemovableTypes.AddDecreases(new Wrap<Expression>(expression, decreases.Expressions), member); } }
private void FindRemovableTypesInCalcStmt(CalcStmt calc, Statement parent, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { Wrap <Statement> calcWrap = null; if (parent is BlockStmt) { calcWrap = new Wrap <Statement>(calc, ((BlockStmt)parent).Body); } else if (parent is MatchStmt) { var matchStmt = (MatchStmt)parent; foreach (var matchCase in matchStmt.Cases) { if (!matchCase.Body.Contains(calc)) { continue; } calcWrap = new Wrap <Statement>(calc, matchCase.Body); break; } if (calcWrap == null) { throw new Exception("Calc not found!"); } } else { throw new Exception("Calc not found!"); } _allRemovableTypes.AddCalc(calcWrap, method); foreach (var hint in calc.Hints) { FindRemovableTypesInStatement(hint, calc, method, wildCardParent, classDecl); // This will check the inside of the hint - it will ID anything that can be shortened inside it. } }
private void FindRemovableTypesInMethod(Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { if (method.Body == null) return; var block = method.Body; foreach (var statement in block.Body) FindRemovableTypesInStatement(statement, block, method, wildCardParent, classDecl); }
private void FindDecreasesTypesInMember(MemberDecl member, ref WildCardDecreases wildCardParent) { Specification<Expression> decreases = null; if (member is Method) { var method = (Method) member; decreases = method.Decreases; } else if (member is Function) { var function = (Function) member; decreases = function.Decreases; } if (decreases != null) FindDecreasesTypesInMethodFunction(decreases, ref wildCardParent, member); }
private void FindRemovableTypesInBlockStmt(BlockStmt blockStmt, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { foreach (var stmt in blockStmt.Body) FindRemovableTypesInStatement(stmt, blockStmt, method, wildCardParent, classDecl); }
public void AddWildCardDecreases(WildCardDecreases wildCardDecreases, MemberDecl member) { AddMember(member); RemovableTypesInMethods[member].WildCardDecreaseses.Add(wildCardDecreases); }
private void FindRemovableTypesInBlockStmt(BlockStmt blockStmt, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl) { foreach (var stmt in blockStmt.Body) { FindRemovableTypesInStatement(stmt, blockStmt, method, wildCardParent, classDecl); } }