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

nickg / nvc / 21785110820

07 Feb 2026 06:50PM UTC coverage: 92.6% (-0.004%) from 92.604%
21785110820

push

github

nickg
Work around case where cloned layout may not match

4 of 4 new or added lines in 1 file covered. (100.0%)

146 existing lines in 6 files now uncovered.

76629 of 82753 relevant lines covered (92.6%)

441555.36 hits per line

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

99.26
/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_TYPE | 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_CHOICES | I_STMTS | I_DECLS),
332

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

336
   // T_VERILOG
337
   (I_IDENT | I_FOREIGN),
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),
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
   // T_PSL_UNION
388
   (I_FOREIGN | I_TYPE),
389

390
   // T_CHOICE
391
   (I_NAME | I_RANGES),
392
};
393

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

437
static const change_allowed_t change_allowed[] = {
438
   { T_REF,         T_FCALL         },
439
   { T_REF,         T_PCALL         },
440
   { T_ARRAY_REF,   T_FCALL         },
441
   { T_FCALL,       T_ARRAY_REF     },
442
   { T_PROT_FCALL,  T_ARRAY_REF     },
443
   { T_DESIGN_UNIT, T_ENTITY        },
444
   { T_DESIGN_UNIT, T_PACKAGE       },
445
   { T_DESIGN_UNIT, T_PACK_BODY     },
446
   { T_DESIGN_UNIT, T_ARCH          },
447
   { T_DESIGN_UNIT, T_CONFIGURATION },
448
   { T_DESIGN_UNIT, T_CONTEXT       },
449
   { T_DESIGN_UNIT, T_PACK_INST     },
450
   { T_FUNC_DECL,   T_FUNC_BODY     },
451
   { T_PROC_DECL,   T_PROC_BODY     },
452
   { T_FCALL,       T_PROT_FCALL    },
453
   { T_PCALL,       T_PROT_PCALL    },
454
   { -1,            -1              }
455
};
456

457
struct _tree {
458
   object_t object;
459
};
460

461
struct _type {
462
   object_t object;
463
};
464

465
struct _psl_node {
466
   object_t object;
467
};
468

469
struct _vlog_node {
470
   object_t object;
471
};
472

473
object_class_t tree_object = {
474
   .name           = "tree",
475
   .change_allowed = change_allowed,
476
   .has_map        = has_map,
477
   .kind_text_map  = kind_text_map,
478
   .tag            = OBJECT_TAG_TREE,
479
   .last_kind      = T_LAST_TREE_KIND,
480
   .has_loc        = true,
481
   .gc_roots       = { T_ARCH, T_ENTITY, T_PACKAGE, T_ELAB, T_PACK_BODY,
482
                       T_CONTEXT, T_CONFIGURATION, T_DESIGN_UNIT,
483
                       T_PACK_INST },
484
   .gc_num_roots   = 9
485
};
486

487
typedef struct {
488
   tree_deps_fn_t fn;
489
   void          *context;
490
} tree_deps_args_t;
491

492
#ifdef DEBUG
493
static tree_kind_t expr_kinds[] = {
494
   T_FCALL,     T_LITERAL,       T_REF,        T_QUALIFIED,
495
   T_AGGREGATE, T_ATTR_REF,      T_ARRAY_REF,  T_ARRAY_SLICE,
496
   T_TYPE_CONV, T_OPEN,          T_RECORD_REF, T_ALL,
497
   T_NEW,       T_PROT_FCALL,    T_CONV_FUNC,  T_TYPE_REF,
498
   T_BOX,       T_EXTERNAL_NAME, T_PROT_REF,   T_STRING,
499
};
500

501
static tree_kind_t decl_kinds[] = {
502
   T_PORT_DECL,      T_SIGNAL_DECL,    T_VAR_DECL,        T_TYPE_DECL,
503
   T_CONST_DECL,     T_FUNC_DECL,      T_FUNC_BODY,       T_ALIAS,
504
   T_ATTR_DECL,      T_ATTR_SPEC,      T_PROC_DECL,       T_PROC_BODY,
505
   T_COMPONENT,      T_FILE_DECL,      T_FIELD_DECL,      T_UNIT_DECL,
506
   T_HIER,           T_SPEC,           T_BINDING,         T_USE,
507
   T_PROT_BODY,      T_BLOCK_CONFIG,   T_IMPLICIT_SIGNAL, T_DISCONNECT,
508
   T_GROUP_TEMPLATE, T_GROUP,          T_SUBTYPE_DECL,    T_PACKAGE,
509
   T_PACK_BODY,      T_PACK_INST,      T_GENERIC_DECL,    T_PARAM_DECL,
510
   T_PROC_INST,      T_FUNC_INST,      T_PSL_DECL,        T_VIEW_DECL,
511
   T_PROT_DECL,      T_VERILOG,
512
};
513

514
static void tree_assert_kind(tree_t t, const tree_kind_t *list, size_t len,
415,226✔
515
                             const char *what)
516
{
517
   for (size_t i = 0; i < len; i++) {
5,125,468✔
518
      if (t->object.kind == list[i])
5,125,468✔
519
         return;
415,226✔
520
   }
521

522
   fatal_trace("tree kind %s is not %s", tree_kind_str(t->object.kind), what);
523
}
524
#else
525
#define tree_assert_kind(t, list, len, what)
526
#endif
527

528
static inline void tree_assert_expr(tree_t t)
157,238✔
529
{
530
   tree_assert_kind(t, expr_kinds, ARRAY_LEN(expr_kinds), "an expression");
157,238✔
531
}
157,238✔
532

533
static inline void tree_assert_decl(tree_t t)
257,988✔
534
{
535
   tree_assert_kind(t, decl_kinds, ARRAY_LEN(decl_kinds), "a declaration");
257,988✔
536
}
257,988✔
537

538
static inline tree_t tree_array_nth(item_t *item, unsigned n)
33,268,036✔
539
{
540
   object_t *o = obj_array_nth(item->obj_array, n);
33,268,036✔
541
   return container_of(o, struct _tree, object);
33,268,036✔
542
}
543

544
static inline void tree_array_add(item_t *item, tree_t t)
1,198,749✔
545
{
546
   obj_array_add(&(item->obj_array), &(t->object));
1,198,749✔
547
}
1,198,749✔
548

549
static inline void tree_copy_array(tree_t t, tree_t from, imask_t mask)
28,929✔
550
{
551
   item_t *dst = lookup_item(&tree_object, t, mask);
28,929✔
552
   const item_t *src = lookup_item(&tree_object, from, mask);
28,929✔
553
   if (src->obj_array == NULL)
28,929✔
554
      return;
555

556
   obj_array_copy(&(dst->obj_array), src->obj_array);
11,471✔
557

558
   for (int i = 0; i < src->obj_array->count; i++)
54,150✔
559
      object_write_barrier(&(t->object), src->obj_array->items[i]);
42,679✔
560
}
561

562
tree_t tree_new(tree_kind_t kind)
1,866,873✔
563
{
564
   object_t *o = object_new(NULL, &tree_object, kind);
1,866,873✔
565
   return container_of(o, struct _tree, object);
1,866,873✔
566
}
567

568
const loc_t *tree_loc(tree_t t)
2,347,841✔
569
{
570
   assert(t != NULL);
2,347,841✔
571
   return &t->object.loc;
2,347,841✔
572
}
573

574
void tree_set_loc(tree_t t, const loc_t *loc)
1,909,250✔
575
{
576
   assert(t != NULL);
1,909,250✔
577
   assert(loc != NULL);
1,909,250✔
578

579
   t->object.loc = *loc;
1,909,250✔
580
}
1,909,250✔
581

582
ident_t tree_ident(tree_t t)
30,454,035✔
583
{
584
   item_t *item = lookup_item(&tree_object, t, I_IDENT);
30,454,035✔
585
   assert(item->ident != NULL);
30,454,035✔
586
   return item->ident;
30,454,035✔
587
}
588

589
bool tree_has_ident(tree_t t)
11,315✔
590
{
591
   return lookup_item(&tree_object, t, I_IDENT)->ident != NULL;
11,315✔
592
}
593

594
void tree_set_ident(tree_t t, ident_t i)
1,271,396✔
595
{
596
   lookup_item(&tree_object, t, I_IDENT)->ident = i;
1,271,396✔
597
}
1,271,396✔
598

599
ident_t tree_ident2(tree_t t)
764,457✔
600
{
601
   item_t *item = lookup_item(&tree_object, t, I_IDENT2);
764,457✔
602
   assert(item->ident != NULL);
764,457✔
603
   return item->ident;
764,457✔
604
}
605

606
void tree_set_ident2(tree_t t, ident_t i)
135,815✔
607
{
608
   lookup_item(&tree_object, t, I_IDENT2)->ident = i;
135,815✔
609
}
135,815✔
610

611
bool tree_has_ident2(tree_t t)
78,840✔
612
{
613
   return lookup_item(&tree_object, t, I_IDENT2)->ident != NULL;
78,840✔
614
}
615

616
tree_kind_t tree_kind(tree_t t)
128,923,614✔
617
{
618
   assert(t != NULL);
128,923,614✔
619
   return t->object.kind;
128,923,614✔
620
}
621

622
void tree_change_kind(tree_t t, tree_kind_t kind)
25,278✔
623
{
624
   object_change_kind(&tree_object, &(t->object), kind);
25,278✔
625
}
25,278✔
626

627
unsigned tree_ports(tree_t t)
4,137,989✔
628
{
629
   item_t *item = lookup_item(&tree_object, t, I_PORTS);
4,137,989✔
630
   return obj_array_count(item->obj_array);
4,137,989✔
631
}
632

633
tree_t tree_port(tree_t t, unsigned n)
5,806,775✔
634
{
635
   item_t *item = lookup_item(&tree_object, t, I_PORTS);
5,806,775✔
636
   return tree_array_nth(item, n);
5,806,775✔
637
}
638

639
void tree_add_port(tree_t t, tree_t d)
119,987✔
640
{
641
   tree_assert_decl(d);
119,987✔
642
   tree_array_add(lookup_item(&tree_object, t, I_PORTS), d);
119,987✔
643
   object_write_barrier(&(t->object), &(d->object));
119,987✔
644
}
119,987✔
645

646
void tree_copy_ports(tree_t t, tree_t from)
5,598✔
647
{
648
   tree_copy_array(t, from, I_PORTS);
5,598✔
649
}
5,598✔
650

651
unsigned tree_subkind(tree_t t)
31,773,212✔
652
{
653
   item_t *item = lookup_item(&tree_object, t, I_SUBKIND);
31,773,212✔
654
   return item->ival;
31,773,212✔
655
}
656

657
void tree_set_subkind(tree_t t, unsigned sub)
745,668✔
658
{
659
   lookup_item(&tree_object, t, I_SUBKIND)->ival = sub;
745,668✔
660
}
745,668✔
661

662
unsigned tree_generics(tree_t t)
227,388✔
663
{
664
   item_t *item = lookup_item(&tree_object, t, I_GENERICS);
227,388✔
665
   return obj_array_count(item->obj_array);
227,388✔
666
}
667

668
tree_t tree_generic(tree_t t, unsigned n)
57,592✔
669
{
670
   item_t *item = lookup_item(&tree_object, t, I_GENERICS);
57,592✔
671
   return tree_array_nth(item, n);
57,592✔
672
}
673

674
void tree_add_generic(tree_t t, tree_t d)
11,060✔
675
{
676
   assert(d->object.kind == T_GENERIC_DECL);
11,060✔
677
   tree_array_add(lookup_item(&tree_object, t, I_GENERICS), d);
11,060✔
678
   object_write_barrier(&(t->object), &(d->object));
11,060✔
679
}
11,060✔
680

681
void tree_copy_generics(tree_t t, tree_t from)
418✔
682
{
683
   tree_copy_array(t, from, I_GENERICS);
418✔
684
}
418✔
685

686
type_t tree_type(tree_t t)
34,939,939✔
687
{
688
   item_t *item = lookup_item(&tree_object, t, I_TYPE);
34,939,939✔
689
   assert(item->object != NULL);
34,939,939✔
690
   return container_of(item->object, struct _type, object);
34,939,939✔
691
}
692

693
void tree_set_type(tree_t t, type_t ty)
1,290,948✔
694
{
695
   object_t *obj = ty ? &(ty->object) : NULL;
1,290,948✔
696
   lookup_item(&tree_object, t, I_TYPE)->object = obj;
1,290,948✔
697
   object_write_barrier(&(t->object), obj);
1,290,948✔
698
}
1,290,948✔
699

700
bool tree_has_type(tree_t t)
5,190,649✔
701
{
702
   return lookup_item(&tree_object, t, I_TYPE)->object != NULL;
5,190,649✔
703
}
704

705
unsigned tree_params(tree_t t)
14,769,501✔
706
{
707
   item_t *item = lookup_item(&tree_object, t, I_PARAMS);
14,769,501✔
708
   return obj_array_count(item->obj_array);
14,769,501✔
709
}
710

711
tree_t tree_param(tree_t t, unsigned n)
15,058,430✔
712
{
713
   item_t *item = lookup_item(&tree_object, t, I_PARAMS);
15,058,430✔
714
   return tree_array_nth(item, n);
15,058,430✔
715
}
716

717
void tree_add_param(tree_t t, tree_t e)
232,725✔
718
{
719
   assert(e->object.kind == T_PARAM);
232,725✔
720
   tree_array_add(lookup_item(&tree_object, t, I_PARAMS), e);
232,725✔
721
   object_write_barrier(&(t->object), &(e->object));
232,725✔
722
}
232,725✔
723

724
unsigned tree_genmaps(tree_t t)
59,131✔
725
{
726
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
59,131✔
727
   return obj_array_count(item->obj_array);
59,131✔
728
}
729

730
tree_t tree_genmap(tree_t t, unsigned n)
47,862✔
731
{
732
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
47,862✔
733
   return tree_array_nth(item, n);
47,862✔
734
}
735

736
void tree_add_genmap(tree_t t, tree_t e)
12,477✔
737
{
738
   tree_array_add(lookup_item(&tree_object, t, I_GENMAPS), e);
12,477✔
739
}
12,477✔
740

741
void tree_trim_genmaps(tree_t t, unsigned n)
5✔
742
{
743
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
5✔
744
   assert(n < obj_array_count(item->obj_array));
5✔
745
   assert(n > 0);
5✔
746
   item->obj_array->count = n;
5✔
747
}
5✔
748

749
int64_t tree_ival(tree_t t)
3,013,847✔
750
{
751
   return lookup_item(&tree_object, t, I_IVAL)->ival;
3,013,847✔
752
}
753

754
void tree_set_ival(tree_t t, int64_t i)
124,038✔
755
{
756
   lookup_item(&tree_object, t, I_IVAL)->ival = i;
124,038✔
757
}
124,038✔
758

759
double tree_dval(tree_t t)
271,147✔
760
{
761
   return lookup_item(&tree_object, t, I_DVAL)->dval;
271,147✔
762
}
763

764
void tree_set_dval(tree_t t, double d)
23,694✔
765
{
766
   lookup_item(&tree_object, t, I_DVAL)->dval = d;
23,694✔
767
}
23,694✔
768

769
tree_flags_t tree_flags(tree_t t)
18,151,563✔
770
{
771
   return lookup_item(&tree_object, t, I_FLAGS)->ival;
18,151,563✔
772
}
773

774
void tree_set_flag(tree_t t, tree_flags_t mask)
168,293✔
775
{
776
   lookup_item(&tree_object, t, I_FLAGS)->ival |= mask;
168,293✔
777
}
168,293✔
778

779
void tree_clear_flag(tree_t t, tree_flags_t mask)
673✔
780
{
781
   lookup_item(&tree_object, t, I_FLAGS)->ival &= ~mask;
673✔
782
}
673✔
783

784
tree_t tree_primary(tree_t t)
65,412✔
785
{
786
   item_t *item = lookup_item(&tree_object, t, I_PRIMARY);
65,412✔
787
   assert(item->object != NULL);
65,412✔
788
   return container_of(item->object, struct _tree, object);
65,412✔
789
}
790

791
bool tree_has_primary(tree_t t)
6,231✔
792
{
793
   return lookup_item(&tree_object, t, I_PRIMARY)->object != NULL;
6,231✔
794
}
795

796
void tree_set_primary(tree_t t, tree_t unit)
6,430✔
797
{
798
   lookup_item(&tree_object, t, I_PRIMARY)->object = &(unit->object);
6,430✔
799
   object_write_barrier(&(t->object), &(unit->object));
6,430✔
800
}
6,430✔
801

802
psl_node_t tree_psl(tree_t t)
1,432✔
803
{
804
   item_t *item = lookup_item(&tree_object, t, I_FOREIGN);
1,432✔
805
   assert(item->object != NULL);
1,432✔
806
   return container_of(item->object, struct _psl_node, object);
1,432✔
807
}
808

809
void tree_set_psl(tree_t t, psl_node_t p)
583✔
810
{
811
   assert(p != NULL);
583✔
812
   lookup_item(&tree_object, t, I_FOREIGN)->object = &(p->object);
583✔
813
   object_write_barrier(&(t->object), &(p->object));
583✔
814
}
583✔
815

816
bool tree_has_psl(tree_t t)
×
817
{
818
   return lookup_item(&tree_object, t, I_FOREIGN)->object != NULL;
×
819
}
820

821
vlog_node_t tree_vlog(tree_t t)
2,597✔
822
{
823
   item_t *item = lookup_item(&tree_object, t, I_FOREIGN);
2,597✔
824
   assert(item->object != NULL);
2,597✔
825
   return container_of(item->object, struct _vlog_node, object);
2,597✔
826
}
827

828
void tree_set_vlog(tree_t t, vlog_node_t v)
2,919✔
829
{
830
   assert(v != NULL);
2,919✔
831
   lookup_item(&tree_object, t, I_FOREIGN)->object = &(v->object);
2,919✔
832
   object_write_barrier(&(t->object), &(v->object));
2,919✔
833
}
2,919✔
834

835
unsigned tree_chars(tree_t t)
135,606✔
836
{
837
   item_t *item = lookup_item(&tree_object, t, I_CHARS);
135,606✔
838
   return obj_array_count(item->obj_array);
135,606✔
839
}
840

841
tree_t tree_char(tree_t t, unsigned n)
1,034,467✔
842
{
843
   item_t *item = lookup_item(&tree_object, t, I_CHARS);
1,034,467✔
844
   return tree_array_nth(item, n);
1,034,467✔
845
}
846

847
void tree_add_char(tree_t t, tree_t ref)
368,983✔
848
{
849
   tree_array_add(lookup_item(&tree_object, t, I_CHARS), ref);
368,983✔
850
   object_write_barrier(&(t->object), &(ref->object));
368,983✔
851
}
368,983✔
852

853
unsigned tree_parts(tree_t t)
859✔
854
{
855
   item_t *item = lookup_item(&tree_object, t, I_PARTS);
859✔
856
   return obj_array_count(item->obj_array);
859✔
857
}
858

859
tree_t tree_part(tree_t t, unsigned n)
2,272✔
860
{
861
   item_t *item = lookup_item(&tree_object, t, I_PARTS);
2,272✔
862
   return tree_array_nth(item, n);
2,272✔
863
}
864

865
void tree_add_part(tree_t t, tree_t ref)
653✔
866
{
867
   tree_array_add(lookup_item(&tree_object, t, I_PARTS), ref);
653✔
868
   object_write_barrier(&(t->object), &(ref->object));
653✔
869
}
653✔
870

871
bool tree_has_value(tree_t t)
3,282,194✔
872
{
873
   return lookup_item(&tree_object, t, I_VALUE)->object != NULL;
3,282,194✔
874
}
875

876
tree_t tree_value(tree_t t)
17,269,644✔
877
{
878
   item_t *item = lookup_item(&tree_object, t, I_VALUE);
17,269,644✔
879
   assert(item->object != NULL);
17,269,644✔
880
   return container_of(item->object, struct _tree, object);
17,269,644✔
881
}
882

883
void tree_set_value(tree_t t, tree_t v)
419,552✔
884
{
885
   object_t *obj = v ? &(v->object) : NULL;
419,552✔
886
   lookup_item(&tree_object, t, I_VALUE)->object = obj;
419,552✔
887
   object_write_barrier(&(t->object), obj);
419,552✔
888
}
419,552✔
889

890
bool tree_has_result(tree_t t)
330✔
891
{
892
   return lookup_item(&tree_object, t, I_RESULT)->object != NULL;
330✔
893
}
894

895
tree_t tree_result(tree_t t)
324✔
896
{
897
   item_t *item = lookup_item(&tree_object, t, I_RESULT);
324✔
898
   assert(item->object != NULL);
324✔
899
   return container_of(item->object, struct _tree, object);
324✔
900
}
901

902
void tree_set_result(tree_t t, tree_t v)
117✔
903
{
904
   object_t *obj = v ? &(v->object) : NULL;
117✔
905
   lookup_item(&tree_object, t, I_RESULT)->object = obj;
117✔
906
   object_write_barrier(&(t->object), obj);
117✔
907
}
117✔
908

909
unsigned tree_decls(tree_t t)
142,058✔
910
{
911
   item_t *item = lookup_item(&tree_object, t, I_DECLS);
142,058✔
912
   return obj_array_count(item->obj_array);
142,058✔
913
}
914

915
tree_t tree_decl(tree_t t, unsigned n)
8,006,871✔
916
{
917
   item_t *item = lookup_item(&tree_object, t, I_DECLS);
8,006,871✔
918
   return tree_array_nth(item, n);
8,006,871✔
919
}
920

921
void tree_add_decl(tree_t t, tree_t d)
138,001✔
922
{
923
   tree_assert_decl(d);
138,001✔
924
   tree_array_add(lookup_item(&tree_object, t, I_DECLS), d);
138,001✔
925
   object_write_barrier(&(t->object), &(d->object));
138,001✔
926
}
138,001✔
927

928
void tree_copy_decls(tree_t t, tree_t from)
11,409✔
929
{
930
   tree_copy_array(t, from, I_DECLS);
11,409✔
931
}
11,409✔
932

933
unsigned tree_stmts(tree_t t)
135,412✔
934
{
935
   item_t *item = lookup_item(&tree_object, t, I_STMTS);
135,412✔
936
   return obj_array_count(item->obj_array);
135,412✔
937
}
938

939
tree_t tree_stmt(tree_t t, unsigned n)
204,404✔
940
{
941
   item_t *item = lookup_item(&tree_object, t, I_STMTS);
204,404✔
942
   return tree_array_nth(item, n);
204,404✔
943
}
944

945
void tree_add_stmt(tree_t t, tree_t s)
138,279✔
946
{
947
   assert(s != NULL);
138,279✔
948
   tree_array_add(lookup_item(&tree_object, t, I_STMTS), s);
138,279✔
949
   object_write_barrier(&(t->object), &(s->object));
138,279✔
950
}
138,279✔
951

952
void tree_copy_stmts(tree_t t, tree_t from)
11,504✔
953
{
954
   tree_copy_array(t, from, I_STMTS);
11,504✔
955
}
11,504✔
956

957
unsigned tree_waveforms(tree_t t)
36,978✔
958
{
959
   item_t *item = lookup_item(&tree_object, t, I_WAVES);
36,978✔
960
   return obj_array_count(item->obj_array);
36,978✔
961
}
962

963
tree_t tree_waveform(tree_t t, unsigned n)
37,773✔
964
{
965
   item_t *item = lookup_item(&tree_object, t, I_WAVES);
37,773✔
966
   return tree_array_nth(item, n);
37,773✔
967
}
968

969
void tree_add_waveform(tree_t t, tree_t w)
8,281✔
970
{
971
   assert(w->object.kind == T_WAVEFORM);
8,281✔
972
   tree_array_add(lookup_item(&tree_object, t, I_WAVES), w);
8,281✔
973
   object_write_barrier(&(t->object), &(w->object));
8,281✔
974
}
8,281✔
975

976
unsigned tree_conds(tree_t t)
37,981✔
977
{
978
   item_t *item = lookup_item(&tree_object, t, I_CONDS);
37,981✔
979
   return obj_array_count(item->obj_array);
37,981✔
980
}
981

982
tree_t tree_cond(tree_t t, unsigned n)
53,021✔
983
{
984
   item_t *item = lookup_item(&tree_object, t, I_CONDS);
53,021✔
985
   return tree_array_nth(item, n);
53,021✔
986
}
987

988
void tree_add_cond(tree_t t, tree_t c)
16,103✔
989
{
990
   assert(c->object.kind == T_COND_STMT || c->object.kind == T_COND_EXPR);
16,103✔
991
   tree_array_add(lookup_item(&tree_object, t, I_CONDS), c);
16,103✔
992
   object_write_barrier(&(t->object), &(c->object));
16,103✔
993
}
16,103✔
994

995
bool tree_has_delay(tree_t t)
72,620✔
996
{
997
   return lookup_item(&tree_object, t, I_DELAY)->object != NULL;
72,620✔
998
}
999

1000
tree_t tree_delay(tree_t t)
19,808✔
1001
{
1002
   item_t *item = lookup_item(&tree_object, t, I_DELAY);
19,808✔
1003
   assert(item->object != NULL);
19,808✔
1004
   return container_of(item->object, struct _tree, object);
19,808✔
1005
}
1006

1007
void tree_set_delay(tree_t t, tree_t d)
6,476✔
1008
{
1009
   tree_assert_expr(d);
6,476✔
1010
   lookup_item(&tree_object, t, I_DELAY)->object = &(d->object);
6,476✔
1011
   object_write_barrier(&(t->object), &(d->object));
6,476✔
1012
}
6,476✔
1013

1014
unsigned tree_triggers(tree_t t)
58,624✔
1015
{
1016
   item_t *item = lookup_item(&tree_object, t, I_TRIGGERS);
58,624✔
1017
   return obj_array_count(item->obj_array);
58,624✔
1018
}
1019

1020
tree_t tree_trigger(tree_t t, unsigned n)
8,311✔
1021
{
1022
   item_t *item = lookup_item(&tree_object, t, I_TRIGGERS);
8,311✔
1023
   return tree_array_nth(item, n);
8,311✔
1024
}
1025

1026
void tree_add_trigger(tree_t t, tree_t s)
4,416✔
1027
{
1028
   tree_assert_expr(s);
4,416✔
1029
   tree_array_add(lookup_item(&tree_object, t, I_TRIGGERS), s);
4,416✔
1030
   object_write_barrier(&(t->object), &(s->object));
4,416✔
1031
}
4,416✔
1032

1033
tree_t tree_target(tree_t t)
106,552✔
1034
{
1035
   item_t *item = lookup_item(&tree_object, t, I_TARGET);
106,552✔
1036
   assert(item->object != NULL);
106,552✔
1037
   return container_of(item->object, struct _tree, object);
106,552✔
1038
}
1039

1040
void tree_set_target(tree_t t, tree_t lhs)
29,319✔
1041
{
1042
   lookup_item(&tree_object, t, I_TARGET)->object = &(lhs->object);
29,319✔
1043
   object_write_barrier(&(t->object), &(lhs->object));
29,319✔
1044
}
29,319✔
1045

1046
tree_t tree_ref(tree_t t)
19,898,367✔
1047
{
1048
   item_t *item = lookup_item(&tree_object, t, I_REF);
19,898,367✔
1049
   assert(item->object != NULL);
19,898,367✔
1050
   return container_of(item->object, struct _tree, object);
19,898,367✔
1051
}
1052

1053
bool tree_has_ref(tree_t t)
15,917,886✔
1054
{
1055
   return lookup_item(&tree_object, t, I_REF)->object != NULL;
15,917,886✔
1056
}
1057

1058
void tree_set_ref(tree_t t, tree_t decl)
1,162,944✔
1059
{
1060
   object_t *obj = decl ? &(decl->object) : NULL;
1,162,944✔
1061
   lookup_item(&tree_object, t, I_REF)->object = obj;
1,162,944✔
1062
   object_write_barrier(&(t->object), obj);
1,162,944✔
1063
}
1,162,944✔
1064

1065
tree_t tree_spec(tree_t t)
2,717✔
1066
{
1067
   item_t *item = lookup_item(&tree_object, t, I_SPEC);
2,717✔
1068
   assert(item->object != NULL);
2,717✔
1069
   return container_of(item->object, struct _tree, object);
2,717✔
1070
}
1071

1072
bool tree_has_spec(tree_t t)
16,790✔
1073
{
1074
   return lookup_item(&tree_object, t, I_SPEC)->object != NULL;
16,790✔
1075
}
1076

1077
void tree_set_spec(tree_t t, tree_t s)
327✔
1078
{
1079
   assert(s != NULL);
327✔
1080
   lookup_item(&tree_object, t, I_SPEC)->object = &(s->object);
327✔
1081
   object_write_barrier(&(t->object), &(s->object));
327✔
1082
}
327✔
1083

1084
unsigned tree_contexts(tree_t t)
29,719✔
1085
{
1086
   item_t *item = lookup_item(&tree_object, t, I_CONTEXT);
29,719✔
1087
   return obj_array_count(item->obj_array);
29,719✔
1088
}
1089

1090
tree_t tree_context(tree_t t, unsigned n)
99,330✔
1091
{
1092
   item_t *item = lookup_item(&tree_object, t, I_CONTEXT);
99,330✔
1093
   return tree_array_nth(item, n);
99,330✔
1094
}
1095

1096
void tree_add_context(tree_t t, tree_t ctx)
43,620✔
1097
{
1098
   assert(ctx->object.kind == T_USE || ctx->object.kind == T_LIBRARY
43,620✔
1099
          || ctx->object.kind == T_CONTEXT_REF);
1100
   tree_array_add(lookup_item(&tree_object, t, I_CONTEXT), ctx);
43,620✔
1101
   object_write_barrier(&(t->object), &(ctx->object));
43,620✔
1102
}
43,620✔
1103

1104
unsigned tree_pragmas(tree_t t)
410✔
1105
{
1106
   item_t *item = lookup_item(&tree_object, t, I_PRAGMAS);
410✔
1107
   return obj_array_count(item->obj_array);
410✔
1108
}
1109

1110
tree_t tree_pragma(tree_t t, unsigned n)
51✔
1111
{
1112
   item_t *item = lookup_item(&tree_object, t, I_PRAGMAS);
51✔
1113
   return tree_array_nth(item, n);
51✔
1114
}
1115

1116
void tree_add_pragma(tree_t t, tree_t p)
59✔
1117
{
1118
   assert(p->object.kind == T_PRAGMA);
59✔
1119
   tree_array_add(lookup_item(&tree_object, t, I_PRAGMAS), p);
59✔
1120
   object_write_barrier(&(t->object), &(p->object));
59✔
1121
}
59✔
1122

1123
unsigned tree_assocs(tree_t t)
202,928✔
1124
{
1125
   item_t *item = lookup_item(&tree_object, t, I_ASSOCS);
202,928✔
1126
   return obj_array_count(item->obj_array);
202,928✔
1127
}
1128

1129
tree_t tree_assoc(tree_t t, unsigned n)
1,108,992✔
1130
{
1131
   item_t *item = lookup_item(&tree_object, t, I_ASSOCS);
1,108,992✔
1132
   return tree_array_nth(item, n);
1,108,992✔
1133
}
1134

1135
void tree_add_assoc(tree_t t, tree_t a)
48,607✔
1136
{
1137
   assert(a->object.kind == T_ASSOC);
48,607✔
1138
   tree_array_add(lookup_item(&tree_object, t, I_ASSOCS), a);
48,607✔
1139
   object_write_barrier(&(t->object), &(a->object));
48,607✔
1140
}
48,607✔
1141

1142
unsigned tree_choices(tree_t t)
12,461✔
1143
{
1144
   item_t *item = lookup_item(&tree_object, t, I_CHOICES);
12,461✔
1145
   return obj_array_count(item->obj_array);
12,461✔
1146
}
1147

1148
tree_t tree_choice(tree_t t, unsigned n)
13,370✔
1149
{
1150
   item_t *item = lookup_item(&tree_object, t, I_CHOICES);
13,370✔
1151
   return tree_array_nth(item, n);
13,370✔
1152
}
1153

1154
void tree_add_choice(tree_t t, tree_t c)
3,990✔
1155
{
1156
   assert(c->object.kind == T_CHOICE);
3,990✔
1157
   tree_array_add(lookup_item(&tree_object, t, I_CHOICES), c);
3,990✔
1158
   object_write_barrier(&(t->object), &(c->object));
3,990✔
1159
}
3,990✔
1160

1161
tree_t tree_severity(tree_t t)
9,514✔
1162
{
1163
   item_t *item = lookup_item(&tree_object, t, I_SEVERITY);
9,514✔
1164
   assert(item->object != NULL);
9,514✔
1165
   return container_of(item->object, struct _tree, object);
9,514✔
1166
}
1167

1168
void tree_set_severity(tree_t t, tree_t s)
6,192✔
1169
{
1170
   tree_assert_expr(s);
6,192✔
1171
   lookup_item(&tree_object, t, I_SEVERITY)->object = &(s->object);
6,192✔
1172
   object_write_barrier(&(t->object), &(s->object));
6,192✔
1173
}
6,192✔
1174

1175
bool tree_has_severity(tree_t t)
36,314✔
1176
{
1177
   return lookup_item(&tree_object, t, I_SEVERITY)->object != NULL;
36,314✔
1178
}
1179

1180
tree_t tree_message(tree_t t)
14,067✔
1181
{
1182
   item_t *item = lookup_item(&tree_object, t, I_MESSAGE);
14,067✔
1183
   assert(item->object != NULL);
14,067✔
1184
   return container_of(item->object, struct _tree, object);
14,067✔
1185
}
1186

1187
bool tree_has_message(tree_t t)
49,028✔
1188
{
1189
   return lookup_item(&tree_object, t, I_MESSAGE)->object != NULL;
49,028✔
1190
}
1191

1192
void tree_set_message(tree_t t, tree_t m)
8,384✔
1193
{
1194
   tree_assert_expr(m);
8,384✔
1195
   lookup_item(&tree_object, t, I_MESSAGE)->object = &(m->object);
8,384✔
1196
   object_write_barrier(&(t->object), &(m->object));
8,384✔
1197
}
8,384✔
1198

1199
void tree_add_range(tree_t t, tree_t r)
51,508✔
1200
{
1201
   tree_array_add(lookup_item(&tree_object, t, I_RANGES), r);
51,508✔
1202
   object_write_barrier(&(t->object), &(r->object));
51,508✔
1203
}
51,508✔
1204

1205
tree_t tree_range(tree_t t, unsigned n)
1,728,515✔
1206
{
1207
   item_t *item = lookup_item(&tree_object, t, I_RANGES);
1,728,515✔
1208
   return tree_array_nth(item, n);
1,728,515✔
1209
}
1210

1211
unsigned tree_ranges(tree_t t)
1,676,550✔
1212
{
1213
   item_t *item = lookup_item(&tree_object, t, I_RANGES);
1,676,550✔
1214
   return obj_array_count(item->obj_array);
1,676,550✔
1215
}
1216

1217
unsigned tree_pos(tree_t t)
3,845,263✔
1218
{
1219
   return lookup_item(&tree_object, t, I_POS)->ival;
3,845,263✔
1220
}
1221

1222
void tree_set_pos(tree_t t, unsigned pos)
270,747✔
1223
{
1224
   lookup_item(&tree_object, t, I_POS)->ival = pos;
270,747✔
1225
}
270,747✔
1226

1227
tree_t tree_left(tree_t t)
2,609,547✔
1228
{
1229
   item_t *item = lookup_item(&tree_object, t, I_LEFT);
2,609,547✔
1230
   assert(item->object != NULL);
2,609,547✔
1231
   return container_of(item->object, struct _tree, object);
2,609,547✔
1232
}
1233

1234
void tree_set_left(tree_t t, tree_t left)
42,699✔
1235
{
1236
   tree_assert_expr(left);
42,699✔
1237
   lookup_item(&tree_object, t, I_LEFT)->object = &(left->object);
42,699✔
1238
   object_write_barrier(&(t->object), &(left->object));
42,699✔
1239
}
42,699✔
1240

1241
tree_t tree_right(tree_t t)
2,137,710✔
1242
{
1243
   item_t *item = lookup_item(&tree_object, t, I_RIGHT);
2,137,710✔
1244
   assert(item->object != NULL);
2,137,710✔
1245
   return container_of(item->object, struct _tree, object);
2,137,710✔
1246
}
1247

1248
void tree_set_right(tree_t t, tree_t right)
42,698✔
1249
{
1250
   tree_assert_expr(right);
42,698✔
1251
   lookup_item(&tree_object, t, I_RIGHT)->object = &(right->object);
42,698✔
1252
   object_write_barrier(&(t->object), &(right->object));
42,698✔
1253
}
42,698✔
1254

1255
class_t tree_class(tree_t t)
952,915✔
1256
{
1257
   return lookup_item(&tree_object, t, I_CLASS)->ival;
952,915✔
1258
}
1259

1260
void tree_set_class(tree_t t, class_t c)
123,453✔
1261
{
1262
   lookup_item(&tree_object, t, I_CLASS)->ival = c;
123,453✔
1263
}
123,453✔
1264

1265
tree_t tree_reject(tree_t t)
2,201✔
1266
{
1267
   item_t *item = lookup_item(&tree_object, t, I_REJECT);
2,201✔
1268
   assert(item->object != NULL);
2,201✔
1269
   return container_of(item->object, struct _tree, object);
2,201✔
1270
}
1271

1272
void tree_set_reject(tree_t t, tree_t r)
710✔
1273
{
1274
   tree_assert_expr(r);
710✔
1275
   lookup_item(&tree_object, t, I_REJECT)->object = &(r->object);
710✔
1276
   object_write_barrier(&(t->object), &(r->object));
710✔
1277
}
710✔
1278

1279
bool tree_has_reject(tree_t t)
25,417✔
1280
{
1281
   return lookup_item(&tree_object, t, I_REJECT)->object != NULL;
25,417✔
1282
}
1283

1284
tree_t tree_guard(tree_t t)
29✔
1285
{
1286
   item_t *item = lookup_item(&tree_object, t, I_GUARD);
29✔
1287
   assert(item->object != NULL);
29✔
1288
   return container_of(item->object, struct _tree, object);
29✔
1289
}
1290

1291
void tree_set_guard(tree_t t, tree_t g)
22✔
1292
{
1293
   assert(g->object.kind == T_GUARD);
22✔
1294
   lookup_item(&tree_object, t, I_GUARD)->object = &(g->object);
22✔
1295
   object_write_barrier(&(t->object), &(g->object));
22✔
1296
}
22✔
1297

1298
bool tree_has_guard(tree_t t)
4,527✔
1299
{
1300
   return lookup_item(&tree_object, t, I_GUARD)->object != NULL;
4,527✔
1301
}
1302

1303
tree_t tree_name(tree_t t)
523,535✔
1304
{
1305
   item_t *item = lookup_item(&tree_object, t, I_NAME);
523,535✔
1306
   assert(item->object != NULL);
523,535✔
1307
   return container_of(item->object, struct _tree, object);
523,535✔
1308
}
1309

1310
void tree_set_name(tree_t t, tree_t n)
45,663✔
1311
{
1312
   tree_assert_expr(n);
45,663✔
1313
   lookup_item(&tree_object, t, I_NAME)->object = &(n->object);
45,663✔
1314
   object_write_barrier(&(t->object), &(n->object));
45,663✔
1315
}
45,663✔
1316

1317
bool tree_has_name(tree_t t)
17,994✔
1318
{
1319
   return lookup_item(&tree_object, t, I_NAME)->object != NULL;
17,994✔
1320
}
1321

1322
tree_t tree_file_mode(tree_t t)
1,125✔
1323
{
1324
   item_t *item = lookup_item(&tree_object, t, I_FILE_MODE);
1,125✔
1325
   return container_of(item->object, struct _tree, object);
1,125✔
1326
}
1327

1328
void tree_set_file_mode(tree_t t, tree_t m)
53✔
1329
{
1330
   lookup_item(&tree_object, t, I_FILE_MODE)->object = &(m->object);
53✔
1331
   object_write_barrier(&(t->object), &(m->object));
53✔
1332
}
53✔
1333

1334
unsigned tree_visit(tree_t t, tree_visit_fn_t fn, void *context)
8,195✔
1335
{
1336
   return tree_visit_only(t, fn, context, T_LAST_TREE_KIND);
8,195✔
1337
}
1338

1339
unsigned tree_visit_only(tree_t t, tree_visit_fn_t fn,
9,388✔
1340
                         void *context, tree_kind_t kind)
1341
{
1342
   assert(t != NULL);
9,388✔
1343

1344
   object_visit_ctx_t ctx = {
9,388✔
1345
      .count      = 0,
1346
      .postorder  = (object_visit_fn_t)fn,
1347
      .preorder   = NULL,
1348
      .context    = context,
1349
      .kind       = kind,
1350
      .tag        = OBJECT_TAG_TREE,
1351
      .generation = object_next_generation(),
9,388✔
1352
      .deep       = false
1353
   };
1354

1355
   object_visit(&(t->object), &ctx);
9,388✔
1356

1357
   return ctx.count;
9,388✔
1358
}
1359

1360
tree_t tree_rewrite(tree_t t, tree_rewrite_pre_fn_t pre_fn,
29,905✔
1361
                    tree_rewrite_post_fn_t tree_post_fn,
1362
                    type_rewrite_post_fn_t type_post_fn,
1363
                    void *context)
1364
{
1365
   object_arena_t *arena = object_arena(&(t->object));
29,905✔
1366
   if (arena_frozen(arena))
29,905✔
1367
      return t;
1368

1369
   object_rewrite_ctx_t ctx = {
29,905✔
1370
      .generation = object_next_generation(),
29,905✔
1371
      .context    = context,
1372
      .arena      = arena,
1373
   };
1374

1375
   ctx.pre_fn[OBJECT_TAG_TREE] = (object_rewrite_pre_fn_t)pre_fn;
29,905✔
1376

1377
   ctx.post_fn[OBJECT_TAG_TREE] = (object_rewrite_post_fn_t)tree_post_fn;
29,905✔
1378
   ctx.post_fn[OBJECT_TAG_TYPE] = (object_rewrite_post_fn_t)type_post_fn;
29,905✔
1379

1380
   object_t *result = object_rewrite(&(t->object), &ctx);
29,905✔
1381
   free(ctx.cache);
29,901✔
1382
   return container_of(result, struct _tree, object);
29,901✔
1383
}
1384

1385
object_copy_ctx_t *tree_copy_begin(tree_t *roots, unsigned nroots,
5,879✔
1386
                                   tree_copy_pred_t tree_pred,
1387
                                   type_copy_pred_t type_pred,
1388
                                   void *pred_context,
1389
                                   tree_copy_fn_t tree_callback,
1390
                                   type_copy_fn_t type_callback,
1391
                                   void *callback_context)
1392
{
1393
   object_copy_ctx_t *ctx = xcalloc_flex(sizeof(object_copy_ctx_t),
5,879✔
1394
                                         nroots, sizeof(object_t *));
1395

1396
   ctx->generation       = object_next_generation();
5,879✔
1397
   ctx->pred_context     = pred_context;
5,879✔
1398
   ctx->callback_context = callback_context;
5,879✔
1399
   ctx->nroots           = nroots;
5,879✔
1400

1401
   for (unsigned i = 0; i < nroots; i++)
17,636✔
1402
      ctx->roots[i] = &(roots[i]->object);
11,757✔
1403

1404
   ctx->should_copy[OBJECT_TAG_TREE] = (object_copy_pred_t)tree_pred;
5,879✔
1405
   ctx->should_copy[OBJECT_TAG_TYPE] = (object_copy_pred_t)type_pred;
5,879✔
1406

1407
   ctx->callback[OBJECT_TAG_TREE] = (object_copy_fn_t)tree_callback;
5,879✔
1408
   ctx->callback[OBJECT_TAG_TYPE] = (object_copy_fn_t)type_callback;
5,879✔
1409

1410
   object_copy_begin(ctx);
5,879✔
1411

1412
   return ctx;
5,879✔
1413
}
1414

1415
void tree_copy_finish(tree_t *roots, unsigned nroots, object_copy_ctx_t *ctx)
5,879✔
1416
{
1417
   object_copy_finish(ctx);
5,879✔
1418

1419
   for (unsigned i = 0; i < nroots; i++)
17,636✔
1420
      roots[i] = container_of(ctx->roots[i], struct _tree, object);
11,757✔
1421

1422
   free(ctx);
5,879✔
1423
}
5,879✔
1424

1425
void tree_copy_mark(tree_t t, object_copy_ctx_t *ctx)
13,374✔
1426
{
1427
   object_copy_mark_root(&(t->object), ctx);
13,374✔
1428
}
13,374✔
1429

1430
const char *tree_kind_str(tree_kind_t t)
189✔
1431
{
1432
   return kind_text_map[t];
189✔
1433
}
1434

UNCOV
1435
object_arena_t *tree_arena(tree_t t)
×
1436
{
UNCOV
1437
   return object_arena(&(t->object));
×
1438
}
1439

1440
bool tree_frozen(tree_t t)
61,840✔
1441
{
1442
   return arena_frozen(object_arena(&(t->object)));
61,840✔
1443
}
1444

1445
tree_t tree_container(tree_t t)
19,728✔
1446
{
1447
   object_t *o = arena_root(object_arena(&(t->object)));
19,728✔
1448
   assert(o->tag == OBJECT_TAG_TREE);
19,728✔
1449
   return container_of(o, struct _tree, object);
19,728✔
1450
}
1451

1452
static void tree_deps_cb(object_t *obj, void *ctx)
57,422✔
1453
{
1454
   tree_deps_args_t *args = ctx;
57,422✔
1455
   tree_t t = tree_from_object(obj);
57,422✔
1456
   if (t != NULL)
57,422✔
1457
      (*args->fn)(t, args->context);
57,422✔
1458
}
57,422✔
1459

1460
void tree_walk_deps(tree_t t, tree_deps_fn_t fn, void *ctx)
32,817✔
1461
{
1462
   tree_deps_args_t args = { fn, ctx };
32,817✔
1463
   arena_walk_deps(object_arena(&(t->object)), tree_deps_cb, &args);
32,817✔
1464
}
32,817✔
1465

1466
object_t *tree_to_object(tree_t t)
897,630✔
1467
{
1468
   return t ? &(t->object) : NULL;
897,630✔
1469
}
1470

1471
tree_t tree_from_object(object_t *obj)
251,591✔
1472
{
1473
   if (obj != NULL && obj->tag == OBJECT_TAG_TREE)
251,591✔
1474
      return container_of(obj, struct _tree, object);
1475
   else
1476
      return NULL;
3,525✔
1477
}
1478

1479
tree_global_flags_t tree_global_flags(tree_t t)
53,717✔
1480
{
1481
   return arena_flags(object_arena(&(t->object)));
53,717✔
1482
}
1483

1484
void tree_set_global_flags(tree_t t, tree_global_flags_t flags)
7,224✔
1485
{
1486
   arena_set_flags(object_arena(&(t->object)), flags);
7,224✔
1487
}
7,224✔
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