File: Exception.cpp

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 (122 lines) | stat: -rw-r--r-- 3,968 bytes parent folder | download
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
#include "stdafx.h"
#include "Exception.h"
#include "Type.h"
#include "Core/Str.h"

namespace storm {

	Str *CodeError::messageText() const {
		StrBuf *buf = new (this) StrBuf();
		messageText(buf);
		return buf->toS();
	}

	CodeError::CodeError(SrcPos where) : pos(where) {}

	void CodeError::message(StrBuf *to) const {
		*to << S("@") << pos << S(": ");
		messageText(to);
	}

	LangDefError::LangDefError(const wchar *msg) {
		w = new (this) Str(msg);
	}

	LangDefError::LangDefError(Str *msg) : w(msg) {}

	void LangDefError::message(StrBuf *to) const {
		*to << w;
	}

	DebugError::DebugError() {
		saveTrace();
	}

	void DebugError::message(StrBuf *to) const {
		*to << S("Debug error");
	}

	InternalTypeError::InternalTypeError(const wchar *context, Type *expected, Type *got) :
		InternalError(TO_S(engine(), context << S(": expected ") << expected->identifier()
									<< S(", got ") << (got ? got->identifier() : new (engine()) Str(S("null"))))) {}

	InternalTypeError::InternalTypeError(Str *context, Type *expected, Type *got) :
		InternalError(TO_S(engine(), context << S(": expected ") << expected->identifier()
									<< S(", got ") << (got ? got->identifier() : new (engine()) Str(S("null"))))) {}


	LookupError::LookupError(Str *msg) : CodeError(SrcPos()), msg(msg) {}

	LookupError::LookupError(SrcPos pos, Str *msg) : CodeError(pos), msg(msg) {}

	void LookupError::messageText(StrBuf *to) const {
		*to << S("Name lookup error: ") << msg;
	}

	SyntaxError::SyntaxError(SrcPos where, const wchar *msg) :
		CodeError(where), text(new (engine()) Str(msg)) {}

	SyntaxError::SyntaxError(SrcPos where, Str *msg) :
		CodeError(where), text(msg) {}

	void SyntaxError::messageText(StrBuf *to) const {
		*to << S("Syntax error: ") << text;
	}

	TypeError::TypeError(SrcPos where, const wchar *msg) : CodeError(where), msg(new (engine()) Str(msg)) {}
	TypeError::TypeError(SrcPos where, Str *msg) : CodeError(where), msg(msg) {}
	TypeError::TypeError(SrcPos where, Value expected, ExprResult got)
		: CodeError(where),
		  msg(TO_S(engine(), S("Expected ") << expected << S(" but got ") << got)) {}
	TypeError::TypeError(SrcPos where, Value expected, Value got)
		: CodeError(where),
		  msg(TO_S(engine(), S("Expected ") << expected << S(" but got ") << got)) {}

	void TypeError::messageText(StrBuf *to) const {
		*to << S("Type error: ") << msg;
	}

	TypedefError::TypedefError(SrcPos pos, const wchar *msg) : CodeError(pos), msg(new (engine()) Str(msg)) {}
	TypedefError::TypedefError(SrcPos pos, Str *msg) : CodeError(pos), msg(msg) {}

	void TypedefError::messageText(StrBuf *to) const {
		*to << S("Type definition error: ") << msg;
	}

	BuiltInError::BuiltInError(const wchar *msg) {
		this->msg = new (this) Str(msg);
		saveTrace();
	}

	BuiltInError::BuiltInError(Str *msg) : msg(msg) {
		saveTrace();
	}

	void BuiltInError::message(StrBuf *to) const {
		*to << S("Error while loading built in functions: ") << msg;
	}

	InstantiationError::InstantiationError(SrcPos pos, const wchar *msg) : CodeError(pos), msg(new (engine()) Str(msg)) {}
	InstantiationError::InstantiationError(SrcPos pos, Str *msg) : CodeError(pos), msg(msg) {}

	void InstantiationError::messageText(StrBuf *to) const {
		*to << S("Instantiation error: ") << msg;
	}

	ReplaceError::ReplaceError(SrcPos pos, const wchar *msg) : CodeError(pos), msg(new (engine()) Str(msg)) {}
	ReplaceError::ReplaceError(SrcPos pos, Str *msg) : CodeError(pos), msg(msg) {}

	void ReplaceError::messageText(StrBuf *to) const {
		*to << S("Replace error: ") << msg;
	}

	ActiveReplaceError::ActiveReplaceError(CodeError *src, Named *entity)
		: ReplaceError(src->pos, S("")), original(src), entity(entity) {}

	void ActiveReplaceError::messageText(StrBuf *to) const {
		*to << S("Replacement error: failed to update invocations of ") << entity->identifier()
			<< S(" due to the error below. Fix the error and update again to replace the function.\n");
		original->messageText(to);
	}

}