Package: CompStrategy

CompStrategy

nameinstructionbranchcomplexitylinemethod
CompStrategy(TransAssistantIR, SExpIR, String, STypeIR, ILanguageIterator, ITempVarGen, IterationVarPrefixes)
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
consConditionalAdd(AIdentifierVarExpIR, SStmIR)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getOuterBlockDecls(AIdentifierVarExpIR, List)
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
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.comp;
23:
24: import java.util.List;
25:
26: import org.overture.codegen.ir.ITempVarGen;
27: import org.overture.codegen.ir.SExpIR;
28: import org.overture.codegen.ir.SPatternIR;
29: import org.overture.codegen.ir.SStmIR;
30: import org.overture.codegen.ir.STypeIR;
31: import org.overture.codegen.ir.analysis.AnalysisException;
32: import org.overture.codegen.ir.declarations.AVarDeclIR;
33: import org.overture.codegen.ir.expressions.AIdentifierVarExpIR;
34: import org.overture.codegen.ir.patterns.AIdentifierPatternIR;
35: import org.overture.codegen.ir.statements.AIfStmIR;
36: import org.overture.codegen.trans.AbstractIterationStrategy;
37: import org.overture.codegen.trans.IterationVarPrefixes;
38: import org.overture.codegen.trans.assistants.TransAssistantIR;
39: import org.overture.codegen.trans.iterator.ILanguageIterator;
40:
41: public abstract class CompStrategy extends AbstractIterationStrategy
42: {
43:         protected SExpIR predicate;
44:         protected AIdentifierPatternIR idPattern;
45:         protected STypeIR compType;
46:
47:         public CompStrategy(TransAssistantIR transformationAssistant,
48:                         SExpIR predicate, String varName, STypeIR compType,
49:                         ILanguageIterator langIterator, ITempVarGen tempGen,
50:                         IterationVarPrefixes iteVarPrefixes)
51:         {
52:                 super(transformationAssistant, langIterator, tempGen, iteVarPrefixes);
53:
54:                 this.predicate = predicate;
55:
56:                 AIdentifierPatternIR idPattern = new AIdentifierPatternIR();
57:                 idPattern.setName(varName);
58:
59:                 this.idPattern = idPattern;
60:                 this.compType = compType;
61:         }
62:
63:         protected abstract SExpIR getEmptyCollection();
64:
65:         protected abstract List<SStmIR> getConditionalAdd(
66:                         AIdentifierVarExpIR setVar, List<SPatternIR> patterns,
67:                         SPatternIR pattern);
68:
69:         protected List<SStmIR> consConditionalAdd(AIdentifierVarExpIR compResult,
70:                         SStmIR collectionAdd)
71:         {
72:•                if (predicate != null)
73:                 {
74:                         AIfStmIR condCollectionUnion = new AIfStmIR();
75:                         condCollectionUnion.setIfExp(predicate.clone());
76:                         condCollectionUnion.setThenStm(collectionAdd);
77:
78:                         return packStm(condCollectionUnion);
79:                 } else
80:                 {
81:                         return packStm(collectionAdd);
82:                 }
83:         }
84:
85:         @Override
86:         public List<AVarDeclIR> getOuterBlockDecls(AIdentifierVarExpIR setVar,
87:                         List<SPatternIR> patterns) throws AnalysisException
88:         {
89:                 SExpIR emptyCollection = getEmptyCollection();
90:                 emptyCollection.setType(compType.clone());
91:                 AVarDeclIR compResultInit = transAssist.getInfo().getDeclAssistant().consLocalVarDecl(compType.clone(), idPattern.clone(), emptyCollection);
92:
93:                 return packDecl(compResultInit);
94:         }
95: }