Package: FuncIterationObligation

FuncIterationObligation

nameinstructionbranchcomplexitylinemethod
FuncIterationObligation(AStarStarBinaryExp, ILexNameToken, IPOContextStack, IPogAssistantFactory)
M: 0 C: 68
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
getImplies(PExp, PExp, ILexNameToken, ILexNameToken)
M: 0 C: 40
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getPredicate(AStarStarBinaryExp, ILexNameToken, ILexNameToken)
M: 36 C: 12
25%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 7 C: 2
22%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.pog.obligation;
25:
26: import java.util.LinkedList;
27: import java.util.List;
28:
29: import org.overture.ast.analysis.AnalysisException;
30: import org.overture.ast.expressions.AApplyExp;
31: import org.overture.ast.expressions.AForAllExp;
32: import org.overture.ast.expressions.AGreaterNumericBinaryExp;
33: import org.overture.ast.expressions.AImpliesBooleanBinaryExp;
34: import org.overture.ast.expressions.AStarStarBinaryExp;
35: import org.overture.ast.expressions.PExp;
36: import org.overture.ast.factory.AstExpressionFactory;
37: import org.overture.ast.intf.lex.ILexNameToken;
38: import org.overture.ast.lex.LexNameToken;
39: import org.overture.ast.patterns.PMultipleBind;
40: import org.overture.pog.pub.IPOContextStack;
41: import org.overture.pog.pub.IPogAssistantFactory;
42: import org.overture.pog.pub.POType;
43:
44: public class FuncIterationObligation extends ProofObligation
45: {
46:         /**
47:          * VDM Bits: f: nat -> nat1 f(a) == a + 1 pre a < 10; g: nat -> nat g(n) == (f ** n)(0); Generate PO: (forall n:nat
48:          * & n > 1 => forall arg:nat & pre_f(arg) => pre_f(f(arg)))
49:          */
50:
51:         private static final long serialVersionUID = -6041213040266345023L;
52:
53:         public FuncIterationObligation(AStarStarBinaryExp exp,
54:                         ILexNameToken preName, IPOContextStack ctxt,
55:                         IPogAssistantFactory assistantFactory) throws AnalysisException
56:         {
57:                 super(exp, POType.FUNC_ITERATION, ctxt, exp.getLocation(), assistantFactory);
58:
59:                 // n > 1
60:                 AGreaterNumericBinaryExp gTExp = AstExpressionFactory.newAGreaterNumericBinaryExp(exp.getRight().clone(), getIntLiteral(1));
61:
62:                 // forall n :T & P(X)
63:                 AForAllExp forAllExp = new AForAllExp();
64:                 ILexNameToken arg = getUnique("arg");
65:                 List<PMultipleBind> bindList = getMultipleTypeBindList(assistantFactory.createPTypeAssistant().getNumeric(exp.getRight().getType().clone(), null), arg);
66:                 forAllExp.setBindList(bindList);
67:                 forAllExp.setPredicate(getPredicate(exp.clone(), preName.clone(), arg));
68:
69:                 // n > 1 => forall n :T & P(X)
70:                 AImpliesBooleanBinaryExp impliesExp = AstExpressionFactory.newAImpliesBooleanBinaryExp(gTExp, forAllExp);
71:                 
72:                 stitch = impliesExp.clone();
73:                 valuetree.setPredicate(ctxt.getPredWithContext(impliesExp));
74:         }
75:
76:         PExp getImplies(PExp preExp, PExp leftExp, ILexNameToken preName,
77:                         ILexNameToken arg)
78:         {
79:                 // pre_f(a)
80:                 AApplyExp pre_exp = getApplyExp(preExp, getVarExp(arg));
81:
82:                 // f(a)
83:                 AApplyExp left_exp = getApplyExp(leftExp, getVarExp(arg));
84:
85:                 // pre_f(f(a))
86:                 AApplyExp preleft_exp = getApplyExp(pre_exp, left_exp);
87:
88:                 // pre_f(a) => pre_f(f(a))
89:                 AImpliesBooleanBinaryExp impliesExp = AstExpressionFactory.newAImpliesBooleanBinaryExp(pre_exp, preleft_exp);
90:                 
91:                 return impliesExp;
92:
93:         }
94:
95:         private PExp getPredicate(AStarStarBinaryExp exp, ILexNameToken preName,
96:                         ILexNameToken arg)
97:         {
98:•                if (preName != null)
99:                 {
100:
101:                         return getImplies(getVarExp(preName), exp.getLeft(), preName, arg);
102:
103:                 } else
104:                 { // if no existing pre_f, build it
105:                         AApplyExp applyExp = new AApplyExp();
106:
107:                         ILexNameToken prename = new LexNameToken("", "pre_", null);
108:                         applyExp.setRoot(getVarExp(prename));
109:                         List<PExp> argList = new LinkedList<PExp>();
110:                         argList.add(exp.getLeft());
111:                         applyExp.setArgs(argList);
112:
113:                         return getImplies(applyExp, exp.getLeft(), prename, arg);
114:
115:                 }
116:         }
117:
118: }