*/
#include <babeltrace/format.h>
+#include <limits.h>
#include <glib.h>
#include <errno.h>
}
static
-struct declaration_variant *
+struct declaration_untagged_variant *
lookup_variant_declaration_scope(GQuark variant_name,
struct declaration_scope *scope)
{
(gconstpointer) (unsigned long) variant_name);
}
-struct declaration_variant *
+struct declaration_untagged_variant *
lookup_variant_declaration(GQuark variant_name,
struct declaration_scope *scope)
{
- struct declaration_variant *declaration;
+ struct declaration_untagged_variant *declaration;
while (scope) {
declaration = lookup_variant_declaration_scope(variant_name, scope);
}
int register_variant_declaration(GQuark variant_name,
- struct declaration_variant *variant_declaration,
+ struct declaration_untagged_variant *untagged_variant_declaration,
struct declaration_scope *scope)
{
if (!variant_name)
g_hash_table_insert(scope->variant_declarations,
(gpointer) (unsigned long) variant_name,
- variant_declaration);
- declaration_ref(&variant_declaration->p);
+ untagged_variant_declaration);
+ declaration_ref(&untagged_variant_declaration->p);
return 0;
}
}
/*
- * Same as new_definition_scope, but reset the scope path.
+ * in: path (dot separated), out: q (GArray of GQuark)
*/
-struct definition_scope *
- new_dynamic_definition_scope(struct definition_scope *parent_scope,
- GQuark field_name)
+void append_scope_path(const char *path, GArray *q)
{
- struct definition_scope *scope;
+ 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);
+ }
+}
- scope = _new_definition_scope(parent_scope, 1);
- g_array_index(scope->scope_path, GQuark, 0) = field_name;
- return scope;
+void set_dynamic_definition_scope(struct definition *definition,
+ struct definition_scope *scope,
+ const char *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.
+ */
+ definition->index = INT_MAX;
}
void free_definition_scope(struct definition_scope *scope)