diff mbox

[v3,01/10] qapi: Rename 'fields' to 'members' in generator

Message ID 1457021813-10704-2-git-send-email-eblake@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Blake March 3, 2016, 4:16 p.m. UTC
C types and JSON objects don't have fields, but members.  We
shouldn't gratuitously invent terminology.  This patch is a
strict renaming of generator code internals (including testsuite
comments), before later patches rename C interfaces.

No change to generated code with this patch.

Suggested-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>

---
v3: split out Python/comment renames from C code
v2: new patch
---
 scripts/qapi.py                         | 20 ++++++++++----------
 scripts/qapi-commands.py                |  4 ++--
 scripts/qapi-event.py                   |  4 ++--
 scripts/qapi-types.py                   |  8 ++++----
 scripts/qapi-visit.py                   | 28 ++++++++++++++--------------
 tests/qapi-schema/qapi-schema-test.json |  2 +-
 6 files changed, 33 insertions(+), 33 deletions(-)
diff mbox

Patch

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 18adca7..6b2aa6e 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -326,7 +326,7 @@  class QAPISchemaParser(object):
 #


-def find_base_fields(base):
+def find_base_members(base):
     base_struct_define = find_struct(base)
     if not base_struct_define:
         return None
@@ -355,11 +355,11 @@  def discriminator_find_enum_define(expr):
     if not (discriminator and base):
         return None

-    base_fields = find_base_fields(base)
-    if not base_fields:
+    base_members = find_base_members(base)
+    if not base_members:
         return None

-    discriminator_type = base_fields.get(discriminator)
+    discriminator_type = base_members.get(discriminator)
     if not discriminator_type:
         return None

@@ -567,14 +567,14 @@  def check_union(expr, expr_info):
             raise QAPIExprError(expr_info,
                                 "Flat union '%s' must have a base"
                                 % name)
-        base_fields = find_base_fields(base)
-        assert base_fields
+        base_members = find_base_members(base)
+        assert base_members

         # The value of member 'discriminator' must name a non-optional
         # member of the base struct.
         check_name(expr_info, "Discriminator of flat union '%s'" % name,
                    discriminator)
-        discriminator_type = base_fields.get(discriminator)
+        discriminator_type = base_members.get(discriminator)
         if not discriminator_type:
             raise QAPIExprError(expr_info,
                                 "Discriminator '%s' is not a member of base "
@@ -969,7 +969,7 @@  class QAPISchemaObjectType(QAPISchemaType):
             assert self.variants.tag_member in self.members
             self.variants.check_clash(schema, self.info, seen)

-    # Check that the members of this type do not cause duplicate JSON fields,
+    # Check that the members of this type do not cause duplicate JSON members,
     # and update seen to track the members seen so far. Report any errors
     # on behalf of info, which is not necessarily self.info
     def check_clash(self, schema, info, seen):
@@ -1647,8 +1647,8 @@  def gen_err_check(label='out', skiperr=False):
                  label=label)


-def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False,
-                     label='out'):
+def gen_visit_members(members, prefix='', need_cast=False, skiperr=False,
+                      label='out'):
     ret = ''
     if skiperr:
         errparg = 'NULL'
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index f831621..f44e01f 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -111,7 +111,7 @@  def gen_marshal_input_visit(arg_type, dealloc=False):
     v = qmp_input_get_visitor(qiv);
 ''')

-    ret += gen_visit_fields(arg_type.members, skiperr=dealloc)
+    ret += gen_visit_members(arg_type.members, skiperr=dealloc)

     if dealloc:
         ret += mcgen('''
@@ -175,7 +175,7 @@  def gen_marshal(name, arg_type, ret_type):
     ret += gen_marshal_input_visit(arg_type)
     ret += gen_call(name, arg_type, ret_type)

-    # 'goto out' produced by gen_marshal_input_visit->gen_visit_fields()
+    # 'goto out' produced by gen_marshal_input_visit->gen_visit_members()
     # for each arg_type member, and by gen_call() for ret_type
     if (arg_type and arg_type.members) or ret_type:
         ret += mcgen('''
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 544ae12..fb579dd 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -67,8 +67,8 @@  def gen_event_send(name, arg_type):
 ''',
                      name=name)
         ret += gen_err_check()
-        ret += gen_visit_fields(arg_type.members, need_cast=True,
-                                label='out_obj')
+        ret += gen_visit_members(arg_type.members, need_cast=True,
+                                 label='out_obj')
         ret += mcgen('''
 out_obj:
     visit_end_struct(v, err ? NULL : &err);
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index eac90d2..8858d29 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -38,7 +38,7 @@  struct %(c_name)s {
                  c_name=c_name(name), c_type=element_type.c_type())


-def gen_struct_fields(members):
+def gen_struct_members(members):
     ret = ''
     for memb in members:
         if memb.optional:
@@ -77,16 +77,16 @@  struct %(c_name)s {
     /* Members inherited from %(c_name)s: */
 ''',
                      c_name=base.c_name())
-        ret += gen_struct_fields(base.members)
+        ret += gen_struct_members(base.members)
         ret += mcgen('''
     /* Own members: */
 ''')
-    ret += gen_struct_fields(members)
+    ret += gen_struct_members(members)

     if variants:
         ret += gen_variants(variants)

-    # Make sure that all structs have at least one field; this avoids
+    # Make sure that all structs have at least one member; this avoids
     # potential issues with attempting to malloc space for zero-length
     # structs in C, and also incompatibility with C++ (where an empty
     # struct is size 1).
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 2308268..b21d3ef 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -15,9 +15,9 @@ 
 from qapi import *
 import re

-# visit_type_FOO_fields() is always emitted; track if a forward declaration
+# visit_type_FOO_members() is always emitted; track if a forward declaration
 # or implementation has already been output.
-struct_fields_seen = set()
+object_members_seen = set()


 def gen_visit_decl(name, scalar=False):
@@ -30,10 +30,10 @@  void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_type)sobj, Error **
                  c_name=c_name(name), c_type=c_type)


-def gen_visit_fields_decl(typ):
-    if typ.name in struct_fields_seen:
+def gen_visit_members_decl(typ):
+    if typ.name in object_members_seen:
         return ''
-    struct_fields_seen.add(typ.name)
+    object_members_seen.add(typ.name)
     return mcgen('''

 static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s *obj, Error **errp);
@@ -41,18 +41,18 @@  static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s *obj, Error **er
                  c_type=typ.c_name())


-def gen_visit_struct_fields(name, base, members, variants):
+def gen_visit_object_members(name, base, members, variants):
     ret = ''

     if base:
-        ret += gen_visit_fields_decl(base)
+        ret += gen_visit_members_decl(base)
     if variants:
         for var in variants.variants:
             # Ugly special case for simple union TODO get rid of it
             if not var.simple_union_type():
-                ret += gen_visit_fields_decl(var.type)
+                ret += gen_visit_members_decl(var.type)

-    struct_fields_seen.add(name)
+    object_members_seen.add(name)
     ret += mcgen('''

 static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **errp)
@@ -69,7 +69,7 @@  static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **er
                      c_type=base.c_name())
         ret += gen_err_check()

-    ret += gen_visit_fields(members, prefix='obj->')
+    ret += gen_visit_members(members, prefix='obj->')

     if variants:
         ret += mcgen('''
@@ -108,7 +108,7 @@  static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **er
     }
 ''')

-    # 'goto out' produced for base, by gen_visit_fields() for each member,
+    # 'goto out' produced for base, by gen_visit_members() for each member,
     # and if variants were present
     if base or members or variants:
         ret += mcgen('''
@@ -174,7 +174,7 @@  def gen_visit_alternate(name, variants):
         if var.type.alternate_qtype() == 'QTYPE_QINT':
             promote_int = 'false'
         if isinstance(var.type, QAPISchemaObjectType):
-            ret += gen_visit_fields_decl(var.type)
+            ret += gen_visit_members_decl(var.type)

     ret += mcgen('''

@@ -235,10 +235,10 @@  out:


 def gen_visit_object(name, base, members, variants):
-    ret = gen_visit_struct_fields(name, base, members, variants)
+    ret = gen_visit_object_members(name, base, members, variants)

     # FIXME: if *obj is NULL on entry, and visit_start_struct() assigns to
-    # *obj, but then visit_type_FOO_fields() fails, we should clean up *obj
+    # *obj, but then visit_type_FOO_members() fails, we should clean up *obj
     # rather than leaving it non-NULL. As currently written, the caller must
     # call qapi_free_FOO() to avoid a memory leak of the partial FOO.
     ret += mcgen('''
diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index 632964a..728659e 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -77,7 +77,7 @@ 
   'base': 'UserDefZero',
   'data': { 'string': 'str', 'enum1': 'QEnumTwo' } }

-# this variant of UserDefFlatUnion defaults to a union that uses fields with
+# this variant of UserDefFlatUnion defaults to a union that uses members with
 # allocated types to test corner cases in the cleanup/dealloc visitor
 { 'union': 'UserDefFlatUnion2',
   'base': 'UserDefUnionBase2',