Derive-C
Loading...
Searching...
No Matches
debug.h File Reference
#include <stdio.h>
#include <derive-c/core/debug/fmt.h>
#include <derive-c/core/namespace.h>
#include <derive-c/core/require.h>
#include <derive-c/core/std/reflect.h>

Go to the source code of this file.

Macros

#define DC_TRAIT_DEBUGABLE(SELF)
 The debug trait Inspired by rust's {:?} pretty print, any data structure can be dumped to a stream.
#define NO_DEBUG   PRIV(no_debug)
#define _DC_DERIVE_DEBUG_MEMBER(MEMBER_TYPE, MEMBER_NAME)
#define DC_DERIVE_DEBUG(TYPE)
#define _DERIVE_STD_DEBUG(TYPE, FMT, ...)
#define _DC_DEFAULT_DEBUG_CASE(TYPE, _, x)
#define _DC_DEFAULT_DEBUG(SELF, FMT, STREAM)
#define DC_DEFAULT_DEBUG   _DC_DEFAULT_DEBUG

Functions

static void PRIV no_debug (void const *self, dc_debug_fmt fmt, FILE *stream)
static void dc_string_debug (char const *const *string, dc_debug_fmt fmt, FILE *stream)

Macro Definition Documentation

◆ _DC_DEFAULT_DEBUG

#define _DC_DEFAULT_DEBUG ( SELF,
FMT,
STREAM )
Value:
_Generic(*(SELF), \
default: PRIV(no_debug))(SELF, FMT, STREAM);
#define _DC_DEFAULT_DEBUG_CASE(TYPE, _, x)
Definition debug.h:75
static void PRIV no_debug(void const *self, dc_debug_fmt fmt, FILE *stream)
Definition debug.h:22
static void dc_string_debug(char const *const *string, dc_debug_fmt fmt, FILE *stream)
Definition debug.h:49
#define PRIV(name)
Definition namespace.h:6
#define DC_STD_REFLECT(F,...)
Definition reflect.h:11
#define SELF
Definition def.h:52

Definition at line 79 of file debug.h.

79 #define _DC_DEFAULT_DEBUG(SELF, FMT, STREAM) \
80 _Generic(*(SELF), \
81 DC_STD_REFLECT(_DC_DEFAULT_DEBUG_CASE, f) char const*: dc_string_debug, \
82 default: PRIV(no_debug))(SELF, FMT, STREAM);

◆ _DC_DEFAULT_DEBUG_CASE

#define _DC_DEFAULT_DEBUG_CASE ( TYPE,
_,
x )
Value:
TYPE: \
NS(TYPE, debug),
static void debug(SELF const *self, dc_debug_fmt fmt, FILE *stream)
Definition template.h:62

Definition at line 75 of file debug.h.

75 #define _DC_DEFAULT_DEBUG_CASE(TYPE, _, x) \
76 TYPE: \
77 NS(TYPE, debug),

◆ _DC_DERIVE_DEBUG_MEMBER

#define _DC_DERIVE_DEBUG_MEMBER ( MEMBER_TYPE,
MEMBER_NAME )
Value:
dc_debug_fmt_print(fmt, stream, STRINGIFY(MEMBER_NAME) ": "); \
NS(MEMBER_TYPE, debug)(&self->MEMBER_NAME, fmt, stream); \
fprintf(fmt, stream, ",\n");
static void dc_debug_fmt_print(dc_debug_fmt fmt, FILE *stream, const char *format,...)
Definition fmt.h:22
#define STRINGIFY(MACRO)
Definition namespace.h:7
static FILE * stream(SELF *self)
Opens a file for.
Definition template.h:107

Definition at line 28 of file debug.h.

28#define _DC_DERIVE_DEBUG_MEMBER(MEMBER_TYPE, MEMBER_NAME) \
29 dc_debug_fmt_print(fmt, stream, STRINGIFY(MEMBER_NAME) ": "); \
30 NS(MEMBER_TYPE, debug)(&self->MEMBER_NAME, fmt, stream); \
31 fprintf(fmt, stream, ",\n");

◆ _DERIVE_STD_DEBUG

#define _DERIVE_STD_DEBUG ( TYPE,
FMT,
... )
Value:
static void NS(TYPE, debug)(TYPE const* self, dc_debug_fmt fmt, FILE* stream) { \
(void)fmt; \
fprintf(stream, FMT, *self); \
}
#define NS(pre, post)
Definition namespace.h:4
Debug format helpers for debug printin data structures.
Definition fmt.h:10

Definition at line 41 of file debug.h.

41#define _DERIVE_STD_DEBUG(TYPE, FMT, ...) \
42 static void NS(TYPE, debug)(TYPE const* self, dc_debug_fmt fmt, FILE* stream) { \
43 (void)fmt; \
44 fprintf(stream, FMT, *self); \
45 }

◆ DC_DEFAULT_DEBUG

#define DC_DEFAULT_DEBUG   _DC_DEFAULT_DEBUG

Definition at line 85 of file debug.h.

◆ DC_DERIVE_DEBUG

#define DC_DERIVE_DEBUG ( TYPE)
Value:
static TYPE NS(TYPE, DEBUG)(TYPE const* self, dc_debug_fmt fmt, FILE* stream) { \
fprintf(stream, STRINGIFY(TYPE) "@%p {\n", self); \
NS(TYPE, REFLECT)(_DC_DERIVE_DEBUG_MEMBER); \
fmt = dc_debug_fmt_scope_end(fmt); \
}
#define _DC_DERIVE_DEBUG_MEMBER(MEMBER_TYPE, MEMBER_NAME)
Definition debug.h:28
dc_debug_fmt dc_debug_fmt_scope_end(dc_debug_fmt fmt)
Definition fmt.h:39
dc_debug_fmt dc_debug_fmt_scope_begin(dc_debug_fmt fmt)
Definition fmt.h:33

Definition at line 33 of file debug.h.

33#define DC_DERIVE_DEBUG(TYPE) \
34 static TYPE NS(TYPE, DEBUG)(TYPE const* self, dc_debug_fmt fmt, FILE* stream) { \
35 fprintf(stream, STRINGIFY(TYPE) "@%p {\n", self); \
36 fmt = dc_debug_fmt_scope_begin(fmt); \
37 NS(TYPE, REFLECT)(_DC_DERIVE_DEBUG_MEMBER); \
38 fmt = dc_debug_fmt_scope_end(fmt); \
39 }

◆ DC_TRAIT_DEBUGABLE

#define DC_TRAIT_DEBUGABLE ( SELF)
Value:
DC_REQUIRE_METHOD(void, SELF, debug, (SELF const*, dc_debug_fmt fmt, FILE*));
#define DC_REQUIRE_METHOD(ret, obj, name, args)
Definition require.h:17

The debug trait Inspired by rust's {:?} pretty print, any data structure can be dumped to a stream.

  • For debugging (not display) (so contains ptr information, internals)
  • Prints the types (so users can cross reference)
  • Print allocators (for debugging memory issues)
  • Overrideable per data structure

Definition at line 17 of file debug.h.

17#define DC_TRAIT_DEBUGABLE(SELF) \
18 DC_REQUIRE_METHOD(void, SELF, debug, (SELF const*, dc_debug_fmt fmt, FILE*));

◆ NO_DEBUG

#define NO_DEBUG   PRIV(no_debug)

Definition at line 20 of file debug.h.

Function Documentation

◆ dc_string_debug()

void dc_string_debug ( char const *const * string,
dc_debug_fmt fmt,
FILE * stream )
static

Definition at line 49 of file debug.h.

49 {
50 (void)fmt;
51 fprintf(stream, "char*@%p \"%s\"", *string, *string);
52}

◆ no_debug()

void PRIV no_debug ( void const * self,
dc_debug_fmt fmt,
FILE * stream )
static

Definition at line 22 of file debug.h.

22 {
23 (void)self;
24 (void)fmt;
25 fprintf(stream, "(no debug provided)");
26}