From 40d0e13db68ecfa382144da10b281906af570e4f Mon Sep 17 00:00:00 2001 From: Rob Hoes Date: Wed, 6 Nov 2013 17:49:48 +0000 Subject: [PATCH] libxl: ocaml: generate string_of_* functions for enums Signed-off-by: Rob Hoes Acked-by: David Scott Acked-by:Ian Campbell --- 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 bdae88670f..0f73e26eae 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 += "" -- 2.30.2