Package: FiniteSetObligation

FiniteSetObligation

nameinstructionbranchcomplexitylinemethod
FiniteSetObligation(ASetCompSetExp, SSetType, IPOContextStack, IPogAssistantFactory)
M: 0 C: 64
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
getExistsPredicate(ASetCompSetExp, ILexNameToken, ILexNameToken)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getForallExp(ASetCompSetExp, ILexNameToken, ILexNameToken)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getImpliesExists(ASetCompSetExp, ILexNameToken, ILexNameToken)
M: 0 C: 40
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
getImpliesExpression(ASetCompSetExp, ILexNameToken, ILexNameToken)
M: 6 C: 14
70%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
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.List;
27:
28: import org.overture.ast.analysis.AnalysisException;
29: import org.overture.ast.expressions.AApplyExp;
30: import org.overture.ast.expressions.AExistsExp;
31: import org.overture.ast.expressions.AForAllExp;
32: import org.overture.ast.expressions.AMapDomainUnaryExp;
33: import org.overture.ast.expressions.ASetCompSetExp;
34: import org.overture.ast.expressions.PExp;
35: import org.overture.ast.factory.AstExpressionFactory;
36: import org.overture.ast.intf.lex.ILexNameToken;
37: import org.overture.ast.patterns.PMultipleBind;
38: import org.overture.ast.types.ABooleanBasicType;
39: import org.overture.ast.types.AMapMapType;
40: import org.overture.ast.types.ANatNumericBasicType;
41: import org.overture.ast.types.SSetType;
42: import org.overture.pog.pub.IPOContextStack;
43: import org.overture.pog.pub.IPogAssistantFactory;
44: import org.overture.pog.pub.POType;
45:
46: public class FiniteSetObligation extends ProofObligation
47: {
48:
49:         private static final long serialVersionUID = 4471304924561635823L;
50:
51:         /**
52:          * {@code
53: { f(a) | a:A & p(a) } yields exists m:map nat to map A to :f & forall a:A & p(a) => exists idx in set dom m &
54:          * m(idx) = f(a)
55: * }
56:          *
57:          * @param exp
58:          * @param settype
59:          * @param ctxt
60:          * @param af
61:          * @throws AnalysisException
62:          */
63:         public FiniteSetObligation(ASetCompSetExp exp, SSetType settype,
64:                         IPOContextStack ctxt, IPogAssistantFactory af)
65:                         throws AnalysisException
66:         {
67:                 super(exp, POType.FINITE_SET, ctxt, exp.getLocation(), af);
68:
69:                 ILexNameToken finmap = getUnique("finmap");
70:                 ILexNameToken findex = getUnique("findex");
71:
72:                 AExistsExp existsExp = new AExistsExp();
73:
74:                 AMapMapType mapType = new AMapMapType();
75:                 mapType.setFrom(new ANatNumericBasicType());
76:                 mapType.setTo(settype.getSetof().clone());
77:
78:                 existsExp.setBindList(getMultipleTypeBindList(mapType, finmap));
79:                 existsExp.setPredicate(getForallExp(exp.clone(), finmap, findex));
80:
81:                 stitch = existsExp.clone();
82:                 valuetree.setPredicate(ctxt.getPredWithContext(existsExp));
83:         }
84:
85:         /**
86:          * forall a:A & p(a) => exists idx in set dom m & m(idx) = f(a)
87:          */
88:         private PExp getForallExp(ASetCompSetExp exp, ILexNameToken finmap,
89:                         ILexNameToken findex)
90:         {
91:                 AForAllExp forallExp = new AForAllExp();
92:                 forallExp.setBindList(exp.clone().getBindings());
93:                 forallExp.setPredicate(getImpliesExpression(exp, finmap, findex));
94:                 return forallExp;
95:         }
96:
97:         /**
98:          * p(a,b) => exists idx in set dom m & m(idx) = f(a)
99:          */
100:         private PExp getImpliesExpression(ASetCompSetExp exp, ILexNameToken finmap,
101:                         ILexNameToken findex)
102:         {
103:•                if (exp.getPredicate() == null) // set comprehension has no predicate
104:                 {
105:                         return getImpliesExists(exp, finmap, findex);
106:                 } else
107:                 {
108:                         return AstExpressionFactory.newAImpliesBooleanBinaryExp(exp.getPredicate().clone(), getImpliesExists(exp.clone(), finmap, findex));
109:                 }
110:         }
111:
112:         /**
113:          * exists idx in set dom m & m(idx) =f(a)
114:          */
115:         private PExp getImpliesExists(ASetCompSetExp exp, ILexNameToken finmap,
116:                         ILexNameToken findex)
117:         {
118:                 AExistsExp exists = new AExistsExp();
119:
120:                 AMapDomainUnaryExp domExp = new AMapDomainUnaryExp();
121:                 domExp.setType(new ABooleanBasicType());
122:                 domExp.setExp(getVarExp(finmap));
123:                 List<PMultipleBind> bindList = getMultipleSetBindList(domExp, findex);
124:                 exists.setBindList(bindList);
125:
126:                 exists.setPredicate(getExistsPredicate(exp, finmap, findex));
127:                 return exists;
128:         }
129:
130:         /**
131:          * m(idx) = f(a)
132:          */
133:         private PExp getExistsPredicate(ASetCompSetExp exp, ILexNameToken finmap,
134:                         ILexNameToken findex)
135:         {
136:                 AApplyExp apply = getApplyExp(getVarExp(finmap), getVarExp(findex));
137:
138:                 return getEqualsExp(apply, exp.getFirst());
139:         }
140:
141: }