GQuark *field_name,
struct ctf_node *node_type_declarator,
struct declaration_scope *declaration_scope,
- struct declaration *nested_declaration)
+ struct declaration *nested_declaration,
+ struct ctf_trace *trace)
{
/*
* Visit type declarator by first taking care of sequence/array
* of pointers.
*/
- assert(node_type_declarator->u.type_declarator.type != TYPEDEC_UNKNOWN);
+ if (node_type_declarator) {
+ assert(node_type_declarator->u.type_declarator.type != TYPEDEC_UNKNOWN);
- /* TODO: gcc bitfields not supported yet. */
- if (node_type_declarator->u.type_declarator.bitfield_len != NULL) {
- fprintf(stderr, "[error] %s: gcc bitfields are not supported yet.\n", __func__);
- return NULL;
+ /* TODO: gcc bitfields not supported yet. */
+ if (node_type_declarator->u.type_declarator.bitfield_len != NULL) {
+ fprintf(stderr, "[error] %s: gcc bitfields are not supported yet.\n", __func__);
+ return NULL;
+ }
}
if (!nested_declaration) {
- if (!cds_list_empty(&node_type_declarator->u.type_declarator.pointers)) {
+ if (node_type_declarator && !cds_list_empty(&node_type_declarator->u.type_declarator.pointers)) {
GQuark alias_q;
/*
return NULL;
}
} else {
- nested_declaration = /* parse declaration_specifier */;
+ nested_declaration = ctf_declaration_specifier_visit(fd, depth,
+ declaration_specifier, declaration_scope, trace);
}
}
+ if (!node_type_declarator)
+ return nested_declaration;
+
if (node_type_declarator->u.type_declarator.type == TYPEDEC_ID) {
if (node_type_declarator->u.type_declarator.u.id)
*field_name = g_quark_from_string(node_type_declarator->u.type_declarator.u.id);
if (length) {
switch (length->type) {
case NODE_UNARY_EXPRESSION:
- /* Array */
- /* TODO */
- .............
- declaration = /* create array */;
+ {
+ struct declaration_array *array_declaration;
+ size_t len;
+
+ if (length->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT) {
+ fprintf(stderr, "[error] %s: array: unexpected unary expression.\n", __func__);
+ return NULL;
+ }
+ len = length->u.unary_expression.u.unsigned_constant;
+ array_declaration = array_declaration_new(len, nested_declaration,
+ declaration_scope);
+ declaration = &array_declaration->p;
break;
+ }
+ case NODE_INTEGER:
case NODE_TYPE_SPECIFIER:
- /* Sequence */
- declaration = /* create sequence */;
+ {
+ struct declaration_sequence *sequence_declaration;
+ struct declaration_integer *integer_declaration;
+ GQuark dummy_id;
+
+ declaration = ctf_type_declarator_visit(fd, depth,
+ length,
+ &dummy_id, NULL,
+ declaration_scope,
+ NULL, trace);
+ assert(declaration->id == CTF_TYPE_INTEGER);
+ integer_declaration = container_of(declaration, struct declaration_integer, p);
+ declaration_sequence = sequence_declaration_new(integer_declaration,
+ nested_declaration, declaration_scope);
+ declaration = &declaration_sequence->p;
break;
+ }
default:
assert(0);
}
declaration = ctf_type_declarator_visit(fd, depth,
declaration_specifier, field_name,
node_type_declarator->u.type_declarator.u.nested.type_declarator,
- declaration_scope, declaration);
+ declaration_scope, declaration, trace);
return declaration;
}
}
struct declaration_struct *struct_declaration,
struct cds_list_head *declaration_specifier,
struct cds_list_head *type_declarators,
- struct declaration_scope *declaration_scope)
+ struct declaration_scope *declaration_scope,
+ struct ctf_trace *trace)
{
struct ctf_node *iter;
GQuark field_name;
declaration_specifier,
&field_name, iter,
struct_declaration->scope,
- NULL);
+ NULL, trace);
struct_declaration_add_field(struct_declaration,
g_quark_to_string(field_name),
field_declaration);
struct declaration_variant *variant_declaration,
struct cds_list_head *declaration_specifier,
struct cds_list_head *type_declarators,
- struct declaration_scope *declaration_scope)
+ struct declaration_scope *declaration_scope,
+ struct ctf_trace *trace)
{
struct ctf_node *iter;
GQuark field_name;
declaration_specifier,
&field_name, iter,
variant_declaration->scope,
- NULL);
+ NULL, trace);
variant_declaration_add_field(variant_declaration,
g_quark_to_string(field_name),
field_declaration);
static
int ctf_typedef_visit(int fd, int depth, struct declaration_scope *scope,
struct cds_list_head *declaration_specifier,
- struct cds_list_head *type_declarators)
+ struct cds_list_head *type_declarators,
+ struct ctf_trace *trace)
{
struct ctf_node *iter;
GQuark identifier;
type_declaration = ctf_type_declarator_visit(fd, depth,
declaration_specifier,
&identifier, iter,
- scope, NULL);
+ scope, NULL, trace);
ret = register_declaration(identifier, type_declaration, scope);
if (ret) {
type_declaration->declaration_free(type_declaration);
static
int ctf_typealias_visit(int fd, int depth, struct declaration_scope *scope,
- struct ctf_node *target, struct ctf_node *alias)
+ struct ctf_node *target, struct ctf_node *alias,
+ struct ctf_trace *trace)
{
struct declaration *type_declaration;
struct ctf_node *iter, *node;
type_declaration = ctf_type_declarator_visit(fd, depth,
&target->u.typealias_target.declaration_specifier,
&dummy_id, &target->u.typealias_target.type_declarators,
- scope, NULL);
+ scope, NULL, trace);
if (!type_declaration) {
fprintf(stderr, "[error] %s: problem creating type declaration\n", __func__);
err = -EINVAL;
static
int ctf_struct_declaration_list_visit(int fd, int depth,
- struct ctf_node *iter, struct declaration_struct *struct_declaration)
+ struct ctf_node *iter, struct declaration_struct *struct_declaration,
+ struct ctf_trace *trace)
{
struct declaration *declaration;
int ret;
ret = ctf_typedef_visit(fd, depth,
struct_declaration->scope,
&iter->u._typedef.declaration_specifier,
- &iter->u._typedef.type_declarators);
+ &iter->u._typedef.type_declarators, trace);
if (ret)
return ret;
break;
ret = ctf_typealias_visit(fd, depth,
struct_declaration->scope,
iter->u.typealias.target,
- iter->u.typealias.alias);
+ iter->u.typealias.alias, trace);
if (ret)
return ret;
break;
ret = ctf_struct_type_declarators_visit(fd, depth,
struct_declaration,
&iter->u.struct_or_variant_declaration.declaration_specifier,
- &iter->u.struct_or_variant_declaration.type_declarators);
+ &iter->u.struct_or_variant_declaration.type_declarators, trace);
if (ret)
return ret;
break;
static
int ctf_variant_declaration_list_visit(int fd, int depth,
- struct ctf_node *iter, struct declaration_variant *variant_declaration)
+ struct ctf_node *iter, struct declaration_variant *variant_declaration,
+ struct ctf_trace *trace)
{
struct declaration *declaration;
int ret;
ret = ctf_typedef_visit(fd, depth,
variant_declaration->scope,
&iter->u._typedef.declaration_specifier,
- &iter->u._typedef.type_declarators);
+ &iter->u._typedef.type_declarators, trace);
if (ret)
return ret;
break;
ret = ctf_typealias_visit(fd, depth,
variant_declaration->scope,
iter->u.typealias.target,
- iter->u.typealias.alias);
+ iter->u.typealias.alias, trace);
if (ret)
return ret;
break;
ret = ctf_variant_type_declarators_visit(fd, depth,
variant_declaration,
&iter->u.struct_or_variant_declaration.declaration_specifier,
- &iter->u.struct_or_variant_declaration.type_declarators);
+ &iter->u.struct_or_variant_declaration.type_declarators, trace);
if (ret)
return ret;
break;
static
struct declaration_struct *ctf_declaration_struct_visit(FILE *fd,
int depth, const char *name, struct cds_list_head *declaration_list,
- int has_body, struct declaration_scope *declaration_scope)
+ int has_body, struct declaration_scope *declaration_scope,
+ struct ctf_trace *trace)
{
struct declaration *declaration;
struct declaration_struct *struct_declaration;
}
struct_declaration = struct_declaration_new(name, declaration_scope);
cds_list_for_each_entry(iter, declaration_list, siblings) {
- ret = ctf_struct_declaration_list_visit(fd, depth + 1, iter, struct_declaration);
+ ret = ctf_struct_declaration_list_visit(fd, depth + 1, iter,
+ struct_declaration, trace);
if (ret)
goto error;
}
static
struct declaration_variant *ctf_declaration_variant_visit(FILE *fd,
int depth, const char *name, struct cds_list_head *declaration_list,
- int has_body, struct declaration_scope *declaration_scope)
+ int has_body, struct declaration_scope *declaration_scope,
+ struct ctf_trace *trace)
{
struct declaration *declaration;
struct declaration_variant *variant_declaration;
}
variant_declaration = variant_declaration_new(name, declaration_scope);
cds_list_for_each_entry(iter, declaration_list, siblings) {
- ret = ctf_variant_declaration_list_visit(fd, depth + 1, iter, variant_declaration);
+ ret = ctf_variant_declaration_list_visit(fd, depth + 1, iter,
+ variant_declaration, trace);
if (ret)
goto error;
}
struct ctf_node *enumerator,
struct declaration_enum *enum_declaration)
{
- /* TODO */
-........
+ GQuark q;
+ struct ctf_node *iter;
+
+ q = g_quark_from_string(enumerator->u.enumerator.id);
+ if (enum_declaration->integer->signedness) {
+ int64_t start, end;
+ int nr_vals = 0;
+
+ cds_list_for_each_entry(iter, enumerator->u.enumerator.values, siblings) {
+ int64_t *target;
+
+ assert(iter->type == NODE_UNARY_EXPRESSION);
+ if (nr_vals == 0)
+ target = &start;
+ else
+ target = &end;
+
+ switch (iter->u.unary_expression.type) {
+ case UNARY_SIGNED_CONSTANT:
+ *target = iter->u.unary_expression.u.signed_constant;
+ break;
+ case UNARY_UNSIGNED_CONSTANT:
+ *target = iter->u.unary_expression.u.unsigned_constant;
+ break;
+ default:
+ fprintf(stderr, "[error] %s: invalid enumerator\n", __func__);
+ return -EINVAL;
+ }
+ if (nr_vals > 1) {
+ fprintf(stderr, "[error] %s: invalid enumerator\n", __func__);
+ return -EINVAL;
+ }
+ nr_vals++;
+ }
+ if (nr_vals == 1)
+ end = start;
+ enum_signed_insert(enum_declaration, start, end, q);
+ } else
+ uint64_t start, end;
+ int nr_vals = 0;
+
+ cds_list_for_each_entry(iter, enumerator->u.enumerator.values, siblings) {
+ int64_t *target;
+
+ assert(iter->type == NODE_UNARY_EXPRESSION);
+ if (nr_vals == 0)
+ target = &start;
+ else
+ target = &end;
+
+ switch (iter->u.unary_expression.type) {
+ case UNARY_UNSIGNED_CONSTANT:
+ *target = iter->u.unary_expression.u.unsigned_constant;
+ break;
+ case UNARY_SIGNED_CONSTANT:
+ /*
+ * We don't accept signed constants for enums with unsigned
+ * container type.
+ */
+ fprintf(stderr, "[error] %s: invalid enumerator (signed constant encountered, but enum container type is unsigned)\n", __func__);
+ return -EINVAL;
+ default:
+ fprintf(stderr, "[error] %s: invalid enumerator\n", __func__);
+ return -EINVAL;
+ }
+ if (nr_vals > 1) {
+ fprintf(stderr, "[error] %s: invalid enumerator\n", __func__);
+ return -EINVAL;
+ }
+ nr_vals++;
+ }
+ if (nr_vals == 1)
+ end = start;
+ enum_unsigned_insert(enum_declaration, start, end, q);
+ }
return 0;
}
static
struct declaration *ctf_declaration_enum_visit(int fd, int depth,
const char *name,
- struct ctf_node *container_type,
+ struct cds_list_head *container_type,
struct cds_list_head *enumerator_list,
- int has_body)
+ int has_body,
+ struct declaration_scope *declaration_scope,
+ struct ctf_trace *trace)
{
struct declaration *declaration;
struct declaration_enum *enum_declaration;
struct declaration_integer *integer_declaration;
- struct ctf_node *iter;
+ struct ctf_node *iter, *first;
+ GQuark dummy_id;
/*
* For named enum (without body), lookup in
return NULL;
}
}
-
- /* TODO CHECK Enumerations need to have their size/type specifier (< >). */
- integer_declaration = integer_declaration_new(); /* TODO ... */
- .....
+ if (cds_list_empty(container_type)) {
+ fprintf(stderr, "[error] %s: missing container type for enumeration\n", __func__, name);
+ return NULL;
+
+ }
+ first = _cds_list_first_entry(container_type, struct node, siblings);
+ switch (first->type) {
+ case NODE_INTEGER:
+ case NODE_TYPE_SPECIFIER:
+ declaration = ctf_type_declarator_visit(fd, depth,
+ container_type,
+ &dummy_id, NULL,
+ declaration_scope,
+ NULL, trace);
+ assert(declaration->id == CTF_TYPE_INTEGER);
+ integer_declaration = container_of(declaration, struct declaration_integer, p);
+ break;
+ }
+ default:
+ assert(0);
+ }
enum_declaration = enum_declaration_new(name, integer_declaration);
declaration_unref(&integer_declaration->p); /* leave ref to enum */
cds_list_for_each_entry(iter, enumerator_list, siblings) {
case NODE_ENUM:
return ctf_declaration_enum_visit(fd, depth,
first->u._enum.enum_id,
- first->u._enum.container_type,
+ &first->u._enum.container_type,
&first->u._enum.enumerator_list,
first->u._enum.has_body,
+ declaration_scope,
trace);
case NODE_INTEGER:
return ctf_declaration_integer_visit(fd, depth,