- Timestamp:
- Sep 9, 2020, 5:03:40 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b9fa85b, c402739f
- Parents:
- 2b7f6f0
- Location:
- src
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/module.mk
r2b7f6f0 r1c01c58 22 22 Common/ErrorObjects.h \ 23 23 Common/Eval.cc \ 24 Common/Examine.cc \ 25 Common/Examine.h \ 24 26 Common/FilterCombos.h \ 25 27 Common/Indenter.h \ -
src/Concurrency/Keywords.cc
r2b7f6f0 r1c01c58 19 19 #include <string> // for string, operator== 20 20 21 #include <iostream> 22 23 #include "Common/Examine.h" // for isMainFor 21 24 #include "Common/PassVisitor.h" // for PassVisitor 22 25 #include "Common/SemanticError.h" // for SemanticError … … 34 37 #include "SynTree/Type.h" // for StructInstType, Type, PointerType 35 38 #include "SynTree/Visitor.h" // for Visitor, acceptAll 39 #include "Virtual/Tables.h" 36 40 37 41 class Attribute; 38 42 39 43 namespace Concurrency { 44 inline static std::string getVTableName( std::string const & exception_name ) { 45 return exception_name.empty() ? std::string() : Virtual::vtableTypeName(exception_name); 46 } 47 40 48 //============================================================================================= 41 49 // Pass declarations … … 54 62 public: 55 63 56 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, AggregateDecl::Aggregate cast_target ) : 57 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ), cast_target( cast_target ) {} 64 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, 65 std::string&& getter_name, std::string&& context_error, std::string&& exception_name, 66 bool needs_main, AggregateDecl::Aggregate cast_target ) : 67 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), 68 context_error( context_error ), vtable_name( getVTableName( exception_name ) ), 69 needs_main( needs_main ), cast_target( cast_target ) {} 58 70 59 71 virtual ~ConcurrentSueKeyword() {} … … 63 75 64 76 void handle( StructDecl * ); 77 void addVtableForward( StructDecl * ); 65 78 FunctionDecl * forwardDeclare( StructDecl * ); 66 79 ObjectDecl * addField( StructDecl * ); … … 76 89 const std::string getter_name; 77 90 const std::string context_error; 91 const std::string vtable_name; 78 92 bool needs_main; 79 93 AggregateDecl::Aggregate cast_target; … … 81 95 StructDecl * type_decl = nullptr; 82 96 FunctionDecl * dtor_decl = nullptr; 97 StructDecl * vtable_decl = nullptr; 83 98 }; 84 99 … … 101 116 "get_thread", 102 117 "thread keyword requires threads to be in scope, add #include <thread.hfa>\n", 118 "", 103 119 true, 104 120 AggregateDecl::Thread … … 133 149 "get_coroutine", 134 150 "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>\n", 151 "CoroutineCancelled", 135 152 true, 136 153 AggregateDecl::Coroutine … … 167 184 "get_monitor", 168 185 "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>\n", 186 "", 169 187 false, 170 188 AggregateDecl::Monitor … … 198 216 "get_generator", 199 217 "Unable to find builtin type $generator\n", 218 "", 200 219 true, 201 220 AggregateDecl::Generator … … 231 250 232 251 private: 233 DeclarationWithType * is_main( FunctionDecl * );234 252 bool is_real_suspend( FunctionDecl * ); 235 253 … … 359 377 handle( decl ); 360 378 } 379 else if ( !vtable_decl && vtable_name == decl->name && decl->body ) { 380 vtable_decl = decl; 381 } 382 // Might be able to get ride of is target. 383 assert( is_target(decl) == (cast_target == decl->kind) ); 361 384 return decl; 362 385 } 363 386 364 387 DeclarationWithType * ConcurrentSueKeyword::postmutate( FunctionDecl * decl ) { 365 if( !type_decl ) return decl; 366 if( !CodeGen::isDestructor( decl->name ) ) return decl; 367 368 auto params = decl->type->parameters; 369 if( params.size() != 1 ) return decl; 370 371 auto type = dynamic_cast<ReferenceType*>( params.front()->get_type() ); 372 if( !type ) return decl; 373 374 auto stype = dynamic_cast<StructInstType*>( type->base ); 375 if( !stype ) return decl; 376 if( stype->baseStruct != type_decl ) return decl; 377 378 if( !dtor_decl ) dtor_decl = decl; 388 if ( type_decl && isDestructorFor( decl, type_decl ) ) 389 dtor_decl = decl; 390 else if ( vtable_name.empty() ) 391 ; 392 else if ( auto param = isMainFor( decl, cast_target ) ) { 393 // This should never trigger. 394 assert( vtable_decl ); 395 // Should be safe because of isMainFor. 396 StructInstType * struct_type = static_cast<StructInstType *>( 397 static_cast<ReferenceType *>( param->get_type() )->base ); 398 assert( struct_type ); 399 400 declsToAddAfter.push_back( Virtual::makeVtableInstance( vtable_decl, { 401 new TypeExpr( struct_type->clone() ), 402 }, struct_type, nullptr ) ); 403 } 404 379 405 return decl; 380 406 } … … 400 426 if( !dtor_decl ) SemanticError( decl, context_error ); 401 427 428 addVtableForward( decl ); 402 429 FunctionDecl * func = forwardDeclare( decl ); 403 430 ObjectDecl * field = addField( decl ); 404 431 addRoutines( field, func ); 432 } 433 434 void ConcurrentSueKeyword::addVtableForward( StructDecl * decl ) { 435 if ( vtable_decl ) { 436 declsToAddBefore.push_back( Virtual::makeVtableForward( vtable_decl, { 437 new TypeExpr( new StructInstType( noQualifiers, decl ) ), 438 } ) ); 439 // Its only an error if we want a vtable and don't have one. 440 } else if ( ! vtable_name.empty() ) { 441 SemanticError( decl, context_error ); 442 } 405 443 } 406 444 … … 528 566 // Suspend keyword implementation 529 567 //============================================================================================= 530 DeclarationWithType * SuspendKeyword::is_main( FunctionDecl * func) {531 if(func->name != "main") return nullptr;532 if(func->type->parameters.size() != 1) return nullptr;533 534 auto param = func->type->parameters.front();535 536 auto type = dynamic_cast<ReferenceType * >(param->get_type());537 if(!type) return nullptr;538 539 auto obj = dynamic_cast<StructInstType *>(type->base);540 if(!obj) return nullptr;541 542 if(!obj->baseStruct->is_generator()) return nullptr;543 544 return param;545 }546 547 568 bool SuspendKeyword::is_real_suspend( FunctionDecl * func ) { 548 569 if(isMangled(func->linkage)) return false; // the real suspend isn't mangled … … 565 586 566 587 // Is this the main of a generator? 567 auto param = is _main( func);588 auto param = isMainFor( func, AggregateDecl::Aggregate::Generator ); 568 589 if(!param) return; 569 590 … … 1033 1054 // tab-width: 4 // 1034 1055 // End: // 1056 -
src/Virtual/module.mk
r2b7f6f0 r1c01c58 15 15 ############################################################################### 16 16 17 SRC += Virtual/ExpandCasts.cc Virtual/ExpandCasts.h 17 SRC += Virtual/ExpandCasts.cc Virtual/ExpandCasts.h \ 18 Virtual/Tables.cc Virtual/Tables.h 19 20 SRCDEMANGLE += Virtual/Tables.cc
Note: See TracChangeset
for help on using the changeset viewer.