lang: add diagnostic definitions
This commit is contained in:
@@ -11,5 +11,5 @@ else ()
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_include_directories(ivy-lang PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
target_include_directories(ivy-lang PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
||||||
target_link_libraries(ivy-lang mie ivy-common Bluelib::Core Bluelib::Object Bluelib::Term)
|
target_link_libraries(ivy-lang mie ivy-diag ivy-common Bluelib::Core Bluelib::Object Bluelib::Term)
|
||||||
target_compile_definitions(ivy-lang PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC})
|
target_compile_definitions(ivy-lang PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC})
|
||||||
|
|||||||
26
lang/diag.c
Normal file
26
lang/diag.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include <ivy/diag.h>
|
||||||
|
#include <ivy/lang/diag.h>
|
||||||
|
|
||||||
|
#define ERROR_CLASS(id, title) \
|
||||||
|
[id] = {.c_type = IVY_DIAG_ERROR, .c_title = (title)}
|
||||||
|
|
||||||
|
#define MSG(id, content) [id] = {.msg_content = (content)}
|
||||||
|
|
||||||
|
static const struct ivy_diag_class diag_classes[] = {
|
||||||
|
ERROR_CLASS(IVY_LANG_E_UNRECOGNISED_SYMBOL, "Unrecognised symbol"),
|
||||||
|
};
|
||||||
|
static const size_t nr_diag_classes = sizeof diag_classes / sizeof diag_classes[0];
|
||||||
|
|
||||||
|
static const struct ivy_diag_msg diag_msg[] = {
|
||||||
|
MSG(IVY_LANG_MSG_UNKNOWN_SYMBOL_ENCOUNTERED,
|
||||||
|
"encountered a symbol that is not part of the Ivy syntax."),
|
||||||
|
};
|
||||||
|
static const size_t nr_diag_msg = sizeof diag_msg / sizeof diag_msg[0];
|
||||||
|
|
||||||
|
enum ivy_status ivy_lang_diag_ctx_init(struct ivy_diag_ctx *ctx)
|
||||||
|
{
|
||||||
|
ivy_diag_ctx_set_class_definitions(ctx, diag_classes, nr_diag_msg);
|
||||||
|
ivy_diag_ctx_set_msg_definitions(ctx, diag_msg, nr_diag_msg);
|
||||||
|
|
||||||
|
return IVY_OK;
|
||||||
|
}
|
||||||
20
lang/include/ivy/lang/diag.h
Normal file
20
lang/include/ivy/lang/diag.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef IVY_LANG_DIAG_H_
|
||||||
|
#define IVY_LANG_DIAG_H_
|
||||||
|
|
||||||
|
#include <ivy/misc.h>
|
||||||
|
|
||||||
|
struct ivy_diag_ctx;
|
||||||
|
|
||||||
|
enum ivy_lang_diag_code {
|
||||||
|
IVY_LANG_E_NONE = 0,
|
||||||
|
IVY_LANG_E_UNRECOGNISED_SYMBOL,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ivy_lang_diag_msg {
|
||||||
|
IVY_LANG_MSG_NONE = 0,
|
||||||
|
IVY_LANG_MSG_UNKNOWN_SYMBOL_ENCOUNTERED,
|
||||||
|
};
|
||||||
|
|
||||||
|
IVY_API enum ivy_status ivy_lang_diag_ctx_init(struct ivy_diag_ctx *ctx);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user