[PATCH v3 wayland 3/4] scanner: support "since" attribute for enum entries

Peter Hutterer peter.hutterer at who-t.net
Mon Jan 23 23:56:38 UTC 2017


This was already in the DTD but not supported by the scanner.

The check for ever-increasing "since" tags is not strictly required for enum
entries as we control the binary value. But it keeps the xml file in
good order, preventing things like:

      <entry name="first" value="…" />
      <entry name="second" value="…" since="3"/>
      <entry name="third" value="…" since="2"/>
      <entry name="fourth" value="…" since="3"/>

If this is undesirable in the future the check can be removed without
side-effects.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Changes to v2:
- Add the 'since' version comparison to make sure entry names have
  increasing 'since' attributes (and adjust the commit message)
- Add the test parsing bits to tests/data/small.xml instead of example.xml

 src/scanner.c                  | 34 ++++++++++++++++++++++++++++++----
 tests/data/small-client-core.h | 23 +++++++++++++++++++++++
 tests/data/small-client.h      | 23 +++++++++++++++++++++++
 tests/data/small-code-core.c   |  2 +-
 tests/data/small-code.c        |  2 +-
 tests/data/small-server-core.h | 23 +++++++++++++++++++++++
 tests/data/small-server.h      | 23 +++++++++++++++++++++++
 tests/data/small.xml           |  8 +++++++-
 8 files changed, 131 insertions(+), 7 deletions(-)

diff --git a/src/scanner.c b/src/scanner.c
index 5d66fa4..a6c334f 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -213,6 +213,7 @@ struct enumeration {
 	struct wl_list link;
 	struct description *description;
 	bool bitfield;
+	int since;
 };
 
 struct entry {
@@ -220,6 +221,7 @@ struct entry {
 	char *uppercase_name;
 	char *value;
 	char *summary;
+	int since;
 	struct wl_list link;
 };
 
@@ -494,6 +496,7 @@ create_enumeration(const char *name)
 	enumeration = xzalloc(sizeof *enumeration);
 	enumeration->name = xstrdup(name);
 	enumeration->uppercase_name = uppercase_dup(name);
+	enumeration->since = 1;
 
 	wl_list_init(&enumeration->entry_list);
 
@@ -797,6 +800,12 @@ start_element(void *data, const char *element_name, const char **atts)
 			fail(&ctx->loc, "no entry name given");
 
 		entry = create_entry(name, value);
+		version = version_from_since(ctx, since);
+
+		if (version < ctx->enumeration->since)
+			warn(&ctx->loc, "since version not increasing\n");
+		ctx->enumeration->since = version;
+		entry->since = version;
 
 		if (summary)
 			entry->summary = xstrdup(summary);
@@ -1278,16 +1287,33 @@ emit_enumerations(struct interface *interface)
 		}
 		printf("enum %s_%s {\n", interface->name, e->name);
 		wl_list_for_each(entry, &e->entry_list, link) {
-			if (entry->summary)
-				printf("\t/**\n"
-				       "\t * %s\n"
-				       "\t */\n", entry->summary);
+			if (entry->summary || entry->since > 1) {
+				printf("\t/**\n");
+				if (entry->summary)
+					printf("\t * %s\n", entry->summary);
+				if (entry->since > 1)
+					printf("\t * @since %d\n", entry->since);
+				printf("\t */\n");
+			}
 			printf("\t%s_%s_%s = %s,\n",
 			       interface->uppercase_name,
 			       e->uppercase_name,
 			       entry->uppercase_name, entry->value);
 		}
 		printf("};\n");
+
+		wl_list_for_each(entry, &e->entry_list, link) {
+			if (entry->since == 1)
+                            continue;
+
+                        printf("/**\n * @ingroup iface_%s\n */\n", interface->name);
+                        printf("#define %s_%s_%s_SINCE_VERSION %d\n",
+                               interface->uppercase_name,
+                               e->uppercase_name, entry->uppercase_name,
+                               entry->since);
+
+		}
+
 		printf("#endif /* %s_%s_ENUM */\n\n",
 		       interface->uppercase_name, e->uppercase_name);
 	}
diff --git a/tests/data/small-client-core.h b/tests/data/small-client-core.h
index 8d02edb..c85cca6 100644
--- a/tests/data/small-client-core.h
+++ b/tests/data/small-client-core.h
@@ -61,6 +61,29 @@ struct intf_not_here;
  */
 extern const struct wl_interface intf_A_interface;
 
+#ifndef INTF_A_FOO_ENUM
+#define INTF_A_FOO_ENUM
+enum intf_A_foo {
+	/**
+	 * this is the first
+	 */
+	INTF_A_FOO_FIRST = 0,
+	/**
+	 * this is the second
+	 */
+	INTF_A_FOO_SECOND = 1,
+	/**
+	 * this is the third
+	 * @since 2
+	 */
+	INTF_A_FOO_THIRD = 2,
+};
+/**
+ * @ingroup iface_intf_A
+ */
+#define INTF_A_FOO_THIRD_SINCE_VERSION 2
+#endif /* INTF_A_FOO_ENUM */
+
 /**
  * @ingroup iface_intf_A
  * @struct intf_A_listener
diff --git a/tests/data/small-client.h b/tests/data/small-client.h
index 050e63f..884346d 100644
--- a/tests/data/small-client.h
+++ b/tests/data/small-client.h
@@ -61,6 +61,29 @@ struct intf_not_here;
  */
 extern const struct wl_interface intf_A_interface;
 
+#ifndef INTF_A_FOO_ENUM
+#define INTF_A_FOO_ENUM
+enum intf_A_foo {
+	/**
+	 * this is the first
+	 */
+	INTF_A_FOO_FIRST = 0,
+	/**
+	 * this is the second
+	 */
+	INTF_A_FOO_SECOND = 1,
+	/**
+	 * this is the third
+	 * @since 2
+	 */
+	INTF_A_FOO_THIRD = 2,
+};
+/**
+ * @ingroup iface_intf_A
+ */
+#define INTF_A_FOO_THIRD_SINCE_VERSION 2
+#endif /* INTF_A_FOO_ENUM */
+
 /**
  * @ingroup iface_intf_A
  * @struct intf_A_listener
diff --git a/tests/data/small-code-core.c b/tests/data/small-code-core.c
index dbf7f40..28a00ab 100644
--- a/tests/data/small-code-core.c
+++ b/tests/data/small-code-core.c
@@ -54,7 +54,7 @@ static const struct wl_message intf_A_events[] = {
 };
 
 WL_EXPORT const struct wl_interface intf_A_interface = {
-	"intf_A", 1,
+	"intf_A", 3,
 	3, intf_A_requests,
 	1, intf_A_events,
 };
diff --git a/tests/data/small-code.c b/tests/data/small-code.c
index dbf7f40..28a00ab 100644
--- a/tests/data/small-code.c
+++ b/tests/data/small-code.c
@@ -54,7 +54,7 @@ static const struct wl_message intf_A_events[] = {
 };
 
 WL_EXPORT const struct wl_interface intf_A_interface = {
-	"intf_A", 1,
+	"intf_A", 3,
 	3, intf_A_requests,
 	1, intf_A_events,
 };
diff --git a/tests/data/small-server-core.h b/tests/data/small-server-core.h
index c1e8d05..6dd2d05 100644
--- a/tests/data/small-server-core.h
+++ b/tests/data/small-server-core.h
@@ -64,6 +64,29 @@ struct intf_not_here;
  */
 extern const struct wl_interface intf_A_interface;
 
+#ifndef INTF_A_FOO_ENUM
+#define INTF_A_FOO_ENUM
+enum intf_A_foo {
+	/**
+	 * this is the first
+	 */
+	INTF_A_FOO_FIRST = 0,
+	/**
+	 * this is the second
+	 */
+	INTF_A_FOO_SECOND = 1,
+	/**
+	 * this is the third
+	 * @since 2
+	 */
+	INTF_A_FOO_THIRD = 2,
+};
+/**
+ * @ingroup iface_intf_A
+ */
+#define INTF_A_FOO_THIRD_SINCE_VERSION 2
+#endif /* INTF_A_FOO_ENUM */
+
 /**
  * @ingroup iface_intf_A
  * @struct intf_A_interface
diff --git a/tests/data/small-server.h b/tests/data/small-server.h
index 0bd8a1d..4763f5b 100644
--- a/tests/data/small-server.h
+++ b/tests/data/small-server.h
@@ -64,6 +64,29 @@ struct intf_not_here;
  */
 extern const struct wl_interface intf_A_interface;
 
+#ifndef INTF_A_FOO_ENUM
+#define INTF_A_FOO_ENUM
+enum intf_A_foo {
+	/**
+	 * this is the first
+	 */
+	INTF_A_FOO_FIRST = 0,
+	/**
+	 * this is the second
+	 */
+	INTF_A_FOO_SECOND = 1,
+	/**
+	 * this is the third
+	 * @since 2
+	 */
+	INTF_A_FOO_THIRD = 2,
+};
+/**
+ * @ingroup iface_intf_A
+ */
+#define INTF_A_FOO_THIRD_SINCE_VERSION 2
+#endif /* INTF_A_FOO_ENUM */
+
 /**
  * @ingroup iface_intf_A
  * @struct intf_A_interface
diff --git a/tests/data/small.xml b/tests/data/small.xml
index 571618f..a6e62ad 100644
--- a/tests/data/small.xml
+++ b/tests/data/small.xml
@@ -26,7 +26,7 @@
     SOFTWARE.
   </copyright>
 
-  <interface name="intf_A" version="1">
+  <interface name="intf_A" version="3">
     <description summary="the thing A">
       A useless example trying to tickle the scanner.
     </description>
@@ -48,5 +48,11 @@
     <request name="destroy" type="destructor"/>
 
     <event name="hey"/>
+
+    <enum name="foo">
+        <entry name="first" value="0" summary="this is the first"/>
+        <entry name="second" value="1" summary="this is the second"/>
+        <entry name="third" value="2" since="2" summary="this is the third"/>
+    </enum>
   </interface>
 </protocol>
-- 
2.9.3



More information about the wayland-devel mailing list