Package: DefinitionCollector

DefinitionCollector

nameinstructionbranchcomplexitylinemethod
DefinitionCollector(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%
caseAAssignmentDefinition(AAssignmentDefinition)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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: 4 C: 6
60%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
caseAExplicitFunctionDefinition(AExplicitFunctionDefinition)
M: 5 C: 35
88%
M: 1 C: 7
88%
M: 1 C: 4
80%
M: 1 C: 8
89%
M: 0 C: 1
100%
caseAExplicitOperationDefinition(AExplicitOperationDefinition)
M: 0 C: 32
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
caseAExternalDefinition(AExternalDefinition)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseAImplicitFunctionDefinition(AImplicitFunctionDefinition)
M: 11 C: 29
73%
M: 3 C: 5
63%
M: 2 C: 3
60%
M: 1 C: 8
89%
M: 0 C: 1
100%
caseAImplicitOperationDefinition(AImplicitOperationDefinition)
M: 0 C: 32
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
caseAImportedDefinition(AImportedDefinition)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseAInheritedDefinition(AInheritedDefinition)
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%
caseAInstanceVariableDefinition(AInstanceVariableDefinition)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseALocalDefinition(ALocalDefinition)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseAMultiBindListDefinition(AMultiBindListDefinition)
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%
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: 3
100%
M: 0 C: 1
100%
caseAPerSyncDefinition(APerSyncDefinition)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseARenamedDefinition(ARenamedDefinition)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
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: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseATypeDefinition(ATypeDefinition)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
caseAUntypedDefinition(AUntypedDefinition)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseAValueDefinition(AValueDefinition)
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%
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: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
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.List;
25: import java.util.Vector;
26:
27: import org.overture.ast.analysis.AnalysisException;
28: import org.overture.ast.analysis.AnswerAdaptor;
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.lex.Dialect;
54: import org.overture.ast.node.INode;
55: import org.overture.config.Release;
56: import org.overture.config.Settings;
57: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
58:
59: /**
60: * This class implements a way to collect definitions from a node in the AST
61: *
62: * @author kel
63: */
64:•public class DefinitionCollector extends AnswerAdaptor<List<PDefinition>>
65: {
66:
67:         protected ITypeCheckerAssistantFactory af;
68:
69:         public DefinitionCollector(ITypeCheckerAssistantFactory af)
70:         {
71:                 this.af = af;
72:         }
73:
74:         @Override
75:         public List<PDefinition> caseAAssignmentDefinition(
76:                         AAssignmentDefinition node) throws AnalysisException
77:         {
78:                 List<PDefinition> res = new Vector<PDefinition>();
79:                 res.add(node);
80:                 return res;
81:         }
82:
83:         @Override
84:         public List<PDefinition> defaultSClassDefinition(SClassDefinition node)
85:                         throws AnalysisException
86:         {
87:                 List<PDefinition> all = new Vector<PDefinition>();
88:
89:                 all.addAll(node.getAllInheritedDefinitions());
90:                 all.addAll(af.createPDefinitionListAssistant().singleDefinitions(node.getDefinitions()));
91:
92:                 return all;
93:         }
94:
95:         @Override
96:         public List<PDefinition> caseAClassInvariantDefinition(
97:                         AClassInvariantDefinition node) throws AnalysisException
98:         {
99:                 return new Vector<PDefinition>();
100:         }
101:
102:         @Override
103:         public List<PDefinition> caseAEqualsDefinition(AEqualsDefinition node)
104:                         throws AnalysisException
105:         {
106:•                return node.getDefs() == null ? new Vector<PDefinition>()
107:                                 : node.getDefs();
108:         }
109:
110:         @Override
111:         public List<PDefinition> caseAExplicitFunctionDefinition(
112:                         AExplicitFunctionDefinition node) throws AnalysisException
113:         {
114:                 List<PDefinition> defs = new Vector<PDefinition>();
115:                 defs.add(node);
116:
117:•                if (node.getPredef() != null)
118:                 {
119:                         defs.add(node.getPredef());
120:                 }
121:
122:•                if (node.getPostdef() != null)
123:                 {
124:                         defs.add(node.getPostdef());
125:                 }
126:                 
127:•                if (node.getMeasureName() != null && node.getMeasureName().getName().startsWith("measure_"))
128:                 {
129:                         defs.add(node.getMeasureDef());
130:                 }
131:
132:                 return defs;
133:         }
134:
135:         @Override
136:         public List<PDefinition> caseAExplicitOperationDefinition(
137:                         AExplicitOperationDefinition node) throws AnalysisException
138:         {
139:                 List<PDefinition> defs = new Vector<PDefinition>();
140:                 defs.add(node);
141:
142:•                if (Settings.dialect == Dialect.VDM_SL || Settings.release == Release.CLASSIC)
143:                 {
144:•                 if (node.getPredef() != null)
145:                 {
146:                         defs.add(node.getPredef());
147:                 }
148:
149:•                 if (node.getPostdef() != null)
150:                 {
151:                         defs.add(node.getPostdef());
152:                 }
153:                 }
154:
155:                 return defs;
156:         }
157:
158:         @Override
159:         public List<PDefinition> caseAExternalDefinition(AExternalDefinition node)
160:                         throws AnalysisException
161:         {
162:                 List<PDefinition> result = new Vector<PDefinition>();
163:                 result.add(node.getState());
164:
165:                 return result;
166:         }
167:
168:         @Override
169:         public List<PDefinition> caseAImplicitFunctionDefinition(
170:                         AImplicitFunctionDefinition node) throws AnalysisException
171:         {
172:                 List<PDefinition> defs = new Vector<PDefinition>();
173:                 defs.add(node);
174:
175:•                if (node.getPredef() != null)
176:                 {
177:                         defs.add(node.getPredef());
178:                 }
179:
180:•                if (node.getPostdef() != null)
181:                 {
182:                         defs.add(node.getPostdef());
183:                 }
184:                 
185:•                if (node.getMeasureDef() != null && node.getMeasureName().getName().startsWith("measure_"))
186:                 {
187:                         defs.add(node.getMeasureDef());
188:                 }
189:
190:                 return defs;
191:         }
192:
193:         @Override
194:         public List<PDefinition> caseAImplicitOperationDefinition(
195:                         AImplicitOperationDefinition node) throws AnalysisException
196:         {
197:                 List<PDefinition> defs = new Vector<PDefinition>();
198:                 defs.add(node);
199:
200:•                if (Settings.dialect == Dialect.VDM_SL || Settings.release == Release.CLASSIC)
201:                 {
202:•                 if (node.getPredef() != null)
203:                 {
204:                         defs.add(node.getPredef());
205:                 }
206:
207:•                 if (node.getPostdef() != null)
208:                 {
209:                         defs.add(node.getPostdef());
210:                 }
211:                 }
212:
213:                 return defs;
214:         }
215:
216:         @Override
217:         public List<PDefinition> caseAImportedDefinition(AImportedDefinition node)
218:                         throws AnalysisException
219:         {
220:                 List<PDefinition> result = new Vector<PDefinition>();
221:                 result.add(node.getDef());
222:                 return result;
223:         }
224:
225:         @Override
226:         public List<PDefinition> caseAInheritedDefinition(AInheritedDefinition node)
227:                         throws AnalysisException
228:         {
229:                 return node.getSuperdef().apply(THIS);
230:         }
231:
232:         @Override
233:         public List<PDefinition> caseAInstanceVariableDefinition(
234:                         AInstanceVariableDefinition node) throws AnalysisException
235:         {
236:                 List<PDefinition> res = new Vector<PDefinition>();
237:                 res.add(node);
238:                 return res;
239:         }
240:
241:         @Override
242:         public List<PDefinition> caseALocalDefinition(ALocalDefinition node)
243:                         throws AnalysisException
244:         {
245:                 List<PDefinition> res = new Vector<PDefinition>();
246:                 res.add(node);
247:                 return res;
248:         }
249:
250:         @Override
251:         public List<PDefinition> caseAMultiBindListDefinition(
252:                         AMultiBindListDefinition node) throws AnalysisException
253:         {
254:•                return node.getDefs() == null ? new Vector<PDefinition>()
255:                                 : node.getDefs();
256:         }
257:
258:         @Override
259:         public List<PDefinition> caseAMutexSyncDefinition(AMutexSyncDefinition node)
260:                         throws AnalysisException
261:         {
262:                 return new Vector<PDefinition>();
263:         }
264:
265:         @Override
266:         public List<PDefinition> caseANamedTraceDefinition(
267:                         ANamedTraceDefinition node) throws AnalysisException
268:         {
269:                 List<PDefinition> result = new Vector<PDefinition>();
270:                 result.add(node);
271:                 return result;
272:         }
273:
274:         @Override
275:         public List<PDefinition> caseAPerSyncDefinition(APerSyncDefinition node)
276:                         throws AnalysisException
277:         {
278:                 List<PDefinition> result = new Vector<PDefinition>();
279:                 result.add(node);
280:                 return result;
281:         }
282:
283:         @Override
284:         public List<PDefinition> caseARenamedDefinition(ARenamedDefinition node)
285:                         throws AnalysisException
286:         {
287:                 List<PDefinition> result = new Vector<PDefinition>();
288:                 result.add(node);
289:                 return result;
290:         }
291:
292:         @Override
293:         public List<PDefinition> caseAStateDefinition(AStateDefinition node)
294:                         throws AnalysisException
295:         {
296:                 return node.getStateDefs();
297:         }
298:
299:         @Override
300:         public List<PDefinition> caseAThreadDefinition(AThreadDefinition node)
301:                         throws AnalysisException
302:         {
303:
304:                 List<PDefinition> result = new Vector<PDefinition>();
305:                 result.add(node.getOperationDef());
306:                 return result;
307:         }
308:
309:         @Override
310:         public List<PDefinition> caseATypeDefinition(ATypeDefinition node)
311:                         throws AnalysisException
312:         {
313:                 List<PDefinition> defs = new Vector<PDefinition>();
314:                 defs.add(node);
315:                 defs.addAll(node.getComposeDefinitions());
316:
317:•                if (node.getInvdef() != null)
318:                 {
319:                         defs.add(node.getInvdef());
320:                 }
321:
322:                 return defs;
323:         }
324:
325:         @Override
326:         public List<PDefinition> caseAUntypedDefinition(AUntypedDefinition node)
327:                         throws AnalysisException
328:         {
329:
330:                 List<PDefinition> result = new Vector<PDefinition>();
331:                 result.add(node);
332:                 return result;
333:         }
334:
335:         @Override
336:         public List<PDefinition> caseAValueDefinition(AValueDefinition node)
337:                         throws AnalysisException
338:         {
339:                 return node.getDefs();
340:         }
341:
342:         @Override
343:         public List<PDefinition> createNewReturnValue(INode node)
344:         {
345:•                assert false : "getDefinitions should never hit the default case";
346:                 return null;
347:         }
348:
349:         @Override
350:         public List<PDefinition> createNewReturnValue(Object node)
351:         {
352:•                assert false : "getDefinitions should never hit the default case";
353:                 return null;
354:         }
355: }