Changeset fd54fef for tests/forall.cfa


Ignore:
Timestamp:
Jan 19, 2021, 8:44:29 PM (4 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
dafbde8
Parents:
2f47ea4
Message:

Converting the project to use the new syntax for otype, dtype and ttytpe.

Changed prelude (gen), libcfa and test suite to use it. Added a simple deprecation rule of the old syntax to the parser; we might wish to support both syntaxes "officially," like with an extra CLI switch, but this measure should serve as a simple reminder for our team to try the new syntax.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/forall.cfa

    r2f47ea4 rfd54fef  
    1515
    1616void g1() {
    17         forall( otype T ) T f( T ) {};
     17        forall( T ) T f( T ) {};
    1818        void f( int ) {};
    1919        void h( void (*p)(void) ) {};
     
    3232
    3333void g2() {
    34         forall( otype T ) void f( T, T ) {}
    35         forall( otype T, otype U ) void f( T, U ) {}
     34        forall( T ) void f( T, T ) {}
     35        forall( T, U ) void f( T, U ) {}
    3636
    3737        int x;
     
    4545}
    4646
    47 typedef forall ( otype T ) int (* f)( int );
    48 
    49 forall( otype T )
     47typedef forall ( T ) int (* f)( int );
     48
     49forall( T )
    5050void swap( T left, T right ) {
    5151        T temp = left;
     
    5454}
    5555
    56 trait sumable( otype T ) {
     56trait sumable( T ) {
    5757        void ?{}( T &, zero_t );                                                        // 0 literal constructor
    5858        T ?+?( T, T );                                                                          // assortment of additions
     
    6262}; // sumable
    6363
    64 forall( otype T | sumable( T ) )                                                // use trait
     64forall( T | sumable( T ) )                                              // use trait
    6565T sum( size_t size, T a[] ) {
    6666        T total = 0;                                                                            // initialize by 0 constructor
     
    7070} // sum
    7171
    72 forall( otype T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )
     72forall( T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )
    7373T twice( T t ) {
    7474        return t + t;
    7575}
    7676
    77 forall( otype T | { int ?<?(T, T); } )
     77forall( T | { int ?<?(T, T); } )
    7878T min( T t1, T t2 ) {
    7979        return t1 < t2 ? t1 : t2;
     
    9191
    9292// Multiple forall
    93 forall( otype T ) forall( otype S ) struct { int i; };
    94 forall( otype T ) struct { int i; } forall( otype S );
    95 struct { int i; } forall( otype T ) forall( otype S );
    96 forall( otype W ) struct { int i; } forall( otype T ) forall( otype S );
     93forall( T ) forall( S ) struct { int i; };
     94forall( T ) struct { int i; } forall( S );
     95struct { int i; } forall( T ) forall( S );
     96forall( W ) struct { int i; } forall( T ) forall( S );
    9797
    9898// Distribution
    9999struct P { int i; };
    100 forall( otype T ) struct Q { T i; };
    101 forall( otype T ) struct { int i; };
     100forall( T ) struct Q { T i; };
     101forall( T ) struct { int i; };
    102102struct KK { int i; };
    103103inline static {
    104104        void RT1() {}
    105105}
    106 forall( otype T ) {
     106forall( T ) {
    107107        T RT2( T ) {
    108108                typedef int TD1;
    109109                struct S1 { T t; };
    110110        }
    111         forall( otype X ) {
     111        forall( X ) {
    112112                typedef int TD2;
    113113                struct S2 {};
     
    117117        }
    118118        extern "C" {
    119                 forall( otype W ) {
     119                forall( W ) {
    120120                        W RT3( W ) {}
    121121                        struct S3 {};
     
    123123        }
    124124        void RT4() {
    125                 forall( otype W ) struct S4 {};
     125                forall( W ) struct S4 {};
    126126                typedef int TD3;
    127127        }
     
    147147
    148148static inline {
    149         forall( otype T ) {
     149        forall( T ) {
    150150                int RT6( T p );
    151151        }
    152         forall( otype T, otype U ) {
     152        forall( T, U ) {
    153153                int RT7( T, U );
    154154        }
    155155}
    156 static forall( otype T ) {
     156static forall( T ) {
    157157        int RT8( T );
    158158}
    159 forall( otype T ) inline static {
     159forall( T ) inline static {
    160160        int RT9( T ) { T t; return 3; }
    161161}
    162162
    163 forall( otype T | { T ?+?( T, T ); } ) {
    164         forall( otype S | { T ?+?( T, S ); } ) {
    165                 forall( otype W ) T bar( T t, S s ) { return t + s; }
    166                 forall( otype W | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; }
     163forall( T | { T ?+?( T, T ); } ) {
     164        forall( S | { T ?+?( T, S ); } ) {
     165                forall( W ) T bar( T t, S s ) { return t + s; }
     166                forall( W | { W ?+?( T, W ); } ) W baz( T t, S s, W w ) { return t + s + w; }
    167167                struct W { T t; } (int,int) ww;
    168168                struct P pp;
     
    170170}
    171171
    172 forall( otype T | { T ?+?( T, T ); } ) forall( otype S | { T ?+?( T, S ); } )
     172forall( T | { T ?+?( T, T ); } ) forall( S | { T ?+?( T, S ); } )
    173173struct XW { T t; };
    174174XW(int,int) xww;
    175175
    176 forall( otype T ) struct S { T t; } (int) x, y, z;
    177 forall( otype T ) struct { T t; } (int) a, b, c;
    178 
    179 forall( otype T ) static forall( otype S ) {
    180     forall( otype X ) struct U {
     176forall( T ) struct S { T t; } (int) x, y, z;
     177forall( T ) struct { T t; } (int) a, b, c;
     178
     179forall( T ) static forall( S ) {
     180    forall( X ) struct U {
    181181                T x;
    182182    };
    183183}
    184184
    185 forall( otype T ) {
     185forall( T ) {
    186186        extern "C" {
    187187                struct SS { T t; };
Note: See TracChangeset for help on using the changeset viewer.