From 76f5670fa47d85ddc1a4a87cf94b2c8b568d3f11 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 5 Oct 2022 21:33:06 +0100 Subject: [PATCH] Fix OCaml %rename for enum items --- CHANGES.current | 3 +++ Examples/test-suite/ocaml/enum_rename_runme.ml | 10 ++++++++++ Source/Modules/ocaml.cxx | 9 +++++---- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 Examples/test-suite/ocaml/enum_rename_runme.ml diff --git a/CHANGES.current b/CHANGES.current index 5d79c9084..8a0f628b4 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-10-05: wsfulton + [OCaml] Fix %rename for enum items. Previously the rename had no effect. + 2022-10-05: olly #1465 Report errors in preprocessor expressions by default diff --git a/Examples/test-suite/ocaml/enum_rename_runme.ml b/Examples/test-suite/ocaml/enum_rename_runme.ml new file mode 100644 index 000000000..4aef31bac --- /dev/null +++ b/Examples/test-suite/ocaml/enum_rename_runme.ml @@ -0,0 +1,10 @@ +open Swig +open Enum_rename + +let mydec = C_enum `M_Dec +let _ = assert (((enum_to_int `Month mydec)) = C_int 2) +let _ = assert (((int_to_enum `Month 2)) = C_enum `M_Dec) + +let mymay = C_enum `May +let _ = assert (((enum_to_int `Month mymay)) = C_int 1) +let _ = assert (((int_to_enum `Month 1)) = C_enum `May) diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 84f16aa99..6955cdced 100644 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -1238,6 +1238,7 @@ public: int enumvalueDeclaration(Node *n) { String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); SwigType *qtype = 0; if (name_qualifier_type) { @@ -1245,8 +1246,8 @@ public: Printv(qtype, name, NIL); } - if (const_enum && qtype && name && !Getattr(seen_enumvalues, name)) { - Setattr(seen_enumvalues, name, "true"); + if (const_enum && qtype && symname && !Getattr(seen_enumvalues, symname)) { + Setattr(seen_enumvalues, symname, "true"); SetFlag(n, "feature:immutable"); Setattr(n, "feature:enumvalue", "1"); // this does not appear to be used @@ -1255,10 +1256,10 @@ public: String *evname = SwigType_manglestr(qtype); Insert(evname, 0, "SWIG_ENUM_"); - Setattr(n, "feature:enumvname", name); + Setattr(n, "feature:enumvname", symname); Setattr(n, "feature:symname", evname); Delete(evname); - Printf(f_enumtypes_value, "| `%s\n", name); + Printf(f_enumtypes_value, "| `%s\n", symname); return Language::enumvalueDeclaration(n); } else