qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH RFC v4 02.5/32] qapi: Hide internal data members of


From: Eric Blake
Subject: [Qemu-devel] [PATCH RFC v4 02.5/32] qapi: Hide internal data members of schema objects.
Date: Fri, 4 Sep 2015 17:51:08 -0600

We have a few fields that exist mainly to hold information from
__init__() until check() (matching the fact that parsing is
two-pass; the first to find type names, the second to associate
types together while honoring forward references), or which should
only be used through accessor methods.  We should not use these
fields directly in other files after check() has run, so use the
python convention of naming these fields with leading underscore
to mark their internal usage, and to check that no one else was
using them.

Exception: our crazy handling of simple unions (with a C member
'kind' matching the QMP wire 'type') requires peeking through
the hidden field.  This leaky abstraction will be cleaned up in
a later patch.

Signed-off-by: Eric Blake <address@hidden>
---

Technically, I wrote this patch after 32; if you decide to rebase
it into the series, you'll have to split it among 2, 10, 11, and 30.
Up to you if you want to squash this in during your spin of v5, or
if you want me to keep it as a separate patch for inclusion after
your series.

 scripts/qapi-introspect.py |  2 +-
 scripts/qapi-types.py      |  2 +-
 scripts/qapi-visit.py      |  4 ++--
 scripts/qapi.py            | 54 +++++++++++++++++++++++-----------------------
 4 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index 9886b65..c7a2dfb 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -138,7 +138,7 @@ const char %(c_name)s[] = %(c_string)s;
     def visit_object_type_flat(self, name, info, members, variants):
         obj = {'members': [self._gen_member(m) for m in members]}
         if variants:
-            obj.update(self._gen_variants(variants.tag_name,
+            obj.update(self._gen_variants(variants._tag_name,
                                           variants.variants))
         self._gen_json(name, 'object', obj)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 83fc421..65c5ed4 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -144,7 +144,7 @@ struct %(c_name)s {
     union { /* union tag is @%(c_name)s */
         void *data;
 ''',
-                 c_name=c_name(variants.tag_name or 'kind'))
+                 c_name=c_name(variants._tag_name or 'kind'))

     for var in variants.variants:
         # TODO ugly special case for simple union
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 468080e..196f389 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -270,7 +270,7 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, 
const char *name, Error
                      c_name=c_name(name))

     tag_key = variants.tag_member.name
-    if not variants.tag_name:
+    if not variants._tag_name:
         # we pointlessly use a different key for simple unions
         tag_key = 'type'
     ret += mcgen('''
@@ -284,7 +284,7 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, 
const char *name, Error
         switch ((*obj)->%(c_name)s) {
 ''',
                  c_type=variants.tag_member.type.c_name(),
-                 c_name=c_name(variants.tag_name or 'kind'),
+                 c_name=c_name(variants._tag_name or 'kind'),
                  name=tag_key)

     for var in variants.variants:
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 1058f9e..17e81f5 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -806,19 +806,19 @@ class QAPISchemaBuiltinType(QAPISchemaType):
         assert not c_type or isinstance(c_type, str)
         assert json_type in ('string', 'number', 'int', 'boolean', 'null',
                              'value')
-        self.json_type_name = json_type
-        self.c_type_name = c_type
-        self.c_null_val = c_null
+        self._json_type_name = json_type
+        self._c_type_name = c_type
+        self._c_null_val = c_null
     def c_name(self):
         return self.name
     def c_type(self, is_param=False):
         if is_param and self.name == 'str':
-            return 'const ' + self.c_type_name
-        return self.c_type_name
+            return 'const ' + self._c_type_name
+        return self._c_type_name
     def c_null(self):
-        return self.c_null_val
+        return self._c_null_val
     def json_type(self):
-        return self.json_type_name
+        return self._json_type_name
     def visit(self, visitor):
         visitor.visit_builtin_type(self.name, self.info, self.json_type())

@@ -843,10 +843,10 @@ class QAPISchemaArrayType(QAPISchemaType):
     def __init__(self, name, info, element_type):
         QAPISchemaType.__init__(self, name, info)
         assert isinstance(element_type, str)
-        self.element_type_name = element_type
+        self._element_type_name = element_type
         self.element_type = None
     def check(self, schema):
-        self.element_type = schema.lookup_type(self.element_type_name)
+        self.element_type = schema.lookup_type(self._element_type_name)
         assert self.element_type
     def json_type(self):
         return 'array'
@@ -861,7 +861,7 @@ class QAPISchemaObjectType(QAPISchemaType):
             assert isinstance(m, QAPISchemaObjectTypeMember)
         assert variants == None \
             or isinstance(variants, QAPISchemaObjectTypeVariants)
-        self.base_name = base
+        self._base_name = base
         self.base = None
         self.local_members = local_members
         self.variants = variants
@@ -871,8 +871,8 @@ class QAPISchemaObjectType(QAPISchemaType):
         if self.members:
             return
         self.members = False            # mark as being checked
-        if self.base_name:
-            self.base = schema.lookup_type(self.base_name)
+        if self._base_name:
+            self.base = schema.lookup_type(self._base_name)
             assert isinstance(self.base, QAPISchemaObjectType)
             assert not self.base.variants # not implemented
             self.base.check(schema)
@@ -907,12 +907,12 @@ class QAPISchemaObjectTypeMember(object):
         assert isinstance(typ, str)
         assert isinstance(optional, bool)
         self.name = name
-        self.type_name = typ
+        self._type_name = typ
         self.type = None
         self.optional = optional
     def check(self, schema, all_members, seen):
         assert self.name not in seen
-        self.type = schema.lookup_type(self.type_name)
+        self.type = schema.lookup_type(self._type_name)
         assert self.type
         all_members.append(self)
         seen[self.name] = self
@@ -923,7 +923,7 @@ class QAPISchemaObjectTypeVariants(object):
         assert tag_enum == None or isinstance(tag_enum, str)
         for v in variants:
             assert isinstance(v, QAPISchemaObjectTypeVariant)
-        self.tag_name = tag_name
+        self._tag_name = tag_name
         if tag_name:
             assert not tag_enum
             self.tag_member = None
@@ -932,8 +932,8 @@ class QAPISchemaObjectTypeVariants(object):
                                                          False)
         self.variants = variants
     def check(self, schema, members, seen):
-        if self.tag_name:
-            self.tag_member = seen[self.tag_name]
+        if self._tag_name:
+            self.tag_member = seen[self._tag_name]
         else:
             self.tag_member.check(schema, members, seen)
         assert isinstance(self.tag_member.type, QAPISchemaEnumType)
@@ -959,7 +959,7 @@ class QAPISchemaAlternateType(QAPISchemaType):
     def __init__(self, name, info, variants):
         QAPISchemaType.__init__(self, name, info)
         assert isinstance(variants, QAPISchemaObjectTypeVariants)
-        assert not variants.tag_name
+        assert not variants._tag_name
         self.variants = variants
     def check(self, schema):
         self.variants.check(schema, [], {})
@@ -973,19 +973,19 @@ class QAPISchemaCommand(QAPISchemaEntity):
         QAPISchemaEntity.__init__(self, name, info)
         assert not arg_type or isinstance(arg_type, str)
         assert not ret_type or isinstance(ret_type, str)
-        self.arg_type_name = arg_type
+        self._arg_type_name = arg_type
         self.arg_type = None
-        self.ret_type_name = ret_type
+        self._ret_type_name = ret_type
         self.ret_type = None
         self.gen = gen
         self.success_response = success_response
     def check(self, schema):
-        if self.arg_type_name:
-            self.arg_type = schema.lookup_type(self.arg_type_name)
+        if self._arg_type_name:
+            self.arg_type = schema.lookup_type(self._arg_type_name)
             assert isinstance(self.arg_type, QAPISchemaObjectType)
             assert not self.arg_type.variants # not implemented
-        if self.ret_type_name:
-            self.ret_type = schema.lookup_type(self.ret_type_name)
+        if self._ret_type_name:
+            self.ret_type = schema.lookup_type(self._ret_type_name)
             assert isinstance(self.ret_type, QAPISchemaType)
     def visit(self, visitor):
         visitor.visit_command(self.name, self.info,
@@ -996,11 +996,11 @@ class QAPISchemaEvent(QAPISchemaEntity):
     def __init__(self, name, info, arg_type):
         QAPISchemaEntity.__init__(self, name, info)
         assert not arg_type or isinstance(arg_type, str)
-        self.arg_type_name = arg_type
+        self._arg_type_name = arg_type
         self.arg_type = None
     def check(self, schema):
-        if self.arg_type_name:
-            self.arg_type = schema.lookup_type(self.arg_type_name)
+        if self._arg_type_name:
+            self.arg_type = schema.lookup_type(self._arg_type_name)
             assert isinstance(self.arg_type, QAPISchemaObjectType)
             assert not self.arg_type.variants # not implemented
     def visit(self, visitor):
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]