-
Notifications
You must be signed in to change notification settings - Fork 5
/
error.py
99 lines (71 loc) · 2.15 KB
/
error.py
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
from enum import Enum
class VerboseLevel(Enum):
NONE = 0
CURR_ONLY = 1
FULL = 2
# flag for displaying uniquified names
unique_names = False
def set_unique_names(b):
global unique_names
unique_names = b
def get_unique_names():
global unique_names
return unique_names
# flag for verbose trace
verbose = False
def set_verbose(b):
global verbose
verbose = b
def get_verbose():
global verbose
if verbose == VerboseLevel.NONE:
return False
return verbose
# flag for expect fail
expect_fail_flag = False
def expect_fail():
return expect_fail_flag
def set_expect_fail(b):
global expect_fail_flag
expect_fail_flag = b
# flag for expect static_fail
expect_static_fail_flag = False
def expect_static_fail():
return expect_static_fail_flag
def set_expect_static_fail(b):
global expect_static_fail_flag
expect_static_fail_flag = b
def error_header(location):
# seeing a strange error where some Meta objects don't have a line member.
if hasattr(location, 'line'):
return '{file}:{line1}.{column1}-{line2}.{column2}: ' \
.format(file=location.filename,
line1=location.line, column1=location.column,
line2=location.end_line, column2=location.end_column)
def warning(location, msg):
if not expect_fail():
header = '{file}:{line1}.{column1}-{line2}.{column2}: ' \
.format(file=location.filename,
line1=location.line, column1=location.column,
line2=location.end_line, column2=location.end_column)
print(header + 'warning: ' + msg)
def error(location, msg):
raise Exception(error_header(location) + msg)
class IncompleteProof(Exception):
pass
def incomplete_error(location, msg):
raise IncompleteProof(error_header(location) + msg)
def last_error(location, msg):
e = Exception(error_header(location) + msg)
e.last = True
raise e
def missing_error(location, msg):
e = Exception(error_header(location) + msg)
e.missing = True
raise e
def warning(location, msg):
print(error_header(location) + msg)
class StaticError(Exception):
pass
def static_error(location, msg):
raise StaticError(error_header(location) + msg)