sink.text.pretty: abort on unknown field class type
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-update-text-array-sequence.cpp
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #include <stdint.h>
8
9 #include "ctf-meta-visitors.hpp"
10
11 static inline int set_text_array_sequence_field_class(struct ctf_field_class *fc)
12 {
13 int ret = 0;
14 uint64_t i;
15
16 if (!fc) {
17 goto end;
18 }
19
20 switch (fc->type) {
21 case CTF_FIELD_CLASS_TYPE_STRUCT:
22 {
23 struct ctf_field_class_struct *struct_fc = ctf_field_class_as_struct(fc);
24
25 for (i = 0; i < struct_fc->members->len; i++) {
26 struct ctf_named_field_class *named_fc =
27 ctf_field_class_struct_borrow_member_by_index(struct_fc, i);
28
29 ret = set_text_array_sequence_field_class(named_fc->fc);
30 if (ret) {
31 goto end;
32 }
33 }
34
35 break;
36 }
37 case CTF_FIELD_CLASS_TYPE_VARIANT:
38 {
39 struct ctf_field_class_variant *var_fc = ctf_field_class_as_variant(fc);
40
41 for (i = 0; i < var_fc->options->len; i++) {
42 struct ctf_named_field_class *named_fc =
43 ctf_field_class_variant_borrow_option_by_index(var_fc, i);
44
45 ret = set_text_array_sequence_field_class(named_fc->fc);
46 if (ret) {
47 goto end;
48 }
49 }
50
51 break;
52 }
53 case CTF_FIELD_CLASS_TYPE_ARRAY:
54 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
55 {
56 struct ctf_field_class_array_base *array_fc = ctf_field_class_as_array_base(fc);
57
58 if (array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_INT ||
59 array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_ENUM) {
60 struct ctf_field_class_int *int_fc = ctf_field_class_as_int(array_fc->elem_fc);
61
62 if (int_fc->base.base.alignment == 8 && int_fc->base.size == 8 &&
63 int_fc->encoding == CTF_ENCODING_UTF8) {
64 array_fc->is_text = true;
65
66 /*
67 * Force integer element to be unsigned;
68 * this makes the decoder enter a single
69 * path when reading a text
70 * array/sequence and we can safely
71 * decode bytes as characters anyway.
72 */
73 int_fc->is_signed = false;
74 }
75 }
76
77 ret = set_text_array_sequence_field_class(array_fc->elem_fc);
78 if (ret) {
79 goto end;
80 }
81
82 break;
83 }
84 default:
85 break;
86 }
87
88 end:
89 return ret;
90 }
91
92 int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class *ctf_tc)
93 {
94 int ret = 0;
95 uint64_t i;
96
97 if (!ctf_tc->is_translated) {
98 ret = set_text_array_sequence_field_class(ctf_tc->packet_header_fc);
99 if (ret) {
100 goto end;
101 }
102 }
103
104 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
105 ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i];
106 uint64_t j;
107
108 if (!sc->is_translated) {
109 ret = set_text_array_sequence_field_class(sc->packet_context_fc);
110 if (ret) {
111 goto end;
112 }
113
114 ret = set_text_array_sequence_field_class(sc->event_header_fc);
115 if (ret) {
116 goto end;
117 }
118
119 ret = set_text_array_sequence_field_class(sc->event_common_context_fc);
120 if (ret) {
121 goto end;
122 }
123 }
124
125 for (j = 0; j < sc->event_classes->len; j++) {
126 struct ctf_event_class *ec = (ctf_event_class *) sc->event_classes->pdata[j];
127
128 if (ec->is_translated) {
129 continue;
130 }
131
132 ret = set_text_array_sequence_field_class(ec->spec_context_fc);
133 if (ret) {
134 goto end;
135 }
136
137 ret = set_text_array_sequence_field_class(ec->payload_fc);
138 if (ret) {
139 goto end;
140 }
141 }
142 }
143
144 end:
145 return ret;
146 }
This page took 0.034434 seconds and 5 git commands to generate.