WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 06 of 10] libxl: IDL: add helper to generate referenc

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 06 of 10] libxl: IDL: add helper to generate references to Aggregate type members
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Thu, 23 Jun 2011 17:20:57 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Thu, 23 Jun 2011 09:28:36 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1308846051@xxxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1308846051@xxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1308845933 -3600
# Node ID 273be439b67afbeefdf00e68efb5b09412a25c82
# Parent  2b91546fb417458d3fa29da85aed44bddb91854f
libxl: IDL: add helper to generate references to Aggregate type members.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 2b91546fb417 -r 273be439b67a tools/libxl/gentypes.py
--- a/tools/libxl/gentypes.py   Thu Jun 23 17:18:48 2011 +0100
+++ b/tools/libxl/gentypes.py   Thu Jun 23 17:18:53 2011 +0100
@@ -76,27 +76,21 @@ def libxl_C_type_define(ty, indent = "")
     return s.replace("\n", "\n%s" % indent)
 
 def libxl_C_type_destroy(ty, v, indent = "    ", parent = None):
-    if parent is None:
-        deref = v + "->"
-    else:
-        deref = v + "."
         
     s = ""
     if isinstance(ty, libxltypes.KeyedUnion):
         if parent is None:
             raise Exception("KeyedUnion type must have a parent")
         for f in ty.fields:
+            (nparent,fexpr) = ty.member(v, f, parent is None)
             keyvar_expr = f.keyvar_expr % (parent + ty.keyvar_name)
             s += "if (" + keyvar_expr + ") {\n"
-            s += libxl_C_type_destroy(f.type, deref + f.name, indent + "    ", 
deref)
+            s += libxl_C_type_destroy(f.type, fexpr, indent + "    ", nparent)
             s += "}\n"
     elif isinstance(ty, libxltypes.Struct) and (parent is None or 
ty.destructor_fn is None):
         for f in [f for f in ty.fields if not f.const]:
-
-            if f.name is None: # Anonymous struct
-                s += libxl_C_type_destroy(f.type, deref, "", deref)
-            else:
-                s += libxl_C_type_destroy(f.type, deref + f.name, "", deref)
+            (nparent,fexpr) = ty.member(v, f, parent is None)
+            s += libxl_C_type_destroy(f.type, fexpr, "", nparent)
     else:
         if ty.destructor_fn is not None:
             s += "%s(%s);\n" % (ty.destructor_fn, ty.pass_arg(v, parent is 
None))
diff -r 2b91546fb417 -r 273be439b67a tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Thu Jun 23 17:18:48 2011 +0100
+++ b/tools/libxl/libxltypes.py Thu Jun 23 17:18:53 2011 +0100
@@ -147,6 +147,24 @@ class Aggregate(Type):
                 n,t,const,comment = f
             self.fields.append(Field(t,n,const=const,comment=comment))
 
+    # Returns a tuple (stem, field-expr)
+    #
+    # field-expr is a C expression for a field "f" within the struct
+    # "v".
+    #
+    # stem is the stem common to both "f" and any other sibbling field
+    # within the "v".
+    def member(self, v, f, isref):
+        if isref:
+            deref = v + "->"
+        else:
+            deref = v + "."
+        
+        if f.name is None: # Anonymous
+            return (deref, deref)
+        else:
+            return (deref, deref + f.name)
+
 class Struct(Aggregate):
     def __init__(self, name, fields, **kwargs):
         kwargs.setdefault('passby', PASS_BY_REFERENCE)

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel