Package: StoreAssistant

StoreAssistant

nameinstructionbranchcomplexitylinemethod
StoreAssistant(TraceNames, TransAssistantIR)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
appendStoreRegStms(ABlockStmIR, String, String, boolean)
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
consIdConstDecl(String)
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
consStoreLookup(AIdentifierVarExpIR)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
consStoreLookup(AIdentifierVarExpIR, boolean)
M: 0 C: 71
100%
M: 3 C: 5
63%
M: 3 C: 2
40%
M: 0 C: 11
100%
M: 0 C: 1
100%
consStoreRegistration(String, SExpIR, boolean)
M: 0 C: 48
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
consStoreRegistration(String, STypeIR, String, boolean)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getIdConstNameMap()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: package org.overture.codegen.traces;
2:
3: import java.util.HashMap;
4: import java.util.Map;
5:
6: import org.overture.codegen.ir.SExpIR;
7: import org.overture.codegen.ir.STypeIR;
8: import org.overture.codegen.ir.declarations.AVarDeclIR;
9: import org.overture.codegen.ir.expressions.ACastUnaryExpIR;
10: import org.overture.codegen.ir.expressions.AIdentifierVarExpIR;
11: import org.overture.codegen.ir.statements.ABlockStmIR;
12: import org.overture.codegen.ir.statements.ACallObjectExpStmIR;
13: import org.overture.codegen.ir.types.AClassTypeIR;
14: import org.overture.codegen.ir.types.ANatNumericBasicTypeIR;
15: import org.overture.codegen.ir.types.AObjectTypeIR;
16: import org.overture.codegen.ir.types.AUnionTypeIR;
17: import org.overture.codegen.ir.types.AUnknownTypeIR;
18: import org.overture.codegen.trans.assistants.TransAssistantIR;
19:
20: public class StoreAssistant
21: {
22:         private TraceNames tracePrefixes;
23:         private Map<String, String> idConstNameMap;
24:         private TransAssistantIR transAssistant;
25:
26:         public StoreAssistant(TraceNames tracePrefixes,
27:                         TransAssistantIR transAssistant)
28:         {
29:                 super();
30:                 this.tracePrefixes = tracePrefixes;
31:                 this.idConstNameMap = new HashMap<String, String>();
32:                 this.transAssistant = transAssistant;
33:         }
34:
35:         public Map<String, String> getIdConstNameMap()
36:         {
37:                 return idConstNameMap;
38:         }
39:
40:         public void appendStoreRegStms(ABlockStmIR declBlock, String varName,
41:                         String idConstName, boolean staticReg)
42:         {
43:                 // Passing the variable type as the unknown type is not very accurate.
44:                 // However, it simplifies the store registration.
45:                 declBlock.getStatements().add(consStoreRegistration(idConstName, new AUnknownTypeIR(), varName, staticReg));
46:                 idConstNameMap.put(varName, idConstName);
47:         }
48:
49:         public AVarDeclIR consIdConstDecl(String idConstName)
50:         {
51:                 ANatNumericBasicTypeIR intType = new ANatNumericBasicTypeIR();
52:                 AClassTypeIR idGenType = transAssistant.consClassType(tracePrefixes.idGeneratorClassName());
53:                 SExpIR init = transAssistant.consInstanceCall(idGenType, tracePrefixes.idGeneratorVarName(), intType, tracePrefixes.idGeneratorIncrementMethodName());
54:
55:                 AVarDeclIR idConstDecl = transAssistant.consDecl(idConstName, intType.clone(), init);
56:                 idConstDecl.setFinal(true);
57:
58:                 return idConstDecl;
59:         }
60:
61:         public ACallObjectExpStmIR consStoreRegistration(String idConstName,
62:                         STypeIR varType, String varName, boolean staticReg)
63:         {
64:                 AIdentifierVarExpIR idVar = transAssistant.getInfo().getExpAssistant().consIdVar(varName, varType);
65:
66:                 return consStoreRegistration(idConstName, idVar, staticReg);
67:         }
68:
69:         public ACallObjectExpStmIR consStoreRegistration(String idConstName,
70:                         SExpIR subject, boolean staticReg)
71:         {
72:                 AIdentifierVarExpIR idVarExp = transAssistant.getInfo().getExpAssistant().consIdVar(idConstName, new ANatNumericBasicTypeIR());
73:                 AClassTypeIR storageType = transAssistant.consClassType(tracePrefixes.storeClassName());
74:                 String storeVarName = tracePrefixes.storeVarName();
75:
76:•                String method = staticReg
77:                                 ? tracePrefixes.storeStaticRegistrationMethodName()
78:                                 : tracePrefixes.storeRegistrationMethodName();
79:
80:                 return transAssistant.consInstanceCallStm(storageType, storeVarName, method, idVarExp, subject);
81:         }
82:
83:         public SExpIR consStoreLookup(AIdentifierVarExpIR node)
84:         {
85:                 return consStoreLookup(node, false);
86:         }
87:
88:         public SExpIR consStoreLookup(AIdentifierVarExpIR node, boolean noCast)
89:         {
90:                 AClassTypeIR storeType = transAssistant.consClassType(tracePrefixes.storeClassName());
91:
92:                 AIdentifierVarExpIR idArg = transAssistant.getInfo().getExpAssistant().consIdVar(idConstNameMap.get(node.getName()), new ANatNumericBasicTypeIR());
93:
94:                 SExpIR call = transAssistant.consInstanceCall(storeType, tracePrefixes.storeVarName(), node.getType(), tracePrefixes.storeGetValueMethodName(), idArg);
95:
96:•                if (noCast || node.getType() instanceof AUnionTypeIR
97:•                                || node.getType() instanceof AUnknownTypeIR
98:•                                || node.getType() instanceof AObjectTypeIR)
99:                 {
100:                         return call;
101:                 } else
102:                 {
103:                         ACastUnaryExpIR cast = new ACastUnaryExpIR();
104:                         cast.setType(node.getType().clone());
105:                         cast.setExp(call);
106:
107:                         return cast;
108:                 }
109:         }
110: }