• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nickg / nvc / 12854971287

19 Jan 2025 03:39PM UTC coverage: 92.194% (+0.002%) from 92.192%
12854971287

push

github

nickg
Implement PSL prev() built-in function. Fixes #1135

48 of 53 new or added lines in 3 files covered. (90.57%)

419 existing lines in 12 files now uncovered.

64159 of 69591 relevant lines covered (92.19%)

508771.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.03
/src/tree.c
1
//
2
//  Copyright (C) 2011-2025  Nick Gasson
3
//
4
//  This program is free software: you can redistribute it and/or modify
5
//  it under the terms of the GNU General Public License as published by
6
//  the Free Software Foundation, either version 3 of the License, or
7
//  (at your option) any later version.
8
//
9
//  This program is distributed in the hope that it will be useful,
10
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
//  GNU General Public License for more details.
13
//
14
//  You should have received a copy of the GNU General Public License
15
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
//
17

18
#include "tree.h"
19
#include "util.h"
20
#include "object.h"
21
#include "common.h"
22

23
#include <assert.h>
24
#include <stdlib.h>
25
#include <string.h>
26
#include <ctype.h>
27

28
static const imask_t has_map[T_LAST_TREE_KIND] = {
29
   // T_ENTITY
30
   (I_IDENT | I_PORTS | I_GENERICS | I_CONTEXT | I_DECLS | I_STMTS | I_PRAGMAS),
31

32
   // T_ARCH
33
   (I_IDENT | I_IDENT2 | I_DECLS | I_STMTS | I_CONTEXT | I_PRIMARY | I_PRAGMAS),
34

35
   // T_PORT_DECL
36
   (I_IDENT | I_VALUE | I_TYPE | I_SUBKIND | I_CLASS | I_FLAGS),
37

38
   // T_FCALL
39
   (I_IDENT | I_PARAMS | I_TYPE | I_REF | I_FLAGS),
40

41
   // T_LITERAL
42
   (I_SUBKIND | I_TYPE | I_IVAL | I_DVAL | I_IDENT | I_REF),
43

44
   // T_SIGNAL_DECL
45
   (I_IDENT | I_VALUE | I_TYPE | I_FLAGS),
46

47
   // T_VAR_DECL
48
   (I_IDENT | I_VALUE | I_TYPE | I_FLAGS),
49

50
   // T_PROCESS
51
   (I_IDENT | I_DECLS | I_STMTS | I_TRIGGERS | I_FLAGS),
52

53
   // T_REF
54
   (I_IDENT | I_TYPE | I_REF | I_FLAGS),
55

56
   // T_WAIT
57
   (I_IDENT | I_VALUE | I_DELAY | I_TRIGGERS | I_FLAGS),
58

59
   // T_TYPE_DECL
60
   (I_IDENT | I_TYPE),
61

62
   // T_VAR_ASSIGN
63
   (I_IDENT | I_VALUE | I_TARGET),
64

65
   // T_PACKAGE
66
   (I_IDENT | I_DECLS | I_CONTEXT | I_GENERICS | I_GENMAPS | I_PRAGMAS),
67

68
   // T_SIGNAL_ASSIGN
69
   (I_IDENT | I_TARGET | I_WAVES | I_REJECT),
70

71
   // T_QUALIFIED
72
   (I_IDENT | I_VALUE | I_TYPE),
73

74
   // T_ENUM_LIT
75
   (I_IDENT | I_TYPE | I_POS),
76

77
   // T_CONST_DECL
78
   (I_IDENT | I_VALUE | I_TYPE | I_FLAGS),
79

80
   // T_FUNC_DECL
81
   (I_IDENT | I_PORTS | I_TYPE | I_FLAGS | I_IDENT2 | I_SUBKIND | I_GENERICS),
82

83
   // T_ELAB
84
   (I_IDENT | I_DECLS | I_STMTS | I_CONTEXT),
85

86
   // T_AGGREGATE
87
   (I_TYPE | I_ASSOCS | I_FLAGS),
88

89
   // T_ASSERT
90
   (I_IDENT | I_VALUE | I_SEVERITY | I_MESSAGE),
91

92
   // T_ATTR_REF
93
   (I_NAME | I_VALUE | I_IDENT | I_PARAMS | I_TYPE | I_SUBKIND),
94

95
   // T_ARRAY_REF
96
   (I_VALUE | I_PARAMS | I_TYPE | I_FLAGS),
97

98
   // T_ARRAY_SLICE
99
   (I_VALUE | I_TYPE | I_RANGES),
100

101
   // T_INSTANCE
102
   (I_IDENT | I_IDENT2 | I_PARAMS | I_GENMAPS | I_REF | I_CLASS | I_SPEC),
103

104
   // T_IF
105
   (I_IDENT | I_CONDS),
106

107
   // T_NULL
108
   (I_IDENT),
109

110
   // T_PACK_BODY
111
   (I_IDENT | I_DECLS | I_CONTEXT | I_PRIMARY | I_PRAGMAS),
112

113
   // T_FUNC_BODY
114
   (I_IDENT | I_DECLS | I_STMTS | I_PORTS | I_TYPE | I_FLAGS | I_GENERICS
115
    | I_IDENT2 | I_SUBKIND),
116

117
   // T_RETURN
118
   (I_IDENT | I_VALUE),
119

120
   // T_COND_ASSIGN
121
   (I_IDENT | I_TARGET | I_CONDS | I_GUARD),
122

123
   // T_WHILE
124
   (I_IDENT | I_VALUE | I_STMTS),
125

126
   // T_WAVEFORM
127
   (I_VALUE | I_DELAY),
128

129
   // T_ALIAS
130
   (I_IDENT | I_VALUE | I_TYPE | I_FLAGS),
131

132
   // T_FOR
133
   (I_IDENT | I_STMTS | I_RANGES | I_DECLS),
134

135
   // T_ATTR_DECL
136
   (I_IDENT | I_TYPE),
137

138
   // T_ATTR_SPEC
139
   (I_IDENT | I_VALUE | I_IDENT2 | I_CLASS | I_REF | I_TYPE | I_SUBKIND),
140

141
   // T_PROC_DECL
142
   (I_IDENT | I_PORTS | I_TYPE | I_FLAGS | I_IDENT2 | I_SUBKIND | I_GENERICS),
143

144
   // T_PROC_BODY
145
   (I_IDENT | I_DECLS | I_STMTS | I_PORTS | I_TYPE | I_FLAGS | I_GENERICS
146
    | I_IDENT2 | I_SUBKIND),
147

148
   // T_EXIT
149
   (I_IDENT | I_VALUE | I_IDENT2),
150

151
   // T_PCALL
152
   (I_IDENT | I_IDENT2 | I_PARAMS | I_REF),
153

154
   // T_CASE
155
   (I_IDENT | I_VALUE | I_STMTS),
156

157
   // T_BLOCK
158
   (I_IDENT | I_DECLS | I_STMTS | I_PORTS | I_GENERICS | I_PARAMS | I_GENMAPS),
159

160
   // T_COND_STMT
161
   (I_IDENT | I_VALUE | I_DECLS | I_STMTS),
162

163
   // T_TYPE_CONV
164
   (I_VALUE | I_TYPE | I_FLAGS),
165

166
   // T_SELECT
167
   (I_IDENT | I_VALUE | I_STMTS | I_GUARD),
168

169
   // T_COMPONENT
170
   (I_IDENT | I_PORTS | I_GENERICS),
171

172
   // T_IF_GENERATE
173
   (I_IDENT | I_CONDS),
174

175
   // T_FOR_GENERATE
176
   (I_IDENT | I_DECLS | I_STMTS | I_RANGES),
177

178
   // T_FILE_DECL
179
   (I_IDENT | I_VALUE | I_TYPE | I_FILE_MODE),
180

181
   // T_OPEN
182
   (I_TYPE),
183

184
   // T_FIELD_DECL
185
   (I_IDENT | I_TYPE | I_POS),
186

187
   // T_RECORD_REF
188
   (I_IDENT | I_VALUE | I_TYPE | I_REF),
189

190
   // T_ALL
191
   (I_VALUE | I_TYPE),
192

193
   // T_NEW
194
   (I_VALUE | I_TYPE),
195

196
   // T_UNIT_DECL
197
   (I_IDENT | I_VALUE | I_TYPE),
198

199
   // T_NEXT
200
   (I_IDENT | I_VALUE | I_IDENT2),
201

202
   // T_PARAM
203
   (I_VALUE | I_POS | I_SUBKIND | I_NAME),
204

205
   // T_ASSOC
206
   (I_VALUE | I_POS | I_NAME | I_RANGES | I_SUBKIND),
207

208
   // T_USE
209
   (I_IDENT | I_IDENT2 | I_REF),
210

211
   // T_HIER
212
   (I_IDENT | I_SUBKIND | I_IDENT2 | I_REF),
213

214
   // T_SPEC
215
   (I_IDENT | I_IDENT2 | I_VALUE | I_REF | I_DECLS),
216

217
   // T_BINDING
218
   (I_PARAMS | I_GENMAPS | I_IDENT | I_IDENT2 | I_CLASS | I_REF),
219

220
   // T_LIBRARY
221
   (I_IDENT | I_IDENT2),
222

223
   // T_DESIGN_UNIT
224
   (I_CONTEXT),
225

226
   // T_CONFIGURATION
227
   (I_IDENT | I_IDENT2 | I_DECLS | I_PRIMARY | I_PRAGMAS),
228

229
   // T_PROT_BODY
230
   (I_IDENT | I_TYPE | I_DECLS | I_PRIMARY),
231

232
   // T_CONTEXT
233
   (I_CONTEXT | I_IDENT | I_PRAGMAS),
234

235
   // T_CONTEXT_REF
236
   (I_IDENT | I_REF),
237

238
   // T_CONSTRAINT
239
   (I_SUBKIND | I_RANGES | I_REF),
240

241
   // T_BLOCK_CONFIG
242
   (I_DECLS | I_IDENT | I_VALUE | I_RANGES | I_REF),
243

244
   // T_PROT_FCALL
245
   (I_IDENT | I_PARAMS | I_TYPE | I_REF | I_FLAGS | I_NAME),
246

247
   // T_PROT_PCALL
248
   (I_IDENT | I_IDENT2 | I_PARAMS | I_REF | I_NAME),
249

250
   // T_RANGE
251
   (I_SUBKIND | I_VALUE | I_LEFT | I_RIGHT | I_TYPE),
252

253
   // T_IMPLICIT_SIGNAL
254
   (I_IDENT | I_TYPE | I_SUBKIND | I_VALUE | I_FLAGS),
255

256
   // T_DISCONNECT
257
   (I_IDENT | I_REF | I_TYPE | I_DELAY),
258

259
   // T_GROUP_TEMPLATE
260
   (I_IDENT),
261

262
   // T_GROUP
263
   (I_IDENT | I_REF),
264

265
   // T_SUBTYPE_DECL
266
   (I_IDENT | I_TYPE),
267

268
   // T_CONV_FUNC
269
   (I_IDENT | I_REF | I_VALUE | I_TYPE),
270

271
   // T_CONCURRENT
272
   (I_IDENT | I_STMTS | I_FLAGS),
273

274
   // T_SEQUENCE
275
   (I_IDENT | I_STMTS | I_DECLS),
276

277
   // T_PACK_INST
278
   (I_IDENT | I_REF | I_DECLS | I_CONTEXT | I_GENERICS | I_GENMAPS | I_PRAGMAS),
279

280
   // T_GENERIC_DECL
281
   (I_IDENT | I_VALUE | I_TYPE | I_CLASS | I_SUBKIND | I_FLAGS | I_PORTS),
282

283
   // T_TYPE_REF
284
   (I_IDENT | I_TYPE),
285

286
   // T_BOX
287
   (I_IDENT | I_TYPE | I_REF),
288

289
   // T_PARAM_DECL
290
   (I_IDENT | I_VALUE | I_TYPE | I_SUBKIND | I_CLASS | I_FLAGS),
291

292
   // T_EXTERNAL_NAME
293
   (I_PARTS | I_CLASS | I_TYPE | I_REF),
294

295
   // T_FORCE
296
   (I_IDENT | I_TARGET | I_VALUE | I_SUBKIND),
297

298
   // T_RELEASE
299
   (I_IDENT | I_TARGET | I_SUBKIND),
300

301
   // T_PROT_REF
302
   (I_IDENT | I_VALUE | I_TYPE | I_REF),
303

304
   // T_MATCH_CASE
305
   (I_IDENT | I_VALUE | I_STMTS),
306

307
   // T_FUNC_INST
308
   (I_IDENT | I_DECLS | I_STMTS | I_PORTS | I_TYPE | I_FLAGS | I_GENERICS
309
    | I_IDENT2 | I_SUBKIND | I_GENMAPS | I_REF),
310

311
   // T_PROC_INST
312
   (I_IDENT | I_DECLS | I_STMTS | I_PORTS | I_TYPE | I_FLAGS | I_GENERICS
313
    | I_IDENT2 | I_SUBKIND | I_GENMAPS | I_REF),
314

315
   // T_ELEM_CONSTRAINT
316
   (I_IDENT | I_REF | I_TYPE),
317

318
   // T_STRING
319
   (I_CHARS | I_TYPE),
320

321
   // T_PATH_ELT
322
   (I_SUBKIND | I_IDENT | I_VALUE),
323

324
   // T_PRAGMA
325
   (I_SUBKIND),
326

327
   // T_CASE_GENERATE
328
   (I_IDENT | I_VALUE | I_STMTS),
329

330
   // T_ALTERNATIVE
331
   (I_IDENT | I_ASSOCS | I_STMTS | I_DECLS),
332

333
   // T_PSL_DECL
334
   (I_IDENT | I_FOREIGN),
335

336
   // T_VERILOG
337
   (I_IDENT | I_FOREIGN | I_PARAMS | I_GENMAPS),
338

339
   // T_VIEW_DECL
340
   (I_IDENT | I_TYPE),
341

342
   // T_PACKAGE_MAP
343
   (I_IDENT | I_SUBKIND | I_GENMAPS | I_REF),
344

345
   // T_COND_EXPR
346
   (I_VALUE | I_RESULT),
347

348
   // T_COND_VALUE
349
   (I_CONDS | I_TYPE),
350

351
   // T_COND_RETURN
352
   (I_IDENT | I_VALUE),
353

354
   // T_VIEW_ELEMENT
355
   (I_IDENT | I_REF | I_SUBKIND | I_TYPE | I_VALUE),
356

357
   // T_MATCH_SELECT
358
   (I_IDENT | I_VALUE | I_STMTS | I_GUARD),
359

360
   // T_PROT_DECL
361
   (I_IDENT | I_DECLS | I_TYPE),
362

363
   // T_DUMMY_DRIVER
364
   (I_TARGET | I_IDENT),
365

366
   // T_GUARD
367
   (I_REF | I_SPEC | I_TYPE),
368

369
   // T_INERTIAL
370
   (I_VALUE | I_TYPE | I_TARGET),
371

372
   // T_ELEM_RESOLUTION
373
   (I_ASSOCS),
374

375
   // T_LOOP
376
   (I_IDENT | I_STMTS),
377

378
   // T_REPORT
379
   (I_IDENT | I_SEVERITY | I_MESSAGE),
380

381
   // T_PSL_DIRECT
382
   (I_IDENT | I_FOREIGN),
383

384
   // T_PSL_FCALL
385
   (I_FOREIGN | I_TYPE),
386
};
387

388
static const char *kind_text_map[T_LAST_TREE_KIND] = {
389
   "T_ENTITY",          "T_ARCH",            "T_PORT_DECL",
390
   "T_FCALL",           "T_LITERAL",         "T_SIGNAL_DECL",
391
   "T_VAR_DECL",        "T_PROCESS",         "T_REF",
392
   "T_WAIT",            "T_TYPE_DECL",       "T_VAR_ASSIGN",
393
   "T_PACKAGE",         "T_SIGNAL_ASSIGN",   "T_QUALIFIED",
394
   "T_ENUM_LIT",        "T_CONST_DECL",      "T_FUNC_DECL",
395
   "T_ELAB",            "T_AGGREGATE",       "T_ASSERT",
396
   "T_ATTR_REF",        "T_ARRAY_REF",       "T_ARRAY_SLICE",
397
   "T_INSTANCE",        "T_IF",              "T_NULL",
398
   "T_PACK_BODY",       "T_FUNC_BODY",       "T_RETURN",
399
   "T_COND_ASSIGN",     "T_WHILE",           "T_WAVEFORM",
400
   "T_ALIAS",           "T_FOR",             "T_ATTR_DECL",
401
   "T_ATTR_SPEC",       "T_PROC_DECL",       "T_PROC_BODY",
402
   "T_EXIT",            "T_PCALL",           "T_CASE",
403
   "T_BLOCK",           "T_COND_STMT",       "T_TYPE_CONV",
404
   "T_SELECT",          "T_COMPONENT",       "T_IF_GENERATE",
405
   "T_FOR_GENERATE",    "T_FILE_DECL",       "T_OPEN",
406
   "T_FIELD_DECL",      "T_RECORD_REF",      "T_ALL",
407
   "T_NEW",             "T_UNIT_DECL",       "T_NEXT",
408
   "T_PARAM",           "T_ASSOC",           "T_USE",
409
   "T_HIER",            "T_SPEC",            "T_BINDING",
410
   "T_LIBRARY",         "T_DESIGN_UNIT",     "T_CONFIGURATION",
411
   "T_PROT_BODY",       "T_CONTEXT",         "T_CONTEXT_REF",
412
   "T_CONSTRAINT",      "T_BLOCK_CONFIG",    "T_PROT_FCALL",
413
   "T_PROT_PCALL",      "T_RANGE",           "T_IMPLICIT_SIGNAL",
414
   "T_DISCONNECT",      "T_GROUP_TEMPLATE",  "T_GROUP",
415
   "T_SUBTYPE_DECL",    "T_CONV_FUNC",       "T_CONCURRENT",
416
   "T_SEQUENCE",        "T_PACK_INST",       "T_GENERIC_DECL",
417
   "T_TYPE_REF",        "T_BOX",             "T_PARAM_DECL",
418
   "T_EXTERNAL_NAME",   "T_FORCE",           "T_RELEASE",
419
   "T_PROT_REF",        "T_MATCH_CASE",      "T_FUNC_INST",
420
   "T_PROC_INST",       "T_ELEM_CONSTRAINT", "T_STRING",
421
   "T_PATH_ELT",        "T_PRAGMA",          "T_CASE_GENERATE",
422
   "T_ALTERNATIVE",     "T_PSL_DECL",        "T_VERILOG",
423
   "T_VIEW_DECL",       "T_PACKAGE_MAP",     "T_COND_EXPR",
424
   "T_COND_VALUE",      "T_COND_RETURN",     "T_VIEW_ELEMENT",
425
   "T_MATCH_SELECT",    "T_PROT_DECL",       "T_DUMMY_DRIVER",
426
   "T_GUARD",           "T_INERTIAL",        "T_ELEM_RESOLUTION",
427
   "T_LOOP",            "T_REPORT",          "T_PSL_DIRECT",
428
   "T_PSL_FCALL",
429
};
430

431
static const change_allowed_t change_allowed[] = {
432
   { T_REF,         T_FCALL         },
433
   { T_REF,         T_PCALL         },
434
   { T_ARRAY_REF,   T_FCALL         },
435
   { T_FCALL,       T_ARRAY_REF     },
436
   { T_PROT_FCALL,  T_ARRAY_REF     },
437
   { T_DESIGN_UNIT, T_ENTITY        },
438
   { T_DESIGN_UNIT, T_PACKAGE       },
439
   { T_DESIGN_UNIT, T_PACK_BODY     },
440
   { T_DESIGN_UNIT, T_ARCH          },
441
   { T_DESIGN_UNIT, T_CONFIGURATION },
442
   { T_DESIGN_UNIT, T_CONTEXT       },
443
   { T_DESIGN_UNIT, T_PACK_INST     },
444
   { T_FUNC_DECL,   T_FUNC_BODY     },
445
   { T_PROC_DECL,   T_PROC_BODY     },
446
   { T_FCALL,       T_PROT_FCALL    },
447
   { T_PCALL,       T_PROT_PCALL    },
448
   { -1,            -1              }
449
};
450

451
struct _tree {
452
   object_t object;
453
};
454

455
struct _type {
456
   object_t object;
457
};
458

459
struct _psl_node {
460
   object_t object;
461
};
462

463
struct _vlog_node {
464
   object_t object;
465
};
466

467
object_class_t tree_object = {
468
   .name           = "tree",
469
   .change_allowed = change_allowed,
470
   .has_map        = has_map,
471
   .kind_text_map  = kind_text_map,
472
   .tag            = OBJECT_TAG_TREE,
473
   .last_kind      = T_LAST_TREE_KIND,
474
   .has_loc        = true,
475
   .gc_roots       = { T_ARCH, T_ENTITY, T_PACKAGE, T_ELAB, T_PACK_BODY,
476
                       T_CONTEXT, T_CONFIGURATION, T_DESIGN_UNIT,
477
                       T_PACK_INST },
478
   .gc_num_roots   = 9
479
};
480

481
#ifdef DEBUG
482
static tree_kind_t expr_kinds[] = {
483
   T_FCALL,     T_LITERAL,       T_REF,        T_QUALIFIED,
484
   T_AGGREGATE, T_ATTR_REF,      T_ARRAY_REF,  T_ARRAY_SLICE,
485
   T_TYPE_CONV, T_OPEN,          T_RECORD_REF, T_ALL,
486
   T_NEW,       T_PROT_FCALL,    T_CONV_FUNC,  T_TYPE_REF,
487
   T_BOX,       T_EXTERNAL_NAME, T_PROT_REF,   T_STRING,
488
};
489

490
static tree_kind_t decl_kinds[] = {
491
   T_PORT_DECL,      T_SIGNAL_DECL,    T_VAR_DECL,        T_TYPE_DECL,
492
   T_CONST_DECL,     T_FUNC_DECL,      T_FUNC_BODY,       T_ALIAS,
493
   T_ATTR_DECL,      T_ATTR_SPEC,      T_PROC_DECL,       T_PROC_BODY,
494
   T_COMPONENT,      T_FILE_DECL,      T_FIELD_DECL,      T_UNIT_DECL,
495
   T_HIER,           T_SPEC,           T_BINDING,         T_USE,
496
   T_PROT_BODY,      T_BLOCK_CONFIG,   T_IMPLICIT_SIGNAL, T_DISCONNECT,
497
   T_GROUP_TEMPLATE, T_GROUP,          T_SUBTYPE_DECL,    T_PACKAGE,
498
   T_PACK_BODY,      T_PACK_INST,      T_GENERIC_DECL,    T_PARAM_DECL,
499
   T_PROC_INST,      T_FUNC_INST,      T_PSL_DECL,        T_VIEW_DECL,
500
   T_PROT_DECL,
501
};
502

503
static void tree_assert_kind(tree_t t, const tree_kind_t *list, size_t len,
379,643✔
504
                             const char *what)
505
{
506
   for (size_t i = 0; i < len; i++) {
4,601,388✔
507
      if (t->object.kind == list[i])
4,601,388✔
508
         return;
379,643✔
509
   }
510

511
   fatal_trace("tree kind %s is not %s", tree_kind_str(t->object.kind), what);
512
}
513
#else
514
#define tree_assert_kind(t, list, len, what)
515
#endif
516

517
static inline void tree_assert_expr(tree_t t)
144,069✔
518
{
519
   tree_assert_kind(t, expr_kinds, ARRAY_LEN(expr_kinds), "an expression");
144,069✔
520
}
144,069✔
521

522
static inline void tree_assert_decl(tree_t t)
235,574✔
523
{
524
   tree_assert_kind(t, decl_kinds, ARRAY_LEN(decl_kinds), "a declaration");
235,574✔
525
}
235,574✔
526

527
static inline tree_t tree_array_nth(item_t *item, unsigned n)
26,662,837✔
528
{
529
   object_t *o = obj_array_nth(item->obj_array, n);
26,662,837✔
530
   return container_of(o, struct _tree, object);
26,662,837✔
531
}
532

533
static inline void tree_array_add(item_t *item, tree_t t)
1,118,902✔
534
{
535
   obj_array_add(&(item->obj_array), &(t->object));
1,118,902✔
536
}
1,118,902✔
537

538
tree_t tree_new(tree_kind_t kind)
1,741,921✔
539
{
540
   object_t *o = object_new(NULL, &tree_object, kind);
1,741,921✔
541
   return container_of(o, struct _tree, object);
1,741,921✔
542
}
543

544
const loc_t *tree_loc(tree_t t)
1,703,859✔
545
{
546
   assert(t != NULL);
1,703,859✔
547
   return &t->object.loc;
1,703,859✔
548
}
549

550
void tree_set_loc(tree_t t, const loc_t *loc)
1,779,967✔
551
{
552
   assert(t != NULL);
1,779,967✔
553
   assert(loc != NULL);
1,779,967✔
554

555
   t->object.loc = *loc;
1,779,967✔
556
}
1,779,967✔
557

558
ident_t tree_ident(tree_t t)
29,750,619✔
559
{
560
   item_t *item = lookup_item(&tree_object, t, I_IDENT);
29,750,619✔
561
   assert(item->ident != NULL);
29,750,619✔
562
   return item->ident;
29,750,619✔
563
}
564

565
bool tree_has_ident(tree_t t)
12,125✔
566
{
567
   return lookup_item(&tree_object, t, I_IDENT)->ident != NULL;
12,125✔
568
}
569

570
void tree_set_ident(tree_t t, ident_t i)
1,188,398✔
571
{
572
   lookup_item(&tree_object, t, I_IDENT)->ident = i;
1,188,398✔
573
}
1,188,398✔
574

575
ident_t tree_ident2(tree_t t)
204,302✔
576
{
577
   item_t *item = lookup_item(&tree_object, t, I_IDENT2);
204,302✔
578
   assert(item->ident != NULL);
204,302✔
579
   return item->ident;
204,302✔
580
}
581

582
void tree_set_ident2(tree_t t, ident_t i)
125,515✔
583
{
584
   lookup_item(&tree_object, t, I_IDENT2)->ident = i;
125,515✔
585
}
125,515✔
586

587
bool tree_has_ident2(tree_t t)
73,248✔
588
{
589
   return lookup_item(&tree_object, t, I_IDENT2)->ident != NULL;
73,248✔
590
}
591

592
tree_kind_t tree_kind(tree_t t)
114,656,685✔
593
{
594
   assert(t != NULL);
114,656,685✔
595
   return t->object.kind;
114,656,685✔
596
}
597

598
void tree_change_kind(tree_t t, tree_kind_t kind)
23,344✔
599
{
600
   object_change_kind(&tree_object, &(t->object), kind);
23,344✔
601
}
23,344✔
602

603
unsigned tree_ports(tree_t t)
3,971,143✔
604
{
605
   item_t *item = lookup_item(&tree_object, t, I_PORTS);
3,971,143✔
606
   return obj_array_count(item->obj_array);
3,971,143✔
607
}
608

609
tree_t tree_port(tree_t t, unsigned n)
5,351,572✔
610
{
611
   item_t *item = lookup_item(&tree_object, t, I_PORTS);
5,351,572✔
612
   return tree_array_nth(item, n);
5,351,572✔
613
}
614

615
void tree_add_port(tree_t t, tree_t d)
110,242✔
616
{
617
   tree_assert_decl(d);
110,242✔
618
   tree_array_add(lookup_item(&tree_object, t, I_PORTS), d);
110,242✔
619
   object_write_barrier(&(t->object), &(d->object));
110,242✔
620
}
110,242✔
621

622
unsigned tree_subkind(tree_t t)
26,059,580✔
623
{
624
   item_t *item = lookup_item(&tree_object, t, I_SUBKIND);
26,059,580✔
625
   return item->ival;
26,059,580✔
626
}
627

628
void tree_set_subkind(tree_t t, unsigned sub)
699,461✔
629
{
630
   lookup_item(&tree_object, t, I_SUBKIND)->ival = sub;
699,461✔
631
}
699,461✔
632

633
unsigned tree_generics(tree_t t)
216,914✔
634
{
635
   item_t *item = lookup_item(&tree_object, t, I_GENERICS);
216,914✔
636
   return obj_array_count(item->obj_array);
216,914✔
637
}
638

639
tree_t tree_generic(tree_t t, unsigned n)
49,904✔
640
{
641
   item_t *item = lookup_item(&tree_object, t, I_GENERICS);
49,904✔
642
   return tree_array_nth(item, n);
49,904✔
643
}
644

645
void tree_add_generic(tree_t t, tree_t d)
9,878✔
646
{
647
   assert(d->object.kind == T_GENERIC_DECL);
9,878✔
648
   tree_array_add(lookup_item(&tree_object, t, I_GENERICS), d);
9,878✔
649
   object_write_barrier(&(t->object), &(d->object));
9,878✔
650
}
9,878✔
651

652
type_t tree_type(tree_t t)
32,565,651✔
653
{
654
   item_t *item = lookup_item(&tree_object, t, I_TYPE);
32,565,651✔
655
   assert(item->object != NULL);
32,565,651✔
656
   return container_of(item->object, struct _type, object);
32,565,651✔
657
}
658

659
void tree_set_type(tree_t t, type_t ty)
1,202,988✔
660
{
661
   object_t *obj = ty ? &(ty->object) : NULL;
1,202,988✔
662
   lookup_item(&tree_object, t, I_TYPE)->object = obj;
1,202,988✔
663
   object_write_barrier(&(t->object), obj);
1,202,988✔
664
}
1,202,988✔
665

666
bool tree_has_type(tree_t t)
4,705,758✔
667
{
668
   return lookup_item(&tree_object, t, I_TYPE)->object != NULL;
4,705,758✔
669
}
670

671
unsigned tree_params(tree_t t)
14,462,433✔
672
{
673
   item_t *item = lookup_item(&tree_object, t, I_PARAMS);
14,462,433✔
674
   return obj_array_count(item->obj_array);
14,462,433✔
675
}
676

677
tree_t tree_param(tree_t t, unsigned n)
15,048,119✔
678
{
679
   item_t *item = lookup_item(&tree_object, t, I_PARAMS);
15,048,119✔
680
   return tree_array_nth(item, n);
15,048,119✔
681
}
682

683
void tree_add_param(tree_t t, tree_t e)
217,124✔
684
{
685
   assert(e->object.kind == T_PARAM);
217,124✔
686
   tree_array_add(lookup_item(&tree_object, t, I_PARAMS), e);
217,124✔
687
   object_write_barrier(&(t->object), &(e->object));
217,124✔
688
}
217,124✔
689

690
unsigned tree_genmaps(tree_t t)
39,484✔
691
{
692
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
39,484✔
693
   return obj_array_count(item->obj_array);
39,484✔
694
}
695

696
tree_t tree_genmap(tree_t t, unsigned n)
40,985✔
697
{
698
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
40,985✔
699
   return tree_array_nth(item, n);
40,985✔
700
}
701

702
void tree_add_genmap(tree_t t, tree_t e)
9,940✔
703
{
704
   tree_array_add(lookup_item(&tree_object, t, I_GENMAPS), e);
9,940✔
705
}
9,940✔
706

707
void tree_trim_genmaps(tree_t t, unsigned n)
5✔
708
{
709
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
5✔
710
   assert(n < obj_array_count(item->obj_array));
5✔
711
   assert(n > 0);
5✔
712
   item->obj_array->count = n;
5✔
713
}
5✔
714

715
int64_t tree_ival(tree_t t)
2,764,398✔
716
{
717
   return lookup_item(&tree_object, t, I_IVAL)->ival;
2,764,398✔
718
}
719

720
void tree_set_ival(tree_t t, int64_t i)
120,874✔
721
{
722
   lookup_item(&tree_object, t, I_IVAL)->ival = i;
120,874✔
723
}
120,874✔
724

725
double tree_dval(tree_t t)
220,948✔
726
{
727
   return lookup_item(&tree_object, t, I_DVAL)->dval;
220,948✔
728
}
729

730
void tree_set_dval(tree_t t, double d)
23,604✔
731
{
732
   lookup_item(&tree_object, t, I_DVAL)->dval = d;
23,604✔
733
}
23,604✔
734

735
tree_flags_t tree_flags(tree_t t)
17,339,125✔
736
{
737
   return lookup_item(&tree_object, t, I_FLAGS)->ival;
17,339,125✔
738
}
739

740
void tree_set_flag(tree_t t, tree_flags_t mask)
156,601✔
741
{
742
   lookup_item(&tree_object, t, I_FLAGS)->ival |= mask;
156,601✔
743
}
156,601✔
744

745
void tree_clear_flag(tree_t t, tree_flags_t mask)
575✔
746
{
747
   lookup_item(&tree_object, t, I_FLAGS)->ival &= ~mask;
575✔
748
}
575✔
749

750
tree_t tree_primary(tree_t t)
51,850✔
751
{
752
   item_t *item = lookup_item(&tree_object, t, I_PRIMARY);
51,850✔
753
   assert(item->object != NULL);
51,850✔
754
   return container_of(item->object, struct _tree, object);
51,850✔
755
}
756

757
bool tree_has_primary(tree_t t)
5,791✔
758
{
759
   return lookup_item(&tree_object, t, I_PRIMARY)->object != NULL;
5,791✔
760
}
761

762
void tree_set_primary(tree_t t, tree_t unit)
5,980✔
763
{
764
   lookup_item(&tree_object, t, I_PRIMARY)->object = &(unit->object);
5,980✔
765
   object_write_barrier(&(t->object), &(unit->object));
5,980✔
766
}
5,980✔
767

768
psl_node_t tree_psl(tree_t t)
990✔
769
{
770
   item_t *item = lookup_item(&tree_object, t, I_FOREIGN);
990✔
771
   assert(item->object != NULL);
990✔
772
   return container_of(item->object, struct _psl_node, object);
990✔
773
}
774

775
void tree_set_psl(tree_t t, psl_node_t p)
432✔
776
{
777
   assert(p != NULL);
432✔
778
   lookup_item(&tree_object, t, I_FOREIGN)->object = &(p->object);
432✔
779
   object_write_barrier(&(t->object), &(p->object));
432✔
780
}
432✔
781

UNCOV
782
bool tree_has_psl(tree_t t)
×
783
{
UNCOV
784
   return lookup_item(&tree_object, t, I_FOREIGN)->object != NULL;
×
785
}
786

787
vlog_node_t tree_vlog(tree_t t)
521✔
788
{
789
   item_t *item = lookup_item(&tree_object, t, I_FOREIGN);
521✔
790
   assert(item->object != NULL);
521✔
791
   return container_of(item->object, struct _vlog_node, object);
521✔
792
}
793

794
void tree_set_vlog(tree_t t, vlog_node_t v)
318✔
795
{
796
   assert(v != NULL);
318✔
797
   lookup_item(&tree_object, t, I_FOREIGN)->object = &(v->object);
318✔
798
   object_write_barrier(&(t->object), &(v->object));
318✔
799
}
318✔
800

801
unsigned tree_chars(tree_t t)
125,880✔
802
{
803
   item_t *item = lookup_item(&tree_object, t, I_CHARS);
125,880✔
804
   return obj_array_count(item->obj_array);
125,880✔
805
}
806

807
tree_t tree_char(tree_t t, unsigned n)
973,611✔
808
{
809
   item_t *item = lookup_item(&tree_object, t, I_CHARS);
973,611✔
810
   return tree_array_nth(item, n);
973,611✔
811
}
812

813
void tree_add_char(tree_t t, tree_t ref)
360,338✔
814
{
815
   tree_array_add(lookup_item(&tree_object, t, I_CHARS), ref);
360,338✔
816
   object_write_barrier(&(t->object), &(ref->object));
360,338✔
817
}
360,338✔
818

819
unsigned tree_parts(tree_t t)
534✔
820
{
821
   item_t *item = lookup_item(&tree_object, t, I_PARTS);
534✔
822
   return obj_array_count(item->obj_array);
534✔
823
}
824

825
tree_t tree_part(tree_t t, unsigned n)
1,476✔
826
{
827
   item_t *item = lookup_item(&tree_object, t, I_PARTS);
1,476✔
828
   return tree_array_nth(item, n);
1,476✔
829
}
830

831
void tree_add_part(tree_t t, tree_t ref)
647✔
832
{
833
   tree_array_add(lookup_item(&tree_object, t, I_PARTS), ref);
647✔
834
   object_write_barrier(&(t->object), &(ref->object));
647✔
835
}
647✔
836

837
bool tree_has_value(tree_t t)
2,931,303✔
838
{
839
   return lookup_item(&tree_object, t, I_VALUE)->object != NULL;
2,931,303✔
840
}
841

842
tree_t tree_value(tree_t t)
16,515,829✔
843
{
844
   item_t *item = lookup_item(&tree_object, t, I_VALUE);
16,515,829✔
845
   assert(item->object != NULL);
16,515,829✔
846
   return container_of(item->object, struct _tree, object);
16,515,829✔
847
}
848

849
void tree_set_value(tree_t t, tree_t v)
391,105✔
850
{
851
   object_t *obj = v ? &(v->object) : NULL;
391,105✔
852
   lookup_item(&tree_object, t, I_VALUE)->object = obj;
391,105✔
853
   object_write_barrier(&(t->object), obj);
391,105✔
854
}
391,105✔
855

856
bool tree_has_result(tree_t t)
295✔
857
{
858
   return lookup_item(&tree_object, t, I_RESULT)->object != NULL;
295✔
859
}
860

861
tree_t tree_result(tree_t t)
280✔
862
{
863
   item_t *item = lookup_item(&tree_object, t, I_RESULT);
280✔
864
   assert(item->object != NULL);
280✔
865
   return container_of(item->object, struct _tree, object);
280✔
866
}
867

868
void tree_set_result(tree_t t, tree_t v)
104✔
869
{
870
   object_t *obj = v ? &(v->object) : NULL;
104✔
871
   lookup_item(&tree_object, t, I_RESULT)->object = obj;
104✔
872
   object_write_barrier(&(t->object), obj);
104✔
873
}
104✔
874

875
unsigned tree_decls(tree_t t)
107,589✔
876
{
877
   item_t *item = lookup_item(&tree_object, t, I_DECLS);
107,589✔
878
   return obj_array_count(item->obj_array);
107,589✔
879
}
880

881
tree_t tree_decl(tree_t t, unsigned n)
3,115,923✔
882
{
883
   item_t *item = lookup_item(&tree_object, t, I_DECLS);
3,115,923✔
884
   return tree_array_nth(item, n);
3,115,923✔
885
}
886

887
void tree_add_decl(tree_t t, tree_t d)
125,332✔
888
{
889
   tree_assert_decl(d);
125,332✔
890
   tree_array_add(lookup_item(&tree_object, t, I_DECLS), d);
125,332✔
891
   object_write_barrier(&(t->object), &(d->object));
125,332✔
892
}
125,332✔
893

894
unsigned tree_stmts(tree_t t)
123,736✔
895
{
896
   item_t *item = lookup_item(&tree_object, t, I_STMTS);
123,736✔
897
   return obj_array_count(item->obj_array);
123,736✔
898
}
899

900
tree_t tree_stmt(tree_t t, unsigned n)
183,609✔
901
{
902
   item_t *item = lookup_item(&tree_object, t, I_STMTS);
183,609✔
903
   return tree_array_nth(item, n);
183,609✔
904
}
905

906
void tree_add_stmt(tree_t t, tree_t s)
129,086✔
907
{
908
   assert(s != NULL);
129,086✔
909
   tree_array_add(lookup_item(&tree_object, t, I_STMTS), s);
129,086✔
910
   object_write_barrier(&(t->object), &(s->object));
129,086✔
911
}
129,086✔
912

913
unsigned tree_waveforms(tree_t t)
36,751✔
914
{
915
   item_t *item = lookup_item(&tree_object, t, I_WAVES);
36,751✔
916
   return obj_array_count(item->obj_array);
36,751✔
917
}
918

919
tree_t tree_waveform(tree_t t, unsigned n)
37,507✔
920
{
921
   item_t *item = lookup_item(&tree_object, t, I_WAVES);
37,507✔
922
   return tree_array_nth(item, n);
37,507✔
923
}
924

925
void tree_add_waveform(tree_t t, tree_t w)
7,693✔
926
{
927
   assert(w->object.kind == T_WAVEFORM);
7,693✔
928
   tree_array_add(lookup_item(&tree_object, t, I_WAVES), w);
7,693✔
929
   object_write_barrier(&(t->object), &(w->object));
7,693✔
930
}
7,693✔
931

932
unsigned tree_conds(tree_t t)
36,479✔
933
{
934
   item_t *item = lookup_item(&tree_object, t, I_CONDS);
36,479✔
935
   return obj_array_count(item->obj_array);
36,479✔
936
}
937

938
tree_t tree_cond(tree_t t, unsigned n)
51,105✔
939
{
940
   item_t *item = lookup_item(&tree_object, t, I_CONDS);
51,105✔
941
   return tree_array_nth(item, n);
51,105✔
942
}
943

944
void tree_add_cond(tree_t t, tree_t c)
14,860✔
945
{
946
   assert(c->object.kind == T_COND_STMT || c->object.kind == T_COND_EXPR);
14,860✔
947
   tree_array_add(lookup_item(&tree_object, t, I_CONDS), c);
14,860✔
948
   object_write_barrier(&(t->object), &(c->object));
14,860✔
949
}
14,860✔
950

951
bool tree_has_delay(tree_t t)
73,080✔
952
{
953
   return lookup_item(&tree_object, t, I_DELAY)->object != NULL;
73,080✔
954
}
955

956
tree_t tree_delay(tree_t t)
18,787✔
957
{
958
   item_t *item = lookup_item(&tree_object, t, I_DELAY);
18,787✔
959
   assert(item->object != NULL);
18,787✔
960
   return container_of(item->object, struct _tree, object);
18,787✔
961
}
962

963
void tree_set_delay(tree_t t, tree_t d)
5,922✔
964
{
965
   tree_assert_expr(d);
5,922✔
966
   lookup_item(&tree_object, t, I_DELAY)->object = &(d->object);
5,922✔
967
   object_write_barrier(&(t->object), &(d->object));
5,922✔
968
}
5,922✔
969

970
unsigned tree_triggers(tree_t t)
62,745✔
971
{
972
   item_t *item = lookup_item(&tree_object, t, I_TRIGGERS);
62,745✔
973
   return obj_array_count(item->obj_array);
62,745✔
974
}
975

976
tree_t tree_trigger(tree_t t, unsigned n)
9,639✔
977
{
978
   item_t *item = lookup_item(&tree_object, t, I_TRIGGERS);
9,639✔
979
   return tree_array_nth(item, n);
9,639✔
980
}
981

982
void tree_add_trigger(tree_t t, tree_t s)
4,005✔
983
{
984
   tree_assert_expr(s);
4,005✔
985
   tree_array_add(lookup_item(&tree_object, t, I_TRIGGERS), s);
4,005✔
986
   object_write_barrier(&(t->object), &(s->object));
4,005✔
987
}
4,005✔
988

989
tree_t tree_target(tree_t t)
104,489✔
990
{
991
   item_t *item = lookup_item(&tree_object, t, I_TARGET);
104,489✔
992
   assert(item->object != NULL);
104,489✔
993
   return container_of(item->object, struct _tree, object);
104,489✔
994
}
995

996
void tree_set_target(tree_t t, tree_t lhs)
26,660✔
997
{
998
   lookup_item(&tree_object, t, I_TARGET)->object = &(lhs->object);
26,660✔
999
   object_write_barrier(&(t->object), &(lhs->object));
26,660✔
1000
}
26,660✔
1001

1002
tree_t tree_ref(tree_t t)
18,741,001✔
1003
{
1004
   item_t *item = lookup_item(&tree_object, t, I_REF);
18,741,001✔
1005
   assert(item->object != NULL);
18,741,001✔
1006
   return container_of(item->object, struct _tree, object);
18,741,001✔
1007
}
1008

1009
bool tree_has_ref(tree_t t)
15,381,721✔
1010
{
1011
   return lookup_item(&tree_object, t, I_REF)->object != NULL;
15,381,721✔
1012
}
1013

1014
void tree_set_ref(tree_t t, tree_t decl)
1,090,844✔
1015
{
1016
   object_t *obj = decl ? &(decl->object) : NULL;
1,090,844✔
1017
   lookup_item(&tree_object, t, I_REF)->object = obj;
1,090,844✔
1018
   object_write_barrier(&(t->object), obj);
1,090,844✔
1019
}
1,090,844✔
1020

1021
tree_t tree_spec(tree_t t)
226✔
1022
{
1023
   item_t *item = lookup_item(&tree_object, t, I_SPEC);
226✔
1024
   assert(item->object != NULL);
226✔
1025
   return container_of(item->object, struct _tree, object);
226✔
1026
}
1027

1028
bool tree_has_spec(tree_t t)
2,365✔
1029
{
1030
   return lookup_item(&tree_object, t, I_SPEC)->object != NULL;
2,365✔
1031
}
1032

1033
void tree_set_spec(tree_t t, tree_t s)
101✔
1034
{
1035
   assert(s != NULL);
101✔
1036
   lookup_item(&tree_object, t, I_SPEC)->object = &(s->object);
101✔
1037
   object_write_barrier(&(t->object), &(s->object));
101✔
1038
}
101✔
1039

1040
unsigned tree_contexts(tree_t t)
29,868✔
1041
{
1042
   item_t *item = lookup_item(&tree_object, t, I_CONTEXT);
29,868✔
1043
   return obj_array_count(item->obj_array);
29,868✔
1044
}
1045

1046
tree_t tree_context(tree_t t, unsigned n)
99,596✔
1047
{
1048
   item_t *item = lookup_item(&tree_object, t, I_CONTEXT);
99,596✔
1049
   return tree_array_nth(item, n);
99,596✔
1050
}
1051

1052
void tree_add_context(tree_t t, tree_t ctx)
40,585✔
1053
{
1054
   assert(ctx->object.kind == T_USE || ctx->object.kind == T_LIBRARY
40,585✔
1055
          || ctx->object.kind == T_CONTEXT_REF);
1056
   tree_array_add(lookup_item(&tree_object, t, I_CONTEXT), ctx);
40,585✔
1057
   object_write_barrier(&(t->object), &(ctx->object));
40,585✔
1058
}
40,585✔
1059

1060
unsigned tree_pragmas(tree_t t)
183✔
1061
{
1062
   item_t *item = lookup_item(&tree_object, t, I_PRAGMAS);
183✔
1063
   return obj_array_count(item->obj_array);
183✔
1064
}
1065

1066
tree_t tree_pragma(tree_t t, unsigned n)
39✔
1067
{
1068
   item_t *item = lookup_item(&tree_object, t, I_PRAGMAS);
39✔
1069
   return tree_array_nth(item, n);
39✔
1070
}
1071

1072
void tree_add_pragma(tree_t t, tree_t p)
47✔
1073
{
1074
   assert(p->object.kind == T_PRAGMA);
47✔
1075
   tree_array_add(lookup_item(&tree_object, t, I_PRAGMAS), p);
47✔
1076
   object_write_barrier(&(t->object), &(p->object));
47✔
1077
}
47✔
1078

1079
unsigned tree_assocs(tree_t t)
118,945✔
1080
{
1081
   item_t *item = lookup_item(&tree_object, t, I_ASSOCS);
118,945✔
1082
   return obj_array_count(item->obj_array);
118,945✔
1083
}
1084

1085
tree_t tree_assoc(tree_t t, unsigned n)
431,001✔
1086
{
1087
   item_t *item = lookup_item(&tree_object, t, I_ASSOCS);
431,001✔
1088
   return tree_array_nth(item, n);
431,001✔
1089
}
1090

1091
void tree_add_assoc(tree_t t, tree_t a)
41,242✔
1092
{
1093
   assert(a->object.kind == T_ASSOC);
41,242✔
1094
   tree_array_add(lookup_item(&tree_object, t, I_ASSOCS), a);
41,242✔
1095
   object_write_barrier(&(t->object), &(a->object));
41,242✔
1096
}
41,242✔
1097

1098
tree_t tree_severity(tree_t t)
10,207✔
1099
{
1100
   item_t *item = lookup_item(&tree_object, t, I_SEVERITY);
10,207✔
1101
   assert(item->object != NULL);
10,207✔
1102
   return container_of(item->object, struct _tree, object);
10,207✔
1103
}
1104

1105
void tree_set_severity(tree_t t, tree_t s)
6,419✔
1106
{
1107
   tree_assert_expr(s);
6,419✔
1108
   lookup_item(&tree_object, t, I_SEVERITY)->object = &(s->object);
6,419✔
1109
   object_write_barrier(&(t->object), &(s->object));
6,419✔
1110
}
6,419✔
1111

1112
bool tree_has_severity(tree_t t)
35,109✔
1113
{
1114
   return lookup_item(&tree_object, t, I_SEVERITY)->object != NULL;
35,109✔
1115
}
1116

1117
tree_t tree_message(tree_t t)
14,303✔
1118
{
1119
   item_t *item = lookup_item(&tree_object, t, I_MESSAGE);
14,303✔
1120
   assert(item->object != NULL);
14,303✔
1121
   return container_of(item->object, struct _tree, object);
14,303✔
1122
}
1123

1124
bool tree_has_message(tree_t t)
47,501✔
1125
{
1126
   return lookup_item(&tree_object, t, I_MESSAGE)->object != NULL;
47,501✔
1127
}
1128

1129
void tree_set_message(tree_t t, tree_t m)
8,345✔
1130
{
1131
   tree_assert_expr(m);
8,345✔
1132
   lookup_item(&tree_object, t, I_MESSAGE)->object = &(m->object);
8,345✔
1133
   object_write_barrier(&(t->object), &(m->object));
8,345✔
1134
}
8,345✔
1135

1136
void tree_add_range(tree_t t, tree_t r)
47,883✔
1137
{
1138
   tree_array_add(lookup_item(&tree_object, t, I_RANGES), r);
47,883✔
1139
   object_write_barrier(&(t->object), &(r->object));
47,883✔
1140
}
47,883✔
1141

1142
tree_t tree_range(tree_t t, unsigned n)
1,268,751✔
1143
{
1144
   item_t *item = lookup_item(&tree_object, t, I_RANGES);
1,268,751✔
1145
   return tree_array_nth(item, n);
1,268,751✔
1146
}
1147

1148
unsigned tree_ranges(tree_t t)
1,217,114✔
1149
{
1150
   item_t *item = lookup_item(&tree_object, t, I_RANGES);
1,217,114✔
1151
   return obj_array_count(item->obj_array);
1,217,114✔
1152
}
1153

1154
unsigned tree_pos(tree_t t)
2,621,294✔
1155
{
1156
   return lookup_item(&tree_object, t, I_POS)->ival;
2,621,294✔
1157
}
1158

1159
void tree_set_pos(tree_t t, unsigned pos)
251,335✔
1160
{
1161
   lookup_item(&tree_object, t, I_POS)->ival = pos;
251,335✔
1162
}
251,335✔
1163

1164
tree_t tree_left(tree_t t)
2,056,231✔
1165
{
1166
   item_t *item = lookup_item(&tree_object, t, I_LEFT);
2,056,231✔
1167
   assert(item->object != NULL);
2,056,231✔
1168
   return container_of(item->object, struct _tree, object);
2,056,231✔
1169
}
1170

1171
void tree_set_left(tree_t t, tree_t left)
40,131✔
1172
{
1173
   tree_assert_expr(left);
40,131✔
1174
   lookup_item(&tree_object, t, I_LEFT)->object = &(left->object);
40,131✔
1175
   object_write_barrier(&(t->object), &(left->object));
40,131✔
1176
}
40,131✔
1177

1178
tree_t tree_right(tree_t t)
1,638,455✔
1179
{
1180
   item_t *item = lookup_item(&tree_object, t, I_RIGHT);
1,638,455✔
1181
   assert(item->object != NULL);
1,638,455✔
1182
   return container_of(item->object, struct _tree, object);
1,638,455✔
1183
}
1184

1185
void tree_set_right(tree_t t, tree_t right)
40,130✔
1186
{
1187
   tree_assert_expr(right);
40,130✔
1188
   lookup_item(&tree_object, t, I_RIGHT)->object = &(right->object);
40,130✔
1189
   object_write_barrier(&(t->object), &(right->object));
40,130✔
1190
}
40,130✔
1191

1192
class_t tree_class(tree_t t)
791,541✔
1193
{
1194
   return lookup_item(&tree_object, t, I_CLASS)->ival;
791,541✔
1195
}
1196

1197
void tree_set_class(tree_t t, class_t c)
49,558✔
1198
{
1199
   lookup_item(&tree_object, t, I_CLASS)->ival = c;
49,558✔
1200
}
49,558✔
1201

1202
tree_t tree_reject(tree_t t)
2,543✔
1203
{
1204
   item_t *item = lookup_item(&tree_object, t, I_REJECT);
2,543✔
1205
   assert(item->object != NULL);
2,543✔
1206
   return container_of(item->object, struct _tree, object);
2,543✔
1207
}
1208

1209
void tree_set_reject(tree_t t, tree_t r)
631✔
1210
{
1211
   tree_assert_expr(r);
631✔
1212
   lookup_item(&tree_object, t, I_REJECT)->object = &(r->object);
631✔
1213
   object_write_barrier(&(t->object), &(r->object));
631✔
1214
}
631✔
1215

1216
bool tree_has_reject(tree_t t)
27,012✔
1217
{
1218
   return lookup_item(&tree_object, t, I_REJECT)->object != NULL;
27,012✔
1219
}
1220

1221
tree_t tree_guard(tree_t t)
29✔
1222
{
1223
   item_t *item = lookup_item(&tree_object, t, I_GUARD);
29✔
1224
   assert(item->object != NULL);
29✔
1225
   return container_of(item->object, struct _tree, object);
29✔
1226
}
1227

1228
void tree_set_guard(tree_t t, tree_t g)
22✔
1229
{
1230
   assert(g->object.kind == T_GUARD);
22✔
1231
   lookup_item(&tree_object, t, I_GUARD)->object = &(g->object);
22✔
1232
   object_write_barrier(&(t->object), &(g->object));
22✔
1233
}
22✔
1234

1235
bool tree_has_guard(tree_t t)
4,206✔
1236
{
1237
   return lookup_item(&tree_object, t, I_GUARD)->object != NULL;
4,206✔
1238
}
1239

1240
tree_t tree_name(tree_t t)
492,574✔
1241
{
1242
   item_t *item = lookup_item(&tree_object, t, I_NAME);
492,574✔
1243
   assert(item->object != NULL);
492,574✔
1244
   return container_of(item->object, struct _tree, object);
492,574✔
1245
}
1246

1247
void tree_set_name(tree_t t, tree_t n)
38,486✔
1248
{
1249
   tree_assert_expr(n);
38,486✔
1250
   lookup_item(&tree_object, t, I_NAME)->object = &(n->object);
38,486✔
1251
   object_write_barrier(&(t->object), &(n->object));
38,486✔
1252
}
38,486✔
1253

1254
bool tree_has_name(tree_t t)
2,151✔
1255
{
1256
   return lookup_item(&tree_object, t, I_NAME)->object != NULL;
2,151✔
1257
}
1258

1259
tree_t tree_file_mode(tree_t t)
142✔
1260
{
1261
   item_t *item = lookup_item(&tree_object, t, I_FILE_MODE);
142✔
1262
   return container_of(item->object, struct _tree, object);
142✔
1263
}
1264

1265
void tree_set_file_mode(tree_t t, tree_t m)
47✔
1266
{
1267
   lookup_item(&tree_object, t, I_FILE_MODE)->object = &(m->object);
47✔
1268
   object_write_barrier(&(t->object), &(m->object));
47✔
1269
}
47✔
1270

1271
unsigned tree_visit(tree_t t, tree_visit_fn_t fn, void *context)
10,007✔
1272
{
1273
   return tree_visit_only(t, fn, context, T_LAST_TREE_KIND);
10,007✔
1274
}
1275

1276
unsigned tree_visit_only(tree_t t, tree_visit_fn_t fn,
11,231✔
1277
                         void *context, tree_kind_t kind)
1278
{
1279
   assert(t != NULL);
11,231✔
1280

1281
   object_visit_ctx_t ctx = {
11,231✔
1282
      .count      = 0,
1283
      .postorder  = (object_visit_fn_t)fn,
1284
      .preorder   = NULL,
1285
      .context    = context,
1286
      .kind       = kind,
1287
      .tag        = OBJECT_TAG_TREE,
1288
      .generation = object_next_generation(),
11,231✔
1289
      .deep       = false
1290
   };
1291

1292
   object_visit(&(t->object), &ctx);
11,231✔
1293

1294
   return ctx.count;
11,231✔
1295
}
1296

1297
tree_t tree_rewrite(tree_t t, tree_rewrite_pre_fn_t pre_fn,
30,010✔
1298
                    tree_rewrite_post_fn_t tree_post_fn,
1299
                    type_rewrite_post_fn_t type_post_fn,
1300
                    void *context)
1301
{
1302
   object_arena_t *arena = object_arena(&(t->object));
30,010✔
1303
   if (arena_frozen(arena))
30,010✔
1304
      return t;
1305

1306
   object_rewrite_ctx_t ctx = {
27,460✔
1307
      .generation = object_next_generation(),
27,460✔
1308
      .context    = context,
1309
      .arena      = arena,
1310
   };
1311

1312
   ctx.pre_fn[OBJECT_TAG_TREE] = (object_rewrite_pre_fn_t)pre_fn;
27,460✔
1313

1314
   ctx.post_fn[OBJECT_TAG_TREE] = (object_rewrite_post_fn_t)tree_post_fn;
27,460✔
1315
   ctx.post_fn[OBJECT_TAG_TYPE] = (object_rewrite_post_fn_t)type_post_fn;
27,460✔
1316

1317
   object_t *result = object_rewrite(&(t->object), &ctx);
27,460✔
1318
   free(ctx.cache);
27,457✔
1319
   return container_of(result, struct _tree, object);
27,457✔
1320
}
1321

1322
void tree_copy(tree_t *roots, unsigned nroots,
7,812✔
1323
               tree_copy_pred_t tree_pred,
1324
               type_copy_pred_t type_pred,
1325
               void *pred_context,
1326
               tree_copy_fn_t tree_callback,
1327
               type_copy_fn_t type_callback,
1328
               void *callback_context)
1329
{
1330
   object_copy_ctx_t *ctx LOCAL = xcalloc_flex(sizeof(object_copy_ctx_t),
15,624✔
1331
                                               nroots, sizeof(object_t *));
1332

1333
   ctx->generation       = object_next_generation();
7,812✔
1334
   ctx->pred_context     = pred_context;
7,812✔
1335
   ctx->callback_context = callback_context;
7,812✔
1336
   ctx->nroots           = nroots;
7,812✔
1337

1338
   for (unsigned i = 0; i < nroots; i++)
22,123✔
1339
      ctx->roots[i] = &(roots[i]->object);
14,311✔
1340

1341
   ctx->should_copy[OBJECT_TAG_TREE] = (object_copy_pred_t)tree_pred;
7,812✔
1342
   ctx->should_copy[OBJECT_TAG_TYPE] = (object_copy_pred_t)type_pred;
7,812✔
1343

1344
   ctx->callback[OBJECT_TAG_TREE] = (object_copy_fn_t)tree_callback;
7,812✔
1345
   ctx->callback[OBJECT_TAG_TYPE] = (object_copy_fn_t)type_callback;
7,812✔
1346

1347
   object_copy(ctx);
7,812✔
1348

1349
   for (unsigned i = 0; i < nroots; i++)
22,123✔
1350
      roots[i] = container_of(ctx->roots[i], struct _tree, object);
14,311✔
1351
}
7,812✔
1352

1353
const char *tree_kind_str(tree_kind_t t)
172✔
1354
{
1355
   return kind_text_map[t];
172✔
1356
}
1357

UNCOV
1358
object_arena_t *tree_arena(tree_t t)
×
1359
{
UNCOV
1360
   return object_arena(&(t->object));
×
1361
}
1362

1363
bool tree_frozen(tree_t t)
221✔
1364
{
1365
   return arena_frozen(object_arena(&(t->object)));
221✔
1366
}
1367

1368
tree_t tree_container(tree_t t)
55,310✔
1369
{
1370
   object_t *o = arena_root(object_arena(&(t->object)));
55,310✔
1371
   assert(o->tag == OBJECT_TAG_TREE);
55,310✔
1372
   return container_of(o, struct _tree, object);
55,310✔
1373
}
1374

1375
void tree_locus(tree_t t, ident_t *unit, ptrdiff_t *offset)
119,412✔
1376
{
1377
   assert(t != NULL);
119,412✔
1378
   object_locus(&(t->object), unit, offset);
119,412✔
1379
}
119,412✔
1380

1381
tree_t tree_from_locus(ident_t unit, ptrdiff_t offset,
3✔
1382
                       tree_load_fn_t find_deps_fn)
1383
{
1384
   object_t *o = object_from_locus(unit, offset,
3✔
1385
                                   (object_load_fn_t)find_deps_fn);
1386
   assert(o->tag == OBJECT_TAG_TREE);
3✔
1387
   return container_of(o, struct _tree, object);
3✔
1388
}
1389

1390
void tree_walk_deps(tree_t t, tree_deps_fn_t fn, void *ctx)
30,563✔
1391
{
1392
   object_arena_walk_deps(object_arena(&(t->object)), fn, ctx);
30,563✔
1393
}
30,563✔
1394

1395
int tree_stable_compar(const void *pa, const void *pb)
×
1396
{
UNCOV
1397
   tree_t a = *(tree_t *)pa;
×
1398
   tree_t b = *(tree_t *)pb;
×
1399

UNCOV
1400
   if (a == NULL)
×
1401
      return -1;
UNCOV
1402
   else if (b == NULL)
×
1403
      return 1;
1404
   else
UNCOV
1405
      return tree_loc(a)->first_line - tree_loc(b)->first_line;
×
1406
}
1407

1408
object_t *tree_to_object(tree_t t)
136,069✔
1409
{
1410
   return t ? &(t->object) : NULL;
136,069✔
1411
}
1412

1413
tree_t tree_from_object(object_t *obj)
289,436✔
1414
{
1415
   if (obj != NULL && obj->tag == OBJECT_TAG_TREE)
289,436✔
1416
      return container_of(obj, struct _tree, object);
1417
   else
1418
      return NULL;
549✔
1419
}
1420

1421
tree_global_flags_t tree_global_flags(tree_t t)
40,351✔
1422
{
1423
   return arena_flags(object_arena(&(t->object)));
40,351✔
1424
}
1425

1426
void tree_set_global_flags(tree_t t, tree_global_flags_t flags)
7,594✔
1427
{
1428
   arena_set_flags(object_arena(&(t->object)), flags);
7,594✔
1429
}
7,594✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc