Package: ExpAssistantIR

ExpAssistantIR

nameinstructionbranchcomplexitylinemethod
ExpAssistantIR(AssistantManager)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
appearsInModuleStateInv(INode)
M: 2 C: 34
94%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 1 C: 10
91%
M: 0 C: 1
100%
consBoolLiteral(boolean)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
consCharLiteral(char)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
consCharSequence(STypeIR, String)
M: 0 C: 39
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
consHeader(SMultipleBindIR, SExpIR)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
consIdVar(String, STypeIR)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
consIntLiteral(long)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
consNullExp()
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%
consQuoteLiteral(String)
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
consRealLiteral(double)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
consStringLiteral(String, boolean)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
consUndefinedExp()
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%
findSubject(SExpIR)
M: 35 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getDefaultBoolValue()
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%
getDefaultCharlValue()
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%
getDefaultIntValue()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDefaultNat1Value()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDefaultNatValue()
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%
getDefaultRealValue()
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%
getDefaultStringlValue()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
handleAlternativesCasesExp(IRInfo, PExp, List, List)
M: 0 C: 102
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 20
100%
M: 0 C: 1
100%
handleBinaryExp(SBinaryExp, SBinaryExpIR, IRInfo)
M: 1 C: 44
98%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 11
100%
M: 0 C: 1
100%
handleMapType(SMapTypeBase, IRInfo, boolean)
M: 0 C: 44
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
handleQuantifier(PExp, List, PExp, SQuantifierExpIR, IRInfo, String)
M: 0 C: 56
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 13
100%
M: 0 C: 1
100%
handleUnaryExp(SUnaryExp, SUnaryExpIR, IRInfo)
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
idStateDesignatorToExp(AIdentifierStateDesignatorIR)
M: 0 C: 68
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
isAssigned(PExp)
M: 0 C: 54
100%
M: 0 C: 12
100%
M: 0 C: 7
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
isIntegerType(PExp)
M: 19 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
isIntegerType(SExpIR)
M: 0 C: 19
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
isLoopCondition(SExpIR)
M: 0 C: 20
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 4
100%
M: 0 C: 1
100%
isOld(String)
M: 0 C: 10
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 1
100%
M: 0 C: 1
100%
isResult(String)
M: 0 C: 10
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 1
100%
M: 0 C: 1
100%
isUndefined(SExpIR)
M: 0 C: 16
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
isolateExpression(SExpIR)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
negate(SExpIR)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
oldNameToCurrentName(String)
M: 2 C: 10
83%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 2
67%
M: 0 C: 1
100%
outsideImperativeContext(INode)
M: 0 C: 24
100%
M: 1 C: 9
90%
M: 1 C: 5
83%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * VDM Code Generator
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.codegen.assistant;
23:
24: import java.util.HashSet;
25: import java.util.LinkedList;
26: import java.util.List;
27: import java.util.Set;
28:
29: import org.overture.ast.analysis.AnalysisException;
30: import org.overture.ast.definitions.AAssignmentDefinition;
31: import org.overture.ast.definitions.AClassInvariantDefinition;
32: import org.overture.ast.definitions.AInstanceVariableDefinition;
33: import org.overture.ast.definitions.ANamedTraceDefinition;
34: import org.overture.ast.definitions.AStateDefinition;
35: import org.overture.ast.definitions.ATypeDefinition;
36: import org.overture.ast.definitions.AValueDefinition;
37: import org.overture.ast.definitions.SFunctionDefinition;
38: import org.overture.ast.definitions.SOperationDefinition;
39: import org.overture.ast.expressions.ACaseAlternative;
40: import org.overture.ast.expressions.ALambdaExp;
41: import org.overture.ast.expressions.ARealLiteralExp;
42: import org.overture.ast.expressions.PExp;
43: import org.overture.ast.expressions.SBinaryExp;
44: import org.overture.ast.expressions.SUnaryExp;
45: import org.overture.ast.patterns.PMultipleBind;
46: import org.overture.ast.statements.AAssignmentStm;
47: import org.overture.ast.types.AIntNumericBasicType;
48: import org.overture.ast.types.ANatNumericBasicType;
49: import org.overture.ast.types.ANatOneNumericBasicType;
50: import org.overture.ast.types.AUnionType;
51: import org.overture.ast.types.PType;
52: import org.overture.ast.types.SMapTypeBase;
53: import org.overture.codegen.ir.INode;
54: import org.overture.codegen.ir.IRInfo;
55: import org.overture.codegen.ir.SExpIR;
56: import org.overture.codegen.ir.SMultipleBindIR;
57: import org.overture.codegen.ir.STypeIR;
58: import org.overture.codegen.ir.expressions.AApplyExpIR;
59: import org.overture.codegen.ir.expressions.ABoolLiteralExpIR;
60: import org.overture.codegen.ir.expressions.ACaseAltExpExpIR;
61: import org.overture.codegen.ir.expressions.ACastUnaryExpIR;
62: import org.overture.codegen.ir.expressions.ACharLiteralExpIR;
63: import org.overture.codegen.ir.expressions.AEnumSeqExpIR;
64: import org.overture.codegen.ir.expressions.AExplicitVarExpIR;
65: import org.overture.codegen.ir.expressions.AFieldExpIR;
66: import org.overture.codegen.ir.expressions.AIdentifierVarExpIR;
67: import org.overture.codegen.ir.expressions.AIntLiteralExpIR;
68: import org.overture.codegen.ir.expressions.AIsolationUnaryExpIR;
69: import org.overture.codegen.ir.expressions.AMapSeqGetExpIR;
70: import org.overture.codegen.ir.expressions.ANotUnaryExpIR;
71: import org.overture.codegen.ir.expressions.ANullExpIR;
72: import org.overture.codegen.ir.expressions.AQuoteLiteralExpIR;
73: import org.overture.codegen.ir.expressions.ARealLiteralExpIR;
74: import org.overture.codegen.ir.expressions.AStringLiteralExpIR;
75: import org.overture.codegen.ir.expressions.AUndefinedExpIR;
76: import org.overture.codegen.ir.expressions.SBinaryExpIR;
77: import org.overture.codegen.ir.expressions.SQuantifierExpIR;
78: import org.overture.codegen.ir.expressions.SUnaryExpIR;
79: import org.overture.codegen.ir.expressions.SVarExpIR;
80: import org.overture.codegen.ir.statements.AForLoopStmIR;
81: import org.overture.codegen.ir.statements.AIdentifierStateDesignatorIR;
82: import org.overture.codegen.ir.statements.AWhileStmIR;
83: import org.overture.codegen.ir.types.ABoolBasicTypeIR;
84: import org.overture.codegen.ir.types.ACharBasicTypeIR;
85: import org.overture.codegen.ir.types.AClassTypeIR;
86: import org.overture.codegen.ir.types.AIntNumericBasicTypeIR;
87: import org.overture.codegen.ir.types.AMapMapTypeIR;
88: import org.overture.codegen.ir.types.ANat1NumericBasicTypeIR;
89: import org.overture.codegen.ir.types.ANatNumericBasicTypeIR;
90: import org.overture.codegen.ir.types.AQuoteTypeIR;
91: import org.overture.codegen.ir.types.ARealNumericBasicTypeIR;
92: import org.overture.codegen.ir.types.AStringTypeIR;
93: import org.overture.codegen.ir.types.AUnknownTypeIR;
94: import org.overture.codegen.ir.utils.AHeaderLetBeStIR;
95:
96: public class ExpAssistantIR extends AssistantBase
97: {
98:         public ExpAssistantIR(AssistantManager assistantManager)
99:         {
100:                 super(assistantManager);
101:         }
102:
103:         public AIdentifierVarExpIR consIdVar(String name, STypeIR type)
104:         {
105:                 AIdentifierVarExpIR var = new AIdentifierVarExpIR();
106:                 var.setIsLambda(false);
107:                 var.setIsLocal(true);
108:                 var.setType(type);
109:                 var.setName(name);
110:
111:                 return var;
112:         }
113:
114:         public SExpIR isolateExpression(SExpIR exp)
115:         {
116:                 AIsolationUnaryExpIR isolationExp = new AIsolationUnaryExpIR();
117:                 isolationExp.setExp(exp);
118:                 isolationExp.setType(exp.getType().clone());
119:                 return isolationExp;
120:         }
121:
122:         public ANotUnaryExpIR negate(SExpIR exp)
123:         {
124:                 ANotUnaryExpIR negated = new ANotUnaryExpIR();
125:                 negated.setType(exp.getType().clone());
126:                 negated.setExp(exp);
127:
128:                 return negated;
129:         }
130:
131:         public SExpIR handleUnaryExp(SUnaryExp vdmExp, SUnaryExpIR codeGenExp,
132:                         IRInfo question) throws AnalysisException
133:         {
134:                 SExpIR expCg = vdmExp.getExp().apply(question.getExpVisitor(), question);
135:                 STypeIR typeCg = vdmExp.getType().apply(question.getTypeVisitor(), question);
136:
137:                 codeGenExp.setType(typeCg);
138:                 codeGenExp.setExp(expCg);
139:
140:                 return codeGenExp;
141:         }
142:
143:         public SExpIR handleBinaryExp(SBinaryExp vdmExp, SBinaryExpIR codeGenExp,
144:                         IRInfo question) throws AnalysisException
145:         {
146:                 PType type = vdmExp.getType();
147:
148:•                STypeIR typeCg = type != null
149:                                 ? type.apply(question.getTypeVisitor(), question) : null;
150:                 codeGenExp.setType(typeCg);
151:
152:                 PExp vdmExpLeft = vdmExp.getLeft();
153:                 PExp vdmExpRight = vdmExp.getRight();
154:
155:                 SExpIR leftExpCg = vdmExpLeft.apply(question.getExpVisitor(), question);
156:                 SExpIR rightExpCg = vdmExpRight.apply(question.getExpVisitor(), question);
157:
158:                 codeGenExp.setLeft(leftExpCg);
159:                 codeGenExp.setRight(rightExpCg);
160:
161:                 return codeGenExp;
162:         }
163:
164:         public boolean isIntegerType(PExp exp)
165:         {
166:                 PType type = exp.getType();
167:
168:                 // Expressions like 1.0 are considered real literal expressions
169:                 // of type NatOneNumericBasicType
170:
171:•                return (type instanceof ANatOneNumericBasicType
172:                                 || type instanceof ANatNumericBasicType
173:                                 || type instanceof AIntNumericBasicType)
174:                                 && !(exp instanceof ARealLiteralExp);
175:         }
176:
177:         public boolean isIntegerType(SExpIR exp)
178:         {
179:                 STypeIR type = exp.getType();
180:
181:                 // Expressions like 1.0 are considered real literal expressions
182:                 // of type NatOneNumericBasicType
183:
184:•                return (type instanceof ANat1NumericBasicTypeIR
185:                                 || type instanceof ANatNumericBasicTypeIR
186:                                 || type instanceof AIntNumericBasicTypeIR)
187:                                 && !(exp instanceof ARealLiteralExpIR);
188:         }
189:
190:         public ABoolLiteralExpIR consBoolLiteral(boolean val)
191:         {
192:                 ABoolLiteralExpIR boolLiteral = new ABoolLiteralExpIR();
193:                 boolLiteral.setType(new ABoolBasicTypeIR());
194:                 boolLiteral.setValue(val);
195:
196:                 return boolLiteral;
197:         }
198:
199:         public AIntLiteralExpIR consIntLiteral(long value)
200:         {
201:                 AIntLiteralExpIR intLiteral = new AIntLiteralExpIR();
202:                 intLiteral.setType(new AIntNumericBasicTypeIR());
203:                 intLiteral.setValue(value);
204:
205:                 return intLiteral;
206:         }
207:
208:         public ARealLiteralExpIR consRealLiteral(double value)
209:         {
210:                 ARealLiteralExpIR realLiteral = new ARealLiteralExpIR();
211:                 realLiteral.setType(new ARealNumericBasicTypeIR());
212:                 realLiteral.setValue(value);
213:
214:                 return realLiteral;
215:         }
216:
217:         public ACharLiteralExpIR consCharLiteral(char value)
218:         {
219:                 ACharLiteralExpIR charLiteral = new ACharLiteralExpIR();
220:                 charLiteral.setType(new ACharBasicTypeIR());
221:                 charLiteral.setValue(value);
222:
223:                 return charLiteral;
224:         }
225:
226:         public AStringLiteralExpIR consStringLiteral(String value, boolean isNull)
227:         {
228:                 AStringLiteralExpIR stringLiteral = new AStringLiteralExpIR();
229:
230:                 stringLiteral.setType(new AStringTypeIR());
231:                 stringLiteral.setIsNull(isNull);
232:                 stringLiteral.setValue(value);
233:
234:                 return stringLiteral;
235:         }
236:
237:         public SExpIR consCharSequence(STypeIR seqType, String value)
238:         {
239:                 AEnumSeqExpIR enumSeq = new AEnumSeqExpIR();
240:
241:                 enumSeq.setType(seqType);
242:
243:•                for (int i = 0; i < value.length(); i++)
244:                 {
245:                         char currentChar = value.charAt(i);
246:                         ACharLiteralExpIR charLit = new ACharLiteralExpIR();
247:                         charLit.setType(new ACharBasicTypeIR());
248:                         charLit.setValue(currentChar);
249:
250:                         enumSeq.getMembers().add(charLit);
251:                 }
252:
253:                 return enumSeq;
254:         }
255:
256:         public AQuoteLiteralExpIR consQuoteLiteral(String value)
257:         {
258:                 AQuoteLiteralExpIR quoteLiteral = new AQuoteLiteralExpIR();
259:                 AQuoteTypeIR type = new AQuoteTypeIR();
260:                 type.setValue(value);
261:                 quoteLiteral.setType(type);
262:                 quoteLiteral.setValue(value);
263:
264:                 return quoteLiteral;
265:         }
266:
267:         public AIntLiteralExpIR getDefaultIntValue()
268:         {
269:                 return consIntLiteral(0L);
270:         }
271:
272:         public AIntLiteralExpIR getDefaultNat1Value()
273:         {
274:                 return consIntLiteral(1L);
275:         }
276:
277:         public AIntLiteralExpIR getDefaultNatValue()
278:         {
279:                 return consIntLiteral(0L);
280:         }
281:
282:         public ARealLiteralExpIR getDefaultRealValue()
283:         {
284:                 return consRealLiteral(0.0);
285:         }
286:
287:         public ABoolLiteralExpIR getDefaultBoolValue()
288:         {
289:                 return consBoolLiteral(false);
290:         }
291:
292:         public ACharLiteralExpIR getDefaultCharlValue()
293:         {
294:                 return consCharLiteral('0');
295:         }
296:
297:         public AStringLiteralExpIR getDefaultStringlValue()
298:         {
299:                 return consStringLiteral("", true);
300:         }
301:
302:         public boolean isAssigned(PExp exp)
303:         {
304:                 org.overture.ast.node.INode parent = exp.parent();
305:
306:•                if (parent == null)
307:                 {
308:                         return false;
309:                 }
310:
311:                 Set<org.overture.ast.node.INode> visitedNodes = new HashSet<>();
312:                 visitedNodes.add(parent);
313:
314:                 do
315:                 {
316:•                        if (parent instanceof AInstanceVariableDefinition
317:                                         | parent instanceof AValueDefinition
318:                                         | parent instanceof AAssignmentDefinition
319:                                         | parent instanceof AAssignmentStm)
320:                         {
321:                                 return true;
322:                         }
323:
324:•                        if (parent instanceof ALambdaExp)
325:                         {
326:                                 return false;
327:                         }
328:
329:                         parent = parent.parent();
330:
331:•                        if (parent != null)
332:                         {
333:•                                if (visitedNodes.contains(parent))
334:                                 {
335:                                         parent = null;
336:                                 } else
337:                                 {
338:                                         visitedNodes.add(parent);
339:                                 }
340:                         }
341:
342:•                } while (parent != null);
343:
344:                 return false;
345:         }
346:
347:         public AHeaderLetBeStIR consHeader(SMultipleBindIR binding, SExpIR suchThat)
348:         {
349:                 AHeaderLetBeStIR header = new AHeaderLetBeStIR();
350:
351:                 header.setBinding(binding);
352:                 header.setSuchThat(suchThat);
353:
354:                 return header;
355:         }
356:
357:         public boolean appearsInModuleStateInv(org.overture.ast.node.INode node)
358:         {
359:                 AStateDefinition stateDef = node.getAncestor(AStateDefinition.class);
360:•                if (stateDef != null)
361:                 {
362:                         LinkedList<org.overture.ast.node.INode> ancestors = new LinkedList<>();
363:                         org.overture.ast.node.INode next = node;
364:
365:                         do
366:                         {
367:                                 ancestors.add(next);
368:                                 next = node.parent();
369:•                        } while (!(next instanceof AStateDefinition)
370:•                                        && !ancestors.contains(next));
371:
372:•                        if (ancestors.getLast() == stateDef.getInvExpression())
373:                         {
374:                                 return true;
375:                         }
376:                 }
377:                 return false;
378:         }
379:
380:         public boolean outsideImperativeContext(org.overture.ast.node.INode node)
381:         {
382:                 // The transformation of the 'and' and 'or' logical expressions also assumes that the
383:                 // expressions exist within a statement. However, in case it does not, the transformation
384:                 // is not performed. In this way, the 'and' and 'or' expressions can
385:                 // still be used (say) in instance variable assignment.
386:
387:•                return node.getAncestor(SOperationDefinition.class) == null
388:•                                && node.getAncestor(SFunctionDefinition.class) == null
389:•                                && node.getAncestor(ANamedTraceDefinition.class) == null
390:•                                && node.getAncestor(ATypeDefinition.class) == null
391:•                                && node.getAncestor(AClassInvariantDefinition.class) == null;
392:         }
393:
394:         public SExpIR handleQuantifier(PExp node, List<PMultipleBind> bindings,
395:                         PExp predicate, SQuantifierExpIR quantifier, IRInfo question,
396:                         String nodeStr) throws AnalysisException
397:         {
398:                 LinkedList<SMultipleBindIR> bindingsCg = new LinkedList<SMultipleBindIR>();
399:•                for (PMultipleBind multipleBind : bindings)
400:                 {
401:                         SMultipleBindIR multipleBindCg = multipleBind.apply(question.getMultipleBindVisitor(), question);
402:
403:•                        if (multipleBindCg != null)
404:                         {
405:                                 bindingsCg.add(multipleBindCg);
406:                         }
407:                 }
408:
409:                 PType type = node.getType();
410:
411:                 STypeIR typeCg = type.apply(question.getTypeVisitor(), question);
412:                 SExpIR predicateCg = predicate.apply(question.getExpVisitor(), question);
413:
414:                 quantifier.setType(typeCg);
415:                 quantifier.setBindList(bindingsCg);
416:                 quantifier.setPredicate(predicateCg);
417:
418:                 return quantifier;
419:         }
420:
421:         public void handleAlternativesCasesExp(IRInfo question, PExp exp,
422:                         List<ACaseAlternative> cases, List<ACaseAltExpExpIR> casesCg)
423:                         throws AnalysisException
424:         {
425:•                for (ACaseAlternative alt : cases)
426:                 {
427:                         SExpIR altCg = alt.apply(question.getExpVisitor(), question);
428:                         casesCg.add((ACaseAltExpExpIR) altCg);
429:                 }
430:
431:                 PType expType = question.getTypeAssistant().resolve(exp.getType());
432:
433:•                if (expType instanceof AUnionType)
434:                 {
435:                         AUnionType unionType = ((AUnionType) expType).clone();
436:                         question.getTcFactory().createAUnionTypeAssistant().expand(unionType);
437:
438:•                        for (int i = 0; i < cases.size(); i++)
439:                         {
440:                                 ACaseAlternative vdmCase = cases.get(i);
441:                                 ACaseAltExpExpIR cgCase = casesCg.get(i);
442:
443:                                 PType patternType = question.getAssistantManager().getTypeAssistant().getType(question, unionType, vdmCase.getPattern());
444:                                 STypeIR patternTypeCg = patternType.apply(question.getTypeVisitor(), question);
445:                                 cgCase.setPatternType(patternTypeCg);
446:                         }
447:                 } else
448:                 {
449:                         STypeIR expTypeCg = expType.apply(question.getTypeVisitor(), question);
450:
451:•                        for (ACaseAltExpExpIR altCg : casesCg)
452:                         {
453:                                 altCg.setPatternType(expTypeCg.clone());
454:                         }
455:                 }
456:         }
457:
458:         public boolean isLoopCondition(SExpIR exp)
459:         {
460:                 INode node = exp.parent();
461:
462:•                while (node instanceof SExpIR)
463:                 {
464:                         node = node.parent();
465:                 }
466:
467:•                return node instanceof AWhileStmIR || node instanceof AForLoopStmIR;
468:                 // The ForLoopStmIR is only used in the transformation process. It corresponds
469:                 // to the standard for loop in Java, e.g. for(int i = 0; i < 10; i++){...}
470:         }
471:
472:         public SVarExpIR idStateDesignatorToExp(AIdentifierStateDesignatorIR node)
473:         {
474:•                if (node.getExplicit())
475:                 {
476:                         AClassTypeIR classType = new AClassTypeIR();
477:                         classType.setName(node.getClassName());
478:
479:                         AExplicitVarExpIR explicitVar = new AExplicitVarExpIR();
480:                         explicitVar.setClassType(classType);
481:                         explicitVar.setIsLambda(false);
482:                         explicitVar.setIsLocal(node.getIsLocal());
483:                         explicitVar.setName(node.getName());
484:                         explicitVar.setSourceNode(node.getSourceNode());
485:                         explicitVar.setTag(node.getTag());
486:                         explicitVar.setType(node.getType().clone());
487:
488:                         return explicitVar;
489:                 } else
490:                 {
491:                         AIdentifierVarExpIR idVar = consIdVar(node.getName(), node.getType().clone());
492:                         idVar.setTag(node.getTag());
493:                         idVar.setSourceNode(node.getSourceNode());
494:                         idVar.setIsLocal(node.getIsLocal());
495:
496:                         return idVar;
497:                 }
498:         }
499:
500:         public boolean isOld(String name)
501:         {
502:•                return name != null && name.startsWith("_");
503:         }
504:
505:         public String oldNameToCurrentName(String oldName)
506:         {
507:•                if (oldName != null && oldName.startsWith("_"))
508:                 {
509:                         return oldName.substring(1);
510:                 } else
511:                 {
512:                         return oldName;
513:                 }
514:         }
515:
516:         public boolean isResult(String name)
517:         {
518:•                return name != null && name.equals("RESULT");
519:         }
520:
521:         public SExpIR findSubject(SExpIR next)
522:         {
523:•                while (next instanceof AFieldExpIR || next instanceof AMapSeqGetExpIR
524:                                 || next instanceof AApplyExpIR)
525:                 {
526:•                        if (next instanceof AFieldExpIR)
527:                         {
528:                                 next = ((AFieldExpIR) next).getObject();
529:•                        } else if (next instanceof AMapSeqGetExpIR)
530:                         {
531:                                 next = ((AMapSeqGetExpIR) next).getCol();
532:•                        } else if (next instanceof AApplyExpIR)
533:                         {
534:                                 next = ((AApplyExpIR) next).getRoot();
535:                         }
536:                 }
537:
538:                 return next;
539:         }
540:
541:         public AUndefinedExpIR consUndefinedExp()
542:         {
543:                 AUndefinedExpIR undefExp = new AUndefinedExpIR();
544:                 undefExp.setType(new AUnknownTypeIR());
545:
546:                 return undefExp;
547:         }
548:
549:         public ANullExpIR consNullExp()
550:         {
551:                 ANullExpIR nullExp = new ANullExpIR();
552:                 nullExp.setType(new AUnknownTypeIR());
553:
554:                 return nullExp;
555:         }
556:
557:         public STypeIR handleMapType(SMapTypeBase node, IRInfo question,
558:                         boolean isInjective) throws AnalysisException
559:         {
560:                 PType from = node.getFrom();
561:                 PType to = node.getTo();
562:                 boolean empty = node.getEmpty();
563:
564:                 STypeIR fromCg = from.apply(question.getTypeVisitor(), question);
565:                 STypeIR toCg = to.apply(question.getTypeVisitor(), question);
566:
567:                 AMapMapTypeIR mapType = new AMapMapTypeIR();
568:                 mapType.setFrom(fromCg);
569:                 mapType.setTo(toCg);
570:                 mapType.setEmpty(empty);
571:
572:                 mapType.setInjective(isInjective);
573:
574:                 return mapType;
575:         }
576:
577:         public boolean isUndefined(SExpIR exp)
578:         {
579:•                if (exp instanceof ACastUnaryExpIR)
580:                 {
581:                         return isUndefined(((ACastUnaryExpIR) exp).getExp());
582:•                } else if (exp instanceof AUndefinedExpIR)
583:                 {
584:                         return true;
585:                 } else
586:                 {
587:                         return false;
588:                 }
589:         }
590: }