- int set = 0;
- int ret = 0;
- int signedness = 0;
- struct ctf_node *expression;
- uint64_t alignment = 0, size = 0;
- struct ctf_clock_class *mapped_clock_class = NULL;
- enum ctf_encoding encoding = CTF_ENCODING_NONE;
- bt_field_class_integer_preferred_display_base base =
- BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL;
- enum ctf_byte_order byte_order = ctx->ctf_tc->default_byte_order;
-
- *integer_decl = NULL;
-
- bt_list_for_each_entry(expression, expressions, siblings) {
- struct ctf_node *left, *right;
-
- left = _BT_LIST_FIRST_ENTRY(&expression->u.ctf_expression.left,
- struct ctf_node, siblings);
- right = _BT_LIST_FIRST_ENTRY(
- &expression->u.ctf_expression.right, struct ctf_node,
- siblings);
-
- if (left->u.unary_expression.type != UNARY_STRING) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(left,
- "Unexpected unary expression type: type=%d",
- left->u.unary_expression.type);
- ret = -EINVAL;
- goto error;
- }
-
- if (strcmp(left->u.unary_expression.u.string, "signed") == 0) {
- if (_IS_SET(&set, _INTEGER_SIGNED_SET)) {
- _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "signed",
- "integer field class");
- ret = -EPERM;
- goto error;
- }
-
- signedness = get_boolean(ctx, right);
- if (signedness < 0) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid boolean value for integer field class's `signed` attribute: "
- "ret=%d", ret);
- ret = -EINVAL;
- goto error;
- }
-
- _SET(&set, _INTEGER_SIGNED_SET);
- } else if (strcmp(left->u.unary_expression.u.string, "byte_order") == 0) {
- if (_IS_SET(&set, _INTEGER_BYTE_ORDER_SET)) {
- _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "byte_order",
- "integer field class");
- ret = -EPERM;
- goto error;
- }
-
- byte_order = get_real_byte_order(ctx, right);
- if (byte_order == CTF_BYTE_ORDER_UNKNOWN) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `byte_order` attribute in integer field class: "
- "ret=%d", ret);
- ret = -EINVAL;
- goto error;
- }
-
- _SET(&set, _INTEGER_BYTE_ORDER_SET);
- } else if (strcmp(left->u.unary_expression.u.string, "size") == 0) {
- if (_IS_SET(&set, _INTEGER_SIZE_SET)) {
- _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "size",
- "integer field class");
- ret = -EPERM;
- goto error;
- }
-
- if (right->u.unary_expression.type !=
- UNARY_UNSIGNED_CONSTANT) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `size` attribute in integer field class: "
- "expecting unsigned constant integer: "
- "node-type=%d",
- right->u.unary_expression.type);
- ret = -EINVAL;
- goto error;
- }
-
- size = right->u.unary_expression.u.unsigned_constant;
- if (size == 0) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `size` attribute in integer field class: "
- "expecting positive constant integer: "
- "size=%" PRIu64, size);
- ret = -EINVAL;
- goto error;
- } else if (size > 64) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `size` attribute in integer field class: "
- "integer fields over 64 bits are not supported as of this version: "
- "size=%" PRIu64, size);
- ret = -EINVAL;
- goto error;
- }
-
- _SET(&set, _INTEGER_SIZE_SET);
- } else if (strcmp(left->u.unary_expression.u.string, "align") == 0) {
- if (_IS_SET(&set, _INTEGER_ALIGN_SET)) {
- _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "align",
- "integer field class");
- ret = -EPERM;
- goto error;
- }
-
- if (right->u.unary_expression.type !=
- UNARY_UNSIGNED_CONSTANT) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `align` attribute in integer field class: "
- "expecting unsigned constant integer: "
- "node-type=%d",
- right->u.unary_expression.type);
- ret = -EINVAL;
- goto error;
- }
-
- alignment =
- right->u.unary_expression.u.unsigned_constant;
- if (!is_align_valid(alignment)) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `align` attribute in integer field class: "
- "expecting power of two: "
- "align=%" PRIu64, alignment);
- ret = -EINVAL;
- goto error;
- }
-
- _SET(&set, _INTEGER_ALIGN_SET);
- } else if (strcmp(left->u.unary_expression.u.string, "base") == 0) {
- if (_IS_SET(&set, _INTEGER_BASE_SET)) {
- _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "base",
- "integer field class");
- ret = -EPERM;
- goto error;
- }
-
- switch (right->u.unary_expression.type) {
- case UNARY_UNSIGNED_CONSTANT:
- {
- uint64_t constant = right->u.unary_expression.
- u.unsigned_constant;
-
- switch (constant) {
- case 2:
- base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY;
- break;
- case 8:
- base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL;
- break;
- case 10:
- base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL;
- break;
- case 16:
- base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL;
- break;
- default:
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `base` attribute in integer field class: "
- "base=%" PRIu64,
- right->u.unary_expression.u.unsigned_constant);
- ret = -EINVAL;
- goto error;
- }
- break;
- }
- case UNARY_STRING:
- {
- char *s_right = ctf_ast_concatenate_unary_strings(
- &expression->u.ctf_expression.right);
- if (!s_right) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Unexpected unary expression for integer field class's `base` attribute.");
- ret = -EINVAL;
- goto error;
- }
-
- if (strcmp(s_right, "decimal") == 0 ||
- strcmp(s_right, "dec") == 0 ||
- strcmp(s_right, "d") == 0 ||
- strcmp(s_right, "i") == 0 ||
- strcmp(s_right, "u") == 0) {
- base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL;
- } else if (strcmp(s_right, "hexadecimal") == 0 ||
- strcmp(s_right, "hex") == 0 ||
- strcmp(s_right, "x") == 0 ||
- strcmp(s_right, "X") == 0 ||
- strcmp(s_right, "p") == 0) {
- base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL;
- } else if (strcmp(s_right, "octal") == 0 ||
- strcmp(s_right, "oct") == 0 ||
- strcmp(s_right, "o") == 0) {
- base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL;
- } else if (strcmp(s_right, "binary") == 0 ||
- strcmp(s_right, "b") == 0) {
- base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY;
- } else {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Unexpected unary expression for integer field class's `base` attribute: "
- "base=\"%s\"", s_right);
- g_free(s_right);
- ret = -EINVAL;
- goto error;
- }
-
- g_free(s_right);
- break;
- }
- default:
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `base` attribute in integer field class: "
- "expecting unsigned constant integer or unary string.");
- ret = -EINVAL;
- goto error;
- }
-
- _SET(&set, _INTEGER_BASE_SET);
- } else if (strcmp(left->u.unary_expression.u.string, "encoding") == 0) {
- char *s_right;
-
- if (_IS_SET(&set, _INTEGER_ENCODING_SET)) {
- _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "encoding",
- "integer field class");
- ret = -EPERM;
- goto error;
- }
-
- if (right->u.unary_expression.type != UNARY_STRING) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `encoding` attribute in integer field class: "
- "expecting unary string.");
- ret = -EINVAL;
- goto error;
- }
-
- s_right = ctf_ast_concatenate_unary_strings(
- &expression->u.ctf_expression.right);
- if (!s_right) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Unexpected unary expression for integer field class's `encoding` attribute.");
- ret = -EINVAL;
- goto error;
- }
-
- if (strcmp(s_right, "UTF8") == 0 ||
- strcmp(s_right, "utf8") == 0 ||
- strcmp(s_right, "utf-8") == 0 ||
- strcmp(s_right, "UTF-8") == 0 ||
- strcmp(s_right, "ASCII") == 0 ||
- strcmp(s_right, "ascii") == 0) {
- encoding = CTF_ENCODING_UTF8;
- } else if (strcmp(s_right, "none") == 0) {
- encoding = CTF_ENCODING_NONE;
- } else {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `encoding` attribute in integer field class: "
- "unknown encoding: encoding=\"%s\"",
- s_right);
- g_free(s_right);
- ret = -EINVAL;
- goto error;
- }
-
- g_free(s_right);
- _SET(&set, _INTEGER_ENCODING_SET);
- } else if (strcmp(left->u.unary_expression.u.string, "map") == 0) {
- const char *clock_name;
-
- if (_IS_SET(&set, _INTEGER_MAP_SET)) {
- _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "map",
- "integer field class");
- ret = -EPERM;
- goto error;
- }
-
- if (right->u.unary_expression.type != UNARY_STRING) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `map` attribute in integer field class: "
- "expecting unary string.");
- ret = -EINVAL;
- goto error;
- }
-
- clock_name =
- get_map_clock_name_value(
- &expression->u.ctf_expression.right);
- if (!clock_name) {
- char *s_right = ctf_ast_concatenate_unary_strings(
- &expression->u.ctf_expression.right);
-
- if (!s_right) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Unexpected unary expression for integer field class's `map` attribute.");
- ret = -EINVAL;
- goto error;
- }
-
- _BT_COMP_LOGE_NODE(right,
- "Invalid `map` attribute in integer field class: "
- "cannot find clock class at this point: name=\"%s\"",
- s_right);
- _SET(&set, _INTEGER_MAP_SET);
- g_free(s_right);
- continue;
- }
-
- mapped_clock_class =
- ctf_trace_class_borrow_clock_class_by_name(
- ctx->ctf_tc, clock_name);
- if (!mapped_clock_class) {
- _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
- "Invalid `map` attribute in integer field class: "
- "cannot find clock class at this point: name=\"%s\"",
- clock_name);
- ret = -EINVAL;
- goto error;
- }
-
- _SET(&set, _INTEGER_MAP_SET);
- } else {
- _BT_COMP_LOGW_NODE(left,
- "Unknown attribute in integer field class: "
- "attr-name=\"%s\"",
- left->u.unary_expression.u.string);
- }
- }
-
- if (!_IS_SET(&set, _INTEGER_SIZE_SET)) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Missing `size` attribute in integer field class.");
- ret = -EPERM;
- goto error;
- }
-
- if (!_IS_SET(&set, _INTEGER_ALIGN_SET)) {
- if (size % CHAR_BIT) {
- /* Bit-packed alignment */
- alignment = 1;
- } else {
- /* Byte-packed alignment */
- alignment = CHAR_BIT;
- }
- }
-
- *integer_decl = ctf_field_class_int_create();
- BT_ASSERT(*integer_decl);
- (*integer_decl)->base.base.alignment = alignment;
- (*integer_decl)->base.byte_order = byte_order;
- (*integer_decl)->base.size = size;
- (*integer_decl)->is_signed = (signedness > 0);
- (*integer_decl)->disp_base = base;
- (*integer_decl)->encoding = encoding;
- (*integer_decl)->mapped_clock_class = mapped_clock_class;
- return 0;
+ int set = 0;
+ int ret = 0;
+ int signedness = 0;
+ struct ctf_node *expression;
+ uint64_t alignment = 0, size = 0;
+ struct ctf_clock_class *mapped_clock_class = NULL;
+ enum ctf_encoding encoding = CTF_ENCODING_NONE;
+ bt_field_class_integer_preferred_display_base base =
+ BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL;
+ enum ctf_byte_order byte_order = ctx->ctf_tc->default_byte_order;
+
+ *integer_decl = NULL;
+
+ bt_list_for_each_entry (expression, expressions, siblings) {
+ struct ctf_node *left, *right;
+
+ left = _BT_LIST_FIRST_ENTRY(&expression->u.ctf_expression.left, struct ctf_node, siblings);
+ right =
+ _BT_LIST_FIRST_ENTRY(&expression->u.ctf_expression.right, struct ctf_node, siblings);
+
+ if (left->u.unary_expression.type != UNARY_STRING) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(left, "Unexpected unary expression type: type=%d",
+ left->u.unary_expression.type);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ if (strcmp(left->u.unary_expression.u.string, "signed") == 0) {
+ if (_IS_SET(&set, _INTEGER_SIGNED_SET)) {
+ _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "signed", "integer field class");
+ ret = -EPERM;
+ goto error;
+ }
+
+ signedness = get_boolean(ctx, right);
+ if (signedness < 0) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right,
+ "Invalid boolean value for integer field class's `signed` attribute: "
+ "ret=%d",
+ ret);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ _SET(&set, _INTEGER_SIGNED_SET);
+ } else if (strcmp(left->u.unary_expression.u.string, "byte_order") == 0) {
+ if (_IS_SET(&set, _INTEGER_BYTE_ORDER_SET)) {
+ _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "byte_order", "integer field class");
+ ret = -EPERM;
+ goto error;
+ }
+
+ byte_order = get_real_byte_order(ctx, right);
+ if (byte_order == CTF_BYTE_ORDER_UNKNOWN) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right,
+ "Invalid `byte_order` attribute in integer field class: "
+ "ret=%d",
+ ret);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ _SET(&set, _INTEGER_BYTE_ORDER_SET);
+ } else if (strcmp(left->u.unary_expression.u.string, "size") == 0) {
+ if (_IS_SET(&set, _INTEGER_SIZE_SET)) {
+ _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "size", "integer field class");
+ ret = -EPERM;
+ goto error;
+ }
+
+ if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
+ "Invalid `size` attribute in integer field class: "
+ "expecting unsigned constant integer: "
+ "node-type=%d",
+ right->u.unary_expression.type);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ size = right->u.unary_expression.u.unsigned_constant;
+ if (size == 0) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
+ "Invalid `size` attribute in integer field class: "
+ "expecting positive constant integer: "
+ "size=%" PRIu64,
+ size);
+ ret = -EINVAL;
+ goto error;
+ } else if (size > 64) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right,
+ "Invalid `size` attribute in integer field class: "
+ "integer fields over 64 bits are not supported as of this version: "
+ "size=%" PRIu64,
+ size);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ _SET(&set, _INTEGER_SIZE_SET);
+ } else if (strcmp(left->u.unary_expression.u.string, "align") == 0) {
+ if (_IS_SET(&set, _INTEGER_ALIGN_SET)) {
+ _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "align", "integer field class");
+ ret = -EPERM;
+ goto error;
+ }
+
+ if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
+ "Invalid `align` attribute in integer field class: "
+ "expecting unsigned constant integer: "
+ "node-type=%d",
+ right->u.unary_expression.type);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ alignment = right->u.unary_expression.u.unsigned_constant;
+ if (!is_align_valid(alignment)) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
+ "Invalid `align` attribute in integer field class: "
+ "expecting power of two: "
+ "align=%" PRIu64,
+ alignment);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ _SET(&set, _INTEGER_ALIGN_SET);
+ } else if (strcmp(left->u.unary_expression.u.string, "base") == 0) {
+ if (_IS_SET(&set, _INTEGER_BASE_SET)) {
+ _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "base", "integer field class");
+ ret = -EPERM;
+ goto error;
+ }
+
+ switch (right->u.unary_expression.type) {
+ case UNARY_UNSIGNED_CONSTANT:
+ {
+ uint64_t constant = right->u.unary_expression.u.unsigned_constant;
+
+ switch (constant) {
+ case 2:
+ base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY;
+ break;
+ case 8:
+ base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL;
+ break;
+ case 10:
+ base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL;
+ break;
+ case 16:
+ base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL;
+ break;
+ default:
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right,
+ "Invalid `base` attribute in integer field class: "
+ "base=%" PRIu64,
+ right->u.unary_expression.u.unsigned_constant);
+ ret = -EINVAL;
+ goto error;
+ }
+ break;
+ }
+ case UNARY_STRING:
+ {
+ char *s_right =
+ ctf_ast_concatenate_unary_strings(&expression->u.ctf_expression.right);
+ if (!s_right) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right,
+ "Unexpected unary expression for integer field class's `base` attribute.");
+ ret = -EINVAL;
+ goto error;
+ }
+
+ if (strcmp(s_right, "decimal") == 0 || strcmp(s_right, "dec") == 0 ||
+ strcmp(s_right, "d") == 0 || strcmp(s_right, "i") == 0 ||
+ strcmp(s_right, "u") == 0) {
+ base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL;
+ } else if (strcmp(s_right, "hexadecimal") == 0 || strcmp(s_right, "hex") == 0 ||
+ strcmp(s_right, "x") == 0 || strcmp(s_right, "X") == 0 ||
+ strcmp(s_right, "p") == 0) {
+ base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL;
+ } else if (strcmp(s_right, "octal") == 0 || strcmp(s_right, "oct") == 0 ||
+ strcmp(s_right, "o") == 0) {
+ base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL;
+ } else if (strcmp(s_right, "binary") == 0 || strcmp(s_right, "b") == 0) {
+ base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY;
+ } else {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right,
+ "Unexpected unary expression for integer field class's `base` attribute: "
+ "base=\"%s\"",
+ s_right);
+ g_free(s_right);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ g_free(s_right);
+ break;
+ }
+ default:
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right, "Invalid `base` attribute in integer field class: "
+ "expecting unsigned constant integer or unary string.");
+ ret = -EINVAL;
+ goto error;
+ }
+
+ _SET(&set, _INTEGER_BASE_SET);
+ } else if (strcmp(left->u.unary_expression.u.string, "encoding") == 0) {
+ char *s_right;
+
+ if (_IS_SET(&set, _INTEGER_ENCODING_SET)) {
+ _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "encoding", "integer field class");
+ ret = -EPERM;
+ goto error;
+ }
+
+ if (right->u.unary_expression.type != UNARY_STRING) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right, "Invalid `encoding` attribute in integer field class: "
+ "expecting unary string.");
+ ret = -EINVAL;
+ goto error;
+ }
+
+ s_right = ctf_ast_concatenate_unary_strings(&expression->u.ctf_expression.right);
+ if (!s_right) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right,
+ "Unexpected unary expression for integer field class's `encoding` attribute.");
+ ret = -EINVAL;
+ goto error;
+ }
+
+ if (strcmp(s_right, "UTF8") == 0 || strcmp(s_right, "utf8") == 0 ||
+ strcmp(s_right, "utf-8") == 0 || strcmp(s_right, "UTF-8") == 0 ||
+ strcmp(s_right, "ASCII") == 0 || strcmp(s_right, "ascii") == 0) {
+ encoding = CTF_ENCODING_UTF8;
+ } else if (strcmp(s_right, "none") == 0) {
+ encoding = CTF_ENCODING_NONE;
+ } else {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right,
+ "Invalid `encoding` attribute in integer field class: "
+ "unknown encoding: encoding=\"%s\"",
+ s_right);
+ g_free(s_right);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ g_free(s_right);
+ _SET(&set, _INTEGER_ENCODING_SET);
+ } else if (strcmp(left->u.unary_expression.u.string, "map") == 0) {
+ const char *clock_name;
+
+ if (_IS_SET(&set, _INTEGER_MAP_SET)) {
+ _BT_COMP_LOGE_APPEND_CAUSE_DUP_ATTR(left, "map", "integer field class");
+ ret = -EPERM;
+ goto error;
+ }
+
+ if (right->u.unary_expression.type != UNARY_STRING) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(right,
+ "Invalid `map` attribute in integer field class: "
+ "expecting unary string.");
+ ret = -EINVAL;
+ goto error;
+ }
+
+ clock_name = get_map_clock_name_value(&expression->u.ctf_expression.right);
+ if (!clock_name) {
+ char *s_right =
+ ctf_ast_concatenate_unary_strings(&expression->u.ctf_expression.right);
+
+ if (!s_right) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right,
+ "Unexpected unary expression for integer field class's `map` attribute.");
+ ret = -EINVAL;
+ goto error;
+ }
+
+ _BT_COMP_LOGE_NODE(right,
+ "Invalid `map` attribute in integer field class: "
+ "cannot find clock class at this point: name=\"%s\"",
+ s_right);
+ _SET(&set, _INTEGER_MAP_SET);
+ g_free(s_right);
+ continue;
+ }
+
+ mapped_clock_class =
+ ctf_trace_class_borrow_clock_class_by_name(ctx->ctf_tc, clock_name);
+ if (!mapped_clock_class) {
+ _BT_COMP_LOGE_APPEND_CAUSE_NODE(
+ right,
+ "Invalid `map` attribute in integer field class: "
+ "cannot find clock class at this point: name=\"%s\"",
+ clock_name);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ _SET(&set, _INTEGER_MAP_SET);
+ } else {
+ _BT_COMP_LOGW_NODE(left,
+ "Unknown attribute in integer field class: "
+ "attr-name=\"%s\"",
+ left->u.unary_expression.u.string);
+ }
+ }
+
+ if (!_IS_SET(&set, _INTEGER_SIZE_SET)) {
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
+ "Missing `size` attribute in integer field class.");
+ ret = -EPERM;
+ goto error;
+ }
+
+ if (!_IS_SET(&set, _INTEGER_ALIGN_SET)) {
+ if (size % CHAR_BIT) {
+ /* Bit-packed alignment */
+ alignment = 1;
+ } else {
+ /* Byte-packed alignment */
+ alignment = CHAR_BIT;
+ }
+ }
+
+ *integer_decl = ctf_field_class_int_create();
+ BT_ASSERT(*integer_decl);
+ (*integer_decl)->base.base.alignment = alignment;
+ (*integer_decl)->base.byte_order = byte_order;
+ (*integer_decl)->base.size = size;
+ (*integer_decl)->is_signed = (signedness > 0);
+ (*integer_decl)->disp_base = base;
+ (*integer_decl)->encoding = encoding;
+ (*integer_decl)->mapped_clock_class = mapped_clock_class;
+ return 0;