Package: POCaseContext

POCaseContext

nameinstructionbranchcomplexitylinemethod
POCaseContext(PPattern, PType, PExp, IPogAssistantFactory)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getContext()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getContextNode(PExp)
M: 0 C: 118
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 23
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.contexts;
25:
26: import java.util.List;
27: import java.util.Vector;
28:
29: import org.overture.ast.definitions.AEqualsDefinition;
30: import org.overture.ast.definitions.PDefinition;
31: import org.overture.ast.expressions.AExistsExp;
32: import org.overture.ast.expressions.AImpliesBooleanBinaryExp;
33: import org.overture.ast.expressions.ALetDefExp;
34: import org.overture.ast.expressions.PExp;
35: import org.overture.ast.factory.AstExpressionFactory;
36: import org.overture.ast.patterns.PMultipleBind;
37: import org.overture.ast.patterns.PPattern;
38: import org.overture.ast.types.ABooleanBasicType;
39: import org.overture.ast.types.PType;
40: import org.overture.pog.pub.IPogAssistantFactory;
41: import org.overture.pog.utility.ContextHelper;
42: import org.overture.pog.utility.UniqueNameGenerator;
43:
44: public class POCaseContext extends POContext
45: {
46:         public final PPattern pattern;
47:         public final PType type;
48:         public final PExp exp;
49:         public final IPogAssistantFactory assistantFactory;
50:
51:         
52:         public POCaseContext(PPattern pattern, PType type, PExp exp,
53:                         IPogAssistantFactory assistantFactory)
54:         {
55:                 this.pattern = pattern;
56:                 this.type = type;
57:                 this.exp = exp;
58:                 this.assistantFactory = assistantFactory;
59:         }
60:
61:         @Override
62:         public PExp getContextNode(PExp stitch)
63:         {
64:•                if (assistantFactory.createPPatternAssistant(null).isSimple(pattern))
65:                 {
66:                         PExp matching = patternToExp(pattern,assistantFactory,new UniqueNameGenerator(exp));
67:                         PExp premise = AstExpressionFactory.newAEqualsBinaryExp(matching.clone(), exp.clone());
68:                         AImpliesBooleanBinaryExp impliesExp = AstExpressionFactory.newAImpliesBooleanBinaryExp(premise, stitch);
69:                         impliesExp.setType(new ABooleanBasicType());
70:                         return impliesExp;
71:                 } else
72:                 {
73:                         AExistsExp existsExp = new AExistsExp();
74:                         List<PMultipleBind> bindList = ContextHelper.bindListFromPattern(pattern.clone(), type.clone());
75:                         existsExp.setBindList(bindList);
76:                         PExp matching = patternToExp(pattern,assistantFactory,new UniqueNameGenerator(exp));
77:
78:                         PExp premise = AstExpressionFactory.newAEqualsBinaryExp(matching.clone(), exp.clone());
79:
80:                         ALetDefExp letDefExp = new ALetDefExp();
81:
82:                         AEqualsDefinition local = new AEqualsDefinition();
83:                         local.setPattern(pattern.clone());
84:                         // local.setName(def.getName().clone());
85:                         local.setTest(exp.clone());
86:                         List<PDefinition> lDefs = new Vector<PDefinition>();
87:                         lDefs.add(local);
88:                         letDefExp.setLocalDefs(lDefs);
89:                         letDefExp.setExpression(stitch);
90:
91:                         AImpliesBooleanBinaryExp impliesExp = AstExpressionFactory.newAImpliesBooleanBinaryExp(premise, letDefExp);
92:                         impliesExp.setType(new ABooleanBasicType());
93:                         existsExp.setPredicate(impliesExp);
94:
95:                         return existsExp;
96:                 }
97:
98:         }
99:
100:         @Override
101:         public String getContext()
102:         {
103:                 return "";
104:         }
105: }