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

[Xen-changelog] [xen-unstable] libxl: IDL: add helper to generate references to Aggregate type members.



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1310646156 -3600
# Node ID 215c3f510040fc882aa9494881d22371e5e530c2
# Parent  d52b62dc910f2c616d12dde0e783d0a5ce1dfa02
libxl: IDL: add helper to generate references to Aggregate type members.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
---


diff -r d52b62dc910f -r 215c3f510040 tools/libxl/gentypes.py
--- a/tools/libxl/gentypes.py   Thu Jul 14 13:22:36 2011 +0100
+++ b/tools/libxl/gentypes.py   Thu Jul 14 13:22:36 2011 +0100
@@ -76,27 +76,21 @@
     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 d52b62dc910f -r 215c3f510040 tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Thu Jul 14 13:22:36 2011 +0100
+++ b/tools/libxl/libxltypes.py Thu Jul 14 13:22:36 2011 +0100
@@ -147,6 +147,24 @@
                 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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.