2#define REDUCT_ERROR_H 1
22#define REDUCT_ERROR_MAX_LEN 128
23#define REDUCT_ERROR_BACKTRACE_MAX 8
29typedef enum reduct_error_type
44typedef struct reduct_error_frame
54typedef struct reduct_error
75#define REDUCT_ERROR() ((reduct_error_t){0})
122 const char** input,
size_t* inputLength,
size_t* regionLength,
size_t* position);
159#define REDUCT_ERROR_GENERIC(_reduct, _error, _item, _type, ...) \
162 const char* __path; \
163 const char* __input; \
164 size_t __inputLength; \
165 size_t __regionLength; \
167 reduct_error_get_item_params((_reduct), (_item), &__path, &__input, &__inputLength, &__regionLength, \
169 reduct_error_set((_error), __path, __input, __inputLength, __regionLength, __position, \
170 REDUCT_ERROR_TYPE_##_type, __VA_ARGS__); \
171 longjmp((_error)->jmp, true); \
179#define REDUCT_ERROR_SUCCESS(_error) ((_error)->type == REDUCT_ERROR_TYPE_NONE)
186#define REDUCT_ERROR_CATCH(_error) (setjmp((_error)->jmp))
197#define REDUCT_ERROR_TRY(_reduct, _error) \
198 for (int _once = (reduct_error_push((_reduct), (_error)), 0); _once < 1; (reduct_error_pop(_reduct), _once++)) \
199 if (REDUCT_ERROR_CATCH(_error) == 0)
207#define REDUCT_ERROR_THROW(_reduct, ...) reduct_error_throw_runtime((_reduct), __VA_ARGS__)
215#define REDUCT_ERROR_RETHROW(_reduct, _error) REDUCT_ERROR_THROW(_reduct, "%s", (_error)->message);
224#define REDUCT_ERROR_ASSERT(_reduct, _expr, ...) \
227 if (REDUCT_UNLIKELY(!(_expr))) \
229 REDUCT_ERROR_THROW(_reduct, __VA_ARGS__); \
241#define REDUCT_ERROR_SYNTAX(_error, _input, _ptr, ...) \
244 reduct_error_set((_error), (_input)->path, (_input)->buffer, (_input)->end - (_input)->buffer, 1, \
245 (size_t)((_ptr) - (_input)->buffer), REDUCT_ERROR_TYPE_SYNTAX, __VA_ARGS__); \
246 longjmp((_error)->jmp, true); \
256#define REDUCT_ERROR_COMPILE(_compiler, _handle, ...) \
259 struct reduct_item* __item = REDUCT_HANDLE_TO_ITEM(_handle); \
260 REDUCT_ERROR_GENERIC((_compiler)->reduct, (_compiler)->reduct->error, \
261 (((__item) != NULL && (__item)->inputId != REDUCT_INPUT_ID_NONE) \
263 : ((_compiler)->lastItem != NULL ? (_compiler)->lastItem : (__item))), \
264 COMPILE, __VA_ARGS__); \
274#define REDUCT_ERROR_COMPILE_LAST(_compiler, ...) \
277 reduct_handle_t __handle = REDUCT_HANDLE_FROM_ITEM((_compiler)->lastItem); \
278 REDUCT_ERROR_COMPILE((_compiler), __handle, __VA_ARGS__); \
289#define REDUCT_ERROR_COMPILE_ASSERT(_compiler, _expr, ...) \
292 if (REDUCT_UNLIKELY(!(_expr))) \
294 reduct_handle_t __handle = REDUCT_HANDLE_FROM_ITEM((_compiler)->lastItem); \
295 REDUCT_ERROR_COMPILE((_compiler), __handle, __VA_ARGS__); \
305#define REDUCT_ERROR_INTERNAL(_reduct, ...) REDUCT_ERROR_GENERIC(_reduct, (_reduct)->error, NULL, INTERNAL, __VA_ARGS__)
uint16_t reduct_input_id_t
Identifies a reduct_input_t within a Reduct structure.
REDUCT_API void reduct_error_set(reduct_error_t *error, const char *path, const char *input, size_t inputLength, size_t regionLength, size_t position, reduct_error_type_t type, const char *message,...)
Set the error information in the error structure.
REDUCT_API REDUCT_NORETURN void reduct_error_throw_runtime(struct reduct *reduct, const char *message,...)
Throw a runtime error utilizing the evaluation state to determine the context.
REDUCT_API void reduct_error_push(struct reduct *reduct, reduct_error_t *error)
Push a new error handler onto the stack.
reduct_error_type_t
Error type enumeration.
REDUCT_API void reduct_error_get_item_params(struct reduct *reduct, struct reduct_item *item, const char **path, const char **input, size_t *inputLength, size_t *regionLength, size_t *position)
Get the error parameters from a Reduct item.
REDUCT_API void reduct_error_get_row_column(reduct_error_t *error, size_t *row, size_t *column)
Get the row and column by traversing the input buffer.
REDUCT_API void reduct_error_print(reduct_error_t *error, FILE *file)
Format and print the error to a file.
REDUCT_API void reduct_error_pop(struct reduct *reduct)
Pop the current error handler from the stack.
#define REDUCT_ERROR_BACKTRACE_MAX
Maximum number of backtrace frames.
#define REDUCT_ERROR_MAX_LEN
Maximum length of an error string.
@ REDUCT_ERROR_TYPE_SYNTAX
@ REDUCT_ERROR_TYPE_RUNTIME
@ REDUCT_ERROR_TYPE_INTERNAL
@ REDUCT_ERROR_TYPE_COMPILE
Backtrace frame structure.
reduct_input_id_t inputId
The input ID of the source file.
uint32_t position
The position in the input buffer.
reduct_error_type_t type
The type of the error.
size_t index
The index of the region in the input buffer that caused the error.
size_t regionLength
The length of the region that caused the error.
const char * input
The input buffer.
uint8_t frameCount
The number of backtrace frames.
struct reduct_error * prev
Previous error handler in the stack.
struct reduct * reduct
The owning Reduct structure.
const char * path
The path to the file that caused the error.
size_t inputLength
The total length of the input buffer.