Package: JavaLanguageIterator

JavaLanguageIterator

nameinstructionbranchcomplexitylinemethod
JavaLanguageIterator(TransAssistantIR, IterationVarPrefixes)
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%
consNextElementCall(AIdentifierVarExpIR)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getForLoopCond(AIdentifierVarExpIR, List, SPatternIR)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getForLoopInc(AIdentifierVarExpIR, List, SPatternIR)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getForLoopInit(AIdentifierVarExpIR, List, SPatternIR)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getNextElementAssigned(AIdentifierVarExpIR, List, SPatternIR, AVarDeclIR, AVarDeclIR)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getNextElementDeclared(AIdentifierVarExpIR, List, SPatternIR)
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getPreForLoopStms(AIdentifierVarExpIR, List, SPatternIR)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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.trans.iterator;
23:
24: import java.util.List;
25:
26: import org.overture.codegen.ir.SExpIR;
27: import org.overture.codegen.ir.SPatternIR;
28: import org.overture.codegen.ir.SStmIR;
29: import org.overture.codegen.ir.STypeIR;
30: import org.overture.codegen.ir.analysis.AnalysisException;
31: import org.overture.codegen.ir.declarations.AVarDeclIR;
32: import org.overture.codegen.ir.expressions.AIdentifierVarExpIR;
33: import org.overture.codegen.ir.statements.ALocalPatternAssignmentStmIR;
34: import org.overture.codegen.ir.types.ABoolBasicTypeIR;
35: import org.overture.codegen.ir.types.AClassTypeIR;
36: import org.overture.codegen.trans.IterationVarPrefixes;
37: import org.overture.codegen.trans.assistants.TransAssistantIR;
38:
39: public class JavaLanguageIterator extends AbstractLanguageIterator
40: {
41:         private static final String GET_ITERATOR = "iterator";
42:         private static final String NEXT_ELEMENT_ITERATOR = "next";
43:         private static final String HAS_NEXT_ELEMENT_ITERATOR = "hasNext";
44:         private static final String ITERATOR_TYPE = "Iterator";
45:
46:         public JavaLanguageIterator(TransAssistantIR transformationAssistant,
47:                         IterationVarPrefixes iteVarPrefixes)
48:         {
49:                 super(transformationAssistant, iteVarPrefixes);
50:         }
51:
52:         protected String iteratorName;
53:
54:         @Override
55:         public List<SStmIR> getPreForLoopStms(AIdentifierVarExpIR setVar,
56:                         List<SPatternIR> patterns, SPatternIR pattern)
57:         {
58:                 // Generate nothing
59:                 return null;
60:         }
61:
62:         @Override
63:         public AVarDeclIR getForLoopInit(AIdentifierVarExpIR setVar,
64:                         List<SPatternIR> patterns, SPatternIR pattern)
65:         {
66:                 iteratorName = transAssistant.getInfo().getTempVarNameGen().nextVarName(iteVarPrefixes.iterator());
67:                 String setName = setVar.getName();
68:                 AClassTypeIR iteratorType = transAssistant.consClassType(ITERATOR_TYPE);
69:                 STypeIR setType = setVar.getType().clone();
70:                 SExpIR getIteratorCall = transAssistant.consInstanceCall(setType, setName, iteratorType.clone(), GET_ITERATOR);
71:
72:                 return transAssistant.getInfo().getDeclAssistant().consLocalVarDecl(iteratorType, transAssistant.getInfo().getPatternAssistant().consIdPattern(iteratorName), getIteratorCall);
73:         }
74:
75:         @Override
76:         public SExpIR getForLoopCond(AIdentifierVarExpIR setVar,
77:                         List<SPatternIR> patterns, SPatternIR pattern)
78:                         throws AnalysisException
79:         {
80:                 AClassTypeIR iteratorType = transAssistant.consClassType(ITERATOR_TYPE);
81:
82:                 return transAssistant.consInstanceCall(iteratorType, iteratorName, new ABoolBasicTypeIR(), HAS_NEXT_ELEMENT_ITERATOR);
83:         }
84:
85:         @Override
86:         public SExpIR getForLoopInc(AIdentifierVarExpIR setVar,
87:                         List<SPatternIR> patterns, SPatternIR pattern)
88:         {
89:                 return null;
90:         }
91:
92:         @Override
93:         public AVarDeclIR getNextElementDeclared(AIdentifierVarExpIR setVar,
94:                         List<SPatternIR> patterns, SPatternIR pattern)
95:                         throws AnalysisException
96:         {
97:                 STypeIR elementType = transAssistant.getElementType(setVar.getType());
98:
99:                 return transAssistant.consNextElementDeclared(transAssistant.consClassType(ITERATOR_TYPE), elementType, pattern, iteratorName, NEXT_ELEMENT_ITERATOR);
100:         }
101:
102:         @Override
103:         public ALocalPatternAssignmentStmIR getNextElementAssigned(
104:                         AIdentifierVarExpIR setVar, List<SPatternIR> patterns,
105:                         SPatternIR pattern, AVarDeclIR successVarDecl,
106:                         AVarDeclIR nextElementDecl) throws AnalysisException
107:         {
108:                 STypeIR elementType = transAssistant.getElementType(setVar.getType());
109:
110:                 return transAssistant.consNextElementAssignment(transAssistant.consClassType(ITERATOR_TYPE), elementType, pattern, iteratorName, NEXT_ELEMENT_ITERATOR, nextElementDecl);
111:         }
112:
113:         @Override
114:         public SExpIR consNextElementCall(AIdentifierVarExpIR setVar)
115:                         throws AnalysisException
116:         {
117:                 STypeIR elementType = transAssistant.getSetTypeCloned(setVar).getSetOf();
118:
119:                 return transAssistant.consNextElementCall(transAssistant.consClassType(ITERATOR_TYPE), iteratorName, elementType, NEXT_ELEMENT_ITERATOR);
120:         }
121: }