Package: MapInjectivityComp

MapInjectivityComp

nameinstructionbranchcomplexitylinemethod
MapInjectivityComp(AMapCompMapExp, IPOContextStack, IPogAssistantFactory)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
MapInjectivityComp(PExp, IPOContextStack, IPogAssistantFactory)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
buildPredicate(PExp)
M: 0 C: 203
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 41
100%
M: 0 C: 1
100%
makePattern(ILexNameToken)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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 java.util.LinkedList;
27: import java.util.List;
28:
29: import org.overture.ast.analysis.AnalysisException;
30: import org.overture.ast.expressions.AForAllExp;
31: import org.overture.ast.expressions.AImpliesBooleanBinaryExp;
32: import org.overture.ast.expressions.AMapCompMapExp;
33: import org.overture.ast.expressions.AMapDomainUnaryExp;
34: import org.overture.ast.expressions.ASetCompSetExp;
35: import org.overture.ast.expressions.ASetEnumSetExp;
36: import org.overture.ast.expressions.PExp;
37: import org.overture.ast.factory.AstExpressionFactory;
38: import org.overture.ast.intf.lex.ILexNameToken;
39: import org.overture.ast.patterns.AIdentifierPattern;
40: import org.overture.ast.patterns.ASetMultipleBind;
41: import org.overture.ast.patterns.PMultipleBind;
42: import org.overture.ast.patterns.PPattern;
43: import org.overture.pog.pub.IPOContextStack;
44: import org.overture.pog.pub.IPogAssistantFactory;
45: import org.overture.pog.pub.POType;
46:
47: public class MapInjectivityComp extends ProofObligation
48: {
49:         /**
50:          *
51:          */
52:         private static final long serialVersionUID = 6082219504509442557L;
53:
54:         public MapInjectivityComp(PExp exp, IPOContextStack ctxt,
55:                         IPogAssistantFactory af) throws AnalysisException
56:         {
57:                 super(exp, POType.MAP_INJ_COMP, ctxt, exp.getLocation(), af);
58:
59:                 stitch = buildPredicate(exp.clone());
60:                 valuetree.setPredicate(ctxt.getPredWithContext(stitch));
61:         }
62:
63:         public MapInjectivityComp(AMapCompMapExp exp, IPOContextStack ctxt,
64:                         IPogAssistantFactory af) throws AnalysisException
65:         {
66:                 super(exp, POType.MAP_INJ_COMP, ctxt, exp.getLocation(), af);
67:
68:                 stitch = buildPredicate(exp.clone());
69:                 valuetree.setPredicate(ctxt.getPredWithContext(stitch));
70:         }
71:
72:         private PPattern makePattern(ILexNameToken name)
73:         {
74:                 AIdentifierPattern pattern = new AIdentifierPattern();
75:                 pattern.setName(name);
76:                 return pattern;
77:         }
78:
79:         private PExp buildPredicate(PExp mapExp)
80:         {
81:
82:                 /*
83:                  * forall m1, m2 in set exp & -- set of maps forall d1 in set dom m1, d2 in set dom m2 & (d1 = d2) => (m1(d1) =
84:                  * m2(d2))
85:                  */
86:
87:                 ILexNameToken m1 = getUnique("m");
88:                 ILexNameToken m2 = getUnique("m");
89:
90:                 PPattern p1 = makePattern(m1);
91:                 PPattern p2 = makePattern(m2);
92:
93:                 ASetMultipleBind setBind = new ASetMultipleBind();
94:•                if (mapExp instanceof AMapCompMapExp)
95:                 {
96:                         AMapCompMapExp mapCompExp = (AMapCompMapExp) mapExp;
97:                         ASetCompSetExp setExp = new ASetCompSetExp();
98:                         ASetEnumSetExp setEnumExp = new ASetEnumSetExp();
99:                         List<PExp> member = new LinkedList<PExp>();
100:                         member.add(mapCompExp.getFirst().clone());
101:                         setEnumExp.setMembers(member);
102:                         setExp.setFirst(setEnumExp);
103:                         setExp.setBindings(cloneListMultipleBind(mapCompExp.getBindings()));
104:•                        if (mapCompExp.getPredicate() != null)
105:                         {
106:                                 setExp.setPredicate(mapCompExp.getPredicate().clone());
107:                         }
108:                         setBind.setSet(setExp);
109:                 } else
110:                 {
111:                         setBind.setSet(mapExp.clone());
112:                 }
113:                 List<PPattern> patternList = new LinkedList<PPattern>();
114:                 patternList.add(p1);
115:                 patternList.add(p2);
116:                 setBind.setPlist(patternList);
117:
118:                 AForAllExp domForallExp = new AForAllExp();
119:                 ILexNameToken d1 = getUnique("d");
120:                 ILexNameToken d2 = getUnique("d");
121:
122:                 AMapDomainUnaryExp domM1 = new AMapDomainUnaryExp();
123:                 domM1.setExp(getVarExp(m1));
124:                 AMapDomainUnaryExp domM2 = new AMapDomainUnaryExp();
125:                 domM2.setExp(getVarExp(m2));
126:
127:                 AImpliesBooleanBinaryExp implies = AstExpressionFactory.newAImpliesBooleanBinaryExp(getEqualsExp(getVarExp(d1), getVarExp(d2)), getEqualsExp(getApplyExp(getVarExp(m1), getVarExp(d1)), getApplyExp(getVarExp(m2), getVarExp(d2))));
128:
129:                 List<PMultipleBind> domBinding = getMultipleSetBindList(domM1, d1);
130:                 domBinding.addAll(getMultipleSetBindList(domM2, d2));
131:                 domForallExp.setBindList(domBinding);
132:                 domForallExp.setPredicate(implies);
133:
134:                 AForAllExp forallExp = new AForAllExp();
135:                 List<PMultipleBind> setBindList = new LinkedList<PMultipleBind>();
136:                 setBindList.add(setBind);
137:                 forallExp.setBindList(setBindList);
138:                 forallExp.setPredicate(domForallExp);
139:
140:                 return forallExp;
141:
142:         }
143:
144: }