true and false supported in constant expressions (C++ only). && || == != < > <= >= operators now return type bool (C++ only) and type int for C as per C/C++ standards.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11677 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d841f7a66c
commit
7c6aca2ebc
10 changed files with 276 additions and 15 deletions
|
|
@ -257,6 +257,7 @@ CPP_TEST_CASES += \
|
|||
overload_template \
|
||||
overload_template_fast \
|
||||
pointer_reference \
|
||||
preproc_constants \
|
||||
primitive_ref \
|
||||
private_assign \
|
||||
protected_rename \
|
||||
|
|
@ -456,6 +457,7 @@ C_TEST_CASES += \
|
|||
overload_extend \
|
||||
overload_extendc \
|
||||
preproc \
|
||||
preproc_constants_c \
|
||||
ret_by_value \
|
||||
simple_array \
|
||||
sizeof_pointer \
|
||||
|
|
|
|||
68
Examples/test-suite/csharp/preproc_constants_c_runme.cs
Normal file
68
Examples/test-suite/csharp/preproc_constants_c_runme.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using preproc_constants_cNamespace;
|
||||
|
||||
// Same as preproc_constants_c.i testcase, but bool types are int instead
|
||||
public class runme {
|
||||
static void Main() {
|
||||
assert( typeof(int) == preproc_constants_c.CONST_INT1.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.CONST_INT2.GetType() );
|
||||
assert( typeof(uint) == preproc_constants_c.CONST_UINT1.GetType() );
|
||||
assert( typeof(uint) == preproc_constants_c.CONST_UINT2.GetType() );
|
||||
assert( typeof(uint) == preproc_constants_c.CONST_UINT3.GetType() );
|
||||
assert( typeof(uint) == preproc_constants_c.CONST_UINT4.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.CONST_LONG1.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.CONST_LONG2.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.CONST_LONG3.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.CONST_LONG4.GetType() );
|
||||
assert( typeof(long) == preproc_constants_c.CONST_LLONG1.GetType() );
|
||||
assert( typeof(long) == preproc_constants_c.CONST_LLONG2.GetType() );
|
||||
assert( typeof(long) == preproc_constants_c.CONST_LLONG3.GetType() );
|
||||
assert( typeof(long) == preproc_constants_c.CONST_LLONG4.GetType() );
|
||||
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG1.GetType() );
|
||||
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG2.GetType() );
|
||||
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG3.GetType() );
|
||||
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG4.GetType() );
|
||||
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE1.GetType() );
|
||||
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE2.GetType() );
|
||||
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE3.GetType() );
|
||||
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE4.GetType() );
|
||||
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE5.GetType() );
|
||||
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE6.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.CONST_BOOL1.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.CONST_BOOL2.GetType() );
|
||||
assert( typeof(char) == preproc_constants_c.CONST_CHAR.GetType() );
|
||||
assert( typeof(string) == preproc_constants_c.CONST_STRING1.GetType() );
|
||||
assert( typeof(string) == preproc_constants_c.CONST_STRING2.GetType() );
|
||||
|
||||
assert( typeof(int) == preproc_constants_c.INT_AND_BOOL.GetType() );
|
||||
// assert( typeof(int) == preproc_constants_c.INT_AND_CHAR.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.INT_AND_INT.GetType() );
|
||||
assert( typeof(uint) == preproc_constants_c.INT_AND_UINT.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.INT_AND_LONG.GetType() );
|
||||
assert( typeof(uint) == preproc_constants_c.INT_AND_ULONG.GetType() );
|
||||
assert( typeof(long) == preproc_constants_c.INT_AND_LLONG.GetType() );
|
||||
assert( typeof(ulong) == preproc_constants_c.INT_AND_ULLONG.GetType() );
|
||||
assert( typeof(int ) == preproc_constants_c.BOOL_AND_BOOL.GetType() );
|
||||
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_MULTIPLY.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_DIVIDE.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_PLUS.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_MINUS.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_LSHIFT.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_RSHIFT.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_INEQUALITY.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_EQUALITY.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_AND.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_XOR.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_OR.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_LAND.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_LOR.GetType() );
|
||||
assert( typeof(double) == preproc_constants_c.EXPR_CONDITIONAL.GetType() );
|
||||
|
||||
}
|
||||
static void assert(bool assertion) {
|
||||
if (!assertion)
|
||||
throw new ApplicationException("test failed");
|
||||
}
|
||||
}
|
||||
67
Examples/test-suite/csharp/preproc_constants_runme.cs
Normal file
67
Examples/test-suite/csharp/preproc_constants_runme.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using preproc_constantsNamespace;
|
||||
|
||||
public class runme {
|
||||
static void Main() {
|
||||
assert( typeof(int) == preproc_constants.CONST_INT1.GetType() );
|
||||
assert( typeof(int) == preproc_constants.CONST_INT2.GetType() );
|
||||
assert( typeof(uint) == preproc_constants.CONST_UINT1.GetType() );
|
||||
assert( typeof(uint) == preproc_constants.CONST_UINT2.GetType() );
|
||||
assert( typeof(uint) == preproc_constants.CONST_UINT3.GetType() );
|
||||
assert( typeof(uint) == preproc_constants.CONST_UINT4.GetType() );
|
||||
assert( typeof(int) == preproc_constants.CONST_LONG1.GetType() );
|
||||
assert( typeof(int) == preproc_constants.CONST_LONG2.GetType() );
|
||||
assert( typeof(int) == preproc_constants.CONST_LONG3.GetType() );
|
||||
assert( typeof(int) == preproc_constants.CONST_LONG4.GetType() );
|
||||
assert( typeof(long) == preproc_constants.CONST_LLONG1.GetType() );
|
||||
assert( typeof(long) == preproc_constants.CONST_LLONG2.GetType() );
|
||||
assert( typeof(long) == preproc_constants.CONST_LLONG3.GetType() );
|
||||
assert( typeof(long) == preproc_constants.CONST_LLONG4.GetType() );
|
||||
assert( typeof(ulong) == preproc_constants.CONST_ULLONG1.GetType() );
|
||||
assert( typeof(ulong) == preproc_constants.CONST_ULLONG2.GetType() );
|
||||
assert( typeof(ulong) == preproc_constants.CONST_ULLONG3.GetType() );
|
||||
assert( typeof(ulong) == preproc_constants.CONST_ULLONG4.GetType() );
|
||||
assert( typeof(double) == preproc_constants.CONST_DOUBLE1.GetType() );
|
||||
assert( typeof(double) == preproc_constants.CONST_DOUBLE2.GetType() );
|
||||
assert( typeof(double) == preproc_constants.CONST_DOUBLE3.GetType() );
|
||||
assert( typeof(double) == preproc_constants.CONST_DOUBLE4.GetType() );
|
||||
assert( typeof(double) == preproc_constants.CONST_DOUBLE5.GetType() );
|
||||
assert( typeof(double) == preproc_constants.CONST_DOUBLE6.GetType() );
|
||||
assert( typeof(bool) == preproc_constants.CONST_BOOL1.GetType() );
|
||||
assert( typeof(bool) == preproc_constants.CONST_BOOL2.GetType() );
|
||||
assert( typeof(char) == preproc_constants.CONST_CHAR.GetType() );
|
||||
assert( typeof(string) == preproc_constants.CONST_STRING1.GetType() );
|
||||
assert( typeof(string) == preproc_constants.CONST_STRING2.GetType() );
|
||||
|
||||
assert( typeof(int) == preproc_constants.INT_AND_BOOL.GetType() );
|
||||
// assert( typeof(int) == preproc_constants.INT_AND_CHAR.GetType() );
|
||||
assert( typeof(int) == preproc_constants.INT_AND_INT.GetType() );
|
||||
assert( typeof(uint) == preproc_constants.INT_AND_UINT.GetType() );
|
||||
assert( typeof(int) == preproc_constants.INT_AND_LONG.GetType() );
|
||||
assert( typeof(uint) == preproc_constants.INT_AND_ULONG.GetType() );
|
||||
assert( typeof(long) == preproc_constants.INT_AND_LLONG.GetType() );
|
||||
assert( typeof(ulong) == preproc_constants.INT_AND_ULLONG.GetType() );
|
||||
assert( typeof(int ) == preproc_constants.BOOL_AND_BOOL.GetType() );
|
||||
|
||||
assert( typeof(int) == preproc_constants.EXPR_MULTIPLY.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_DIVIDE.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_PLUS.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_MINUS.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_LSHIFT.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_RSHIFT.GetType() );
|
||||
assert( typeof(bool) == preproc_constants.EXPR_INEQUALITY.GetType() );
|
||||
assert( typeof(bool) == preproc_constants.EXPR_EQUALITY.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_AND.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_XOR.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_OR.GetType() );
|
||||
assert( typeof(bool) == preproc_constants.EXPR_LAND.GetType() );
|
||||
assert( typeof(bool) == preproc_constants.EXPR_LOR.GetType() );
|
||||
assert( typeof(double) == preproc_constants.EXPR_CONDITIONAL.GetType() );
|
||||
|
||||
}
|
||||
static void assert(bool assertion) {
|
||||
if (!assertion)
|
||||
throw new ApplicationException("test failed");
|
||||
}
|
||||
}
|
||||
82
Examples/test-suite/preproc_constants.i
Normal file
82
Examples/test-suite/preproc_constants.i
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
%module preproc_constants
|
||||
|
||||
// Note: C types are slightly different to C++ types as (a && b) is int in C and bool in C++
|
||||
|
||||
// Simple constants
|
||||
#define CONST_INT1 10
|
||||
#define CONST_INT2 0xFF
|
||||
|
||||
#define CONST_UINT1 10u
|
||||
#define CONST_UINT2 10U
|
||||
#define CONST_UINT3 0xFFu
|
||||
#define CONST_UINT4 0xFFU
|
||||
|
||||
#define CONST_LONG1 10l
|
||||
#define CONST_LONG2 10L
|
||||
#define CONST_LONG3 0xFFl
|
||||
#define CONST_LONG4 0xFFL
|
||||
|
||||
#define CONST_LLONG1 10LL
|
||||
#define CONST_LLONG2 10ll
|
||||
#define CONST_LLONG3 0xFFll
|
||||
#define CONST_LLONG4 0xFFLL
|
||||
|
||||
#define CONST_ULLONG1 10ull
|
||||
#define CONST_ULLONG2 10ULL
|
||||
#define CONST_ULLONG3 0xFFull
|
||||
#define CONST_ULLONG4 0xFFULL
|
||||
|
||||
#define CONST_DOUBLE1 10e1
|
||||
#define CONST_DOUBLE2 10E1
|
||||
#define CONST_DOUBLE3 12.3
|
||||
#define CONST_DOUBLE4 12.
|
||||
#define CONST_DOUBLE5 12.3f
|
||||
#define CONST_DOUBLE6 12.3F
|
||||
|
||||
#define CONST_BOOL1 true
|
||||
#define CONST_BOOL2 false
|
||||
|
||||
#define CONST_CHAR 'x'
|
||||
#define CONST_STRING1 "const string"
|
||||
#define CONST_STRING2 "const" " string"
|
||||
|
||||
// Expressions - runtime tests check the type for any necessary type promotions of the expressions
|
||||
|
||||
#define INT_AND_BOOL 0xFF & true
|
||||
//#define INT_AND_CHAR 0xFF & 'A' /* FIXME compile error */
|
||||
#define INT_AND_INT 0xFF & 2
|
||||
#define INT_AND_UINT 0xFF & 2u
|
||||
#define INT_AND_LONG 0xFF & 2l
|
||||
#define INT_AND_ULONG 0xFF & 2ul
|
||||
#define INT_AND_LLONG 0xFF & 2ll
|
||||
#define INT_AND_ULLONG 0xFF & 2ull
|
||||
|
||||
#define BOOL_AND_BOOL true & true // Note integral promotion to type int
|
||||
//#define CHAR_AND_CHAR 'A' & 'B' // Note integral promotion to type int
|
||||
/* FIXME ABOVE */
|
||||
|
||||
|
||||
#define EXPR_MULTIPLY 0xFF * 2
|
||||
#define EXPR_DIVIDE 0xFF / 2
|
||||
//FIXME #define EXPR_MOD 0xFF % 2
|
||||
|
||||
#define EXPR_PLUS 0xFF + 2
|
||||
#define EXPR_MINUS 0xFF + 2
|
||||
|
||||
#define EXPR_LSHIFT 0xFF << 2
|
||||
#define EXPR_RSHIFT 0xFF >> 2
|
||||
/* FIXME
|
||||
#define EXPR_LT 0xFF < 255
|
||||
#define EXPR_GT 0xFF > 255
|
||||
#define EXPR_LTE 0xFF <= 255
|
||||
#define EXPR_LGE 0xFF >= 255
|
||||
*/
|
||||
#define EXPR_INEQUALITY 0xFF != 255
|
||||
#define EXPR_EQUALITY 0xFF == 255
|
||||
#define EXPR_AND 0xFF & 1
|
||||
#define EXPR_XOR 0xFF ^ 1
|
||||
#define EXPR_OR 0xFF | 1
|
||||
#define EXPR_LAND 0xFF && 1
|
||||
#define EXPR_LOR 0xFF || 1
|
||||
#define EXPR_CONDITIONAL true ? 2 : 2.2
|
||||
|
||||
6
Examples/test-suite/preproc_constants_c.i
Normal file
6
Examples/test-suite/preproc_constants_c.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
%module preproc_constants_c
|
||||
|
||||
%define true 1 %enddef
|
||||
%define false 0 %enddef
|
||||
|
||||
%include "preproc_constants.i"
|
||||
Loading…
Add table
Add a link
Reference in a new issue