-
-
Notifications
You must be signed in to change notification settings - Fork 230
/
mod_jam_errors.h
206 lines (152 loc) · 5.09 KB
/
mod_jam_errors.h
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
Copyright 2022 René Ferdinand Rivera Morell
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
*/
#ifndef B2_MOD_JAM_ERRORS_H
#define B2_MOD_JAM_ERRORS_H
#include "config.h"
#include "bind.h"
#include "lists.h"
#include "value.h"
#include <tuple>
/* tag::reference[]
[[b2.reference.modules.errors]]
= `errors` module.
end::reference[] */
namespace b2 { namespace jam { namespace errors {
/* tag::reference[]
== `b2::jam::errors::backtrace`
====
[horizontal]
Jam:: `rule backtrace ( skip-frames prefix messages * : * )`
{CPP}:: `void backtrace(std::tuple<int, std::string, list_ref>
skip_prefix_messages, const lists & rest, bind::context_ref_ context_ref);`
====
Print a stack backtrace leading to this rule's caller. Each argument
represents a line of output to be printed after the first line of the
backtrace.
end::reference[] */
void backtrace(std::tuple<int, std::string, list_ref> skip_prefix_messages,
const lists & rest,
bind::context_ref_ context_ref);
/* tag::reference[]
== `b2::jam::errors::error_skip_frames`
====
[horizontal]
Jam:: `rule error-skip-frames ( skip-frames messages * : * )`
{CPP}:: `void error_skip_frames(std::tuple<int, list_ref> skip_messages, const
lists & rest, bind::context_ref_ context_ref);`
====
end::reference[] */
void error_skip_frames(std::tuple<int, list_ref> skip_messages,
const lists & rest,
bind::context_ref_ context_ref);
/* tag::reference[]
== `b2::jam::errors::try-catch`
====
[horizontal]
Jam:: `rule error-skip-frames ( skip-frames messages * : * )`
{CPP}:: `void error_skip_frames(std::tuple<int, list_ref> skip_messages, const
lists & rest, bind::context_ref_ context_ref);`
====
This is not really an exception-handling mechanism, but it does allow us to
perform some error-checking on our error-checking. Errors are suppressed
after a try, and the first one is recorded. Use catch to check that the
error message matched expectations.
====
[horizontal]
Jam:: `rule try ( )`
{CPP}:: `void error_try();`
====
Begin looking for error messages.
====
[horizontal]
Jam:: `rule catch ( messages * : * )`
{CPP}:: `void error_catch(const lists & rest, bind::context_ref_ context_ref);`
====
Stop looking for error messages; generate an error if an argument of
messages is not found in the corresponding argument in the error call.
end::reference[] */
void error_try();
void error_catch(const lists & rest, bind::context_ref_ context_ref);
/* tag::reference[]
== `b2::jam::errors::error`
====
[horizontal]
Jam:: `rule error ( messages * : * )`
{CPP}:: `void error(const lists & rest, bind::context_ref_ context_ref);`
====
Print an error message with a stack backtrace and exit.
end::reference[] */
void error(const lists & rest, bind::context_ref_ context_ref);
/* tag::reference[]
== `b2::jam::errors::user_error`
====
[horizontal]
Jam:: `rule user-error ( messages * : * )`
{CPP}:: `void user_error(const lists & rest, bind::context_ref_ context_ref);`
====
Same as 'error', but the generated backtrace will include only user files.
end::reference[] */
void user_error(const lists & rest, bind::context_ref_ context_ref);
/* tag::reference[]
== `b2::jam::errors::warning`
====
[horizontal]
Jam:: `rule warning ( messages * : * )`
{CPP}:: `void warning(const lists & rest, bind::context_ref_ context_ref);`
====
Print a warning message with a stack backtrace and exit.
end::reference[] */
void warning(const lists & rest, bind::context_ref_ context_ref);
/* tag::reference[]
== `b2::jam::errors::lol_to_list`
====
[horizontal]
Jam:: `rule lol->list ( * )`
{CPP}:: `list_ref lol_to_list(const lists & rest);`
====
Convert an arbitrary argument list into a list with ":" separators and quoted
elements representing the same information. This is mostly useful for
formatting descriptions of arguments with which a rule was called when
reporting an error.
end::reference[] */
list_ref lol_to_list(const lists & rest);
/* tag::reference[]
== `b2::jam::errors::nearest_user_location`
====
[horizontal]
Jam:: `rule nearest-user-location ( )`
{CPP}:: `list_ref nearest_user_location(bind::context_ref_ context_ref);`
====
Return the file:line for the nearest entry in backtrace which correspond to a
user module.
end::reference[] */
list_ref nearest_user_location(bind::context_ref_ context_ref);
struct errors_module : b2::bind::module_<errors_module>
{
const char * module_name = "errors";
static const char * init_code;
template <class Binder>
void def(Binder & binder)
{
binder
.def(&backtrace, "backtrace",
("skip-frames" * _1 + "prefix" * _1 + "messages" * _n)
| ("rest" * _r))
.def(&error_skip_frames, "error-skip-frames",
("skip-frames" * _1 + "messages" * _n) | ("rest" * _r))
.def(&error_try, "try")
.def(&error_catch, "catch", "messages" * _r)
.def(&error, "error", "messages" * _r)
.def(&user_error, "user-error", "messages" * _r)
.def(&warning, "warning", "messages" * _r)
.def(&nearest_user_location, "nearest-user-location")
.def(&lol_to_list, "lol->list", "rest" * _r);
binder.eval(init_code);
binder.loaded();
}
};
}}} // namespace b2::jam::errors
#endif