- Timestamp:
- Jul 6, 2018, 3:47:41 PM (6 years ago)
- 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, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 250e29a
- Parents:
- 1d386a7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/prelude/prelude-gen.cc
r1d386a7 r1629965 121 121 if(mask & (1 << i)) { 122 122 result += name; 123 } else { 124 result.append(name.size(), ' '); 123 125 } 124 126 i++; … … 148 150 cout << endl; 149 151 150 cout << "void ?{}( zero_t & );" << endl;151 cout << "void ?{}( one_t & );" << endl;152 cout << "void ?{}( zero_t &, zero_t );" << endl;153 cout << "void ?{}( one_t &, one_t );" << endl;154 cout << "void ^?{}( zero_t & );" << endl;155 cout << "void ^?{}( one_t & );" << endl;156 cout << "zero_t ?=?( zero_t &, zero_t );" << endl;157 cout << "one_t ?=?( one_t &, one_t );" << endl;158 152 cout << "signed int ?==?( zero_t, zero_t ), ?!=?( zero_t, zero_t );" << endl; 159 153 cout << "signed int ?==?( one_t, one_t ), ?!=?( one_t, one_t );" << endl; 160 161 154 cout << "signed int ?==?( _Bool, _Bool ), ?!=?( _Bool, _Bool );" << endl; 162 cout << "void ?{}( _Bool & );" << endl;163 cout << "void ?{}( _Bool &, _Bool );" << endl;164 cout << "void ^?{}( _Bool & );" << endl;165 cout << "_Bool ?=?( _Bool &, _Bool ), ?=?( volatile _Bool &, _Bool );" << endl;166 155 cout << "signed int !?( _Bool );" << endl; 167 168 cout << "void ^?{}( char & );" << endl;169 cout << "void ^?{}( char unsigned & );" << endl;170 cout << "void ^?{}( char signed & );" << endl;171 cout << "void ?{}( char &, char );" << endl;172 cout << "void ?{}( unsigned char &, unsigned char );" << endl;173 cout << "void ?{}( char signed &, char signed );" << endl;174 cout << "void ?{}( char & );" << endl;175 cout << "void ?{}( unsigned char & );" << endl;176 cout << "void ?{}( char signed & );" << endl;177 cout << "char ?=?( char &, char ), ?=?( volatile char &, char );" << endl;178 cout << "char signed ?=?( char signed &, char signed ), ?=?( volatile char signed &, char signed );" << endl;179 cout << "char unsigned ?=?( char unsigned &, char unsigned ), ?=?( volatile char unsigned &, char unsigned );" << endl;180 181 156 182 157 for (auto op : arithmeticOperators) { … … 213 188 cout << "// Arithmetic Constructors //" << endl; 214 189 cout << "/////////////////////////////" << endl; 190 auto otype = [](const std::string & type, bool do_volatile = false) { 191 cout << "void \t?{} ( " << type << " & );" << endl; 192 cout << "void \t?{} ( " << type << " &, " << type << " );" << endl; 193 cout << type << " \t?=? ( " << type << " &, " << type << " )"; 194 if( do_volatile ) { 195 cout << ", \t?=?( volatile " << type << " &, " << type << " )"; 196 } 197 cout << ";" << endl; 198 cout << "void \t^?{}( " << type << " & );" << endl; 199 }; 200 201 otype("zero_t"); 202 otype("one_t"); 203 otype("_Bool", true); 204 otype("char", true); 205 otype("signed char", true); 206 otype("unsigned char", true); 207 215 208 for (auto type : basicTypes) { 216 209 cout << "void ?{}(" << type.name << " &);" << endl; … … 227 220 cout << "forall(ftype FT) void ?{}( FT * volatile &, FT * );" << endl; 228 221 229 // generate qualifiers for first and second parameters of copy constructors 222 // generate qualifiers 223 vector<string> qualifiersSingle; 230 224 vector<pair<const string, const string>> qualifiersPair; 231 225 const unsigned int NQ = 2; 232 226 for(unsigned int lhs = 0; lhs < (1<<NQ); lhs++) { 227 // for parameter of default constructor and destructor 228 qualifiersSingle.push_back(mask2string(lhs, make_array("const "s, "volatile "s))); 229 230 // for first and second parameters of copy constructors 233 231 for(unsigned int rhs = 0; rhs < (1<<NQ); rhs++) { 234 232 if((lhs & rhs) == rhs) { … … 241 239 } 242 240 243 for (auto type : { " DT", "void" }) {244 for (auto q : qualifiersPair) {245 cout << "forall(dtype DT) void ?{}(" << q.first << type << " *&, " << q.second << "DT *);" << endl;246 }247 }248 249 250 // generate qualifiers for parameter of default constructor and destructor251 vector<string> qualifiersSingle;252 for (unsigned int lhs = 0; lhs < (1<<NQ); lhs++) {253 qualifiersSingle.push_back(mask2string(lhs, make_array("const "s, "volatile "s)));254 }255 256 for (auto type : { "DT", "void" }) {257 for (auto q : qualifiersSingle) {258 cout << "forall(dtype DT) void ?{}(" << q << type << " *&);" << endl; 259 cout << "forall(dtype DT) void ^?{}(" << q << type << " *&);" << endl;260 }261 }262 cout << endl;263 264 cout << "forall(dtype DT) void ?{}( DT * &, zero_t );" << endl;265 cout << "forall(dtype DT) void ?{}( DT * volatile &, zero_t );" << endl;266 cout << "forall(dtype DT) void ?{}( const DT * &, zero_t );" << endl;267 cout << "forall(dtype DT) void ?{}( volatile DT * &, zero_t );" << endl; 268 cout << "forall(dtype DT) void ?{}( volatile DT * volatile &, zero_t );" <<endl;269 cout << "forall(dtype DT) void ?{}( const volatile DT * &, zero_t );" << endl; 241 for (auto type : { " DT", "void" }) { 242 for (auto cvq : qualifiersPair) { 243 for (auto is_vol : { " ", "volatile" }) { 244 cout << "forall(dtype DT) void ?{}(" << cvq.first << type << " * " << is_vol << " &, " << cvq.second << "DT *);" << endl; 245 } 246 } 247 for (auto cvq : qualifiersSingle) { 248 for (auto is_vol : { " ", "volatile" }) { 249 cout << "forall(dtype DT) void ?{}(" << cvq << type << " * " << is_vol << " &);" << endl; 250 } 251 for (auto is_vol : { " ", "volatile" }) { 252 cout << "forall(dtype DT) void ^?{}(" << cvq << type << " * " << is_vol << " &);" << endl; 253 } 254 } 255 } 256 257 { 258 auto type = " DT"; 259 for (auto is_vol : { " ", "volatile" }) { 260 for (auto cvq : qualifiersSingle) { 261 cout << "forall(dtype DT) void ?{}( " << cvq << type << " * " << is_vol << " &, zero_t);" << endl; 262 } 263 } 264 } 265 266 cout << endl; 267 270 268 cout << "forall(ftype FT) void ?{}( FT * &, zero_t ); " << endl; 269 cout << "forall(ftype FT) FT * ?=?( FT * &, zero_t );" << endl; 270 cout << "forall(ftype FT) FT * ?=?( FT * volatile &, zero_t );" << endl; 271 271 cout << "forall( ftype FT ) void ?{}( FT * & );" << endl; 272 272 cout << "forall( ftype FT ) void ^?{}( FT * & );" << endl; … … 285 285 286 286 287 cout << "forall( dtype DT ) void * ?=?( void * &, DT * );" << endl;288 cout << "forall( dtype DT ) void * ?=?( void * volatile &, DT * );" << endl;289 cout << "forall( dtype DT ) const void * ?=?( const void * &, DT * );" << endl;290 cout << "forall( dtype DT ) const void * ?=?( const void * volatile &, DT * );" << endl;291 cout << "forall( dtype DT ) const void * ?=?( const void * &, const DT * );" << endl;292 cout << "forall( dtype DT ) const void * ?=?( const void * volatile &, const DT * );" << endl;293 cout << "forall( dtype DT ) volatile void * ?=?( volatile void * &, DT * );" << endl;294 cout << "forall( dtype DT ) volatile void * ?=?( volatile void * volatile &, DT * );" << endl;295 cout << "forall( dtype DT ) volatile void * ?=?( volatile void * &, volatile DT * );" << endl;296 cout << "forall( dtype DT ) volatile void * ?=?( volatile void * volatile &, volatile DT * );" << endl;297 cout << "forall( dtype DT ) const volatile void * ?=?( const volatile void * &, DT * );" << endl;298 cout << "forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &, DT * );" << endl;299 cout << "forall( dtype DT ) const volatile void * ?=?( const volatile void * &, const DT * );" << endl;300 cout << "forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &, const DT * );" << endl;301 cout << "forall( dtype DT ) const volatile void * ?=?( const volatile void * &, volatile DT * );" << endl;302 cout << "forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &, volatile DT * );" << endl;303 cout << "forall( dtype DT ) const volatile void * ?=?( const volatile void * &, const volatile DT * );" << endl;304 cout << "forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &, const volatile DT * );" << endl;305 306 287 for (auto op : pointerOperators) { 288 auto forall = [&op]() { 289 cout << "forall(dtype DT" << op.sized << ") "; 290 }; 307 291 for (auto type : { "DT"/*, "void"*/ } ) { 308 292 auto operands = count(op.name.begin(), op.name.end(), '?'); … … 313 297 if (operands == 1) { 314 298 for (auto q : qualifiersSingle){ 315 for (auto q2 : { " ", " volatile" }) {316 cout << "forall(dtype DT" << op.sized << ") ";299 for (auto q2 : { " ", "volatile" }) { 300 forall(); 317 301 cout << q << type << " * " << op.name << "("; 318 cout << q << type << " * " << q2 << "&";302 cout << q << type << " * " << q2 << " &"; 319 303 cout << ");" << endl; 320 304 } … … 322 306 } else { 323 307 for (auto q : qualifiersPair){ 324 for (auto q2 : { " ", " volatile" }) {325 cout << "forall(dtype DT" << op.sized << ") ";308 for (auto q2 : { " ", "volatile" }) { 309 forall(); 326 310 cout << q.first << type << " * " << op.name << "("; 327 cout << q.first << type << " * " << q2 << "&";311 cout << q.first << type << " * " << q2 << " &"; 328 312 329 313 for (int i = 1; i < operands; ++i) { … … 337 321 case PtrDiff: 338 322 for (auto q : qualifiersSingle){ 339 for (auto q2 : { " ", " volatile" }) {340 cout << "forall(dtype DT" << op.sized << ") ";323 for (auto q2 : { " ", "volatile" }) { 324 forall(); 341 325 cout << q << type << " * " << op.name << "("; 342 cout << q << type << " * " << q2 << "&";326 cout << q << type << " * " << q2 << " &"; 343 327 344 328 for (int i = 1; i < operands; ++i) { … … 353 337 } 354 338 } else { 339 auto name_and_arg1 = [&op, &type](const std::string & q) { 340 if (op.diffReturn == "&") cout << q << type << " &"; // -- qualifiers 341 else if (op.diffReturn != "") cout << op.diffReturn; 342 else cout << q << type << " *"; 343 cout << " " << op.name << "("; 344 }; 355 345 switch(op.diffArg2) { 356 346 case Normal: 357 347 for (auto q : qualifiersSingle) { 358 cout << "forall(dtype DT" << op.sized << ") "; 359 if (op.diffReturn == "&") cout << q << type << " &"; // -- qualifiers 360 else if (op.diffReturn != "") cout << op.diffReturn; 361 else cout << q << type << " *"; 362 cout << " " << op.name << "("; 348 forall(); 349 name_and_arg1( q ); 363 350 for (int i = 0; i < operands; ++i) { 364 351 cout << q << type << " *"; … … 370 357 case CommPtrDiff: 371 358 for (auto q : qualifiersSingle) { 372 cout << "forall(dtype DT" << op.sized << ") "; 373 if (op.diffReturn == "&") cout << q << type << " &"; // -- qualifiers 374 else if (op.diffReturn != "") cout << op.diffReturn; 375 else cout << q << type << " *"; 376 cout << " " << op.name << "(ptrdiff_t, " << q << type << " *);" << endl; 359 forall(); 360 name_and_arg1( q ); 361 cout << "ptrdiff_t, " << q << type << " *);" << endl; 377 362 } 378 363 // fallthrough 379 364 case PtrDiff: 380 365 for (auto q : qualifiersSingle) { 381 cout << "forall(dtype DT" << op.sized << ") "; 382 if (op.diffReturn == "&") cout << q << type << " &"; // -- qualifiers 383 else if (op.diffReturn != "") cout << op.diffReturn; 384 else cout << q << type << " *"; 385 cout << " " << op.name << "(" << q << type << " *, ptrdiff_t);" << endl; 366 forall(); 367 name_and_arg1( q ); 368 cout << q << type << " *, ptrdiff_t);" << endl; 386 369 } 387 370 break; … … 393 376 cout << endl; 394 377 395 cout << "forall(dtype DT) DT * ?=?( DT * &, zero_t );" << endl; 396 cout << "forall(dtype DT) DT * ?=?( DT * volatile &, zero_t );" << endl; 397 cout << "forall(dtype DT) const DT * ?=?( const DT * &, zero_t );" << endl; 398 cout << "forall(dtype DT) const DT * ?=?( const DT * volatile &, zero_t );" << endl; 399 cout << "forall(dtype DT) volatile DT * ?=?( volatile DT * &, zero_t );" << endl; 400 cout << "forall(dtype DT) volatile DT * ?=?( volatile DT * volatile &, zero_t );" << endl; 401 cout << "forall(dtype DT) const volatile DT * ?=?( const volatile DT * &, zero_t );" << endl; 402 cout << "forall(dtype DT) const volatile DT * ?=?( const volatile DT * volatile &, zero_t );" << endl; 403 cout << "forall(ftype FT) FT * ?=?( FT * &, zero_t );" << endl; 404 cout << "forall(ftype FT) FT * ?=?( FT * volatile &, zero_t );" << endl; 378 for (auto is_vol : { " ", "volatile" }) { 379 for (auto cvq : qualifiersPair) { 380 cout << "forall(dtype DT) " << cvq.first << "void * ?=?( " << cvq.first << "void * " << is_vol << " &, " << cvq.second << "DT *);" << endl; 381 } 382 for (auto cvq : qualifiersSingle) { 383 cout << "forall(dtype DT) " << cvq << " DT * ?=?( " << cvq << " DT * " << is_vol << " &, zero_t);" << endl; 384 } 385 } 386 cout << endl; 405 387 } 406 388
Note: See TracChangeset
for help on using the changeset viewer.