Package: DefinitionTypeFinder

DefinitionTypeFinder

nameinstructionbranchcomplexitylinemethod
DefinitionTypeFinder(ITypeCheckerAssistantFactory)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseAAssignmentDefinition(AAssignmentDefinition)
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%
caseAClassInvariantDefinition(AClassInvariantDefinition)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAEqualsDefinition(AEqualsDefinition)
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
caseAExplicitFunctionDefinition(AExplicitFunctionDefinition)
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%
caseAExplicitOperationDefinition(AExplicitOperationDefinition)
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%
caseAExternalDefinition(AExternalDefinition)
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%
caseAImplicitFunctionDefinition(AImplicitFunctionDefinition)
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%
caseAImplicitOperationDefinition(AImplicitOperationDefinition)
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%
caseAImportedDefinition(AImportedDefinition)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
caseAInheritedDefinition(AInheritedDefinition)
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%
caseAInstanceVariableDefinition(AInstanceVariableDefinition)
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%
caseALocalDefinition(ALocalDefinition)
M: 4 C: 6
60%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
caseAMultiBindListDefinition(AMultiBindListDefinition)
M: 0 C: 28
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
caseAMutexSyncDefinition(AMutexSyncDefinition)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseANamedTraceDefinition(ANamedTraceDefinition)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAPerSyncDefinition(APerSyncDefinition)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseARenamedDefinition(ARenamedDefinition)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAStateDefinition(AStateDefinition)
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%
caseAThreadDefinition(AThreadDefinition)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseATypeDefinition(ATypeDefinition)
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%
caseAUntypedDefinition(AUntypedDefinition)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAValueDefinition(AValueDefinition)
M: 3 C: 13
81%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 3
100%
M: 0 C: 1
100%
checkSuperDefinition(AInheritedDefinition)
M: 0 C: 20
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 4
100%
M: 0 C: 1
100%
createNewReturnValue(INode)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createNewReturnValue(Object)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
defaultSClassDefinition(SClassDefinition)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 2 C: 6
75%
M: 1 C: 1
50%
M: 1 C: 1
50%
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;
23:
24: import java.util.Vector;
25:
26: import org.overture.ast.analysis.AnalysisException;
27: import org.overture.ast.analysis.AnswerAdaptor;
28: import org.overture.ast.assistant.pattern.PTypeList;
29: import org.overture.ast.definitions.AAssignmentDefinition;
30: import org.overture.ast.definitions.AClassInvariantDefinition;
31: import org.overture.ast.definitions.AEqualsDefinition;
32: import org.overture.ast.definitions.AExplicitFunctionDefinition;
33: import org.overture.ast.definitions.AExplicitOperationDefinition;
34: import org.overture.ast.definitions.AExternalDefinition;
35: import org.overture.ast.definitions.AImplicitFunctionDefinition;
36: import org.overture.ast.definitions.AImplicitOperationDefinition;
37: import org.overture.ast.definitions.AImportedDefinition;
38: import org.overture.ast.definitions.AInheritedDefinition;
39: import org.overture.ast.definitions.AInstanceVariableDefinition;
40: import org.overture.ast.definitions.ALocalDefinition;
41: import org.overture.ast.definitions.AMultiBindListDefinition;
42: import org.overture.ast.definitions.AMutexSyncDefinition;
43: import org.overture.ast.definitions.ANamedTraceDefinition;
44: import org.overture.ast.definitions.APerSyncDefinition;
45: import org.overture.ast.definitions.ARenamedDefinition;
46: import org.overture.ast.definitions.AStateDefinition;
47: import org.overture.ast.definitions.AThreadDefinition;
48: import org.overture.ast.definitions.ATypeDefinition;
49: import org.overture.ast.definitions.AUntypedDefinition;
50: import org.overture.ast.definitions.AValueDefinition;
51: import org.overture.ast.definitions.PDefinition;
52: import org.overture.ast.definitions.SClassDefinition;
53: import org.overture.ast.factory.AstFactory;
54: import org.overture.ast.node.INode;
55: import org.overture.ast.types.AUnionType;
56: import org.overture.ast.types.PType;
57: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
58:
59: //TODO Add assistant Javadoc
60:
61: /**
62: * A refactored assistant/ functionality visitor. This class implements a way to collect definitions from a node in the
63: * AST
64: * <p>
65: * Note that this class may be generalized to a TypeFinder class if this kind of functionality also exists for
66: * non-definition nodes
67: * </p>
68: *
69: * @author kel
70: */
71:•public class DefinitionTypeFinder extends AnswerAdaptor<PType>
72: {
73:
74:         protected static ITypeCheckerAssistantFactory af;
75:
76:         public DefinitionTypeFinder(ITypeCheckerAssistantFactory af)
77:         {
78:                 DefinitionTypeFinder.af = af;
79:         }
80:
81:         @Override
82:         public PType caseAAssignmentDefinition(AAssignmentDefinition node)
83:                         throws AnalysisException
84:         {
85:                 return node.getType();
86:         }
87:
88:         @Override
89:         public PType defaultSClassDefinition(SClassDefinition node)
90:                         throws AnalysisException
91:         {
92:                 return af.createSClassDefinitionAssistant().getType((SClassDefinition) node);
93:         }
94:
95:         @Override
96:         public PType caseAClassInvariantDefinition(AClassInvariantDefinition node)
97:                         throws AnalysisException
98:         {
99:                 return AstFactory.newABooleanBasicType(node.getLocation());
100:         }
101:
102:         @Override
103:         public PType caseAEqualsDefinition(AEqualsDefinition node)
104:                         throws AnalysisException
105:         {
106:•                return node.getDefType() != null ? node.getDefType()
107:                                 : AstFactory.newAUnknownType(node.getLocation());
108:         }
109:
110:         @Override
111:         public PType caseAExplicitFunctionDefinition(
112:                         AExplicitFunctionDefinition node) throws AnalysisException
113:         {
114:                 return node.getType();
115:         }
116:
117:         @Override
118:         public PType caseAExplicitOperationDefinition(
119:                         AExplicitOperationDefinition node) throws AnalysisException
120:         {
121:                 return node.getType();
122:         }
123:
124:         @Override
125:         public PType caseAExternalDefinition(AExternalDefinition node)
126:                         throws AnalysisException
127:         {
128:                 return af.createPDefinitionAssistant().getType(node.getState());
129:         }
130:
131:         @Override
132:         public PType caseAImplicitFunctionDefinition(
133:                         AImplicitFunctionDefinition node) throws AnalysisException
134:         {
135:                 return node.getType();
136:         }
137:
138:         @Override
139:         public PType caseAImplicitOperationDefinition(
140:                         AImplicitOperationDefinition node) throws AnalysisException
141:         {
142:                 return node.getType();
143:         }
144:
145:         @Override
146:         public PType caseAImportedDefinition(AImportedDefinition node)
147:                         throws AnalysisException
148:         {
149:                 return ((AImportedDefinition) node).getDef().apply(THIS);
150:         }
151:
152:         public static void checkSuperDefinition(AInheritedDefinition d)
153:         {
154:                 // This is used to get over the case where an inherited definition
155:                 // is a ValueDefinition that has since been replaced with a new
156:                 // LocalDefinition. It would be better to somehow list the
157:                 // inherited definitions that refer to a LocalDefinition and update
158:                 // them...
159:
160:•                if (d.getSuperdef() instanceof AUntypedDefinition)
161:                 {
162:•                        if (d.getClassDefinition() != null)
163:                         {
164:                                 d.setSuperdef(af.createPDefinitionAssistant().findName(d.getClassDefinition(), d.getSuperdef().getName(), d.getNameScope()));
165:                         }
166:                 }
167:         }
168:
169:         @Override
170:         public PType caseAInheritedDefinition(AInheritedDefinition node)
171:                         throws AnalysisException
172:         {
173:
174:                 checkSuperDefinition(node);
175:                 return af.createPDefinitionAssistant().getType(node.getSuperdef());
176:         }
177:
178:         @Override
179:         public PType caseAInstanceVariableDefinition(
180:                         AInstanceVariableDefinition node) throws AnalysisException
181:         {
182:                 return node.getType();
183:         }
184:
185:         @Override
186:         public PType caseALocalDefinition(ALocalDefinition node)
187:                         throws AnalysisException
188:         {
189:•                return node.getType() == null ? AstFactory.newAUnknownType(node.getLocation())
190:                                 : node.getType();
191:         }
192:
193:         @Override
194:         public PType caseAMultiBindListDefinition(AMultiBindListDefinition node)
195:                         throws AnalysisException
196:         {
197:                 PTypeList types = new PTypeList();
198:
199:•                for (PDefinition definition : node.getDefs())
200:                 {
201:                         types.add(definition.getType());
202:                 }
203:
204:                 AUnionType result = AstFactory.newAUnionType(node.getLocation(), types);
205:
206:                 return result;
207:         }
208:
209:         @Override
210:         public PType caseAMutexSyncDefinition(AMutexSyncDefinition node)
211:                         throws AnalysisException
212:         {
213:                 return AstFactory.newAUnknownType(node.getLocation());
214:         }
215:
216:         @Override
217:         public PType caseANamedTraceDefinition(ANamedTraceDefinition node)
218:                         throws AnalysisException
219:         {
220:                 return AstFactory.newAOperationType(node.getLocation(), new Vector<PType>(), AstFactory.newAVoidType(node.getLocation()));
221:         }
222:
223:         @Override
224:         public PType caseAPerSyncDefinition(APerSyncDefinition node)
225:                         throws AnalysisException
226:         {
227:                 return AstFactory.newABooleanBasicType(node.getLocation());
228:         }
229:
230:         @Override
231:         public PType caseARenamedDefinition(ARenamedDefinition node)
232:                         throws AnalysisException
233:         {
234:                 return ((ARenamedDefinition) node).getDef().apply(THIS);
235:         }
236:
237:         @Override
238:         public PType caseAStateDefinition(AStateDefinition node)
239:                         throws AnalysisException
240:         {
241:                 return ((AStateDefinition) node).getRecordType();
242:         }
243:
244:         @Override
245:         public PType caseAThreadDefinition(AThreadDefinition node)
246:                         throws AnalysisException
247:         {
248:                 return AstFactory.newAUnknownType(node.getLocation());
249:         }
250:
251:         @Override
252:         public PType caseATypeDefinition(ATypeDefinition node)
253:                         throws AnalysisException
254:         {
255:                 return ((ATypeDefinition) node).getInvType();
256:         }
257:
258:         @Override
259:         public PType caseAUntypedDefinition(AUntypedDefinition node)
260:                         throws AnalysisException
261:         {
262:                 return AstFactory.newAUnknownType(node.getLocation());
263:         }
264:
265:         @Override
266:         public PType caseAValueDefinition(AValueDefinition node)
267:                         throws AnalysisException
268:         {
269:                 // return AValueDefinitionAssistantTC.getType((AValueDefinition) node);
270:•                return node.getType() != null ? node.getType()
271:•                                : node.getExpType() != null ? node.getExpType()
272:                                                 : AstFactory.newAUnknownType(node.getLocation());
273:         }
274:
275:         @Override
276:         public PType createNewReturnValue(INode node)
277:         {
278:•                assert false : "getDefinitions should never hit the default case";
279:                 return null;
280:         }
281:
282:         @Override
283:         public PType createNewReturnValue(Object node)
284:         {
285:•                assert false : "getDefinitions should never hit the default case";
286:                 return null;
287:         }
288: }