Package: PPatternListAssistantTC

PPatternListAssistantTC

nameinstructionbranchcomplexitylinemethod
PPatternListAssistantTC(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%
alwaysMatches(List)
M: 0 C: 24
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getPossibleType(LinkedList, ILexLocation)
M: 0 C: 48
100%
M: 0 C: 5
100%
M: 0 C: 4
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
isSimple(LinkedList)
M: 0 C: 24
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
typeResolve(List, IQuestionAnswer, TypeCheckInfo)
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
typeResolvePairs(List, IQuestionAnswer, TypeCheckInfo)
M: 22 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
unResolve(List)
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%

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.pattern;
23:
24: import java.util.LinkedList;
25: import java.util.List;
26:
27: import org.overture.ast.analysis.AnalysisException;
28: import org.overture.ast.analysis.intf.IQuestionAnswer;
29: import org.overture.ast.assistant.IAstAssistant;
30: import org.overture.ast.factory.AstFactory;
31: import org.overture.ast.intf.lex.ILexLocation;
32: import org.overture.ast.patterns.ANamePatternPair;
33: import org.overture.ast.patterns.PPattern;
34: import org.overture.ast.types.PType;
35: import org.overture.ast.util.PTypeSet;
36: import org.overture.typechecker.TypeCheckInfo;
37: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
38:
39: public class PPatternListAssistantTC implements IAstAssistant
40: {
41:         protected ITypeCheckerAssistantFactory af;
42:
43:         public PPatternListAssistantTC(ITypeCheckerAssistantFactory af)
44:         {
45:                 this.af = af;
46:         }
47:
48:         public void typeResolve(List<PPattern> pp,
49:                         IQuestionAnswer<TypeCheckInfo, PType> rootVisitor,
50:                         TypeCheckInfo question) throws AnalysisException
51:         {
52:
53:•                for (PPattern pattern : pp)
54:                 {
55:                         af.createPPatternAssistant(question.fromModule).typeResolve(pattern, rootVisitor, question);
56:                 }
57:         }
58:
59:         public void typeResolvePairs(List<ANamePatternPair> npplist,
60:                         IQuestionAnswer<TypeCheckInfo, PType> rootVisitor,
61:                         TypeCheckInfo question) throws AnalysisException
62:         {
63:
64:•                for (ANamePatternPair npp : npplist)
65:                 {
66:                         af.createPPatternAssistant(question.fromModule).typeResolve(npp.getPattern(), rootVisitor, question);
67:                 }
68:         }
69:
70:         public void unResolve(List<PPattern> pp)
71:         {
72:•                for (PPattern pPattern : pp)
73:                 {
74:                         af.createPPatternAssistant(null).unResolve(pPattern);
75:                 }
76:         }
77:
78:         public PType getPossibleType(LinkedList<PPattern> plist,
79:                         ILexLocation location)
80:         {
81:
82:•                switch (plist.size())
83:                 {
84:                         case 0:
85:                                 return AstFactory.newAUnknownType(location);
86:
87:                         case 1:
88:                                 return af.createPPatternAssistant(location.getModule()).getPossibleType(plist.get(0));
89:
90:                         default:
91:                                 PTypeSet list = new PTypeSet(af);
92:
93:•                                for (PPattern p : plist)
94:                                 {
95:                                         list.add(af.createPPatternAssistant(location.getModule()).getPossibleType(p));
96:                                 }
97:
98:                                 return list.getType(location); // NB. a union of types
99:                 }
100:         }
101:
102:         public boolean isSimple(LinkedList<PPattern> p)
103:         {
104:•                for (PPattern pattern : p)
105:                 {
106:•                        if (!af.createPPatternAssistant(pattern.getLocation().getModule()).isSimple(pattern))
107:                         {
108:
109:                                 return false; // NB. AND
110:                         }
111:                 }
112:
113:                 return true;
114:         }
115:
116:         public boolean alwaysMatches(List<PPattern> pl)
117:         {
118:•                for (PPattern p : pl)
119:                 {
120:•                        if (!af.createPPatternAssistant(p.getLocation().getModule()).alwaysMatches(p))
121:                         {
122:
123:                                 return false; // NB. AND
124:                         }
125:                 }
126:
127:                 return true;
128:         }
129:
130: }