Package: AModuleModulesAssistantInterpreter

AModuleModulesAssistantInterpreter

nameinstructionbranchcomplexitylinemethod
AModuleModulesAssistantInterpreter(IInterpreterAssistantFactory)
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%
findExpression(AModuleModules, File, int)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
findExpression(CombinedDefaultModule, File, int)
M: 24 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
findExpression(ModuleListInterpreter, File, int)
M: 36 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
findStatement(AModuleModules, File, int)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
findStatement(CombinedDefaultModule, File, int)
M: 24 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
findStatement(ModuleListInterpreter, File, int)
M: 36 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getProofObligations(AModuleModules)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getStateContext(AModuleModules)
M: 0 C: 15
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
initialize(AModuleModules, StateContext)
M: 24 C: 87
78%
M: 3 C: 11
79%
M: 3 C: 5
63%
M: 9 C: 24
73%
M: 0 C: 1
100%

Coverage

1: package org.overture.interpreter.assistant.module;
2:
3: import java.io.File;
4: import java.util.HashSet;
5: import java.util.Set;
6:
7: import org.overture.ast.analysis.AnalysisException;
8: import org.overture.ast.definitions.ARenamedDefinition;
9: import org.overture.ast.definitions.AStateDefinition;
10: import org.overture.ast.definitions.PDefinition;
11: import org.overture.ast.expressions.PExp;
12: import org.overture.ast.modules.AModuleModules;
13: import org.overture.ast.statements.PStm;
14: import org.overture.ast.util.modules.CombinedDefaultModule;
15: import org.overture.interpreter.assistant.IInterpreterAssistantFactory;
16: import org.overture.interpreter.runtime.Context;
17: import org.overture.interpreter.runtime.ContextException;
18: import org.overture.interpreter.runtime.StateContext;
19: import org.overture.interpreter.util.ModuleListInterpreter;
20: import org.overture.pog.pub.IProofObligationList;
21: import org.overture.pog.pub.ProofObligationGenerator;
22: import org.overture.typechecker.assistant.module.AModuleModulesAssistantTC;
23:
24: public class AModuleModulesAssistantInterpreter extends
25:                 AModuleModulesAssistantTC
26: {
27:         protected static IInterpreterAssistantFactory af;
28:
29:         @SuppressWarnings("static-access")
30:         public AModuleModulesAssistantInterpreter(IInterpreterAssistantFactory af)
31:         {
32:                 super(af);
33:                 this.af = af;
34:         }
35:
36:         public PStm findStatement(ModuleListInterpreter modules, File file,
37:                         int lineno)
38:         {
39:•                for (AModuleModules m : modules)
40:                 {
41:                         PStm stmt = null;
42:•                        if (m instanceof CombinedDefaultModule)
43:                         {
44:                                 stmt = findStatement((CombinedDefaultModule) m, file, lineno);
45:                         } else
46:                         {
47:                                 stmt = findStatement(m, file, lineno);
48:                         }
49:
50:•                        if (stmt != null)
51:                         {
52:                                 return stmt;
53:                         }
54:                 }
55:                 return null;
56:         }
57:
58:         public PStm findStatement(CombinedDefaultModule m, File file, int lineno)
59:         {
60:•                for (AModuleModules module : m.getModules())
61:                 {
62:                         PStm stmt = findStatement(module, file, lineno);
63:
64:•                        if (stmt != null)
65:                         {
66:                                 return stmt;
67:                         }
68:                 }
69:                 return null;
70:         }
71:
72:         public PStm findStatement(AModuleModules m, File file, int lineno)
73:         {
74:•                if (m.getName().getLocation().getFile().equals(file))
75:                 {
76:                         return af.createPDefinitionAssistant().findStatement(m.getDefs(), lineno);
77:                 }
78:                 return null;
79:         }
80:
81:         public PExp findExpression(ModuleListInterpreter modules, File file,
82:                         int lineno)
83:         {
84:•                for (AModuleModules m : modules)
85:                 {
86:                         PExp exp = null;
87:•                        if (m instanceof CombinedDefaultModule)
88:                         {
89:                                 exp = findExpression((CombinedDefaultModule) m, file, lineno);
90:                         } else
91:                         {
92:                                 exp = findExpression(m, file, lineno);
93:                         }
94:
95:•                        if (exp != null)
96:                         {
97:                                 return exp;
98:                         }
99:                 }
100:
101:                 return null;
102:         }
103:
104:         public PExp findExpression(CombinedDefaultModule m, File file, int lineno)
105:         {
106:•                for (AModuleModules module : m.getModules())
107:                 {
108:                         PExp exp = findExpression(module, file, lineno);
109:
110:•                        if (exp != null)
111:                         {
112:                                 return exp;
113:                         }
114:                 }
115:                 return null;
116:         }
117:
118:         public PExp findExpression(AModuleModules m, File file, int lineno)
119:         {
120:•                if (m.getName().getLocation().getFile().equals(file))
121:                 {
122:                         return af.createPDefinitionListAssistant().findExpression(m.getDefs(), lineno);
123:                 }
124:                 return null;
125:         }
126:
127:         public Context getStateContext(AModuleModules defaultModule)
128:         {
129:                 AStateDefinition sdef = af.createPDefinitionListAssistant().findStateDefinition(defaultModule.getDefs());
130:
131:•                if (sdef != null)
132:                 {
133:                         return af.createAStateDefinitionAssistant().getStateContext(sdef);
134:                 }
135:
136:                 return null;
137:         }
138:
139:         /**
140:          * Initialize the system for execution from this module. The initial {@link Context} is created, and populated with
141:          * name/value pairs from the local definitions and the imported definitions. If state is defined by the module, this
142:          * is also initialized, creating the state Context.
143:          *
144:          * @param m
145:          * @param initialContext
146:          * @return True if initialized OK.
147:          */
148:         public Set<ContextException> initialize(AModuleModules m,
149:                         StateContext initialContext)
150:         {
151:
152:                 Set<ContextException> trouble = new HashSet<ContextException>();
153:
154:•                for (PDefinition d : m.getImportdefs())
155:                 {
156:•                        if (d instanceof ARenamedDefinition)
157:                         {
158:                                 try
159:                                 {
160:                                         initialContext.putList(af.createPDefinitionAssistant().getNamedValues(d, initialContext));
161:                                 } catch (ContextException e)
162:                                 {
163:•                                        if (e.isStackOverflow())        // Stack overflow returns immediately
164:                                         {
165:                                                 trouble.clear();
166:                                                 trouble.add(e);
167:                                                 return trouble;
168:                                         }
169:
170:                                         trouble.add(e); // Carry on...
171:                                 }
172:                         }
173:                 }
174:
175:•                for (PDefinition d : m.getDefs())
176:                 {
177:                         try
178:                         {
179:                                 initialContext.putList(af.createPDefinitionAssistant().getNamedValues(d, initialContext));
180:                         } catch (ContextException e)
181:                         {
182:•                                if (e.isStackOverflow())        // Stack overflow returns immediately
183:                                 {
184:                                         trouble.clear();
185:                                         trouble.add(e);
186:                                         return trouble;
187:                                 }
188:
189:                                 trouble.add(e); // Carry on...
190:                         }
191:                 }
192:
193:                 try
194:                 {
195:                         AStateDefinition sdef = af.createPDefinitionListAssistant().findStateDefinition(m.getDefs());
196:
197:•                        if (sdef != null)
198:                         {
199:                                 af.createAStateDefinitionAssistant().initState(sdef, initialContext);
200:                         }
201:                 } catch (ContextException e)
202:                 {
203:•                        if (e.isStackOverflow())        // Stack overflow returns immediately
204:                         {
205:                                 trouble.clear();
206:                                 trouble.add(e);
207:                                 return trouble;
208:                         }
209:
210:                         trouble.add(e); // Carry on...
211:                 }
212:
213:                 return trouble;
214:
215:         }
216:
217:         public IProofObligationList getProofObligations(AModuleModules m)
218:                         throws AnalysisException
219:         {
220:                 return ProofObligationGenerator.generateProofObligations(m);
221:         }
222:
223: }