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

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



Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx>

---
New in v3:
* New patch, which allowed us to remove the hand-written string_of_error
  function.
---
 tools/ocaml/libs/xl/genwrap.py |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/ocaml/libs/xl/genwrap.py b/tools/ocaml/libs/xl/genwrap.py
index 2a90681..d8d675c 100644
--- a/tools/ocaml/libs/xl/genwrap.py
+++ b/tools/ocaml/libs/xl/genwrap.py
@@ -152,6 +152,15 @@ 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
+            n = len(ty.rawname) + 1
+            for v in ty.values:
+                s += '\t| %s -> "%s"\n' % (v.rawname, v.rawname[n:])
+
     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®.