[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/15] qapi: Emit structs used as variants in topolog
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 11/15] qapi: Emit structs used as variants in topological order |
Date: |
Fri, 19 Feb 2016 13:18:02 +0100 |
From: Eric Blake <address@hidden>
Right now, we emit the branches of union types as a boxed pointer,
and it suffices to have a forward declaration of the type. However,
a future patch will swap things to directly use the branch type,
instead of hiding it behind a pointer. For this to work, the
compiler needs the full definition of the type, not just a forward
declaration, prior to the union that is including the branch type.
This patch just adds topological sorting to hoist all types
mentioned in a branch of a union to be fully declared before the
union itself. The sort is always possible, because we do not
allow circular union types that include themselves as a direct
branch (it is, however, still possible to include a branch type
that itself has a pointer to the union, for a type that can
indirectly recursively nest itself - that remains safe, because
that the member of the branch type will remain a pointer, and the
QMP representation of such a type adds another {} for each recurring
layer of the union type).
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
scripts/qapi-types.py | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 83f230a..6ea0ae6 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -2,7 +2,7 @@
# QAPI types generator
#
# Copyright IBM, Corp. 2011
-# Copyright (c) 2013-2015 Red Hat Inc.
+# Copyright (c) 2013-2016 Red Hat Inc.
#
# Authors:
# Anthony Liguori <address@hidden>
@@ -14,6 +14,11 @@
from qapi import *
+# variants must be emitted before their container; track what has already
+# been output
+objects_seen = set()
+
+
def gen_fwd_object_or_array(name):
return mcgen('''
@@ -49,11 +54,23 @@ def gen_struct_fields(members):
def gen_object(name, base, members, variants):
- ret = mcgen('''
+ if name in objects_seen:
+ return ''
+ objects_seen.add(name)
+
+ ret = ''
+ if variants:
+ for v in variants.variants:
+ if (isinstance(v.type, QAPISchemaObjectType) and
+ not v.type.is_implicit()):
+ ret += gen_object(v.type.name, v.type.base,
+ v.type.local_members, v.type.variants)
+
+ ret += mcgen('''
struct %(c_name)s {
''',
- c_name=c_name(name))
+ c_name=c_name(name))
if base:
ret += mcgen('''
--
2.4.3
- [Qemu-devel] [PULL 12/15] qapi-visit: Use common idiom in gen_visit_fields_decl(), (continued)
- [Qemu-devel] [PULL 12/15] qapi-visit: Use common idiom in gen_visit_fields_decl(), Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 02/15] qapi: Simplify excess input reporting in input visitors, Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 01/15] qapi-visit: Honor prefix of discriminator enum, Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 04/15] qapi: Forbid 'any' inside an alternate, Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 09/15] qapi-visit: Less indirection in visit_type_Foo_fields(), Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 08/15] qapi-visit: Unify struct and union visit, Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 06/15] qapi-visit: Simplify how we visit common union members, Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 10/15] qapi: Adjust layout of FooList types, Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 13/15] qapi: Don't box struct branch of alternate, Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 03/15] qapi: Forbid empty unions and useless alternates, Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 11/15] qapi: Emit structs used as variants in topological order,
Markus Armbruster <=
- [Qemu-devel] [PULL 07/15] qapi: Visit variants in visit_type_FOO_fields(), Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 05/15] qapi: Add tests of complex objects within alternate, Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 15/15] qapi: Change visit_start_implicit_struct to visit_start_alternate, Markus Armbruster, 2016/02/19
- [Qemu-devel] [PULL 14/15] qapi: Don't box branches of flat unions, Markus Armbruster, 2016/02/19
- Re: [Qemu-devel] [PULL 00/15] QAPI patches for 2016-02-19, Peter Maydell, 2016/02/19