Package: TraceLetBeStStrategy

TraceLetBeStStrategy

nameinstructionbranchcomplexitylinemethod
TraceLetBeStStrategy(TransAssistantIR, SExpIR, SSetTypeIR, ILanguageIterator, ITempVarGen, IterationVarPrefixes, StoreAssistant, Map, TraceNames, AIdentifierPatternIR, AVarDeclIR, TraceNodeData, TraceStmBuilder)
M: 0 C: 36
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
consDeclarationTag()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getForLoopCond(AIdentifierVarExpIR, List, SPatternIR)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getForLoopStms(AIdentifierVarExpIR, List, SPatternIR)
M: 27 C: 191
88%
M: 1 C: 9
90%
M: 1 C: 5
83%
M: 5 C: 31
86%
M: 0 C: 1
100%
getNextElementAssigned(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%
getNextElementDeclared(AIdentifierVarExpIR, List, SPatternIR)
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getOuterBlockDecls(AIdentifierVarExpIR, List)
M: 0 C: 46
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
getPostOuterBlockStms(AIdentifierVarExpIR, List)
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%
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: package org.overture.codegen.traces;
2:
3: import java.util.LinkedList;
4: import java.util.List;
5: import java.util.Map;
6:
7: import org.apache.log4j.Logger;
8: import org.overture.ast.lex.Dialect;
9: import org.overture.codegen.ir.ITempVarGen;
10: import org.overture.codegen.ir.SExpIR;
11: import org.overture.codegen.ir.SPatternIR;
12: import org.overture.codegen.ir.SStmIR;
13: import org.overture.codegen.ir.STypeIR;
14: import org.overture.codegen.ir.analysis.AnalysisException;
15: import org.overture.codegen.ir.declarations.AVarDeclIR;
16: import org.overture.codegen.ir.expressions.AIdentifierVarExpIR;
17: import org.overture.codegen.ir.patterns.AIdentifierPatternIR;
18: import org.overture.codegen.ir.statements.ABlockStmIR;
19: import org.overture.codegen.ir.statements.ACallObjectExpStmIR;
20: import org.overture.codegen.ir.statements.AContinueStmIR;
21: import org.overture.codegen.ir.statements.AIfStmIR;
22: import org.overture.codegen.ir.statements.ALocalPatternAssignmentStmIR;
23: import org.overture.codegen.ir.types.ASetSetTypeIR;
24: import org.overture.codegen.ir.types.SSetTypeIR;
25: import org.overture.codegen.trans.DeclarationTag;
26: import org.overture.codegen.trans.IterationVarPrefixes;
27: import org.overture.codegen.trans.assistants.TransAssistantIR;
28: import org.overture.codegen.trans.iterator.ILanguageIterator;
29: import org.overture.codegen.trans.let.LetBeStStrategy;
30: import org.overture.config.Settings;
31:
32: public class TraceLetBeStStrategy extends LetBeStStrategy
33: {
34:         protected TraceNodeData nodeData;
35:         protected AVarDeclIR altTests;
36:         protected AIdentifierPatternIR id;
37:         protected TraceNames tracePrefixes;
38:         protected StoreAssistant storeAssistant;
39:         protected Map<String, String> idConstNameMap;
40:         protected TraceStmBuilder builder;
41:
42:         private Logger log = Logger.getLogger(this.getClass().getSimpleName());
43:
44:         public TraceLetBeStStrategy(TransAssistantIR transAssistant,
45:                         SExpIR suchThat, SSetTypeIR setType, ILanguageIterator langIterator,
46:                         ITempVarGen tempGen, IterationVarPrefixes iteVarPrefixes,
47:                         StoreAssistant storeAssistant, Map<String, String> idConstNameMap,
48:                         TraceNames tracePrefixes, AIdentifierPatternIR id,
49:                         AVarDeclIR altTests, TraceNodeData nodeData,
50:                         TraceStmBuilder builder)
51:         {
52:                 super(transAssistant, suchThat, setType, langIterator, tempGen, iteVarPrefixes);
53:
54:                 this.storeAssistant = storeAssistant;
55:                 this.idConstNameMap = idConstNameMap;
56:                 this.tracePrefixes = tracePrefixes;
57:                 this.id = id;
58:                 this.altTests = altTests;
59:                 this.nodeData = nodeData;
60:                 this.builder = builder;
61:         }
62:
63:         @Override
64:         public List<AVarDeclIR> getOuterBlockDecls(AIdentifierVarExpIR setVar,
65:                         List<SPatternIR> patterns) throws AnalysisException
66:         {
67:                 STypeIR elementType = transAssist.getElementType(setSeqType);
68:
69:•                for (SPatternIR id : patterns)
70:                 {
71:                         AVarDeclIR decl = transAssist.getInfo().getDeclAssistant().consLocalVarDecl(elementType.clone(), id.clone(), transAssist.getInfo().getExpAssistant().consUndefinedExp());
72:                         decl.setFinal(true);
73:                         decls.add(decl);
74:                 }
75:
76:                 return packDecl(altTests);
77:         }
78:
79:         @Override
80:         public List<SStmIR> getPreForLoopStms(AIdentifierVarExpIR setVar,
81:                         List<SPatternIR> patterns, SPatternIR pattern)
82:         {
83:                 return null;
84:         }
85:
86:         @Override
87:         public SExpIR getForLoopCond(AIdentifierVarExpIR setVar,
88:                         List<SPatternIR> patterns, SPatternIR pattern)
89:                         throws AnalysisException
90:         {
91:                 return langIterator.getForLoopCond(setVar, patterns, pattern);
92:         }
93:
94:         @Override
95:         public DeclarationTag consDeclarationTag()
96:         {
97:                 return new DeclarationTag(false, successVarDecl);
98:         }
99:
100:         @Override
101:         public AVarDeclIR getNextElementDeclared(AIdentifierVarExpIR setVar,
102:                         List<SPatternIR> patterns, SPatternIR pattern)
103:                         throws AnalysisException
104:         {
105:                 AVarDeclIR nextElementDecl = decls.get(count++);
106:                 tagNextElementDeclared(nextElementDecl);
107:
108:                 nextElementDecl.setExp(langIterator.consNextElementCall(setVar));
109:
110:                 return nextElementDecl;
111:         }
112:
113:         @Override
114:         public ALocalPatternAssignmentStmIR getNextElementAssigned(
115:                         AIdentifierVarExpIR setVar, List<SPatternIR> patterns,
116:                         SPatternIR pattern) throws AnalysisException
117:         {
118:                 return null;
119:         }
120:
121:         @Override
122:         public List<SStmIR> getForLoopStms(AIdentifierVarExpIR setVar,
123:                         List<SPatternIR> patterns, SPatternIR pattern)
124:         {
125:                 ABlockStmIR block = new ABlockStmIR();
126:
127:•                if (suchThat != null)
128:                 {
129:                         AIfStmIR ifStm = new AIfStmIR();
130:                         ifStm.setIfExp(transAssist.getInfo().getExpAssistant().negate(suchThat.clone()));
131:                         ifStm.setThenStm(new AContinueStmIR());
132:                         block.getStatements().add(ifStm);
133:                 }
134:
135:                 AVarDeclIR nextElementDecl = decls.get(count - 1);
136:
137:                 IdentifierPatternCollector idCollector = new IdentifierPatternCollector();
138:                 idCollector.setTopNode(nextElementDecl);
139:
140:                 PatternTypeFinder typeFinder = new PatternTypeFinder(transAssist.getInfo());
141:
142:•                if (setVar.getType() instanceof ASetSetTypeIR)
143:                 {
144:                         STypeIR elemType = ((ASetSetTypeIR) setVar.getType()).getSetOf();
145:
146:                         try
147:                         {
148:                                 nextElementDecl.getPattern().apply(typeFinder, elemType);
149:                         } catch (AnalysisException e)
150:                         {
151:                                 log.error("Unexpectected problem occurred when trying to determine the type of pattern "
152:                                                 + nextElementDecl.getPattern());
153:                                 e.printStackTrace();
154:                         }
155:                 } else
156:                 {
157:                         log.error("Expected set type. Got: " + setVar.getType());
158:                 }
159:
160:                 List<AIdentifierVarExpIR> traceVars = new LinkedList<>();
161:
162:•                for (AIdentifierPatternIR idToReg : idCollector.findOccurences())
163:                 {
164:•                        if (Settings.dialect != Dialect.VDM_SL)
165:                         {
166:                                 String idConstName = idConstNameMap.get(idToReg.getName());
167:                                 block.getStatements().add(transAssist.wrap(storeAssistant.consIdConstDecl(idConstName)));
168:                                 storeAssistant.appendStoreRegStms(block, idToReg.getName(), idConstName, false);
169:                         }
170:
171:                         traceVars.add(this.transAssist.getInfo().getExpAssistant().consIdVar(idToReg.getName(), PatternTypeFinder.getType(typeFinder, idToReg)));
172:                 }
173:
174:                 block.getStatements().add(nodeData.getStms());
175:
176:                 STypeIR instanceType = altTests.getType().clone();
177:                 AIdentifierVarExpIR subject = nodeData.getNodeVar();
178:
179:•                for (int i = traceVars.size() - 1; i >= 0; i--)
180:                 {
181:                         block.getStatements().add(builder.consAddTraceVarCall(subject, traceVars.get(i)));
182:                 }
183:
184:                 // E.g. alternatives_2.add(apply_1)
185:                 ACallObjectExpStmIR addCall = transAssist.consInstanceCallStm(instanceType, id.getName(), tracePrefixes.addMethodName(), subject);
186:                 block.getStatements().add(addCall);
187:
188:                 return packStm(block);
189:         }
190:
191:         @Override
192:         public List<SStmIR> getPostOuterBlockStms(AIdentifierVarExpIR setVar,
193:                         List<SPatternIR> patterns)
194:         {
195:                 return null;
196:         }
197: }