libxl: Make IDL KeyedUnion keyvar an idl.Field
authorIan Campbell <ian.campbell@citrix.com>
Thu, 1 Mar 2012 12:26:15 +0000 (12:26 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 1 Mar 2012 12:26:15 +0000 (12:26 +0000)
This is more logical than having keyvar_name and keyvar_type members.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/gentest.py
tools/libxl/gentypes.py
tools/libxl/idl.py
tools/libxl/idl.txt

index 5de7a070c72f452808cd45e3dfe7e3947e4b2e67..04248ee8b1547e2c6178851dd3bd5d0555038d71 100644 (file)
@@ -31,7 +31,7 @@ def gen_rand_init(ty, v, indent = "    ", parent = None):
     elif isinstance(ty, idl.KeyedUnion):
         if parent is None:
             raise Exception("KeyedUnion type must have a parent")
-        s += "switch (%s) {\n" % (parent + ty.keyvar_name)
+        s += "switch (%s) {\n" % (parent + ty.keyvar.name)
         for f in ty.fields:
             (nparent,fexpr) = ty.member(v, f, parent is None)
             s += "case %s:\n" % f.enumname
index ae4a6b6a7a81c3ef2bc1b0c863f28cba55b060a4..4a2d0cecca14e69e656c15a20ddee91a764a175d 100644 (file)
@@ -56,7 +56,7 @@ def libxl_C_type_dispose(ty, v, indent = "    ", parent = None):
     if isinstance(ty, idl.KeyedUnion):
         if parent is None:
             raise Exception("KeyedUnion type must have a parent")
-        s += "switch (%s) {\n" % (parent + ty.keyvar_name)
+        s += "switch (%s) {\n" % (parent + ty.keyvar.name)
         for f in ty.fields:
             (nparent,fexpr) = ty.member(v, f, parent is None)
             s += "case %s:\n" % f.enumname
@@ -86,7 +86,7 @@ def libxl_C_type_gen_json(ty, v, indent = "    ", parent = None):
     elif isinstance(ty, idl.KeyedUnion):
         if parent is None:
             raise Exception("KeyedUnion type must have a parent")
-        s += "switch (%s) {\n" % (parent + ty.keyvar_name)
+        s += "switch (%s) {\n" % (parent + ty.keyvar.name)
         for f in ty.fields:
             (nparent,fexpr) = ty.member(v, f, parent is None)
             s += "case %s:\n" % f.enumname
index 880b7ca71d88bca1bba00cc5aced7e71c936d470..b31956d92ee7f17078c3a561a53c3c9d73ceacee 100644 (file)
@@ -206,8 +206,9 @@ class KeyedUnion(Aggregate):
         if not isinstance(keyvar_type, Enumeration):
             raise ValueError
 
-        self.keyvar_name = keyvar_name
-        self.keyvar_type = keyvar_type
+        kv_kwargs = dict([(x.lstrip('keyvar_'),y) for (x,y) in kwargs.items() if x.startswith('keyvar_')])
+        
+        self.keyvar = Field(keyvar_type, keyvar_name, **kv_kwargs)
 
         for f in fields:
             # (name, enum, type)
index ddcd0b005016b16cc07e4a5a21aec29188689284..183e4fb4cab27494fdb255d933b1bdd24985a22d 100644 (file)
@@ -128,10 +128,9 @@ idl.KeyedUnion
  where the currently valid member of the union can be determined based
  upon another member in the containing type.
 
- The KeyedUnion.keyvar_name must contain the name of the member of the
+ The KeyedUnion.keyvar contains an idl.type the member of the
  containing type which determines the valid member of the union. The
- member referenced by KeyedUnion.keyvar_name has type
- KeyedUnion.keyvar_type which must be an instance of the Enumeration type.
+ must be an instance of the Enumeration type.
 
 Standard Types
 --------------