[gnome-builder/wip/slaf/xml-pack: 22/56] xml-pack: IdeXmlDefine object
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/slaf/xml-pack: 22/56] xml-pack: IdeXmlDefine object
- Date: Thu, 13 Jul 2017 12:20:52 +0000 (UTC)
commit 4bae4f173c80f303b8eb0a408351e6cba6834313
Author: Sebastien Lafargue <slafargue gnome org>
Date: Sun May 14 23:06:29 2017 +0200
xml-pack: IdeXmlDefine object
Used to store node informations when
using the rng parser.
plugins/xml-pack/ide-xml-rng-define.c | 220 +++++++++++++++++++++++++++++++++
plugins/xml-pack/ide-xml-rng-define.h | 94 ++++++++++++++
2 files changed, 314 insertions(+), 0 deletions(-)
---
diff --git a/plugins/xml-pack/ide-xml-rng-define.c b/plugins/xml-pack/ide-xml-rng-define.c
new file mode 100644
index 0000000..24777df
--- /dev/null
+++ b/plugins/xml-pack/ide-xml-rng-define.c
@@ -0,0 +1,220 @@
+/* ide-xml-rng-define.c
+ *
+ * Copyright (C) 2017 Sebastien Lafargue <slafargue gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ide-xml-rng-define.h"
+
+G_DEFINE_BOXED_TYPE (IdeXmlRngDefine, ide_xml_rng_define, ide_xml_rng_define_ref, ide_xml_rng_define_unref)
+
+static gchar *type_names [] =
+{
+ "noop",
+ "define",
+ "empty",
+ "not allowed",
+ "text",
+ "element",
+ "datatype",
+ "value",
+ "list",
+ "ref",
+ "parent ref",
+ "external ref",
+ "zero or more",
+ "one or more",
+ "optional",
+ "choice",
+ "group",
+ "interleave",
+ "attribute",
+ "start",
+ "param",
+ "except"
+};
+
+static void
+dump_tree (IdeXmlRngDefine *self,
+ gint indent)
+{
+ IdeXmlRngDefine *def = self;
+ const gchar *type_name;
+ g_autofree gchar *pad = NULL;
+ guchar *name = NULL;
+
+ pad = g_strnfill (indent, ' ');
+ while (def != NULL)
+ {
+ type_name = type_names [def->type];
+ if (def->type == IDE_XML_RNG_DEFINE_REF || def->type == IDE_XML_RNG_DEFINE_PARENTREF)
+ {
+ if (def->node != NULL &&
+ NULL != (name = xmlGetProp (def->node, (const guchar *)"name")))
+ {
+ printf ("%s%s [%s]:%p\n", pad, type_name, name, def->content);
+ xmlFree (name);
+ }
+ else
+ printf ("%s%s: %p\n", pad, type_name, def->content);
+ }
+ else
+ {
+ if (def->name == NULL)
+ printf ("%s%s\n", pad, type_name);
+ else
+ printf ("%s%s [%s]\n", pad, type_name, def->name);
+
+ if (def->content != NULL)
+ {
+ printf ("%s>content:\n", pad);
+ dump_tree (def->content, indent + 1);
+ }
+
+ if (def->attributes != NULL)
+ {
+ printf ("%s>attributes:\n", pad);
+ dump_tree (def->attributes, indent + 1);
+ }
+
+ if (def->name_class != NULL)
+ {
+ printf ("%s>name classes:\n", pad);
+ dump_tree (def->name_class, indent + 1);
+ }
+ }
+
+ def = def->next;
+ }
+}
+
+void
+ide_xml_rng_define_dump_tree (IdeXmlRngDefine *self,
+ gboolean recursive)
+{
+ const gchar *type_name;
+
+ g_return_if_fail (self != NULL);
+
+ if (recursive)
+ dump_tree (self, 0);
+ else
+ {
+ type_name = type_names [self->type];
+ if (self->name == NULL)
+ printf ("%s\n", type_name);
+ else
+ printf ("%s [%s]\n", type_name, self->name);
+ }
+}
+
+IdeXmlRngDefine *
+ide_xml_rng_define_new (xmlNode *node,
+ IdeXmlRngDefine *parent,
+ const guchar *name,
+ IdeXmlRngDefineType type)
+{
+ IdeXmlRngDefine *self;
+
+ self = g_slice_new0 (IdeXmlRngDefine);
+ self->ref_count = 1;
+
+ if (name != NULL)
+ self->name = (guchar *)xmlStrdup (name);
+
+ self->type = type;
+ self->node = node;
+ self->parent = parent;
+
+ return self;
+}
+
+static void
+ide_xml_rng_define_free (IdeXmlRngDefine *self)
+{
+ g_assert (self);
+ g_assert_cmpint (self->ref_count, ==, 0);
+
+ if (self->name != NULL)
+ xmlFree (self->name);
+
+ if (self->ns != NULL)
+ xmlFree (self->ns);
+
+ if (self->next != NULL)
+ ide_xml_rng_define_unref (self->next);
+
+ if (self->content != NULL)
+ ide_xml_rng_define_unref (self->content);
+
+ if (self->content != NULL)
+ ide_xml_rng_define_unref (self->attributes);
+
+ if (self->content != NULL)
+ ide_xml_rng_define_unref (self->name_class);
+
+ g_slice_free (IdeXmlRngDefine, self);
+}
+
+IdeXmlRngDefine *
+ide_xml_rng_define_ref (IdeXmlRngDefine *self)
+{
+ g_return_val_if_fail (self, NULL);
+ g_return_val_if_fail (self->ref_count, NULL);
+
+ g_atomic_int_inc (&self->ref_count);
+
+ return self;
+}
+
+void
+ide_xml_rng_define_unref (IdeXmlRngDefine *self)
+{
+ g_return_if_fail (self);
+ g_return_if_fail (self->ref_count);
+
+ if (g_atomic_int_dec_and_test (&self->ref_count))
+ ide_xml_rng_define_free (self);
+}
+
+void
+ide_xml_rng_define_append (IdeXmlRngDefine *self,
+ IdeXmlRngDefine *def)
+{
+ IdeXmlRngDefine *last = self;
+
+ g_return_if_fail (self);
+ g_return_if_fail (def);
+
+ while (last->next != NULL)
+ last = last->next;
+
+ last->next = def;
+}
+
+void
+ide_xml_rng_define_propagate_parent (IdeXmlRngDefine *self,
+ IdeXmlRngDefine *parent)
+{
+ IdeXmlRngDefine *last = self;
+
+ g_return_if_fail (self);
+
+ do
+ {
+ last->parent = parent;
+ last = last->next;
+ } while (last != NULL);
+}
diff --git a/plugins/xml-pack/ide-xml-rng-define.h b/plugins/xml-pack/ide-xml-rng-define.h
new file mode 100644
index 0000000..1bf49df
--- /dev/null
+++ b/plugins/xml-pack/ide-xml-rng-define.h
@@ -0,0 +1,94 @@
+/* ide-xml-rng-define.h
+ *
+ * Copyright (C) 2017 Sebastien Lafargue <slafargue gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_XML_RNG_DEFINE_H
+#define IDE_XML_RNG_DEFINE_H
+
+#include <libxml/tree.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_XML_RNG_DEFINE (ide_xml_rng_define_get_type())
+
+typedef struct _IdeXmlRngDefine IdeXmlRngDefine;
+
+typedef enum
+{
+ IDE_XML_RNG_DEFINE_NOOP,
+ IDE_XML_RNG_DEFINE_DEFINE,
+ IDE_XML_RNG_DEFINE_EMPTY,
+ IDE_XML_RNG_DEFINE_NOTALLOWED,
+ IDE_XML_RNG_DEFINE_TEXT,
+ IDE_XML_RNG_DEFINE_ELEMENT,
+ IDE_XML_RNG_DEFINE_DATATYPE,
+ IDE_XML_RNG_DEFINE_VALUE,
+ IDE_XML_RNG_DEFINE_LIST,
+ IDE_XML_RNG_DEFINE_REF,
+ IDE_XML_RNG_DEFINE_PARENTREF,
+ IDE_XML_RNG_DEFINE_EXTERNALREF,
+ IDE_XML_RNG_DEFINE_ZEROORMORE,
+ IDE_XML_RNG_DEFINE_ONEORMORE,
+ IDE_XML_RNG_DEFINE_OPTIONAL,
+ IDE_XML_RNG_DEFINE_CHOICE,
+ IDE_XML_RNG_DEFINE_GROUP,
+ IDE_XML_RNG_DEFINE_INTERLEAVE,
+ IDE_XML_RNG_DEFINE_ATTRIBUTE,
+ IDE_XML_RNG_DEFINE_START,
+ IDE_XML_RNG_DEFINE_PARAM,
+ IDE_XML_RNG_DEFINE_EXCEPT
+} IdeXmlRngDefineType;
+
+struct _IdeXmlRngDefine
+{
+ guint ref_count;
+
+ xmlChar *name;
+ xmlChar *ns;
+ IdeXmlRngDefine *parent;
+ IdeXmlRngDefine *next;
+ IdeXmlRngDefine *content;
+ IdeXmlRngDefine *attributes;
+ IdeXmlRngDefine *name_class;
+ xmlNode *node;
+ IdeXmlRngDefineType type;
+
+ gint16 depth;
+ guint is_external_ref : 1;
+ guint is_ref_simplified : 1;
+};
+
+IdeXmlRngDefine *ide_xml_rng_define_new (xmlNode *node,
+ IdeXmlRngDefine *parent,
+ const guchar *name,
+ IdeXmlRngDefineType type);
+void ide_xml_rng_define_append (IdeXmlRngDefine *self,
+ IdeXmlRngDefine *def);
+void ide_xml_rng_define_propagate_parent (IdeXmlRngDefine *self,
+ IdeXmlRngDefine *parent);
+IdeXmlRngDefine *ide_xml_rng_define_ref (IdeXmlRngDefine *self);
+void ide_xml_rng_define_unref (IdeXmlRngDefine *self);
+void ide_xml_rng_define_dump_tree (IdeXmlRngDefine *self,
+ gboolean recursive);
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeXmlRngDefine, ide_xml_rng_define_unref)
+
+G_END_DECLS
+
+#endif /* IDE_XML_RNG_DEFINE_H */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]