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

Error construction and diagnostic rendering. More...

#include "bfc_error.h"
#include <inttypes.h>
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "bfc_io.h"

Macros

#define X(name)

Functions

bfc_error_t bfc_make_errorf (bfc_err_code_t error_code, const char *format,...)
 Builds a formatted error without source-token context.
bfc_error_t bfc_make_errorf_with_token (bfc_err_code_t error_code, bfc_token_t token, const char *format,...)
 Builds a formatted error associated with a source token.
bfc_error_t bfc_make_error (bfc_err_code_t const error_code, char const *msg)
 Builds an error by copying a plain message.
bfc_error_t bfc_make_error_with_token (bfc_err_code_t const error_code, char const *msg, bfc_token_t const token)
 Builds a token-associated error by copying a plain message.
char const * bfc_get_error_code (bfc_err_code_t const error_code)
 Maps an error enumeration value to its symbolic name.
void bfc_log_error (bfc_error_t const err, const struct bfc_program_t *const program)
 Prints a colourized diagnostic and optional source-line context.

Detailed Description

Error construction and diagnostic rendering.

Formats compiler errors and prints source-context diagnostics for bracket failures.

Macro Definition Documentation

◆ X

#define X ( name)
Value:
case name: { \
return #name; \
} \
break;

Function Documentation

◆ bfc_get_error_code()

char const * bfc_get_error_code ( bfc_err_code_t const error_code)
nodiscard

Maps an error enumeration value to its symbolic name.

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.

◆ bfc_log_error()

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

Prints a colourized diagnostic and optional source-line context.

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.

◆ bfc_make_error()

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

Builds an error by copying a plain message.

Creates an error by copying an existing message string.

Builds an error by copying a plain message.

◆ 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 )

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

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

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

◆ bfc_make_errorf()

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

Builds a formatted error without source-token context.

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.

◆ 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,
... )

Builds a formatted error associated with a source token.

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.