Package: StmAssistantIR

StmAssistantIR

nameinstructionbranchcomplexitylinemethod
StmAssistantIR(AssistantManager)
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%
appearsInRightContext(PStm)
M: 0 C: 24
100%
M: 0 C: 10
100%
M: 0 C: 6
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
equal(AMetaStmIR, AMetaStmIR)
M: 2 C: 38
95%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 1 C: 7
88%
M: 0 C: 1
100%
getSuperClassName(ASuperCallStmIR)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
handleAlternativesCasesStm(IRInfo, PExp, List, List)
M: 0 C: 102
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 20
100%
M: 0 C: 1
100%
inAtomic(SStmIR)
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
injectDeclAsStm(ABlockStmIR, AVarDeclIR)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
isScoped(ABlockSimpleBlockStm)
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%
isScoped(ABlockStmIR)
M: 0 C: 28
100%
M: 4 C: 8
67%
M: 4 C: 3
43%
M: 0 C: 6
100%
M: 0 C: 1
100%
isScoped(ALetStm)
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.assistant;
23:
24: import java.util.List;
25:
26: import org.overture.ast.analysis.AnalysisException;
27: import org.overture.ast.definitions.SOperationDefinition;
28: import org.overture.ast.expressions.PExp;
29: import org.overture.ast.statements.ABlockSimpleBlockStm;
30: import org.overture.ast.statements.ACaseAlternativeStm;
31: import org.overture.ast.statements.AElseIfStm;
32: import org.overture.ast.statements.AForAllStm;
33: import org.overture.ast.statements.AForIndexStm;
34: import org.overture.ast.statements.AIfStm;
35: import org.overture.ast.statements.ALetStm;
36: import org.overture.ast.statements.PStm;
37: import org.overture.ast.types.AUnionType;
38: import org.overture.ast.types.PType;
39: import org.overture.codegen.ir.IRInfo;
40: import org.overture.codegen.ir.SStmIR;
41: import org.overture.codegen.ir.STypeIR;
42: import org.overture.codegen.ir.declarations.ADefaultClassDeclIR;
43: import org.overture.codegen.ir.declarations.AMethodDeclIR;
44: import org.overture.codegen.ir.declarations.AVarDeclIR;
45: import org.overture.codegen.ir.statements.AAtomicStmIR;
46: import org.overture.codegen.ir.statements.ABlockStmIR;
47: import org.overture.codegen.ir.statements.ACaseAltStmStmIR;
48: import org.overture.codegen.ir.statements.AElseIfStmIR;
49: import org.overture.codegen.ir.statements.AForAllStmIR;
50: import org.overture.codegen.ir.statements.AForIndexStmIR;
51: import org.overture.codegen.ir.statements.AForLoopStmIR;
52: import org.overture.codegen.ir.statements.AIfStmIR;
53: import org.overture.codegen.ir.statements.AMetaStmIR;
54: import org.overture.codegen.ir.statements.ASuperCallStmIR;
55:
56: public class StmAssistantIR extends AssistantBase
57: {
58:         public StmAssistantIR(AssistantManager assistantManager)
59:         {
60:                 super(assistantManager);
61:         }
62:
63:         public void injectDeclAsStm(ABlockStmIR block, AVarDeclIR decl)
64:         {
65:                 ABlockStmIR wrappingBlock = new ABlockStmIR();
66:
67:                 wrappingBlock.getLocalDefs().add(decl);
68:
69:                 block.getStatements().add(wrappingBlock);
70:         }
71:
72:         public void handleAlternativesCasesStm(IRInfo question, PExp exp,
73:                         List<ACaseAlternativeStm> cases, List<ACaseAltStmStmIR> casesCg)
74:                         throws AnalysisException
75:         {
76:•                for (ACaseAlternativeStm alt : cases)
77:                 {
78:                         SStmIR altCg = alt.apply(question.getStmVisitor(), question);
79:                         casesCg.add((ACaseAltStmStmIR) altCg);
80:                 }
81:
82:                 PType expType = question.getTypeAssistant().resolve(exp.getType());
83:
84:•                if (expType instanceof AUnionType)
85:                 {
86:                         AUnionType unionType = ((AUnionType) expType).clone();
87:                         question.getTcFactory().createAUnionTypeAssistant().expand(unionType);
88:
89:•                        for (int i = 0; i < cases.size(); i++)
90:                         {
91:                                 ACaseAlternativeStm vdmCase = cases.get(i);
92:                                 ACaseAltStmStmIR cgCase = casesCg.get(i);
93:
94:                                 PType patternType = question.getAssistantManager().getTypeAssistant().getType(question, unionType, vdmCase.getPattern());
95:                                 STypeIR patternTypeCg = patternType.apply(question.getTypeVisitor(), question);
96:                                 cgCase.setPatternType(patternTypeCg);
97:                         }
98:                 } else
99:                 {
100:                         STypeIR expTypeCg = expType.apply(question.getTypeVisitor(), question);
101:
102:•                        for (ACaseAltStmStmIR altCg : casesCg)
103:                         {
104:                                 altCg.setPatternType(expTypeCg.clone());
105:                         }
106:                 }
107:         }
108:
109:         public boolean inAtomic(SStmIR stm)
110:         {
111:•                return stm.getAncestor(AAtomicStmIR.class) != null;
112:         }
113:
114:         public String getSuperClassName(ASuperCallStmIR stm)
115:         {
116:                 ADefaultClassDeclIR enclosingClass = stm.getAncestor(ADefaultClassDeclIR.class);
117:
118:                 return enclosingClass.getName();
119:         }
120:
121:         public boolean isScoped(ABlockSimpleBlockStm block)
122:         {
123:                 return appearsInRightContext(block);
124:         }
125:
126:         public boolean isScoped(ALetStm let)
127:         {
128:                 return appearsInRightContext(let);
129:         }
130:
131:         private boolean appearsInRightContext(PStm block)
132:         {
133:•                return !(block.parent() instanceof SOperationDefinition)
134:•                                && !(block.parent() instanceof AElseIfStm)
135:•                                && !(block.parent() instanceof AIfStm)
136:•                                && !(block.parent() instanceof AForAllStm)
137:•                                && !(block.parent() instanceof AForIndexStm);
138:         }
139:
140:         public boolean isScoped(ABlockStmIR block)
141:         {
142:•                return !(block.parent() instanceof AMethodDeclIR)
143:•                                && !(block.parent() instanceof AElseIfStmIR)
144:•                                && !(block.parent() instanceof AIfStmIR)
145:•                                && !(block.parent() instanceof AForAllStmIR)
146:•                                && !(block.parent() instanceof AForIndexStmIR)
147:•                                && !(block.parent() instanceof AForLoopStmIR);
148:         }
149:
150:         public boolean equal(AMetaStmIR left, AMetaStmIR right)
151:         {
152:•                if (left.getMetaData().size() != right.getMetaData().size())
153:                 {
154:                         return false;
155:                 }
156:
157:•                for (int i = 0; i < left.getMetaData().size(); i++)
158:                 {
159:                         String currentLeft = left.getMetaData().get(i).value;
160:                         String currentRight = right.getMetaData().get(i).value;
161:
162:•                        if (!currentLeft.equals(currentRight))
163:                         {
164:                                 return false;
165:                         }
166:                 }
167:
168:                 return true;
169:         }
170: }