Cthulhu  0.2.10
Cthulhu compiler collection
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
notify.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #pragma once
4 
5 #include <ctu_notify_api.h>
6 
7 #include "core/analyze.h"
8 #include "core/compiler.h"
9 
10 #include "scan/node.h"
11 
12 #include "notify/diagnostic.h"
13 
14 #include <stdarg.h>
15 #include <stdbool.h>
16 
18 
19 typedef struct node_t node_t;
20 typedef struct typevec_t typevec_t;
21 typedef struct vector_t vector_t;
22 typedef struct arena_t arena_t;
23 typedef struct set_t set_t;
24 
29 
31 typedef struct logger_t logger_t;
32 
35 typedef struct event_t
36 {
39 
42 
45 
49 
53 } event_t;
54 
56 typedef struct segment_t
57 {
60 
63 } segment_t;
64 
67 typedef struct event_builder_t
68 {
71 
75 
77 typedef struct notify_rules_t
78 {
82 
88 
93 CT_NOTIFY_API logger_t *logger_new(IN_NOTNULL arena_t *arena);
94 
101 CT_NOTIFY_API typevec_t *logger_get_events(IN_NOTNULL const logger_t *logs);
102 
110 CT_NOTIFY_API bool logger_has_errors(IN_NOTNULL const logger_t *logs, notify_rules_t rules);
111 
116 CT_NOTIFY_API void logger_reset(IN_NOTNULL logger_t *logs);
117 
119 CT_NOTIFY_API arena_t *logger_get_arena(IN_NOTNULL const logger_t *logs);
120 
131 STA_PRINTF(4, 5)
133  INOUT_NOTNULL logger_t *logs,
134  IN_NOTNULL const diagnostic_t *diagnostic,
135  const node_t *node,
136  STA_FORMAT_STRING const char *fmt, ...);
137 
148  INOUT_NOTNULL logger_t *logs,
149  IN_NOTNULL const diagnostic_t *diagnostic,
150  const node_t *node,
151  IN_STRING const char *fmt, va_list args);
152 
159 STA_PRINTF(3, 4)
160 CT_NOTIFY_API void msg_append(
161  event_builder_t builder,
162  const node_t *node,
163  STA_FORMAT_STRING const char *fmt, ...);
164 
171 CT_NOTIFY_API void msg_vappend(
172  event_builder_t builder,
173  const node_t *node,
174  IN_STRING const char *fmt, va_list args);
175 
181 STA_PRINTF(2, 3)
182 CT_NOTIFY_API void msg_note(
183  event_builder_t builder,
184  STA_FORMAT_STRING const char *fmt, ...);
185 
191 CT_NOTIFY_API void msg_vnote(
192  event_builder_t builder,
193  IN_STRING const char *fmt, va_list args);
194 
196 
#define RET_NOTNULL
annotate the return value as not being null
#define STA_FIELD_STRING
annotate a field as being a null terminated string
#define CT_NODISCARD
mark a function as returning a value that must be used
#define STA_PRINTF(a, b)
mark a function as a printf style function
Definition: analyze.h:165
#define IN_NOTNULL
annotate a parameter as not being null
#define STA_FORMAT_STRING
mark a function parameter as a printf format string
#define INOUT_NOTNULL
Definition: analyze.h:101
#define IN_STRING
annotate a parameter as being a null terminated string
#define CT_BEGIN_API
Definition: compiler.h:129
#define CT_END_API
Definition: compiler.h:130
CT_NOTIFY_API event_builder_t msg_notify(INOUT_NOTNULL logger_t *logs, const diagnostic_t *diagnostic, const node_t *node, STA_FORMAT_STRING const char *fmt,...)
notify the logger of a new message
CT_NOTIFY_API void logger_reset(logger_t *logs)
reset the loggers messages
Definition: notify.c:89
CT_NODISCARD CT_NOTIFY_API bool logger_has_errors(const logger_t *logs, notify_rules_t rules)
check if the logger has any fatal errors
Definition: notify.c:44
CT_NOTIFY_API void msg_append(event_builder_t builder, const node_t *node, STA_FORMAT_STRING const char *fmt,...)
append additional information to a message
CT_NODISCARD CT_NOTIFY_API arena_t * logger_get_arena(const logger_t *logs)
Definition: notify.c:97
CT_NOTIFY_API event_builder_t msg_vnotify(INOUT_NOTNULL logger_t *logs, const diagnostic_t *diagnostic, const node_t *node, const char *fmt, va_list args)
notify the logger of a new message
CT_NODISCARD CT_NOTIFY_API logger_t * logger_new(arena_t *arena)
create a new logger
Definition: notify.c:21
CT_NOTIFY_API void msg_vnote(event_builder_t builder, const char *fmt, va_list args)
add a note to an existing message
Definition: notify.c:193
CT_NOTIFY_API void msg_vappend(event_builder_t builder, const node_t *node, const char *fmt, va_list args)
append additional information to a message
Definition: notify.c:158
CT_NOTIFY_API void msg_note(event_builder_t builder, STA_FORMAT_STRING const char *fmt,...)
add a note to an existing message
CT_NODISCARD CT_NOTIFY_API typevec_t * logger_get_events(const logger_t *logs)
get the events from the logger
Definition: notify.c:36
CT_NODISCARD STA_FORMAT_STRING const char * fmt
Definition: str.h:68
typedefCT_BEGIN_API struct event_t event_t
Definition: notify2.h:14
an allocator object
Definition: arena.h:86
a diagnostic
Definition: diagnostic.h:27
an event builder handles adding additional information to an event
Definition: notify.h:68
arena_t * arena
allocation context
Definition: notify.h:73
event_t * event
the event to append to
Definition: notify.h:70
an event handle TODO: make this and segment_t opaque
Definition: notify.h:36
node_t node
the primary node that this event is attached to
Definition: notify.h:41
const diagnostic_t * diagnostic
the related diagnostic
Definition: notify.h:38
vector_t * notes
extra notes that this event is attached to
Definition: notify.h:52
STA_FIELD_STRING char * message
the primary message
Definition: notify.h:44
typevec_t * segments
extra segments that this event is attached to
Definition: notify.h:48
a logging sink
Definition: notify.c:14
a position in a source file
Definition: node.h:23
a set of rules for filtering notifications
Definition: notify.h:78
set_t * warnings_as_errors
the set of warnings to treat as errors
Definition: notify.h:81
set_t * ignored_warnings
the set of warnings to ignore this takes precedence over warnings_as_errors
Definition: notify.h:86
a segment inside an event
Definition: notify.h:57
node_t node
the related node
Definition: notify.h:59
STA_FIELD_STRING char * message
the message associated with this segment
Definition: notify.h:62
an unordered hash set
Definition: set.c:19
A vector with a fixed type size.
Definition: vector.h:24
a generic vector of pointers
Definition: vector.c:16