Package: POContext

POContext

nameinstructionbranchcomplexitylinemethod
POContext()
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%
checkType(PExp)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getName()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isScopeBoundary()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isStateful()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lastStmt()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
noteType(PExp, PType)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
patternToExp(PPattern, IPogAssistantFactory, UniqueNameGenerator)
M: 3 C: 11
79%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 2
50%
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.HashMap;
27: import java.util.Map;
28:
29: import org.overture.ast.analysis.AnalysisException;
30: import org.overture.ast.expressions.PExp;
31: import org.overture.ast.patterns.PPattern;
32: import org.overture.ast.types.PType;
33: import org.overture.pog.pub.IPOContext;
34: import org.overture.pog.pub.IPogAssistantFactory;
35: import org.overture.pog.utility.UniqueNameGenerator;
36: import org.overture.pog.visitors.PatternToExpVisitor;
37:
38: abstract public class POContext implements IPOContext
39: {
40:         abstract public String getContext();
41:
42:         // abstract public List<INode> getContextNodes(int n);
43:         abstract public PExp getContextNode(PExp stitch);
44:
45:         private Map<PExp, PType> knownTypes = new HashMap<PExp, PType>();
46:
47:         @Override
48:         /**
49:          * Any contexts that can be preserved regardless of state need not override this
50:          */
51:         public boolean isStateful()
52:         {
53:                 return false;
54:         }
55:
56:         /**
57:          * Any context that is not stateful need no override this method as it is not used.
58:          */
59:         @Override
60:         public void lastStmt()
61:         {
62:                 // do nothing. Only relevant for statefuls
63:         }
64:
65:         public String getName()
66:         {
67:                 return ""; // Overridden in PONameContext
68:         }
69:
70:         public boolean isScopeBoundary()
71:         {
72:                 return false;
73:         }
74:
75:         public void noteType(PExp exp, PType type)
76:         {
77:                 knownTypes.put(exp, type);
78:         }
79:
80:         public PType checkType(PExp exp)
81:         {
82:                 return knownTypes.get(exp);
83:         }
84:
85:         /**
86:          * Create an expression equivalent to a pattern.
87:          */
88:         protected PExp patternToExp(PPattern pattern, IPogAssistantFactory af,
89:                         UniqueNameGenerator unq)
90:         {
91:                 PatternToExpVisitor visitor = new PatternToExpVisitor(unq, af);
92:                 try
93:                 {
94:                         return pattern.apply(visitor);
95:                 } catch (AnalysisException e)
96:                 {
97:                         return null;
98:                 }
99:         }
100:
101: }