BFC-Compiler
A C23 Brainfuck compiler
Loading...
Searching...
No Matches
bfc_error.h File Reference

Compiler error values and diagnostics. More...

#include "bfc_token.h"

Go to the source code of this file.

Data Structures

struct  bfc_error_t
 Error value propagated through compiler stages. More...

Macros

#define COL_OFF   "\033[m"
#define COL_INFO   "\033[1;1m"
#define COL_ERROR   "\033[1;31m"
#define ERROR_LIST
 Single source of truth for compiler error codes.
#define X(name)
#define BFC_ERR_OK   ((bfc_error_t) {.code = ERR_OK, .msg = {0}, .token = {0}})
#define BFC_ERR_ALLOC   ((bfc_error_t) {.code = ERR_ALLOC, .msg = "Memory allocation failure!", .token = {0}})

Enumerations

enum  bfc_err_code_t { ERROR_LIST }

Functions

bfc_error_t bfc_make_errorf (bfc_err_code_t error_code, const char *format,...)
 Creates an error using printf-style formatting.
bfc_error_t bfc_make_errorf_with_token (bfc_err_code_t error_code, bfc_token_t token, const char *format,...)
 Creates a source-associated formatted error.
bfc_error_t bfc_make_error (bfc_err_code_t const error_code, char const *msg)
 Creates an error by copying an existing message string.
bfc_error_t bfc_make_error_with_token (bfc_err_code_t const error_code, char const *msg, bfc_token_t const token)
 Creates a token-associated error by copying an existing message string.
char const * bfc_get_error_code (bfc_err_code_t const error_code)
 Returns the symbolic name of an error code.
void bfc_log_error (bfc_error_t err, const struct bfc_program_t *program)
 Prints a user-facing compiler diagnostic to standard error.

Detailed Description

Compiler error values and diagnostics.

Defines error codes, formatted error constructors, source-associated errors, and user-facing diagnostic output.

Macro Definition Documentation

◆ ERROR_LIST

#define ERROR_LIST
Value:
X(ERR_OK) \
X(ERR_ARGS) \
X(ERR_IO) \
X(ERR_MISMATCHED_BRACKET) \
X(ERR_MISSING_BRACKET) \
X(ERR_ALLOC) \
X(ERR_INTERNAL)

Single source of truth for compiler error codes.

◆ X

#define X ( name)
Value:
name,

Function Documentation

◆ bfc_get_error_code()

char const * bfc_get_error_code ( bfc_err_code_t const error_code)
nodiscard

Returns the symbolic name of an error code.

Maps an error enumeration value to its symbolic name.

Returns
A pointer to a static null-terminated string.

Returns the symbolic name of an error code.

◆ bfc_log_error()

void bfc_log_error ( bfc_error_t const err,
const struct bfc_program_t *const program )

Prints a user-facing compiler diagnostic to standard error.

Prints a colourized diagnostic and optional source-line context.

Parameters
[in]errError to report.
[in]programLoaded source program, used for source-context diagnostics.

Prints a user-facing compiler diagnostic to standard error.

◆ bfc_make_error()

bfc_error_t bfc_make_error ( bfc_err_code_t const error_code,
char const * msg )

Creates an error by copying an existing message string.

Builds an error by copying a plain message.

Creates an error by copying an existing message string.

◆ bfc_make_error_with_token()

bfc_error_t bfc_make_error_with_token ( bfc_err_code_t const error_code,
char const * msg,
bfc_token_t const token )

Creates a token-associated error by copying an existing message string.

Builds a token-associated error by copying a plain message.

Creates a token-associated error by copying an existing message string.

◆ bfc_make_errorf()

bfc_error_t bfc_make_errorf ( bfc_err_code_t error_code,
const char * format,
... )

Creates an error using printf-style formatting.

Builds a formatted error without source-token context.

Parameters
[in]error_codeError category.
[in]formatFormat string followed by matching arguments.
Returns
A fully initialized error value.

Creates an error using printf-style formatting.

◆ bfc_make_errorf_with_token()

bfc_error_t bfc_make_errorf_with_token ( bfc_err_code_t error_code,
bfc_token_t token,
const char * format,
... )

Creates a source-associated formatted error.

Builds a formatted error associated with a source token.

Parameters
[in]error_codeError category.
[in]tokenSource token associated with the failure.
[in]formatFormat string followed by matching arguments.
Returns
A fully initialized error value.

Creates a source-associated formatted error.