1 /********************************************************************************
2 *
3 * Copyright (c) 2008 Fujitsu Services Ltd.
4 *
5 * Author: Nick Battle
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.overturetool.vdmj.statements;
25
26 import java.io.Serializable;
27
28 import org.overturetool.vdmj.lex.LexLocation;
29 import org.overturetool.vdmj.runtime.Context;
30 import org.overturetool.vdmj.runtime.ContextException;
31 import org.overturetool.vdmj.runtime.ValueException;
32 import org.overturetool.vdmj.typechecker.Environment;
33 import org.overturetool.vdmj.typechecker.TypeChecker;
34 import org.overturetool.vdmj.types.Type;
35 import org.overturetool.vdmj.values.Value;
36
37 /***
38 * The root of the state designator hierarchy.
39 */
40
41 public abstract class StateDesignator implements Serializable
42 {
43 private static final long serialVersionUID = 1L;
44
45 public final LexLocation location;
46
47 public StateDesignator(LexLocation location)
48 {
49 this.location = location;
50 }
51
52 @Override
53 abstract public String toString();
54
55 abstract public Type typeCheck(Environment env);
56
57 abstract public Value eval(Context ctxt);
58
59 public void abort(int number, String msg, Context ctxt)
60 {
61 throw new ContextException(number, msg, location, ctxt);
62 }
63
64 public Value abort(ValueException ve)
65 {
66 throw new ContextException(ve, location);
67 }
68
69 public void report(int number, String msg)
70 {
71 TypeChecker.report(number, msg, location);
72 }
73
74 public void concern(boolean serious, int number, String msg)
75 {
76 if (serious)
77 {
78 TypeChecker.report(number, msg, location);
79 }
80 else
81 {
82 TypeChecker.warning(number, msg, location);
83 }
84 }
85
86 public void detail(String tag, Object obj)
87 {
88 TypeChecker.detail(tag, obj);
89 }
90
91 public void detail2(String tag1, Object obj1, String tag2, Object obj2)
92 {
93 TypeChecker.detail2(tag1, obj1, tag2, obj2);
94 }
95 }