diag.c (893B)
1 /* Varargs convenience over the host DiagSink.emit vtable slot. */ 2 3 #include "core/diag.h" 4 5 #include <stdarg.h> 6 7 void diag_emit(DiagSink* s, DiagKind k, SrcLoc loc, const char* fmt, ...) { 8 va_list ap; 9 va_start(ap, fmt); 10 diag_emitv(s, k, loc, fmt, ap); 11 va_end(ap); 12 } 13 14 void diag_emitv(DiagSink* s, DiagKind k, SrcLoc loc, const char* fmt, 15 va_list ap) { 16 /* Count before emitting: a FATAL sink that longjmps out of emit must still 17 * leave the error reflected in the counter. */ 18 if (s) { 19 if (k == DIAG_WARN) 20 s->warnings++; 21 else if (k == DIAG_ERROR || k == DIAG_FATAL) 22 s->errors++; 23 } 24 if (s && s->emit) s->emit(s, k, loc, fmt, ap); 25 } 26 27 void kit_ctx_diagf(const KitContext* ctx, const char* fmt, ...) { 28 va_list ap; 29 if (!ctx || !ctx->diag) return; 30 va_start(ap, fmt); 31 diag_emitv(ctx->diag, DIAG_ERROR, SRCLOC_NONE, fmt, ap); 32 va_end(ap); 33 }