Package: StateInit

StateInit

nameinstructionbranchcomplexitylinemethod
StateInit(IRInfo)
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%
caseAStateDeclIR(AStateDeclIR)
M: 33 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
makeExecutableInit(AStateDeclIR)
M: 25 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.overturetool.cgisa.transformations;
2:
3: import org.overture.codegen.ir.IRInfo;
4: import org.overture.codegen.ir.analysis.AnalysisException;
5: import org.overture.codegen.ir.analysis.DepthFirstAnalysisAdaptor;
6: import org.overture.codegen.ir.declarations.AMethodDeclIR;
7: import org.overture.codegen.ir.declarations.AModuleDeclIR;
8: import org.overture.codegen.ir.declarations.AStateDeclIR;
9: import org.overture.codegen.ir.expressions.AEqualsBinaryExpIR;
10: import org.overture.codegen.ir.statements.AReturnStmIR;
11:
12: public class StateInit extends DepthFirstAnalysisAdaptor
13: {
14:         private IRInfo info;
15:
16:         public StateInit(IRInfo info)
17:         {
18:                 this.info = info;
19:         }
20:
21:         @Override
22:         public void caseAStateDeclIR(AStateDeclIR node) throws AnalysisException
23:         {
24:•                if (node.getInitDecl() != null)
25:                 {
26:                         AMethodDeclIR initOp;
27:•                        if (node.getExecutable())
28:                         {
29:                                 initOp = makeExecutableInit(node);
30:                         } else
31:                         {
32:                                 initOp = info.getDeclAssistant().funcToMethod(node.getInitDecl());
33:                         }
34:
35:                         AModuleDeclIR module = node.getAncestor(AModuleDeclIR.class);
36:                         module.getDecls().add(initOp);
37:                         node.setInitDecl(null);
38:                 }
39:         }
40:
41:         private AMethodDeclIR makeExecutableInit(AStateDeclIR node)
42:         {
43:                 AMethodDeclIR meth = info.getDeclAssistant().funcToMethod(node.getInitDecl());
44:                 AReturnStmIR ret = new AReturnStmIR();
45:
46:                 AEqualsBinaryExpIR initExp = (AEqualsBinaryExpIR) node.getInitExp();
47:                 ret.setExp(initExp.getRight().clone());
48:
49:                 meth.setBody(ret);
50:                 return meth;
51:         }
52: }