Package: InterpreterUtil

InterpreterUtil

nameinstructionbranchcomplexitylinemethod
InterpreterUtil()
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%
getInterpreter(ClassListInterpreter)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getInterpreter(ModuleListInterpreter)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
interpret(Dialect, String, File)
M: 4 C: 119
97%
M: 5 C: 6
55%
M: 5 C: 3
38%
M: 2 C: 28
93%
M: 0 C: 1
100%
interpret(List, String, Dialect)
M: 0 C: 85
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 19
100%
M: 0 C: 1
100%
interpret(String)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: package org.overture.interpreter.util;
2:
3: import java.io.File;
4: import java.util.List;
5:
6: import org.overture.ast.definitions.SClassDefinition;
7: import org.overture.ast.lex.Dialect;
8: import org.overture.ast.modules.AModuleModules;
9: import org.overture.ast.node.INode;
10: import org.overture.interpreter.runtime.ClassInterpreter;
11: import org.overture.interpreter.runtime.Interpreter;
12: import org.overture.interpreter.runtime.ModuleInterpreter;
13: import org.overture.interpreter.values.Value;
14: import org.overture.typechecker.util.TypeCheckerUtil;
15: import org.overture.typechecker.util.TypeCheckerUtil.TypeCheckResult;
16:
17: public class InterpreterUtil
18: {
19:         public static Interpreter getInterpreter(ModuleListInterpreter modules)
20:                         throws Exception
21:         {
22:                 return new ModuleInterpreter(modules);
23:         }
24:
25:         public static Interpreter getInterpreter(ClassListInterpreter classes)
26:                         throws Exception
27:         {
28:                 return new ClassInterpreter(classes);
29:         }
30:
31:         public static Value interpret(List<INode> ast, String entry, Dialect dialect)
32:                         throws Exception
33:         {
34:•                if (dialect == Dialect.VDM_SL)
35:                 {
36:                         ModuleListInterpreter list = new ModuleListInterpreter();
37:•                        for (INode n : ast)
38:                         {
39:                                 list.add((AModuleModules) n);
40:                         }
41:                         Interpreter interpreter = getInterpreter(list);
42:                         interpreter.init(null);
43:                         interpreter.setDefaultName(list.get(0).getName().getName());
44:                         Value val = interpreter.execute(entry, null);
45:                         return val;
46:                 } else
47:                 {
48:                         ClassListInterpreter list = new ClassListInterpreter();
49:•                        for (INode n : ast)
50:                         {
51:                                 list.add((SClassDefinition) n);
52:                         }
53:                         Interpreter interpreter = getInterpreter(list);
54:                         interpreter.init(null);
55:                         interpreter.setDefaultName(list.get(0).getName().getName());
56:                         Value val = interpreter.execute(entry, null);
57:                         return val;
58:                 }
59:         }
60:
61:         public static Value interpret(String content) throws Exception
62:         {
63:
64:                 Interpreter interpreter = getInterpreter(new ModuleListInterpreter());
65:                 interpreter.init(null);
66:                 Value val = interpreter.execute(content, null);
67:                 return val;
68:         }
69:
70:         public static Value interpret(Dialect dialect, String entry, File file)
71:                         throws Exception
72:         {
73:•                switch (dialect)
74:                 {
75:
76:                         case VDM_SL:
77:                         {
78:                                 TypeCheckResult<List<AModuleModules>> result = TypeCheckerUtil.typeCheckSl(file);
79:
80:•                                if (result.errors.isEmpty())
81:                                 {
82:                                         ModuleListInterpreter list = new ModuleListInterpreter();
83:                                         list.addAll(result.result);
84:                                         Interpreter interpreter = getInterpreter(list);
85:                                         interpreter.init(null);
86:                                         interpreter.setDefaultName(list.get(0).getName().getName());
87:                                         Value val = interpreter.execute(entry, null);
88:                                         return val;
89:                                 }
90:                         }
91:                         case VDM_PP:
92:                         {
93:                                 TypeCheckResult<List<SClassDefinition>> result = TypeCheckerUtil.typeCheckPp(file);
94:
95:•                                if (result.errors.isEmpty())
96:                                 {
97:                                         ClassListInterpreter list = new ClassListInterpreter();
98:                                         list.addAll(result.result);
99:                                         Interpreter interpreter = getInterpreter(list);
100:                                         interpreter.init(null);
101:                                         interpreter.setDefaultName(list.get(0).getName().getName());
102:                                         Value val = interpreter.execute(entry, null);
103:                                         return val;
104:                                 }
105:                         }
106:                         case VDM_RT:
107:                         {
108:                                 TypeCheckResult<List<SClassDefinition>> result = TypeCheckerUtil.typeCheckRt(file);
109:
110:•                                if (result.errors.isEmpty())
111:                                 {
112:                                         ClassListInterpreter list = new ClassListInterpreter();
113:                                         list.addAll(result.result);
114:                                         Interpreter interpreter = getInterpreter(list);
115:                                         interpreter.init(null);
116:                                         interpreter.setDefaultName(list.get(0).getName().getName());
117:                                         Value val = interpreter.execute(entry, null);
118:                                         return val;
119:                                 }
120:                         }
121:                         case CML:
122:                                 return null;
123:                 }
124:                 return null;
125:         }
126: }