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

nickg / nvc / 6604118477

22 Oct 2023 01:25PM UTC coverage: 91.218% (+0.3%) from 90.889%
6604118477

push

github

nickg
Generate unique name mangling for predefined functions

19 of 19 new or added lines in 5 files covered. (100.0%)

49523 of 54291 relevant lines covered (91.22%)

584870.41 hits per line

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

97.57
/src/tree.c
1
//
2
//  Copyright (C) 2011-2023  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_SIGNAL_ASSIGN
121
   (I_IDENT | I_TARGET | I_CONDS),
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_IDENT2),
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),
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),
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 | I_TRIGGERS),
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_GUARD | 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_TYPE),
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
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),
359

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

364
static const char *kind_text_map[T_LAST_TREE_KIND] = {
365
   "T_ENTITY",          "T_ARCH",            "T_PORT_DECL",
366
   "T_FCALL",           "T_LITERAL",         "T_SIGNAL_DECL",
367
   "T_VAR_DECL",        "T_PROCESS",         "T_REF",
368
   "T_WAIT",            "T_TYPE_DECL",       "T_VAR_ASSIGN",
369
   "T_PACKAGE",         "T_SIGNAL_ASSIGN",   "T_QUALIFIED",
370
   "T_ENUM_LIT",        "T_CONST_DECL",      "T_FUNC_DECL",
371
   "T_ELAB",            "T_AGGREGATE",       "T_ASSERT",
372
   "T_ATTR_REF",        "T_ARRAY_REF",       "T_ARRAY_SLICE",
373
   "T_INSTANCE",        "T_IF",              "T_NULL",
374
   "T_PACK_BODY",       "T_FUNC_BODY",       "T_RETURN",
375
   "T_COND_ASSIGN",     "T_WHILE",           "T_WAVEFORM",
376
   "T_ALIAS",           "T_FOR",             "T_ATTR_DECL",
377
   "T_ATTR_SPEC",       "T_PROC_DECL",       "T_PROC_BODY",
378
   "T_EXIT",            "T_PCALL",           "T_CASE",
379
   "T_BLOCK",           "T_COND_STMT",       "T_TYPE_CONV",
380
   "T_SELECT",          "T_COMPONENT",       "T_IF_GENERATE",
381
   "T_FOR_GENERATE",    "T_FILE_DECL",       "T_OPEN",
382
   "T_FIELD_DECL",      "T_RECORD_REF",      "T_ALL",
383
   "T_NEW",             "T_UNIT_DECL",       "T_NEXT",
384
   "T_PARAM",           "T_ASSOC",           "T_USE",
385
   "T_HIER",            "T_SPEC",            "T_BINDING",
386
   "T_LIBRARY",         "T_DESIGN_UNIT",     "T_CONFIGURATION",
387
   "T_PROT_BODY",       "T_CONTEXT",         "T_CONTEXT_REF",
388
   "T_CONSTRAINT",      "T_BLOCK_CONFIG",    "T_PROT_FCALL",
389
   "T_PROT_PCALL",      "T_RANGE",           "T_IMPLICIT_SIGNAL",
390
   "T_DISCONNECT",      "T_GROUP_TEMPLATE",  "T_GROUP",
391
   "T_SUBTYPE_DECL",    "T_CONV_FUNC",       "T_CONCURRENT",
392
   "T_SEQUENCE",        "T_PACK_INST",       "T_GENERIC_DECL",
393
   "T_TYPE_REF",        "T_BOX",             "T_PARAM_DECL",
394
   "T_EXTERNAL_NAME",   "T_FORCE",           "T_RELEASE",
395
   "T_PROT_REF",        "T_MATCH_CASE",      "T_FUNC_INST",
396
   "T_PROC_INST",       "T_ELEM_CONSTRAINT", "T_STRING",
397
   "T_PATH_ELT",        "T_PRAGMA",          "T_CASE_GENERATE",
398
   "T_ALTERNATIVE",     "T_PSL",             "T_VERILOG",
399
   "T_VIEW_DECL",       "T_PACKAGE_MAP",     "T_COND_EXPR",
400
   "T_COND_VALUE",      "T_COND_RETURN",     "T_VIEW_ELEMENT",
401
   "T_MATCH_SELECT",    "T_PROT_DECL",
402
};
403

404
static const change_allowed_t change_allowed[] = {
405
   { T_REF,         T_FCALL         },
406
   { T_REF,         T_PCALL         },
407
   { T_ARRAY_REF,   T_FCALL         },
408
   { T_FCALL,       T_ARRAY_REF     },
409
   { T_PROT_FCALL,  T_ARRAY_REF     },
410
   { T_DESIGN_UNIT, T_ENTITY        },
411
   { T_DESIGN_UNIT, T_PACKAGE       },
412
   { T_DESIGN_UNIT, T_PACK_BODY     },
413
   { T_DESIGN_UNIT, T_ARCH          },
414
   { T_DESIGN_UNIT, T_CONFIGURATION },
415
   { T_DESIGN_UNIT, T_CONTEXT       },
416
   { T_DESIGN_UNIT, T_PACK_INST     },
417
   { T_FUNC_DECL,   T_FUNC_BODY     },
418
   { T_PROC_DECL,   T_PROC_BODY     },
419
   { T_FCALL,       T_PROT_FCALL    },
420
   { T_PCALL,       T_PROT_PCALL    },
421
   { -1,            -1              }
422
};
423

424
struct _tree {
425
   object_t object;
426
};
427

428
struct _type {
429
   object_t object;
430
};
431

432
struct _psl_node {
433
   object_t object;
434
};
435

436
struct _vlog_node {
437
   object_t object;
438
};
439

440
static tree_kind_t expr_kinds[] = {
441
   T_FCALL,     T_LITERAL,       T_REF,        T_QUALIFIED,
442
   T_AGGREGATE, T_ATTR_REF,      T_ARRAY_REF,  T_ARRAY_SLICE,
443
   T_TYPE_CONV, T_OPEN,          T_RECORD_REF, T_ALL,
444
   T_NEW,       T_PROT_FCALL,    T_CONV_FUNC,  T_TYPE_REF,
445
   T_BOX,       T_EXTERNAL_NAME, T_PROT_REF,   T_STRING,
446
};
447

448
static tree_kind_t decl_kinds[] = {
449
   T_PORT_DECL,      T_SIGNAL_DECL,    T_VAR_DECL,        T_TYPE_DECL,
450
   T_CONST_DECL,     T_FUNC_DECL,      T_FUNC_BODY,       T_ALIAS,
451
   T_ATTR_DECL,      T_ATTR_SPEC,      T_PROC_DECL,       T_PROC_BODY,
452
   T_COMPONENT,      T_FILE_DECL,      T_FIELD_DECL,      T_UNIT_DECL,
453
   T_HIER,           T_SPEC,           T_BINDING,         T_USE,
454
   T_PROT_BODY,      T_BLOCK_CONFIG,   T_IMPLICIT_SIGNAL, T_DISCONNECT,
455
   T_GROUP_TEMPLATE, T_GROUP,          T_SUBTYPE_DECL,    T_PACKAGE,
456
   T_PACK_BODY,      T_PACK_INST,      T_GENERIC_DECL,    T_PARAM_DECL,
457
   T_PROC_INST,      T_FUNC_INST,      T_PSL,             T_VIEW_DECL,
458
   T_PROT_DECL,
459
};
460

461
object_class_t tree_object = {
462
   .name           = "tree",
463
   .change_allowed = change_allowed,
464
   .has_map        = has_map,
465
   .kind_text_map  = kind_text_map,
466
   .tag            = OBJECT_TAG_TREE,
467
   .last_kind      = T_LAST_TREE_KIND,
468
   .has_loc        = true,
469
   .gc_roots       = { T_ARCH, T_ENTITY, T_PACKAGE, T_ELAB, T_PACK_BODY,
470
                       T_CONTEXT, T_CONFIGURATION, T_DESIGN_UNIT,
471
                       T_PACK_INST },
472
   .gc_num_roots   = 9
473
};
474

475
static void tree_assert_kind(tree_t t, const tree_kind_t *list, size_t len,
476
                             const char *what)
477
{
478
#ifndef NDEBUG
479
   for (size_t i = 0; i < len; i++) {
480
      if (t->object.kind == list[i])
481
         return;
482
   }
483

484
   fatal_trace("tree kind %s is not %s", tree_kind_str(t->object.kind), what);
485
#endif
486
}
487

488
static inline void tree_assert_expr(tree_t t)
139,770✔
489
{
490
   tree_assert_kind(t, expr_kinds, ARRAY_LEN(expr_kinds), "an expression");
139,770✔
491
}
139,770✔
492

493
static inline void tree_assert_decl(tree_t t)
203,675✔
494
{
495
   tree_assert_kind(t, decl_kinds, ARRAY_LEN(decl_kinds), "a declaration");
203,675✔
496
}
203,675✔
497

498
static inline tree_t tree_array_nth(item_t *item, unsigned n)
499
{
500
   object_t *o = obj_array_nth(item->obj_array, n);
501
   return container_of(o, struct _tree, object);
502
}
503

504
static inline void tree_array_add(item_t *item, tree_t t)
999,871✔
505
{
506
   obj_array_add(&(item->obj_array), &(t->object));
999,871✔
507
}
999,871✔
508

509
tree_t tree_new(tree_kind_t kind)
1,582,700✔
510
{
511
   object_t *o = object_new(NULL, &tree_object, kind);
1,582,700✔
512
   return container_of(o, struct _tree, object);
1,582,700✔
513
}
514

515
const loc_t *tree_loc(tree_t t)
1,772,770✔
516
{
517
   assert(t != NULL);
1,772,770✔
518
   return &t->object.loc;
1,772,770✔
519
}
520

521
void tree_set_loc(tree_t t, const loc_t *loc)
1,610,550✔
522
{
523
   assert(t != NULL);
1,610,550✔
524
   assert(loc != NULL);
1,610,550✔
525

526
   t->object.loc = *loc;
1,610,550✔
527
}
1,610,550✔
528

529
ident_t tree_ident(tree_t t)
37,436,800✔
530
{
531
   item_t *item = lookup_item(&tree_object, t, I_IDENT);
37,436,800✔
532
   assert(item->ident != NULL);
37,436,800✔
533
   return item->ident;
37,436,800✔
534
}
535

536
bool tree_has_ident(tree_t t)
1,815,190✔
537
{
538
   return lookup_item(&tree_object, t, I_IDENT)->ident != NULL;
1,815,190✔
539
}
540

541
void tree_set_ident(tree_t t, ident_t i)
1,081,700✔
542
{
543
   lookup_item(&tree_object, t, I_IDENT)->ident = i;
1,081,700✔
544
}
1,081,700✔
545

546
ident_t tree_ident2(tree_t t)
153,467✔
547
{
548
   item_t *item = lookup_item(&tree_object, t, I_IDENT2);
153,467✔
549
   assert(item->ident != NULL);
153,467✔
550
   return item->ident;
153,467✔
551
}
552

553
void tree_set_ident2(tree_t t, ident_t i)
110,167✔
554
{
555
   lookup_item(&tree_object, t, I_IDENT2)->ident = i;
110,167✔
556
}
110,167✔
557

558
bool tree_has_ident2(tree_t t)
63,649✔
559
{
560
   return lookup_item(&tree_object, t, I_IDENT2)->ident != NULL;
63,649✔
561
}
562

563
tree_kind_t tree_kind(tree_t t)
105,573,000✔
564
{
565
   assert(t != NULL);
105,573,000✔
566
   return t->object.kind;
105,573,000✔
567
}
568

569
void tree_change_kind(tree_t t, tree_kind_t kind)
20,341✔
570
{
571
   object_change_kind(&tree_object, &(t->object), kind);
20,341✔
572
}
20,341✔
573

574
unsigned tree_ports(tree_t t)
3,843,260✔
575
{
576
   item_t *item = lookup_item(&tree_object, t, I_PORTS);
3,843,260✔
577
   return obj_array_count(item->obj_array);
3,843,260✔
578
}
579

580
tree_t tree_port(tree_t t, unsigned n)
5,135,570✔
581
{
582
   item_t *item = lookup_item(&tree_object, t, I_PORTS);
5,135,570✔
583
   return tree_array_nth(item, n);
5,135,570✔
584
}
585

586
void tree_add_port(tree_t t, tree_t d)
96,268✔
587
{
588
   tree_assert_decl(d);
96,268✔
589
   tree_array_add(lookup_item(&tree_object, t, I_PORTS), d);
96,268✔
590
   object_write_barrier(&(t->object), &(d->object));
96,268✔
591
}
96,268✔
592

593
unsigned tree_subkind(tree_t t)
23,747,000✔
594
{
595
   item_t *item = lookup_item(&tree_object, t, I_SUBKIND);
23,747,000✔
596
   return item->ival;
23,747,000✔
597
}
598

599
void tree_set_subkind(tree_t t, unsigned sub)
621,773✔
600
{
601
   lookup_item(&tree_object, t, I_SUBKIND)->ival = sub;
621,773✔
602
}
621,773✔
603

604
unsigned tree_generics(tree_t t)
177,503✔
605
{
606
   item_t *item = lookup_item(&tree_object, t, I_GENERICS);
177,503✔
607
   return obj_array_count(item->obj_array);
177,503✔
608
}
609

610
tree_t tree_generic(tree_t t, unsigned n)
24,750✔
611
{
612
   item_t *item = lookup_item(&tree_object, t, I_GENERICS);
24,750✔
613
   return tree_array_nth(item, n);
24,750✔
614
}
615

616
void tree_add_generic(tree_t t, tree_t d)
6,146✔
617
{
618
   assert(d->object.kind == T_GENERIC_DECL);
6,146✔
619
   tree_array_add(lookup_item(&tree_object, t, I_GENERICS), d);
6,146✔
620
   object_write_barrier(&(t->object), &(d->object));
6,146✔
621
}
6,146✔
622

623
type_t tree_type(tree_t t)
32,658,000✔
624
{
625
   item_t *item = lookup_item(&tree_object, t, I_TYPE);
32,658,000✔
626
   assert(item->object != NULL);
32,658,000✔
627
   return container_of(item->object, struct _type, object);
32,658,000✔
628
}
629

630
void tree_set_type(tree_t t, type_t ty)
1,195,980✔
631
{
632
   object_t *obj = ty ? &(ty->object) : NULL;
1,195,980✔
633
   lookup_item(&tree_object, t, I_TYPE)->object = obj;
1,195,980✔
634
   object_write_barrier(&(t->object), obj);
1,195,980✔
635
}
1,195,980✔
636

637
bool tree_has_type(tree_t t)
2,921,780✔
638
{
639
   return lookup_item(&tree_object, t, I_TYPE)->object != NULL;
2,921,780✔
640
}
641

642
unsigned tree_params(tree_t t)
14,314,400✔
643
{
644
   item_t *item = lookup_item(&tree_object, t, I_PARAMS);
14,314,400✔
645
   return obj_array_count(item->obj_array);
14,314,400✔
646
}
647

648
tree_t tree_param(tree_t t, unsigned n)
14,806,300✔
649
{
650
   item_t *item = lookup_item(&tree_object, t, I_PARAMS);
14,806,300✔
651
   return tree_array_nth(item, n);
14,806,300✔
652
}
653

654
void tree_add_param(tree_t t, tree_t e)
193,164✔
655
{
656
   assert(e->object.kind == T_PARAM);
193,164✔
657
   tree_array_add(lookup_item(&tree_object, t, I_PARAMS), e);
193,164✔
658
   object_write_barrier(&(t->object), &(e->object));
193,164✔
659
}
193,164✔
660

661
unsigned tree_genmaps(tree_t t)
24,563✔
662
{
663
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
24,563✔
664
   return obj_array_count(item->obj_array);
24,563✔
665
}
666

667
tree_t tree_genmap(tree_t t, unsigned n)
18,990✔
668
{
669
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
18,990✔
670
   return tree_array_nth(item, n);
18,990✔
671
}
672

673
void tree_add_genmap(tree_t t, tree_t e)
5,394✔
674
{
675
   tree_array_add(lookup_item(&tree_object, t, I_GENMAPS), e);
5,394✔
676
}
5,394✔
677

678
void tree_trim_genmaps(tree_t t, unsigned n)
5✔
679
{
680
   item_t *item = lookup_item(&tree_object, t, I_GENMAPS);
5✔
681
   assert(n < obj_array_count(item->obj_array));
5✔
682
   assert(n > 0);
5✔
683
   item->obj_array->count = n;
5✔
684
}
5✔
685

686
int64_t tree_ival(tree_t t)
2,079,930✔
687
{
688
   return lookup_item(&tree_object, t, I_IVAL)->ival;
2,079,930✔
689
}
690

691
void tree_set_ival(tree_t t, int64_t i)
100,867✔
692
{
693
   lookup_item(&tree_object, t, I_IVAL)->ival = i;
100,867✔
694
}
100,867✔
695

696
double tree_dval(tree_t t)
157,972✔
697
{
698
   return lookup_item(&tree_object, t, I_DVAL)->dval;
157,972✔
699
}
700

701
void tree_set_dval(tree_t t, double d)
22,241✔
702
{
703
   lookup_item(&tree_object, t, I_DVAL)->dval = d;
22,241✔
704
}
22,241✔
705

706
tree_flags_t tree_flags(tree_t t)
14,442,200✔
707
{
708
   return lookup_item(&tree_object, t, I_FLAGS)->ival;
14,442,200✔
709
}
710

711
void tree_set_flag(tree_t t, tree_flags_t mask)
115,530✔
712
{
713
   lookup_item(&tree_object, t, I_FLAGS)->ival |= mask;
115,530✔
714
}
115,530✔
715

716
void tree_clear_flag(tree_t t, tree_flags_t mask)
1,870✔
717
{
718
   lookup_item(&tree_object, t, I_FLAGS)->ival &= ~mask;
1,870✔
719
}
1,870✔
720

721
tree_t tree_primary(tree_t t)
26,145✔
722
{
723
   item_t *item = lookup_item(&tree_object, t, I_PRIMARY);
26,145✔
724
   assert(item->object != NULL);
26,145✔
725
   return container_of(item->object, struct _tree, object);
26,145✔
726
}
727

728
bool tree_has_primary(tree_t t)
4,750✔
729
{
730
   return lookup_item(&tree_object, t, I_PRIMARY)->object != NULL;
4,750✔
731
}
732

733
void tree_set_primary(tree_t t, tree_t unit)
4,925✔
734
{
735
   lookup_item(&tree_object, t, I_PRIMARY)->object = &(unit->object);
4,925✔
736
   object_write_barrier(&(t->object), &(unit->object));
4,925✔
737
}
4,925✔
738

739
psl_node_t tree_psl(tree_t t)
445✔
740
{
741
   item_t *item = lookup_item(&tree_object, t, I_FOREIGN);
445✔
742
   assert(item->object != NULL);
445✔
743
   return container_of(item->object, struct _psl_node, object);
445✔
744
}
745

746
void tree_set_psl(tree_t t, psl_node_t p)
204✔
747
{
748
   assert(p != NULL);
204✔
749
   lookup_item(&tree_object, t, I_FOREIGN)->object = &(p->object);
204✔
750
   object_write_barrier(&(t->object), &(p->object));
204✔
751
}
204✔
752

753
bool tree_has_psl(tree_t t)
5✔
754
{
755
   return lookup_item(&tree_object, t, I_FOREIGN)->object != NULL;
5✔
756
}
757

758
vlog_node_t tree_vlog(tree_t t)
53✔
759
{
760
   item_t *item = lookup_item(&tree_object, t, I_FOREIGN);
53✔
761
   assert(item->object != NULL);
53✔
762
   return container_of(item->object, struct _vlog_node, object);
53✔
763
}
764

765
void tree_set_vlog(tree_t t, vlog_node_t v)
38✔
766
{
767
   assert(v != NULL);
38✔
768
   lookup_item(&tree_object, t, I_FOREIGN)->object = &(v->object);
38✔
769
   object_write_barrier(&(t->object), &(v->object));
38✔
770
}
38✔
771

772
unsigned tree_chars(tree_t t)
118,410✔
773
{
774
   item_t *item = lookup_item(&tree_object, t, I_CHARS);
118,410✔
775
   return obj_array_count(item->obj_array);
118,410✔
776
}
777

778
tree_t tree_char(tree_t t, unsigned n)
945,035✔
779
{
780
   item_t *item = lookup_item(&tree_object, t, I_CHARS);
945,035✔
781
   return tree_array_nth(item, n);
945,035✔
782
}
783

784
void tree_add_char(tree_t t, tree_t ref)
340,638✔
785
{
786
   tree_array_add(lookup_item(&tree_object, t, I_CHARS), ref);
340,638✔
787
   object_write_barrier(&(t->object), &(ref->object));
340,638✔
788
}
340,638✔
789

790
unsigned tree_parts(tree_t t)
283✔
791
{
792
   item_t *item = lookup_item(&tree_object, t, I_PARTS);
283✔
793
   return obj_array_count(item->obj_array);
283✔
794
}
795

796
tree_t tree_part(tree_t t, unsigned n)
1,100✔
797
{
798
   item_t *item = lookup_item(&tree_object, t, I_PARTS);
1,100✔
799
   return tree_array_nth(item, n);
1,100✔
800
}
801

802
void tree_add_part(tree_t t, tree_t ref)
315✔
803
{
804
   tree_array_add(lookup_item(&tree_object, t, I_PARTS), ref);
315✔
805
   object_write_barrier(&(t->object), &(ref->object));
315✔
806
}
315✔
807

808
bool tree_has_value(tree_t t)
2,867,160✔
809
{
810
   return lookup_item(&tree_object, t, I_VALUE)->object != NULL;
2,867,160✔
811
}
812

813
tree_t tree_value(tree_t t)
15,983,800✔
814
{
815
   item_t *item = lookup_item(&tree_object, t, I_VALUE);
15,983,800✔
816
   assert(item->object != NULL);
15,983,800✔
817
   return container_of(item->object, struct _tree, object);
15,983,800✔
818
}
819

820
void tree_set_value(tree_t t, tree_t v)
352,357✔
821
{
822
   object_t *obj = v ? &(v->object) : NULL;
352,357✔
823
   lookup_item(&tree_object, t, I_VALUE)->object = obj;
352,357✔
824
   object_write_barrier(&(t->object), obj);
352,357✔
825
}
352,357✔
826

827
bool tree_has_result(tree_t t)
295✔
828
{
829
   return lookup_item(&tree_object, t, I_RESULT)->object != NULL;
295✔
830
}
831

832
tree_t tree_result(tree_t t)
280✔
833
{
834
   item_t *item = lookup_item(&tree_object, t, I_RESULT);
280✔
835
   assert(item->object != NULL);
280✔
836
   return container_of(item->object, struct _tree, object);
280✔
837
}
838

839
void tree_set_result(tree_t t, tree_t v)
104✔
840
{
841
   object_t *obj = v ? &(v->object) : NULL;
104✔
842
   lookup_item(&tree_object, t, I_RESULT)->object = obj;
104✔
843
   object_write_barrier(&(t->object), obj);
104✔
844
}
104✔
845

846
unsigned tree_decls(tree_t t)
146,774✔
847
{
848
   item_t *item = lookup_item(&tree_object, t, I_DECLS);
146,774✔
849
   return obj_array_count(item->obj_array);
146,774✔
850
}
851

852
tree_t tree_decl(tree_t t, unsigned n)
5,484,960✔
853
{
854
   item_t *item = lookup_item(&tree_object, t, I_DECLS);
5,484,960✔
855
   return tree_array_nth(item, n);
5,484,960✔
856
}
857

858
void tree_add_decl(tree_t t, tree_t d)
107,407✔
859
{
860
   tree_assert_decl(d);
107,407✔
861
   tree_array_add(lookup_item(&tree_object, t, I_DECLS), d);
107,407✔
862
   object_write_barrier(&(t->object), &(d->object));
107,407✔
863
}
107,407✔
864

865
unsigned tree_stmts(tree_t t)
96,074✔
866
{
867
   item_t *item = lookup_item(&tree_object, t, I_STMTS);
96,074✔
868
   return obj_array_count(item->obj_array);
96,074✔
869
}
870

871
tree_t tree_stmt(tree_t t, unsigned n)
142,846✔
872
{
873
   item_t *item = lookup_item(&tree_object, t, I_STMTS);
142,846✔
874
   return tree_array_nth(item, n);
142,846✔
875
}
876

877
void tree_add_stmt(tree_t t, tree_t s)
112,038✔
878
{
879
   assert(s != NULL);
112,038✔
880
   tree_array_add(lookup_item(&tree_object, t, I_STMTS), s);
112,038✔
881
   object_write_barrier(&(t->object), &(s->object));
112,038✔
882
}
112,038✔
883

884
unsigned tree_waveforms(tree_t t)
29,470✔
885
{
886
   item_t *item = lookup_item(&tree_object, t, I_WAVES);
29,470✔
887
   return obj_array_count(item->obj_array);
29,470✔
888
}
889

890
tree_t tree_waveform(tree_t t, unsigned n)
29,893✔
891
{
892
   item_t *item = lookup_item(&tree_object, t, I_WAVES);
29,893✔
893
   return tree_array_nth(item, n);
29,893✔
894
}
895

896
void tree_add_waveform(tree_t t, tree_t w)
5,995✔
897
{
898
   assert(w->object.kind == T_WAVEFORM);
5,995✔
899
   tree_array_add(lookup_item(&tree_object, t, I_WAVES), w);
5,995✔
900
   object_write_barrier(&(t->object), &(w->object));
5,995✔
901
}
5,995✔
902

903
unsigned tree_conds(tree_t t)
32,663✔
904
{
905
   item_t *item = lookup_item(&tree_object, t, I_CONDS);
32,663✔
906
   return obj_array_count(item->obj_array);
32,663✔
907
}
908

909
tree_t tree_cond(tree_t t, unsigned n)
39,298✔
910
{
911
   item_t *item = lookup_item(&tree_object, t, I_CONDS);
39,298✔
912
   return tree_array_nth(item, n);
39,298✔
913
}
914

915
void tree_add_cond(tree_t t, tree_t c)
13,859✔
916
{
917
   assert(c->object.kind == T_COND_STMT || c->object.kind == T_COND_EXPR);
13,859✔
918
   tree_array_add(lookup_item(&tree_object, t, I_CONDS), c);
13,859✔
919
   object_write_barrier(&(t->object), &(c->object));
13,859✔
920
}
13,859✔
921

922
bool tree_has_delay(tree_t t)
58,673✔
923
{
924
   return lookup_item(&tree_object, t, I_DELAY)->object != NULL;
58,673✔
925
}
926

927
tree_t tree_delay(tree_t t)
14,590✔
928
{
929
   item_t *item = lookup_item(&tree_object, t, I_DELAY);
14,590✔
930
   assert(item->object != NULL);
14,590✔
931
   return container_of(item->object, struct _tree, object);
14,590✔
932
}
933

934
void tree_set_delay(tree_t t, tree_t d)
4,579✔
935
{
936
   tree_assert_expr(d);
4,579✔
937
   lookup_item(&tree_object, t, I_DELAY)->object = &(d->object);
4,579✔
938
   object_write_barrier(&(t->object), &(d->object));
4,579✔
939
}
4,579✔
940

941
unsigned tree_triggers(tree_t t)
43,814✔
942
{
943
   item_t *item = lookup_item(&tree_object, t, I_TRIGGERS);
43,814✔
944
   return obj_array_count(item->obj_array);
43,814✔
945
}
946

947
tree_t tree_trigger(tree_t t, unsigned n)
7,270✔
948
{
949
   item_t *item = lookup_item(&tree_object, t, I_TRIGGERS);
7,270✔
950
   return tree_array_nth(item, n);
7,270✔
951
}
952

953
void tree_add_trigger(tree_t t, tree_t s)
3,295✔
954
{
955
   tree_assert_expr(s);
3,295✔
956
   tree_array_add(lookup_item(&tree_object, t, I_TRIGGERS), s);
3,295✔
957
   object_write_barrier(&(t->object), &(s->object));
3,295✔
958
}
3,295✔
959

960
tree_t tree_target(tree_t t)
90,403✔
961
{
962
   item_t *item = lookup_item(&tree_object, t, I_TARGET);
90,403✔
963
   assert(item->object != NULL);
90,403✔
964
   return container_of(item->object, struct _tree, object);
90,403✔
965
}
966

967
void tree_set_target(tree_t t, tree_t lhs)
23,404✔
968
{
969
   lookup_item(&tree_object, t, I_TARGET)->object = &(lhs->object);
23,404✔
970
   object_write_barrier(&(t->object), &(lhs->object));
23,404✔
971
}
23,404✔
972

973
tree_t tree_ref(tree_t t)
18,031,100✔
974
{
975
   item_t *item = lookup_item(&tree_object, t, I_REF);
18,031,100✔
976
   assert(item->object != NULL);
18,031,100✔
977
   return container_of(item->object, struct _tree, object);
18,031,100✔
978
}
979

980
bool tree_has_ref(tree_t t)
13,598,600✔
981
{
982
   return lookup_item(&tree_object, t, I_REF)->object != NULL;
13,598,600✔
983
}
984

985
void tree_set_ref(tree_t t, tree_t decl)
1,014,520✔
986
{
987
   object_t *obj = decl ? &(decl->object) : NULL;
1,014,520✔
988
   lookup_item(&tree_object, t, I_REF)->object = obj;
1,014,520✔
989
   object_write_barrier(&(t->object), obj);
1,014,520✔
990
}
1,014,520✔
991

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

999
bool tree_has_spec(tree_t t)
6,051✔
1000
{
1001
   return lookup_item(&tree_object, t, I_SPEC)->object != NULL;
6,051✔
1002
}
1003

1004
void tree_set_spec(tree_t t, tree_t s)
141✔
1005
{
1006
   assert(s != NULL);
141✔
1007
   lookup_item(&tree_object, t, I_SPEC)->object = &(s->object);
141✔
1008
   object_write_barrier(&(t->object), &(s->object));
141✔
1009
}
141✔
1010

1011
unsigned tree_contexts(tree_t t)
25,230✔
1012
{
1013
   item_t *item = lookup_item(&tree_object, t, I_CONTEXT);
25,230✔
1014
   return obj_array_count(item->obj_array);
25,230✔
1015
}
1016

1017
tree_t tree_context(tree_t t, unsigned n)
83,840✔
1018
{
1019
   item_t *item = lookup_item(&tree_object, t, I_CONTEXT);
83,840✔
1020
   return tree_array_nth(item, n);
83,840✔
1021
}
1022

1023
void tree_add_context(tree_t t, tree_t ctx)
33,196✔
1024
{
1025
   assert(ctx->object.kind == T_USE || ctx->object.kind == T_LIBRARY
33,196✔
1026
          || ctx->object.kind == T_CONTEXT_REF);
1027
   tree_array_add(lookup_item(&tree_object, t, I_CONTEXT), ctx);
33,196✔
1028
   object_write_barrier(&(t->object), &(ctx->object));
33,196✔
1029
}
33,196✔
1030

1031
unsigned tree_pragmas(tree_t t)
122✔
1032
{
1033
   item_t *item = lookup_item(&tree_object, t, I_PRAGMAS);
122✔
1034
   return obj_array_count(item->obj_array);
122✔
1035
}
1036

1037
tree_t tree_pragma(tree_t t, unsigned n)
39✔
1038
{
1039
   item_t *item = lookup_item(&tree_object, t, I_PRAGMAS);
39✔
1040
   return tree_array_nth(item, n);
39✔
1041
}
1042

1043
void tree_add_pragma(tree_t t, tree_t p)
47✔
1044
{
1045
   assert(p->object.kind == T_PRAGMA);
47✔
1046
   tree_array_add(lookup_item(&tree_object, t, I_PRAGMAS), p);
47✔
1047
   object_write_barrier(&(t->object), &(p->object));
47✔
1048
}
47✔
1049

1050
unsigned tree_assocs(tree_t t)
112,226✔
1051
{
1052
   item_t *item = lookup_item(&tree_object, t, I_ASSOCS);
112,226✔
1053
   return obj_array_count(item->obj_array);
112,226✔
1054
}
1055

1056
tree_t tree_assoc(tree_t t, unsigned n)
466,911✔
1057
{
1058
   item_t *item = lookup_item(&tree_object, t, I_ASSOCS);
466,911✔
1059
   return tree_array_nth(item, n);
466,911✔
1060
}
1061

1062
void tree_add_assoc(tree_t t, tree_t a)
38,577✔
1063
{
1064
   assert(a->object.kind == T_ASSOC);
38,577✔
1065
   tree_array_add(lookup_item(&tree_object, t, I_ASSOCS), a);
38,577✔
1066
   object_write_barrier(&(t->object), &(a->object));
38,577✔
1067
}
38,577✔
1068

1069
tree_t tree_severity(tree_t t)
32,255✔
1070
{
1071
   item_t *item = lookup_item(&tree_object, t, I_SEVERITY);
32,255✔
1072
   assert(item->object != NULL);
32,255✔
1073
   return container_of(item->object, struct _tree, object);
32,255✔
1074
}
1075

1076
void tree_set_severity(tree_t t, tree_t s)
17,608✔
1077
{
1078
   tree_assert_expr(s);
17,608✔
1079
   lookup_item(&tree_object, t, I_SEVERITY)->object = &(s->object);
17,608✔
1080
   object_write_barrier(&(t->object), &(s->object));
17,608✔
1081
}
17,608✔
1082

1083
tree_t tree_message(tree_t t)
13,485✔
1084
{
1085
   item_t *item = lookup_item(&tree_object, t, I_MESSAGE);
13,485✔
1086
   assert(item->object != NULL);
13,485✔
1087
   return container_of(item->object, struct _tree, object);
13,485✔
1088
}
1089

1090
bool tree_has_message(tree_t t)
45,172✔
1091
{
1092
   return lookup_item(&tree_object, t, I_MESSAGE)->object != NULL;
45,172✔
1093
}
1094

1095
void tree_set_message(tree_t t, tree_t m)
8,066✔
1096
{
1097
   tree_assert_expr(m);
8,066✔
1098
   lookup_item(&tree_object, t, I_MESSAGE)->object = &(m->object);
8,066✔
1099
   object_write_barrier(&(t->object), &(m->object));
8,066✔
1100
}
8,066✔
1101

1102
void tree_add_range(tree_t t, tree_t r)
43,532✔
1103
{
1104
   tree_array_add(lookup_item(&tree_object, t, I_RANGES), r);
43,532✔
1105
   object_write_barrier(&(t->object), &(r->object));
43,532✔
1106
}
43,532✔
1107

1108
tree_t tree_range(tree_t t, unsigned n)
1,058,520✔
1109
{
1110
   item_t *item = lookup_item(&tree_object, t, I_RANGES);
1,058,520✔
1111
   return tree_array_nth(item, n);
1,058,520✔
1112
}
1113

1114
unsigned tree_ranges(tree_t t)
19,619✔
1115
{
1116
   item_t *item = lookup_item(&tree_object, t, I_RANGES);
19,619✔
1117
   return obj_array_count(item->obj_array);
19,619✔
1118
}
1119

1120
unsigned tree_pos(tree_t t)
2,490,360✔
1121
{
1122
   return lookup_item(&tree_object, t, I_POS)->ival;
2,490,360✔
1123
}
1124

1125
void tree_set_pos(tree_t t, unsigned pos)
228,307✔
1126
{
1127
   lookup_item(&tree_object, t, I_POS)->ival = pos;
228,307✔
1128
}
228,307✔
1129

1130
tree_t tree_left(tree_t t)
1,646,040✔
1131
{
1132
   item_t *item = lookup_item(&tree_object, t, I_LEFT);
1,646,040✔
1133
   assert(item->object != NULL);
1,646,040✔
1134
   return container_of(item->object, struct _tree, object);
1,646,040✔
1135
}
1136

1137
void tree_set_left(tree_t t, tree_t left)
35,781✔
1138
{
1139
   tree_assert_expr(left);
35,781✔
1140
   lookup_item(&tree_object, t, I_LEFT)->object = &(left->object);
35,781✔
1141
   object_write_barrier(&(t->object), &(left->object));
35,781✔
1142
}
35,781✔
1143

1144
tree_t tree_right(tree_t t)
1,264,860✔
1145
{
1146
   item_t *item = lookup_item(&tree_object, t, I_RIGHT);
1,264,860✔
1147
   assert(item->object != NULL);
1,264,860✔
1148
   return container_of(item->object, struct _tree, object);
1,264,860✔
1149
}
1150

1151
void tree_set_right(tree_t t, tree_t right)
35,769✔
1152
{
1153
   tree_assert_expr(right);
35,769✔
1154
   lookup_item(&tree_object, t, I_RIGHT)->object = &(right->object);
35,769✔
1155
   object_write_barrier(&(t->object), &(right->object));
35,769✔
1156
}
35,769✔
1157

1158
class_t tree_class(tree_t t)
664,193✔
1159
{
1160
   return lookup_item(&tree_object, t, I_CLASS)->ival;
664,193✔
1161
}
1162

1163
void tree_set_class(tree_t t, class_t c)
40,250✔
1164
{
1165
   lookup_item(&tree_object, t, I_CLASS)->ival = c;
40,250✔
1166
}
40,250✔
1167

1168
tree_t tree_reject(tree_t t)
1,907✔
1169
{
1170
   item_t *item = lookup_item(&tree_object, t, I_REJECT);
1,907✔
1171
   assert(item->object != NULL);
1,907✔
1172
   return container_of(item->object, struct _tree, object);
1,907✔
1173
}
1174

1175
void tree_set_reject(tree_t t, tree_t r)
440✔
1176
{
1177
   tree_assert_expr(r);
440✔
1178
   lookup_item(&tree_object, t, I_REJECT)->object = &(r->object);
440✔
1179
   object_write_barrier(&(t->object), &(r->object));
440✔
1180
}
440✔
1181

1182
bool tree_has_reject(tree_t t)
21,918✔
1183
{
1184
   return lookup_item(&tree_object, t, I_REJECT)->object != NULL;
21,918✔
1185
}
1186

1187
tree_t tree_guard(tree_t t)
23✔
1188
{
1189
   item_t *item = lookup_item(&tree_object, t, I_GUARD);
23✔
1190
   assert(item->object != NULL);
23✔
1191
   return container_of(item->object, struct _tree, object);
23✔
1192
}
1193

1194
void tree_set_guard(tree_t t, tree_t g)
14✔
1195
{
1196
   assert(g->object.kind == T_REF);
14✔
1197
   lookup_item(&tree_object, t, I_GUARD)->object = &(g->object);
14✔
1198
   object_write_barrier(&(t->object), &(g->object));
14✔
1199
}
14✔
1200

1201
bool tree_has_guard(tree_t t)
4,713✔
1202
{
1203
   return lookup_item(&tree_object, t, I_GUARD)->object != NULL;
4,713✔
1204
}
1205

1206
tree_t tree_name(tree_t t)
459,820✔
1207
{
1208
   item_t *item = lookup_item(&tree_object, t, I_NAME);
459,820✔
1209
   assert(item->object != NULL);
459,820✔
1210
   return container_of(item->object, struct _tree, object);
459,820✔
1211
}
1212

1213
void tree_set_name(tree_t t, tree_t n)
34,232✔
1214
{
1215
   tree_assert_expr(n);
34,232✔
1216
   lookup_item(&tree_object, t, I_NAME)->object = &(n->object);
34,232✔
1217
   object_write_barrier(&(t->object), &(n->object));
34,232✔
1218
}
34,232✔
1219

1220
bool tree_has_name(tree_t t)
2,084✔
1221
{
1222
   return lookup_item(&tree_object, t, I_NAME)->object != NULL;
2,084✔
1223
}
1224

1225
tree_t tree_file_mode(tree_t t)
106✔
1226
{
1227
   item_t *item = lookup_item(&tree_object, t, I_FILE_MODE);
106✔
1228
   return container_of(item->object, struct _tree, object);
106✔
1229
}
1230

1231
void tree_set_file_mode(tree_t t, tree_t m)
44✔
1232
{
1233
   lookup_item(&tree_object, t, I_FILE_MODE)->object = &(m->object);
44✔
1234
   object_write_barrier(&(t->object), &(m->object));
44✔
1235
}
44✔
1236

1237
unsigned tree_visit(tree_t t, tree_visit_fn_t fn, void *context)
8,350✔
1238
{
1239
   return tree_visit_only(t, fn, context, T_LAST_TREE_KIND);
8,350✔
1240
}
1241

1242
unsigned tree_visit_only(tree_t t, tree_visit_fn_t fn,
9,581✔
1243
                         void *context, tree_kind_t kind)
1244
{
1245
   assert(t != NULL);
9,581✔
1246

1247
   object_visit_ctx_t ctx = {
9,581✔
1248
      .count      = 0,
1249
      .postorder  = (object_visit_fn_t)fn,
1250
      .preorder   = NULL,
1251
      .context    = context,
1252
      .kind       = kind,
1253
      .tag        = OBJECT_TAG_TREE,
1254
      .generation = object_next_generation(),
9,581✔
1255
      .deep       = false
1256
   };
1257

1258
   object_visit(&(t->object), &ctx);
9,581✔
1259

1260
   return ctx.count;
9,581✔
1261
}
1262

1263
tree_t tree_rewrite(tree_t t, tree_rewrite_pre_fn_t pre_fn,
26,682✔
1264
                    tree_rewrite_post_fn_t tree_post_fn,
1265
                    type_rewrite_post_fn_t type_post_fn,
1266
                    void *context)
1267
{
1268
   object_arena_t *arena = object_arena(&(t->object));
26,682✔
1269
   if (arena_frozen(arena))
26,682✔
1270
      return t;
1271

1272
   object_rewrite_ctx_t ctx = {
22,981✔
1273
      .generation = object_next_generation(),
22,981✔
1274
      .context    = context,
1275
      .arena      = arena,
1276
   };
1277

1278
   ctx.pre_fn[OBJECT_TAG_TREE] = (object_rewrite_pre_fn_t)pre_fn;
22,981✔
1279

1280
   ctx.post_fn[OBJECT_TAG_TREE] = (object_rewrite_post_fn_t)tree_post_fn;
22,981✔
1281
   ctx.post_fn[OBJECT_TAG_TYPE] = (object_rewrite_post_fn_t)type_post_fn;
22,981✔
1282

1283
   object_t *result = object_rewrite(&(t->object), &ctx);
22,981✔
1284
   free(ctx.cache);
22,978✔
1285
   return container_of(result, struct _tree, object);
22,978✔
1286
}
1287

1288
void tree_copy(tree_t *roots, unsigned nroots,
6,593✔
1289
               tree_copy_pred_t tree_pred,
1290
               type_copy_pred_t type_pred,
1291
               void *pred_context,
1292
               tree_copy_fn_t tree_callback,
1293
               type_copy_fn_t type_callback,
1294
               void *callback_context)
1295
{
1296
   object_copy_ctx_t *ctx LOCAL = xcalloc_flex(sizeof(object_copy_ctx_t),
13,186✔
1297
                                               nroots, sizeof(object_t *));
1298

1299
   ctx->generation       = object_next_generation();
6,593✔
1300
   ctx->pred_context     = pred_context;
6,593✔
1301
   ctx->callback_context = callback_context;
6,593✔
1302
   ctx->nroots           = nroots;
6,593✔
1303

1304
   for (unsigned i = 0; i < nroots; i++)
18,571✔
1305
      ctx->roots[i] = &(roots[i]->object);
11,978✔
1306

1307
   ctx->should_copy[OBJECT_TAG_TREE] = (object_copy_pred_t)tree_pred;
6,593✔
1308
   ctx->should_copy[OBJECT_TAG_TYPE] = (object_copy_pred_t)type_pred;
6,593✔
1309

1310
   ctx->callback[OBJECT_TAG_TREE] = (object_copy_fn_t)tree_callback;
6,593✔
1311
   ctx->callback[OBJECT_TAG_TYPE] = (object_copy_fn_t)type_callback;
6,593✔
1312

1313
   object_copy(ctx);
6,593✔
1314

1315
   for (unsigned i = 0; i < nroots; i++)
18,571✔
1316
      roots[i] = container_of(ctx->roots[i], struct _tree, object);
11,978✔
1317
}
6,593✔
1318

1319
const char *tree_kind_str(tree_kind_t t)
823✔
1320
{
1321
   return kind_text_map[t];
823✔
1322
}
1323

1324
object_arena_t *tree_arena(tree_t t)
124✔
1325
{
1326
   return object_arena(&(t->object));
124✔
1327
}
1328

1329
bool tree_frozen(tree_t t)
×
1330
{
1331
   return arena_frozen(object_arena(&(t->object)));
×
1332
}
1333

1334
tree_t tree_container(tree_t t)
39,277✔
1335
{
1336
   object_t *o = arena_root(object_arena(&(t->object)));
39,277✔
1337
   assert(o->tag == OBJECT_TAG_TREE);
39,277✔
1338
   return container_of(o, struct _tree, object);
39,277✔
1339
}
1340

1341
void tree_locus(tree_t t, ident_t *unit, ptrdiff_t *offset)
89,016✔
1342
{
1343
   assert(t != NULL);
89,016✔
1344
   object_locus(&(t->object), unit, offset);
89,016✔
1345
}
89,016✔
1346

1347
tree_t tree_from_locus(ident_t unit, ptrdiff_t offset,
×
1348
                       tree_load_fn_t find_deps_fn)
1349
{
1350
   object_t *o = object_from_locus(unit, offset,
×
1351
                                   (object_load_fn_t)find_deps_fn);
1352
   assert(o->tag == OBJECT_TAG_TREE);
×
1353
   return container_of(o, struct _tree, object);
×
1354
}
1355

1356
void tree_walk_deps(tree_t t, tree_deps_fn_t fn, void *ctx)
18,557✔
1357
{
1358
   object_arena_walk_deps(object_arena(&(t->object)), fn, ctx);
18,557✔
1359
}
18,557✔
1360

1361
int tree_stable_compar(const void *pa, const void *pb)
×
1362
{
1363
   tree_t a = *(tree_t *)pa;
×
1364
   tree_t b = *(tree_t *)pb;
×
1365

1366
   if (a == NULL)
×
1367
      return -1;
1368
   else if (b == NULL)
×
1369
      return 1;
1370
   else
1371
      return tree_loc(a)->first_line - tree_loc(b)->first_line;
×
1372
}
1373

1374
object_t *tree_to_object(tree_t t)
101,123✔
1375
{
1376
   return t ? &(t->object) : NULL;
101,123✔
1377
}
1378

1379
tree_t tree_from_object(object_t *obj)
101,149✔
1380
{
1381
   if (obj != NULL && obj->tag == OBJECT_TAG_TREE)
101,149✔
1382
      return container_of(obj, struct _tree, object);
101,149✔
1383
   else
1384
      return NULL;
110✔
1385
}
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