Package: LetBeStTrans

LetBeStTrans

nameinstructionbranchcomplexitylinemethod
LetBeStTrans(TransAssistantIR, ILanguageIterator, IterationVarPrefixes)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
caseALetBeStStmIR(ALetBeStStmIR)
M: 39 C: 113
74%
M: 2 C: 8
80%
M: 2 C: 4
67%
M: 6 C: 23
79%
M: 0 C: 1
100%
getCol(SMultipleBindIR)
M: 13 C: 14
52%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 2 C: 4
67%
M: 0 C: 1
100%

Coverage

1: package org.overture.codegen.trans;
2:
3: import java.util.LinkedList;
4:
5: import org.apache.log4j.Logger;
6: import org.overture.codegen.ir.ITempVarGen;
7: import org.overture.codegen.ir.SExpIR;
8: import org.overture.codegen.ir.SMultipleBindIR;
9: import org.overture.codegen.ir.SPatternIR;
10: import org.overture.codegen.ir.STypeIR;
11: import org.overture.codegen.ir.analysis.AnalysisException;
12: import org.overture.codegen.ir.analysis.DepthFirstAnalysisAdaptor;
13: import org.overture.codegen.ir.patterns.ASeqMultipleBindIR;
14: import org.overture.codegen.ir.patterns.ASetMultipleBindIR;
15: import org.overture.codegen.ir.statements.ABlockStmIR;
16: import org.overture.codegen.ir.statements.ALetBeStStmIR;
17: import org.overture.codegen.ir.types.AUnknownTypeIR;
18: import org.overture.codegen.ir.utils.AHeaderLetBeStIR;
19: import org.overture.codegen.trans.assistants.TransAssistantIR;
20: import org.overture.codegen.trans.iterator.ILanguageIterator;
21: import org.overture.codegen.trans.let.LetBeStStrategy;
22:
23: public class LetBeStTrans extends DepthFirstAnalysisAdaptor
24: {
25:         private TransAssistantIR transAssistant;
26:         private ILanguageIterator langIterator;
27:         private IterationVarPrefixes iteVarPrefixes;
28:
29:         private Logger log = Logger.getLogger(this.getClass().getName());
30:
31:         public LetBeStTrans(TransAssistantIR transAssistant,
32:                         ILanguageIterator langIterator, IterationVarPrefixes iteVarPrefixes)
33:         {
34:                 this.transAssistant = transAssistant;
35:                 this.langIterator = langIterator;
36:                 this.iteVarPrefixes = iteVarPrefixes;
37:         }
38:
39:         @Override
40:         public void caseALetBeStStmIR(ALetBeStStmIR node) throws AnalysisException
41:         {
42:                 AHeaderLetBeStIR header = node.getHeader();
43:
44:•                if (!(header.getBinding() instanceof ASetMultipleBindIR
45:•                                || header.getBinding() instanceof ASeqMultipleBindIR))
46:                 {
47:                         transAssistant.getInfo().addTransformationWarning(node.getHeader().getBinding(), "This transformation only works for 'let be st' "
48:                                         + "statements with with multiple set binds and not multiple type binds in '"
49:                                         + this.getClass().getSimpleName() + "'");
50:                         return;
51:                 }
52:
53:                 SExpIR suchThat = header.getSuchThat();
54:                 SMultipleBindIR binding = node.getHeader().getBinding();
55:
56:                 STypeIR setSeqType;
57:•                if (binding instanceof ASetMultipleBindIR)
58:                 {
59:                         ASetMultipleBindIR sb = (ASetMultipleBindIR) binding;
60:                         setSeqType = sb.getSet().getType().clone();
61:•                } else if (binding instanceof ASeqMultipleBindIR)
62:                 {
63:                         ASeqMultipleBindIR sb = (ASeqMultipleBindIR) binding;
64:                         setSeqType = sb.getSeq().getType().clone();
65:                 } else
66:                 {
67:                         log.error("Expected multiple set bind or multiple sequence bind. Got: "
68:                                         + binding);
69:                         setSeqType = new AUnknownTypeIR();
70:
71:                         // The closest we get
72:                         setSeqType.setSourceNode(binding.getSourceNode());
73:                 }
74:
75:                 ITempVarGen tempVarNameGen = transAssistant.getInfo().getTempVarNameGen();
76:
77:                 LetBeStStrategy strategy = new LetBeStStrategy(transAssistant, suchThat, setSeqType.clone(), langIterator, tempVarNameGen, iteVarPrefixes);
78:
79:•                if (transAssistant.hasEmptySet(binding))
80:                 {
81:                         transAssistant.cleanUpBinding(binding);
82:                         node.setStatement(new ABlockStmIR());
83:                 }
84:
85:                 LinkedList<SPatternIR> patterns = binding.getPatterns();
86:                 ABlockStmIR outerBlock = transAssistant.consIterationBlock(patterns, getCol(binding), tempVarNameGen, strategy, iteVarPrefixes);
87:
88:                 // Only the statement of the let be st statement is added to the outer block statements.
89:                 // We obtain the equivalent functionality of the remaining part of the let be st statement
90:                 // from the transformation in the outer block
91:                 outerBlock.getStatements().add(node.getStatement());
92:
93:                 // Replace the let be st statement with the transformation
94:                 transAssistant.replaceNodeWithRecursively(node, outerBlock, this);
95:
96:                 outerBlock.setScoped(transAssistant.getInfo().getStmAssistant().isScoped(outerBlock));
97:         }
98:
99:         private SExpIR getCol(SMultipleBindIR binding)
100:         {
101:•                if (binding instanceof ASetMultipleBindIR)
102:                 {
103:                         return ((ASetMultipleBindIR) binding).getSet();
104:•                } else if (binding instanceof ASeqMultipleBindIR)
105:                 {
106:                         return ((ASeqMultipleBindIR) binding).getSeq();
107:                 } else
108:                 {
109:                         log.error("Expected multiple set bind or multiple sequence bind. Got: "
110:                                         + binding);
111:                         return null;
112:                 }
113:         }
114: }