Package: IRGenerator

IRGenerator

nameinstructionbranchcomplexitylinemethod
IRGenerator()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
applyPartialTransformation(IRStatus, IAnalysis)
M: 5 C: 21
81%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 6
86%
M: 0 C: 1
100%
applyTotalTransformation(IRStatus, ITotalTransformation)
M: 5 C: 25
83%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 7
88%
M: 0 C: 1
100%
clear()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
computeDefTable(List)
M: 0 C: 36
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 8
100%
M: 0 C: 1
100%
generateFrom(INode)
M: 2 C: 67
97%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 11
92%
M: 0 C: 1
100%
generateFrom(PExp)
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getIRInfo()
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%
getQuoteValues()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * VDM Code Generator
4: * %%
5: * Copyright (C) 2008 - 2014 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.overture.codegen.ir;
23:
24: import java.util.HashSet;
25: import java.util.LinkedList;
26: import java.util.List;
27: import java.util.Map;
28: import java.util.Set;
29:
30: import org.overture.ast.analysis.AnalysisException;
31: import org.overture.ast.definitions.PDefinition;
32: import org.overture.ast.definitions.SClassDefinition;
33: import org.overture.ast.expressions.PExp;
34: import org.overture.ast.modules.AModuleModules;
35: import org.overture.ast.statements.AIdentifierStateDesignator;
36: import org.overture.codegen.analysis.vdm.IdStateDesignatorDefCollector;
37: import org.overture.codegen.ir.declarations.AModuleDeclIR;
38: import org.overture.codegen.ir.declarations.SClassDeclIR;
39: import org.overture.codegen.trans.ITotalTransformation;
40:
41: public class IRGenerator
42: {
43:         protected IRInfo codeGenInfo;
44:
45:         public IRGenerator()
46:         {
47:                 this.codeGenInfo = new IRInfo();
48:         }
49:
50:         public void computeDefTable(
51:                         List<? extends org.overture.ast.node.INode> mergedParseLists)
52:                         throws AnalysisException
53:         {
54:                 List<org.overture.ast.node.INode> classesToConsider = new LinkedList<>();
55:
56:•                for (org.overture.ast.node.INode node : mergedParseLists)
57:                 {
58:•                        if (!codeGenInfo.getDeclAssistant().isLibrary(node))
59:                         {
60:                                 classesToConsider.add(node);
61:                         }
62:                 }
63:
64:                 Map<AIdentifierStateDesignator, PDefinition> idDefs = IdStateDesignatorDefCollector.getIdDefs(classesToConsider, codeGenInfo.getTcFactory());
65:                 codeGenInfo.setIdStateDesignatorDefs(idDefs);
66:         }
67:
68:         public void clear()
69:         {
70:                 codeGenInfo.clear();
71:         }
72:
73:         public IRStatus<PIR> generateFrom(org.overture.ast.node.INode node)
74:                         throws AnalysisException
75:         {
76:                 codeGenInfo.clearNodes();
77:
78:•                if (node instanceof SClassDefinition)
79:                 {
80:                         SClassDeclIR classCg = node.apply(codeGenInfo.getClassVisitor(), codeGenInfo);
81:                         Set<VdmNodeInfo> unsupportedNodes = new HashSet<VdmNodeInfo>(codeGenInfo.getUnsupportedNodes());
82:                         String name = ((SClassDefinition) node).getName().getName();
83:
84:                         return new IRStatus<PIR>(node, name, classCg, unsupportedNodes);
85:•                } else if (node instanceof AModuleModules)
86:                 {
87:                         AModuleDeclIR module = node.apply(codeGenInfo.getModuleVisitor(), codeGenInfo);
88:                         Set<VdmNodeInfo> unsupportedNodes = new HashSet<VdmNodeInfo>(codeGenInfo.getUnsupportedNodes());
89:                         String name = ((AModuleModules) node).getName().getName();
90:
91:                         return new IRStatus<PIR>(node, name, module, unsupportedNodes);
92:                 }
93:
94:                 return null;
95:         }
96:
97:         public void applyPartialTransformation(IRStatus<? extends INode> status,
98:                         org.overture.codegen.ir.analysis.intf.IAnalysis transformation)
99:                         throws org.overture.codegen.ir.analysis.AnalysisException
100:         {
101:•                if (!status.canBeGenerated())
102:                 {
103:                         throw new org.overture.codegen.ir.analysis.AnalysisException("Cannot apply partial transformation to a status that cannot be generated!");
104:                 }
105:
106:                 codeGenInfo.clearTransformationWarnings();
107:
108:                 status.getIrNode().apply(transformation);
109:                 HashSet<IrNodeInfo> transformationWarnings = new HashSet<IrNodeInfo>(codeGenInfo.getTransformationWarnings());
110:
111:                 status.addTransformationWarnings(transformationWarnings);
112:         }
113:
114:         public void applyTotalTransformation(IRStatus<PIR> status,
115:                         ITotalTransformation trans)
116:                         throws org.overture.codegen.ir.analysis.AnalysisException
117:         {
118:•                if (!status.canBeGenerated())
119:                 {
120:                         throw new org.overture.codegen.ir.analysis.AnalysisException("Cannot apply total transformation to a status that cannot be generated!");
121:                 }
122:
123:                 codeGenInfo.clearTransformationWarnings();
124:
125:                 status.getIrNode().apply(trans);
126:                 HashSet<IrNodeInfo> transformationWarnings = new HashSet<IrNodeInfo>(codeGenInfo.getTransformationWarnings());
127:                 status.addTransformationWarnings(transformationWarnings);
128:                 status.setIrNode(trans.getResult());
129:         }
130:
131:         public IRStatus<SExpIR> generateFrom(PExp exp) throws AnalysisException
132:         {
133:                 codeGenInfo.clearNodes();
134:
135:                 SExpIR expCg = exp.apply(codeGenInfo.getExpVisitor(), codeGenInfo);
136:                 Set<VdmNodeInfo> unsupportedNodes = new HashSet<VdmNodeInfo>(codeGenInfo.getUnsupportedNodes());
137:
138:                 return new IRStatus<SExpIR>(exp, "expression", expCg, unsupportedNodes);
139:         }
140:
141:         public List<String> getQuoteValues()
142:         {
143:                 return codeGenInfo.getQuoteValues();
144:         }
145:
146:         public IRInfo getIRInfo()
147:         {
148:                 return codeGenInfo;
149:         }
150: }