+ left = _cds_list_first_entry(&expression->u.ctf_expression.left, struct ctf_node, siblings);
+ right = _cds_list_first_entry(&expression->u.ctf_expression.right, struct ctf_node, siblings);
+ assert(left->u.unary_expression.type == UNARY_STRING);
+ if (!strcmp(left->u.unary_expression.u.string, "byte_order")) {
+ byte_order = get_byte_order(fd, depth, right, trace);
+ if (byte_order < 0)
+ return NULL;
+ } else if (!strcmp(left->u.unary_expression.u.string, "exp_dig")) {
+ if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) {
+ fprintf(fd, "[error] %s: exp_dig: expecting unsigned constant\n",
+ __func__);
+ return NULL;
+ }
+ exp_dig = right->u.unary_expression.u.unsigned_constant;
+ has_exp_dig = 1;
+ } else if (!strcmp(left->u.unary_expression.u.string, "mant_dig")) {
+ if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) {
+ fprintf(fd, "[error] %s: mant_dig: expecting unsigned constant\n",
+ __func__);
+ return NULL;
+ }
+ mant_dig = right->u.unary_expression.u.unsigned_constant;
+ has_mant_dig = 1;
+ } else if (!strcmp(left->u.unary_expression.u.string, "align")) {
+ if (right->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) {
+ fprintf(fd, "[error] %s: align: expecting unsigned constant\n",
+ __func__);
+ return NULL;
+ }
+ alignment = right->u.unary_expression.u.unsigned_constant;
+ /* Make sure alignment is a power of two */
+ if (alignment == 0 || (alignment & (alignment - 1)) != 0) {
+ fprintf(fd, "[error] %s: align: expecting power of two\n",
+ __func__);
+ return NULL;
+ }
+ has_alignment = 1;
+ } else {
+ fprintf(fd, "[error] %s: unknown attribute name %s\n",
+ __func__, left->u.unary_expression.u.string);
+ return NULL;
+ }
+ }
+ if (!has_mant_dig) {
+ fprintf(fd, "[error] %s: missing mant_dig attribute\n", __func__);
+ return NULL;
+ }
+ if (!has_exp_dig) {
+ fprintf(fd, "[error] %s: missing exp_dig attribute\n", __func__);
+ return NULL;
+ }
+ if (!has_alignment) {
+ if ((mant_dig + exp_dig) % CHAR_BIT) {
+ /* bit-packed alignment */
+ alignment = 1;
+ } else {
+ /* byte-packed alignment */
+ alignment = CHAR_BIT;
+ }
+ }
+ float_declaration = float_declaration_new(mant_dig, exp_dig,
+ byte_order, alignment);
+ return &float_declaration->p;
+}
+
+static
+struct declaration *ctf_declaration_string_visit(FILE *fd, int depth,
+ struct cds_list_head *expressions,
+ struct ctf_trace *trace)
+{
+ struct ctf_node *expression;
+ const char *encoding_c = NULL;
+ enum ctf_string_encoding encoding = CTF_STRING_UTF8;
+ struct declaration_string *string_declaration;
+
+ cds_list_for_each_entry(expression, expressions, siblings) {
+ struct ctf_node *left, *right;
+
+ left = _cds_list_first_entry(&expression->u.ctf_expression.left, struct ctf_node, siblings);
+ right = _cds_list_first_entry(&expression->u.ctf_expression.right, struct ctf_node, siblings);
+ assert(left->u.unary_expression.type == UNARY_STRING);
+ if (!strcmp(left->u.unary_expression.u.string, "encoding")) {
+ if (right->u.unary_expression.type != UNARY_STRING) {
+ fprintf(fd, "[error] %s: encoding: expecting string\n",
+ __func__);
+ return NULL;
+ }
+ encoding_c = right->u.unary_expression.u.string;
+ } else {
+ fprintf(fd, "[error] %s: unknown attribute name %s\n",
+ __func__, left->u.unary_expression.u.string);
+ return NULL;
+ }
+ }
+ if (encoding_c && !strcmp(encoding_c, "ASCII"))
+ encoding = CTF_STRING_ASCII;
+ string_declaration = string_declaration_new(encoding);
+ return &string_declaration->p;
+}
+
+
+static
+struct declaration *ctf_type_specifier_list_visit(FILE *fd,
+ int depth, struct ctf_node *type_specifier_list,
+ struct declaration_scope *declaration_scope,
+ struct ctf_trace *trace)
+{
+ struct ctf_node *first;
+ struct ctf_node *node;
+
+ assert(type_specifier_list->type == NODE_TYPE_SPECIFIER_LIST);
+
+ first = _cds_list_first_entry(&type_specifier_list->u.type_specifier_list.head, struct ctf_node, siblings);
+
+ assert(first->type == NODE_TYPE_SPECIFIER);
+
+ node = first->u.type_specifier.node;
+
+ switch (first->u.type_specifier.type) {
+ case TYPESPEC_FLOATING_POINT:
+ return ctf_declaration_floating_point_visit(fd, depth,
+ &node->u.floating_point.expressions, trace);
+ case TYPESPEC_INTEGER:
+ return ctf_declaration_integer_visit(fd, depth,
+ &node->u.integer.expressions, trace);
+ case TYPESPEC_STRING:
+ return ctf_declaration_string_visit(fd, depth,
+ &node->u.string.expressions, trace);
+ case TYPESPEC_STRUCT: