Fix wrapping of C++ enum boolean values
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12028 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
227f2e2e0a
commit
8a169eb0cb
4 changed files with 26 additions and 4 deletions
|
|
@ -1,6 +1,10 @@
|
|||
Version 2.0.0 (in progress)
|
||||
============================
|
||||
|
||||
2010-05-14: wsfulton
|
||||
Fix wrapping of C++ enum boolean values reported by Torsten Landschoff:
|
||||
typedef enum { PLAY = true, STOP = false } play_state;
|
||||
|
||||
2010-05-14: olly
|
||||
[PHP] Fix wrapping of global variables which was producing
|
||||
uncompilable code in some cases.
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ struct StructWithEnums {
|
|||
enum SOME_ENUM& enum_test8() { return some_enum; };
|
||||
};
|
||||
|
||||
|
||||
struct Foo
|
||||
{
|
||||
enum {Hi, Hello } hola;
|
||||
|
|
@ -41,3 +40,15 @@ extern "C"
|
|||
}
|
||||
|
||||
%}
|
||||
|
||||
// Using true and false in enums is legal in C++. Quoting the standard:
|
||||
// [dcl.enum]
|
||||
// ... The constant-expression shall be of integral or enumeration type.
|
||||
// [basic.fundamental]
|
||||
// ... Types bool, char, wchar_t, and the signed and unsigned integer
|
||||
// types are collectively called integral types.
|
||||
// So this shouldn't lead to a warning, at least in C++ mode.
|
||||
%inline %{
|
||||
typedef enum { PLAY = true, STOP = false } play_state;
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -5601,7 +5601,7 @@ edecl : ID {
|
|||
Setattr($$,"type",type);
|
||||
Delete(type);
|
||||
} else {
|
||||
SwigType *type = NewSwigType(T_INT);
|
||||
SwigType *type = NewSwigType($3.type == T_BOOL ? T_BOOL : T_INT);
|
||||
Setattr($$,"value",$1);
|
||||
Setattr($$,"type",type);
|
||||
Delete(type);
|
||||
|
|
@ -5617,8 +5617,8 @@ etype : expr {
|
|||
($$.type != T_LONG) && ($$.type != T_ULONG) &&
|
||||
($$.type != T_SHORT) && ($$.type != T_USHORT) &&
|
||||
($$.type != T_SCHAR) && ($$.type != T_UCHAR) &&
|
||||
($$.type != T_CHAR)) {
|
||||
Swig_error(cparse_file,cparse_line,"Type error. Expecting an int\n");
|
||||
($$.type != T_CHAR) && ($$.type != T_BOOL)) {
|
||||
Swig_error(cparse_file,cparse_line,"Type error. Expecting an integral type\n");
|
||||
}
|
||||
if ($$.type == T_CHAR) $$.type = T_INT;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1282,6 +1282,13 @@ public:
|
|||
// Note that this is used in enumValue() amongst other places
|
||||
Setattr(n, "value", tmpValue);
|
||||
|
||||
// Deal with enum values that are bools
|
||||
if (SwigType_type(Getattr(n, "type")) == T_BOOL) {
|
||||
String *boolValue = NewStringf("%s ? 1 : 0", Getattr(n, "enumvalue"));
|
||||
Setattr(n, "enumvalue", boolValue);
|
||||
Delete(boolValue);
|
||||
}
|
||||
|
||||
{
|
||||
EnumFeature enum_feature = decodeEnumFeature(parent);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue