Package: EquivalenceRelationObligation

EquivalenceRelationObligation

nameinstructionbranchcomplexitylinemethod
EquivalenceRelationObligation(ATypeDefinition, IPOContextStack, IPogAssistantFactory)
M: 0 C: 74
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
makeEqWithApply(PExp, PExp, ATypeDefinition)
M: 0 C: 26
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
makeReflexive(PExp, ATypeDefinition)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
makeSymmetric(PExp, PExp, ATypeDefinition)
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%
makeTransitive(PExp, PExp, AVariableExp, ATypeDefinition)
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
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 org.overture.ast.analysis.AnalysisException;
27: import org.overture.ast.definitions.ATypeDefinition;
28: import org.overture.ast.expressions.*;
29: import org.overture.ast.factory.AstExpressionFactory;
30: import org.overture.ast.factory.AstFactory;
31: import org.overture.ast.types.ABooleanBasicType;
32: import org.overture.pog.pub.IPOContextStack;
33: import org.overture.pog.pub.IPogAssistantFactory;
34: import org.overture.pog.pub.POType;
35:
36: import java.util.List;
37: import java.util.Vector;
38:
39: public class EquivalenceRelationObligation extends ProofObligation
40: {
41:         private static final long serialVersionUID = -3771203462569628826L;
42:
43:         public EquivalenceRelationObligation(ATypeDefinition node,
44:                         IPOContextStack question, IPogAssistantFactory af)
45:                         throws AnalysisException
46:         {
47:                 super(node, POType.EQUIV_REL, question, node.getLocation(), af);
48:
49:                 AVariableExp xExp = getVarExp(getUnique("x"));
50:                 AVariableExp yExp = getVarExp(getUnique("y"));
51:                 AVariableExp zExp = getVarExp(getUnique("z"));
52:
53:                 AForAllExp forallExp = makeRelContext(node,xExp,yExp,zExp);
54:
55:                 PExp andExp1 = makeAnd(makeReflexive(xExp,node),makeSymmetric(xExp,yExp,node));
56:                 PExp andExp2 = makeAnd(andExp1, makeTransitive(xExp,yExp,zExp,node));
57:                 forallExp.setPredicate(andExp2);
58:                 valuetree.setPredicate(forallExp);
59:         }
60:
61:         private PExp makeTransitive(PExp x, PExp y, AVariableExp z,
62:                         ATypeDefinition node)
63:         {
64:                 PExp xyExp = makeEqWithApply(x,y,node);
65:                 PExp yzExp = makeEqWithApply(y,z,node);
66:                 PExp xzExp = makeEqWithApply(x,z,node);
67:                 AAndBooleanBinaryExp andExp = AstExpressionFactory.newAAndBooleanBinaryExp(xyExp,yzExp);
68:                 AImpliesBooleanBinaryExp impExp = AstExpressionFactory.newAImpliesBooleanBinaryExp(andExp,xzExp);
69:                 return impExp;
70:         }
71:
72:         private PExp makeSymmetric(PExp x, PExp y,ATypeDefinition node)
73:         {
74:                 PExp xyExp = makeEqWithApply(x,y,node);
75:                 PExp yxExp = makeEqWithApply(y,x,node);
76:                 PExp impliesExp = AstExpressionFactory.newAImpliesBooleanBinaryExp(xyExp,yxExp);
77:                 return impliesExp;
78:         }
79:
80:         private PExp makeReflexive(PExp xExp, ATypeDefinition node)
81:         {
82:                 PExp applyExp = makeEqWithApply(xExp, xExp, node);
83:                 return applyExp;
84:         }
85:
86:         private PExp makeEqWithApply(PExp l, PExp r, ATypeDefinition node){
87:                 List<PExp> args = new Vector<>();
88:                 args.add(l.clone());
89:                 args.add(r.clone());
90:                 PExp root = AstFactory.newAVariableExp(node.getName().getEqName(node.getLocation()).clone());
91:                 return AstFactory.newAApplyExp(root,args);
92:         }
93: }