Last change
on this file since 8705a11 was 7959e56, checked in by Michael Brooks <mlbrooks@…>, 8 months ago |
Eliminate libcfa-build warnings of missing int-to-pointer casts.
Replace a zero_t variable use with literal 0 when it's an argument to an intrinsic and we're generating final C code. Partially revert e0330d2cd1a. Such intrinsics are initialization/assignment of pointers; using the variable implies a missing cast, while using literal 0 needs no cast.
CodeGenerator.hpp
CodeGenerator.cpp
Put attibute unused on all zero_t/one_t object decls. It is needed on those whose uses are rewritten by the rule above.
Generate.cpp
|
-
Property mode
set to
100644
|
File size:
1.7 KB
|
Rev | Line | |
---|
[fd0a1799] | 1 | #include <fstream.hfa>
|
---|
| 2 |
|
---|
| 3 | void foo(zero_t)
|
---|
| 4 | {
|
---|
| 5 | sout | "It's a Zero!";
|
---|
| 6 | }
|
---|
| 7 |
|
---|
| 8 | void foo(one_t)
|
---|
| 9 | {
|
---|
| 10 | sout | "It's a One!";
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | void foo(int)
|
---|
| 14 | {
|
---|
| 15 | sout | "It's a Number!";
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | void testOverloads()
|
---|
| 19 | {
|
---|
| 20 | foo(0);
|
---|
| 21 | foo(1);
|
---|
| 22 | foo(2);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | struct S { int i, j; };
|
---|
[6e6e372] | 26 | void ?{}( S & s, zero_t ) { s.[i,j] = 0; } // constructors
|
---|
[fd0a1799] | 27 | void ?{}( S & s, one_t ) { s.[i,j] = 1; }
|
---|
[6e6e372] | 28 | S ?=?( S & dst, zero_t ) { dst.[i,j] = 0; return dst; } // assignment
|
---|
[fd0a1799] | 29 | S ?=?( S & dst, one_t ) { dst.[i,j] = 1; return dst; }
|
---|
[6e6e372] | 30 | S ?+=?( S & s, one_t ) { s.[i,j] += 1; return s; } // increment/decrement each field
|
---|
[fd0a1799] | 31 | S ?-=?( S & s, one_t ) { s.[i,j] -= 1; return s; }
|
---|
| 32 | int ?!=?( S s, zero_t ) { return s.i != 0 && s.j != 0; } // comparison
|
---|
| 33 | void testInitAssignQueryIncrement() {
|
---|
[6e6e372] | 34 | S s = 0; // initialization
|
---|
| 35 | s = 0; // assignments
|
---|
| 36 | s = 1;
|
---|
| 37 | if ( s ) ++s; // special, unary ++/-\,- come from +=/-=
|
---|
| 38 | sout | s.i | s.j;
|
---|
[fd0a1799] | 39 | }
|
---|
| 40 |
|
---|
[7959e56] | 41 | void testCompats() {
|
---|
| 42 | zero_t zero = 0;
|
---|
| 43 | one_t one = 1;
|
---|
| 44 |
|
---|
| 45 | int x = 0;
|
---|
| 46 | int xx = zero;
|
---|
| 47 |
|
---|
| 48 | sout | x | xx;
|
---|
| 49 |
|
---|
| 50 | x = xx = 42;
|
---|
| 51 | sout | x | xx;
|
---|
| 52 |
|
---|
| 53 | x = 0;
|
---|
| 54 | xx = zero;
|
---|
| 55 | sout | x | xx;
|
---|
| 56 |
|
---|
| 57 | int y = 1;
|
---|
| 58 | int yy = one;
|
---|
| 59 |
|
---|
| 60 | sout | y | yy;
|
---|
| 61 |
|
---|
| 62 | y = yy = 42;
|
---|
| 63 | sout | y | yy;
|
---|
| 64 |
|
---|
| 65 | y = 1;
|
---|
| 66 | yy = one;
|
---|
| 67 | sout | y | yy;
|
---|
| 68 |
|
---|
| 69 | void z_helper( int * p, zero_t z ) {
|
---|
| 70 | p = z; // expect z not reported unused here; expect no missing cast from -Wint-conversion
|
---|
| 71 | sout | "zero" | (bool) (p == 0);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | void z_call( int * p, zero_t z ) {
|
---|
| 75 | z_helper(p, z);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void o_helper( int * p, one_t o ) {
|
---|
| 79 | #ifdef ERR1
|
---|
| 80 | p = o;
|
---|
| 81 | #else
|
---|
| 82 | (void) x; (void) o;
|
---|
| 83 | #endif
|
---|
| 84 | sout | "one" | (bool) (p == 0);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | void o_call( int * p, one_t o ) {
|
---|
| 88 | o_helper(p, o);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | z_call( &x, 0 );
|
---|
| 92 | z_call( &x, zero );
|
---|
| 93 |
|
---|
| 94 | o_call( &x, 1 );
|
---|
| 95 | o_call( &x, one );
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[fd0a1799] | 98 | int main() {
|
---|
| 99 | testOverloads();
|
---|
| 100 | testInitAssignQueryIncrement();
|
---|
[7959e56] | 101 | testCompats();
|
---|
[fd0a1799] | 102 | return 0;
|
---|
| 103 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.