File: Exception.h

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (142 lines) | stat: -rw-r--r-- 3,084 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma once
#include "Var.h"
#include "Block.h"
#include "Core/Exception.h"

namespace code {
	STORM_PKG(core.asm);

	// Base for all exceptions in the Code backend.
	class EXCEPTION_EXPORT CodeError : public storm::Exception {
		STORM_EXCEPTION;
	public:
		STORM_CTOR CodeError() {
			saveTrace();
		}
	};

	// Thrown when an instruction contains invalid data for some reason.
	class EXCEPTION_EXPORT InvalidValue : public CodeError {
		STORM_EXCEPTION;
	public:
		InvalidValue(const wchar *what) {
			error = new (engine()) Str(what);
		}
		STORM_CTOR InvalidValue(Str *what) {
			error = what;
		}
		virtual void STORM_FN message(StrBuf *to) const {
			*to << S("Invalid value: ") << error;
		}

	private:
		Str *error;
	};

	class EXCEPTION_EXPORT BlockBeginError : public CodeError {
		STORM_EXCEPTION;
	public:
		STORM_CTOR BlockBeginError() {
			msg = new (engine()) Str(S("The parent scope must be entered before a child scope."));
		}
		STORM_CTOR BlockBeginError(Str *msg) {
			this->msg = msg;
		}
		virtual void STORM_FN message(StrBuf *to) const {
			*to << msg;
		}
	private:
		Str *msg;
	};

	class EXCEPTION_EXPORT BlockEndError : public CodeError {
		STORM_EXCEPTION;
	public:
		STORM_CTOR BlockEndError() {
			msg = new (engine()) Str(S("The scope is not the topmost active scope."));
		}
		BlockEndError(Str *msg) {
			this->msg = msg;
		}
		virtual void STORM_FN message(StrBuf *to) const {
			*to << msg;
		}
	private:
		Str *msg;
	};

	class EXCEPTION_EXPORT FrameError : public CodeError {
		STORM_EXCEPTION;
	public:
		STORM_CTOR FrameError() {}
		virtual void STORM_FN message(StrBuf *to) const {
			*to << S("Trying to use an invalid block or variable.");
		}
	};

	class EXCEPTION_EXPORT DuplicateLabelError : public CodeError {
		STORM_EXCEPTION;
	public:
		STORM_CTOR DuplicateLabelError(Nat id) {
			this->id = id;
		}

		Nat id;

		virtual void STORM_FN message(StrBuf *to) const {
			*to << S("Duplicate usage of label ") << id << S(".");
		}
	};

	class EXCEPTION_EXPORT UnusedLabelError : public CodeError {
		STORM_EXCEPTION;
	public:
		STORM_CTOR UnusedLabelError(Nat id) {
			this->id = id;
		}

		Nat id;

		virtual void STORM_FN message(StrBuf *to) const {
			*to << S("Use of undefined label ") << id << S(".");
		}
	};

	class EXCEPTION_EXPORT VariableUseError : public CodeError {
		STORM_EXCEPTION;
	public:
		STORM_CTOR VariableUseError(Var v, Block b) {
			var = v;
			block = b;
		}

		Var var;
		Block block;

		virtual void STORM_FN message(StrBuf *to) const {
			*to << S("Trying to use ") << var << S(" in ") << block << S(", where it is not accessible.");
		}
	};

	class EXCEPTION_EXPORT VariableActivationError : public CodeError {
		STORM_EXCEPTION;
	public:
		VariableActivationError(Var v, const wchar *msg) {
			this->var = v;
			this->msg = new (this) Str(msg);
		}

		STORM_CTOR VariableActivationError(Var v, Str *msg) {
			this->var = v;
			this->msg = msg;
		}

		Var var;
		Str *msg;

		virtual void STORM_FN message(StrBuf *to) const {
			*to << S("Error activating the variable ") << var << S(": ") << msg;
		}
	};
}