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

nickg / nvc / 14179081493

31 Mar 2025 06:49PM UTC coverage: 92.319% (+0.03%) from 92.287%
14179081493

push

github

web-flow
Fix coverage report table sorting with N/A, #1179 (#1180)

68698 of 74414 relevant lines covered (92.32%)

420334.55 hits per line

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

96.45
/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
   // T_PSL_UNION
388
   (I_FOREIGN | I_TYPE)
389
};
390

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

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

454
struct _tree {
455
   object_t object;
456
};
457

458
struct _type {
459
   object_t object;
460
};
461

462
struct _psl_node {
463
   object_t object;
464
};
465

466
struct _vlog_node {
467
   object_t object;
468
};
469

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

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

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

506
static void tree_assert_kind(tree_t t, const tree_kind_t *list, size_t len,
381,566✔
507
                             const char *what)
508
{
509
   for (size_t i = 0; i < len; i++) {
4,623,780✔
510
      if (t->object.kind == list[i])
4,623,780✔
511
         return;
381,566✔
512
   }
513

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

520
static inline void tree_assert_expr(tree_t t)
144,661✔
521
{
522
   tree_assert_kind(t, expr_kinds, ARRAY_LEN(expr_kinds), "an expression");
144,661✔
523
}
144,661✔
524

525
static inline void tree_assert_decl(tree_t t)
236,905✔
526
{
527
   tree_assert_kind(t, decl_kinds, ARRAY_LEN(decl_kinds), "a declaration");
236,905✔
528
}
236,905✔
529

530
static inline tree_t tree_array_nth(item_t *item, unsigned n)
26,727,518✔
531
{
532
   object_t *o = obj_array_nth(item->obj_array, n);
26,727,518✔
533
   return container_of(o, struct _tree, object);
26,727,518✔
534
}
535

536
static inline void tree_array_add(item_t *item, tree_t t)
1,123,257✔
537
{
538
   obj_array_add(&(item->obj_array), &(t->object));
1,123,257✔
539
}
1,123,257✔
540

541
tree_t tree_new(tree_kind_t kind)
1,747,971✔
542
{
543
   object_t *o = object_new(NULL, &tree_object, kind);
1,747,971✔
544
   return container_of(o, struct _tree, object);
1,747,971✔
545
}
546

547
const loc_t *tree_loc(tree_t t)
1,718,561✔
548
{
549
   assert(t != NULL);
1,718,561✔
550
   return &t->object.loc;
1,718,561✔
551
}
552

553
void tree_set_loc(tree_t t, const loc_t *loc)
1,786,322✔
554
{
555
   assert(t != NULL);
1,786,322✔
556
   assert(loc != NULL);
1,786,322✔
557

558
   t->object.loc = *loc;
1,786,322✔
559
}
1,786,322✔
560

561
ident_t tree_ident(tree_t t)
29,754,495✔
562
{
563
   item_t *item = lookup_item(&tree_object, t, I_IDENT);
29,754,495✔
564
   assert(item->ident != NULL);
29,754,495✔
565
   return item->ident;
29,754,495✔
566
}
567

568
bool tree_has_ident(tree_t t)
12,355✔
569
{
570
   return lookup_item(&tree_object, t, I_IDENT)->ident != NULL;
12,355✔
571
}
572

573
void tree_set_ident(tree_t t, ident_t i)
1,193,396✔
574
{
575
   lookup_item(&tree_object, t, I_IDENT)->ident = i;
1,193,396✔
576
}
1,193,396✔
577

578
ident_t tree_ident2(tree_t t)
205,467✔
579
{
580
   item_t *item = lookup_item(&tree_object, t, I_IDENT2);
205,467✔
581
   assert(item->ident != NULL);
205,467✔
582
   return item->ident;
205,467✔
583
}
584

585
void tree_set_ident2(tree_t t, ident_t i)
126,559✔
586
{
587
   lookup_item(&tree_object, t, I_IDENT2)->ident = i;
126,559✔
588
}
126,559✔
589

590
bool tree_has_ident2(tree_t t)
73,814✔
591
{
592
   return lookup_item(&tree_object, t, I_IDENT2)->ident != NULL;
73,814✔
593
}
594

595
tree_kind_t tree_kind(tree_t t)
113,053,563✔
596
{
597
   assert(t != NULL);
113,053,563✔
598
   return t->object.kind;
113,053,563✔
599
}
600

601
void tree_change_kind(tree_t t, tree_kind_t kind)
23,604✔
602
{
603
   object_change_kind(&tree_object, &(t->object), kind);
23,604✔
604
}
23,604✔
605

606
unsigned tree_ports(tree_t t)
3,981,016✔
607
{
608
   item_t *item = lookup_item(&tree_object, t, I_PORTS);
3,981,016✔
609
   return obj_array_count(item->obj_array);
3,981,016✔
610
}
611

612
tree_t tree_port(tree_t t, unsigned n)
5,362,627✔
613
{
614
   item_t *item = lookup_item(&tree_object, t, I_PORTS);
5,362,627✔
615
   return tree_array_nth(item, n);
5,362,627✔
616
}
617

618
void tree_add_port(tree_t t, tree_t d)
110,653✔
619
{
620
   tree_assert_decl(d);
110,653✔
621
   tree_array_add(lookup_item(&tree_object, t, I_PORTS), d);
110,653✔
622
   object_write_barrier(&(t->object), &(d->object));
110,653✔
623
}
110,653✔
624

625
unsigned tree_subkind(tree_t t)
26,055,418✔
626
{
627
   item_t *item = lookup_item(&tree_object, t, I_SUBKIND);
26,055,418✔
628
   return item->ival;
26,055,418✔
629
}
630

631
void tree_set_subkind(tree_t t, unsigned sub)
701,746✔
632
{
633
   lookup_item(&tree_object, t, I_SUBKIND)->ival = sub;
701,746✔
634
}
701,746✔
635

636
unsigned tree_generics(tree_t t)
203,115✔
637
{
638
   item_t *item = lookup_item(&tree_object, t, I_GENERICS);
203,115✔
639
   return obj_array_count(item->obj_array);
203,115✔
640
}
641

642
tree_t tree_generic(tree_t t, unsigned n)
47,754✔
643
{
644
   item_t *item = lookup_item(&tree_object, t, I_GENERICS);
47,754✔
645
   return tree_array_nth(item, n);
47,754✔
646
}
647

648
void tree_add_generic(tree_t t, tree_t d)
9,969✔
649
{
650
   assert(d->object.kind == T_GENERIC_DECL);
9,969✔
651
   tree_array_add(lookup_item(&tree_object, t, I_GENERICS), d);
9,969✔
652
   object_write_barrier(&(t->object), &(d->object));
9,969✔
653
}
9,969✔
654

655
type_t tree_type(tree_t t)
32,614,944✔
656
{
657
   item_t *item = lookup_item(&tree_object, t, I_TYPE);
32,614,944✔
658
   assert(item->object != NULL);
32,614,944✔
659
   return container_of(item->object, struct _type, object);
32,614,944✔
660
}
661

662
void tree_set_type(tree_t t, type_t ty)
1,206,826✔
663
{
664
   object_t *obj = ty ? &(ty->object) : NULL;
1,206,826✔
665
   lookup_item(&tree_object, t, I_TYPE)->object = obj;
1,206,826✔
666
   object_write_barrier(&(t->object), obj);
1,206,826✔
667
}
1,206,826✔
668

669
bool tree_has_type(tree_t t)
4,725,994✔
670
{
671
   return lookup_item(&tree_object, t, I_TYPE)->object != NULL;
4,725,994✔
672
}
673

674
unsigned tree_params(tree_t t)
14,466,006✔
675
{
676
   item_t *item = lookup_item(&tree_object, t, I_PARAMS);
14,466,006✔
677
   return obj_array_count(item->obj_array);
14,466,006✔
678
}
679

680
tree_t tree_param(tree_t t, unsigned n)
15,052,078✔
681
{
682
   item_t *item = lookup_item(&tree_object, t, I_PARAMS);
15,052,078✔
683
   return tree_array_nth(item, n);
15,052,078✔
684
}
685

686
void tree_add_param(tree_t t, tree_t e)
217,757✔
687
{
688
   assert(e->object.kind == T_PARAM);
217,757✔
689
   tree_array_add(lookup_item(&tree_object, t, I_PARAMS), e);
217,757✔
690
   object_write_barrier(&(t->object), &(e->object));
217,757✔
691
}
217,757✔
692

693
unsigned tree_genmaps(tree_t t)
34,896✔
694
{
695
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
34,896✔
696
   return obj_array_count(item->obj_array);
34,896✔
697
}
698

699
tree_t tree_genmap(tree_t t, unsigned n)
34,319✔
700
{
701
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
34,319✔
702
   return tree_array_nth(item, n);
34,319✔
703
}
704

705
void tree_add_genmap(tree_t t, tree_t e)
9,847✔
706
{
707
   tree_array_add(lookup_item(&tree_object, t, I_GENMAPS), e);
9,847✔
708
}
9,847✔
709

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

718
int64_t tree_ival(tree_t t)
2,766,895✔
719
{
720
   return lookup_item(&tree_object, t, I_IVAL)->ival;
2,766,895✔
721
}
722

723
void tree_set_ival(tree_t t, int64_t i)
121,466✔
724
{
725
   lookup_item(&tree_object, t, I_IVAL)->ival = i;
121,466✔
726
}
121,466✔
727

728
double tree_dval(tree_t t)
219,906✔
729
{
730
   return lookup_item(&tree_object, t, I_DVAL)->dval;
219,906✔
731
}
732

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

738
tree_flags_t tree_flags(tree_t t)
17,372,309✔
739
{
740
   return lookup_item(&tree_object, t, I_FLAGS)->ival;
17,372,309✔
741
}
742

743
void tree_set_flag(tree_t t, tree_flags_t mask)
157,399✔
744
{
745
   lookup_item(&tree_object, t, I_FLAGS)->ival |= mask;
157,399✔
746
}
157,399✔
747

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

753
tree_t tree_primary(tree_t t)
52,604✔
754
{
755
   item_t *item = lookup_item(&tree_object, t, I_PRIMARY);
52,604✔
756
   assert(item->object != NULL);
52,604✔
757
   return container_of(item->object, struct _tree, object);
52,604✔
758
}
759

760
bool tree_has_primary(tree_t t)
5,863✔
761
{
762
   return lookup_item(&tree_object, t, I_PRIMARY)->object != NULL;
5,863✔
763
}
764

765
void tree_set_primary(tree_t t, tree_t unit)
6,052✔
766
{
767
   lookup_item(&tree_object, t, I_PRIMARY)->object = &(unit->object);
6,052✔
768
   object_write_barrier(&(t->object), &(unit->object));
6,052✔
769
}
6,052✔
770

771
psl_node_t tree_psl(tree_t t)
1,305✔
772
{
773
   item_t *item = lookup_item(&tree_object, t, I_FOREIGN);
1,305✔
774
   assert(item->object != NULL);
1,305✔
775
   return container_of(item->object, struct _psl_node, object);
1,305✔
776
}
777

778
void tree_set_psl(tree_t t, psl_node_t p)
543✔
779
{
780
   assert(p != NULL);
543✔
781
   lookup_item(&tree_object, t, I_FOREIGN)->object = &(p->object);
543✔
782
   object_write_barrier(&(t->object), &(p->object));
543✔
783
}
543✔
784

785
bool tree_has_psl(tree_t t)
×
786
{
787
   return lookup_item(&tree_object, t, I_FOREIGN)->object != NULL;
×
788
}
789

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

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

804
unsigned tree_chars(tree_t t)
125,985✔
805
{
806
   item_t *item = lookup_item(&tree_object, t, I_CHARS);
125,985✔
807
   return obj_array_count(item->obj_array);
125,985✔
808
}
809

810
tree_t tree_char(tree_t t, unsigned n)
975,129✔
811
{
812
   item_t *item = lookup_item(&tree_object, t, I_CHARS);
975,129✔
813
   return tree_array_nth(item, n);
975,129✔
814
}
815

816
void tree_add_char(tree_t t, tree_t ref)
360,976✔
817
{
818
   tree_array_add(lookup_item(&tree_object, t, I_CHARS), ref);
360,976✔
819
   object_write_barrier(&(t->object), &(ref->object));
360,976✔
820
}
360,976✔
821

822
unsigned tree_parts(tree_t t)
533✔
823
{
824
   item_t *item = lookup_item(&tree_object, t, I_PARTS);
533✔
825
   return obj_array_count(item->obj_array);
533✔
826
}
827

828
tree_t tree_part(tree_t t, unsigned n)
1,479✔
829
{
830
   item_t *item = lookup_item(&tree_object, t, I_PARTS);
1,479✔
831
   return tree_array_nth(item, n);
1,479✔
832
}
833

834
void tree_add_part(tree_t t, tree_t ref)
650✔
835
{
836
   tree_array_add(lookup_item(&tree_object, t, I_PARTS), ref);
650✔
837
   object_write_barrier(&(t->object), &(ref->object));
650✔
838
}
650✔
839

840
bool tree_has_value(tree_t t)
2,930,224✔
841
{
842
   return lookup_item(&tree_object, t, I_VALUE)->object != NULL;
2,930,224✔
843
}
844

845
tree_t tree_value(tree_t t)
16,494,457✔
846
{
847
   item_t *item = lookup_item(&tree_object, t, I_VALUE);
16,494,457✔
848
   assert(item->object != NULL);
16,494,457✔
849
   return container_of(item->object, struct _tree, object);
16,494,457✔
850
}
851

852
void tree_set_value(tree_t t, tree_t v)
392,312✔
853
{
854
   object_t *obj = v ? &(v->object) : NULL;
392,312✔
855
   lookup_item(&tree_object, t, I_VALUE)->object = obj;
392,312✔
856
   object_write_barrier(&(t->object), obj);
392,312✔
857
}
392,312✔
858

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

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

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

878
unsigned tree_decls(tree_t t)
103,450✔
879
{
880
   item_t *item = lookup_item(&tree_object, t, I_DECLS);
103,450✔
881
   return obj_array_count(item->obj_array);
103,450✔
882
}
883

884
tree_t tree_decl(tree_t t, unsigned n)
3,150,735✔
885
{
886
   item_t *item = lookup_item(&tree_object, t, I_DECLS);
3,150,735✔
887
   return tree_array_nth(item, n);
3,150,735✔
888
}
889

890
void tree_add_decl(tree_t t, tree_t d)
126,252✔
891
{
892
   tree_assert_decl(d);
126,252✔
893
   tree_array_add(lookup_item(&tree_object, t, I_DECLS), d);
126,252✔
894
   object_write_barrier(&(t->object), &(d->object));
126,252✔
895
}
126,252✔
896

897
unsigned tree_stmts(tree_t t)
136,715✔
898
{
899
   item_t *item = lookup_item(&tree_object, t, I_STMTS);
136,715✔
900
   return obj_array_count(item->obj_array);
136,715✔
901
}
902

903
tree_t tree_stmt(tree_t t, unsigned n)
195,442✔
904
{
905
   item_t *item = lookup_item(&tree_object, t, I_STMTS);
195,442✔
906
   return tree_array_nth(item, n);
195,442✔
907
}
908

909
void tree_add_stmt(tree_t t, tree_t s)
129,919✔
910
{
911
   assert(s != NULL);
129,919✔
912
   tree_array_add(lookup_item(&tree_object, t, I_STMTS), s);
129,919✔
913
   object_write_barrier(&(t->object), &(s->object));
129,919✔
914
}
129,919✔
915

916
unsigned tree_waveforms(tree_t t)
37,037✔
917
{
918
   item_t *item = lookup_item(&tree_object, t, I_WAVES);
37,037✔
919
   return obj_array_count(item->obj_array);
37,037✔
920
}
921

922
tree_t tree_waveform(tree_t t, unsigned n)
37,787✔
923
{
924
   item_t *item = lookup_item(&tree_object, t, I_WAVES);
37,787✔
925
   return tree_array_nth(item, n);
37,787✔
926
}
927

928
void tree_add_waveform(tree_t t, tree_t w)
7,750✔
929
{
930
   assert(w->object.kind == T_WAVEFORM);
7,750✔
931
   tree_array_add(lookup_item(&tree_object, t, I_WAVES), w);
7,750✔
932
   object_write_barrier(&(t->object), &(w->object));
7,750✔
933
}
7,750✔
934

935
unsigned tree_conds(tree_t t)
36,728✔
936
{
937
   item_t *item = lookup_item(&tree_object, t, I_CONDS);
36,728✔
938
   return obj_array_count(item->obj_array);
36,728✔
939
}
940

941
tree_t tree_cond(tree_t t, unsigned n)
51,416✔
942
{
943
   item_t *item = lookup_item(&tree_object, t, I_CONDS);
51,416✔
944
   return tree_array_nth(item, n);
51,416✔
945
}
946

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

954
bool tree_has_delay(tree_t t)
73,610✔
955
{
956
   return lookup_item(&tree_object, t, I_DELAY)->object != NULL;
73,610✔
957
}
958

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

966
void tree_set_delay(tree_t t, tree_t d)
5,978✔
967
{
968
   tree_assert_expr(d);
5,978✔
969
   lookup_item(&tree_object, t, I_DELAY)->object = &(d->object);
5,978✔
970
   object_write_barrier(&(t->object), &(d->object));
5,978✔
971
}
5,978✔
972

973
unsigned tree_triggers(tree_t t)
63,141✔
974
{
975
   item_t *item = lookup_item(&tree_object, t, I_TRIGGERS);
63,141✔
976
   return obj_array_count(item->obj_array);
63,141✔
977
}
978

979
tree_t tree_trigger(tree_t t, unsigned n)
9,641✔
980
{
981
   item_t *item = lookup_item(&tree_object, t, I_TRIGGERS);
9,641✔
982
   return tree_array_nth(item, n);
9,641✔
983
}
984

985
void tree_add_trigger(tree_t t, tree_t s)
4,029✔
986
{
987
   tree_assert_expr(s);
4,029✔
988
   tree_array_add(lookup_item(&tree_object, t, I_TRIGGERS), s);
4,029✔
989
   object_write_barrier(&(t->object), &(s->object));
4,029✔
990
}
4,029✔
991

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

999
void tree_set_target(tree_t t, tree_t lhs)
26,785✔
1000
{
1001
   lookup_item(&tree_object, t, I_TARGET)->object = &(lhs->object);
26,785✔
1002
   object_write_barrier(&(t->object), &(lhs->object));
26,785✔
1003
}
26,785✔
1004

1005
tree_t tree_ref(tree_t t)
18,750,720✔
1006
{
1007
   item_t *item = lookup_item(&tree_object, t, I_REF);
18,750,720✔
1008
   assert(item->object != NULL);
18,750,720✔
1009
   return container_of(item->object, struct _tree, object);
18,750,720✔
1010
}
1011

1012
bool tree_has_ref(tree_t t)
15,405,690✔
1013
{
1014
   return lookup_item(&tree_object, t, I_REF)->object != NULL;
15,405,690✔
1015
}
1016

1017
void tree_set_ref(tree_t t, tree_t decl)
1,094,393✔
1018
{
1019
   object_t *obj = decl ? &(decl->object) : NULL;
1,094,393✔
1020
   lookup_item(&tree_object, t, I_REF)->object = obj;
1,094,393✔
1021
   object_write_barrier(&(t->object), obj);
1,094,393✔
1022
}
1,094,393✔
1023

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

1031
bool tree_has_spec(tree_t t)
2,377✔
1032
{
1033
   return lookup_item(&tree_object, t, I_SPEC)->object != NULL;
2,377✔
1034
}
1035

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

1043
unsigned tree_contexts(tree_t t)
30,298✔
1044
{
1045
   item_t *item = lookup_item(&tree_object, t, I_CONTEXT);
30,298✔
1046
   return obj_array_count(item->obj_array);
30,298✔
1047
}
1048

1049
tree_t tree_context(tree_t t, unsigned n)
100,958✔
1050
{
1051
   item_t *item = lookup_item(&tree_object, t, I_CONTEXT);
100,958✔
1052
   return tree_array_nth(item, n);
100,958✔
1053
}
1054

1055
void tree_add_context(tree_t t, tree_t ctx)
41,094✔
1056
{
1057
   assert(ctx->object.kind == T_USE || ctx->object.kind == T_LIBRARY
41,094✔
1058
          || ctx->object.kind == T_CONTEXT_REF);
1059
   tree_array_add(lookup_item(&tree_object, t, I_CONTEXT), ctx);
41,094✔
1060
   object_write_barrier(&(t->object), &(ctx->object));
41,094✔
1061
}
41,094✔
1062

1063
unsigned tree_pragmas(tree_t t)
237✔
1064
{
1065
   item_t *item = lookup_item(&tree_object, t, I_PRAGMAS);
237✔
1066
   return obj_array_count(item->obj_array);
237✔
1067
}
1068

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

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

1082
unsigned tree_assocs(tree_t t)
119,723✔
1083
{
1084
   item_t *item = lookup_item(&tree_object, t, I_ASSOCS);
119,723✔
1085
   return obj_array_count(item->obj_array);
119,723✔
1086
}
1087

1088
tree_t tree_assoc(tree_t t, unsigned n)
439,012✔
1089
{
1090
   item_t *item = lookup_item(&tree_object, t, I_ASSOCS);
439,012✔
1091
   return tree_array_nth(item, n);
439,012✔
1092
}
1093

1094
void tree_add_assoc(tree_t t, tree_t a)
41,303✔
1095
{
1096
   assert(a->object.kind == T_ASSOC);
41,303✔
1097
   tree_array_add(lookup_item(&tree_object, t, I_ASSOCS), a);
41,303✔
1098
   object_write_barrier(&(t->object), &(a->object));
41,303✔
1099
}
41,303✔
1100

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

1108
void tree_set_severity(tree_t t, tree_t s)
6,423✔
1109
{
1110
   tree_assert_expr(s);
6,423✔
1111
   lookup_item(&tree_object, t, I_SEVERITY)->object = &(s->object);
6,423✔
1112
   object_write_barrier(&(t->object), &(s->object));
6,423✔
1113
}
6,423✔
1114

1115
bool tree_has_severity(tree_t t)
35,244✔
1116
{
1117
   return lookup_item(&tree_object, t, I_SEVERITY)->object != NULL;
35,244✔
1118
}
1119

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

1127
bool tree_has_message(tree_t t)
47,682✔
1128
{
1129
   return lookup_item(&tree_object, t, I_MESSAGE)->object != NULL;
47,682✔
1130
}
1131

1132
void tree_set_message(tree_t t, tree_t m)
8,335✔
1133
{
1134
   tree_assert_expr(m);
8,335✔
1135
   lookup_item(&tree_object, t, I_MESSAGE)->object = &(m->object);
8,335✔
1136
   object_write_barrier(&(t->object), &(m->object));
8,335✔
1137
}
8,335✔
1138

1139
void tree_add_range(tree_t t, tree_t r)
48,104✔
1140
{
1141
   tree_array_add(lookup_item(&tree_object, t, I_RANGES), r);
48,104✔
1142
   object_write_barrier(&(t->object), &(r->object));
48,104✔
1143
}
48,104✔
1144

1145
tree_t tree_range(tree_t t, unsigned n)
1,269,102✔
1146
{
1147
   item_t *item = lookup_item(&tree_object, t, I_RANGES);
1,269,102✔
1148
   return tree_array_nth(item, n);
1,269,102✔
1149
}
1150

1151
unsigned tree_ranges(tree_t t)
1,216,296✔
1152
{
1153
   item_t *item = lookup_item(&tree_object, t, I_RANGES);
1,216,296✔
1154
   return obj_array_count(item->obj_array);
1,216,296✔
1155
}
1156

1157
unsigned tree_pos(tree_t t)
2,625,686✔
1158
{
1159
   return lookup_item(&tree_object, t, I_POS)->ival;
2,625,686✔
1160
}
1161

1162
void tree_set_pos(tree_t t, unsigned pos)
251,867✔
1163
{
1164
   lookup_item(&tree_object, t, I_POS)->ival = pos;
251,867✔
1165
}
251,867✔
1166

1167
tree_t tree_left(tree_t t)
2,048,876✔
1168
{
1169
   item_t *item = lookup_item(&tree_object, t, I_LEFT);
2,048,876✔
1170
   assert(item->object != NULL);
2,048,876✔
1171
   return container_of(item->object, struct _tree, object);
2,048,876✔
1172
}
1173

1174
void tree_set_left(tree_t t, tree_t left)
40,252✔
1175
{
1176
   tree_assert_expr(left);
40,252✔
1177
   lookup_item(&tree_object, t, I_LEFT)->object = &(left->object);
40,252✔
1178
   object_write_barrier(&(t->object), &(left->object));
40,252✔
1179
}
40,252✔
1180

1181
tree_t tree_right(tree_t t)
1,634,026✔
1182
{
1183
   item_t *item = lookup_item(&tree_object, t, I_RIGHT);
1,634,026✔
1184
   assert(item->object != NULL);
1,634,026✔
1185
   return container_of(item->object, struct _tree, object);
1,634,026✔
1186
}
1187

1188
void tree_set_right(tree_t t, tree_t right)
40,251✔
1189
{
1190
   tree_assert_expr(right);
40,251✔
1191
   lookup_item(&tree_object, t, I_RIGHT)->object = &(right->object);
40,251✔
1192
   object_write_barrier(&(t->object), &(right->object));
40,251✔
1193
}
40,251✔
1194

1195
class_t tree_class(tree_t t)
792,530✔
1196
{
1197
   return lookup_item(&tree_object, t, I_CLASS)->ival;
792,530✔
1198
}
1199

1200
void tree_set_class(tree_t t, class_t c)
49,716✔
1201
{
1202
   lookup_item(&tree_object, t, I_CLASS)->ival = c;
49,716✔
1203
}
49,716✔
1204

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

1212
void tree_set_reject(tree_t t, tree_t r)
647✔
1213
{
1214
   tree_assert_expr(r);
647✔
1215
   lookup_item(&tree_object, t, I_REJECT)->object = &(r->object);
647✔
1216
   object_write_barrier(&(t->object), &(r->object));
647✔
1217
}
647✔
1218

1219
bool tree_has_reject(tree_t t)
27,215✔
1220
{
1221
   return lookup_item(&tree_object, t, I_REJECT)->object != NULL;
27,215✔
1222
}
1223

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

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

1238
bool tree_has_guard(tree_t t)
4,271✔
1239
{
1240
   return lookup_item(&tree_object, t, I_GUARD)->object != NULL;
4,271✔
1241
}
1242

1243
tree_t tree_name(tree_t t)
491,767✔
1244
{
1245
   item_t *item = lookup_item(&tree_object, t, I_NAME);
491,767✔
1246
   assert(item->object != NULL);
491,767✔
1247
   return container_of(item->object, struct _tree, object);
491,767✔
1248
}
1249

1250
void tree_set_name(tree_t t, tree_t n)
38,746✔
1251
{
1252
   tree_assert_expr(n);
38,746✔
1253
   lookup_item(&tree_object, t, I_NAME)->object = &(n->object);
38,746✔
1254
   object_write_barrier(&(t->object), &(n->object));
38,746✔
1255
}
38,746✔
1256

1257
bool tree_has_name(tree_t t)
2,169✔
1258
{
1259
   return lookup_item(&tree_object, t, I_NAME)->object != NULL;
2,169✔
1260
}
1261

1262
tree_t tree_file_mode(tree_t t)
150✔
1263
{
1264
   item_t *item = lookup_item(&tree_object, t, I_FILE_MODE);
150✔
1265
   return container_of(item->object, struct _tree, object);
150✔
1266
}
1267

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

1274
unsigned tree_visit(tree_t t, tree_visit_fn_t fn, void *context)
10,073✔
1275
{
1276
   return tree_visit_only(t, fn, context, T_LAST_TREE_KIND);
10,073✔
1277
}
1278

1279
unsigned tree_visit_only(tree_t t, tree_visit_fn_t fn,
11,297✔
1280
                         void *context, tree_kind_t kind)
1281
{
1282
   assert(t != NULL);
11,297✔
1283

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

1295
   object_visit(&(t->object), &ctx);
11,297✔
1296

1297
   return ctx.count;
11,297✔
1298
}
1299

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

1309
   object_rewrite_ctx_t ctx = {
27,938✔
1310
      .generation = object_next_generation(),
27,938✔
1311
      .context    = context,
1312
      .arena      = arena,
1313
   };
1314

1315
   ctx.pre_fn[OBJECT_TAG_TREE] = (object_rewrite_pre_fn_t)pre_fn;
27,938✔
1316

1317
   ctx.post_fn[OBJECT_TAG_TREE] = (object_rewrite_post_fn_t)tree_post_fn;
27,938✔
1318
   ctx.post_fn[OBJECT_TAG_TYPE] = (object_rewrite_post_fn_t)type_post_fn;
27,938✔
1319

1320
   object_t *result = object_rewrite(&(t->object), &ctx);
27,938✔
1321
   free(ctx.cache);
27,934✔
1322
   return container_of(result, struct _tree, object);
27,934✔
1323
}
1324

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

1336
   ctx->generation       = object_next_generation();
7,921✔
1337
   ctx->pred_context     = pred_context;
7,921✔
1338
   ctx->callback_context = callback_context;
7,921✔
1339
   ctx->nroots           = nroots;
7,921✔
1340

1341
   for (unsigned i = 0; i < nroots; i++)
22,448✔
1342
      ctx->roots[i] = &(roots[i]->object);
14,527✔
1343

1344
   ctx->should_copy[OBJECT_TAG_TREE] = (object_copy_pred_t)tree_pred;
7,921✔
1345
   ctx->should_copy[OBJECT_TAG_TYPE] = (object_copy_pred_t)type_pred;
7,921✔
1346

1347
   ctx->callback[OBJECT_TAG_TREE] = (object_copy_fn_t)tree_callback;
7,921✔
1348
   ctx->callback[OBJECT_TAG_TYPE] = (object_copy_fn_t)type_callback;
7,921✔
1349

1350
   object_copy(ctx);
7,921✔
1351

1352
   for (unsigned i = 0; i < nroots; i++)
22,448✔
1353
      roots[i] = container_of(ctx->roots[i], struct _tree, object);
14,527✔
1354
}
7,921✔
1355

1356
const char *tree_kind_str(tree_kind_t t)
168✔
1357
{
1358
   return kind_text_map[t];
168✔
1359
}
1360

1361
object_arena_t *tree_arena(tree_t t)
×
1362
{
1363
   return object_arena(&(t->object));
×
1364
}
1365

1366
bool tree_frozen(tree_t t)
188✔
1367
{
1368
   return arena_frozen(object_arena(&(t->object)));
188✔
1369
}
1370

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

1378
void tree_locus(tree_t t, ident_t *unit, ptrdiff_t *offset)
×
1379
{
1380
   assert(t != NULL);
×
1381
   object_locus(&(t->object), unit, offset);
×
1382
}
×
1383

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

1393
void tree_walk_deps(tree_t t, tree_deps_fn_t fn, void *ctx)
25,072✔
1394
{
1395
   arena_walk_deps(object_arena(&(t->object)), fn, ctx);
25,072✔
1396
}
25,072✔
1397

1398
int tree_stable_compar(const void *pa, const void *pb)
×
1399
{
1400
   tree_t a = *(tree_t *)pa;
×
1401
   tree_t b = *(tree_t *)pb;
×
1402

1403
   if (a == NULL)
×
1404
      return -1;
1405
   else if (b == NULL)
×
1406
      return 1;
1407
   else
1408
      return tree_loc(a)->first_line - tree_loc(b)->first_line;
×
1409
}
1410

1411
object_t *tree_to_object(tree_t t)
260,635✔
1412
{
1413
   return t ? &(t->object) : NULL;
260,635✔
1414
}
1415

1416
tree_t tree_from_object(object_t *obj)
283,152✔
1417
{
1418
   if (obj != NULL && obj->tag == OBJECT_TAG_TREE)
283,152✔
1419
      return container_of(obj, struct _tree, object);
1420
   else
1421
      return NULL;
1,048✔
1422
}
1423

1424
tree_global_flags_t tree_global_flags(tree_t t)
40,970✔
1425
{
1426
   return arena_flags(object_arena(&(t->object)));
40,970✔
1427
}
1428

1429
void tree_set_global_flags(tree_t t, tree_global_flags_t flags)
7,710✔
1430
{
1431
   arena_set_flags(object_arena(&(t->object)), flags);
7,710✔
1432
}
7,710✔
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