Package: DelegateExpressionEvaluator

DelegateExpressionEvaluator

nameinstructionbranchcomplexitylinemethod
DelegateExpressionEvaluator()
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%
caseANotYetSpecifiedExp(ANotYetSpecifiedExp, Context)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
evalDelegatedANotYetSpecified(INode, ILexLocation, int, String, boolean, Context)
M: 83 C: 96
54%
M: 8 C: 20
71%
M: 8 C: 7
47%
M: 12 C: 26
68%
M: 0 C: 1
100%
get_file_pos(Context)
M: 100 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.overture.interpreter.eval;
2:
3: import java.lang.reflect.Method;
4:
5: import org.overture.ast.analysis.AnalysisException;
6: import org.overture.ast.definitions.SClassDefinition;
7: import org.overture.ast.expressions.ANotYetSpecifiedExp;
8: import org.overture.ast.intf.lex.ILexLocation;
9: import org.overture.ast.lex.Dialect;
10: import org.overture.ast.lex.LexNameToken;
11: import org.overture.ast.messages.InternalException;
12: import org.overture.ast.modules.AModuleModules;
13: import org.overture.ast.node.INode;
14: import org.overture.config.Settings;
15: import org.overture.interpreter.debug.BreakpointManager;
16: import org.overture.interpreter.runtime.ClassInterpreter;
17: import org.overture.interpreter.runtime.Context;
18: import org.overture.interpreter.runtime.ContextException;
19: import org.overture.interpreter.runtime.Interpreter;
20: import org.overture.interpreter.runtime.ModuleInterpreter;
21: import org.overture.interpreter.runtime.RootContext;
22: import org.overture.interpreter.runtime.ValueException;
23: import org.overture.interpreter.runtime.VdmRuntime;
24: import org.overture.interpreter.runtime.VdmRuntimeError;
25: import org.overture.interpreter.runtime.state.AModuleModulesRuntime;
26: import org.overture.interpreter.runtime.state.SClassDefinitionRuntime;
27: import org.overture.interpreter.values.NaturalOneValue;
28: import org.overture.interpreter.values.ObjectValue;
29: import org.overture.interpreter.values.SeqValue;
30: import org.overture.interpreter.values.TupleValue;
31: import org.overture.interpreter.values.Value;
32: import org.overture.interpreter.values.ValueList;
33:
34: public class DelegateExpressionEvaluator extends ExpressionEvaluator
35: {
36:
37:         protected Value evalDelegatedANotYetSpecified(INode node,
38:                         ILexLocation location, int abortNumber, String type,
39:                         boolean failOnUnhandled, Context ctxt) throws AnalysisException
40:         {
41:                 BreakpointManager.getBreakpoint(node).check(location, ctxt);
42:
43:•                if (location.getModule().equals("VDMUtil")
44:•                                || location.getModule().equals("DEFAULT"))
45:                 {
46:•                        if (ctxt.title.equals("get_file_pos()"))
47:                         {
48:                                 // This needs location information from the context, so we
49:                                 // can't just call down to a native method for this one.
50:
51:                                 return get_file_pos(ctxt);
52:                         }
53:                 }
54:
55:•                if (location.getModule().equals("IO")
56:•                                || location.getModule().equals("DEFAULT"))
57:                 {
58:•                        if (ctxt.title.equals("freadval(filename)"))
59:                         {
60:                                 // This needs type invariant information from the context, so we
61:                                 // can't just call down to a native method for this one.
62:
63:                                 try
64:                                 {
65:                                         LexNameToken arg = new LexNameToken("IO", "filename", location);
66:                                         Value fval = ctxt.get(arg);
67:
68:                                         // We can't link with the IO class directly because it's in the default
69:                                         // package, so we reflect our way over to it.
70:
71:                                         @SuppressWarnings("rawtypes")
72:                                         Class io = Class.forName("IO");
73:                                         @SuppressWarnings("unchecked")
74:                                         Method m = io.getMethod("freadval", new Class[] {
75:                                                         Value.class, Context.class });
76:                                         return (Value) m.invoke(io.newInstance(), new Object[] {
77:                                                         fval, ctxt });
78:                                 } catch (Exception e)
79:                                 {
80:                                         throw new InternalException(62, "Cannot invoke native method: "
81:                                                         + e.getMessage());
82:                                 }
83:                         }
84:                 }
85:
86:•                if (Settings.dialect == Dialect.VDM_SL)
87:                 {
88:                         ModuleInterpreter i = (ModuleInterpreter) Interpreter.getInstance();
89:                         AModuleModules module = i.findModule(location.getModule());
90:
91:•                        if (module != null)
92:                         {
93:                                 AModuleModulesRuntime state = VdmRuntime.getNodeState(module, ctxt.assistantFactory);
94:•                                if (state.hasDelegate())
95:                                 {
96:                                         return state.invokeDelegate(ctxt);
97:                                 }
98:                         }
99:                 } else
100:                 {
101:                         ObjectValue self = ctxt.getSelf();
102:
103:•                        if (self == null)
104:                         {
105:                                 ClassInterpreter i = (ClassInterpreter) Interpreter.getInstance();
106:                                 SClassDefinition cls = i.findClass(location.getModule());
107:
108:•                                if (cls != null)
109:                                 {
110:                                         SClassDefinitionRuntime state = VdmRuntime.getNodeState(ctxt.assistantFactory, cls);
111:•                                        if (state.hasDelegate())
112:                                         {
113:                                                 return state.invokeDelegate(ctxt);
114:                                         }
115:                                 }
116:                         } else
117:                         {
118:•                                if (self.hasDelegate(ctxt))
119:                                 {
120:                                         return self.invokeDelegate(ctxt);
121:                                 }
122:                         }
123:                 }
124:
125:•                if (failOnUnhandled)
126:                 {
127:                         return VdmRuntimeError.abort(location, abortNumber, "'not yet specified' "
128:                                         + type + " reached", ctxt);
129:                 }
130:                 return null;
131:
132:         }
133:
134:         @Override
135:         public Value caseANotYetSpecifiedExp(ANotYetSpecifiedExp node, Context ctxt)
136:                         throws AnalysisException
137:         {
138:                 return evalDelegatedANotYetSpecified(node, node.getLocation(), 4024, "expression", true, ctxt);
139:         }
140:
141:         private Value get_file_pos(Context ctxt)
142:         {
143:                 try
144:                 {
145:                         ValueList tuple = new ValueList();
146:                         Context outer = ctxt.getRoot().outer;
147:                         RootContext root = outer.getRoot();
148:
149:                         tuple.add(new SeqValue(ctxt.location.getFile().getPath()));
150:                         tuple.add(new NaturalOneValue(ctxt.location.getStartLine()));
151:                         tuple.add(new NaturalOneValue(ctxt.location.getStartPos()));
152:                         tuple.add(new SeqValue(ctxt.location.getModule()));
153:
154:                         int bra = root.title.indexOf('(');
155:
156:•                        if (bra > 0)
157:                         {
158:                                 tuple.add(new SeqValue(root.title.substring(0, bra)));
159:                         } else
160:                         {
161:                                 tuple.add(new SeqValue(""));
162:                         }
163:
164:                         return new TupleValue(tuple);
165:                 } catch (ValueException e)
166:                 {
167:                         throw new ContextException(e, ctxt.location);
168:                 } catch (Exception e)
169:                 {
170:                         throw new ContextException(4076, e.getMessage(), ctxt.location, ctxt);
171:                 }
172:         }
173: }