Package: CallObjTraceLocalizer

CallObjTraceLocalizer

nameinstructionbranchcomplexitylinemethod
CallObjTraceLocalizer(TransAssistantIR, TraceNames, String)
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%
caseAApplyExpIR(AApplyExpIR)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
caseAFieldExpIR(AFieldExpIR)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAIdentifierVarExpIR(AIdentifierVarExpIR)
M: 39 C: 11
22%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 9 C: 4
31%
M: 0 C: 1
100%
caseANewExpIR(ANewExpIR)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
caseASelfExpIR(ASelfExpIR)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
consObjId()
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
createNewReturnValue(INode)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createNewReturnValue(Object)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 2 C: 6
75%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: package org.overture.codegen.traces;
2:
3: import org.apache.commons.lang.BooleanUtils;
4: import org.apache.log4j.Logger;
5: import org.overture.codegen.ir.INode;
6: import org.overture.codegen.ir.SExpIR;
7: import org.overture.codegen.ir.analysis.AnalysisException;
8: import org.overture.codegen.ir.analysis.AnswerAdaptor;
9: import org.overture.codegen.ir.expressions.AApplyExpIR;
10: import org.overture.codegen.ir.expressions.ACastUnaryExpIR;
11: import org.overture.codegen.ir.expressions.AFieldExpIR;
12: import org.overture.codegen.ir.expressions.AIdentifierVarExpIR;
13: import org.overture.codegen.ir.expressions.ANewExpIR;
14: import org.overture.codegen.ir.expressions.ASelfExpIR;
15: import org.overture.codegen.ir.expressions.SVarExpIR;
16: import org.overture.codegen.ir.types.AObjectTypeIR;
17: import org.overture.codegen.trans.assistants.TransAssistantIR;
18:
19:•public class CallObjTraceLocalizer extends AnswerAdaptor<SExpIR>
20: {
21:         private TransAssistantIR assist;
22:         private TraceNames tracePrefixes;
23:         private String traceEnclosingClass;
24:
25:         private Logger log = Logger.getLogger(this.getClass().getName());
26:
27:         public CallObjTraceLocalizer(TransAssistantIR transAssistant,
28:                         TraceNames tracePrefixes, String traceEnclosingClass)
29:         {
30:                 this.assist = transAssistant;
31:                 this.tracePrefixes = tracePrefixes;
32:                 this.traceEnclosingClass = traceEnclosingClass;
33:         }
34:
35:         @Override
36:         public SExpIR caseAApplyExpIR(AApplyExpIR node) throws AnalysisException
37:         {
38:                 return node.getRoot().apply(this);
39:         }
40:
41:         @Override
42:         public SExpIR caseAFieldExpIR(AFieldExpIR node) throws AnalysisException
43:         {
44:                 return node.getObject().apply(this);
45:         }
46:
47:         @Override
48:         public SExpIR caseAIdentifierVarExpIR(AIdentifierVarExpIR node)
49:                         throws AnalysisException
50:         {
51:•                if (node instanceof SVarExpIR)
52:                 {
53:                         SVarExpIR varExp = (SVarExpIR) node;
54:
55:•                        if (BooleanUtils.isFalse(varExp.getIsLocal()))
56:                         {
57:                                 ACastUnaryExpIR objId = consObjId();
58:
59:                                 AFieldExpIR fieldObj = new AFieldExpIR();
60:                                 fieldObj.setType(node.getType().clone());
61:                                 fieldObj.setMemberName(varExp.getName());
62:                                 fieldObj.setObject(objId);
63:
64:                                 assist.replaceNodeWith(node, fieldObj);
65:
66:                                 return objId;
67:                         }
68:
69:                         return node;
70:                 }
71:
72:                 log.error("Expected variable expression at this point. Got: " + node);
73:
74:                 return null;
75:         }
76:
77:         @Override
78:         public SExpIR caseASelfExpIR(ASelfExpIR node) throws AnalysisException
79:         {
80:                 ACastUnaryExpIR objId = consObjId();
81:                 assist.replaceNodeWith(node, objId);
82:
83:                 return objId;
84:         }
85:
86:         @Override
87:         public SExpIR caseANewExpIR(ANewExpIR node) throws AnalysisException
88:         {
89:                 return node;
90:         }
91:
92:         private ACastUnaryExpIR consObjId()
93:         {
94:                 String paramName = tracePrefixes.callStmMethodParamName();
95:
96:                 AIdentifierVarExpIR idVar = assist.getInfo().getExpAssistant().consIdVar(paramName, new AObjectTypeIR());
97:
98:                 ACastUnaryExpIR castVar = new ACastUnaryExpIR();
99:
100:                 castVar.setType(assist.consClassType(traceEnclosingClass));
101:                 castVar.setExp(idVar);
102:
103:                 return castVar;
104:         }
105:
106:         @Override
107:         public SExpIR createNewReturnValue(INode node) throws AnalysisException
108:         {
109:•                assert false : "Should not happen";
110:                 return null;
111:         }
112:
113:         @Override
114:         public SExpIR createNewReturnValue(Object node) throws AnalysisException
115:         {
116:•                assert false : "Should not happen";
117:                 return null;
118:         }
119:
120: }