ADT
        ast-experimental
      
      
        
          | Last change
 on this file since c63f470 was             fd54fef, checked in by Michael Brooks <mlbrooks@…>, 5 years ago | 
        
          | 
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.
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1008 bytes | 
      
      
| Line |  | 
|---|
| 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 |  | 
|---|
| 16 | #include <limits.hfa> | 
|---|
| 17 |  | 
|---|
| 18 | forall(T) | 
|---|
| 19 | union ByteView { | 
|---|
| 20 | T val; | 
|---|
| 21 | char bytes[(sizeof(int))];                                                      // want to change to sizeof(T) | 
|---|
| 22 | }; | 
|---|
| 23 |  | 
|---|
| 24 | forall(T) | 
|---|
| 25 | void print(ByteView(T) x) { | 
|---|
| 26 | for (int i = 0; i < sizeof(int); i++) {                         // want to change to sizeof(T) | 
|---|
| 27 | printf("%02x", x.bytes[i] & 0xff); | 
|---|
| 28 | } | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | forall(T) | 
|---|
| 32 | void f(ByteView(T) x, T val) { | 
|---|
| 33 | print(x); | 
|---|
| 34 | printf(" "); | 
|---|
| 35 | x.val = val; | 
|---|
| 36 | print(x); | 
|---|
| 37 | printf("\n"); | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | int main() { | 
|---|
| 41 | ByteView(unsigned) u = { 0 }; | 
|---|
| 42 | ByteView(int) i = { 0 }; | 
|---|
| 43 | f(u, MAX); | 
|---|
| 44 | f(i, -1); | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | // Local Variables: // | 
|---|
| 48 | // tab-width: 4 // | 
|---|
| 49 | // compile-command: "cfa genericUnion.cfa" // | 
|---|
| 50 | // End: // | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.