All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, akong@redhat.com, berto@igalia.com,
	armbru@redhat.com, mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v4 11/16] qapi: Support downstream structs
Date: Thu, 14 May 2015 06:50:57 -0600	[thread overview]
Message-ID: <1431607862-9238-12-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1431607862-9238-1-git-send-email-eblake@redhat.com>

Enhance the testsuite to cover downstream structs, including struct
members and base structs.  Update the generator to mangle the
struct names in the appropriate places.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi-types.py                   |  4 ++--
 scripts/qapi-visit.py                   | 11 ++++++-----
 tests/qapi-schema/qapi-schema-test.json |  4 ++++
 tests/qapi-schema/qapi-schema-test.out  |  8 ++++++--
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 1593fc6..5118151 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -45,7 +45,7 @@ typedef struct %(name)sList
     struct %(name)sList *next;
 } %(name)sList;
 ''',
-                 name=name)
+                 name=c_name(name))

 def generate_fwd_enum_struct(name, members):
     return mcgen('''
@@ -87,7 +87,7 @@ def generate_struct(expr):
 struct %(name)s
 {
 ''',
-          name=structname)
+          name=c_name(structname))

     if base:
         ret += generate_struct_fields({'base': base})
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 7697ec6..b500724 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -56,7 +56,7 @@ static void visit_type_%(name)s_fields(Visitor *m, %(name)s **obj, Error **errp)
 {
     Error *err = NULL;
 ''',
-                 name=name)
+                 name=c_name(name))
     push_indent()

     if base:
@@ -111,16 +111,16 @@ def generate_visit_struct_body(name, members):
     ret = mcgen('''
     Error *err = NULL;

-    visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err);
+    visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(c_name)s), &err);
     if (!err) {
         if (*obj) {
-            visit_type_%(name)s_fields(m, obj, errp);
+            visit_type_%(c_name)s_fields(m, obj, errp);
         }
         visit_end_struct(m, &err);
     }
     error_propagate(errp, err);
 ''',
-                name=name)
+                name=name, c_name=c_name(name))

     return ret

@@ -137,7 +137,7 @@ def generate_visit_struct(expr):
 void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **errp)
 {
 ''',
-                name=name)
+                 name=c_name(name))

     ret += generate_visit_struct_body(name, members)

@@ -347,6 +347,7 @@ out:
 def generate_declaration(name, members, builtin_type=False):
     ret = ""
     if not builtin_type:
+        name = c_name(name)
         ret += mcgen('''

 void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **errp);
diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index 5f9af66..ca9b34c 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -110,3 +110,7 @@

 # test that we correctly compile downstream extensions
 { 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
+{ 'struct': '__org.qemu_x-Base',
+  'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
+{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
+  'data': { '__org.qemu_x-member2': 'str' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index 40f0f20..6ab4f00 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -23,7 +23,9 @@
  OrderedDict([('event', 'EVENT_B'), ('data', OrderedDict())]),
  OrderedDict([('event', 'EVENT_C'), ('data', OrderedDict([('*a', 'int'), ('*b', 'UserDefOne'), ('c', 'str')]))]),
  OrderedDict([('event', 'EVENT_D'), ('data', OrderedDict([('a', 'EventStructOne'), ('b', 'str'), ('*c', 'str'), ('*enum3', 'EnumOne')]))]),
- OrderedDict([('enum', '__org.qemu_x-Enum'), ('data', ['__org.qemu_x-value'])])]
+ OrderedDict([('enum', '__org.qemu_x-Enum'), ('data', ['__org.qemu_x-value'])]),
+ OrderedDict([('struct', '__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member1', '__org.qemu_x-Enum')]))]),
+ OrderedDict([('struct', '__org.qemu_x-Struct'), ('base', '__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2', 'str')]))])]
 [{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
  {'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
  {'enum_name': 'UserDefAlternateKind', 'enum_values': None},
@@ -39,4 +41,6 @@
  OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]),
  OrderedDict([('struct', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]),
  OrderedDict([('struct', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))]),
- OrderedDict([('struct', 'EventStructOne'), ('data', OrderedDict([('struct1', 'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))])]
+ OrderedDict([('struct', 'EventStructOne'), ('data', OrderedDict([('struct1', 'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))]),
+ OrderedDict([('struct', '__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member1', '__org.qemu_x-Enum')]))]),
+ OrderedDict([('struct', '__org.qemu_x-Struct'), ('base', '__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2', 'str')]))])]
-- 
2.1.0

  parent reply	other threads:[~2015-05-14 12:51 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-14 12:50 [Qemu-devel] [PATCH v4 00/16] Fix qapi mangling of downstream names Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 01/16] qapi: Fix C identifiers generated for names containing '.' Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 02/16] qapi: Rename identical c_fun()/c_var() into c_name() Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 03/16] qapi: Rename _generate_enum_string() to camel_to_upper() Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 04/16] qapi: Rename generate_enum_full_value() to c_enum_const() Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 05/16] qapi: Simplify c_enum_const() Eric Blake
2015-05-19  8:12   ` Alberto Garcia
2015-05-19 10:15     ` Markus Armbruster
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 06/16] qapi: Use c_enum_const() in generate_alternate_qtypes() Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 07/16] qapi: Move camel_to_upper(), c_enum_const() to closely related code Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 08/16] qapi: Tidy c_type logic Eric Blake
2015-05-14 15:35   ` Markus Armbruster
2015-05-14 15:39   ` Eric Blake
2015-05-14 16:13     ` Markus Armbruster
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 09/16] qapi: Make c_type() consistently convert qapi names Eric Blake
2015-05-14 15:40   ` Markus Armbruster
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 10/16] qapi: Support downstream enums Eric Blake
2015-05-14 16:02   ` Markus Armbruster
2015-05-14 12:50 ` Eric Blake [this message]
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 12/16] qapi: Support downstream simple unions Eric Blake
2015-05-14 12:50 ` [Qemu-devel] [PATCH v4 13/16] qapi: Support downstream flat unions Eric Blake
2015-05-14 12:51 ` [Qemu-devel] [PATCH v4 14/16] qapi: Support downstream alternates Eric Blake
2015-05-14 12:51 ` [Qemu-devel] [PATCH v4 15/16] qapi: Support downstream events and commands Eric Blake
2015-05-14 12:51 ` [Qemu-devel] [PATCH v4 16/16] qapi: Prefer '"str" + var' over '"str%s" % var' Eric Blake
2015-05-14 16:09   ` Markus Armbruster
2015-05-14 16:25     ` Eric Blake
2015-05-14 13:07 ` [Qemu-devel] [PATCH v4 00/16] Fix qapi mangling of downstream names Eric Blake
2015-05-14 16:46   ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431607862-9238-12-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=akong@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berto@igalia.com \
    --cc=kwolf@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.