From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 6 of 8] libxl: add KeyedUnion type
Date: Tue, 03 Aug 2010 12:00:21 +0100 [thread overview]
Message-ID: <5d51a404379e3e91c08c.1280833221@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1280833215@localhost.localdomain>
# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1280829586 -3600
# Node ID 5d51a404379e3e91c08c07c8292abefa1440a655
# Parent c87dd259a8ed069d8786aadf9e1f6e555aa6778e
libxl: add KeyedUnion type
Use this to express the construct where a union is differentiated on a
variable in the containing struct.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
diff -r c87dd259a8ed -r 5d51a404379e tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Tue Aug 03 10:59:46 2010 +0100
+++ b/tools/libxl/libxltypes.py Tue Aug 03 10:59:46 2010 +0100
@@ -35,12 +35,13 @@ class BitField(Type):
class Field(Type):
"""An element of an Aggregate type"""
- def __init__(self, type, name, const = False, comment = None):
+ def __init__(self, type, name, const = False, comment = None, keyvar_expr = None):
Type.__init__(self,type.typename)
self.type = type
self.name = name
self.const = const
self.comment = comment
+ self.keyvar_expr = keyvar_expr
class Aggregate(Type):
"""A type containing a collection of other types"""
@@ -79,6 +80,19 @@ class KeyValueList(Type):
Type.__init__(self, "char **", namespace = None)
+class KeyedUnion(Aggregate):
+ """A union which is keyed of another variable"""
+ def __init__(self, name, keyvar_name, fields, comment = None):
+ self.keyvar = keyvar_name
+ Aggregate.__init__(self, "union", name, [], comment)
+ for f in fields:
+ # (name, keyvar_expr, type)
+
+ # keyvar_expr must contain exactly one %s which will be replaced with the keyvar_name
+
+ n, kve, ty = f
+ self.fields.append(Field(ty, n, False, None, kve))
+
class Reference(Type):
"""A reference to another type"""
def __init__(self, ty):
@@ -199,26 +213,26 @@ libxl_domain_build_info = Struct("domain
("disable_migrate", bool),
("kernel", libxl_file_reference),
("hvm", integer),
- ("u", Union(None,
- [("hvm", Struct(None,
- [("pae", bool),
- ("apic", bool),
- ("acpi", bool),
- ("nx", bool),
- ("viridian", bool),
- ("timeoffset", string),
- ("hpet", bool),
- ("vpt_align", bool),
- ("timer_mode", integer),
- ])),
- ("pv", Struct(None,
- [("slack_memkb", uint32),
- ("bootloader", string, True),
- ("bootloader_args", string, True),
- ("cmdline", string),
- ("ramdisk", libxl_file_reference),
- ("features", string, True),
- ])),
+ ("u", KeyedUnion(None, "hvm",
+ [("hvm", "%s", Struct(None,
+ [("pae", bool),
+ ("apic", bool),
+ ("acpi", bool),
+ ("nx", bool),
+ ("viridian", bool),
+ ("timeoffset", string),
+ ("hpet", bool),
+ ("vpt_align", bool),
+ ("timer_mode", integer),
+ ])),
+ ("pv", "!%s", Struct(None,
+ [("slack_memkb", uint32),
+ ("bootloader", string, True),
+ ("bootloader_args", string, True),
+ ("cmdline", string),
+ ("ramdisk", libxl_file_reference),
+ ("features", string, True),
+ ])),
])),
],
comment =
next prev parent reply other threads:[~2010-08-03 11:00 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-03 11:00 [PATCH 0 of 8] [RFC] libxl: autogenerate type definitions and destructor functions Ian Campbell
2010-08-03 11:00 ` [PATCH 1 of 8] libxl: add a specific UUID type Ian Campbell
2010-08-03 11:00 ` [PATCH 2 of 8] libxl: add a specific MAC address type Ian Campbell
2010-08-03 11:00 ` [PATCH 3 of 8] libxl: move type definitions into _libxl_types.h Ian Campbell
2010-08-03 11:00 ` [PATCH 4 of 8] libxl: tweak formatting/whitespace of _libxl_types.h Ian Campbell
2010-08-03 11:00 ` [PATCH 5 of 8] libxl: autogenerate _libxl_types.h Ian Campbell
2010-08-03 12:13 ` Gianni Tedesco
2010-08-03 12:29 ` Ian Campbell
2010-08-03 12:36 ` Gianni Tedesco
2010-08-03 13:30 ` Ian Campbell
2010-08-03 11:00 ` Ian Campbell [this message]
2010-08-03 11:00 ` [PATCH 7 of 8] libxl: generate destructors for each libxl defined type Ian Campbell
2010-08-03 12:07 ` Gianni Tedesco
2010-08-03 12:24 ` Ian Campbell
2010-08-03 12:34 ` Gianni Tedesco
2010-08-03 11:00 ` [PATCH 8 of 8] xl: free the libxl types contained in struct domain_config Ian Campbell
2010-08-04 10:25 ` [PATCH 0 of 8] [RFC] libxl: autogenerate type definitions and destructor functions Gianni Tedesco
2010-08-04 17:16 ` Stefano Stabellini
2010-08-10 14:41 ` Ian Jackson
2010-08-10 14:48 ` Ian Campbell
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=5d51a404379e3e91c08c.1280833221@localhost.localdomain \
--to=ian.campbell@citrix.com \
--cc=xen-devel@lists.xensource.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).