source: tests/userLiterals.cfa@ 4be0117

Last change on this file since 4be0117 was 641707d, checked in by Andrew Beach <ajbeach@…>, 8 months ago

More fixing of warnings. Including another error that slipped through to the build and the rest of the 'easy' fixes on tests not in a directory.

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[73abe95]1//
[f47ba55]2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
[73abe95]6//
[c9f4cf8]7// userLiterals.cfa --
[73abe95]8//
[f47ba55]9// Author : Peter A. Buhr
10// Created On : Wed Sep 6 21:40:50 2017
11// Last Modified By : Peter A. Buhr
[e326ebca]12// Last Modified On : Wed Feb 19 07:48:45 2020
13// Update Count : 74
[73abe95]14//
[f47ba55]15
[73abe95]16#include <fstream.hfa>
[eb68ebb]17#include <uchar.h>
18
[641707d]19// Warning triggered by the standard header, we can't fix that.
20#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-Wtype-limits"
22#include <wchar.h>
23#pragma GCC diagnostic pop
24
[200fcb3]25int ?`s( int s ) { sout | "secs" | s; return s; }
26int ?`m( int m ) { sout | "mins" | m; return m * 60; }
27int ?`h( int h ) { sout | "hours" | h; return h * 3600; }
28int ?`_A_( int x ) { sout | "_A_" | x; return x; }
29int ?`__thingy_( int x ) { sout | "_thingy_" | x; return x; }
[eb68ebb]30
[c9f4cf8]31int ?`s( const char * s ) { sout | "s" | s; return 0; }
32int ?`m( const char16_t * m ) { sout | "m" | m; return 0;}
33int ?`h( const char32_t * h ) { sout | "h" | h; return 0; }
[200fcb3]34int ?`_A_( const wchar_t * str ) { sout | "_A_" | str; return 0; }
35int ?`__thingy_( const char * str ) { sout | "_thingy_" | str; return 0; }
[eb68ebb]36
[f47ba55]37
[ea46db7]38struct Weight { double stones; };
39void ?{}( Weight & w ) { w.stones = 0; }
[f47ba55]40void ?{}( Weight & w, double w ) { w.stones = w; }
[ea46db7]41Weight ?+?( Weight l, Weight r ) {
42 return (Weight){ l.stones + r.stones };
43}
[c9f4cf8]44ofstream & ?|?( ofstream & os, Weight w ) { return os | wd(1,1, w.stones); }
45void ?|?( ofstream & os, Weight w ) { (ofstream)(os | w); ends( os ); }
[f47ba55]46
[cd218e8]47Weight ?`st( double w ) { return (Weight){ w }; } // backquote for user literals
[f47ba55]48Weight ?`lb( double w ) { return (Weight){ w / 14.0 }; }
[ea46db7]49Weight ?`kg( double w ) { return (Weight) { w * 0.16 }; }
[eb68ebb]50
[f47ba55]51int main() {
[ea46db7]52 Weight w, heavy = { 20 }; // 20 stone
[cd218e8]53 w = 155`lb;
[200fcb3]54 sout | w;
[ea46db7]55 w = 0b_1111`st;
[200fcb3]56 sout | w;
[cd218e8]57 w = 0_233`lb; // octal weight (155)
[200fcb3]58 sout | w;
[ea46db7]59 w = 0x_9b_u`kg;
[200fcb3]60 sout | w;
[ea46db7]61 w = 70.3`kg;
[200fcb3]62 sout | w;
[ea46db7]63 w = 11`st + 1`lb;
[200fcb3]64 sout | w;
[ea46db7]65 w = 5`st + 8`kg + 25`lb + heavy;
[200fcb3]66 sout | w;
[f47ba55]67
[c9f4cf8]68 0`s;
[eb68ebb]69 1`s;
70 23`s;
71 23u`m;
72 23l`h;
73 23_ul`_A_;
74 1_234_LL`__thingy_;
75
76 0xff_ffl;
77 0xff_ff`s;
78 0xff_ffu`m;
79 0xff_ffl`h;
80 0xff_fful`_A_;
81 0xff_ffLL`__thingy_;
82
[cd218e8]83 '\n'`s;
84 L'\n'`h;
85 u'\n'`m;
86 L_'\n'`_A_;
87 U_'\n'`__thingy_;
[f47ba55]88
[eb68ebb]89 "abc"`s;
[e326ebca]90 // FIX ME: requires char16_t, char32_t, and wchar_t be unique types
91 // u"abc"`m;
92 // U_"abc"`h;
93 // L"abc"`_A_;
[eb68ebb]94 u8_"abc"`__thingy_;
95} // main
[f47ba55]96
97// Local Variables: //
98// tab-width: 4 //
[c9f4cf8]99// compile-command: "cfa userLiterals.cfa" //
[f47ba55]100// End: //
Note: See TracBrowser for help on using the repository browser.