Cthulhu  0.2.10
Cthulhu compiler collection
node.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/where.h"
9 
10 #include "scan/scan.h"
11 
12 #include <stdbool.h>
13 
15 
20 
22 typedef struct node_t
23 {
25  const scan_t *scan;
26 
29 } node_t;
30 
32 CT_SCAN_API extern const where_t kNowhere;
33 
40 CT_SCAN_API const scan_t *node_get_scan(IN_NOTNULL const node_t *node);
41 
48 CT_SCAN_API where_t node_get_location(IN_NOTNULL const node_t *node);
49 
55 CT_SCAN_API void node_init(OUT_NOTNULL node_t *node, IN_NOTNULL const scan_t *scan, where_t where);
56 
64 CT_SCAN_API node_t *node_new(IN_NOTNULL const scan_t *scan, where_t where);
65 
73 CT_SCAN_API node_t node_make(IN_NOTNULL const scan_t *scan, where_t where);
74 
83 CT_SCAN_API node_t *node_builtin(
84  IN_STRING const char *name,
85  IN_NOTNULL arena_t *arena);
86 
93 CT_SCAN_API bool node_is_builtin(IN_NOTNULL const node_t *node);
94 
96 
typedefCT_BEGIN_API struct node_t node_t
Definition: notify.h:19
#define CT_PUREFN
mark a function as pure, always returns the same value for the same arguments
Definition: analyze.h:228
#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 OUT_NOTNULL
Definition: analyze.h:99
#define CT_BEGIN_API
Definition: compiler.h:129
#define CT_END_API
Definition: compiler.h:130
CT_NODISCARD CT_SCAN_API node_t * node_builtin(const char *name, arena_t *arena)
get the builtin node node used for drivers that declare builtin symbols
Definition: node.c:11
CT_NODISCARD CT_PUREFN CT_SCAN_API const scan_t * node_get_scan(const node_t *node)
get the associated source file of a node
Definition: node.c:57
CT_NODISCARD CT_PUREFN CT_SCAN_API bool node_is_builtin(const node_t *node)
check if a node is the builtin node
Definition: node.c:23
CT_NODISCARD CT_PUREFN CT_SCAN_API where_t node_get_location(const node_t *node)
get the location of a node inside its source file
Definition: node.c:65
CT_SCAN_API void node_init(OUT_NOTNULL node_t *node, const scan_t *scan, where_t where)
initialize a source node
CT_SCAN_API const where_t kNowhere
nowhere in a source file
Definition: node.c:8
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
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
an allocator object
Definition: arena.h:86
a position in a source file
Definition: node.h:23
const scan_t * scan
the scanner that this node is in
Definition: node.h:25
where_t where
the location of this node
Definition: node.h:28
a source file scanner
Definition: scan.h:24
a location inside a scanner locations are inclusive and 0-based
Definition: where.h:23