Package: PatternResolver

PatternResolver

nameinstructionbranchcomplexitylinemethod
PatternResolver(ITypeCheckerAssistantFactory, String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
caseAConcatenationPattern(AConcatenationPattern, PatternResolver.NewQuestion)
M: 10 C: 23
70%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 3 C: 7
70%
M: 0 C: 1
100%
caseAExpressionPattern(AExpressionPattern, PatternResolver.NewQuestion)
M: 10 C: 28
74%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 3 C: 8
73%
M: 0 C: 1
100%
caseAMapPattern(AMapPattern, PatternResolver.NewQuestion)
M: 9 C: 27
75%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 4 C: 7
64%
M: 0 C: 1
100%
caseAMapUnionPattern(AMapUnionPattern, PatternResolver.NewQuestion)
M: 31 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
caseAObjectPattern(AObjectPattern, PatternResolver.NewQuestion)
M: 44 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
caseARecordPattern(ARecordPattern, PatternResolver.NewQuestion)
M: 0 C: 44
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
caseASeqPattern(ASeqPattern, PatternResolver.NewQuestion)
M: 10 C: 21
68%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 3 C: 6
67%
M: 0 C: 1
100%
caseASetPattern(ASetPattern, PatternResolver.NewQuestion)
M: 10 C: 21
68%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 3 C: 6
67%
M: 0 C: 1
100%
caseATuplePattern(ATuplePattern, PatternResolver.NewQuestion)
M: 10 C: 21
68%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 3 C: 6
67%
M: 0 C: 1
100%
caseAUnionPattern(AUnionPattern, PatternResolver.NewQuestion)
M: 10 C: 23
70%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 3 C: 7
70%
M: 0 C: 1
100%
defaultPPattern(PPattern, PatternResolver.NewQuestion)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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 org.overture.ast.analysis.AnalysisException;
25: import org.overture.ast.analysis.QuestionAdaptor;
26: import org.overture.ast.analysis.intf.IQuestionAnswer;
27: import org.overture.ast.patterns.AConcatenationPattern;
28: import org.overture.ast.patterns.AExpressionPattern;
29: import org.overture.ast.patterns.AMapPattern;
30: import org.overture.ast.patterns.AMapUnionPattern;
31: import org.overture.ast.patterns.AMapletPatternMaplet;
32: import org.overture.ast.patterns.AObjectPattern;
33: import org.overture.ast.patterns.ARecordPattern;
34: import org.overture.ast.patterns.ASeqPattern;
35: import org.overture.ast.patterns.ASetPattern;
36: import org.overture.ast.patterns.ATuplePattern;
37: import org.overture.ast.patterns.AUnionPattern;
38: import org.overture.ast.patterns.PPattern;
39: import org.overture.ast.typechecker.NameScope;
40: import org.overture.ast.types.PType;
41: import org.overture.typechecker.TypeCheckException;
42: import org.overture.typechecker.TypeCheckInfo;
43: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
44: import org.overture.typechecker.visitor.TypeCheckVisitor;
45:
46: /**
47: * This class set a pattern to resolved.
48: *
49: * @author kel
50: */
51:
52: public class PatternResolver extends
53:                 QuestionAdaptor<PatternResolver.NewQuestion>
54: {
55:         public static class NewQuestion
56:         {
57:                 IQuestionAnswer<TypeCheckInfo, PType> rootVisitor;
58:                 TypeCheckInfo question;
59:
60:                 public NewQuestion(IQuestionAnswer<TypeCheckInfo, PType> rootVisitor,
61:                                 TypeCheckInfo question)
62:                 {
63:                         this.rootVisitor = rootVisitor;
64:                         this.question = question;
65:                 }
66:         }
67:
68:         protected final ITypeCheckerAssistantFactory af;
69:         protected final String fromModule;
70:
71:         public PatternResolver(ITypeCheckerAssistantFactory af, String fromModule)
72:         {
73:                 this.af = af;
74:                 this.fromModule = fromModule;
75:         }
76:
77:         @Override
78:         public void caseAConcatenationPattern(AConcatenationPattern pattern,
79:                         NewQuestion question) throws AnalysisException
80:         {
81:
82:•                if (pattern.getResolved())
83:                 {
84:                         return;
85:                 } else
86:                 {
87:                         pattern.setResolved(true);
88:                 }
89:
90:                 try
91:                 {
92:                         pattern.getLeft().apply(THIS, question);
93:                         pattern.getRight().apply(THIS, question);
94:                 } catch (TypeCheckException e)
95:                 {
96:                         af.createPPatternAssistant(fromModule).unResolve(pattern);
97:                         throw e;
98:                 }
99:         }
100:
101:         @Override
102:         public void caseAExpressionPattern(AExpressionPattern pattern,
103:                         NewQuestion question) throws AnalysisException
104:         {
105:                 // af.createAExpressionPatternAssistant().typeResolve(pattern, question.rootVisitor, question.question);
106:                 // Have to ask how is it done.
107:•                if (pattern.getResolved())
108:                 {
109:                         return;
110:                 } else
111:                 {
112:                         pattern.setResolved(true);
113:                 }
114:
115:                 try
116:                 {
117:                         question.question.qualifiers = null;
118:                         question.question.scope = NameScope.NAMESANDSTATE;
119:                         pattern.getExp().apply(new TypeCheckVisitor(), question.question);
120:                 } catch (TypeCheckException e)
121:                 {
122:                         af.createPPatternAssistant(fromModule).unResolve(pattern);
123:                         throw e;
124:                 }
125:         }
126:
127:         @Override
128:         public void caseARecordPattern(ARecordPattern pattern, NewQuestion question)
129:                         throws AnalysisException
130:         {
131:•                if (pattern.getResolved())
132:                 {
133:                         return;
134:                 } else
135:                 {
136:                         pattern.setResolved(true);
137:                 }
138:
139:                 try
140:                 {
141:                         af.createPPatternListAssistant().typeResolve(pattern.getPlist(), question.rootVisitor, question.question);
142:                         pattern.setType(af.createPTypeAssistant().typeResolve(pattern.getType(), null, question.rootVisitor, question.question));
143:                 } catch (TypeCheckException e)
144:                 {
145:                         af.createPPatternAssistant(fromModule).unResolve(pattern);
146:                         throw e;
147:                 }
148:         }
149:
150:         @Override
151:         public void caseASeqPattern(ASeqPattern pattern, NewQuestion question)
152:                         throws AnalysisException
153:         {
154:•                if (pattern.getResolved())
155:                 {
156:                         return;
157:                 } else
158:                 {
159:                         pattern.setResolved(true);
160:                 }
161:
162:                 try
163:                 {
164:                         af.createPPatternListAssistant().typeResolve(pattern.getPlist(), question.rootVisitor, question.question);
165:                 } catch (TypeCheckException e)
166:                 {
167:                         af.createPPatternAssistant(fromModule).unResolve(pattern);
168:                         throw e;
169:                 }
170:         }
171:
172:         @Override
173:         public void caseASetPattern(ASetPattern pattern, NewQuestion question)
174:                         throws AnalysisException
175:         {
176:•                if (pattern.getResolved())
177:                 {
178:                         return;
179:                 } else
180:                 {
181:                         pattern.setResolved(true);
182:                 }
183:
184:                 try
185:                 {
186:                         af.createPPatternListAssistant().typeResolve(pattern.getPlist(), question.rootVisitor, question.question);
187:                 } catch (TypeCheckException e)
188:                 {
189:                         af.createPPatternAssistant(fromModule).unResolve(pattern);
190:                         throw e;
191:                 }
192:         }
193:
194:         @Override
195:         public void caseATuplePattern(ATuplePattern pattern, NewQuestion question)
196:                         throws AnalysisException
197:         {
198:•                if (pattern.getResolved())
199:                 {
200:                         return;
201:                 } else
202:                 {
203:                         pattern.setResolved(true);
204:                 }
205:
206:                 try
207:                 {
208:                         af.createPPatternListAssistant().typeResolve(pattern.getPlist(), question.rootVisitor, question.question);
209:                 } catch (TypeCheckException e)
210:                 {
211:                         af.createPPatternAssistant(fromModule).unResolve(pattern);
212:                         throw e;
213:                 }
214:         }
215:
216:         @Override
217:         public void caseAUnionPattern(AUnionPattern pattern, NewQuestion question)
218:                         throws AnalysisException
219:         {
220:•                if (pattern.getResolved())
221:                 {
222:                         return;
223:                 } else
224:                 {
225:                         pattern.setResolved(true);
226:                 }
227:
228:                 try
229:                 {
230:                         pattern.getLeft().apply(THIS, question);
231:                         pattern.getRight().apply(THIS, question);
232:                 } catch (TypeCheckException e)
233:                 {
234:                         // AUnionPatternAssistantTC.unResolve(pattern);
235:                         af.createPPatternAssistant(fromModule).unResolve(pattern);
236:                         throw e;
237:                 }
238:         }
239:
240:         @Override
241:         public void caseAMapPattern(AMapPattern pattern, NewQuestion question)
242:                         throws AnalysisException
243:         {
244:•                if (pattern.getResolved())
245:                 {
246:                         return;
247:                 } else
248:                 {
249:                         pattern.setResolved(true);
250:                 }
251:
252:                 try
253:                 {
254:•                        for (AMapletPatternMaplet mp : pattern.getMaplets())
255:                         {
256:                                 // af.createAMapletPatternMapletAssistant().typeResolve(mp, question.rootVisitor, question.question);
257:                                 mp.apply(THIS, question);
258:                         }
259:                 } catch (TypeCheckException e)
260:                 {
261:                         // af.createAMapPatternAssistant().unResolve(pattern);
262:                         pattern.apply(af.getPatternUnresolver());
263:                         throw e;
264:                 }
265:         }
266:
267:         @Override
268:         public void caseAMapUnionPattern(AMapUnionPattern pattern,
269:                         NewQuestion question) throws AnalysisException
270:         {
271:•                if (pattern.getResolved())
272:                 {
273:                         return;
274:                 } else
275:                 {
276:                         pattern.setResolved(true);
277:                 }
278:
279:                 try
280:                 {
281:                         pattern.getLeft().apply(THIS, question);
282:                         pattern.getRight().apply(THIS, question);
283:                 } catch (TypeCheckException e)
284:                 {
285:                         // af.createAMapUnionPatternAssistant().unResolve(pattern);
286:                         pattern.apply(af.getPatternUnresolver());
287:                         throw e;
288:                 }
289:         }
290:
291:         @Override
292:         public void caseAObjectPattern(AObjectPattern pattern, NewQuestion question) throws AnalysisException
293:         {
294:•                if (pattern.getResolved())
295:                 {
296:                         return;
297:                 }
298:                 else
299:                 {
300:                         pattern.setResolved(true);
301:                 }
302:
303:                 try
304:                 {
305:                         af.createPPatternListAssistant().typeResolvePairs(pattern.getFields(), question.rootVisitor, question.question);
306:                         pattern.setType(af.createPTypeAssistant().typeResolve(pattern.getType(), null, question.rootVisitor, question.question));
307:                 }
308:                 catch (TypeCheckException e)
309:                 {
310:                         af.createPPatternAssistant(fromModule).unResolve(pattern);
311:                         throw e;
312:                 }
313:         }
314:
315:         @Override
316:         public void defaultPPattern(PPattern pattern, NewQuestion question)
317:                         throws AnalysisException
318:         {
319:                 pattern.setResolved(true);
320:         }
321: }