Cthulhu  0.2.10
Cthulhu compiler collection
actions.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 #include "base/panic.h"
3 #include "json_actions.h"
4 
5 #include "interop/actions.h"
6 
7 void json_action(json_where_t *where, const char *text, size_t length)
8 {
9  flex_action(&where->where, text);
10  where->offset += length;
11 }
12 
13 void json_init(json_where_t *where)
14 {
15  flex_init(&where->where);
16  where->offset = 0;
17 }
18 
19 // TODO: some of this could be deduplicated with flex_update
20 void json_update(json_where_t *where, const json_where_t *offsets, int steps)
21 {
22  CTASSERT(where != NULL);
23  CTASSERT(offsets != NULL);
24 
25  if (steps)
26  {
27  json_where_t rhs1 = offsets[1];
28  json_where_t rhsn = offsets[steps];
29 
30  where_t tmp = {
31  .first_line = rhs1.where.first_line,
32  .first_column = rhs1.where.first_column,
33  .last_line = rhsn.where.last_line,
34  .last_column = rhsn.where.last_column,
35  };
36 
37  where->where = tmp;
38  }
39  else
40  {
41  json_where_t rhs = offsets[0];
42  where_t tmp = where->where;
43  tmp.last_line = rhs.where.last_line;
44  tmp.last_column = rhs.where.last_column;
45 
46  // TODO: is this correct?
47  where->where = tmp;
48  }
49 }
void json_init(json_where_t *where)
Definition: actions.c:13
void json_action(json_where_t *where, const char *text, size_t length)
Definition: actions.c:7
void json_update(json_where_t *where, const json_where_t *offsets, int steps)
Definition: actions.c:20
CT_INTEROP_API void flex_action(INOUT_NOTNULL where_t *where, const char *text)
tracks the current source position
CT_INTEROP_API void flex_init(OUT_NOTNULL where_t *where)
initialize source location tracking
#define CTASSERT(expr)
assert a condition, prints the condition as a message
Definition: panic.h:130
size_t offset
Definition: json_scan.h:19
where_t where
Definition: json_scan.h:20
a location inside a scanner locations are inclusive and 0-based
Definition: where.h:23
ctu_column_t first_column
the first column of the location
Definition: where.h:31
ctu_column_t last_column
the last column of the location
Definition: where.h:34
ctu_line_t last_line
the last line of the location
Definition: where.h:28
ctu_line_t first_line
the first line of the location
Definition: where.h:25