Package: GroupMutRecs

GroupMutRecs

nameinstructionbranchcomplexitylinemethod
GroupMutRecs()
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
calcDependencies()
M: 3 C: 11
79%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 4
67%
M: 0 C: 1
100%
caseAModuleDeclIR(AModuleDeclIR)
M: 0 C: 57
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
filterFunctions(LinkedList)
M: 14 C: 7
33%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 3 C: 2
40%
M: 0 C: 1
100%
getResult()
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%
groupDeps()
M: 25 C: 14
36%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 5 C: 3
38%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * The VDM to Isabelle Translator
4: * %%
5: * Copyright (C) 2008 - 2015 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overturetool.cgisa.transformations;
23:
24: import org.jgrapht.DirectedGraph;
25: import org.jgrapht.alg.StrongConnectivityInspector;
26: import org.jgrapht.graph.DefaultDirectedGraph;
27: import org.jgrapht.graph.DefaultEdge;
28: import org.overture.cgisa.isair.analysis.DepthFirstAnalysisIsaAdaptor;
29: import org.overture.cgisa.isair.declarations.AMrFuncGroupDeclIR;
30: import org.overture.codegen.ir.SDeclIR;
31: import org.overture.codegen.ir.analysis.AnalysisException;
32: import org.overture.codegen.ir.declarations.AFuncDeclIR;
33: import org.overture.codegen.ir.declarations.AModuleDeclIR;
34: import org.overture.codegen.trans.ITotalTransformation;
35:
36: import java.util.LinkedList;
37: import java.util.List;
38: import java.util.Set;
39:
40: public class GroupMutRecs extends DepthFirstAnalysisIsaAdaptor implements
41: ITotalTransformation {
42:
43: private AModuleDeclIR result = null;
44: Dependencies depUtils;
45: DirectedGraph<AFuncDeclIR, DefaultEdge> deps;
46: List<AFuncDeclIR> funcs;
47:
48: public GroupMutRecs() {
49: super();
50: deps = new DefaultDirectedGraph<>(DefaultEdge.class);
51: depUtils = new Dependencies();
52: funcs = new LinkedList<AFuncDeclIR>();
53: }
54:
55: @Override
56: public void caseAModuleDeclIR(AModuleDeclIR node) throws AnalysisException {
57: result = new AModuleDeclIR();
58: result.setExports(node.getExports());
59: result.setImport(node.getImport());
60: result.setIsDLModule(node.getIsDLModule());
61: result.setIsFlat(node.getIsFlat());
62: result.setMetaData(node.getMetaData());
63: result.setName(node.getName());
64: result.setSourceNode(node.getSourceNode());
65: result.setTag(node.getTag());
66: result.setDecls(node.getDecls());
67: filterFunctions(node.getDecls());
68: calcDependencies();
69:
70: }
71:
72: private void filterFunctions(LinkedList<SDeclIR> decls) {
73:• for (SDeclIR d : decls) {
74:• if (d instanceof AFuncDeclIR) {
75: funcs.add((AFuncDeclIR) d);
76: }
77: }
78: }
79:
80: private void calcDependencies() {
81: try {
82: this.deps = depUtils.calDepsAsGraph(funcs);
83: } catch (AnalysisException e) {
84: e.printStackTrace();
85: }
86: groupDeps();
87:
88: }
89:
90: private void groupDeps() {
91: StrongConnectivityInspector<AFuncDeclIR, DefaultEdge> visitor = new StrongConnectivityInspector<>(deps);
92:• for (Set<AFuncDeclIR> scs : visitor.stronglyConnectedSets()) {
93:• if (scs.size() > 1) {
94: AMrFuncGroupDeclIR aux = new AMrFuncGroupDeclIR();
95: aux.setFuncs(new LinkedList<>(scs));
96: // this line also removes the function from the functions block
97: result.getDecls().add(aux);
98: }
99: }
100: }
101:
102: @Override
103: public AModuleDeclIR getResult() {
104: return result;
105: }
106:
107: }