Package: VDMUtil

VDMUtil

nameinstructionbranchcomplexitylinemethod
VDMUtil()
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%
classname(Value)
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
seq_of_char2val_(Value)
M: 110 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 23 C: 0
0%
M: 1 C: 0
0%
set2seq(Value)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
val2seq_of_char(Value)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: import org.overture.ast.expressions.PExp;
2: import org.overture.ast.lex.Dialect;
3: import org.overture.interpreter.runtime.Context;
4: import org.overture.interpreter.runtime.Interpreter;
5: import org.overture.interpreter.runtime.ValueException;
6: import org.overture.interpreter.runtime.VdmRuntime;
7: import org.overture.interpreter.values.BooleanValue;
8: import org.overture.interpreter.values.CharacterValue;
9: import org.overture.interpreter.values.NilValue;
10: import org.overture.interpreter.values.ObjectValue;
11: import org.overture.interpreter.values.SeqValue;
12: import org.overture.interpreter.values.TupleValue;
13: import org.overture.interpreter.values.Value;
14: import org.overture.interpreter.values.ValueList;
15: import org.overture.interpreter.values.ValueSet;
16: import org.overture.parser.lex.LexTokenReader;
17: import org.overture.parser.syntax.ExpressionReader;
18:
19: /*******************************************************************************
20: * Copyright (C) 2008, 2009 Fujitsu Services Ltd. Author: Nick Battle This file is part of VDMJ. VDMJ is free software:
21: * you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free
22: * Software Foundation, either version 3 of the License, or (at your option) any later version. VDMJ is distributed in
23: * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a
25: * copy of the GNU General Public License along with VDMJ. If not, see <a href="http://www.gnu.org/licenses/">gnu license</a>.
26: ******************************************************************************/
27:
28: // This must be in the default package to work with VDMJ's native delegation.
29:
30: public class VDMUtil
31: {
32:         public static Value set2seq(Value arg) throws ValueException
33:         {
34:                 ValueSet set = arg.setValue(null);
35:                 ValueList list = new ValueList();
36:                 list.addAll(set);
37:                 return new SeqValue(list);
38:         }
39:
40:         public static Value val2seq_of_char(Value arg)
41:         {
42:                 return new SeqValue(arg.toString());
43:         }
44:
45:         public static Value seq_of_char2val_(Value arg)
46:         {
47:                 ValueList result = new ValueList();
48:
49:                 try
50:                 {
51:                         SeqValue seq = (SeqValue) arg.deref();
52:                         StringBuilder expression = new StringBuilder();
53:
54:•                        for (Value v : seq.values)
55:                         {
56:                                 CharacterValue ch = (CharacterValue) v.deref();
57:                                 expression.append(ch.unicode);
58:                         }
59:
60:                         LexTokenReader ltr = new LexTokenReader(expression.toString(), Dialect.VDM_PP);
61:                         ExpressionReader reader = new ExpressionReader(ltr);
62:                         reader.setCurrentModule("VDMUtil");
63:                         PExp exp = reader.readExpression();
64:                         Interpreter ip = Interpreter.getInstance();
65:                         ip.typeCheck(exp, ip.getGlobalEnvironment());
66:
67:                         result.add(new BooleanValue(true));
68:                         Context ctxt = new Context(Interpreter.getInstance().getAssistantFactory(), null, "seq_of_char2val_", null);
69:                         ctxt.setThreadState(null, null);
70:                         result.add(exp.apply(VdmRuntime.getExpressionEvaluator(), ctxt));
71:                 } catch (Exception e)
72:                 {
73:                         result = new ValueList();
74:                         result.add(new BooleanValue(false));
75:                         result.add(new NilValue());
76:                 }
77:
78:                 return new TupleValue(result);
79:         }
80:
81:         public static Value classname(Value arg)
82:         {
83:                 Value a = arg.deref();
84:
85:•                if (a instanceof ObjectValue)
86:                 {
87:                         ObjectValue obj = (ObjectValue) a;
88:                         return new SeqValue(obj.type.getName().getName());
89:                 } else
90:                 {
91:                         return new NilValue();
92:                 }
93:         }
94: }