Cthulhu  0.2.10
Cthulhu compiler collection
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
query_scan.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 #include "query_scan.h"
3 
4 #include "core/macros.h"
6 #include "cthulhu/util/text.h"
7 
9 {
10  return (query_scan_t *)scan_get_context(scan);
11 }
12 
13 void query_parse_integer(mpz_t integer, scan_t *scan, where_t where, const char *text, int base)
14 {
15  int result = mpz_init_set_str(integer, text, base);
16  if (result != 0)
17  {
18  query_scan_t *ctx = query_scan_context(scan);
19  node_t node = node_make(scan, where);
20  msg_notify(ctx->reports, &kEvent_InvalidIntegerLiteral, &node, "invalid integer literal");
21  }
22 }
23 
24 void query_parse_string(text_t *string, scan_t *scan, where_t where, const char *text, size_t length)
25 {
26  query_scan_t *ctx = query_scan_context(scan);
27  arena_t *arena = scan_get_arena(scan);
28  node_t node = node_make(scan, where);
29  *string = util_text_escape(ctx->reports, &node, text, length, arena);
30 }
31 
32 void queryerror(where_t *where, void *state, scan_t *scan, const char *msg)
33 {
34  CT_UNUSED(state);
35 
36  query_scan_t *ctx = query_scan_context(scan);
37 
38  node_t node = node_make(scan, *where);
39  evt_scan_error(ctx->reports, &node, msg);
40 }
CT_NODISCARD CT_PUREFN CT_SCAN_API arena_t * scan_get_arena(const scan_t *scan)
get the arena of a scanner
Definition: scan.c:113
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_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_make(const scan_t *scan, where_t where)
create a new node on the stack
Definition: node.c:49
#define CT_UNUSED(x)
mark a variable as unused
Definition: macros.h:46
CT_NOTIFY_API event_builder_t msg_notify(INOUT_NOTNULL logger_t *logs, const diagnostic_t *diagnostic, const node_t *node, STA_FORMAT_STRING const char *fmt,...)
notify the logger of a new message
CT_BEGIN_API CT_UTIL_API text_t util_text_escape(logger_t *reports, const node_t *node, STA_READS(length) const char *text, size_t length, arena_t *arena)
escape a string literal into a string
void query_parse_string(text_t *string, scan_t *scan, where_t where, const char *text, size_t length)
Definition: query_scan.c:24
void query_parse_integer(mpz_t integer, scan_t *scan, where_t where, const char *text, int base)
Definition: query_scan.c:13
void queryerror(where_t *where, void *state, scan_t *scan, const char *msg)
Definition: query_scan.c:32
query_scan_t * query_scan_context(scan_t *scan)
Definition: query_scan.c:8
an allocator object
Definition: arena.h:86
a position in a source file
Definition: node.h:23
logger_t * reports
Definition: query_scan.h:14
a source file scanner
Definition: scan.h:24
a range of text
Definition: text.h:14
a location inside a scanner locations are inclusive and 0-based
Definition: where.h:23