Package: SimplePatternChecker

SimplePatternChecker

nameinstructionbranchcomplexitylinemethod
SimplePatternChecker(ITypeCheckerAssistantFactory)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseAConcatenationPattern(AConcatenationPattern)
M: 10 C: 11
52%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAIdentifierPattern(AIdentifierPattern)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAIgnorePattern(AIgnorePattern)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAMapPattern(AMapPattern)
M: 25 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
caseAMapUnionPattern(AMapUnionPattern)
M: 21 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
caseAObjectPattern(AObjectPattern)
M: 28 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
caseARecordPattern(ARecordPattern)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseASeqPattern(ASeqPattern)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseASetPattern(ASetPattern)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseATuplePattern(ATuplePattern)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAUnionPattern(AUnionPattern)
M: 21 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createNewReturnValue(INode)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createNewReturnValue(Object)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
defaultPPattern(PPattern)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * The VDM Type Checker
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.typechecker.utilities.pattern;
23:
24: import java.util.LinkedList;
25:
26: import org.overture.ast.analysis.AnalysisException;
27: import org.overture.ast.analysis.AnswerAdaptor;
28: import org.overture.ast.node.INode;
29: import org.overture.ast.patterns.AConcatenationPattern;
30: import org.overture.ast.patterns.AIdentifierPattern;
31: import org.overture.ast.patterns.AIgnorePattern;
32: import org.overture.ast.patterns.AMapPattern;
33: import org.overture.ast.patterns.AMapUnionPattern;
34: import org.overture.ast.patterns.AMapletPatternMaplet;
35: import org.overture.ast.patterns.ANamePatternPair;
36: import org.overture.ast.patterns.AObjectPattern;
37: import org.overture.ast.patterns.ARecordPattern;
38: import org.overture.ast.patterns.ASeqPattern;
39: import org.overture.ast.patterns.ASetPattern;
40: import org.overture.ast.patterns.ATuplePattern;
41: import org.overture.ast.patterns.AUnionPattern;
42: import org.overture.ast.patterns.PPattern;
43: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
44:
45: /**
46: * Used to check if a pattern is a simple value.
47: *
48: * @author kel
49: */
50: public class SimplePatternChecker extends AnswerAdaptor<Boolean>
51: {
52:         protected ITypeCheckerAssistantFactory af;
53:
54:         public SimplePatternChecker(ITypeCheckerAssistantFactory af)
55:         {
56:                 this.af = af;
57:         }
58:
59:         @Override
60:         public Boolean caseAConcatenationPattern(AConcatenationPattern pattern)
61:                         throws AnalysisException
62:         {
63:•                return pattern.getLeft().apply(THIS) && pattern.getRight().apply(THIS);
64:         }
65:
66:         @Override
67:         public Boolean caseAIdentifierPattern(AIdentifierPattern pattern)
68:                         throws AnalysisException
69:         {
70:                 return false;
71:         }
72:
73:         @Override
74:         public Boolean caseAIgnorePattern(AIgnorePattern pattern)
75:                         throws AnalysisException
76:         {
77:                 return false;
78:         }
79:
80:         @Override
81:         public Boolean caseAMapUnionPattern(AMapUnionPattern pattern)
82:                         throws AnalysisException
83:         {
84:•                return pattern.getLeft().apply(THIS) && pattern.getRight().apply(THIS);
85:         }
86:
87:         @Override
88:         public Boolean caseARecordPattern(ARecordPattern pattern)
89:                         throws AnalysisException
90:         {
91:                 return af.createPPatternListAssistant().isSimple(pattern.getPlist());
92:         }
93:
94:         @Override
95:         public Boolean caseASeqPattern(ASeqPattern pattern)
96:                         throws AnalysisException
97:         {
98:                 return af.createPPatternListAssistant().isSimple(pattern.getPlist());
99:         }
100:
101:         @Override
102:         public Boolean caseASetPattern(ASetPattern pattern)
103:                         throws AnalysisException
104:         {
105:                 return af.createPPatternListAssistant().isSimple(pattern.getPlist());
106:         }
107:
108:         @Override
109:         public Boolean caseATuplePattern(ATuplePattern pattern)
110:                         throws AnalysisException
111:         {
112:                 return af.createPPatternListAssistant().isSimple(pattern.getPlist());
113:         }
114:
115:         @Override
116:         public Boolean caseAUnionPattern(AUnionPattern pattern)
117:                         throws AnalysisException
118:         {
119:•                return pattern.getLeft().apply(THIS) && pattern.getRight().apply(THIS);
120:         }
121:
122:         @Override
123:         public Boolean caseAMapPattern(AMapPattern pattern)
124:                         throws AnalysisException
125:         {
126:•                for (AMapletPatternMaplet mp : pattern.getMaplets())
127:                 {
128:
129:                         // if (!AMapletPatternMapletAssistantTC.isSimple(mp)) // Original code.
130:•                        if (!mp.apply(THIS))
131:                         {
132:                                 return false;
133:                         }
134:
135:                 }
136:                 return true;
137:         }
138:
139:         @Override
140:         public Boolean caseAObjectPattern(AObjectPattern pattern)
141:                         throws AnalysisException
142:         {
143:                 LinkedList<PPattern> list = new LinkedList<PPattern>();
144:                 
145:•                for (ANamePatternPair npp: pattern.getFields())
146:                 {
147:                         list.add(npp.getPattern());
148:                 }
149:                 
150:                 return af.createPPatternListAssistant().isSimple(list);
151:         }
152:
153:         @Override
154:         public Boolean defaultPPattern(PPattern pattern) throws AnalysisException
155:         {
156:                 /*
157:                  * True if the pattern is a simple value that can match only one value for certain. Most pattern types are like
158:                  * this, but any that include variables or ignore patterns are not.
159:                  */
160:                 return true;
161:         }
162:
163:         @Override
164:         public Boolean createNewReturnValue(INode node) throws AnalysisException
165:         {
166:                 // TODO Auto-generated method stub
167:                 return false;
168:         }
169:
170:         @Override
171:         public Boolean createNewReturnValue(Object node) throws AnalysisException
172:         {
173:                 // TODO Auto-generated method stub
174:                 return false;
175:         }
176:
177: }