Package: IsExpSimplifyTrans

IsExpSimplifyTrans

nameinstructionbranchcomplexitylinemethod
IsExpSimplifyTrans(TransAssistantIR)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseAGeneralIsExpIR(AGeneralIsExpIR)
M: 17 C: 17
50%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 3 C: 5
63%
M: 0 C: 1
100%
consGeneralIsExp(SExpIR, STypeIR)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
consIsExp(SExpIR, STypeIR)
M: 5 C: 132
96%
M: 5 C: 27
84%
M: 5 C: 12
71%
M: 3 C: 36
92%
M: 0 C: 1
100%
consIsExpBasicType(SExpIR, STypeIR)
M: 7 C: 71
91%
M: 2 C: 14
88%
M: 2 C: 7
78%
M: 2 C: 19
90%
M: 0 C: 1
100%
consIsExpQuoteType(SExpIR, AQuoteTypeIR)
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
consTupleIsExp(SExpIR, STypeIR)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: package org.overture.codegen.trans;
2:
3:
4: import org.overture.codegen.ir.SExpIR;
5: import org.overture.codegen.ir.STypeIR;
6: import org.overture.codegen.ir.analysis.AnalysisException;
7: import org.overture.codegen.ir.analysis.DepthFirstAnalysisAdaptor;
8: import org.overture.codegen.ir.expressions.*;
9: import org.overture.codegen.ir.types.*;
10: import org.overture.codegen.trans.assistants.TransAssistantIR;
11:
12: public class IsExpSimplifyTrans extends DepthFirstAnalysisAdaptor {
13:
14: private TransAssistantIR assist;
15:
16: public IsExpSimplifyTrans(TransAssistantIR assist)
17: {
18: this.assist = assist;
19: }
20:
21: @Override
22: public void caseAGeneralIsExpIR(AGeneralIsExpIR node) throws AnalysisException {
23:
24: super.caseAGeneralIsExpIR(node);
25:
26: SExpIR isExp = consIsExp(node.getExp(), node.getCheckedType());
27:
28:• if (isExp == null) {
29: assist.getInfo().addTransformationWarning(node, "The 'is' expression is not supported for type: "
30: + node.getCheckedType().getClass().getName());
31: return;
32: }
33: else
34: {
35: assist.replaceNodeWith(node, isExp);
36: }
37: }
38:
39: public static SExpIR consIsExp(SExpIR exp, STypeIR checkedType)
40: {
41: exp = exp.clone();
42: checkedType = checkedType.clone();
43:
44:• if (checkedType instanceof AUnionTypeIR)
45: {
46: return consGeneralIsExp(exp, checkedType);
47:• } else if (checkedType instanceof SBasicTypeIR)
48: {
49: return consIsExpBasicType(exp, checkedType);
50:• } else if (checkedType instanceof AQuoteTypeIR)
51: {
52: return consIsExpQuoteType(exp, (AQuoteTypeIR) checkedType);
53:• } else if (checkedType instanceof ATupleTypeIR)
54: {
55: return consTupleIsExp(exp, checkedType);
56:• } else if (checkedType instanceof ARecordTypeIR
57: || checkedType instanceof AClassTypeIR
58: || checkedType instanceof AStringTypeIR)
59: {
60: return consGeneralIsExp(exp, checkedType);
61:• } else if(checkedType instanceof AUnknownTypeIR)
62: {
63: ABoolLiteralExpIR boolLiteral = new ABoolLiteralExpIR();
64: boolLiteral.setType(new ABoolBasicTypeIR());
65: boolLiteral.setValue(true);
66:
67: return boolLiteral;
68:
69: } else
70: {
71:• if (checkedType instanceof ASeqSeqTypeIR)
72: {
73: ASeqSeqTypeIR seqType = (ASeqSeqTypeIR) checkedType;
74:
75:• if (seqType.getSeqOf() instanceof AUnknownTypeIR)
76: {
77: return consGeneralIsExp(exp, checkedType);
78: }
79:• } else if (checkedType instanceof AMapMapTypeIR)
80: {
81: AMapMapTypeIR mapType = (AMapMapTypeIR) checkedType;
82:
83:• if (mapType.getFrom() instanceof AUnknownTypeIR
84:• && mapType.getTo() instanceof AUnknownTypeIR)
85: {
86: return consGeneralIsExp(exp, checkedType);
87: }
88: }
89:• else if(checkedType instanceof ASetSetTypeIR)
90: {
91: ASetSetTypeIR setType = (ASetSetTypeIR) checkedType;
92:
93:• if(setType.getSetOf() instanceof AUnknownTypeIR)
94: {
95: return consGeneralIsExp(exp, checkedType);
96: }
97: }
98:• else if(checkedType instanceof ATemplateTypeIR)
99: {
100: ATemplateTypeIR templateType = (ATemplateTypeIR) checkedType;
101:
102: String argName = PolyFuncTrans.toTypeArgName(templateType);
103:
104: AExternalTypeIR typeVar = new AExternalTypeIR();
105: typeVar.setName(argName);
106:
107: return consGeneralIsExp(exp, typeVar);
108: }
109:
110: return null;
111: }
112: }
113:
114: public static SExpIR consIsExpQuoteType(SExpIR exp, AQuoteTypeIR quoteType)
115: {
116: AQuoteLiteralExpIR lit = new AQuoteLiteralExpIR();
117: lit.setType(quoteType);
118: lit.setValue(quoteType.getValue());
119:
120: AEqualsBinaryExpIR equals = new AEqualsBinaryExpIR();
121: equals.setType(new ABoolBasicTypeIR());
122: equals.setLeft(exp);
123: equals.setRight(lit);
124:
125: return equals;
126: }
127:
128: public static SExpIR consGeneralIsExp(SExpIR expCg, STypeIR checkedTypeCg)
129: {
130: AGeneralIsExpIR generalIsExp = new AGeneralIsExpIR();
131: generalIsExp = new AGeneralIsExpIR();
132: generalIsExp.setType(new ABoolBasicTypeIR());
133: generalIsExp.setExp(expCg);
134: generalIsExp.setCheckedType(checkedTypeCg);
135:
136: return generalIsExp;
137: }
138:
139: public static ATupleIsExpIR consTupleIsExp(SExpIR exp, STypeIR checkedType)
140: {
141: ATupleIsExpIR tupleIsExp = new ATupleIsExpIR();
142: tupleIsExp.setType(new ABoolBasicTypeIR());
143: tupleIsExp.setExp(exp);
144: tupleIsExp.setCheckedType(checkedType);
145:
146: return tupleIsExp;
147: }
148:
149: public static SExpIR consIsExpBasicType(SExpIR expCg, STypeIR checkedType)
150: {
151: SIsExpIR basicIsExp = null;
152:
153:• if (checkedType instanceof ABoolBasicTypeIR)
154: {
155: basicIsExp = new ABoolIsExpIR();
156:• } else if (checkedType instanceof ANatNumericBasicTypeIR)
157: {
158: basicIsExp = new ANatIsExpIR();
159:• } else if (checkedType instanceof ANat1NumericBasicTypeIR)
160: {
161: basicIsExp = new ANat1IsExpIR();
162:• } else if (checkedType instanceof AIntNumericBasicTypeIR)
163: {
164: basicIsExp = new AIntIsExpIR();
165:• } else if (checkedType instanceof ARatNumericBasicTypeIR)
166: {
167: basicIsExp = new ARatIsExpIR();
168:• } else if (checkedType instanceof ARealNumericBasicTypeIR)
169: {
170: basicIsExp = new ARealIsExpIR();
171:• } else if (checkedType instanceof ACharBasicTypeIR)
172: {
173: basicIsExp = new ACharIsExpIR();
174:• } else if (checkedType instanceof ATokenBasicTypeIR)
175: {
176: basicIsExp = new ATokenIsExpIR();
177: } else
178: {
179: return null;
180: }
181:
182: basicIsExp.setType(new ABoolBasicTypeIR());
183: basicIsExp.setExp(expCg);
184:
185: return basicIsExp;
186: }
187: }