Scope path: split dynamic scope path
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 18 Apr 2011 19:35:53 +0000 (15:35 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 18 Apr 2011 19:35:53 +0000 (15:35 -0400)
Keep the lookup code regular.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
include/babeltrace/types.h
types/types.c

index 2c01a9a2510bbf2087daa45ff53588549e256af3..499db793ac0b1eade3fa13b1a93e4c03995c7720 100644 (file)
@@ -517,7 +517,7 @@ int ctf_event_visit(FILE *fd, int depth, struct ctf_node *node,
                                parent_def_scope, 0, 0);
                set_dynamic_definition_scope(&event->context->p,
                                             event->context->scope,
-                                            g_quark_from_string("event.context"));
+                                            "event.context");
                parent_def_scope = event->context->scope;
                declaration_unref(event->context_decl);
        }
@@ -527,7 +527,7 @@ int ctf_event_visit(FILE *fd, int depth, struct ctf_node *node,
                                parent_def_scope, 0, 0);
                set_dynamic_definition_scope(&event->fields->p,
                                             event->fields->scope,
-                                            g_quark_from_string("event.fields"));
+                                            "event.fields");
                parent_def_scope = event->fields->scope;
                declaration_unref(event->fields_decl);
        }
@@ -656,7 +656,7 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
                                parent_def_scope, 0, 0);
                set_dynamic_definition_scope(&stream->packet_context->p,
                                             stream->packet_context->scope,
-                                            g_quark_from_string("stream.packet.context"));
+                                            "stream.packet.context");
                parent_def_scope = stream->packet_context->scope;
                declaration_unref(stream->packet_context_decl);
        }
@@ -666,7 +666,7 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
                                parent_def_scope, 0, 0);
                set_dynamic_definition_scope(&stream->event_header->p,
                                             stream->event_header->scope,
-                                            g_quark_from_string("stream.event.header"));
+                                            "stream.event.header");
                parent_def_scope = stream->event_header->scope;
                declaration_unref(stream->event_header_decl);
        }
@@ -676,7 +676,7 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
                                parent_def_scope, 0, 0);
                set_dynamic_definition_scope(&stream->event_context->p,
                                             stream->event_context->scope,
-                                            g_quark_from_string("stream.event.context"));
+                                            "stream.event.context");
                parent_def_scope = stream->event_context->scope;
                declaration_unref(stream->event_context_decl);
        }
index 21dd66f246f0c9d71845858320bb359d7313ae60..6fde4d18605a117529ba96fc5e5a4a4cefdc3988 100644 (file)
@@ -382,7 +382,7 @@ struct definition_scope *
                             GQuark field_name);
 void set_dynamic_definition_scope(struct definition *definition,
                                  struct definition_scope *scope,
-                                 GQuark root_name);
+                                 const char *root_name);
 void free_definition_scope(struct definition_scope *scope);
 
 void declaration_ref(struct declaration *declaration);
index fe1538f0102c6a1824bac0485eef3e2cb8125fed..e57624fb707b73225b2400d4b8f29d192e828132 100644 (file)
@@ -446,12 +446,46 @@ struct definition_scope *
        return scope;
 }
 
+/*
+ * in: path, out: q (GArray of GQuark)
+ */
+static
+void append_scope_path(const char *path, GArray *q)
+{
+       const char *ptrbegin, *ptrend = path;
+       GQuark quark;
+
+       for (;;) {
+               char *str;
+               size_t len;
+
+               ptrbegin = ptrend;
+               ptrend = strchr(ptrbegin, '.');
+               if (!ptrend)
+                       break;
+               len = ptrend - ptrbegin;
+               /* Don't accept two consecutive dots */
+               assert(len != 0);
+               str = g_new(char, len + 1);     /* include \0 */
+               memcpy(str, ptrbegin, len);
+               str[len] = '\0';
+               quark = g_quark_from_string(str);
+               g_array_append_val(q, quark);
+               g_free(str);
+       }
+       /* last. Check for trailing dot (and discard). */
+       if (ptrbegin[0] != '\0') {
+               quark = g_quark_from_string(ptrbegin);
+               g_array_append_val(q, quark);
+       }
+}
+
 void set_dynamic_definition_scope(struct definition *definition,
                                  struct definition_scope *scope,
-                                 GQuark root_name)
+                                 const char *root_name)
 {
-       g_array_set_size(scope->scope_path, 1);
-       g_array_index(scope->scope_path, GQuark, 0) = root_name;
+       g_array_set_size(scope->scope_path, 0);
+       append_scope_path(root_name, scope->scope_path);
        /*
         * Use INT_MAX order to ensure that all fields of the parent
         * scope are seen as being prior to this scope.
This page took 0.037736 seconds and 4 git commands to generate.