bt2: add boolean field class and field support
[babeltrace.git] / src / lib / trace-ir / resolve-field-path.c
CommitLineData
44c440bc
PP
1/*
2 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
350ad6c1 23#define BT_LOG_TAG "LIB/RESOLVE-FIELD-PATH"
c2d9d9cf 24#include "lib/logging.h"
44c440bc 25
578e048b
MJ
26#include "lib/assert-pre.h"
27#include "common/assert.h"
3fadfbc0 28#include <babeltrace2/trace-ir/field-path-const.h>
44c440bc
PP
29#include <limits.h>
30#include <stdint.h>
31#include <inttypes.h>
32#include <glib.h>
33
578e048b
MJ
34#include "field-class.h"
35#include "field-path.h"
36#include "resolve-field-path.h"
37
44c440bc 38static
5cd6d0e5
PP
39bool find_field_class_recursive(struct bt_field_class *fc,
40 struct bt_field_class *tgt_fc, struct bt_field_path *field_path)
44c440bc
PP
41{
42 bool found = false;
43
5cd6d0e5 44 if (tgt_fc == fc) {
44c440bc
PP
45 found = true;
46 goto end;
47 }
48
864cad70
PP
49 switch (fc->type) {
50 case BT_FIELD_CLASS_TYPE_STRUCTURE:
45c51519
PP
51 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
52 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
53 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
44c440bc 54 {
5cd6d0e5
PP
55 struct bt_field_class_named_field_class_container *container_fc =
56 (void *) fc;
44c440bc
PP
57 uint64_t i;
58
5cd6d0e5
PP
59 for (i = 0; i < container_fc->named_fcs->len; i++) {
60 struct bt_named_field_class *named_fc =
45c51519 61 container_fc->named_fcs->pdata[i];
66ddcddf
PP
62 struct bt_field_path_item item = {
63 .type = BT_FIELD_PATH_ITEM_TYPE_INDEX,
64 .index = i,
65 };
44c440bc 66
66ddcddf 67 bt_field_path_append_item(field_path, &item);
5cd6d0e5
PP
68 found = find_field_class_recursive(named_fc->fc,
69 tgt_fc, field_path);
44c440bc
PP
70 if (found) {
71 goto end;
72 }
73
66ddcddf 74 bt_field_path_remove_last_item(field_path);
44c440bc
PP
75 }
76
77 break;
78 }
864cad70
PP
79 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
80 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
44c440bc 81 {
5cd6d0e5 82 struct bt_field_class_array *array_fc = (void *) fc;
66ddcddf
PP
83 struct bt_field_path_item item = {
84 .type = BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT,
85 .index = UINT64_C(-1),
86 };
44c440bc 87
66ddcddf 88 bt_field_path_append_item(field_path, &item);
5cd6d0e5
PP
89 found = find_field_class_recursive(array_fc->element_fc,
90 tgt_fc, field_path);
66ddcddf
PP
91 if (found) {
92 goto end;
93 }
94
95 bt_field_path_remove_last_item(field_path);
44c440bc
PP
96 break;
97 }
98 default:
99 break;
100 }
101
102end:
103 return found;
104}
105
106static
5cd6d0e5 107int find_field_class(struct bt_field_class *root_fc,
e7ceb9df 108 enum bt_field_path_scope root_scope, struct bt_field_class *tgt_fc,
44c440bc
PP
109 struct bt_field_path **ret_field_path)
110{
111 int ret = 0;
112 struct bt_field_path *field_path = NULL;
113
5cd6d0e5 114 if (!root_fc) {
44c440bc
PP
115 goto end;
116 }
117
118 field_path = bt_field_path_create();
119 if (!field_path) {
120 ret = -1;
121 goto end;
122 }
123
124 field_path->root = root_scope;
5cd6d0e5 125 if (!find_field_class_recursive(root_fc, tgt_fc, field_path)) {
44c440bc 126 /* Not found here */
65300d60 127 BT_OBJECT_PUT_REF_AND_RESET(field_path);
44c440bc
PP
128 }
129
130end:
131 *ret_field_path = field_path;
132 return ret;
133}
134
135static
5cd6d0e5 136struct bt_field_path *find_field_class_in_ctx(struct bt_field_class *fc,
44c440bc
PP
137 struct bt_resolve_field_path_context *ctx)
138{
139 struct bt_field_path *field_path = NULL;
140 int ret;
141
e7ceb9df 142 ret = find_field_class(ctx->packet_context, BT_FIELD_PATH_SCOPE_PACKET_CONTEXT,
5cd6d0e5 143 fc, &field_path);
44c440bc
PP
144 if (ret || field_path) {
145 goto end;
146 }
147
5cd6d0e5 148 ret = find_field_class(ctx->event_common_context,
e7ceb9df 149 BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT, fc, &field_path);
44c440bc
PP
150 if (ret || field_path) {
151 goto end;
152 }
153
5cd6d0e5 154 ret = find_field_class(ctx->event_specific_context,
e7ceb9df 155 BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT, fc, &field_path);
44c440bc
PP
156 if (ret || field_path) {
157 goto end;
158 }
159
e7ceb9df 160 ret = find_field_class(ctx->event_payload, BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD,
5cd6d0e5 161 fc, &field_path);
44c440bc
PP
162 if (ret || field_path) {
163 goto end;
164 }
165
166end:
167 return field_path;
168}
169
bdb288b3 170BT_ASSERT_PRE_DEV_FUNC
44c440bc
PP
171static inline
172bool target_is_before_source(struct bt_field_path *src_field_path,
173 struct bt_field_path *tgt_field_path)
174{
175 bool is_valid = true;
176 uint64_t src_i = 0, tgt_i = 0;
177
178 if (tgt_field_path->root < src_field_path->root) {
179 goto end;
180 }
181
182 if (tgt_field_path->root > src_field_path->root) {
183 is_valid = false;
184 goto end;
185 }
186
187 BT_ASSERT(tgt_field_path->root == src_field_path->root);
188
66ddcddf
PP
189 for (src_i = 0, tgt_i = 0; src_i < src_field_path->items->len &&
190 tgt_i < tgt_field_path->items->len; src_i++, tgt_i++) {
191 struct bt_field_path_item *src_fp_item =
192 bt_field_path_borrow_item_by_index_inline(
193 src_field_path, src_i);
194 struct bt_field_path_item *tgt_fp_item =
195 bt_field_path_borrow_item_by_index_inline(
196 tgt_field_path, tgt_i);
197
198 if (src_fp_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX &&
199 tgt_fp_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX) {
200 if (tgt_fp_item->index > src_fp_item->index) {
201 is_valid = false;
202 goto end;
203 }
44c440bc
PP
204 }
205
206 src_i++;
207 tgt_i++;
208 }
209
210end:
211 return is_valid;
212}
213
bdb288b3 214BT_ASSERT_PRE_DEV_FUNC
44c440bc 215static inline
5cd6d0e5 216struct bt_field_class *borrow_root_field_class(
e7ceb9df 217 struct bt_resolve_field_path_context *ctx, enum bt_field_path_scope scope)
44c440bc
PP
218{
219 switch (scope) {
e7ceb9df 220 case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT:
44c440bc 221 return ctx->packet_context;
e7ceb9df 222 case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT:
44c440bc 223 return ctx->event_common_context;
e7ceb9df 224 case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT:
44c440bc 225 return ctx->event_specific_context;
e7ceb9df 226 case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD:
44c440bc
PP
227 return ctx->event_payload;
228 default:
229 abort();
230 }
231
232 return NULL;
233}
234
bdb288b3 235BT_ASSERT_PRE_DEV_FUNC
44c440bc 236static inline
66ddcddf
PP
237struct bt_field_class *borrow_child_field_class(
238 struct bt_field_class *parent_fc,
239 struct bt_field_path_item *fp_item)
44c440bc 240{
5cd6d0e5 241 struct bt_field_class *child_fc = NULL;
44c440bc 242
864cad70
PP
243 switch (parent_fc->type) {
244 case BT_FIELD_CLASS_TYPE_STRUCTURE:
45c51519
PP
245 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
246 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
247 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
44c440bc 248 {
45c51519
PP
249 struct bt_field_class_named_field_class_container *container_fc =
250 (void *) parent_fc;
66ddcddf 251 struct bt_named_field_class *named_fc;
44c440bc 252
66ddcddf 253 BT_ASSERT(fp_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX);
45c51519 254 named_fc = container_fc->named_fcs->pdata[fp_item->index];
5cd6d0e5 255 child_fc = named_fc->fc;
44c440bc
PP
256 break;
257 }
864cad70
PP
258 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
259 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
44c440bc 260 {
5cd6d0e5 261 struct bt_field_class_array *array_fc = (void *) parent_fc;
44c440bc 262
66ddcddf
PP
263 BT_ASSERT(fp_item->type ==
264 BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT);
5cd6d0e5 265 child_fc = array_fc->element_fc;
44c440bc
PP
266 break;
267 }
268 default:
269 break;
270 }
271
5cd6d0e5 272 return child_fc;
44c440bc
PP
273}
274
bdb288b3 275BT_ASSERT_PRE_DEV_FUNC
44c440bc 276static inline
5cd6d0e5 277bool target_field_path_in_different_scope_has_struct_fc_only(
44c440bc
PP
278 struct bt_field_path *src_field_path,
279 struct bt_field_path *tgt_field_path,
280 struct bt_resolve_field_path_context *ctx)
281{
282 bool is_valid = true;
283 uint64_t i = 0;
5cd6d0e5 284 struct bt_field_class *fc;
44c440bc
PP
285
286 if (src_field_path->root == tgt_field_path->root) {
287 goto end;
288 }
289
5cd6d0e5 290 fc = borrow_root_field_class(ctx, tgt_field_path->root);
44c440bc 291
66ddcddf
PP
292 for (i = 0; i < tgt_field_path->items->len; i++) {
293 struct bt_field_path_item *fp_item =
294 bt_field_path_borrow_item_by_index_inline(
295 tgt_field_path, i);
44c440bc 296
864cad70
PP
297 if (fc->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY ||
298 fc->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY ||
45c51519
PP
299 fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR ||
300 fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR ||
301 fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) {
44c440bc
PP
302 is_valid = false;
303 goto end;
304 }
305
66ddcddf
PP
306 BT_ASSERT(fp_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX);
307 fc = borrow_child_field_class(fc, fp_item);
44c440bc
PP
308 }
309
310end:
311 return is_valid;
312}
313
bdb288b3 314BT_ASSERT_PRE_DEV_FUNC
44c440bc 315static inline
5cd6d0e5 316bool lca_is_structure_field_class(struct bt_field_path *src_field_path,
44c440bc
PP
317 struct bt_field_path *tgt_field_path,
318 struct bt_resolve_field_path_context *ctx)
319{
320 bool is_valid = true;
5cd6d0e5
PP
321 struct bt_field_class *src_fc;
322 struct bt_field_class *tgt_fc;
323 struct bt_field_class *prev_fc = NULL;
44c440bc
PP
324 uint64_t src_i = 0, tgt_i = 0;
325
326 if (src_field_path->root != tgt_field_path->root) {
327 goto end;
328 }
329
5cd6d0e5
PP
330 src_fc = borrow_root_field_class(ctx, src_field_path->root);
331 tgt_fc = borrow_root_field_class(ctx, tgt_field_path->root);
332 BT_ASSERT(src_fc);
333 BT_ASSERT(tgt_fc);
44c440bc 334
66ddcddf
PP
335 for (src_i = 0, tgt_i = 0; src_i < src_field_path->items->len &&
336 tgt_i < tgt_field_path->items->len; src_i++, tgt_i++) {
337 struct bt_field_path_item *src_fp_item =
338 bt_field_path_borrow_item_by_index_inline(
339 src_field_path, src_i);
340 struct bt_field_path_item *tgt_fp_item =
341 bt_field_path_borrow_item_by_index_inline(
342 tgt_field_path, tgt_i);
44c440bc 343
5cd6d0e5
PP
344 if (src_fc != tgt_fc) {
345 if (!prev_fc) {
44c440bc
PP
346 /*
347 * This is correct: the LCA is the root
e6276565
PP
348 * scope field class, which must be a
349 * structure field class.
44c440bc
PP
350 */
351 break;
352 }
353
864cad70 354 if (prev_fc->type != BT_FIELD_CLASS_TYPE_STRUCTURE) {
44c440bc
PP
355 is_valid = false;
356 }
357
358 break;
359 }
360
5cd6d0e5 361 prev_fc = src_fc;
66ddcddf
PP
362 src_fc = borrow_child_field_class(src_fc, src_fp_item);
363 tgt_fc = borrow_child_field_class(tgt_fc, tgt_fp_item);
44c440bc
PP
364 }
365
366end:
367 return is_valid;
368}
369
bdb288b3 370BT_ASSERT_PRE_DEV_FUNC
44c440bc 371static inline
5cd6d0e5 372bool lca_to_target_has_struct_fc_only(struct bt_field_path *src_field_path,
44c440bc
PP
373 struct bt_field_path *tgt_field_path,
374 struct bt_resolve_field_path_context *ctx)
375{
376 bool is_valid = true;
5cd6d0e5
PP
377 struct bt_field_class *src_fc;
378 struct bt_field_class *tgt_fc;
44c440bc
PP
379 uint64_t src_i = 0, tgt_i = 0;
380
381 if (src_field_path->root != tgt_field_path->root) {
382 goto end;
383 }
384
5cd6d0e5
PP
385 src_fc = borrow_root_field_class(ctx, src_field_path->root);
386 tgt_fc = borrow_root_field_class(ctx, tgt_field_path->root);
387 BT_ASSERT(src_fc);
388 BT_ASSERT(tgt_fc);
389 BT_ASSERT(src_fc == tgt_fc);
44c440bc
PP
390
391 /* Find LCA */
66ddcddf
PP
392 for (src_i = 0, tgt_i = 0; src_i < src_field_path->items->len &&
393 tgt_i < tgt_field_path->items->len; src_i++, tgt_i++) {
394 struct bt_field_path_item *src_fp_item =
395 bt_field_path_borrow_item_by_index_inline(
396 src_field_path, src_i);
397 struct bt_field_path_item *tgt_fp_item =
398 bt_field_path_borrow_item_by_index_inline(
399 tgt_field_path, tgt_i);
44c440bc
PP
400
401 if (src_i != tgt_i) {
5cd6d0e5 402 /* Next field class is different: LCA is `tgt_fc` */
44c440bc
PP
403 break;
404 }
405
66ddcddf
PP
406 src_fc = borrow_child_field_class(src_fc, src_fp_item);
407 tgt_fc = borrow_child_field_class(tgt_fc, tgt_fp_item);
44c440bc
PP
408 }
409
5cd6d0e5 410 /* Only structure field classes to the target */
66ddcddf
PP
411 for (; tgt_i < tgt_field_path->items->len; tgt_i++) {
412 struct bt_field_path_item *tgt_fp_item =
413 bt_field_path_borrow_item_by_index_inline(
414 tgt_field_path, tgt_i);
44c440bc 415
864cad70
PP
416 if (tgt_fc->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY ||
417 tgt_fc->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY ||
45c51519
PP
418 tgt_fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR ||
419 tgt_fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR ||
420 tgt_fc->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) {
44c440bc
PP
421 is_valid = false;
422 goto end;
423 }
424
66ddcddf 425 tgt_fc = borrow_child_field_class(tgt_fc, tgt_fp_item);
44c440bc
PP
426 }
427
428end:
429 return is_valid;
430}
431
bdb288b3 432BT_ASSERT_PRE_DEV_FUNC
44c440bc 433static inline
5cd6d0e5
PP
434bool field_path_is_valid(struct bt_field_class *src_fc,
435 struct bt_field_class *tgt_fc,
44c440bc
PP
436 struct bt_resolve_field_path_context *ctx)
437{
438 bool is_valid = true;
5cd6d0e5
PP
439 struct bt_field_path *src_field_path = find_field_class_in_ctx(
440 src_fc, ctx);
441 struct bt_field_path *tgt_field_path = find_field_class_in_ctx(
442 tgt_fc, ctx);
44c440bc
PP
443
444 if (!src_field_path) {
bdb288b3 445 BT_ASSERT_PRE_DEV_MSG("Cannot find requesting field class in "
5cd6d0e5 446 "resolving context: %!+F", src_fc);
44c440bc
PP
447 is_valid = false;
448 goto end;
449 }
450
451 if (!tgt_field_path) {
bdb288b3 452 BT_ASSERT_PRE_DEV_MSG("Cannot find target field class in "
5cd6d0e5 453 "resolving context: %!+F", tgt_fc);
44c440bc
PP
454 is_valid = false;
455 goto end;
456 }
457
458 /* Target must be before source */
459 if (!target_is_before_source(src_field_path, tgt_field_path)) {
bdb288b3 460 BT_ASSERT_PRE_DEV_MSG("Target field class is located after "
e6276565 461 "requesting field class: %![req-fc-]+F, %![tgt-fc-]+F",
5cd6d0e5 462 src_fc, tgt_fc);
44c440bc
PP
463 is_valid = false;
464 goto end;
465 }
466
467 /*
468 * If target is in a different scope than source, there are no
5cd6d0e5 469 * array or variant field classes on the way to the target.
44c440bc 470 */
5cd6d0e5 471 if (!target_field_path_in_different_scope_has_struct_fc_only(
44c440bc 472 src_field_path, tgt_field_path, ctx)) {
bdb288b3 473 BT_ASSERT_PRE_DEV_MSG("Target field class is located in a "
e6276565
PP
474 "different scope than requesting field class, "
475 "but within an array or a variant field class: "
5cd6d0e5
PP
476 "%![req-fc-]+F, %![tgt-fc-]+F",
477 src_fc, tgt_fc);
44c440bc
PP
478 is_valid = false;
479 goto end;
480 }
481
e6276565 482 /* Same scope: LCA must be a structure field class */
5cd6d0e5 483 if (!lca_is_structure_field_class(src_field_path, tgt_field_path, ctx)) {
bdb288b3 484 BT_ASSERT_PRE_DEV_MSG("Lowest common ancestor of target and "
e6276565 485 "requesting field classes is not a structure field class: "
5cd6d0e5
PP
486 "%![req-fc-]+F, %![tgt-fc-]+F",
487 src_fc, tgt_fc);
44c440bc
PP
488 is_valid = false;
489 goto end;
490 }
491
492 /* Same scope: path from LCA to target has no array/variant FTs */
5cd6d0e5 493 if (!lca_to_target_has_struct_fc_only(src_field_path, tgt_field_path,
44c440bc 494 ctx)) {
bdb288b3 495 BT_ASSERT_PRE_DEV_MSG("Path from lowest common ancestor of target "
e6276565
PP
496 "and requesting field classes to target field class "
497 "contains an array or a variant field class: "
5cd6d0e5 498 "%![req-fc-]+F, %![tgt-fc-]+F", src_fc, tgt_fc);
44c440bc
PP
499 is_valid = false;
500 goto end;
501 }
502
503end:
65300d60
PP
504 bt_object_put_ref(src_field_path);
505 bt_object_put_ref(tgt_field_path);
44c440bc
PP
506 return is_valid;
507}
508
509static
5cd6d0e5
PP
510struct bt_field_path *resolve_field_path(struct bt_field_class *src_fc,
511 struct bt_field_class *tgt_fc,
44c440bc
PP
512 struct bt_resolve_field_path_context *ctx)
513{
bdb288b3 514 BT_ASSERT_PRE_DEV(field_path_is_valid(src_fc, tgt_fc, ctx),
e6276565 515 "Invalid target field class: %![req-fc-]+F, %![tgt-fc-]+F",
5cd6d0e5
PP
516 src_fc, tgt_fc);
517 return find_field_class_in_ctx(tgt_fc, ctx);
44c440bc
PP
518}
519
520BT_HIDDEN
5cd6d0e5 521int bt_resolve_field_paths(struct bt_field_class *fc,
44c440bc
PP
522 struct bt_resolve_field_path_context *ctx)
523{
524 int ret = 0;
525
5cd6d0e5 526 BT_ASSERT(fc);
44c440bc 527
5cd6d0e5 528 /* Resolving part for dynamic array and variant field classes */
864cad70
PP
529 switch (fc->type) {
530 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
44c440bc 531 {
9c08c816 532 struct bt_field_class_array_dynamic *dyn_array_fc = (void *) fc;
44c440bc 533
5cd6d0e5
PP
534 if (dyn_array_fc->length_fc) {
535 BT_ASSERT(!dyn_array_fc->length_field_path);
536 dyn_array_fc->length_field_path = resolve_field_path(
537 fc, dyn_array_fc->length_fc, ctx);
538 if (!dyn_array_fc->length_field_path) {
44c440bc
PP
539 ret = -1;
540 goto end;
541 }
542 }
543
544 break;
545 }
45c51519
PP
546 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
547 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
44c440bc 548 {
45c51519
PP
549 struct bt_field_class_variant_with_selector *var_fc =
550 (void *) fc;
5cd6d0e5
PP
551
552 if (var_fc->selector_fc) {
553 BT_ASSERT(!var_fc->selector_field_path);
554 var_fc->selector_field_path =
555 resolve_field_path(fc,
45c51519 556 (void *) var_fc->selector_fc, ctx);
5cd6d0e5 557 if (!var_fc->selector_field_path) {
44c440bc
PP
558 ret = -1;
559 goto end;
560 }
561 }
562 }
563 default:
564 break;
565 }
566
567 /* Recursive part */
864cad70
PP
568 switch (fc->type) {
569 case BT_FIELD_CLASS_TYPE_STRUCTURE:
45c51519
PP
570 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
571 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
572 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
44c440bc 573 {
5cd6d0e5
PP
574 struct bt_field_class_named_field_class_container *container_fc =
575 (void *) fc;
44c440bc
PP
576 uint64_t i;
577
5cd6d0e5
PP
578 for (i = 0; i < container_fc->named_fcs->len; i++) {
579 struct bt_named_field_class *named_fc =
45c51519 580 container_fc->named_fcs->pdata[i];
44c440bc 581
5cd6d0e5 582 ret = bt_resolve_field_paths(named_fc->fc, ctx);
44c440bc
PP
583 if (ret) {
584 goto end;
585 }
586 }
587
588 break;
589 }
864cad70
PP
590 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
591 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
44c440bc 592 {
5cd6d0e5 593 struct bt_field_class_array *array_fc = (void *) fc;
44c440bc 594
5cd6d0e5 595 ret = bt_resolve_field_paths(array_fc->element_fc, ctx);
44c440bc
PP
596 break;
597 }
598 default:
599 break;
600 }
601
602end:
603 return ret;
604}
This page took 0.064302 seconds and 4 git commands to generate.