libxl: ocaml: avoid reserved words in type and field names.
authorRob Hoes <rob.hoes@citrix.com>
Wed, 6 Nov 2013 17:49:40 +0000 (17:49 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 11 Nov 2013 15:38:16 +0000 (15:38 +0000)
Do this by adding a "xl_" prefix to all names that are OCaml keywords.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/ocaml/libs/xl/genwrap.py

index 1b68b6b297560e2dc975bc1132cd7fc6153c95c2..bdac6e95994eca4edb372304f16512c66c1aa71f 100644 (file)
@@ -70,8 +70,21 @@ def ocaml_type_of(ty):
     else:
         return ty.rawname
 
+ocaml_keywords = ['and', 'as', 'assert', 'begin', 'end', 'class', 'constraint',
+    'do', 'done', 'downto', 'else', 'if', 'end', 'exception', 'external', 'false',
+    'for', 'fun', 'function', 'functor', 'if', 'in', 'include', 'inherit',
+    'initializer', 'lazy', 'let', 'match', 'method', 'module', 'mutable', 'new',
+    'object', 'of', 'open', 'or', 'private', 'rec', 'sig', 'struct', 'then', 'to',
+    'true', 'try', 'type', 'val', 'virtual', 'when', 'while', 'with']
+
+def munge_name(name):
+    if name in ocaml_keywords:
+        return "xl_" + name
+    else:
+        return name
+
 def ocaml_instance_of(type, name):
-    return "%s : %s" % (name, ocaml_type_of(type))
+    return "%s : %s" % (munge_name(name), ocaml_type_of(type))
 
 def gen_ocaml_ml(ty, interface, indent=""):