Ignore:
Timestamp:
Sep 12, 2017, 4:08:01 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
c935c3a
Parents:
21a1efb (diff), a46478a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/user_literals.c

    r21a1efb rb2e2e34  
    1010// Created On       : Wed Sep  6 21:40:50 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Sep  6 23:19:08 2017
    13 // Update Count     : 36
     12// Last Modified On : Sat Sep  9 08:31:32 2017
     13// Update Count     : 48
    1414//
    1515
    1616#include <fstream>
     17#include <wchar.h>
     18#include <uchar.h>
     19
     20int ?`s( int s ) { sout | "secs" | s | endl; return s; }
     21int ?`m( int m ) { sout | "mins" | m | endl; return m * 60; }
     22int ?`h( int h ) { sout | "hours" | h | endl; return h * 3600; }
     23int ?`_A_( int x ) { sout | "_A_" | x | endl; return x; }
     24int ?`__thingy_( int x ) { sout | "_thingy_" | x | endl; return x; }
     25
     26int ?`s( const char * s ) { sout | "secs" | s | endl; return 0; }
     27int ?`m( const char16_t * m ) { sout | "mins" | m | endl; return 0;}
     28int ?`h( const char32_t * h ) { sout | "hours" | h | endl; return 0; }
     29int ?`_A_( const wchar_t * str ) { sout | "_A_" | str | endl; return 0; }
     30int ?`__thingy_( const char * str ) { sout | "_thingy_" | str | endl; return 0; }
     31
    1732
    1833struct Weight {
    19     double stones;
     34        double stones;
    2035};
    21 void ?{}( Weight & w ) { w.stones = 0; }        // constructors
     36void ?{}( Weight & w ) { w.stones = 0; }                                // operations
    2237void ?{}( Weight & w, double w ) { w.stones = w; }
    23 
    2438Weight ?+?( Weight l, Weight r ) { return (Weight){ l.stones + r.stones }; }
    2539ofstream * ?|?( ofstream * os, Weight w ) { return os | w.stones; }
    2640
    27 Weight ?`st( double w ) { return (Weight){ w }; } // user literals
     41Weight ?`st( double w ) { return (Weight){ w }; }               // backquote for user literals
    2842Weight ?`lb( double w ) { return (Weight){ w / 14.0 }; }
    2943Weight ?`kg( double w ) { return (Weight) { w * 0.1575}; }
    3044
     45
    3146int main() {
    32     Weight w, hw = { 14 };
    33     w = 11`st + 1`lb;
    34     sout | w | endl;
    35     w = 70.3`kg;
    36     sout | w | endl;
    37     w = 155`lb;
    38     sout | w | endl;
    39     w = 0x9b`lb;                // hexadecimal weight
    40     sout | w | endl;
    41     w = 0233`lb;                // octal weight
    42     sout | w | endl;
    43     w = 5`st + 8`kg + 25`lb + hw;
    44     sout | w | endl;
    45 }
     47        Weight w, hw = { 14 };                                                          // 14 stone
     48        w = 11`st + 1`lb;
     49        sout | w | endl;
     50        w = 70.3`kg;
     51        sout | w | endl;
     52        w = 155`lb;
     53        sout | w | endl;
     54        w = 0x_9b_u`lb;                                                                         // hexadecimal unsigned weight (155)
     55        sout | w | endl;
     56        w = 0_233`lb;                                                                           // octal weight (155)
     57        sout | w | endl;
     58        w = 5`st + 8`kg + 25`lb + hw;
     59        sout | w | endl;
    4660
     61//      0`secs;
     62        1`s;
     63        23`s;
     64        23u`m;
     65        23l`h;
     66        23_ul`_A_;
     67        1_234_LL`__thingy_;
    4768
     69        0xff_ffl;
     70        0xff_ff`s;
     71        0xff_ffu`m;
     72        0xff_ffl`h;
     73        0xff_fful`_A_;
     74        0xff_ffLL`__thingy_;
     75
     76        '\n'`s;
     77        L'\n'`h;
     78        u'\n'`m;
     79        L_'\n'`_A_;
     80        U_'\n'`__thingy_;
     81
     82        "abc"`s;
     83        u"abc"`m;
     84        U_"abc"`h;
     85        L"abc"`_A_;
     86        u8_"abc"`__thingy_;
     87} // main
    4888
    4989// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.