json-gen-c  0.1.5
json-gen-c generate C code for json manipulation
diag.h
Go to the documentation of this file.
1
12#ifndef DIAG_H_
13#define DIAG_H_
14
15#include <stdio.h>
16
17#if defined(__clang__) || defined(__GNUC__)
18#define DIAG_PRINTF_FORMAT(fmt_index, first_arg) \
19 __attribute__((format(printf, fmt_index, first_arg)))
20#else
21#define DIAG_PRINTF_FORMAT(fmt_index, first_arg)
22#endif
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
30 DIAG_ERROR,
31 DIAG_WARNING,
32 DIAG_NOTE
33};
34
36struct diag_entry {
37 enum diag_severity severity;
38 int line;
39 int col;
40 char *message;
41};
42
45 const char *filename;
46 const char *source; /* source content (not owned) */
47 long source_len;
48 struct diag_entry *entries;
49 int count;
50 int capacity;
51 int error_count;
52 int warning_count;
53 int max_errors; /* stop collecting after this many errors */
54};
55
63struct diag_engine *diag_engine_new(const char *filename, const char *source,
64 long source_len);
65
69void diag_engine_free(struct diag_engine *engine);
70
79void diag_emit(struct diag_engine *engine, enum diag_severity severity,
80 int line, int col, const char *fmt, ...)
81 DIAG_PRINTF_FORMAT(5, 6);
82
87void diag_print_all(struct diag_engine *engine, FILE *stream);
88
92int diag_has_errors(struct diag_engine *engine);
93
97int diag_error_count(struct diag_engine *engine);
98
99#ifdef __cplusplus
100}
101#endif
102
103#endif /* DIAG_H_ */
void diag_engine_free(struct diag_engine *engine)
Free a diagnostic engine and all its entries.
Definition diag.c:54
int diag_has_errors(struct diag_engine *engine)
Check if any errors were emitted.
Definition diag.c:223
int diag_error_count(struct diag_engine *engine)
Get the number of errors emitted.
Definition diag.c:228
void diag_emit(struct diag_engine *engine, enum diag_severity severity, int line, int col, const char *fmt,...) DIAG_PRINTF_FORMAT(5
Emit a diagnostic message.
struct diag_engine * diag_engine_new(const char *filename, const char *source, long source_len)
Create a new diagnostic engine.
Definition diag.c:30
diag_severity
Definition diag.h:29
void void diag_print_all(struct diag_engine *engine, FILE *stream)
Print all accumulated diagnostics to a stream. Uses ANSI colors if stream is a terminal.
Definition diag.c:160
Definition diag.h:44
Definition diag.h:36