[PATCH wayland] Add support for cross-interface enum attributes

Auke Booij auke at tulcod.com
Sat Nov 28 17:27:39 PST 2015


Signed-off-by: Auke Booij <auke at tulcod.com>
---
 doc/publican/protocol-to-docbook.xsl | 17 +++++++++---
 protocol/wayland.xml                 |  4 +--
 src/scanner.c                        | 51 +++++++++++++++++++++++++++---------
 3 files changed, 55 insertions(+), 17 deletions(-)

diff --git a/doc/publican/protocol-to-docbook.xsl b/doc/publican/protocol-to-docbook.xsl
index fad207a..1fa066d 100644
--- a/doc/publican/protocol-to-docbook.xsl
+++ b/doc/publican/protocol-to-docbook.xsl
@@ -103,9 +103,20 @@
     <listitem>
         <simpara>
           <xsl:if test="@enum">
-            <link linkend="protocol-spec-{../../@name}-enum-{@enum}">
-              <xsl:value-of select="@enum"/>
-            </link>
+            <xsl:choose>
+              <xsl:when test="contains(@enum, '.')">
+                <link linkend="protocol-spec-{substring-before(@enum, '.')}-enum-{substring-after(@enum, '.')}">
+                  <xsl:value-of select="substring-before(@enum, '.')"/>
+                  <xsl:text>::</xsl:text>
+                  <xsl:value-of select="substring-after(@enum, '.')"/>
+                </link>
+              </xsl:when>
+              <xsl:otherwise>
+                <link linkend="protocol-spec-{../../@name}-enum-{@enum}">
+                  <xsl:value-of select="@enum"/>
+                </link>
+              </xsl:otherwise>
+            </xsl:choose>
 	    <xsl:text> </xsl:text>
           </xsl:if>
           <xsl:value-of select="@type"/>
diff --git a/protocol/wayland.xml b/protocol/wayland.xml
index f9e6d76..0873553 100644
--- a/protocol/wayland.xml
+++ b/protocol/wayland.xml
@@ -229,7 +229,7 @@
       <arg name="width" type="int"/>
       <arg name="height" type="int"/>
       <arg name="stride" type="int"/>
-      <arg name="format" type="uint"/>
+      <arg name="format" type="uint" enum="wl_shm.format"/>
     </request>
 
     <request name="destroy" type="destructor">
@@ -1292,7 +1292,7 @@
 	wl_output.transform enum the invalid_transform protocol error
 	is raised.
       </description>
-      <arg name="transform" type="int"/>
+      <arg name="transform" type="int" enum="wl_output.transform"/>
     </request>
 
     <!-- Version 3 additions -->
diff --git a/src/scanner.c b/src/scanner.c
index 406519f..d6edf1a 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -785,6 +785,28 @@ start_element(void *data, const char *element_name, const char **atts)
 	}
 }
 
+static struct enumeration *
+find_enumeration(struct protocol *protocol, char *enum_attribute, size_t interface_length)
+{
+	struct interface *i;
+	struct enumeration *e, *f;
+	char *enum_name;
+
+	if (interface_length == 0)
+		enum_name = enum_attribute;
+	else
+		enum_name = enum_attribute + interface_length + 1;
+
+	f = NULL;
+	wl_list_for_each(i, &protocol->interface_list, link)
+		if (strncmp(i->name, enum_attribute, interface_length) == 0)
+			wl_list_for_each(e, &i->enumeration_list, link)
+				if(strcmp(e->name, enum_name) == 0)
+					f = e;
+
+	return f;
+}
+
 static void
 verify_arguments(struct parse_context *ctx, struct wl_list *messages, struct wl_list *enumerations)
 {
@@ -792,25 +814,29 @@ verify_arguments(struct parse_context *ctx, struct wl_list *messages, struct wl_
 	wl_list_for_each(m, messages, link) {
 		struct arg *a;
 		wl_list_for_each(a, &m->arg_list, link) {
-			struct enumeration *e, *f;
+			struct enumeration *e;
+			int i, j = 0;
 
 			if (!a->enumeration_name)
 				continue;
 
-			f = NULL;
-			wl_list_for_each(e, enumerations, link) {
-				if(strcmp(e->name, a->enumeration_name) == 0)
-					f = e;
+			for (i = 0; i < a->enumeration_name[i]; i++) {
+				if (a->enumeration_name[i] == '.') {
+					j = i;
+				}
+
 			}
 
-			if (f == NULL)
+			e = find_enumeration(ctx->protocol, a->enumeration_name, j);
+
+			if (e == NULL)
 				fail(&ctx->loc,
 				     "could not find enumeration %s",
 				     a->enumeration_name);
 
 			switch (a->type) {
 			case INT:
-				if (f->bitfield)
+				if (e->bitfield)
 					fail(&ctx->loc,
 					     "bitfield-style enum must only be referenced by uint");
 				break;
@@ -848,12 +874,13 @@ end_element(void *data, const XML_Char *name)
 			     ctx->enumeration->name);
 		}
 		ctx->enumeration = NULL;
-	} else if (strcmp(name, "interface") == 0) {
-		struct interface *i = ctx->interface;
-
-		verify_arguments(ctx, &i->request_list, &i->enumeration_list);
-		verify_arguments(ctx, &i->event_list, &i->enumeration_list);
+	} else if (strcmp(name, "protocol") == 0) {
+		struct interface *i;
 
+		wl_list_for_each(i, &ctx->protocol->interface_list, link) {
+			verify_arguments(ctx, &i->request_list, &i->enumeration_list);
+			verify_arguments(ctx, &i->event_list, &i->enumeration_list);
+		}
 	}
 }
 
-- 
2.6.2



More information about the wayland-devel mailing list