Package: ModuleListAssistantInterpreter

ModuleListAssistantInterpreter

nameinstructionbranchcomplexitylinemethod
ModuleListAssistantInterpreter(IInterpreterAssistantFactory)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
createInitialContext(ModuleList)
M: 0 C: 29
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getProofObligations(ModuleList)
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
initialize(RootContext, ModuleList, DBGPReader)
M: 8 C: 92
92%
M: 4 C: 16
80%
M: 4 C: 7
64%
M: 3 C: 22
88%
M: 0 C: 1
100%

Coverage

1: package org.overture.interpreter.assistant.module;
2:
3: import java.util.HashSet;
4: import java.util.Set;
5:
6: import org.overture.ast.analysis.AnalysisException;
7: import org.overture.ast.lex.LexLocation;
8: import org.overture.ast.modules.AModuleModules;
9: import org.overture.ast.util.modules.ModuleList;
10: import org.overture.interpreter.assistant.IInterpreterAssistantFactory;
11: import org.overture.interpreter.debug.DBGPReader;
12: import org.overture.interpreter.messages.Console;
13: import org.overture.interpreter.runtime.CollectedContextException;
14: import org.overture.interpreter.runtime.CollectedExceptions;
15: import org.overture.interpreter.runtime.ContextException;
16: import org.overture.interpreter.runtime.RootContext;
17: import org.overture.interpreter.runtime.StateContext;
18: import org.overture.pog.obligation.ProofObligationList;
19: import org.overture.pog.pub.IProofObligationList;
20:
21: public class ModuleListAssistantInterpreter
22: {
23:         protected static IInterpreterAssistantFactory af;
24:
25:         @SuppressWarnings("static-access")
26:         public ModuleListAssistantInterpreter(IInterpreterAssistantFactory af)
27:         {
28:                 this.af = af;
29:         }
30:
31:         public RootContext createInitialContext(ModuleList modules)
32:         {
33:                 StateContext initialContext = null;
34:
35:•                if (modules.isEmpty())
36:                 {
37:                         initialContext = new StateContext(af, new LexLocation(), "global environment");
38:                 }
39:                 else
40:                 {
41:                         initialContext = new StateContext(af, modules.get(0).getName().getLocation(), "global environment");
42:                 }
43:                 
44:                 return initialContext;
45:         }
46:
47:         public void initialize(RootContext ctxt, ModuleList modules, DBGPReader dbgp)
48:         {
49:                 StateContext initialContext = (StateContext) ctxt;
50:                 initialContext.setThreadState(dbgp, null);
51:                 Set<ContextException> problems = null;
52:                 int retries = 5;
53:
54:                 do
55:                 {
56:                         problems = new HashSet<ContextException>();
57:
58:•                        for (AModuleModules m : modules)
59:                         {
60:                                 Set<ContextException> e = af.createAModuleModulesAssistant().initialize(m, initialContext);
61:
62:•                                if (e != null)
63:                                 {
64:                                         problems.addAll(e);
65:
66:•                                        if (e.size() == 1 && e.iterator().next().isStackOverflow())
67:                         {
68:                                 retries = 0;
69:                                 break;
70:                         }
71:                                 }
72:                         }
73:•                } while (--retries > 0 && !problems.isEmpty());
74:
75:•                if (!problems.isEmpty())
76:                 {
77:                         ContextException toThrow = problems.iterator().next();
78:
79:•                        for (ContextException e : problems)
80:                         {
81:                                 Console.err.println(e);
82:
83:•                                if (e.number != 4034) // Not in scope err
84:                                 {
85:                                         toThrow = e;
86:                                 }
87:                         }
88:
89:                         // throw toThrow;
90:•                        if (toThrow instanceof ContextException)
91:                         {
92:                                 throw new CollectedContextException((ContextException) toThrow, problems);
93:                         } else
94:                         {
95:                                 throw new CollectedExceptions(problems);
96:                         }
97:                 }
98:         }
99:
100:         public IProofObligationList getProofObligations(ModuleList modules)
101:                         throws AnalysisException
102:         {
103:
104:                 IProofObligationList obligations = new ProofObligationList();
105:
106:•                for (AModuleModules m : modules)
107:                 {
108:                         obligations.addAll(af.createAModuleModulesAssistant().getProofObligations(m));
109:                 }
110:
111:                 obligations.trivialCheck();
112:                 return obligations;
113:         }
114:
115: }