From 312623540c466defab45503fbe0ce7ec79dcce85 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 9 May 2011 09:47:54 -0400 Subject: [PATCH] Update pretty-print Signed-off-by: Mathieu Desnoyers --- converter/babeltrace-lib.c | 96 ++----------------- formats/ctf-text/ctf-text.c | 93 ++++++++++++++++++ formats/ctf-text/types/array.c | 15 ++- formats/ctf-text/types/enum.c | 22 ++++- formats/ctf-text/types/float.c | 11 ++- formats/ctf-text/types/integer.c | 26 +++++- formats/ctf-text/types/sequence.c | 15 ++- formats/ctf-text/types/string.c | 13 ++- formats/ctf-text/types/struct.c | 15 ++- formats/ctf-text/types/variant.c | 29 +++++- formats/ctf/ctf.c | 140 ++++++++++++++++++++++++++++ include/babeltrace/ctf-text/types.h | 1 + include/babeltrace/types.h | 14 ++- types/array.c | 1 + types/enum.c | 1 + types/float.c | 1 + types/integer.c | 1 + types/sequence.c | 1 + types/string.c | 1 + types/struct.c | 1 + types/types.c | 24 +++++ types/variant.c | 1 + 22 files changed, 408 insertions(+), 114 deletions(-) diff --git a/converter/babeltrace-lib.c b/converter/babeltrace-lib.c index c96f3890..8f29c5a8 100644 --- a/converter/babeltrace-lib.c +++ b/converter/babeltrace-lib.c @@ -26,93 +26,6 @@ #include #include -static -int convert_event(struct ctf_text_stream_pos *sout, - struct ctf_file_stream *sin) -{ - struct ctf_stream *stream_class = sin->stream; - struct ctf_event *event_class; - uint64_t id = 0; - int len_index; - int ret; - - if (sin->pos.offset == EOF) - return EOF; - - /* Hide event payload struct brackets */ - sout->depth = -1; - - /* Read and print event header */ - if (stream_class->event_header) { - ret = generic_rw(&sin->pos.parent, &stream_class->event_header->p); - if (ret) - goto error; - /* lookup event id */ - len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl, - g_quark_from_static_string("id")); - if (len_index >= 0) { - struct definition_integer *defint; - struct definition *field; - - field = struct_definition_get_field_from_index(stream_class->event_header, len_index); - assert(field->declaration->id == CTF_TYPE_INTEGER); - defint = container_of(field, struct definition_integer, p); - assert(defint->declaration->signedness == FALSE); - id = defint->value._unsigned; /* set id */ - } - - ret = generic_rw(&sout->parent, &stream_class->event_header->p); - if (ret) - goto error; - } - - /* Read and print stream-declared event context */ - if (stream_class->event_context) { - ret = generic_rw(&sin->pos.parent, &stream_class->event_context->p); - if (ret) - goto error; - ret = generic_rw(&sout->parent, &stream_class->event_context->p); - if (ret) - goto error; - } - - if (id >= stream_class->events_by_id->len) { - fprintf(stdout, "[error] Event id %" PRIu64 " is outside range.\n", id); - return -EINVAL; - } - event_class = g_ptr_array_index(stream_class->events_by_id, id); - if (!event_class) { - fprintf(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id); - return -EINVAL; - } - - /* Read and print event-declared event context */ - if (event_class->context) { - ret = generic_rw(&sin->pos.parent, &event_class->context->p); - if (ret) - goto error; - ret = generic_rw(&sout->parent, &event_class->context->p); - if (ret) - goto error; - } - - /* Read and print event payload */ - if (event_class->fields) { - ret = generic_rw(&sin->pos.parent, &event_class->fields->p); - if (ret) - goto error; - ret = generic_rw(&sout->parent, &event_class->fields->p); - if (ret) - goto error; - } - - return 0; - -error: - fprintf(stdout, "[error] Unexpected end of stream. Either the trace data stream is corrupted or metadata description does not match data layout.\n"); - return ret; -} - static int convert_stream(struct ctf_text_stream_pos *sout, struct ctf_file_stream *sin) @@ -122,11 +35,16 @@ int convert_stream(struct ctf_text_stream_pos *sout, /* For each event, print header, context, payload */ /* TODO: order events by timestamps across streams */ for (;;) { - ret = convert_event(sout, sin); + ret = sin->pos.parent.event_cb(&sin->pos.parent, sin->stream); if (ret == EOF) break; else if (ret) { - fprintf(stdout, "[error] Printing event failed.\n"); + fprintf(stdout, "[error] Reading event failed.\n"); + goto error; + } + ret = sout->parent.event_cb(&sout->parent, sin->stream); + if (ret) { + fprintf(stdout, "[error] Writing event failed.\n"); goto error; } } diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c index cc882f60..ceca3e4e 100644 --- a/formats/ctf-text/ctf-text.c +++ b/formats/ctf-text/ctf-text.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -52,6 +53,96 @@ struct format ctf_text_format = { .close_trace = ctf_text_close_trace, }; +static +int ctf_text_write_event(struct stream_pos *ppos, + struct ctf_stream *stream_class) +{ + struct ctf_text_stream_pos *pos = + container_of(ppos, struct ctf_text_stream_pos, parent); + struct ctf_event *event_class; + uint64_t id = 0; + int len_index; + int ret; + + /* print event header */ + if (stream_class->event_header) { + /* lookup event id */ + len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl, + g_quark_from_static_string("id")); + if (len_index >= 0) { + struct definition_integer *defint; + struct definition *field; + + field = struct_definition_get_field_from_index(stream_class->event_header, len_index); + assert(field->declaration->id == CTF_TYPE_INTEGER); + defint = container_of(field, struct definition_integer, p); + assert(defint->declaration->signedness == FALSE); + id = defint->value._unsigned; /* set id */ + } + } + + if (id >= stream_class->events_by_id->len) { + fprintf(stdout, "[error] Event id %" PRIu64 " is outside range.\n", id); + return -EINVAL; + } + event_class = g_ptr_array_index(stream_class->events_by_id, id); + if (!event_class) { + fprintf(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id); + return -EINVAL; + } + + if (pos->print_names) + fprintf(pos->fp, "name = "); + fprintf(pos->fp, "%s", g_quark_to_string(event_class->name)); + + if (stream_class->event_header) { + if (pos->print_names) + fprintf(pos->fp, ", stream.event.header ="); + fprintf(pos->fp, " "); + ret = generic_rw(ppos, &stream_class->event_header->p); + if (ret) + goto error; + } + + /* print stream-declared event context */ + if (stream_class->event_context) { + if (pos->print_names) + fprintf(pos->fp, ", stream.event.context ="); + fprintf(pos->fp, " "); + ret = generic_rw(ppos, &stream_class->event_context->p); + if (ret) + goto error; + } + + /* print event-declared event context */ + if (event_class->context) { + if (pos->print_names) + fprintf(pos->fp, ", event.context ="); + fprintf(pos->fp, " "); + ret = generic_rw(ppos, &event_class->context->p); + if (ret) + goto error; + } + + /* Read and print event payload */ + if (event_class->fields) { + if (pos->print_names) + fprintf(pos->fp, ", event.fields ="); + fprintf(pos->fp, " "); + ret = generic_rw(ppos, &event_class->fields->p); + if (ret) + goto error; + } + fprintf(pos->fp, "\n"); + + return 0; + +error: + fprintf(stdout, "[error] Unexpected end of stream. Either the trace data stream is corrupted or metadata description does not match data layout.\n"); + return ret; +} + + struct trace_descriptor *ctf_text_open_trace(const char *path, int flags) { struct ctf_text_stream_pos *pos; @@ -69,6 +160,8 @@ struct trace_descriptor *ctf_text_open_trace(const char *path, int flags) goto error; pos->fp = fp; pos->parent.rw_table = write_dispatch_table; + pos->parent.event_cb = ctf_text_write_event; + pos->print_names = 1; break; case O_RDONLY: default: diff --git a/formats/ctf-text/types/array.c b/formats/ctf-text/types/array.c index b7770174..f61693ab 100644 --- a/formats/ctf-text/types/array.c +++ b/formats/ctf-text/types/array.c @@ -25,15 +25,22 @@ int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition) int ret; if (!pos->dummy) { - print_pos_tabs(pos); - fprintf(pos->fp, "[\n"); + //print_pos_tabs(pos); + if (definition->index != 0 && definition->index != INT_MAX) + fprintf(pos->fp, ","); + if (definition->index != INT_MAX) + fprintf(pos->fp, " "); + if (pos->print_names) + fprintf(pos->fp, "%s = ", + g_quark_to_string(definition->name)); + fprintf(pos->fp, "["); pos->depth++; } ret = array_rw(ppos, definition); if (!pos->dummy) { pos->depth--; - print_pos_tabs(pos); - fprintf(pos->fp, "]\n"); + //print_pos_tabs(pos); + fprintf(pos->fp, " ]"); } return ret; } diff --git a/formats/ctf-text/types/enum.c b/formats/ctf-text/types/enum.c index 33009da7..cf8cc4fa 100644 --- a/formats/ctf-text/types/enum.c +++ b/formats/ctf-text/types/enum.c @@ -32,11 +32,21 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition) if (pos->dummy) return 0; - print_pos_tabs(pos); + + if (definition->index != 0 && definition->index != INT_MAX) + fprintf(pos->fp, ","); + if (definition->index != INT_MAX) + fprintf(pos->fp, " "); + if (pos->print_names) + fprintf(pos->fp, "%s = ", + g_quark_to_string(definition->name)); + + //print_pos_tabs(pos); fprintf(pos->fp, "("); pos->depth++; ret = generic_rw(ppos, &integer_definition->p); - print_pos_tabs(pos); + //print_pos_tabs(pos); + fprintf(pos->fp, " :"); qs = enum_definition->value; assert(qs); @@ -44,10 +54,14 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition) for (i = 0; i < qs->len; i++) { GQuark q = g_array_index(qs, GQuark, i); const char *str = g_quark_to_string(q); + + if (i != 0) + fprintf(pos->fp, ","); + fprintf(pos->fp, " "); fprintf(pos->fp, "%s\n", str); } pos->depth--; - print_pos_tabs(pos); - fprintf(pos->fp, ")"); + //print_pos_tabs(pos); + fprintf(pos->fp, " )"); return ret; } diff --git a/formats/ctf-text/types/float.c b/formats/ctf-text/types/float.c index 1f52cb07..d2a66d4b 100644 --- a/formats/ctf-text/types/float.c +++ b/formats/ctf-text/types/float.c @@ -29,7 +29,16 @@ int ctf_text_float_write(struct stream_pos *ppos, struct definition *definition) if (pos->dummy) return 0; - print_pos_tabs(pos); + //print_pos_tabs(pos); + + if (definition->index != 0 && definition->index != INT_MAX) + fprintf(pos->fp, ","); + if (definition->index != INT_MAX) + fprintf(pos->fp, " "); + if (pos->print_names) + fprintf(pos->fp, "%s = ", + g_quark_to_string(definition->name)); + fprintf(pos->fp, "%Lg\n", float_definition->value); return 0; } diff --git a/formats/ctf-text/types/integer.c b/formats/ctf-text/types/integer.c index 1b565a29..f25f4540 100644 --- a/formats/ctf-text/types/integer.c +++ b/formats/ctf-text/types/integer.c @@ -31,13 +31,33 @@ int ctf_text_integer_write(struct stream_pos *ppos, struct definition *definitio if (pos->dummy) return 0; - print_pos_tabs(pos); + + if (definition->index != 0 && definition->index != INT_MAX) + fprintf(pos->fp, ","); + if (definition->index != INT_MAX) + fprintf(pos->fp, " "); + if (pos->print_names) + fprintf(pos->fp, "%s = ", + g_quark_to_string(definition->name)); + + //print_pos_tabs(pos); + + if (!compare_definition_path(definition, g_quark_from_static_string("stream.event.header.timestamp"))) { + if (!pos->print_names) + fprintf(pos->fp, "[%" PRIu64 "]", + integer_definition->value._unsigned); + else + fprintf(pos->fp, "%" PRIu64, + integer_definition->value._unsigned); + return 0; + } + if (!integer_declaration->signedness) { - fprintf(pos->fp, "%" PRIu64" (0x%" PRIX64 ")\n", + fprintf(pos->fp, "%" PRIu64" (0x%" PRIX64 ")", integer_definition->value._unsigned, integer_definition->value._unsigned); } else { - fprintf(pos->fp, "%" PRId64" (0x%" PRIX64 ")\n", + fprintf(pos->fp, "%" PRId64" (0x%" PRIX64 ")", integer_definition->value._signed, integer_definition->value._signed); } diff --git a/formats/ctf-text/types/sequence.c b/formats/ctf-text/types/sequence.c index 1e19885c..70a41dc3 100644 --- a/formats/ctf-text/types/sequence.c +++ b/formats/ctf-text/types/sequence.c @@ -25,15 +25,22 @@ int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definiti int ret; if (!pos->dummy) { - print_pos_tabs(pos); - fprintf(pos->fp, "[\n"); + //print_pos_tabs(pos); + if (definition->index != 0 && definition->index != INT_MAX) + fprintf(pos->fp, ","); + if (definition->index != INT_MAX) + fprintf(pos->fp, " "); + if (pos->print_names) + fprintf(pos->fp, "%s = ", + g_quark_to_string(definition->name)); + fprintf(pos->fp, "["); pos->depth++; } ret = sequence_rw(ppos, definition); if (!pos->dummy) { pos->depth--; - print_pos_tabs(pos); - fprintf(pos->fp, "]\n"); + //print_pos_tabs(pos); + fprintf(pos->fp, " ]"); } return ret; } diff --git a/formats/ctf-text/types/string.c b/formats/ctf-text/types/string.c index d07501e5..59924daf 100644 --- a/formats/ctf-text/types/string.c +++ b/formats/ctf-text/types/string.c @@ -31,7 +31,16 @@ int ctf_text_string_write(struct stream_pos *ppos, assert(string_definition->value != NULL); if (pos->dummy) return 0; - print_pos_tabs(pos); - fprintf(pos->fp, "%s\n", string_definition->value); + //print_pos_tabs(pos); + + if (definition->index != 0 && definition->index != INT_MAX) + fprintf(pos->fp, ","); + if (definition->index != INT_MAX) + fprintf(pos->fp, " "); + if (pos->print_names) + fprintf(pos->fp, "%s = ", + g_quark_to_string(definition->name)); + + fprintf(pos->fp, "\"%s\"", string_definition->value); return 0; } diff --git a/formats/ctf-text/types/struct.c b/formats/ctf-text/types/struct.c index 760f1727..e8ffddc2 100644 --- a/formats/ctf-text/types/struct.c +++ b/formats/ctf-text/types/struct.c @@ -26,8 +26,15 @@ int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition if (!pos->dummy) { if (pos->depth >= 0) { - print_pos_tabs(pos); - fprintf(pos->fp, "{\n"); + //print_pos_tabs(pos); + if (definition->index != 0 && definition->index != INT_MAX) + fprintf(pos->fp, ","); + if (definition->index != INT_MAX) + fprintf(pos->fp, " "); + if (pos->print_names && definition->name != 0) + fprintf(pos->fp, "%s = ", + g_quark_to_string(definition->name)); + fprintf(pos->fp, "{"); } pos->depth++; } @@ -35,8 +42,8 @@ int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition if (!pos->dummy) { pos->depth--; if (pos->depth >= 0) { - print_pos_tabs(pos); - fprintf(pos->fp, "}\n"); + //print_pos_tabs(pos); + fprintf(pos->fp, " }"); } } return ret; diff --git a/formats/ctf-text/types/variant.c b/formats/ctf-text/types/variant.c index b4b72e16..e6abd499 100644 --- a/formats/ctf-text/types/variant.c +++ b/formats/ctf-text/types/variant.c @@ -19,7 +19,32 @@ #include #include -int ctf_text_variant_write(struct stream_pos *pos, struct definition *definition) +int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definition) { - return variant_rw(pos, definition); + struct ctf_text_stream_pos *pos = ctf_text_pos(ppos); + int ret; + + if (!pos->dummy) { + if (pos->depth >= 0) { + //print_pos_tabs(pos); + if (definition->index != 0 && definition->index != INT_MAX) + fprintf(pos->fp, ","); + if (definition->index != INT_MAX) + fprintf(pos->fp, " "); + if (pos->print_names) + fprintf(pos->fp, "%s = ", + g_quark_to_string(definition->name)); + fprintf(pos->fp, "{"); + } + pos->depth++; + } + ret = variant_rw(ppos, definition); + if (!pos->dummy) { + pos->depth--; + if (pos->depth >= 0) { + //print_pos_tabs(pos); + fprintf(pos->fp, " }"); + } + } + return ret; } diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 1e7fedd8..50cc93de 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -79,6 +79,144 @@ struct format ctf_format = { .close_trace = ctf_close_trace, }; +static +int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream_class) +{ + struct ctf_stream_pos *pos = + container_of(ppos, struct ctf_stream_pos, parent); + struct ctf_event *event_class; + uint64_t id = 0; + int len_index; + int ret; + + if (pos->offset == EOF) + return EOF; + + /* Read event header */ + if (stream_class->event_header) { + ret = generic_rw(ppos, &stream_class->event_header->p); + if (ret) + goto error; + /* lookup event id */ + len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl, + g_quark_from_static_string("id")); + if (len_index >= 0) { + struct definition_integer *defint; + struct definition *field; + + field = struct_definition_get_field_from_index(stream_class->event_header, len_index); + assert(field->declaration->id == CTF_TYPE_INTEGER); + defint = container_of(field, struct definition_integer, p); + assert(defint->declaration->signedness == FALSE); + id = defint->value._unsigned; /* set id */ + } + } + + /* Read stream-declared event context */ + if (stream_class->event_context) { + ret = generic_rw(ppos, &stream_class->event_context->p); + if (ret) + goto error; + } + + if (id >= stream_class->events_by_id->len) { + fprintf(stdout, "[error] Event id %" PRIu64 " is outside range.\n", id); + return -EINVAL; + } + event_class = g_ptr_array_index(stream_class->events_by_id, id); + if (!event_class) { + fprintf(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id); + return -EINVAL; + } + + /* Read event-declared event context */ + if (event_class->context) { + ret = generic_rw(ppos, &event_class->context->p); + if (ret) + goto error; + } + + /* Read event payload */ + if (event_class->fields) { + ret = generic_rw(ppos, &event_class->fields->p); + if (ret) + goto error; + } + + return 0; + +error: + fprintf(stdout, "[error] Unexpected end of stream. Either the trace data stream is corrupted or metadata description does not match data layout.\n"); + return ret; +} + +static +int ctf_write_event(struct stream_pos *pos, struct ctf_stream *stream_class) +{ + struct ctf_event *event_class; + uint64_t id = 0; + int len_index; + int ret; + + /* print event header */ + if (stream_class->event_header) { + /* lookup event id */ + len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl, + g_quark_from_static_string("id")); + if (len_index >= 0) { + struct definition_integer *defint; + struct definition *field; + + field = struct_definition_get_field_from_index(stream_class->event_header, len_index); + assert(field->declaration->id == CTF_TYPE_INTEGER); + defint = container_of(field, struct definition_integer, p); + assert(defint->declaration->signedness == FALSE); + id = defint->value._unsigned; /* set id */ + } + + ret = generic_rw(pos, &stream_class->event_header->p); + if (ret) + goto error; + } + + /* print stream-declared event context */ + if (stream_class->event_context) { + ret = generic_rw(pos, &stream_class->event_context->p); + if (ret) + goto error; + } + + if (id >= stream_class->events_by_id->len) { + fprintf(stdout, "[error] Event id %" PRIu64 " is outside range.\n", id); + return -EINVAL; + } + event_class = g_ptr_array_index(stream_class->events_by_id, id); + if (!event_class) { + fprintf(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id); + return -EINVAL; + } + + /* print event-declared event context */ + if (event_class->context) { + ret = generic_rw(pos, &event_class->context->p); + if (ret) + goto error; + } + + /* Read and print event payload */ + if (event_class->fields) { + ret = generic_rw(pos, &event_class->fields->p); + if (ret) + goto error; + } + + return 0; + +error: + fprintf(stdout, "[error] Unexpected end of stream. Either the trace data stream is corrupted or metadata description does not match data layout.\n"); + return ret; +} + void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags) { pos->fd = fd; @@ -100,11 +238,13 @@ void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags) pos->prot = PROT_READ; pos->flags = MAP_PRIVATE; pos->parent.rw_table = read_dispatch_table; + pos->parent.event_cb = ctf_read_event; break; case O_RDWR: pos->prot = PROT_WRITE; /* Write has priority */ pos->flags = MAP_SHARED; pos->parent.rw_table = write_dispatch_table; + pos->parent.event_cb = ctf_write_event; if (fd >= 0) ctf_move_pos_slow(pos, 0, SEEK_SET); /* position for write */ break; diff --git a/include/babeltrace/ctf-text/types.h b/include/babeltrace/ctf-text/types.h index 9e65435e..bb837bcd 100644 --- a/include/babeltrace/ctf-text/types.h +++ b/include/babeltrace/ctf-text/types.h @@ -37,6 +37,7 @@ struct ctf_text_stream_pos { FILE *fp; /* File pointer. NULL if unset. */ int depth; int dummy; /* disable output */ + int print_names; /* print field names */ }; static inline diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index 059c371d..6bfd703d 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -31,6 +31,7 @@ /* Preallocate this many fields for structures */ #define DEFAULT_NR_STRUCT_FIELDS 8 +struct ctf_stream; struct stream_pos; struct format; struct definition; @@ -102,6 +103,7 @@ struct definition { int index; /* Position of the definition in its container */ GQuark name; /* Field name in its container (or 0 if unset) */ int ref; /* number of references to the definition */ + GQuark path; }; typedef int (*rw_dispatch)(struct stream_pos *pos, @@ -111,6 +113,8 @@ typedef int (*rw_dispatch)(struct stream_pos *pos, struct stream_pos { /* read/write dispatch table. Specific to plugin used for stream. */ rw_dispatch *rw_table; /* rw dispatch table */ + int (*event_cb)(struct stream_pos *pos, + struct ctf_stream *stream_class); }; static inline @@ -359,6 +363,14 @@ void set_dynamic_definition_scope(struct definition *definition, const char *root_name); void free_definition_scope(struct definition_scope *scope); +GQuark new_definition_path(struct definition_scope *parent_scope, GQuark field_name); + +static inline +int compare_definition_path(struct definition *definition, GQuark path) +{ + return definition->path == path; +} + void declaration_ref(struct declaration *declaration); void declaration_unref(struct declaration *declaration); @@ -493,4 +505,4 @@ int sequence_rw(struct stream_pos *pos, struct definition *definition); */ void append_scope_path(const char *path, GArray *q); -#endif /* _BABELTRACE_declarationS_H */ +#endif /* _BABELTRACE_TYPES_H */ diff --git a/types/array.c b/types/array.c index 92b8dd06..0bb141ce 100644 --- a/types/array.c +++ b/types/array.c @@ -100,6 +100,7 @@ struct definition * array->p.ref = 1; array->p.index = index; array->p.name = field_name; + array->p.path = new_definition_path(parent_scope, field_name); array->scope = new_definition_scope(parent_scope, field_name); array->elems = g_ptr_array_sized_new(array_declaration->len); g_ptr_array_set_size(array->elems, array_declaration->len); diff --git a/types/enum.c b/types/enum.c index 82a02dfe..068651c7 100644 --- a/types/enum.c +++ b/types/enum.c @@ -410,6 +410,7 @@ struct definition * _enum->p.ref = 1; _enum->p.index = index; _enum->p.name = field_name; + _enum->p.path = new_definition_path(parent_scope, field_name); _enum->value = NULL; definition_integer_parent = enum_declaration->integer_declaration->p.definition_new(&enum_declaration->integer_declaration->p, diff --git a/types/float.c b/types/float.c index 7ae4df6e..5ce6bb43 100644 --- a/types/float.c +++ b/types/float.c @@ -104,6 +104,7 @@ struct definition * _float->p.ref = 1; _float->p.index = index; _float->p.name = field_name; + _float->p.path = new_definition_path(parent_scope, field_name); _float->value = 0.0; return &_float->p; } diff --git a/types/integer.c b/types/integer.c index c43f55e6..5aa9c44f 100644 --- a/types/integer.c +++ b/types/integer.c @@ -72,6 +72,7 @@ struct definition * integer->p.ref = 1; integer->p.index = index; integer->p.name = field_name; + integer->p.path = new_definition_path(parent_scope, field_name); integer->value._unsigned = 0; return &integer->p; } diff --git a/types/sequence.c b/types/sequence.c index 5fcf77aa..f4262cdb 100644 --- a/types/sequence.c +++ b/types/sequence.c @@ -131,6 +131,7 @@ struct definition *_sequence_definition_new(struct declaration *declaration, sequence->p.ref = 1; sequence->p.index = index; sequence->p.name = field_name; + sequence->p.path = new_definition_path(parent_scope, field_name); sequence->scope = new_definition_scope(parent_scope, field_name); len_parent = sequence_declaration->len_declaration->p.definition_new(&sequence_declaration->len_declaration->p, sequence->scope, diff --git a/types/string.c b/types/string.c index f9401553..0f261f41 100644 --- a/types/string.c +++ b/types/string.c @@ -68,6 +68,7 @@ struct definition * string->p.ref = 1; string->p.index = index; string->p.name = field_name; + string->p.path = new_definition_path(parent_scope, field_name); string->value = NULL; string->len = 0; string->alloc_len = 0; diff --git a/types/struct.c b/types/struct.c index 1a2b59d5..6012447b 100644 --- a/types/struct.c +++ b/types/struct.c @@ -109,6 +109,7 @@ struct definition * _struct->p.ref = 1; _struct->p.index = index; _struct->p.name = field_name; + _struct->p.path = new_definition_path(parent_scope, field_name); _struct->scope = new_definition_scope(parent_scope, field_name); _struct->fields = g_ptr_array_sized_new(DEFAULT_NR_STRUCT_FIELDS); g_ptr_array_set_size(_struct->fields, struct_declaration->fields->len); diff --git a/types/types.c b/types/types.c index 1766c61b..7369f30d 100644 --- a/types/types.c +++ b/types/types.c @@ -469,6 +469,30 @@ static struct definition_scope * return scope; } +GQuark new_definition_path(struct definition_scope *parent_scope, GQuark field_name) +{ + GQuark path; + GString *str; + gchar *c_str; + int i; + + str = g_string_new(""); + if (parent_scope) { + for (i = 0; i < parent_scope->scope_path->len; i++) { + GQuark q = g_array_index(parent_scope->scope_path, + GQuark, i); + + g_string_append(str, g_quark_to_string(q)); + g_string_append(str, "."); + } + } + g_string_append(str, g_quark_to_string(field_name)); + c_str = g_string_free(str, FALSE); + path = g_quark_from_string(c_str); + g_free(c_str); + return path; +} + struct definition_scope * new_definition_scope(struct definition_scope *parent_scope, GQuark field_name) diff --git a/types/variant.c b/types/variant.c index 479b4ba4..8a781f67 100644 --- a/types/variant.c +++ b/types/variant.c @@ -175,6 +175,7 @@ struct definition * variant->p.ref = 1; variant->p.index = index; variant->p.name = field_name; + variant->p.path = new_definition_path(parent_scope, field_name); variant->scope = new_definition_scope(parent_scope, field_name); variant->enum_tag = lookup_definition(variant->scope->scope_path, variant_declaration->tag_name, -- 2.34.1