From: Rob Hoes Subject: [PATCH v3-RESEND 10/28] libxl: ocaml: generate string_of_* functions for enums Date: Mon, 21 Oct 2013 14:32:27 +0100 Message-ID: <1382362365-6645-11-git-send-email-rob.hoes@citrix.com> References: <1382362365-6645-1-git-send-email-rob.hoes@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1382362365-6645-1-git-send-email-rob.hoes@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: ian.jackson@eu.citrix.com, ian.campbell@citrix.com, Rob Hoes List-Id: xen-devel@lists.xenproject.org Signed-off-by: Rob Hoes --- 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