Cthulhu  0.2.10
Cthulhu compiler collection
context.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #include "cthulhu/broker/scan.h"
4 
6 
7 #include "scan/node.h"
8 #include "scan/scan.h"
9 
10 #include "std/vector.h"
11 
12 #include "core/macros.h"
13 
15 {
16  scan_context_t *ctx = scan_get_context(scan);
17  return ctx->logger;
18 }
19 
21 {
22  scan_context_t *ctx = scan_get_context(scan);
23  return ctx->arena;
24 }
25 
27 {
28  scan_context_t *ctx = scan_get_context(scan);
29  return ctx->string_arena;
30 }
31 
33 {
34  scan_context_t *ctx = scan_get_context(scan);
35  return ctx->ast_arena;
36 }
37 
38 vector_t *ctx_vector_init(void *init, const scan_t *scan)
39 {
40  return vector_init(init, ctx_get_arena(scan));
41 }
42 
43 vector_t *ctx_vector_new(size_t size, const scan_t *scan)
44 {
45  return vector_new(size, ctx_get_arena(scan));
46 }
47 
48 vector_t *ctx_vector_of(size_t size, const scan_t *scan)
49 {
50  return vector_of(size, ctx_get_arena(scan));
51 }
52 
53 void *ctx_get_user(const scan_t *scan)
54 {
55  scan_context_t *ctx = scan_get_context(scan);
56  return ctx->user;
57 }
58 
59 void ctx_error(const where_t *where, const void *state, const scan_t *scan, const char *msg)
60 {
61  CT_UNUSED(state);
62 
63  logger_t *logger = ctx_get_logger(scan);
64  node_t *node = node_new(scan, *where);
65 
66  evt_scan_error(logger, node, msg);
67 }
68 
69 void ctx_unknown_symbol(const scan_t *scan, const where_t *where, const char *msg)
70 {
71  logger_t *logger = ctx_get_logger(scan);
72  node_t *node = node_new(scan, *where);
73 
74  evt_scan_unknown(logger, node, msg);
75 }
vector_t * ctx_vector_of(size_t size, const scan_t *scan)
Definition: context.c:48
void ctx_error(const where_t *where, const void *state, const scan_t *scan, const char *msg)
Definition: context.c:59
void ctx_unknown_symbol(const scan_t *scan, const where_t *where, const char *msg)
Definition: context.c:69
arena_t * ctx_get_arena(const scan_t *scan)
Definition: context.c:20
void * ctx_get_user(const scan_t *scan)
Definition: context.c:53
vector_t * ctx_vector_init(void *init, const scan_t *scan)
Definition: context.c:38
arena_t * ctx_get_string_arena(const scan_t *scan)
Definition: context.c:26
logger_t * ctx_get_logger(const scan_t *scan)
Definition: context.c:14
vector_t * ctx_vector_new(size_t size, const scan_t *scan)
Definition: context.c:43
arena_t * ctx_get_ast_arena(const scan_t *scan)
Definition: context.c:32
CT_NODISCARD CT_PUREFN CT_SCAN_API void * scan_get_context(const scan_t *scan)
get the context of a scanner
Definition: scan.c:88
CT_NODISCARD size_t size
Definition: scan.h:128
CT_EVENTS_API void evt_scan_unknown(logger_t *logger, const node_t *node, const char *msg)
signal that a scanner has encountered an unknown token
Definition: events.c:39
CT_EVENTS_API void evt_scan_error(logger_t *logger, const node_t *node, const char *msg)
signal that a scan error has occurred
Definition: events.c:33
CT_NODISCARD CT_SCAN_API node_t * node_new(const scan_t *scan, where_t where)
create a new node on the heap
Definition: node.c:40
#define CT_UNUSED(x)
mark a variable as unused
Definition: macros.h:46
CT_NODISCARD CT_STD_API vector_t * vector_new(size_t size, arena_t *arena)
create a new vector with an initial capacity
Definition: vector.c:63
CT_NODISCARD CT_STD_API vector_t * vector_of(size_t len, arena_t *arena)
create a new vector with a specified length
Definition: vector.c:71
CT_NODISCARD CT_STD_API vector_t * vector_init(void *value, arena_t *arena)
create a new vector with a single initial value
Definition: vector.c:79
an allocator object
Definition: arena.h:86
a logging sink
Definition: notify.c:14
a position in a source file
Definition: node.h:23
arena_t * ast_arena
Definition: scan.h:24
logger_t * logger
Definition: scan.h:20
char user[]
Definition: scan.h:26
arena_t * arena
Definition: scan.h:22
arena_t * string_arena
Definition: scan.h:23
a source file scanner
Definition: scan.h:24
a generic vector of pointers
Definition: vector.c:16
a location inside a scanner locations are inclusive and 0-based
Definition: where.h:23