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 {
35 for(
int i = 0; i < indent; ++i) {
40 CUDA
void print_line(
const char* line,
int indent)
const {
51 battery::string<allocator_type> ad_name,
52 battery::string<allocator_type> description,
53 const F2& uninterpretable_formula,
56 ad_name(std::move(ad_name)),
57 description(std::move(description)),
58 uninterpretable_formula(uninterpretable_formula),
64 suberrors.push_back(std::move(suberror));
69 return suberrors.size();
73 CUDA
void cut(
size_t i) {
76 for(
size_t j = 0; j < suberrors.size(); ++j) {
88 CUDA
void merge(
bool succeeded,
size_t i) {
90 assert(i <= suberrors.size());
91 suberrors[i-1].fatal = !succeeded;
92 for(
size_t j = i; j < suberrors.size(); ++j) {
94 if(!succeeded || !suberrors[j].
is_fatal()) {
95 suberrors[i-1].add_suberror(std::move(suberrors[j]));
101 CUDA NI
void print(
int indent = 0)
const {
105 print_line(
"[error] ", indent);
108 print_line(
"[warning] ", indent);
110 print_line(
"Uninterpretable formula.", indent);
111 print_indent(indent);
112 printf(
" Abstract domain: %s\n", ad_name.data());
113 print_line(
" Abstract type: ", indent);
120 print_line(
" Formula: ", indent);
121 uninterpretable_formula.
print(
true);
123 print_indent(indent);
124 printf(
" Description: %s\n", description.data());
129 for(
int i = 0; i < suberrors.size(); ++i) {
130 suberrors[i].print(indent + 2);
137 for(
int i = 0; i < suberrors.size(); ++i) {
146#define INTERPRETATION_ERROR(MSG) \
147 if constexpr(diagnose) { \
148 diagnostics.add_suberror(IDiagnostics(true, name, (MSG), f)); \
151#define INTERPRETATION_WARNING(MSG) \
152 if constexpr(diagnose) { \
153 diagnostics.add_suberror(IDiagnostics(false, name, (MSG), f)); \
156#define RETURN_INTERPRETATION_ERROR(MSG) \
157 INTERPRETATION_ERROR(MSG) \
160#define RETURN_INTERPRETATION_WARNING(MSG) \
161 INTERPRETATION_WARNING(MSG) \
168#define CALL_WITH_ERROR_CONTEXT_WITH_MERGE(MSG, CALL, MERGE) \
169 size_t error_context = 0; \
170 if constexpr(diagnose) { \
171 diagnostics.add_suberror(IDiagnostics(false, name, (MSG), f)); \
172 error_context = diagnostics.num_suberrors(); \
175 if constexpr(diagnose) { \
176 diagnostics.merge(res, error_context); \
181#define CALL_WITH_ERROR_CONTEXT(MSG, CALL) \
182 CALL_WITH_ERROR_CONTEXT_WITH_MERGE(MSG, CALL, {})
Definition diagnostics.hpp:19
CUDA void cut(size_t i)
Definition diagnostics.hpp:73
CUDA NI void print(int indent=0) const
Definition diagnostics.hpp:101
CUDA void merge(bool succeeded, size_t i)
Definition diagnostics.hpp:88
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:50
CUDA bool has_warning() const
Definition diagnostics.hpp:136
CUDA size_t num_suberrors() const
Definition diagnostics.hpp:68
battery::standard_allocator allocator_type
Definition diagnostics.hpp:21
CUDA NI IDiagnostics()
Definition diagnostics.hpp:46
CUDA bool is_fatal() const
Definition diagnostics.hpp:135
CUDA NI this_type & add_suberror(IDiagnostics &&suberror)
Definition diagnostics.hpp:62
Definition abstract_deps.hpp:14
int AType
Definition sort.hpp:18
#define UNTYPED
Definition sort.hpp:21