Package: TransAssistantIR

TransAssistantIR

nameinstructionbranchcomplexitylinemethod
TransAssistantIR(IRInfo)
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%
cleanUpBinding(SMultipleBindIR)
M: 24 C: 14
37%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 5 C: 6
55%
M: 0 C: 1
100%
consAndExp(SExpIR, SExpIR)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
consBoolCheck(String, boolean)
M: 0 C: 34
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
consBoolVarAssignment(SExpIR, String)
M: 0 C: 24
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
consBoolVarDecl(String, boolean)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
consClassType(String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
consClassVarDeclDefaultCtor(String, String)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
consComplexCompIterationBlock(List, ITempVarGen, IIterationStrategy, IterationVarPrefixes)
M: 11 C: 90
89%
M: 1 C: 11
92%
M: 1 C: 6
86%
M: 1 C: 17
94%
M: 0 C: 1
100%
consConditionalCall(AMethodDeclIR, AMethodDeclIR)
M: 25 C: 126
83%
M: 3 C: 9
75%
M: 3 C: 4
57%
M: 3 C: 30
91%
M: 0 C: 1
100%
consConditionalIncrement(String, SExpIR)
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
consDecl(String, STypeIR, SExpIR)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
consDefaultConsCall(AClassTypeIR)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
consDefaultConsCall(String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
consField(String, STypeIR, String, SExpIR)
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
consInstanceCall(STypeIR, String, STypeIR, String, SExpIR[])
M: 0 C: 80
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 18
100%
M: 0 C: 1
100%
consInstanceCallStm(STypeIR, String, String, SExpIR[])
M: 0 C: 53
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
consIterationBlock(ABlockStmIR, List, SExpIR, ITempVarGen, IIterationStrategy, IterationVarPrefixes)
M: 0 C: 183
100%
M: 0 C: 20
100%
M: 0 C: 11
100%
M: 0 C: 45
100%
M: 0 C: 1
100%
consIterationBlock(List, SExpIR, ITempVarGen, IIterationStrategy, IterationVarPrefixes)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
consLessThanCheck(String, long)
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
consNextElementAssignment(STypeIR, STypeIR, SPatternIR, String, String, AVarDeclIR)
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
consNextElementCall(STypeIR, String, STypeIR, String)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
consNextElementCall(STypeIR, String, String, ACompSeqExpIR)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
consNextElementDeclared(STypeIR, STypeIR, SPatternIR, String, String)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
consRecType(String, String)
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
consSetBindDecl(String, SExpIR)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
consSetVar(String, SExpIR)
M: 0 C: 24
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
consSuccessVar(String)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
consTypeNameForClass(String)
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%
getElementType(STypeIR)
M: 31 C: 31
50%
M: 3 C: 5
63%
M: 2 C: 3
60%
M: 4 C: 8
67%
M: 0 C: 1
100%
getEnclosingModuleName(AStateDeclIR)
M: 14 C: 10
42%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 3 C: 3
50%
M: 0 C: 1
100%
getInfo()
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%
getRecType(AStateDeclIR)
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%
getSeqTypeCloned(SExpIR)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getSeqTypeCloned(STypeIR)
M: 55 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
getSetTypeCloned(SExpIR)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getSetTypeCloned(STypeIR)
M: 2 C: 9
82%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 3
75%
M: 0 C: 1
100%
getTypeName(AStateDeclIR)
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%
hasEmptySet(SMultipleBindIR)
M: 3 C: 18
86%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 4
80%
M: 0 C: 1
100%
isEmptySetSeq(SExpIR)
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%
wrap(AVarDeclIR)
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%
wrap(SStmIR)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

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.trans.assistants;
23:
24: import org.apache.log4j.Logger;
25: import org.overture.ast.lex.Dialect;
26: import org.overture.ast.types.PType;
27: import org.overture.ast.types.SSeqType;
28: import org.overture.codegen.ir.*;
29: import org.overture.codegen.ir.analysis.AnalysisException;
30: import org.overture.codegen.ir.declarations.*;
31: import org.overture.codegen.ir.expressions.*;
32: import org.overture.codegen.ir.name.ATypeNameIR;
33: import org.overture.codegen.ir.patterns.AIdentifierPatternIR;
34: import org.overture.codegen.ir.patterns.ASeqMultipleBindIR;
35: import org.overture.codegen.ir.patterns.ASetMultipleBindIR;
36: import org.overture.codegen.ir.statements.*;
37: import org.overture.codegen.ir.types.*;
38: import org.overture.codegen.trans.IIterationStrategy;
39: import org.overture.codegen.trans.IterationVarPrefixes;
40: import org.overture.config.Settings;
41:
42: import java.util.LinkedList;
43: import java.util.List;
44:
45: public class TransAssistantIR extends BaseTransformationAssistant
46: {
47:         public static final String ITERABLE = "Iterable";
48:
49:         protected IRInfo info;
50:
51:         private Logger log = Logger.getLogger(this.getClass().getName());
52:
53:         public TransAssistantIR(IRInfo info)
54:         {
55:                 this.info = info;
56:         }
57:
58:         public IRInfo getInfo()
59:         {
60:                 return info;
61:         }
62:
63:         public SSetTypeIR getSetTypeCloned(SExpIR set) throws AnalysisException
64:         {
65:                 STypeIR typeCg = set.getType();
66:
67:                 return getSetTypeCloned(typeCg);
68:         }
69:
70:         public SSetTypeIR getSetTypeCloned(STypeIR typeCg) throws AnalysisException
71:         {
72:•                if (typeCg instanceof SSetTypeIR)
73:                 {
74:                         SSetTypeIR setTypeCg = (SSetTypeIR) typeCg;
75:
76:                         return setTypeCg.clone();
77:                 }
78:
79:                 return null;
80:         }
81:
82:         public SSeqTypeIR getSeqTypeCloned(SExpIR seq) throws AnalysisException
83:         {
84:                 STypeIR typeCg = seq.getType();
85:
86:                 return getSeqTypeCloned(typeCg);
87:         }
88:
89:         public SSeqTypeIR getSeqTypeCloned(STypeIR typeCg) throws AnalysisException
90:         {
91:•                if (typeCg instanceof SSeqTypeIR)
92:                 {
93:                         SSeqTypeIR seqTypeCg = (SSeqTypeIR) typeCg;
94:
95:                         return seqTypeCg.clone();
96:                 } else
97:                 {
98:                         SourceNode sourceNode = typeCg.getSourceNode();
99:
100:•                        if (sourceNode != null && sourceNode.getVdmNode() instanceof PType)
101:                         {
102:                                 PType vdmType = (PType) sourceNode.getVdmNode();
103:                                 SSeqType seqType = info.getTcFactory().createPTypeAssistant().getSeq(vdmType, null);
104:                                 try
105:                                 {
106:                                         typeCg = seqType.apply(info.getTypeVisitor(), info);
107:                                         return (SSeqTypeIR) typeCg;
108:
109:                                 } catch (org.overture.ast.analysis.AnalysisException e)
110:                                 {
111:                                 }
112:                         }
113:
114:                         throw new AnalysisException("Exptected sequence type. Got: "
115:                                         + typeCg);
116:                 }
117:         }
118:
119:         public STypeIR getElementType(STypeIR t)
120:         {
121:                 STypeIR elementType;
122:
123:•                if (t instanceof ASetSetTypeIR)
124:                 {
125:                         elementType = ((ASetSetTypeIR) t).getSetOf().clone();
126:•                } else if (t instanceof ASeqSeqTypeIR)
127:                 {
128:                         elementType = ((ASeqSeqTypeIR) t).getSeqOf().clone();
129:                 } else
130:                 {
131:                         elementType = new AUnknownTypeIR();
132:                         elementType.setSourceNode(t.getSourceNode());
133:                         
134:•                        if(!(t instanceof AClassTypeIR))
135:                         {
136:                                 AClassTypeIR classType = (AClassTypeIR) t;
137:                                 
138:•                                if(!classType.getName().equals(ITERABLE)) {
139:                                         String vdmNodeInfo = info.getLocationAssistant().consVdmNodeInfoStr(t);
140:                                         log.error("Expected set or sequence type. Got: " + t.getClass().getName() + "." + vdmNodeInfo);
141:
142:                                 }
143:                         }
144:                         
145:                 }
146:
147:                 return elementType;
148:         }
149:
150:
151:         public AIdentifierVarExpIR consSuccessVar(String successVarName)
152:         {
153:                 AIdentifierVarExpIR successVar = new AIdentifierVarExpIR();
154:                 successVar.setIsLambda(false);
155:                 successVar.setIsLocal(true);
156:                 successVar.setName(successVarName);
157:                 successVar.setType(new ABoolBasicTypeIR());
158:
159:                 return successVar;
160:         }
161:
162:         public AVarDeclIR consBoolVarDecl(String boolVarName, boolean initValue)
163:         {
164:                 return info.getDeclAssistant().consLocalVarDecl(new ABoolBasicTypeIR(), info.getPatternAssistant().consIdPattern(boolVarName), info.getExpAssistant().consBoolLiteral(initValue));
165:         }
166:
167:         public SExpIR consAndExp(SExpIR left, SExpIR right)
168:         {
169:                 AAndBoolBinaryExpIR andExp = new AAndBoolBinaryExpIR();
170:                 andExp.setType(new ABoolBasicTypeIR());
171:                 andExp.setLeft(left);
172:                 andExp.setRight(right);
173:
174:                 return andExp;
175:         }
176:
177:         public SExpIR consLessThanCheck(String varName, long value)
178:         {
179:                 AIdentifierVarExpIR left = new AIdentifierVarExpIR();
180:                 left.setType(new AIntNumericBasicTypeIR());
181:                 left.setIsLocal(true);
182:                 left.setName(varName);
183:
184:                 AIntLiteralExpIR right = info.getExpAssistant().consIntLiteral(value);
185:
186:                 ALessNumericBinaryExpIR less = new ALessNumericBinaryExpIR();
187:                 less.setType(new ABoolBasicTypeIR());
188:                 less.setLeft(left);
189:                 less.setRight(right);
190:
191:                 return less;
192:         }
193:
194:         public SExpIR consBoolCheck(String boolVarName, boolean negate)
195:         {
196:                 AIdentifierVarExpIR boolVarExp = new AIdentifierVarExpIR();
197:                 boolVarExp.setType(new ABoolBasicTypeIR());
198:                 boolVarExp.setIsLocal(true);
199:                 boolVarExp.setName(boolVarName);
200:
201:•                if (negate)
202:                 {
203:                         ANotUnaryExpIR negated = new ANotUnaryExpIR();
204:                         negated.setType(new ABoolBasicTypeIR());
205:                         negated.setExp(boolVarExp);
206:
207:                         return negated;
208:                 } else
209:                 {
210:                         return boolVarExp;
211:                 }
212:         }
213:
214:         public AAssignToExpStmIR consBoolVarAssignment(SExpIR predicate,
215:                         String boolVarName)
216:         {
217:                 AAssignToExpStmIR boolVarAssignment = new AAssignToExpStmIR();
218:                 boolVarAssignment.setTarget(consBoolCheck(boolVarName, false));
219:•                boolVarAssignment.setExp(predicate != null ? predicate.clone()
220:                                 : info.getExpAssistant().consBoolLiteral(true));
221:
222:                 return boolVarAssignment;
223:         }
224:
225:         public AVarDeclIR consSetBindDecl(String setBindName, SExpIR col)
226:                         throws AnalysisException
227:         {
228:                 return info.getDeclAssistant().consLocalVarDecl(col.getType().clone(), info.getPatternAssistant().consIdPattern(setBindName), col.clone());
229:         }
230:
231:         public AVarDeclIR consDecl(String varName, STypeIR type, SExpIR exp)
232:         {
233:                 return info.getDeclAssistant().consLocalVarDecl(type, info.getPatternAssistant().consIdPattern(varName), exp);
234:         }
235:
236:         public AClassTypeIR consClassType(String classTypeName)
237:         {
238:                 AClassTypeIR classType = new AClassTypeIR();
239:                 classType.setName(classTypeName);
240:
241:                 return classType;
242:         }
243:
244:         public SExpIR consInstanceCall(STypeIR instanceType, String instanceName,
245:                         STypeIR returnType, String memberName, SExpIR... args)
246:         {
247:                 AIdentifierVarExpIR instance = new AIdentifierVarExpIR();
248:                 instance.setType(instanceType.clone());
249:                 instance.setName(instanceName);
250:                 instance.setIsLocal(true);
251:
252:                 AFieldExpIR fieldExp = new AFieldExpIR();
253:                 fieldExp.setMemberName(memberName);
254:                 fieldExp.setObject(instance);
255:
256:                 AMethodTypeIR methodType = new AMethodTypeIR();
257:                 methodType.setResult(returnType.clone());
258:
259:                 AApplyExpIR instanceCall = new AApplyExpIR();
260:
261:                 instanceCall.setType(returnType.clone());
262:
263:•                if (args != null)
264:                 {
265:•                        for (SExpIR arg : args)
266:                         {
267:                                 methodType.getParams().add(arg.getType().clone());
268:                                 instanceCall.getArgs().add(arg);
269:                         }
270:                 }
271:
272:                 fieldExp.setType(methodType.clone());
273:
274:                 instanceCall.setRoot(fieldExp);
275:
276:                 return instanceCall;
277:         }
278:
279:         // TODO: This actually forces the return type to be 'void'. Maybe generalise?
280:         public ACallObjectExpStmIR consInstanceCallStm(STypeIR instanceType,
281:                         String instanceName, String memberName, SExpIR... args)
282:         {
283:                 AIdentifierVarExpIR instance = new AIdentifierVarExpIR();
284:                 instance.setName(instanceName);
285:                 instance.setType(instanceType.clone());
286:                 instance.setIsLocal(true);
287:
288:                 ACallObjectExpStmIR call = new ACallObjectExpStmIR();
289:                 call.setType(new AVoidTypeIR());
290:                 call.setFieldName(memberName);
291:                 call.setObj(instance);
292:
293:•                for (SExpIR arg : args)
294:                 {
295:                         call.getArgs().add(arg);
296:                 }
297:
298:                 return call;
299:         }
300:
301:         public AVarDeclIR consNextElementDeclared(STypeIR iteratorType,
302:                         STypeIR elementType, SPatternIR id, String iteratorName,
303:                         String nextElementMethod) throws AnalysisException
304:         {
305:                 ACastUnaryExpIR cast = consNextElementCall(iteratorType, iteratorName, elementType, nextElementMethod);
306:
307:                 return info.getDeclAssistant().consLocalVarDecl(elementType, id.clone(), cast);
308:         }
309:
310:         public ALocalPatternAssignmentStmIR consNextElementAssignment(
311:                         STypeIR iteratorType, STypeIR elementType, SPatternIR id,
312:                         String iteratorName, String nextElementMethod,
313:                         AVarDeclIR nextElementDecl) throws AnalysisException
314:         {
315:                 ACastUnaryExpIR cast = consNextElementCall(iteratorType, iteratorName, elementType, nextElementMethod);
316:
317:                 ALocalPatternAssignmentStmIR assignment = new ALocalPatternAssignmentStmIR();
318:                 assignment.setTarget(id.clone());
319:                 assignment.setExp(cast);
320:
321:                 // Associate the pattern assignment with its declaration and
322:                 // the corresponding success variable (both are graph fields)
323:                 assignment.setTag(nextElementDecl.getTag());
324:                 assignment.setNextElementDecl(nextElementDecl);
325:                 // assignment.setSuccessVarDecl(successVarDecl);
326:
327:                 return assignment;
328:         }
329:
330:         public ANewExpIR consDefaultConsCall(String className)
331:         {
332:                 return consDefaultConsCall(consClassType(className));
333:         }
334:
335:         public ANewExpIR consDefaultConsCall(AClassTypeIR classType)
336:         {
337:                 ANewExpIR initAltNode = new ANewExpIR();
338:                 initAltNode.setType(classType.clone());
339:                 initAltNode.setName(consTypeNameForClass(classType.getName()));
340:
341:                 return initAltNode;
342:         }
343:
344:         public ATypeNameIR consTypeNameForClass(String classTypeName)
345:         {
346:                 ATypeNameIR typeName = new ATypeNameIR();
347:                 typeName.setDefiningClass(null);
348:                 typeName.setName(classTypeName);
349:
350:                 return typeName;
351:         }
352:
353:         public ACastUnaryExpIR consNextElementCall(STypeIR iteratorType,
354:                         String iteratorName, STypeIR elementType, String nextElementMethod)
355:         {
356:                 ACastUnaryExpIR cast = new ACastUnaryExpIR();
357:                 cast.setType(elementType.clone());
358:                 cast.setExp(consInstanceCall(iteratorType, iteratorName, elementType.clone(), nextElementMethod));
359:                 return cast;
360:         }
361:
362:         public AIfStmIR consConditionalIncrement(String counterName, SExpIR predicate)
363:         {
364:                 AIdentifierVarExpIR col = new AIdentifierVarExpIR();
365:                 col.setType(new AIntNumericBasicTypeIR());
366:                 col.setIsLambda(false);
367:                 col.setIsLocal(true);
368:                 col.setName(counterName);
369:
370:                 AIncrementStmIR inc = new AIncrementStmIR();
371:                 inc.setVar(col);
372:
373:                 AIfStmIR ifStm = new AIfStmIR();
374:                 ifStm.setIfExp(predicate);
375:                 ifStm.setThenStm(inc);
376:
377:                 return ifStm;
378:         }
379:
380:         public ABlockStmIR consIterationBlock(List<SPatternIR> ids, SExpIR set,
381:                         ITempVarGen tempGen, IIterationStrategy strategy,
382:                         IterationVarPrefixes iteVarPrefixes) throws AnalysisException
383:         {
384:                 ABlockStmIR outerBlock = new ABlockStmIR();
385:
386:                 consIterationBlock(outerBlock, ids, set, tempGen, strategy, iteVarPrefixes);
387:
388:                 return outerBlock;
389:         }
390:
391:         public AIdentifierVarExpIR consSetVar(String setName, SExpIR set)
392:         {
393:•                if (set == null)
394:                 {
395:                         return null;
396:                 }
397:
398:                 AIdentifierVarExpIR setVar = new AIdentifierVarExpIR();
399:
400:                 STypeIR setType = set.getType().clone();
401:
402:                 setVar.setType(setType);
403:                 setVar.setName(setName);
404:                 setVar.setIsLocal(true);
405:
406:                 return setVar;
407:         }
408:
409:         private ABlockStmIR consIterationBlock(ABlockStmIR outerBlock,
410:                         List<SPatternIR> patterns, SExpIR set, ITempVarGen tempGen,
411:                         IIterationStrategy strategy, IterationVarPrefixes iteVarPrefixes)
412:                         throws AnalysisException
413:         {
414:•                if(set != null && set.getType() instanceof AUnionTypeIR)
415:                 {
416:                         AClassTypeIR iteType = new AClassTypeIR();
417:                         iteType.setName(ITERABLE);
418:                         
419:                         ACastUnaryExpIR cast = new ACastUnaryExpIR();
420:                         cast.setType(iteType);
421:                         cast.setExp(set);
422:                         
423:                         set = cast;
424:                 }
425:                 
426:                 // Variable names
427:                 String setName = tempGen.nextVarName(iteVarPrefixes.set());
428:                 AIdentifierVarExpIR setVar = consSetVar(setName, set);
429:
430:                 ABlockStmIR forBody = null;
431:                 List<AVarDeclIR> extraDecls = strategy.getOuterBlockDecls(setVar, patterns);
432:
433:•                if (extraDecls != null)
434:                 {
435:                         outerBlock.getLocalDefs().addAll(extraDecls);
436:                 }
437:
438:•                if (setVar != null)
439:                 {
440:                         outerBlock.getLocalDefs().add(consSetBindDecl(setName, set));
441:
442:                         ABlockStmIR nextBlock = outerBlock;
443:
444:                         for (int i = 0;;)
445:                         {
446:                                 SPatternIR pattern = patterns.get(i);
447:
448:                                 List<SStmIR> stms = strategy.getPreForLoopStms(setVar, patterns, pattern);
449:
450:•                                if (stms != null)
451:                                 {
452:                                         nextBlock.getStatements().addAll(stms);
453:                                 }
454:
455:                                 // Construct next for loop
456:                                 AForLoopStmIR forLoop = new AForLoopStmIR();
457:
458:                                 forLoop.setInit(strategy.getForLoopInit(setVar, patterns, pattern));
459:                                 forLoop.setCond(strategy.getForLoopCond(setVar, patterns, pattern));
460:                                 forLoop.setInc(strategy.getForLoopInc(setVar, patterns, pattern));
461:
462:                                 ABlockStmIR stmCollector = new ABlockStmIR();
463:
464:                                 AVarDeclIR nextElementDeclared = strategy.getNextElementDeclared(setVar, patterns, pattern);
465:
466:•                                if (nextElementDeclared != null)
467:                                 {
468:                                         stmCollector.getLocalDefs().add(nextElementDeclared);
469:                                 }
470:
471:                                 ALocalPatternAssignmentStmIR assignment = strategy.getNextElementAssigned(setVar, patterns, pattern);
472:
473:•                                if (assignment != null)
474:                                 {
475:                                         stmCollector.getStatements().add(assignment);
476:                                 }
477:
478:                                 forBody = stmCollector;
479:
480:                                 forLoop.setBody(forBody);
481:
482:                                 nextBlock.getStatements().add(forLoop);
483:
484:•                                if (++i < patterns.size())
485:                                 {
486:                                         nextBlock = forBody;
487:                                 } else
488:                                 {
489:                                         List<SStmIR> extraForLoopStatements = strategy.getForLoopStms(setVar, patterns, pattern);
490:
491:•                                        if (extraForLoopStatements != null)
492:                                         {
493:                                                 forBody.getStatements().addAll(extraForLoopStatements);
494:                                         }
495:
496:                                         break;
497:                                 }
498:                         }
499:                 }
500:
501:                 List<SStmIR> extraOuterBlockStms = strategy.getPostOuterBlockStms(setVar, patterns);
502:
503:•                if (extraOuterBlockStms != null)
504:                 {
505:                         outerBlock.getStatements().addAll(extraOuterBlockStms);
506:                 }
507:
508:                 return forBody;
509:         }
510:
511:         // FIXME make this method work on generic PMUltipleBinds
512:         public ABlockStmIR consComplexCompIterationBlock(
513:                         List<SMultipleBindIR> multipleSetBinds, ITempVarGen tempGen,
514:                         IIterationStrategy strategy, IterationVarPrefixes iteVarPrefixes)
515:                         throws AnalysisException
516:         {
517:                 ABlockStmIR outerBlock = new ABlockStmIR();
518:
519:                 ABlockStmIR nextMultiBindBlock = outerBlock;
520:
521:•                for (SMultipleBindIR bind : multipleSetBinds)
522:                 {
523:•                        if (hasEmptySet(bind))
524:                         {
525:                                 multipleSetBinds.clear();
526:                                 return outerBlock;
527:                         }
528:                 }
529:
530:                 strategy.setFirstBind(true);
531:
532:•                for (int i = 0; i < multipleSetBinds.size(); i++)
533:                 {
534:•                        strategy.setLastBind(i == multipleSetBinds.size() - 1);
535:
536:                         SMultipleBindIR mb = multipleSetBinds.get(i);
537:
538:•                        if (mb instanceof ASetMultipleBindIR)
539:                         {
540:                                 nextMultiBindBlock = consIterationBlock(nextMultiBindBlock, mb.getPatterns(), ((ASetMultipleBindIR) mb).getSet(), tempGen, strategy, iteVarPrefixes);
541:•                        } else if (mb instanceof ASeqMultipleBindIR)
542:                         {
543:                                 nextMultiBindBlock = consIterationBlock(nextMultiBindBlock, mb.getPatterns(), ((ASeqMultipleBindIR) mb).getSeq(), tempGen, strategy, iteVarPrefixes);
544:                         } else
545:                         {
546:                                 log.error("Expected set multiple bind or sequence multiple bind. Got: "
547:                                                 + mb);
548:                         }
549:
550:                         strategy.setFirstBind(false);
551:                 }
552:
553:                 return outerBlock;
554:         }
555:
556:         public ACastUnaryExpIR consNextElementCall(STypeIR instanceType,
557:                         String instance, String member, ACompSeqExpIR seqComp)
558:                         throws AnalysisException
559:         {
560:
561:                 STypeIR elementType = getSeqTypeCloned(seqComp).getSeqOf();
562:
563:                 SExpIR nextCall = consInstanceCall(instanceType, instance, elementType.clone(), member);
564:                 ACastUnaryExpIR cast = new ACastUnaryExpIR();
565:                 cast.setType(elementType.clone());
566:                 cast.setExp(nextCall);
567:
568:                 return cast;
569:         }
570:
571:         public Boolean hasEmptySet(SMultipleBindIR binding) throws AnalysisException
572:         {
573:•                if (binding instanceof ASetMultipleBindIR)
574:                 {
575:                         return isEmptySetSeq(((ASetMultipleBindIR) binding).getSet());
576:•                } else if (binding instanceof ASeqMultipleBindIR)
577:                 {
578:                         return isEmptySetSeq(((ASeqMultipleBindIR) binding).getSeq());
579:                 }
580:
581:                 return false;
582:         }
583:
584:         public Boolean isEmptySetSeq(SExpIR set) throws AnalysisException
585:         {
586:•                if (set.getType() instanceof SSetTypeIR)
587:                 {
588:                         return ((SSetTypeIR) set.getType()).getEmpty();
589:•                } else if (set.getType() instanceof SSeqTypeIR)
590:                 {
591:                         return ((SSeqTypeIR) set.getType()).getEmpty();
592:                 }
593:
594:                 return false;
595:         }
596:
597:         public void cleanUpBinding(SMultipleBindIR binding)
598:         {
599:•                if (binding instanceof ASetMultipleBindIR)
600:                 {
601:                         ASetMultipleBindIR sb = (ASetMultipleBindIR) binding;
602:
603:                         sb.setSet(null);
604:                         sb.getPatterns().clear();
605:•                } else if (binding instanceof ASeqMultipleBindIR)
606:                 {
607:                         ASeqMultipleBindIR sb = (ASeqMultipleBindIR) binding;
608:
609:                         sb.setSeq(null);
610:                         sb.getPatterns().clear();
611:                 } else
612:                 {
613:                         log.error("Expected multiple set bind or multiple sequence bind. Got: "
614:                                         + binding);
615:                 }
616:         }
617:
618:         public AFieldDeclIR consField(String access, STypeIR type, String name,
619:                         SExpIR initExp)
620:         {
621:                 AFieldDeclIR stateField = new AFieldDeclIR();
622:                 stateField.setAccess(access);
623:                 stateField.setType(type);
624:                 stateField.setStatic(true);
625:                 stateField.setFinal(false);
626:                 stateField.setVolatile(false);
627:                 stateField.setName(name);
628:                 stateField.setInitial(initExp);
629:
630:                 return stateField;
631:         }
632:
633:         public AApplyExpIR consConditionalCall(AMethodDeclIR node,
634:                         AMethodDeclIR predMethod)
635:         {
636:                 AIdentifierVarExpIR condVar = new AIdentifierVarExpIR();
637:                 condVar.setType(predMethod.getMethodType().clone());
638:                 condVar.setName(predMethod.getName());
639:                 condVar.setIsLambda(false);
640:                 condVar.setIsLocal(true);
641:
642:                 AApplyExpIR condCall = new AApplyExpIR();
643:                 condCall.setType(new ABoolBasicTypeIR());
644:                 condCall.setRoot(condVar);
645:
646:                 LinkedList<AFormalParamLocalParamIR> params = node.getFormalParams();
647:
648:•                for (AFormalParamLocalParamIR p : params)
649:                 {
650:                         SPatternIR paramPattern = p.getPattern();
651:
652:•                        if (!(paramPattern instanceof AIdentifierPatternIR))
653:                         {
654:                                 log.error("Expected parameter pattern to be an identifier pattern at this point. Got: "
655:                                                 + paramPattern);
656:                                 return null;
657:                         }
658:
659:                         AIdentifierPatternIR paramId = (AIdentifierPatternIR) paramPattern;
660:
661:                         AIdentifierVarExpIR paramArg = new AIdentifierVarExpIR();
662:                         paramArg.setType(p.getType().clone());
663:                         paramArg.setIsLocal(true);
664:                         paramArg.setIsLambda(false);
665:                         paramArg.setName(paramId.getName());
666:
667:                         condCall.getArgs().add(paramArg);
668:                 }
669:
670:•                if (Settings.dialect == Dialect.VDM_SL)
671:                 {
672:                         ADefaultClassDeclIR encClass = node.getAncestor(ADefaultClassDeclIR.class);
673:
674:•                        if (encClass != null)
675:                         {
676:•                                for (AFieldDeclIR f : encClass.getFields())
677:                                 {
678:•                                        if (!f.getFinal())
679:                                         {
680:                                                 // It's the state component
681:                                                 AIdentifierVarExpIR stateArg = info.getExpAssistant().consIdVar(f.getName(), f.getType().clone());
682:                                                 condCall.getArgs().add(stateArg);
683:                                                 break;
684:                                         }
685:                                 }
686:                         } else
687:                         {
688:                                 log.error("Could not find enclosing class of " + node);
689:                         }
690:                 }
691:
692:                 return condCall;
693:         }
694:
695:         public AVarDeclIR consClassVarDeclDefaultCtor(String className,
696:                         String varName)
697:         {
698:                 AClassTypeIR classType = consClassType(className);
699:                 ANewExpIR init = consDefaultConsCall(className);
700:
701:                 AVarDeclIR classDecl = consDecl(varName, classType, init);
702:                 classDecl.setFinal(true);
703:
704:                 return classDecl;
705:         }
706:
707:         public ABlockStmIR wrap(AVarDeclIR decl)
708:         {
709:                 ABlockStmIR block = new ABlockStmIR();
710:                 block.getLocalDefs().add(decl);
711:
712:                 return block;
713:         }
714:
715:         public ARecordTypeIR consRecType(String definingModule, String recName)
716:         {
717:                 ATypeNameIR typeName = new ATypeNameIR();
718:                 typeName.setDefiningClass(definingModule);
719:                 typeName.setName(recName);
720:
721:                 ARecordTypeIR recType = new ARecordTypeIR();
722:                 recType.setName(typeName);
723:
724:                 return recType;
725:         }
726:
727:         public ARecordTypeIR getRecType(final AStateDeclIR stateDecl)
728:         {
729:                 ARecordTypeIR stateType = new ARecordTypeIR();
730:                 stateType.setName(getTypeName(stateDecl));
731:
732:                 return stateType;
733:         }
734:
735:         public ATypeNameIR getTypeName(final AStateDeclIR stateDecl)
736:         {
737:                 ATypeNameIR stateName = new ATypeNameIR();
738:                 stateName.setDefiningClass(getEnclosingModuleName(stateDecl));
739:                 stateName.setName(stateDecl.getName());
740:
741:                 return stateName;
742:         }
743:
744:         public String getEnclosingModuleName(AStateDeclIR stateDecl)
745:         {
746:                 AModuleDeclIR module = stateDecl.getAncestor(AModuleDeclIR.class);
747:
748:•                if (module != null)
749:                 {
750:                         return module.getName();
751:                 } else
752:                 {
753:                         log.error("Could not find enclosing module name of state declaration "
754:                                         + stateDecl.getName());
755:                         return null;
756:                 }
757:         }
758:
759:         public ABlockStmIR wrap(SStmIR stm)
760:         {
761:                 ABlockStmIR block = new ABlockStmIR();
762:                 block.getStatements().add(stm);
763:
764:                 return block;
765:         }
766: }