Changeset d5b2ac8


Ignore:
Timestamp:
Dec 26, 2018, 7:21:08 AM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
0689cd9, 25cdca5
Parents:
f498c51
Message:

formatting

Location:
tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/genericUnion.cfa

    rf498c51 rd5b2ac8  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// genericUnion.cfa --
     8//
     9// Author           : Peter A. Buhr
     10// Created On       : Tue Dec 25 14:42:46 2018
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Dec 25 14:46:33 2018
     13// Update Count     : 2
     14//
     15
    116#include <limits.hfa>
    217
     
    419union ByteView {
    520        T val;
    6         char bytes[(sizeof(int))]; // want to change to sizeof(T)
     21        char bytes[(sizeof(int))];                                                      // want to change to sizeof(T)
    722};
    823
    924forall(otype T)
    1025void print(ByteView(T) x) {
    11         for (int i = 0; i < sizeof(int); i++) { // want to change to sizeof(T)
     26        for (int i = 0; i < sizeof(int); i++) {                         // want to change to sizeof(T)
    1227                printf("%02x", x.bytes[i] & 0xff);
    1328        }
     
    2944        f(i, -1);
    3045}
     46
     47// Local Variables: //
     48// tab-width: 4 //
     49// compile-command: "cfa genericUnion.cfa" //
     50// End: //
  • tests/withStatement.cfa

    rf498c51 rd5b2ac8  
    99// Author           : Rob Schluntz
    1010// Created On       : Mon Dec 04 17:41:45 2017
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Dec 04 17:45:07 2017
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Dec 24 19:08:18 2018
     13// Update Count     : 5
    1414//
    1515
     16#include <fstream.hfa>
     17
    1618struct S {
    17   int i;
    18   // dynamically allocated member ensures ctor/dtors are called correctly on temporaries
    19   int * ptr;
     19        int i;
     20        // dynamically allocated member ensures ctor/dtors are called correctly on temporaries
     21        int * ptr;
    2022};
    2123
    2224// with clause on reference parameter
    23 void ?{}(S & this, int n) with(this) {
    24   i = n;
    25   ptr = (int *)malloc(sizeof(int));
     25void ?{}( S & this, int n ) with( this ) {
     26        i = n;
     27        ptr = (int *)malloc( sizeof(int) );
    2628}
    2729
    28 void ?{}(S & this) {
    29   this{ 0 };
     30void ?{}( S & this ) {
     31        this{ 0 };
    3032}
    3133
    32 void ?{}(S & this, S other) {
    33   this{ other.i };
     34void ?{}( S & this, S other ) {
     35        this{ other.i };
    3436}
    3537
    36 S ?=?(S & this, S other) with(this) {
    37   i = other.i;
    38   *ptr = *other.ptr;
    39   return this;
     38S ?=?( S & this, S other ) with( this ) {
     39        i = other.i;
     40        *ptr = *other.ptr;
     41        return this;
    4042}
    4143
    42 void ^?{}(S & this) with(this) {
    43   free(ptr);
     44void ^?{}( S & this ) with( this ) {
     45        free( ptr );
    4446}
    4547
    4648struct S2 {
    47   S s;
     49        S s;
    4850};
    4951
    50 void ?{}(S2 & this, int n) {
    51   (this.s){ n };
     52void ?{}( S2 & this, int n ) {
     53        (this.s){ n };
    5254}
    5355
    54 forall(otype T)
     56forall( otype T )
    5557struct Box {
    56   T x;
     58        T x;
    5759};
    5860
    59 forall(otype T)
    60 void ?{}(Box(T) & this) with(this) { // with clause in polymorphic function
    61   x{};
     61forall( otype T )
     62void ?{}( Box(T) & this ) with( this ) { // with clause in polymorphic function
     63        x{};
    6264}
    6365
    64 void print(int i) { printf("%d", i); }
     66void print( int i ) { sout | i; }
    6567
    66 forall(otype T | { void print(T); })
    67 void foo(T t) {
    68   Box(T) b = { t };
    69   with(b) {  // with statement in polymorphic function
    70     print(x);
    71     printf("\n");
    72   }
     68forall( otype T | { void print( T ); })
     69void foo( T t ) {
     70        Box( T ) b = { t };
     71        with( b ) {  // with statement in polymorphic function
     72                print( x );
     73        }
    7374}
    7475
    7576// ensure with-statement temporary generation works correctly
    7677S mk() {
    77   printf("called mk\n");
    78   return (S) { 444 };
     78        sout | "called mk";
     79        return (S){ 444 };
    7980}
    8081
    8182// ensure with-statement temporary generation with reference-returning functions works correctly
    8283S & ref() {
    83   static S var = { 123456789 };
    84   return var;
     84        static S var = { 123456789 };
     85        return var;
    8586}
    8687
    8788int main() {
    88   S2 s2 = { 12345 };
    89   with (s2) {
    90     with(s) { // with s2.s
    91       printf("%d %d %d\n", i, s.i, s2.s.i);
    92       foo(i);  // s.i
    93       with(mk()) {
    94         printf("%d %d %d\n", i, i, i);
    95         with(ref()) {
    96           printf("%d %d %d\n", i, i, i);
    97         } // with ref()
    98         with(ref()) {
    99           printf("%d %d %d\n", i, i, i);
    100         } // with ref()
    101       } // with mk()
    102     } // with s
    103   } // with s2
     89        S2 s2 = { 12345 };
     90        with ( s2) {
     91                with( s ) { // with s2.s
     92                        sout | i | s.i | s2.s.i;
     93                        foo( i );  // s.i
     94                        with( mk()) {
     95                                sout | i | i | i;
     96                                with( ref()) {
     97                                        sout | i | i | i;
     98                                } // with ref()
     99                                with( ref()) {
     100                                        sout | i | i | i;
     101                                } // with ref()
     102                        } // with mk()
     103                } // with s
     104        } // with s2
    104105}
    105106
Note: See TracChangeset for help on using the changeset viewer.