Fix OCaml %rename for enum items

This commit is contained in:
William S Fulton 2022-10-05 21:33:06 +01:00
commit 76f5670fa4
3 changed files with 18 additions and 4 deletions

View file

@ -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

View file

@ -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)

View file

@ -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