Package: BasicRuntimeValidator

BasicRuntimeValidator

nameinstructionbranchcomplexitylinemethod
BasicRuntimeValidator()
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
bindSystemVariables(ASystemClassDefinition, IInterpreterAssistantFactory)
M: 46 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
digInCtxt(String[], Context)
M: 59 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
digInVariable(Value, List, Context)
M: 52 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
filterVariablesInSystem(String, List)
M: 24 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getConjectures()
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%
init(ClassInterpreter)
M: 44 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
stop()
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
validate(OperationValue, RTMessage.MessageType)
M: 40 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
validateAsync(OperationValue, AsyncThread)
M: 33 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /***************************************************************************
2: *
3: *        Copyright (c) 2009 IHA
4: *
5: *        Author: Kenneth Lausdahl and Augusto Ribeiro
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: **************************************************************************/
23:
24: package org.overture.interpreter.runtime.validation;
25:
26: import java.io.File;
27: import java.io.IOException;
28: import java.util.ArrayList;
29: import java.util.List;
30:
31: import org.overture.ast.definitions.ASystemClassDefinition;
32: import org.overture.ast.intf.lex.ILexNameToken;
33: import org.overture.interpreter.assistant.IInterpreterAssistantFactory;
34: import org.overture.interpreter.messages.Console;
35: import org.overture.interpreter.messages.rtlog.RTMessage.MessageType;
36: import org.overture.interpreter.runtime.ClassInterpreter;
37: import org.overture.interpreter.runtime.Context;
38: import org.overture.interpreter.runtime.ValueException;
39: import org.overture.interpreter.scheduler.AsyncThread;
40: import org.overture.interpreter.scheduler.BasicSchedulableThread;
41: import org.overture.interpreter.scheduler.ISchedulableThread;
42: import org.overture.interpreter.scheduler.SystemClock;
43: import org.overture.interpreter.values.NameValuePairMap;
44: import org.overture.interpreter.values.ObjectValue;
45: import org.overture.interpreter.values.OperationValue;
46: import org.overture.interpreter.values.Value;
47:
48: public class BasicRuntimeValidator implements IRuntimeValidatior
49: {
50:
51:         final List<ConjectureDefinition> conjectures = new ArrayList<ConjectureDefinition>();
52:         final List<String[]> variables = new ArrayList<String[]>();
53:
54:         public void init(ClassInterpreter classInterpreter)
55:         {
56:                 TimingInvariantsParser parser = new TimingInvariantsParser();
57:
58:•                for (File file : classInterpreter.getSourceFiles())
59:                 {
60:                         try
61:                         {
62:                                 conjectures.addAll(parser.parse(file));
63:                         } catch (IOException e)
64:                         {
65:                                 // TODO Auto-generated catch block
66:                                 e.printStackTrace();
67:                         }
68:                 }
69:•                for (ConjectureDefinition cd : conjectures)
70:                 {
71:                         Console.out.println(cd.toString());
72:                 }
73:
74:         }
75:
76:         public void validate(OperationValue operationValue, MessageType type)
77:         {
78:•                if (operationValue.isStatic)
79:                 {
80:                         return;
81:                 }
82:
83:•                if (conjectures.size() > 0)
84:                 {
85:                         ISchedulableThread ct = BasicSchedulableThread.getThread(Thread.currentThread());
86:
87:•                        for (ConjectureDefinition conj : conjectures)
88:                         {
89:
90:                                 conj.process(operationValue.name.getName(), operationValue.classdef.getName().getName(), type, SystemClock.getWallTime(), ct.getId(), operationValue.getSelf().objectReference);
91:                         }
92:                 }
93:
94:         }
95:
96:         public void bindSystemVariables(ASystemClassDefinition systemDefinition,
97:                         IInterpreterAssistantFactory af)
98:         {
99:
100:                 List<String[]> variablesTemp = filterVariablesInSystem(systemDefinition.getName().getName(), variables);
101:                 Context ctxt = af.createSClassDefinitionAssistant().getStatics(systemDefinition);
102:
103:•                for (String[] strings : variablesTemp)
104:                 {
105:                         Value v = digInCtxt(strings, ctxt);
106:•                        for (ConjectureDefinition definition : conjectures)
107:                         {
108:                                 definition.associateVariable(strings, v);
109:                         }
110:
111:                 }
112:
113:         }
114:
115:         private Value digInCtxt(String[] strings, Context ctxt)
116:         {
117:
118:                 List<String> rest = new ArrayList<String>();
119:•                for (int i = 1; i < strings.length; i++)
120:                 {
121:                         rest.add(strings[i]);
122:                 }
123:
124:•                for (ILexNameToken name : ctxt.keySet())
125:                 {
126:•                        if (name.getName().equals(rest.get(0)))
127:                         {
128:                                 Value v = ctxt.get(name);
129:•                                if (rest.size() > 1)
130:                                 {
131:                                         return digInVariable(v, rest.subList(1, rest.size()), ctxt);
132:                                 } else
133:                                 {
134:                                         return v;
135:                                 }
136:                         }
137:                 }
138:
139:                 return null;
140:
141:         }
142:
143:         private Value digInVariable(Value value, List<String> rest, Context ctxt)
144:         {
145:
146:                 try
147:                 {
148:                         ObjectValue ov = value.objectValue(ctxt);
149:                         NameValuePairMap nvpm = ov.members;
150:
151:•                        for (ILexNameToken name : nvpm.keySet())
152:                         {
153:•                                if (name.getName().equals(rest.get(0)))
154:                                 {
155:                                         Value v = nvpm.get(name);
156:
157:•                                        if (rest.size() > 1)
158:                                         {
159:                                                 return digInVariable(v, rest.subList(1, rest.size()), ctxt);
160:                                         } else
161:                                         {
162:                                                 return v;
163:                                         }
164:                                 }
165:                         }
166:
167:                 } catch (ValueException e)
168:                 {
169:                         // TODO Auto-generated catch block
170:                         e.printStackTrace();
171:                 }
172:
173:                 return null;
174:         }
175:
176:         private List<String[]> filterVariablesInSystem(String name,
177:                         List<String[]> variables)
178:         {
179:•                for (int i = 0; i < variables.size(); i++)
180:                 {
181:
182:•                        if (!variables.get(i)[0].equals(name))
183:                         {
184:                                 variables.remove(i);
185:                                 i--;
186:                         }
187:
188:                 }
189:                 return variables;
190:         }
191:
192:         public void validateAsync(OperationValue op, AsyncThread t)
193:         {
194:•                if (conjectures.size() > 0)
195:                 {
196:
197:•                        for (ConjectureDefinition conj : conjectures)
198:                         {
199:                                 conj.process(op.name.getName(), op.classdef.getName().getName(), MessageType.Request, SystemClock.getWallTime(), t.getId(), t.getObject().objectReference);
200:                         }
201:                 }
202:
203:         }
204:
205:         public String stop()
206:         {
207:
208:                 StringBuffer sb = new StringBuffer();
209:
210:•                for (ConjectureDefinition cj : conjectures)
211:                 {
212:                         sb.append(cj.getLogFormat());
213:                 }
214:                 return sb.toString();
215:         }
216:
217:         public List<ConjectureDefinition> getConjectures()
218:         {
219:                 return this.conjectures;
220:         }
221:
222: }