3#ifndef LALA_CORE_IDIAGNOSTICS_HPP
4#define LALA_CORE_IDIAGNOSTICS_HPP
6#include "battery/utility.hpp"
7#include "battery/vector.hpp"
8#include "battery/string.hpp"
9#include "battery/string.hpp"
10#include "battery/tuple.hpp"
11#include "battery/variant.hpp"
26 battery::string<allocator_type> ad_name;
27 battery::string<allocator_type> description;
28 F uninterpretable_formula;
30 battery::vector<IDiagnostics, allocator_type> suberrors;
33 CUDA
void print_indent(
int indent)
const {
34 for(
int i = 0; i < indent; ++i) {
39 CUDA
void print_line(
const char* line,
int indent)
const {
50 battery::string<allocator_type> ad_name,
51 battery::string<allocator_type> description,
52 const F2& uninterpretable_formula,
55 ad_name(std::move(ad_name)),
56 description(std::move(description)),
57 uninterpretable_formula(uninterpretable_formula),
63 suberrors.push_back(std::move(suberror));
68 return suberrors.size();
72 CUDA
void cut(
size_t i) {
75 for(
size_t j = 0; j < suberrors.size(); ++j) {
87 CUDA
void merge(
bool succeeded,
size_t i) {
89 assert(i <= suberrors.size());
90 suberrors[i-1].fatal = !succeeded;
91 for(
size_t j = i; j < suberrors.size(); ++j) {
93 if(!succeeded || !suberrors[j].
is_fatal()) {
94 suberrors[i-1].add_suberror(std::move(suberrors[j]));
100 CUDA NI
void print(
int indent = 0)
const {
104 print_line(
"[error] ", indent);
107 print_line(
"[warning] ", indent);
109 printf(
"Uninterpretable formula.\n");
110 print_indent(indent);
111 printf(
" Abstract domain: %s\n", ad_name.data());
112 print_line(
" Abstract type: ", indent);
119 print_line(
" Formula: ", indent);
120 uninterpretable_formula.
print(
true);
122 print_indent(indent);
123 printf(
" Description: %s\n", description.data());
128 for(
int i = 0; i < suberrors.size(); ++i) {
129 suberrors[i].print(indent + 2);
136 for(
int i = 0; i < suberrors.size(); ++i) {
145#define INTERPRETATION_ERROR(MSG) \
146 if constexpr(diagnose) { \
147 diagnostics.add_suberror(IDiagnostics(true, name, (MSG), f)); \
150#define INTERPRETATION_WARNING(MSG) \
151 if constexpr(diagnose) { \
152 diagnostics.add_suberror(IDiagnostics(false, name, (MSG), f)); \
155#define RETURN_INTERPRETATION_ERROR(MSG) \
156 INTERPRETATION_ERROR(MSG) \
159#define RETURN_INTERPRETATION_WARNING(MSG) \
160 INTERPRETATION_WARNING(MSG) \
167#define CALL_WITH_ERROR_CONTEXT_WITH_MERGE(MSG, CALL, MERGE) \
168 size_t error_context = 0; \
169 if constexpr(diagnose) { \
170 diagnostics.add_suberror(IDiagnostics(false, name, (MSG), f)); \
171 error_context = diagnostics.num_suberrors(); \
174 if constexpr(diagnose) { \
175 diagnostics.merge(res, error_context); \
180#define CALL_WITH_ERROR_CONTEXT(MSG, CALL) \
181 CALL_WITH_ERROR_CONTEXT_WITH_MERGE(MSG, CALL, {})
Definition diagnostics.hpp:19
CUDA void cut(size_t i)
Definition diagnostics.hpp:72
CUDA NI void print(int indent=0) const
Definition diagnostics.hpp:100
CUDA void merge(bool succeeded, size_t i)
Definition diagnostics.hpp:87
CUDA NI IDiagnostics(bool fatal, battery::string< allocator_type > ad_name, battery::string< allocator_type > description, const F2 &uninterpretable_formula, AType aty=UNTYPED)
Definition diagnostics.hpp:49
CUDA bool has_warning() const
Definition diagnostics.hpp:135
CUDA size_t num_suberrors() const
Definition diagnostics.hpp:67
battery::standard_allocator allocator_type
Definition diagnostics.hpp:21
CUDA NI IDiagnostics()
Definition diagnostics.hpp:45
CUDA bool is_fatal() const
Definition diagnostics.hpp:134
CUDA NI this_type & add_suberror(IDiagnostics &&suberror)
Definition diagnostics.hpp:61
Definition abstract_deps.hpp:14
int AType
Definition sort.hpp:18
#define UNTYPED
Definition sort.hpp:21