# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1308845927 -3600
# Node ID 34279f2359cbaaef7c16287e023cae1b023f02d3
# Parent 4186a6ca6799797e24fafa5fe39e55b474b86bf0
libxl: IDL: refactor code to massage a type into a function argument
Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
diff -r 4186a6ca6799 -r 34279f2359cb tools/libxl/gentypes.py
--- a/tools/libxl/gentypes.py Thu Jun 23 17:18:37 2011 +0100
+++ b/tools/libxl/gentypes.py Thu Jun 23 17:18:47 2011 +0100
@@ -84,11 +84,6 @@ def libxl_C_type_destroy(ty, v, indent =
else:
deref = v + "."
- if ty.passby == libxltypes.PASS_BY_REFERENCE and parent is not None:
- makeref = "&"
- else:
- makeref = ""
-
s = ""
if isinstance(ty, libxltypes.KeyedUnion):
if parent is None:
@@ -107,7 +102,7 @@ def libxl_C_type_destroy(ty, v, indent =
s += libxl_C_type_destroy(f.type, deref + f.name, "", deref)
else:
if ty.destructor_fn is not None:
- s += "%s(%s);\n" % (ty.destructor_fn, makeref + v)
+ s += "%s(%s);\n" % (ty.destructor_fn, ty.pass_arg(v, parent is
None))
if s != "":
s = indent + s
diff -r 4186a6ca6799 -r 34279f2359cb tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Thu Jun 23 17:18:37 2011 +0100
+++ b/tools/libxl/libxltypes.py Thu Jun 23 17:18:47 2011 +0100
@@ -50,6 +50,21 @@ class Type(object):
else:
return "%s %s" % (self.typename, n)
+ def pass_arg(self, n, isref=None, passby=None):
+ if passby is None: passby = self.passby
+ if isref is None: isref = self.passby == PASS_BY_REFERENCE
+
+ if passby == PASS_BY_REFERENCE:
+ if isref:
+ return "%s" % (n)
+ else:
+ return "&%s" % (n)
+ else:
+ if isref:
+ return "*%s" % (n)
+ else:
+ return "%s" % (n)
+
class Builtin(Type):
"""Builtin type"""
def __init__(self, typename, **kwargs):
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|