Package: PTypeAssistantTC

PTypeAssistantTC

nameinstructionbranchcomplexitylinemethod
PTypeAssistantTC(ITypeCheckerAssistantFactory)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
checkConstraint(PType, PType, ILexLocation)
M: 0 C: 21
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
checkReturnType(PType, PType, boolean, ILexLocation)
M: 0 C: 47
100%
M: 0 C: 12
100%
M: 0 C: 7
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
deBracket(Object)
M: 5 C: 5
50%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%
deBracket(PType)
M: 5 C: 5
50%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%
equals(LinkedList, LinkedList)
M: 4 C: 27
87%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 2 C: 4
67%
M: 0 C: 1
100%
equals(PType, Object)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getClassType(PType, Environment, String)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getComposeTypes(PType)
M: 5 C: 7
58%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getFunction(PType)
M: 3 C: 7
70%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getMap(PType, String)
M: 3 C: 8
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getOperation(PType, String)
M: 3 C: 8
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getProduct(PType, String)
M: 3 C: 8
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getProduct(PType, int, String)
M: 3 C: 10
77%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getRecord(PType, String)
M: 3 C: 8
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getSeq(PType, String)
M: 3 C: 8
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getSet(PType, String)
M: 3 C: 8
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
getUnion(PType, String)
M: 3 C: 8
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
hasSupertype(AClassType, PType)
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%
hasVoid(PType)
M: 3 C: 8
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isClass(PType, Environment, String)
M: 3 C: 10
77%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isFunction(PType, String)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isFunctionType(PType, ILexLocation)
M: 2 C: 41
95%
M: 1 C: 11
92%
M: 1 C: 6
86%
M: 1 C: 7
88%
M: 0 C: 1
100%
isMap(PType, String)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isOperation(PType, String)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isOrdered(PType, ILexLocation)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isProduct(PType, String)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isProduct(PType, int, String)
M: 3 C: 11
79%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isRecord(PType, String)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isSeq(PType, String)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isSet(PType, String)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isTag(PType, String)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isType(PType, Class)
M: 3 C: 12
80%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isType(PType, String)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
isUnion(PType, String)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
isUnknown(AUnionType)
M: 0 C: 22
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
isUnknown(PType)
M: 0 C: 15
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
isVoid(PType)
M: 3 C: 8
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
narrowerThan(PType, AAccessSpecifierAccessSpecifier)
M: 3 C: 9
75%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
narrowerThanBaseCase(PType, AAccessSpecifierAccessSpecifier)
M: 4 C: 31
89%
M: 3 C: 5
63%
M: 3 C: 2
40%
M: 1 C: 7
88%
M: 0 C: 1
100%
polymorph(PType, ILexNameToken, PType)
M: 3 C: 12
80%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
possibleConstraint(PType, PType, ILexLocation)
M: 0 C: 20
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
toDetailedString(PType)
M: 3 C: 7
70%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
toDisplay(PType)
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%
typeResolve(PType, ATypeDefinition, IQuestionAnswer, TypeCheckInfo)
M: 3 C: 13
81%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
unResolve(PType)
M: 1 C: 7
88%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 3
75%
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.assistant.type;
23:
24: import java.util.LinkedList;
25:
26: import org.overture.ast.analysis.AnalysisException;
27: import org.overture.ast.analysis.intf.IQuestionAnswer;
28: import org.overture.ast.assistant.IAstAssistant;
29: import org.overture.ast.assistant.pattern.PTypeList;
30: import org.overture.ast.assistant.type.PTypeAssistant;
31: import org.overture.ast.definitions.ATypeDefinition;
32: import org.overture.ast.definitions.PDefinition;
33: import org.overture.ast.intf.lex.ILexLocation;
34: import org.overture.ast.intf.lex.ILexNameToken;
35: import org.overture.ast.types.AAccessSpecifierAccessSpecifier;
36: import org.overture.ast.types.ABracketType;
37: import org.overture.ast.types.AClassType;
38: import org.overture.ast.types.AFunctionType;
39: import org.overture.ast.types.AOperationType;
40: import org.overture.ast.types.AOptionalType;
41: import org.overture.ast.types.AProductType;
42: import org.overture.ast.types.ARecordInvariantType;
43: import org.overture.ast.types.SSetType;
44: import org.overture.ast.types.AUnionType;
45: import org.overture.ast.types.AUnknownType;
46: import org.overture.ast.types.AVoidType;
47: import org.overture.ast.types.PType;
48: import org.overture.ast.types.SMapType;
49: import org.overture.ast.types.SSeqType;
50: import org.overture.typechecker.Environment;
51: import org.overture.typechecker.TypeCheckInfo;
52: import org.overture.typechecker.TypeChecker;
53: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
54: import org.overture.typechecker.utilities.type.ConcreateTypeImplementor;
55: import org.overture.typechecker.utilities.type.PTypeResolver;
56:
57: public class PTypeAssistantTC extends PTypeAssistant implements IAstAssistant
58: {
59:         protected ITypeCheckerAssistantFactory af;
60:
61:         public PTypeAssistantTC(ITypeCheckerAssistantFactory af)
62:         {
63:                 super(af);
64:                 this.af = af;
65:         }
66:
67:         public boolean hasSupertype(AClassType cto, PType other)
68:         {
69:                 return af.createPDefinitionAssistant().hasSupertype(cto.getClassdef(), other);
70:         }
71:
72:         public boolean isType(PType type, Class<? extends PType> typeclass)
73:         {
74:                 try
75:                 {
76:                         return type.apply(af.getPTypeExtendedChecker(type.getLocation().getModule()), typeclass);
77:                 } catch (AnalysisException e)
78:                 {
79:                         return false;
80:                 }
81:
82:         }
83:
84:         public PType polymorph(PType type, ILexNameToken pname, PType actualType)
85:         {
86:                 try
87:                 {
88:                         return type.apply(af.getConcreateTypeImplementor(), new ConcreateTypeImplementor.Newquestion(pname, actualType));
89:
90:                 } catch (AnalysisException e)
91:                 {
92:                         return null;
93:                 }
94:
95:         }
96:
97:         public boolean isUnknown(PType type)
98:         {
99:•                if (type instanceof AUnionType)
100:                 {
101:                         return isUnknown((AUnionType) type);
102:•                } else if (type instanceof AUnknownType)
103:                 {
104:                         return true;
105:                 }
106:                 return false;
107:         }
108:
109:         public boolean isUnion(PType type, String fromModule)
110:         {
111:                 try
112:                 {
113:                         return type.apply(af.getUnionBasisChecker(), fromModule);
114:                 }
115:                 catch (AnalysisException e)
116:                 {
117:                         return false;
118:                 }
119:         }
120:
121:         public AUnionType getUnion(PType type, String fromModule)
122:         {
123:                 try
124:                 {
125:                         return type.apply(af.getUnionTypeFinder(), fromModule);
126:                 }
127:                 catch (AnalysisException e)
128:                 {
129:                         return null;
130:                 }
131:         }
132:
133:         public boolean isFunction(PType type, String fromModule)
134:         {
135:                 try
136:                 {
137:                         return type.apply(af.getPTypeFunctionChecker(fromModule));
138:                 }
139:                 catch (AnalysisException e)
140:                 {
141:                         return false;
142:                 }
143:         }
144:
145:         public AFunctionType getFunction(PType type)
146:         {
147:                 try
148:                 {
149:                         return type.apply(af.getFunctionTypeFinder());
150:                 } catch (AnalysisException e)
151:                 {
152:                         return null;
153:                 }
154:         }
155:
156:         public PType typeResolve(PType type, ATypeDefinition root,
157:                         IQuestionAnswer<TypeCheckInfo, PType> rootVisitor,
158:                         TypeCheckInfo question)
159:         {
160:                 try
161:                 {
162:                         return type.apply(af.getPTypeResolver(), new PTypeResolver.Newquestion(root, rootVisitor, question));
163:                 } catch (AnalysisException e)
164:                 {
165:                         return null;
166:                 }
167:         }
168:
169:         public void unResolve(PType type)
170:         {
171:                 try
172:                 {
173:                         type.apply(af.getTypeUnresolver());
174:                 } catch (AnalysisException e)
175:                 {
176:
177:                 }
178:         }
179:
180:         public boolean isOperation(PType type, String fromModule)
181:         {
182:                 try
183:                 {
184:                         return type.apply(af.getOperationBasisChecker(), fromModule);
185:                 }
186:                 catch (AnalysisException e)
187:                 {
188:                         return false;
189:                 }
190:         }
191:
192:         public AOperationType getOperation(PType type, String fromModule)
193:         {
194:                 try
195:                 {
196:                         return type.apply(af.getOperationTypeFinder(), fromModule);
197:                 }
198:                 catch (AnalysisException e)
199:                 {
200:                         return null;
201:                 }
202:
203:         }
204:
205:         public boolean isSeq(PType type, String fromModule)
206:         {
207:                 try
208:                 {
209:                         return type.apply(af.getSeqBasisChecker(), fromModule);
210:                 }
211:                 catch (AnalysisException e)
212:                 {
213:                         return false;
214:                 }
215:         }
216:
217:         public SSeqType getSeq(PType type, String fromModule)
218:         {
219:                 try
220:                 {
221:                         return type.apply(af.getSeqTypeFinder(), fromModule);
222:                 }
223:                 catch (AnalysisException e)
224:                 {
225:                         return null;
226:                 }
227:         }
228:
229:         public boolean isMap(PType type, String fromModule)
230:         {
231:                 try
232:                 {
233:                         return type.apply(af.getMapBasisChecker(), fromModule);
234:                 }
235:                 catch (AnalysisException e)
236:                 {
237:                         return false;
238:                 }
239:         }
240:
241:         public SMapType getMap(PType type, String fromModule)
242:         {
243:                 try
244:                 {
245:                         return type.apply(af.getMapTypeFinder(), fromModule);
246:                 }
247:                 catch (AnalysisException e)
248:                 {
249:                         return null;
250:                 }
251:         }
252:
253:         public boolean isSet(PType type, String fromModule)
254:         {
255:                 try
256:                 {
257:                         return type.apply(af.getSetBasisChecker(), fromModule);
258:                 }
259:                 catch (AnalysisException e)
260:                 {
261:                         return false;
262:                 }
263:         }
264:
265:         public SSetType getSet(PType type, String fromModule)
266:         {
267:                 try
268:                 {
269:                         return type.apply(af.getSetTypeFinder(), fromModule);
270:                 }
271:                 catch (AnalysisException e)
272:                 {
273:                         return null;
274:                 }
275:         }
276:
277:         public boolean isRecord(PType type, String fromModule)
278:         {
279:                 try
280:                 {
281:                         return type.apply(af.getRecordBasisChecker(), fromModule);
282:                 }
283:                 catch (AnalysisException e)
284:                 {
285:                         return false;
286:                 }
287:         }
288:
289:         public boolean isTag(PType type, String fromModule)
290:         {
291:                 try
292:                 {
293:                         return type.apply(af.getTagBasisChecker(), fromModule);
294:                 }
295:                 catch (AnalysisException e)
296:                 {
297:                         return false;
298:                 }
299:         }
300:
301:         public ARecordInvariantType getRecord(PType type, String fromModule)
302:         {
303:                 try
304:                 {
305:                         return type.apply(af.getRecordTypeFinder(), fromModule);
306:                 }
307:                 catch (AnalysisException e)
308:                 {
309:                         return null;
310:                 }
311:         }
312:
313:         public boolean isClass(PType type, Environment env, String fromModule)
314:         {
315:                 try
316:                 {
317:                         return type.apply(af.getClassBasisChecker(env), fromModule);
318:                 }
319:                 catch (AnalysisException e)
320:                 {
321:                         return false;
322:                 }
323:         }
324:
325:         public AClassType getClassType(PType type, Environment env, String fromModule)
326:         {
327:                 try
328:                 {
329:                         return type.apply(af.getClassTypeFinder(env), fromModule);
330:                 }
331:                 catch (AnalysisException e)
332:                 {
333:                         return null;
334:                 }
335:         }
336:
337:         public AProductType getProduct(PType type, String fromModule)
338:         {
339:                 try
340:                 {
341:                         return type.apply(af.getProductTypeFinder(), fromModule);
342:                 }
343:                 catch (AnalysisException e)
344:                 {
345:                         return null;
346:                 }
347:
348:         }
349:
350:         public boolean isProduct(PType type, String fromModule)
351:         {
352:                 try
353:                 {
354:                         return type.apply(af.getProductBasisChecker(), fromModule);
355:                 }
356:                 catch (AnalysisException e)
357:                 {
358:                         return false;
359:                 }
360:         }
361:
362:         public boolean narrowerThan(PType type,
363:                         AAccessSpecifierAccessSpecifier accessSpecifier)
364:         {
365:                 try
366:                 {
367:                         return type.apply(af.getNarrowerThanComparator(), accessSpecifier);
368:                 } catch (AnalysisException e)
369:                 {
370:                         return false;
371:                 }
372:         }
373:
374:         public boolean narrowerThanBaseCase(PType type,
375:                         AAccessSpecifierAccessSpecifier accessSpecifier)
376:         {
377:•                if (type.getDefinitions() != null)
378:                 {
379:                         boolean result = false;
380:•                        for (PDefinition d : type.getDefinitions())
381:                         {
382:•                                result = result
383:•                                                || af.createPAccessSpecifierAssistant().narrowerThan(d.getAccess(), accessSpecifier);
384:                         }
385:                         return result;
386:                 } else
387:                 {
388:                         return false;
389:                 }
390:         }
391:
392:         public boolean equals(PType type, Object other)
393:         {
394:                 try
395:                 {
396:                         return type.apply(af.getTypeEqualityChecker(), other);
397:                 } catch (AnalysisException e)
398:                 {
399:                         return false;
400:                 }
401:
402:         }
403:
404:         public PType deBracket(PType other)
405:         {
406:
407:•                while (other instanceof ABracketType)
408:                 {
409:                         other = ((ABracketType) other).getType();
410:                 }
411:
412:                 return other;
413:         }
414:
415:         // public static Object deBracket(Object other) // used at pog-string-base, problematic conversion.
416:         // {
417:         // while (other instanceof ABracketType)
418:         // {
419:         // other = ((ABracketType) other).getType();
420:         // }
421:         //
422:         // return other;
423:         // }
424:
425:         public PType isType(PType type, String typename)
426:         {
427:                 try
428:                 {
429:                         return type.apply(af.getPTypeFinder(type.getLocation().getModule()), typename);
430:                 }
431:                 catch (AnalysisException e)
432:                 {
433:                         return null;
434:                 }
435:         }
436:
437:         public String toDisplay(PType type)
438:         {
439:                 try
440:                 {
441:                         return type.apply(af.getTypeDisplayer());
442:                 } catch (AnalysisException e)
443:                 {
444:                         return null;
445:                 }
446:         }
447:
448:         public String toDetailedString(PType type)
449:         {
450:                 try
451:                 {
452:                         return type.apply(af.getDetailedTypeDisplayer());
453:                 } catch (AnalysisException e)
454:                 {
455:                         return null;
456:                 }
457:         }
458:
459:         public boolean isProduct(PType type, int size, String fromModule)
460:         {
461:                 try
462:                 {
463:                         return type.apply(af.getProductExtendedChecker(fromModule), size);
464:                 }
465:                 catch (AnalysisException e)
466:                 {
467:                         return false;
468:                 }
469:         }
470:
471:         public AProductType getProduct(PType type, int size, String fromModule)
472:         {
473:                 try
474:                 {
475:                         return type.apply(af.getProductExtendedTypeFinder(fromModule), size);
476:                 }
477:                 catch (AnalysisException e)
478:                 {
479:                         return null;
480:                 }
481:         }
482:
483:         public boolean equals(LinkedList<PType> parameters, LinkedList<PType> other)
484:         {
485:
486:•                if (parameters.size() != other.size())
487:                 {
488:                         return false;
489:                 }
490:
491:•                for (int i = 0; i < parameters.size(); i++)
492:                 {
493:•                        if (!af.createPTypeAssistant().equals(parameters.get(i), other.get(i)))
494:                         {
495:                                 return false;
496:                         }
497:                 }
498:
499:                 return true;
500:         }
501:
502:         public boolean isVoid(PType type)
503:         {
504:                 try
505:                 {
506:                         return type.apply(af.getVoidBasisChecker());
507:                 } catch (AnalysisException e)
508:                 {
509:                         return false;
510:                 }
511:         }
512:
513:         public boolean hasVoid(PType type)
514:         {
515:                 try
516:                 {
517:                         return type.apply(af.getVoidExistanceChecker());
518:                 } catch (AnalysisException e)
519:                 {
520:                         return false;
521:                 }
522:         }
523:
524:         public Object deBracket(Object other)
525:         {
526:•                while (other instanceof ABracketType)
527:                 {
528:                         other = ((ABracketType) other).getType();
529:                 }
530:
531:                 return other;
532:         }
533:
534:         public PTypeList getComposeTypes(PType type)
535:         {
536:                 try
537:                 {
538:                         return type.apply(af.getComposeTypeCollector());
539:                 } catch (AnalysisException e)
540:                 {
541:                         return new PTypeList();
542:                 }
543:         }
544:
545:         public PType checkConstraint(PType constraint, PType actual,
546:                         ILexLocation location)
547:         {
548:•                if (constraint != null)
549:                 {
550:•                        if (!af.getTypeComparator().isSubType(actual, constraint, true))
551:                         {
552:                                 TypeChecker.report(3327, "Value is not of the right type", location);
553:                                 TypeChecker.detail2("Actual", actual, "Expected", constraint);
554:                         }
555:                 }
556:
557:                 return actual;
558:         }
559:
560:         public PType possibleConstraint(PType constraint, PType actual,
561:                         ILexLocation location)
562:         {
563:•                if (constraint != null)
564:                 {
565:•                        if (!af.getTypeComparator().compatible(constraint, actual))
566:                         {
567:                                 TypeChecker.report(3327, "Value is not of the right type", location);
568:                                 TypeChecker.detail2("Actual", actual, "Expected", constraint);
569:                         }
570:                 }
571:
572:                 return actual;
573:         }
574:
575:         public PType checkReturnType(PType constraint, PType actual, boolean mandatory, ILexLocation location)
576:         {
577:                 PTypeAssistantTC assistant = af.createPTypeAssistant();
578:
579:•                if (constraint != null && mandatory        && !assistant.isUnknown(actual))
580:                 {
581:•                        if (assistant.hasVoid(actual) && !(constraint instanceof AVoidType))
582:                         {
583:                                 TypeChecker.report(3328, "Statement may return void value", location);
584:                                 TypeChecker.detail2("Actual", actual, "Expected", constraint);
585:                         }
586:•                        else if (!af.getTypeComparator().compatible(constraint, actual))
587:                         {
588:                                 TypeChecker.report(3327, "Value is not of the right type", location);
589:                                 TypeChecker.detail2("Actual", actual, "Expected", constraint);
590:                         }
591:                 }
592:
593:                 return actual;
594:         }
595:
596:         public boolean isUnknown(AUnionType type)
597:         {
598:•                for (PType t : type.getTypes())
599:                 {
600:•                        if (af.createPTypeAssistant().isUnknown(t))
601:                         {
602:                                 return true;
603:                         }
604:                 }
605:
606:                 return false;
607:         }
608:
609:         public boolean isOrdered(PType type, ILexLocation from)
610:         {
611:                 try
612:                 {
613:                         return type.apply(af.getIsOrderedVisitor(),from);
614:                 } catch (AnalysisException e)
615:                 {
616:                         return false;
617:                 }
618:         }
619:
620:         public boolean isFunctionType(PType type, ILexLocation from)
621:         {
622:•                if (type instanceof AUnionType)
623:                 {
624:                         AUnionType union = (AUnionType)type;
625:
626:•                        for (PType element: union.getTypes())
627:                         {
628:•                                if (isFunctionType(element, from))
629:                                 {
630:                                         return true;
631:                                 }
632:                         }
633:
634:                         return false;
635:                 }
636:                 else
637:                 {
638:•                        return isFunction(type, from.getModule()) &&
639:                                 !(type instanceof AOptionalType) &&                // eg. nil is not a function
640:                                 !(type instanceof AUnknownType);                // eg. ? is not a function
641:                 }
642:         }
643: }