Improve handling and documentation of missing enum base type information.

Closes #2828
This commit is contained in:
William S Fulton 2024-03-11 08:12:50 +00:00
parent 4c33bcaab9
commit bc0b8b558d
3 changed files with 15 additions and 2 deletions

View File

@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.3.0 (in progress)
===========================
2024-03-11: wsfulton
[C#] Improve handling and documentation of missing enum base type information.
2024-03-07: wsfulton
[Ocaml] Fix SWIGTYPE MOVE 'in' typemap to fix compilation error.

View File

@ -3265,6 +3265,14 @@ public enum SmallNumbers : byte {
</pre>
</div>
<p>
If SWIG cannot find appropriate type information for the C++ enum base, then a type wrapper class (something like
SWIGTYPE_p_xxxx) is generated for the C# enum base.
This will not compile in C#, as a C# integral base is required.
To fix this, make sure the C++ enum base type information is parsed by SWIG; this is usually a typedef to an integral type.
Note that SWIG uses the cstype typemap to lookup the C# type for any given C++ type.
Using the csbase typemap, as described above, overrides the default cstype for looking up the C# integral base type.
</p>
</body>
</html>

View File

@ -1196,11 +1196,13 @@ public:
bool purebase_replace = GetFlag(attributes, "tmap:csbase:replace") ? true : false;
Delete(attributes);
const String *baseclass = NULL;
String *baseclass = NULL;
if (!purebase_replace) {
String *underlying_enum_type = Getattr(n, "enumbase");
if (underlying_enum_type) {
baseclass = typemapLookup(n, "cstype", underlying_enum_type, WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF);
const String *typemap_baseclass = typemapLookup(n, "cstype", underlying_enum_type, WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF);
baseclass = Copy(typemap_baseclass);
substituteClassname(underlying_enum_type, baseclass);
}
}