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

« back to all changes in this revision

Viewing changes to formats/ctf/metadata/ctf-visitor-generate-io-struct.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:
58
58
int opt_clock_force_correlate;
59
59
 
60
60
static
61
 
struct declaration *ctf_type_specifier_list_visit(FILE *fd,
 
61
struct bt_declaration *ctf_type_specifier_list_visit(FILE *fd,
62
62
                int depth, struct ctf_node *type_specifier_list,
63
63
                struct declaration_scope *declaration_scope,
64
64
                struct ctf_trace *trace);
411
411
}
412
412
 
413
413
static
414
 
struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
 
414
struct bt_declaration *ctf_type_declarator_visit(FILE *fd, int depth,
415
415
        struct ctf_node *type_specifier_list,
416
416
        GQuark *field_name,
417
417
        struct ctf_node *node_type_declarator,
418
418
        struct declaration_scope *declaration_scope,
419
 
        struct declaration *nested_declaration,
 
419
        struct bt_declaration *nested_declaration,
420
420
        struct ctf_trace *trace)
421
421
{
422
422
        /*
445
445
                         */
446
446
                        alias_q = create_typealias_identifier(fd, depth,
447
447
                                type_specifier_list, node_type_declarator);
448
 
                        nested_declaration = lookup_declaration(alias_q, declaration_scope);
 
448
                        nested_declaration = bt_lookup_declaration(alias_q, declaration_scope);
449
449
                        if (!nested_declaration) {
450
450
                                fprintf(fd, "[error] %s: cannot find typealias \"%s\".\n", __func__, g_quark_to_string(alias_q));
451
451
                                return NULL;
460
460
                                         * integer declaration to modify it. There could be other references to
461
461
                                         * it.
462
462
                                         */
463
 
                                        integer_declaration = integer_declaration_new(integer_declaration->len,
 
463
                                        integer_declaration = bt_integer_declaration_new(integer_declaration->len,
464
464
                                                integer_declaration->byte_order, integer_declaration->signedness,
465
465
                                                integer_declaration->p.alignment, 16, integer_declaration->encoding,
466
466
                                                integer_declaration->clock);
483
483
                        *field_name = 0;
484
484
                return nested_declaration;
485
485
        } else {
486
 
                struct declaration *declaration;
 
486
                struct bt_declaration *declaration;
487
487
                struct ctf_node *first;
488
488
 
489
489
                /* TYPEDEC_NESTED */
509
509
                        size_t len;
510
510
 
511
511
                        len = first->u.unary_expression.u.unsigned_constant;
512
 
                        array_declaration = array_declaration_new(len, nested_declaration,
 
512
                        array_declaration = bt_array_declaration_new(len, nested_declaration,
513
513
                                                declaration_scope);
514
514
 
515
515
                        if (!array_declaration) {
516
516
                                fprintf(fd, "[error] %s: cannot create array declaration.\n", __func__);
517
517
                                return NULL;
518
518
                        }
519
 
                        declaration_unref(nested_declaration);
 
519
                        bt_declaration_unref(nested_declaration);
520
520
                        declaration = &array_declaration->p;
521
521
                        break;
522
522
                }
526
526
                        char *length_name = concatenate_unary_strings(&node_type_declarator->u.type_declarator.u.nested.length);
527
527
                        struct declaration_sequence *sequence_declaration;
528
528
 
529
 
                        sequence_declaration = sequence_declaration_new(length_name, nested_declaration, declaration_scope);
 
529
                        sequence_declaration = bt_sequence_declaration_new(length_name, nested_declaration, declaration_scope);
530
530
                        if (!sequence_declaration) {
531
531
                                fprintf(fd, "[error] %s: cannot create sequence declaration.\n", __func__);
532
532
                                g_free(length_name);
533
533
                                return NULL;
534
534
                        }
535
 
                        declaration_unref(nested_declaration);
 
535
                        bt_declaration_unref(nested_declaration);
536
536
                        declaration = &sequence_declaration->p;
537
537
                        g_free(length_name);
538
538
                        break;
562
562
        GQuark field_name;
563
563
 
564
564
        bt_list_for_each_entry(iter, type_declarators, siblings) {
565
 
                struct declaration *field_declaration;
 
565
                struct bt_declaration *field_declaration;
566
566
 
567
567
                field_declaration = ctf_type_declarator_visit(fd, depth,
568
568
                                                type_specifier_list,
575
575
                }
576
576
 
577
577
                /* Check if field with same name already exists */
578
 
                if (struct_declaration_lookup_field_index(struct_declaration, field_name) >= 0) {
 
578
                if (bt_struct_declaration_lookup_field_index(struct_declaration, field_name) >= 0) {
579
579
                        fprintf(fd, "[error] %s: duplicate field %s in struct\n", __func__, g_quark_to_string(field_name));
580
580
                        return -EINVAL;
581
581
                }
582
582
 
583
 
                struct_declaration_add_field(struct_declaration,
 
583
                bt_struct_declaration_add_field(struct_declaration,
584
584
                                             g_quark_to_string(field_name),
585
585
                                             field_declaration);
586
 
                declaration_unref(field_declaration);
 
586
                bt_declaration_unref(field_declaration);
587
587
        }
588
588
        return 0;
589
589
}
600
600
        GQuark field_name;
601
601
 
602
602
        bt_list_for_each_entry(iter, type_declarators, siblings) {
603
 
                struct declaration *field_declaration;
 
603
                struct bt_declaration *field_declaration;
604
604
 
605
605
                field_declaration = ctf_type_declarator_visit(fd, depth,
606
606
                                                type_specifier_list,
612
612
                        return -EINVAL;
613
613
                }
614
614
 
615
 
                if (untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration, field_name) != NULL) {
 
615
                if (bt_untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration, field_name) != NULL) {
616
616
                        fprintf(fd, "[error] %s: duplicate field %s in variant\n", __func__, g_quark_to_string(field_name));
617
617
                        return -EINVAL;
618
618
                }
619
619
 
620
 
                untagged_variant_declaration_add_field(untagged_variant_declaration,
 
620
                bt_untagged_variant_declaration_add_field(untagged_variant_declaration,
621
621
                                              g_quark_to_string(field_name),
622
622
                                              field_declaration);
623
 
                declaration_unref(field_declaration);
 
623
                bt_declaration_unref(field_declaration);
624
624
        }
625
625
        return 0;
626
626
}
635
635
        GQuark identifier;
636
636
 
637
637
        bt_list_for_each_entry(iter, type_declarators, siblings) {
638
 
                struct declaration *type_declaration;
 
638
                struct bt_declaration *type_declaration;
639
639
                int ret;
640
640
        
641
641
                type_declaration = ctf_type_declarator_visit(fd, depth,
652
652
                 */
653
653
                if (type_declaration->id == CTF_TYPE_UNTAGGED_VARIANT) {
654
654
                        fprintf(fd, "[error] %s: typedef of untagged variant is not permitted.\n", __func__);
655
 
                        declaration_unref(type_declaration);
 
655
                        bt_declaration_unref(type_declaration);
656
656
                        return -EPERM;
657
657
                }
658
 
                ret = register_declaration(identifier, type_declaration, scope);
 
658
                ret = bt_register_declaration(identifier, type_declaration, scope);
659
659
                if (ret) {
660
660
                        type_declaration->declaration_free(type_declaration);
661
661
                        return ret;
662
662
                }
663
 
                declaration_unref(type_declaration);
 
663
                bt_declaration_unref(type_declaration);
664
664
        }
665
665
        return 0;
666
666
}
670
670
                struct ctf_node *target, struct ctf_node *alias,
671
671
                struct ctf_trace *trace)
672
672
{
673
 
        struct declaration *type_declaration;
 
673
        struct bt_declaration *type_declaration;
674
674
        struct ctf_node *node;
675
675
        GQuark dummy_id;
676
676
        GQuark alias_q;
702
702
         */
703
703
        if (type_declaration->id == CTF_TYPE_UNTAGGED_VARIANT) {
704
704
                fprintf(fd, "[error] %s: typedef of untagged variant is not permitted.\n", __func__);
705
 
                declaration_unref(type_declaration);
 
705
                bt_declaration_unref(type_declaration);
706
706
                return -EPERM;
707
707
        }
708
708
        /*
722
722
                                struct ctf_node, siblings);
723
723
        alias_q = create_typealias_identifier(fd, depth,
724
724
                        alias->u.typealias_alias.type_specifier_list, node);
725
 
        err = register_declaration(alias_q, type_declaration, scope);
 
725
        err = bt_register_declaration(alias_q, type_declaration, scope);
726
726
        if (err)
727
727
                goto error;
728
 
        declaration_unref(type_declaration);
 
728
        bt_declaration_unref(type_declaration);
729
729
        return 0;
730
730
 
731
731
error:
744
744
 
745
745
        switch (iter->type) {
746
746
        case NODE_TYPEDEF:
747
 
                /* For each declarator, declare type and add type to struct declaration scope */
 
747
                /* For each declarator, declare type and add type to struct bt_declaration scope */
748
748
                ret = ctf_typedef_visit(fd, depth,
749
749
                        struct_declaration->scope,
750
750
                        iter->u._typedef.type_specifier_list,
753
753
                        return ret;
754
754
                break;
755
755
        case NODE_TYPEALIAS:
756
 
                /* Declare type with declarator and add type to struct declaration scope */
 
756
                /* Declare type with declarator and add type to struct bt_declaration scope */
757
757
                ret = ctf_typealias_visit(fd, depth,
758
758
                        struct_declaration->scope,
759
759
                        iter->u.typealias.target,
823
823
}
824
824
 
825
825
static
826
 
struct declaration *ctf_declaration_struct_visit(FILE *fd,
 
826
struct bt_declaration *ctf_declaration_struct_visit(FILE *fd,
827
827
        int depth, const char *name, struct bt_list_head *declaration_list,
828
828
        int has_body, struct bt_list_head *min_align,
829
829
        struct declaration_scope *declaration_scope,
840
840
        if (!has_body) {
841
841
                assert(name);
842
842
                struct_declaration =
843
 
                        lookup_struct_declaration(g_quark_from_string(name),
 
843
                        bt_lookup_struct_declaration(g_quark_from_string(name),
844
844
                                                  declaration_scope);
845
 
                declaration_ref(&struct_declaration->p);
 
845
                bt_declaration_ref(&struct_declaration->p);
846
846
                return &struct_declaration->p;
847
847
        } else {
848
848
                uint64_t min_align_value = 0;
850
850
                /* For unnamed struct, create type */
851
851
                /* For named struct (with body), create type and add to declaration scope */
852
852
                if (name) {
853
 
                        if (lookup_struct_declaration(g_quark_from_string(name),
 
853
                        if (bt_lookup_struct_declaration(g_quark_from_string(name),
854
854
                                                      declaration_scope)) {
855
855
                                
856
856
                                fprintf(fd, "[error] %s: struct %s already declared in scope\n", __func__, name);
867
867
                                goto error;
868
868
                        }
869
869
                }
870
 
                struct_declaration = struct_declaration_new(declaration_scope,
 
870
                struct_declaration = bt_struct_declaration_new(declaration_scope,
871
871
                                                            min_align_value);
872
872
                bt_list_for_each_entry(iter, declaration_list, siblings) {
873
873
                        int ret;
880
880
                if (name) {
881
881
                        int ret;
882
882
 
883
 
                        ret = register_struct_declaration(g_quark_from_string(name),
 
883
                        ret = bt_register_struct_declaration(g_quark_from_string(name),
884
884
                                        struct_declaration,
885
885
                                        declaration_scope);
886
886
                        assert(!ret);
894
894
}
895
895
 
896
896
static
897
 
struct declaration *ctf_declaration_variant_visit(FILE *fd,
 
897
struct bt_declaration *ctf_declaration_variant_visit(FILE *fd,
898
898
        int depth, const char *name, const char *choice,
899
899
        struct bt_list_head *declaration_list,
900
900
        int has_body, struct declaration_scope *declaration_scope,
912
912
        if (!has_body) {
913
913
                assert(name);
914
914
                untagged_variant_declaration =
915
 
                        lookup_variant_declaration(g_quark_from_string(name),
 
915
                        bt_lookup_variant_declaration(g_quark_from_string(name),
916
916
                                                   declaration_scope);
917
 
                declaration_ref(&untagged_variant_declaration->p);
 
917
                bt_declaration_ref(&untagged_variant_declaration->p);
918
918
        } else {
919
919
                /* For unnamed variant, create type */
920
920
                /* For named variant (with body), create type and add to declaration scope */
921
921
                if (name) {
922
 
                        if (lookup_variant_declaration(g_quark_from_string(name),
 
922
                        if (bt_lookup_variant_declaration(g_quark_from_string(name),
923
923
                                                       declaration_scope)) {
924
924
                                
925
925
                                fprintf(fd, "[error] %s: variant %s already declared in scope\n", __func__, name);
926
926
                                return NULL;
927
927
                        }
928
928
                }
929
 
                untagged_variant_declaration = untagged_variant_declaration_new(declaration_scope);
 
929
                untagged_variant_declaration = bt_untagged_bt_variant_declaration_new(declaration_scope);
930
930
                bt_list_for_each_entry(iter, declaration_list, siblings) {
931
931
                        int ret;
932
932
 
938
938
                if (name) {
939
939
                        int ret;
940
940
 
941
 
                        ret = register_variant_declaration(g_quark_from_string(name),
 
941
                        ret = bt_register_variant_declaration(g_quark_from_string(name),
942
942
                                        untagged_variant_declaration,
943
943
                                        declaration_scope);
944
944
                        assert(!ret);
951
951
        if (!choice) {
952
952
                return &untagged_variant_declaration->p;
953
953
        } else {
954
 
                variant_declaration = variant_declaration_new(untagged_variant_declaration, choice);
 
954
                variant_declaration = bt_variant_declaration_new(untagged_variant_declaration, choice);
955
955
                if (!variant_declaration)
956
956
                        goto error;
957
 
                declaration_unref(&untagged_variant_declaration->p);
 
957
                bt_declaration_unref(&untagged_variant_declaration->p);
958
958
                return &variant_declaration->p;
959
959
        }
960
960
error:
1007
1007
                if (nr_vals <= 1)
1008
1008
                        end = start;
1009
1009
                last->u.s = end + 1;
1010
 
                enum_signed_insert(enum_declaration, start, end, q);
 
1010
                bt_enum_signed_insert(enum_declaration, start, end, q);
1011
1011
        } else {
1012
1012
                uint64_t start, end;
1013
1013
                int nr_vals = 0;
1047
1047
                if (nr_vals <= 1)
1048
1048
                        end = start;
1049
1049
                last->u.u = end + 1;
1050
 
                enum_unsigned_insert(enum_declaration, start, end, q);
 
1050
                bt_enum_unsigned_insert(enum_declaration, start, end, q);
1051
1051
        }
1052
1052
        return 0;
1053
1053
}
1054
1054
 
1055
1055
static
1056
 
struct declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
 
1056
struct bt_declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
1057
1057
                        const char *name,
1058
1058
                        struct ctf_node *container_type,
1059
1059
                        struct bt_list_head *enumerator_list,
1061
1061
                        struct declaration_scope *declaration_scope,
1062
1062
                        struct ctf_trace *trace)
1063
1063
{
1064
 
        struct declaration *declaration;
 
1064
        struct bt_declaration *declaration;
1065
1065
        struct declaration_enum *enum_declaration;
1066
1066
        struct declaration_integer *integer_declaration;
1067
1067
        struct last_enum_value last_value;
1076
1076
        if (!has_body) {
1077
1077
                assert(name);
1078
1078
                enum_declaration =
1079
 
                        lookup_enum_declaration(g_quark_from_string(name),
 
1079
                        bt_lookup_enum_declaration(g_quark_from_string(name),
1080
1080
                                                declaration_scope);
1081
 
                declaration_ref(&enum_declaration->p);
 
1081
                bt_declaration_ref(&enum_declaration->p);
1082
1082
                return &enum_declaration->p;
1083
1083
        } else {
1084
1084
                /* For unnamed enum, create type */
1085
1085
                /* For named enum (with body), create type and add to declaration scope */
1086
1086
                if (name) {
1087
 
                        if (lookup_enum_declaration(g_quark_from_string(name),
 
1087
                        if (bt_lookup_enum_declaration(g_quark_from_string(name),
1088
1088
                                                    declaration_scope)) {
1089
1089
                                
1090
1090
                                fprintf(fd, "[error] %s: enum %s already declared in scope\n", __func__, name);
1092
1092
                        }
1093
1093
                }
1094
1094
                if (!container_type) {
1095
 
                        declaration = lookup_declaration(g_quark_from_static_string("int"),
 
1095
                        declaration = bt_lookup_declaration(g_quark_from_static_string("int"),
1096
1096
                                                         declaration_scope);
1097
1097
                        if (!declaration) {
1098
1098
                                fprintf(fd, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__);
1114
1114
                        return NULL;
1115
1115
                }
1116
1116
                integer_declaration = container_of(declaration, struct declaration_integer, p);
1117
 
                enum_declaration = enum_declaration_new(integer_declaration);
1118
 
                declaration_unref(&integer_declaration->p);     /* leave ref to enum */
 
1117
                enum_declaration = bt_enum_declaration_new(integer_declaration);
 
1118
                bt_declaration_unref(&integer_declaration->p);  /* leave ref to enum */
1119
1119
                if (enum_declaration->integer_declaration->signedness) {
1120
1120
                        last_value.u.s = 0;
1121
1121
                } else {
1132
1132
                if (name) {
1133
1133
                        int ret;
1134
1134
 
1135
 
                        ret = register_enum_declaration(g_quark_from_string(name),
 
1135
                        ret = bt_register_enum_declaration(g_quark_from_string(name),
1136
1136
                                        enum_declaration,
1137
1137
                                        declaration_scope);
1138
1138
                        assert(!ret);
1139
 
                        declaration_unref(&enum_declaration->p);
 
1139
                        bt_declaration_unref(&enum_declaration->p);
1140
1140
                }
1141
1141
                return &enum_declaration->p;
1142
1142
        }
1146
1146
}
1147
1147
 
1148
1148
static
1149
 
struct declaration *ctf_declaration_type_specifier_visit(FILE *fd, int depth,
 
1149
struct bt_declaration *ctf_declaration_type_specifier_visit(FILE *fd, int depth,
1150
1150
                struct ctf_node *type_specifier_list,
1151
1151
                struct declaration_scope *declaration_scope)
1152
1152
{
1153
1153
        GString *str;
1154
 
        struct declaration *declaration;
 
1154
        struct bt_declaration *declaration;
1155
1155
        char *str_c;
1156
1156
        int ret;
1157
1157
        GQuark id_q;
1163
1163
        str_c = g_string_free(str, FALSE);
1164
1164
        id_q = g_quark_from_string(str_c);
1165
1165
        g_free(str_c);
1166
 
        declaration = lookup_declaration(id_q, declaration_scope);
1167
 
        declaration_ref(declaration);
 
1166
        declaration = bt_lookup_declaration(id_q, declaration_scope);
 
1167
        bt_declaration_ref(declaration);
1168
1168
        return declaration;
1169
1169
}
1170
1170
 
1228
1228
        else if (!strcmp(unary_expression->u.unary_expression.u.string, "le"))
1229
1229
                byte_order = LITTLE_ENDIAN;
1230
1230
        else {
1231
 
                fprintf(fd, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
 
1231
                fprintf(fd, "[error] %s: unexpected string \"%s\". Should be \"be\" or \"le\".\n",
1232
1232
                        __func__, unary_expression->u.unary_expression.u.string);
1233
1233
                return -EINVAL;
1234
1234
        }
1263
1263
}
1264
1264
 
1265
1265
static
1266
 
struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth,
 
1266
struct bt_declaration *ctf_declaration_integer_visit(FILE *fd, int depth,
1267
1267
                struct bt_list_head *expressions,
1268
1268
                struct ctf_trace *trace)
1269
1269
{
1442
1442
                        alignment = CHAR_BIT;
1443
1443
                }
1444
1444
        }
1445
 
        integer_declaration = integer_declaration_new(size,
 
1445
        integer_declaration = bt_integer_declaration_new(size,
1446
1446
                                byte_order, signedness, alignment,
1447
1447
                                base, encoding, clock);
1448
1448
        return &integer_declaration->p;
1449
1449
}
1450
1450
 
1451
1451
static
1452
 
struct declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth,
 
1452
struct bt_declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth,
1453
1453
                struct bt_list_head *expressions,
1454
1454
                struct ctf_trace *trace)
1455
1455
{
1522
1522
                        alignment = CHAR_BIT;
1523
1523
                }
1524
1524
        }
1525
 
        float_declaration = float_declaration_new(mant_dig, exp_dig,
 
1525
        float_declaration = bt_float_declaration_new(mant_dig, exp_dig,
1526
1526
                                byte_order, alignment);
1527
1527
        return &float_declaration->p;
1528
1528
}
1529
1529
 
1530
1530
static
1531
 
struct declaration *ctf_declaration_string_visit(FILE *fd, int depth,
 
1531
struct bt_declaration *ctf_declaration_string_visit(FILE *fd, int depth,
1532
1532
                struct bt_list_head *expressions,
1533
1533
                struct ctf_trace *trace)
1534
1534
{
1558
1558
        }
1559
1559
        if (encoding_c && !strcmp(encoding_c, "ASCII"))
1560
1560
                encoding = CTF_STRING_ASCII;
1561
 
        string_declaration = string_declaration_new(encoding);
 
1561
        string_declaration = bt_string_declaration_new(encoding);
1562
1562
        return &string_declaration->p;
1563
1563
}
1564
1564
 
1565
1565
 
1566
1566
static
1567
 
struct declaration *ctf_type_specifier_list_visit(FILE *fd,
 
1567
struct bt_declaration *ctf_type_specifier_list_visit(FILE *fd,
1568
1568
                int depth, struct ctf_node *type_specifier_list,
1569
1569
                struct declaration_scope *declaration_scope,
1570
1570
                struct ctf_trace *trace)
1715
1715
                        }
1716
1716
                        CTF_EVENT_SET_FIELD(event, stream_id);
1717
1717
                } else if (!strcmp(left, "context")) {
1718
 
                        struct declaration *declaration;
 
1718
                        struct bt_declaration *declaration;
1719
1719
 
1720
1720
                        if (event->context_decl) {
1721
1721
                                fprintf(fd, "[error] %s: context already declared in event declaration\n", __func__);
1736
1736
                        }
1737
1737
                        event->context_decl = container_of(declaration, struct declaration_struct, p);
1738
1738
                } else if (!strcmp(left, "fields")) {
1739
 
                        struct declaration *declaration;
 
1739
                        struct bt_declaration *declaration;
1740
1740
 
1741
1741
                        if (event->fields_decl) {
1742
1742
                                fprintf(fd, "[error] %s: fields already declared in event declaration\n", __func__);
1816
1816
 
1817
1817
        event_decl = g_new0(struct bt_ctf_event_decl, 1);
1818
1818
        event = &event_decl->parent;
1819
 
        event->declaration_scope = new_declaration_scope(parent_declaration_scope);
 
1819
        event->declaration_scope = bt_new_declaration_scope(parent_declaration_scope);
1820
1820
        event->loglevel = -1;
1821
1821
        bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
1822
1822
                ret = ctf_event_declaration_visit(fd, depth + 1, iter, event, trace);
1864
1864
 
1865
1865
error:
1866
1866
        if (event->fields_decl)
1867
 
                declaration_unref(&event->fields_decl->p);
 
1867
                bt_declaration_unref(&event->fields_decl->p);
1868
1868
        if (event->context_decl)
1869
 
                declaration_unref(&event->context_decl->p);
1870
 
        free_declaration_scope(event->declaration_scope);
 
1869
                bt_declaration_unref(&event->context_decl->p);
 
1870
        bt_free_declaration_scope(event->declaration_scope);
1871
1871
        g_free(event_decl);
1872
1872
        return ret;
1873
1873
}
1915
1915
                        }
1916
1916
                        CTF_STREAM_SET_FIELD(stream, stream_id);
1917
1917
                } else if (!strcmp(left, "event.header")) {
1918
 
                        struct declaration *declaration;
 
1918
                        struct bt_declaration *declaration;
1919
1919
 
1920
1920
                        if (stream->event_header_decl) {
1921
1921
                                fprintf(fd, "[error] %s: event.header already declared in stream declaration\n", __func__);
1936
1936
                        }
1937
1937
                        stream->event_header_decl = container_of(declaration, struct declaration_struct, p);
1938
1938
                } else if (!strcmp(left, "event.context")) {
1939
 
                        struct declaration *declaration;
 
1939
                        struct bt_declaration *declaration;
1940
1940
 
1941
1941
                        if (stream->event_context_decl) {
1942
1942
                                fprintf(fd, "[error] %s: event.context already declared in stream declaration\n", __func__);
1957
1957
                        }
1958
1958
                        stream->event_context_decl = container_of(declaration, struct declaration_struct, p);
1959
1959
                } else if (!strcmp(left, "packet.context")) {
1960
 
                        struct declaration *declaration;
 
1960
                        struct bt_declaration *declaration;
1961
1961
 
1962
1962
                        if (stream->packet_context_decl) {
1963
1963
                                fprintf(fd, "[error] %s: packet.context already declared in stream declaration\n", __func__);
2003
2003
        struct ctf_stream_declaration *stream;
2004
2004
 
2005
2005
        stream = g_new0(struct ctf_stream_declaration, 1);
2006
 
        stream->declaration_scope = new_declaration_scope(parent_declaration_scope);
 
2006
        stream->declaration_scope = bt_new_declaration_scope(parent_declaration_scope);
2007
2007
        stream->events_by_id = g_ptr_array_new();
2008
2008
        stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal);
2009
2009
        stream->streams = g_ptr_array_new();
2017
2017
        if (CTF_STREAM_FIELD_IS_SET(stream, stream_id)) {
2018
2018
                /* check that packet header has stream_id field. */
2019
2019
                if (!trace->packet_header_decl
2020
 
                    || struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("stream_id")) < 0) {
 
2020
                    || bt_struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("stream_id")) < 0) {
2021
2021
                        ret = -EPERM;
2022
2022
                        fprintf(fd, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__);
2023
2023
                        goto error;
2040
2040
 
2041
2041
error:
2042
2042
        if (stream->event_header_decl)
2043
 
                declaration_unref(&stream->event_header_decl->p);
 
2043
                bt_declaration_unref(&stream->event_header_decl->p);
2044
2044
        if (stream->event_context_decl)
2045
 
                declaration_unref(&stream->event_context_decl->p);
 
2045
                bt_declaration_unref(&stream->event_context_decl->p);
2046
2046
        if (stream->packet_context_decl)
2047
 
                declaration_unref(&stream->packet_context_decl->p);
 
2047
                bt_declaration_unref(&stream->packet_context_decl->p);
2048
2048
        g_ptr_array_free(stream->streams, TRUE);
2049
2049
        g_ptr_array_free(stream->events_by_id, TRUE);
2050
2050
        g_hash_table_destroy(stream->event_quark_to_id);
2051
 
        free_declaration_scope(stream->declaration_scope);
 
2051
        bt_free_declaration_scope(stream->declaration_scope);
2052
2052
        g_free(stream);
2053
2053
        return ret;
2054
2054
}
2155
2155
                        }
2156
2156
                        CTF_TRACE_SET_FIELD(trace, byte_order);
2157
2157
                } else if (!strcmp(left, "packet.header")) {
2158
 
                        struct declaration *declaration;
 
2158
                        struct bt_declaration *declaration;
2159
2159
 
2160
2160
                        if (trace->packet_header_decl) {
2161
2161
                                fprintf(fd, "[error] %s: packet.header already declared in trace declaration\n", __func__);
2199
2199
 
2200
2200
        if (trace->declaration_scope)
2201
2201
                return -EEXIST;
2202
 
        trace->declaration_scope = new_declaration_scope(trace->root_declaration_scope);
 
2202
        trace->declaration_scope = bt_new_declaration_scope(trace->root_declaration_scope);
2203
2203
        trace->streams = g_ptr_array_new();
2204
2204
        trace->event_declarations = g_ptr_array_new();
2205
2205
        bt_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) {
2226
2226
        if (!CTF_TRACE_FIELD_IS_SET(trace, byte_order)) {
2227
2227
                /* check that the packet header contains a "magic" field */
2228
2228
                if (!trace->packet_header_decl
2229
 
                    || struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("magic")) < 0) {
 
2229
                    || bt_struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("magic")) < 0) {
2230
2230
                        ret = -EPERM;
2231
2231
                        fprintf(fd, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__);
2232
2232
                        goto error;
2236
2236
 
2237
2237
error:
2238
2238
        if (trace->packet_header_decl) {
2239
 
                declaration_unref(&trace->packet_header_decl->p);
 
2239
                bt_declaration_unref(&trace->packet_header_decl->p);
2240
2240
                trace->packet_header_decl = NULL;
2241
2241
        }
2242
2242
        g_ptr_array_free(trace->streams, TRUE);
2243
2243
        g_ptr_array_free(trace->event_declarations, TRUE);
2244
 
        free_declaration_scope(trace->declaration_scope);
 
2244
        bt_free_declaration_scope(trace->declaration_scope);
2245
2245
        trace->declaration_scope = NULL;
2246
2246
        return ret;
2247
2247
}
2398
2398
        if (opt_clock_force_correlate) {
2399
2399
                /*
2400
2400
                 * User requested to forcibly correlate the clock
2401
 
                 * sources, even if we have no correlatation
 
2401
                 * sources, even if we have no correlation
2402
2402
                 * information.
2403
2403
                 */
2404
2404
                if (!clock->absolute) {
2841
2841
                break;
2842
2842
        case NODE_TYPE_SPECIFIER_LIST:
2843
2843
        {
2844
 
                struct declaration *declaration;
 
2844
                struct bt_declaration *declaration;
2845
2845
 
2846
2846
                /*
2847
2847
                 * Just add the type specifier to the root scope
2851
2851
                        node, trace->root_declaration_scope, trace);
2852
2852
                if (!declaration)
2853
2853
                        return -ENOMEM;
2854
 
                declaration_unref(declaration);
 
2854
                bt_declaration_unref(declaration);
2855
2855
                break;
2856
2856
        }
2857
2857
        default:
2868
2868
        struct ctf_node *iter;
2869
2869
        int env_clock_done = 0;
2870
2870
 
2871
 
        printf_verbose("CTF visitor: metadata construction... ");
 
2871
        printf_verbose("CTF visitor: metadata construction...\n");
2872
2872
        trace->byte_order = byte_order;
2873
2873
        trace->clocks = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2874
2874
                                NULL, clock_free);
2876
2876
                                NULL, callsite_free);
2877
2877
 
2878
2878
retry:
2879
 
        trace->root_declaration_scope = new_declaration_scope(NULL);
 
2879
        trace->root_declaration_scope = bt_new_declaration_scope(NULL);
2880
2880
 
2881
2881
        switch (node->type) {
2882
2882
        case NODE_ROOT:
2910
2910
                bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
2911
2911
                        ret = ctf_trace_visit(fd, depth + 1, iter, trace);
2912
2912
                        if (ret == -EINTR) {
2913
 
                                free_declaration_scope(trace->root_declaration_scope);
 
2913
                                bt_free_declaration_scope(trace->root_declaration_scope);
2914
2914
                                /*
2915
2915
                                 * Need to restart creation of type
2916
2916
                                 * definitions, aliases and
2971
2971
        return ret;
2972
2972
 
2973
2973
error:
2974
 
        free_declaration_scope(trace->root_declaration_scope);
 
2974
        bt_free_declaration_scope(trace->root_declaration_scope);
2975
2975
        g_hash_table_destroy(trace->callsites);
2976
2976
        g_hash_table_destroy(trace->clocks);
2977
2977
        return ret;
3004
3004
                                        if (!event)
3005
3005
                                                continue;
3006
3006
                                        if (&event->event_fields->p)
3007
 
                                                definition_unref(&event->event_fields->p);
 
3007
                                                bt_definition_unref(&event->event_fields->p);
3008
3008
                                        if (&event->event_context->p)
3009
 
                                                definition_unref(&event->event_context->p);
 
3009
                                                bt_definition_unref(&event->event_context->p);
3010
3010
                                        g_free(event);
3011
3011
                                }
3012
3012
                                if (&stream_def->trace_packet_header->p)
3013
 
                                        definition_unref(&stream_def->trace_packet_header->p);
 
3013
                                        bt_definition_unref(&stream_def->trace_packet_header->p);
3014
3014
                                if (&stream_def->stream_event_header->p)
3015
 
                                        definition_unref(&stream_def->stream_event_header->p);
 
3015
                                        bt_definition_unref(&stream_def->stream_event_header->p);
3016
3016
                                if (&stream_def->stream_packet_context->p)
3017
 
                                        definition_unref(&stream_def->stream_packet_context->p);
 
3017
                                        bt_definition_unref(&stream_def->stream_packet_context->p);
3018
3018
                                if (&stream_def->stream_event_context->p)
3019
 
                                        definition_unref(&stream_def->stream_event_context->p);
 
3019
                                        bt_definition_unref(&stream_def->stream_event_context->p);
3020
3020
                                g_ptr_array_free(stream_def->events_by_id, TRUE);
3021
3021
                                g_free(stream_def);
3022
3022
                        }
3023
3023
                        if (stream->event_header_decl)
3024
 
                                declaration_unref(&stream->event_header_decl->p);
 
3024
                                bt_declaration_unref(&stream->event_header_decl->p);
3025
3025
                        if (stream->event_context_decl)
3026
 
                                declaration_unref(&stream->event_context_decl->p);
 
3026
                                bt_declaration_unref(&stream->event_context_decl->p);
3027
3027
                        if (stream->packet_context_decl)
3028
 
                                declaration_unref(&stream->packet_context_decl->p);
 
3028
                                bt_declaration_unref(&stream->packet_context_decl->p);
3029
3029
                        g_ptr_array_free(stream->streams, TRUE);
3030
3030
                        g_ptr_array_free(stream->events_by_id, TRUE);
3031
3031
                        g_hash_table_destroy(stream->event_quark_to_id);
3032
 
                        free_declaration_scope(stream->declaration_scope);
 
3032
                        bt_free_declaration_scope(stream->declaration_scope);
3033
3033
                        g_free(stream);
3034
3034
                }
3035
3035
                g_ptr_array_free(trace->streams, TRUE);
3056
3056
 
3057
3057
                        event = &event_decl->parent;
3058
3058
                        if (event->fields_decl)
3059
 
                                declaration_unref(&event->fields_decl->p);
 
3059
                                bt_declaration_unref(&event->fields_decl->p);
3060
3060
                        if (event->context_decl)
3061
 
                                declaration_unref(&event->context_decl->p);
3062
 
                        free_declaration_scope(event->declaration_scope);
 
3061
                                bt_declaration_unref(&event->context_decl->p);
 
3062
                        bt_free_declaration_scope(event->declaration_scope);
3063
3063
 
3064
3064
                        g_free(event);
3065
3065
                }
3066
3066
                g_ptr_array_free(trace->event_declarations, TRUE);
3067
3067
        }
3068
3068
        if (trace->packet_header_decl)
3069
 
                declaration_unref(&trace->packet_header_decl->p);
 
3069
                bt_declaration_unref(&trace->packet_header_decl->p);
3070
3070
 
3071
 
        free_declaration_scope(trace->root_declaration_scope);
3072
 
        free_declaration_scope(trace->declaration_scope);
 
3071
        bt_free_declaration_scope(trace->root_declaration_scope);
 
3072
        bt_free_declaration_scope(trace->declaration_scope);
3073
3073
 
3074
3074
        g_hash_table_destroy(trace->callsites);
3075
3075
        g_hash_table_destroy(trace->clocks);