Package: IsExpTrans

IsExpTrans

nameinstructionbranchcomplexitylinemethod
IsExpTrans(TransAssistantIR, String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
caseAGeneralIsExpIR(AGeneralIsExpIR)
M: 0 C: 198
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 47
100%
M: 0 C: 1
100%

Coverage

1: package org.overture.codegen.trans;
2:
3: import java.util.List;
4:
5: import org.overture.codegen.assistant.ExpAssistantIR;
6: import org.overture.codegen.ir.SExpIR;
7: import org.overture.codegen.ir.SStmIR;
8: import org.overture.codegen.ir.STypeIR;
9: import org.overture.codegen.ir.analysis.AnalysisException;
10: import org.overture.codegen.ir.analysis.DepthFirstAnalysisAdaptor;
11: import org.overture.codegen.ir.declarations.AVarDeclIR;
12: import org.overture.codegen.ir.expressions.AGeneralIsExpIR;
13: import org.overture.codegen.ir.expressions.AOrBoolBinaryExpIR;
14: import org.overture.codegen.ir.expressions.SVarExpBase;
15: import org.overture.codegen.ir.statements.ABlockStmIR;
16: import org.overture.codegen.ir.types.ABoolBasicTypeIR;
17: import org.overture.codegen.ir.types.AUnionTypeIR;
18: import org.overture.codegen.trans.assistants.TransAssistantIR;
19:
20: public class IsExpTrans extends DepthFirstAnalysisAdaptor
21: {
22:         private TransAssistantIR transAssistant;
23:         private String isExpSubjectNamePrefix;
24:
25:         public IsExpTrans(TransAssistantIR transAssistant,
26:                         String isExpSubjectNamePrefix)
27:         {
28:                 this.transAssistant = transAssistant;
29:                 this.isExpSubjectNamePrefix = isExpSubjectNamePrefix;
30:         }
31:
32:         @Override
33:         public void caseAGeneralIsExpIR(AGeneralIsExpIR node)
34:                         throws AnalysisException
35:         {
36:                 STypeIR checkedType = node.getCheckedType();
37:
38:•                if (!(checkedType instanceof AUnionTypeIR))
39:                 {
40:                         node.getExp().apply(this);
41:                         return;
42:                 }
43:
44:                 AUnionTypeIR unionType = (AUnionTypeIR) checkedType;
45:                 List<STypeIR> types = unionType.getTypes();
46:                 types = transAssistant.getInfo().getTypeAssistant().clearObjectTypes(types);
47:
48:                 SExpIR exp = node.getExp();
49:                 STypeIR expType = node.getExp().getType();
50:
51:                 ExpAssistantIR expAssistant = transAssistant.getInfo().getExpAssistant();
52:
53:•                if (types.size() == 1)
54:                 {
55:                         SExpIR isExp = IsExpSimplifyTrans.consIsExp(exp, types.get(0));
56:                         transAssistant.replaceNodeWith(node, isExp);
57:
58:                         isExp.apply(this);
59:
60:                 } else
61:                 {
62:
63:                         ABlockStmIR replacementBlock = new ABlockStmIR();
64:
65:                         SExpIR expVar = null;
66:
67:•                        if (!(exp instanceof SVarExpBase))
68:                         {
69:                                 String varName = transAssistant.getInfo().getTempVarNameGen().nextVarName(isExpSubjectNamePrefix);
70:                                 AVarDeclIR expDecl = transAssistant.consDecl(varName, expType.clone(), exp.clone());
71:                                 replacementBlock.getLocalDefs().add(expDecl);
72:                                 expVar = transAssistant.getInfo().getExpAssistant().consIdVar(varName, expType.clone());
73:                         } else
74:                         {
75:                                 expVar = exp;
76:                         }
77:
78:                         AOrBoolBinaryExpIR topOrExp = new AOrBoolBinaryExpIR();
79:                         topOrExp.setType(new ABoolBasicTypeIR());
80:
81:                         STypeIR firstType = types.get(0);
82:
83:                         SExpIR nextIsExp = IsExpSimplifyTrans.consIsExp(expVar, firstType);
84:                         topOrExp.setLeft(nextIsExp);
85:
86:                         AOrBoolBinaryExpIR nextOrExp = topOrExp;
87:
88:•                        for (int i = 1; i < types.size() - 1; i++)
89:                         {
90:                                 STypeIR currentType = types.get(i);
91:
92:                                 nextIsExp = IsExpSimplifyTrans.consIsExp(expVar, currentType);
93:
94:                                 AOrBoolBinaryExpIR tmp = new AOrBoolBinaryExpIR();
95:                                 tmp.setType(new ABoolBasicTypeIR());
96:                                 tmp.setLeft(nextIsExp);
97:                                 nextOrExp.setRight(tmp);
98:                                 nextOrExp = tmp;
99:                         }
100:
101:                         STypeIR lastType = types.get(types.size() - 1);
102:
103:                         nextIsExp = IsExpSimplifyTrans.consIsExp(expVar, lastType);
104:
105:                         nextOrExp.setRight(nextIsExp);
106:
107:                         SStmIR enclosingStm = transAssistant.getEnclosingStm(node, "general is-expression");
108:                         transAssistant.replaceNodeWith(enclosingStm, replacementBlock);
109:                         transAssistant.replaceNodeWith(node, topOrExp);
110:
111:                         replacementBlock.getStatements().add(enclosingStm);
112:
113:                         topOrExp.apply(this);
114:                 }
115:         }
116: }