|
| 1 | +' TEST_MODE : MULTI_MODULE_TEST |
| 2 | + |
| 3 | +'' test mapping of mangling and calling convention |
| 4 | +'' of global overloaded operators |
| 5 | +'' between c/c++ and fbc |
| 6 | + |
| 7 | +'' helper macro to track progress |
| 8 | +#define DLOG( msg ) '' print #msg |
| 9 | + |
| 10 | +extern "c++" |
| 11 | + '' getters to retrieve call information |
| 12 | + '' from the c++ side |
| 13 | + declare sub resetChecks() |
| 14 | + declare function getPtr1() as any ptr |
| 15 | + declare function getPtr2() as any ptr |
| 16 | + declare function getMsg1() as zstring ptr |
| 17 | + declare function getVal1() as long |
| 18 | + declare function getVal2() as long |
| 19 | + declare function getVal3() as long |
| 20 | +end extern |
| 21 | + |
| 22 | +'' default mangling, default calling convention |
| 23 | +type UDT_DEFAULT |
| 24 | + value as long |
| 25 | +end type |
| 26 | + |
| 27 | +'' fbc will mangle a @N suffix by default |
| 28 | +declare operator +( byref lhs as const UDT_DEFAULT, byref rhs as const UDT_DEFAULT ) as UDT_DEFAULT |
| 29 | +declare operator -( byref lhs as const UDT_DEFAULT, byref rhs as const UDT_DEFAULT ) as UDT_DEFAULT |
| 30 | +declare operator *( byref lhs as const UDT_DEFAULT, byref rhs as const UDT_DEFAULT ) as UDT_DEFAULT |
| 31 | +declare operator /( byref lhs as const UDT_DEFAULT, byref rhs as const UDT_DEFAULT ) as UDT_DEFAULT |
| 32 | +declare operator mod( byref lhs as const UDT_DEFAULT, byref rhs as const UDT_DEFAULT ) as UDT_DEFAULT |
| 33 | +declare operator shl( byref lhs as const UDT_DEFAULT, byref rhs as const UDT_DEFAULT ) as UDT_DEFAULT |
| 34 | +declare operator shr( byref lhs as const UDT_DEFAULT, byref rhs as const UDT_DEFAULT ) as UDT_DEFAULT |
| 35 | +declare operator and( byref lhs as const UDT_DEFAULT, byref rhs as const UDT_DEFAULT ) as UDT_DEFAULT |
| 36 | +declare operator or ( byref lhs as const UDT_DEFAULT, byref rhs as const UDT_DEFAULT ) as UDT_DEFAULT |
| 37 | +declare operator xor( byref lhs as const UDT_DEFAULT, byref rhs as const UDT_DEFAULT ) as UDT_DEFAULT |
| 38 | + |
| 39 | + |
| 40 | +'' extern "c", default calling convention |
| 41 | +type UDT_C_DEFAULT |
| 42 | + value as long |
| 43 | +end type |
| 44 | + |
| 45 | +extern "c" |
| 46 | + declare operator +( byref lhs as const UDT_C_DEFAULT, byref rhs as const UDT_C_DEFAULT ) as UDT_C_DEFAULT |
| 47 | + declare operator -( byref lhs as const UDT_C_DEFAULT, byref rhs as const UDT_C_DEFAULT ) as UDT_C_DEFAULT |
| 48 | + declare operator *( byref lhs as const UDT_C_DEFAULT, byref rhs as const UDT_C_DEFAULT ) as UDT_C_DEFAULT |
| 49 | + declare operator /( byref lhs as const UDT_C_DEFAULT, byref rhs as const UDT_C_DEFAULT ) as UDT_C_DEFAULT |
| 50 | + declare operator mod( byref lhs as const UDT_C_DEFAULT, byref rhs as const UDT_C_DEFAULT ) as UDT_C_DEFAULT |
| 51 | + declare operator shl( byref lhs as const UDT_C_DEFAULT, byref rhs as const UDT_C_DEFAULT ) as UDT_C_DEFAULT |
| 52 | + declare operator shr( byref lhs as const UDT_C_DEFAULT, byref rhs as const UDT_C_DEFAULT ) as UDT_C_DEFAULT |
| 53 | + declare operator and( byref lhs as const UDT_C_DEFAULT, byref rhs as const UDT_C_DEFAULT ) as UDT_C_DEFAULT |
| 54 | + declare operator or ( byref lhs as const UDT_C_DEFAULT, byref rhs as const UDT_C_DEFAULT ) as UDT_C_DEFAULT |
| 55 | + declare operator xor( byref lhs as const UDT_C_DEFAULT, byref rhs as const UDT_C_DEFAULT ) as UDT_C_DEFAULT |
| 56 | +end extern |
| 57 | + |
| 58 | + |
| 59 | +'' extern "c++", default calling convention |
| 60 | +type UDT_CPP_DEFAULT |
| 61 | + value as long |
| 62 | +end type |
| 63 | + |
| 64 | +extern "c++" |
| 65 | + declare operator +( byref lhs as const UDT_CPP_DEFAULT, byref rhs as const UDT_CPP_DEFAULT ) as UDT_CPP_DEFAULT |
| 66 | + declare operator -( byref lhs as const UDT_CPP_DEFAULT, byref rhs as const UDT_CPP_DEFAULT ) as UDT_CPP_DEFAULT |
| 67 | + declare operator *( byref lhs as const UDT_CPP_DEFAULT, byref rhs as const UDT_CPP_DEFAULT ) as UDT_CPP_DEFAULT |
| 68 | + declare operator /( byref lhs as const UDT_CPP_DEFAULT, byref rhs as const UDT_CPP_DEFAULT ) as UDT_CPP_DEFAULT |
| 69 | + declare operator mod( byref lhs as const UDT_CPP_DEFAULT, byref rhs as const UDT_CPP_DEFAULT ) as UDT_CPP_DEFAULT |
| 70 | + declare operator shl( byref lhs as const UDT_CPP_DEFAULT, byref rhs as const UDT_CPP_DEFAULT ) as UDT_CPP_DEFAULT |
| 71 | + declare operator shr( byref lhs as const UDT_CPP_DEFAULT, byref rhs as const UDT_CPP_DEFAULT ) as UDT_CPP_DEFAULT |
| 72 | + declare operator and( byref lhs as const UDT_CPP_DEFAULT, byref rhs as const UDT_CPP_DEFAULT ) as UDT_CPP_DEFAULT |
| 73 | + declare operator or ( byref lhs as const UDT_CPP_DEFAULT, byref rhs as const UDT_CPP_DEFAULT ) as UDT_CPP_DEFAULT |
| 74 | + declare operator xor( byref lhs as const UDT_CPP_DEFAULT, byref rhs as const UDT_CPP_DEFAULT ) as UDT_CPP_DEFAULT |
| 75 | +end extern |
| 76 | + |
| 77 | +#macro chkbop( op, t, m1, arg1, arg2, result ) |
| 78 | + DLOG( n ) |
| 79 | + resetChecks() |
| 80 | + scope |
| 81 | + dim a as t = ( arg1 ) |
| 82 | + dim b as t = ( arg2 ) |
| 83 | + dim r as t |
| 84 | + r = a op b |
| 85 | + assert( m1 = *getMsg1() ) |
| 86 | + assert( @a = getPtr1() ) |
| 87 | + assert( @b = getPtr2() ) |
| 88 | + assert( r.value = result ) |
| 89 | + assert( r.value = getVal3() ) |
| 90 | + end scope |
| 91 | +#endmacro |
| 92 | + |
| 93 | +chkbop( +, UDT_DEFAULT, "UDT_DEFAULT operator+", 5, 7, 12 ) |
| 94 | +chkbop( -, UDT_DEFAULT, "UDT_DEFAULT operator-", 5, 7, -2 ) |
| 95 | +chkbop( *, UDT_DEFAULT, "UDT_DEFAULT operator*", 5, 7, 35 ) |
| 96 | +chkbop( /, UDT_DEFAULT, "UDT_DEFAULT operator/", 35, 7, 5 ) |
| 97 | +chkbop( mod, UDT_DEFAULT, "UDT_DEFAULT operator%", 16, 5, 1 ) |
| 98 | +chkbop( shl, UDT_DEFAULT, "UDT_DEFAULT operator<<", 16, 2, 64 ) |
| 99 | +chkbop( shr, UDT_DEFAULT, "UDT_DEFAULT operator>>", 16, 2, 4 ) |
| 100 | +chkbop( and, UDT_DEFAULT, "UDT_DEFAULT operator&", &b1100, &b1010, &b1000 ) |
| 101 | +chkbop( or , UDT_DEFAULT, "UDT_DEFAULT operator|", &b1100, &b1010, &b1110 ) |
| 102 | +chkbop( xor, UDT_DEFAULT, "UDT_DEFAULT operator^", &b1100, &b1010, &b0110 ) |
| 103 | + |
| 104 | +chkbop( +, UDT_C_DEFAULT, "UDT_C_DEFAULT operator+", 5, 7, 12 ) |
| 105 | +chkbop( -, UDT_C_DEFAULT, "UDT_C_DEFAULT operator-", 5, 7, -2 ) |
| 106 | +chkbop( *, UDT_C_DEFAULT, "UDT_C_DEFAULT operator*", 5, 7, 35 ) |
| 107 | +chkbop( /, UDT_C_DEFAULT, "UDT_C_DEFAULT operator/", 35, 7, 5 ) |
| 108 | +chkbop( mod, UDT_C_DEFAULT, "UDT_C_DEFAULT operator%", 16, 5, 1 ) |
| 109 | +chkbop( shl, UDT_C_DEFAULT, "UDT_C_DEFAULT operator<<", 16, 2, 64 ) |
| 110 | +chkbop( shr, UDT_C_DEFAULT, "UDT_C_DEFAULT operator>>", 16, 2, 4 ) |
| 111 | +chkbop( and, UDT_C_DEFAULT, "UDT_C_DEFAULT operator&", &b1100, &b1010, &b1000 ) |
| 112 | +chkbop( or , UDT_C_DEFAULT, "UDT_C_DEFAULT operator|", &b1100, &b1010, &b1110 ) |
| 113 | +chkbop( xor, UDT_C_DEFAULT, "UDT_C_DEFAULT operator^", &b1100, &b1010, &b0110 ) |
| 114 | + |
| 115 | +chkbop( +, UDT_CPP_DEFAULT, "UDT_CPP_DEFAULT operator+", 5, 7, 12 ) |
| 116 | +chkbop( -, UDT_CPP_DEFAULT, "UDT_CPP_DEFAULT operator-", 5, 7, -2 ) |
| 117 | +chkbop( *, UDT_CPP_DEFAULT, "UDT_CPP_DEFAULT operator*", 5, 7, 35 ) |
| 118 | +chkbop( /, UDT_CPP_DEFAULT, "UDT_CPP_DEFAULT operator/", 35, 7, 5 ) |
| 119 | +chkbop( mod, UDT_CPP_DEFAULT, "UDT_CPP_DEFAULT operator%", 16, 5, 1 ) |
| 120 | +chkbop( shl, UDT_CPP_DEFAULT, "UDT_CPP_DEFAULT operator<<", 16, 2, 64 ) |
| 121 | +chkbop( shr, UDT_CPP_DEFAULT, "UDT_CPP_DEFAULT operator>>", 16, 2, 4 ) |
| 122 | +chkbop( and, UDT_CPP_DEFAULT, "UDT_CPP_DEFAULT operator&", &b1100, &b1010, &b1000 ) |
| 123 | +chkbop( or , UDT_CPP_DEFAULT, "UDT_CPP_DEFAULT operator|", &b1100, &b1010, &b1110 ) |
| 124 | +chkbop( xor, UDT_CPP_DEFAULT, "UDT_CPP_DEFAULT operator^", &b1100, &b1010, &b0110 ) |
0 commit comments