~ubuntu-branches/ubuntu/vivid/babeltrace/vivid

« back to all changes in this revision

Viewing changes to types/types.c

  • Committer: Package Import Robot
  • Author(s): Jon Bernard, a457ed8
  • Date: 2013-04-02 15:49:18 UTC
  • mfrom: (1.1.8) (0.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130402154918-njndzk94lffxhlmx
Tags: 1.1.0-1
[a457ed8] New upstream version 1.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
}
52
52
 
53
53
static
54
 
struct declaration *
55
 
        lookup_declaration_scope(GQuark declaration_name,
 
54
struct bt_declaration *
 
55
        bt_lookup_declaration_scope(GQuark declaration_name,
56
56
                struct declaration_scope *scope)
57
57
{
58
58
        return g_hash_table_lookup(scope->typedef_declarations,
59
59
                                   (gconstpointer) (unsigned long) declaration_name);
60
60
}
61
61
 
62
 
struct declaration *lookup_declaration(GQuark declaration_name,
 
62
struct bt_declaration *bt_lookup_declaration(GQuark declaration_name,
63
63
                struct declaration_scope *scope)
64
64
{
65
 
        struct declaration *declaration;
 
65
        struct bt_declaration *declaration;
66
66
 
67
67
        while (scope) {
68
 
                declaration = lookup_declaration_scope(declaration_name,
 
68
                declaration = bt_lookup_declaration_scope(declaration_name,
69
69
                                                       scope);
70
70
                if (declaration)
71
71
                        return declaration;
74
74
        return NULL;
75
75
}
76
76
 
77
 
int register_declaration(GQuark name, struct declaration *declaration,
 
77
int bt_register_declaration(GQuark name, struct bt_declaration *declaration,
78
78
                struct declaration_scope *scope)
79
79
{
80
80
        if (!name)
81
81
                return -EPERM;
82
82
 
83
83
        /* Only lookup in local scope */
84
 
        if (lookup_declaration_scope(name, scope))
 
84
        if (bt_lookup_declaration_scope(name, scope))
85
85
                return -EEXIST;
86
86
 
87
87
        g_hash_table_insert(scope->typedef_declarations,
88
88
                            (gpointer) (unsigned long) name,
89
89
                            declaration);
90
 
        declaration_ref(declaration);
 
90
        bt_declaration_ref(declaration);
91
91
        return 0;
92
92
}
93
93
 
94
94
static
95
 
struct definition *
 
95
struct bt_definition *
96
96
        lookup_field_definition_scope(GQuark field_name,
97
97
                struct definition_scope *scope)
98
98
{
158
158
}
159
159
 
160
160
static struct definition_scope *
161
 
        get_definition_scope(const struct definition *definition)
 
161
        get_definition_scope(const struct bt_definition *definition)
162
162
{
163
163
        return definition->scope;
164
164
}
183
183
 * lookup_path: the path leading to the enum we want to look for.
184
184
 * scope: the definition scope containing the variant definition.
185
185
 */
186
 
struct definition *
187
 
        lookup_path_definition(GArray *cur_path,
 
186
struct bt_definition *
 
187
        bt_lookup_path_definition(GArray *cur_path,
188
188
                               GArray *lookup_path,
189
189
                               struct definition_scope *scope)
190
190
{
191
 
        struct definition *definition, *lookup_definition;
 
191
        struct bt_definition *definition, *lookup_definition;
192
192
        GQuark last;
193
193
        int index;
194
194
 
262
262
        return NULL;
263
263
}
264
264
 
265
 
int register_field_definition(GQuark field_name, struct definition *definition,
 
265
int bt_register_field_definition(GQuark field_name, struct bt_definition *definition,
266
266
                struct definition_scope *scope)
267
267
{
268
268
        if (!scope || !field_name)
279
279
        return 0;
280
280
}
281
281
 
282
 
void declaration_ref(struct declaration *declaration)
 
282
void bt_declaration_ref(struct bt_declaration *declaration)
283
283
{
284
284
        declaration->ref++;
285
285
}
286
286
 
287
 
void declaration_unref(struct declaration *declaration)
 
287
void bt_declaration_unref(struct bt_declaration *declaration)
288
288
{
289
289
        if (!declaration)
290
290
                return;
292
292
                declaration->declaration_free(declaration);
293
293
}
294
294
 
295
 
void definition_ref(struct definition *definition)
 
295
void bt_definition_ref(struct bt_definition *definition)
296
296
{
297
297
        definition->ref++;
298
298
}
299
299
 
300
 
void definition_unref(struct definition *definition)
 
300
void bt_definition_unref(struct bt_definition *definition)
301
301
{
302
302
        if (!definition)
303
303
                return;
306
306
}
307
307
 
308
308
struct declaration_scope *
309
 
        new_declaration_scope(struct declaration_scope *parent_scope)
 
309
        bt_new_declaration_scope(struct declaration_scope *parent_scope)
310
310
{
311
311
        struct declaration_scope *scope = g_new(struct declaration_scope, 1);
312
312
 
313
313
        scope->typedef_declarations = g_hash_table_new_full(g_direct_hash,
314
314
                                        g_direct_equal, NULL,
315
 
                                        (GDestroyNotify) declaration_unref);
 
315
                                        (GDestroyNotify) bt_declaration_unref);
316
316
        scope->struct_declarations = g_hash_table_new_full(g_direct_hash,
317
317
                                        g_direct_equal, NULL,
318
 
                                        (GDestroyNotify) declaration_unref);
 
318
                                        (GDestroyNotify) bt_declaration_unref);
319
319
        scope->variant_declarations = g_hash_table_new_full(g_direct_hash,
320
320
                                        g_direct_equal, NULL,
321
 
                                        (GDestroyNotify) declaration_unref);
 
321
                                        (GDestroyNotify) bt_declaration_unref);
322
322
        scope->enum_declarations = g_hash_table_new_full(g_direct_hash,
323
323
                                        g_direct_equal, NULL,
324
 
                                        (GDestroyNotify) declaration_unref);
 
324
                                        (GDestroyNotify) bt_declaration_unref);
325
325
        scope->parent_scope = parent_scope;
326
326
        return scope;
327
327
}
328
328
 
329
 
void free_declaration_scope(struct declaration_scope *scope)
 
329
void bt_free_declaration_scope(struct declaration_scope *scope)
330
330
{
331
331
        g_hash_table_destroy(scope->enum_declarations);
332
332
        g_hash_table_destroy(scope->variant_declarations);
336
336
}
337
337
 
338
338
static
339
 
struct declaration_struct *lookup_struct_declaration_scope(GQuark struct_name,
 
339
struct declaration_struct *bt_lookup_struct_declaration_scope(GQuark struct_name,
340
340
                                             struct declaration_scope *scope)
341
341
{
342
342
        return g_hash_table_lookup(scope->struct_declarations,
343
343
                                   (gconstpointer) (unsigned long) struct_name);
344
344
}
345
345
 
346
 
struct declaration_struct *lookup_struct_declaration(GQuark struct_name,
 
346
struct declaration_struct *bt_lookup_struct_declaration(GQuark struct_name,
347
347
                                       struct declaration_scope *scope)
348
348
{
349
349
        struct declaration_struct *declaration;
350
350
 
351
351
        while (scope) {
352
 
                declaration = lookup_struct_declaration_scope(struct_name, scope);
 
352
                declaration = bt_lookup_struct_declaration_scope(struct_name, scope);
353
353
                if (declaration)
354
354
                        return declaration;
355
355
                scope = scope->parent_scope;
357
357
        return NULL;
358
358
}
359
359
 
360
 
int register_struct_declaration(GQuark struct_name,
 
360
int bt_register_struct_declaration(GQuark struct_name,
361
361
        struct declaration_struct *struct_declaration,
362
362
        struct declaration_scope *scope)
363
363
{
368
368
                return -EPERM;
369
369
 
370
370
        /* Only lookup in local scope */
371
 
        if (lookup_struct_declaration_scope(struct_name, scope))
 
371
        if (bt_lookup_struct_declaration_scope(struct_name, scope))
372
372
                return -EEXIST;
373
373
 
374
374
        g_hash_table_insert(scope->struct_declarations,
375
375
                            (gpointer) (unsigned long) struct_name,
376
376
                            struct_declaration);
377
 
        declaration_ref(&struct_declaration->p);
 
377
        bt_declaration_ref(&struct_declaration->p);
378
378
 
379
379
        /* Also add in typedef/typealias scopes */
380
380
        prefix_name = prefix_quark("struct ", struct_name);
381
 
        ret = register_declaration(prefix_name, &struct_declaration->p, scope);
 
381
        ret = bt_register_declaration(prefix_name, &struct_declaration->p, scope);
382
382
        assert(!ret);
383
383
        return 0;
384
384
}
385
385
 
386
386
static
387
387
struct declaration_untagged_variant *
388
 
        lookup_variant_declaration_scope(GQuark variant_name,
 
388
        bt_lookup_variant_declaration_scope(GQuark variant_name,
389
389
                struct declaration_scope *scope)
390
390
{
391
391
        return g_hash_table_lookup(scope->variant_declarations,
393
393
}
394
394
 
395
395
struct declaration_untagged_variant *
396
 
        lookup_variant_declaration(GQuark variant_name,
 
396
        bt_lookup_variant_declaration(GQuark variant_name,
397
397
                struct declaration_scope *scope)
398
398
{
399
399
        struct declaration_untagged_variant *declaration;
400
400
 
401
401
        while (scope) {
402
 
                declaration = lookup_variant_declaration_scope(variant_name, scope);
 
402
                declaration = bt_lookup_variant_declaration_scope(variant_name, scope);
403
403
                if (declaration)
404
404
                        return declaration;
405
405
                scope = scope->parent_scope;
407
407
        return NULL;
408
408
}
409
409
 
410
 
int register_variant_declaration(GQuark variant_name,
 
410
int bt_register_variant_declaration(GQuark variant_name,
411
411
                struct declaration_untagged_variant *untagged_variant_declaration,
412
412
                struct declaration_scope *scope)
413
413
{
418
418
                return -EPERM;
419
419
 
420
420
        /* Only lookup in local scope */
421
 
        if (lookup_variant_declaration_scope(variant_name, scope))
 
421
        if (bt_lookup_variant_declaration_scope(variant_name, scope))
422
422
                return -EEXIST;
423
423
 
424
424
        g_hash_table_insert(scope->variant_declarations,
425
425
                            (gpointer) (unsigned long) variant_name,
426
426
                            untagged_variant_declaration);
427
 
        declaration_ref(&untagged_variant_declaration->p);
 
427
        bt_declaration_ref(&untagged_variant_declaration->p);
428
428
 
429
429
        /* Also add in typedef/typealias scopes */
430
430
        prefix_name = prefix_quark("variant ", variant_name);
431
 
        ret = register_declaration(prefix_name,
 
431
        ret = bt_register_declaration(prefix_name,
432
432
                        &untagged_variant_declaration->p, scope);
433
433
        assert(!ret);
434
434
        return 0;
436
436
 
437
437
static
438
438
struct declaration_enum *
439
 
        lookup_enum_declaration_scope(GQuark enum_name,
 
439
        bt_lookup_enum_declaration_scope(GQuark enum_name,
440
440
                struct declaration_scope *scope)
441
441
{
442
442
        return g_hash_table_lookup(scope->enum_declarations,
444
444
}
445
445
 
446
446
struct declaration_enum *
447
 
        lookup_enum_declaration(GQuark enum_name,
 
447
        bt_lookup_enum_declaration(GQuark enum_name,
448
448
                struct declaration_scope *scope)
449
449
{
450
450
        struct declaration_enum *declaration;
451
451
 
452
452
        while (scope) {
453
 
                declaration = lookup_enum_declaration_scope(enum_name, scope);
 
453
                declaration = bt_lookup_enum_declaration_scope(enum_name, scope);
454
454
                if (declaration)
455
455
                        return declaration;
456
456
                scope = scope->parent_scope;
458
458
        return NULL;
459
459
}
460
460
 
461
 
int register_enum_declaration(GQuark enum_name,
 
461
int bt_register_enum_declaration(GQuark enum_name,
462
462
                struct declaration_enum *enum_declaration,
463
463
                struct declaration_scope *scope)
464
464
{
469
469
                return -EPERM;
470
470
 
471
471
        /* Only lookup in local scope */
472
 
        if (lookup_enum_declaration_scope(enum_name, scope))
 
472
        if (bt_lookup_enum_declaration_scope(enum_name, scope))
473
473
                return -EEXIST;
474
474
 
475
475
        g_hash_table_insert(scope->enum_declarations,
476
476
                            (gpointer) (unsigned long) enum_name,
477
477
                            enum_declaration);
478
 
        declaration_ref(&enum_declaration->p);
 
478
        bt_declaration_ref(&enum_declaration->p);
479
479
 
480
480
        /* Also add in typedef/typealias scopes */
481
481
        prefix_name = prefix_quark("enum ", enum_name);
482
 
        ret = register_declaration(prefix_name, &enum_declaration->p, scope);
 
482
        ret = bt_register_declaration(prefix_name, &enum_declaration->p, scope);
483
483
        assert(!ret);
484
484
        return 0;
485
485
}
486
486
 
487
487
static struct definition_scope *
488
 
        _new_definition_scope(struct definition_scope *parent_scope,
 
488
        _bt_new_definition_scope(struct definition_scope *parent_scope,
489
489
                              int scope_path_len)
490
490
{
491
491
        struct definition_scope *scope = g_new(struct definition_scope, 1);
499
499
        return scope;
500
500
}
501
501
 
502
 
GQuark new_definition_path(struct definition_scope *parent_scope,
 
502
GQuark bt_new_definition_path(struct definition_scope *parent_scope,
503
503
                           GQuark field_name, const char *root_name)
504
504
{
505
505
        GQuark path;
540
540
}
541
541
 
542
542
struct definition_scope *
543
 
        new_definition_scope(struct definition_scope *parent_scope,
 
543
        bt_new_definition_scope(struct definition_scope *parent_scope,
544
544
                             GQuark field_name, const char *root_name)
545
545
{
546
546
        struct definition_scope *scope;
547
547
 
548
548
        if (root_name) {
549
 
                scope = _new_definition_scope(parent_scope, 0);
550
 
                append_scope_path(root_name, scope->scope_path);
 
549
                scope = _bt_new_definition_scope(parent_scope, 0);
 
550
                bt_append_scope_path(root_name, scope->scope_path);
551
551
        } else {
552
552
                int scope_path_len = 1;
553
553
 
554
554
                assert(parent_scope);
555
555
                scope_path_len += parent_scope->scope_path->len;
556
 
                scope = _new_definition_scope(parent_scope, scope_path_len);
 
556
                scope = _bt_new_definition_scope(parent_scope, scope_path_len);
557
557
                memcpy(scope->scope_path->data, parent_scope->scope_path->data,
558
558
                       sizeof(GQuark) * (scope_path_len - 1));
559
559
                g_array_index(scope->scope_path, GQuark, scope_path_len - 1) =
574
574
/*
575
575
 * in: path (dot separated), out: q (GArray of GQuark)
576
576
 */
577
 
void append_scope_path(const char *path, GArray *q)
 
577
void bt_append_scope_path(const char *path, GArray *q)
578
578
{
579
579
        const char *ptrbegin, *ptrend = path;
580
580
        GQuark quark;
605
605
        }
606
606
}
607
607
 
608
 
void free_definition_scope(struct definition_scope *scope)
 
608
void bt_free_definition_scope(struct definition_scope *scope)
609
609
{
610
610
        g_array_free(scope->scope_path, TRUE);
611
611
        g_hash_table_destroy(scope->definitions);
612
612
        g_free(scope);
613
613
}
614
614
 
615
 
struct definition *lookup_definition(const struct definition *definition,
 
615
struct bt_definition *bt_lookup_definition(const struct bt_definition *definition,
616
616
                                     const char *field_name)
617
617
{
618
618
        struct definition_scope *scope = get_definition_scope(definition);
624
624
                                             scope);
625
625
}
626
626
 
627
 
struct definition_integer *lookup_integer(const struct definition *definition,
 
627
struct definition_integer *bt_lookup_integer(const struct bt_definition *definition,
628
628
                                          const char *field_name,
629
629
                                          int signedness)
630
630
{
631
 
        struct definition *lookup;
 
631
        struct bt_definition *lookup;
632
632
        struct definition_integer *lookup_integer;
633
633
 
634
 
        lookup = lookup_definition(definition, field_name);
 
634
        lookup = bt_lookup_definition(definition, field_name);
635
635
        if (!lookup)
636
636
                return NULL;
637
637
        if (lookup->declaration->id != CTF_TYPE_INTEGER)
642
642
        return lookup_integer;
643
643
}
644
644
 
645
 
struct definition_enum *lookup_enum(const struct definition *definition,
 
645
struct definition_enum *bt_lookup_enum(const struct bt_definition *definition,
646
646
                                    const char *field_name,
647
647
                                    int signedness)
648
648
{
649
 
        struct definition *lookup;
 
649
        struct bt_definition *lookup;
650
650
        struct definition_enum *lookup_enum;
651
651
 
652
 
        lookup = lookup_definition(definition, field_name);
 
652
        lookup = bt_lookup_definition(definition, field_name);
653
653
        if (!lookup)
654
654
                return NULL;
655
655
        if (lookup->declaration->id != CTF_TYPE_ENUM)
660
660
        return lookup_enum;
661
661
}
662
662
 
663
 
struct definition *lookup_variant(const struct definition *definition,
 
663
struct bt_definition *bt_lookup_variant(const struct bt_definition *definition,
664
664
                                  const char *field_name)
665
665
{
666
 
        struct definition *lookup;
667
 
        struct definition_variant *lookup_variant;
 
666
        struct bt_definition *lookup;
 
667
        struct definition_variant *bt_lookup_variant;
668
668
 
669
 
        lookup = lookup_definition(definition, field_name);
 
669
        lookup = bt_lookup_definition(definition, field_name);
670
670
        if (!lookup)
671
671
                return NULL;
672
672
        if (lookup->declaration->id != CTF_TYPE_VARIANT)
673
673
                return NULL;
674
 
        lookup_variant = container_of(lookup, struct definition_variant, p);
675
 
        lookup = variant_get_current_field(lookup_variant);
 
674
        bt_lookup_variant = container_of(lookup, struct definition_variant, p);
 
675
        lookup = bt_variant_get_current_field(bt_lookup_variant);
676
676
        assert(lookup);
677
677
        return lookup;
678
678
}