Cthulhu  0.2.10
Cthulhu compiler collection
scan.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 
3 #pragma once
4 
5 #include <ctu_scan_api.h>
6 
7 #include "core/analyze.h"
8 #include "core/compiler.h"
9 #include "core/text.h"
10 
11 #include <stddef.h>
12 #include <stdbool.h>
13 
14 typedef struct io_t io_t;
15 typedef struct arena_t arena_t;
16 
18 
21 
23 typedef struct scan_t
24 {
27  io_t *io;
28 
31 
34 
37 
39  STA_FIELD_STRING const char *path;
40 
42  void *tree;
43 
45  void *context;
46 
49 } scan_t;
50 
51 #define CT_SCAN_BUILTIN_NAME "<builtin>"
56 
63 CT_SCAN_API const char *scan_language(IN_NOTNULL const scan_t *scan);
64 
71 CT_SCAN_API const char *scan_path(IN_NOTNULL const scan_t *scan);
72 
79 CT_SCAN_API void *scan_get(IN_NOTNULL scan_t *scan);
80 
85 CT_SCAN_API void scan_set(IN_NOTNULL scan_t *scan, void *value);
86 
91 CT_SCAN_API void scan_set_context(IN_NOTNULL scan_t *scan, void *value);
92 
99 CT_SCAN_API void *scan_get_context(IN_NOTNULL const scan_t *scan);
100 
107 CT_SCAN_API text_view_t scan_source(IN_NOTNULL const scan_t *scan);
108 
115 CT_SCAN_API arena_t *scan_get_arena(IN_NOTNULL const scan_t *scan);
116 
125 CT_SCAN_API size_t scan_read(
126  IN_NOTNULL scan_t *scan,
127  STA_WRITES(size) void *dst,
128  size_t size);
129 
138 CT_SCAN_API scan_t *scan_io(
139  IN_STRING const char *language,
140  IN_NOTNULL io_t *io,
141  IN_NOTNULL arena_t *arena);
142 
150 CT_SCAN_API scan_t *scan_builtin(IN_STRING const char *language, IN_NOTNULL arena_t *arena);
151 
158 CT_SCAN_API bool scan_is_builtin(IN_NOTNULL const scan_t *scan);
159 
161 
CT_NODISCARD CT_PUREFN CT_SCAN_API const char * scan_path(const scan_t *scan)
get the path of a scanner
Definition: scan.c:56
CT_NODISCARD CT_PUREFN CT_SCAN_API void * scan_get(scan_t *scan)
get the compiled object from a scanner
Definition: scan.c:72
CT_SCAN_API void scan_set(scan_t *scan, void *value)
set the compiled object of a scanner
Definition: scan.c:64
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_SCAN_API scan_t * scan_io(const char *language, io_t *io, arena_t *arena)
create a scanner from an io source
Definition: scan.c:121
CT_NODISCARD STA_RET_RANGE(0, size) CT_NOALIAS CT_SCAN_API size_t scan_read(scan_t *scan
read data from a scanner
CT_NODISCARD CT_PUREFN CT_SCAN_API const char * scan_language(const scan_t *scan)
get the source language of a scanner
Definition: scan.c:48
CT_SCAN_API void scan_set_context(scan_t *scan, void *value)
get the context of a scanner
Definition: scan.c:80
CT_NODISCARD CT_SCAN_API scan_t * scan_builtin(const char *language, arena_t *arena)
create a builtin scanner
Definition: scan.c:33
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 CT_PUREFN CT_SCAN_API text_view_t scan_source(const scan_t *scan)
get a text span of the scanners contents
Definition: scan.c:96
CT_NODISCARD STA_WRITES(size) void *dst
CT_NODISCARD size_t size
Definition: scan.h:128
CT_NODISCARD CT_PUREFN CT_SCAN_API bool scan_is_builtin(const scan_t *scan)
check if a scanner is the builtin scanner
Definition: scan.c:41
STA_DECL CT_NOALIAS size_t scan_read(scan_t *scan, void *dst, size_t size)
Definition: scan.c:104
#define CT_PUREFN
mark a function as pure, always returns the same value for the same arguments
Definition: analyze.h:228
#define STA_FIELD_STRING
annotate a field as being a null terminated string
#define CT_NODISCARD
mark a function as returning a value that must be used
#define IN_NOTNULL
annotate a parameter as not being null
#define IN_STRING
annotate a parameter as being a null terminated string
#define CT_NOALIAS
mark a function as only modifying pointers passed to it the same as CT_CONSTFN but allowed to modify/...
Definition: analyze.h:226
#define CT_BEGIN_API
Definition: compiler.h:129
#define CT_END_API
Definition: compiler.h:130
an allocator object
Definition: arena.h:86
io object implementation
Definition: impl.h:122
a source file scanner
Definition: scan.h:24
void * tree
the tree generated by a language parser
Definition: scan.h:42
void * context
the parser data to use
Definition: scan.h:45
io_t * io
the backing io object
Definition: scan.h:27
STA_FIELD_STRING const char * language
the name of the language this file contains
Definition: scan.h:36
STA_FIELD_STRING const char * path
the path to this file
Definition: scan.h:39
arena_t * arena
the allocator to use
Definition: scan.h:30
arena_t * nodes
arena to use when allocating nodes
Definition: scan.h:33
text_view_t mapped
the text of the file
Definition: scan.h:48
a non-owning view of text
Definition: text.h:24