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

[Xen-devel] [PATCH v4 10/27] libxl: ocaml: generate string_of_* functions for enums



Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx>
Acked-by: David Scott <dave.scott@xxxxxxxxxxxxx>

---
v4: Now using v.valuename, as suggested by Ian.
---
 tools/ocaml/libs/xl/genwrap.py |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/ocaml/libs/xl/genwrap.py b/tools/ocaml/libs/xl/genwrap.py
index bdae886..0f73e26 100644
--- a/tools/ocaml/libs/xl/genwrap.py
+++ b/tools/ocaml/libs/xl/genwrap.py
@@ -162,6 +162,14 @@ def gen_ocaml_ml(ty, interface, indent=""):
         s += "type %s = \n" % ty.rawname
         for v in ty.values:
             s += "\t | %s\n" % v.rawname
+
+        if interface:
+            s += "\nval string_of_%s : %s -> string\n" % (ty.rawname, 
ty.rawname)
+        else:
+            s += "\nlet string_of_%s = function\n" % ty.rawname
+            for v in ty.values:
+                s += '\t| %s -> "%s"\n' % (v.rawname, v.valuename)
+
     elif isinstance(ty, idl.Aggregate):
         s += ""
         
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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