Beispiel #1
0
        private void IdentifyWildCardDecreases(LoopStmt loop, ref WildCardDecreases wildCardParent, Expression expr)
        {
            var newWildCard = new WildCardDecreases(expr, loop.Decreases, wildCardParent);

            wildCardParent.SubDecreases.Add(newWildCard);
            wildCardParent = newWildCard;
        }
Beispiel #2
0
        private int CountWildCards(WildCardDecreases wildCard)
        {
            var count = 1; //1 is THIS wildcard

            foreach (var subWildCard in wildCard.SubDecreases)
            {
                count += CountWildCards(subWildCard);
            }
            return(count);
        }
Beispiel #3
0
 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);
         }
     }
 }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
        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);
        }
Beispiel #6
0
 public void RemoveWildCardDecreases(WildCardDecreases wildCardDecreases)
 {
     foreach (var removableTypesInMethods in RemovableTypesInMethods)
     {
         if (!removableTypesInMethods.Value.WildCardDecreaseses.Contains(wildCardDecreases))
         {
             continue;
         }
         removableTypesInMethods.Value.WildCardDecreaseses.Remove(wildCardDecreases);
         return;
     }
 }
Beispiel #7
0
 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);
     }
 }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
        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);
            }
        }
Beispiel #10
0
        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);
            }
        }
Beispiel #11
0
 public void RemoveWildCardDecreases(WildCardDecreases wildCardDecreases)
 {
     foreach (var removableTypesInMethods in RemovableTypesInMethods) {
         if (!removableTypesInMethods.Value.WildCardDecreaseses.Contains(wildCardDecreases)) continue;
         removableTypesInMethods.Value.WildCardDecreaseses.Remove(wildCardDecreases);
         return;
     }
 }
Beispiel #12
0
 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);
 }
Beispiel #13
0
 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);
 }
Beispiel #14
0
 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);
     }
 }
Beispiel #15
0
 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);
 }
Beispiel #16
0
 private void IdentifyRemovableDecreasesTypesInLoop(LoopStmt loop, Method method, ref WildCardDecreases wildCardParent)
 {
     foreach (var expr in loop.Decreases.Expressions) {
         IdentifyDecreasesExpression(loop, method, ref wildCardParent, expr);
     }
 }
Beispiel #17
0
 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);
 }
Beispiel #18
0
 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);
 }
Beispiel #19
0
 private void FindRemovableTypesInForallStmt(ForallStmt forall, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl)
 {
     FindRemovableTypesInStatement(forall.Body, forall, method, wildCardParent, classDecl);
 }
Beispiel #20
0
        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.
            }

        }
Beispiel #21
0
 private void FindRemovableTypesInForallStmt(ForallStmt forall, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl)
 {
     FindRemovableTypesInStatement(forall.Body, forall, method, wildCardParent, classDecl);
 }
Beispiel #22
0
 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);
     }
 }
Beispiel #23
0
        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.
            }
        }
Beispiel #24
0
 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);
 }
Beispiel #25
0
 private void IdentifyWildCardDecreases(LoopStmt loop, ref WildCardDecreases wildCardParent, Expression expr)
 {
     var newWildCard = new WildCardDecreases(expr, loop.Decreases, wildCardParent);
     wildCardParent.SubDecreases.Add(newWildCard);
     wildCardParent = newWildCard;
 }
Beispiel #26
0
 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);
 }
Beispiel #27
0
 private void IdentifyRemovableDecreasesTypesInLoop(LoopStmt loop, Method method, ref WildCardDecreases wildCardParent)
 {
     foreach (var expr in loop.Decreases.Expressions)
     {
         IdentifyDecreasesExpression(loop, method, ref wildCardParent, expr);
     }
 }
Beispiel #28
0
 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);
 }
Beispiel #29
0
 private void FindRemovableTypesInBlockStmt(BlockStmt blockStmt, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl)
 {
     foreach (var stmt in blockStmt.Body)
         FindRemovableTypesInStatement(stmt, blockStmt, method, wildCardParent, classDecl);
 }
Beispiel #30
0
 public void AddWildCardDecreases(WildCardDecreases wildCardDecreases, MemberDecl member)
 {
     AddMember(member);
     RemovableTypesInMethods[member].WildCardDecreaseses.Add(wildCardDecreases);
 }
Beispiel #31
0
 private void FindRemovableTypesInBlockStmt(BlockStmt blockStmt, Method method, WildCardDecreases wildCardParent, ClassDecl classDecl)
 {
     foreach (var stmt in blockStmt.Body)
     {
         FindRemovableTypesInStatement(stmt, blockStmt, method, wildCardParent, classDecl);
     }
 }
Beispiel #32
0
 public void AddWildCardDecreases(WildCardDecreases wildCardDecreases, MemberDecl member)
 {
     AddMember(member);
     RemovableTypesInMethods[member].WildCardDecreaseses.Add(wildCardDecreases);
 }