-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompileException.cs
119 lines (108 loc) · 4.25 KB
/
CompileException.cs
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
using System;
namespace IL
{
public class CompileException : Exception
{
public string MessageEssence { get; }
public CompileException(string message) :
base("Error while compiling: " + message)
{ MessageEssence = message; }
public CompileException(string message, Exception inner) :
base("Error while compiling: " + message, inner)
{ MessageEssence = message; }
}
public class ParserException : CompileException
{
public delegate ParserException Factory(string at, string message);
public ParserException(string at, string message) :
base("cannot parse expression at " + at + ": " + message) { }
public ParserException(string at, string message, Exception inner) :
base("cannot parse expression at " + at + ": " + message, inner) { }
}
public class UnexpectedTokenException : ParserException
{
public UnexpectedTokenException(string at, string message) :
base(at, "unexpected token: " + message) { }
}
public class UnrecognizedTokenException : ParserException
{
public UnrecognizedTokenException(string at, string message) :
base(at, "unrecognized token: " + message) { }
}
public class UnrecognizedStatementException : ParserException
{
public UnrecognizedStatementException(string at, string message) :
base(at, "unrecognized statement: " + message) { }
}
public class TypeMismatchException : CompileException
{
public Type ExpectedType { get; }
public Type GotType { get; }
public string FunctionName { get; }
public TypeMismatchException(string funcName, string message, Type expected, Type got) :
base(
"type mismatch for " + funcName + (message == "" ? "" : "(" + message + ")") +
": expected '" + expected.Name +
"', got '" + got.Name + "'"
)
{
ExpectedType = expected;
GotType = got;
FunctionName = funcName;
}
}
public class TypeMismatchParserException : ParserException
{
public Type ExpectedType { get; }
public Type GotType { get; }
public string FunctionName { get; }
public TypeMismatchParserException(string at, TypeMismatchException other) :
base(at, other.MessageEssence, other)
{
ExpectedType = other.ExpectedType;
GotType = other.GotType;
FunctionName = other.FunctionName;
}
}
public class ArgumentsNumberMismatchException : CompileException
{
public int ExpectedArgumentsNumber { get; }
public int GotArgumentsNumber { get; }
public string FunctionName { get; }
public ArgumentsNumberMismatchException(string funcName, int expected, int got) :
base(
"arguments number mismatch for " + funcName +
": expected '" + expected +
"', got '" + got + "'"
)
{
ExpectedArgumentsNumber = expected;
GotArgumentsNumber = got;
FunctionName = funcName;
}
}
public class ArgumentsNumberMismatchParserException : ParserException
{
public int ExpectedArgumentsNumber { get; }
public int GotArgumentsNumber { get; }
public string FunctionName { get; }
public ArgumentsNumberMismatchParserException(
string at,
ArgumentsNumberMismatchException other
) : base(at, other.MessageEssence, other)
{
ExpectedArgumentsNumber = other.ExpectedArgumentsNumber;
GotArgumentsNumber = other.GotArgumentsNumber;
FunctionName = other.FunctionName;
}
}
public class UnsupportedIdentifierException : ParserException
{
public string Identifier { get; }
public UnsupportedIdentifierException(string at, string identifier, string message) :
base(at, "unsupported identifier '" + identifier + "' (" + message + ")")
{
Identifier = identifier;
}
}
}