Changeset bd4d011 for src/Concurrency
- Timestamp:
- Mar 23, 2017, 3:05:36 PM (6 years ago)
- Branches:
- aaron-thesis, arm-eh, 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:
- ae6f1ec
- Parents:
- bcda04c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Keywords.cc
rbcda04c rbd4d011 17 17 #include "Concurrency/Keywords.h" 18 18 19 #include "InitTweak/InitTweak.h" 19 20 #include "SymTab/AddVisit.h" 20 21 #include "SynTree/Declaration.h" … … 53 54 public: 54 55 55 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error ) :56 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ) {}56 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main ) : 57 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ) {} 57 58 58 59 virtual ~ConcurrentSueKeyword() {} … … 73 74 const std::string getter_name; 74 75 const std::string context_error; 76 bool needs_main; 75 77 76 78 std::list< Declaration * > declsToAdd, declsToAddAfter; … … 95 97 "__thrd", 96 98 "get_thread", 97 "thread keyword requires threads to be in scope, add #include <thread>" 99 "thread keyword requires threads to be in scope, add #include <thread>", 100 true 98 101 ) 99 102 {} … … 125 128 "__cor", 126 129 "get_coroutine", 127 "coroutine keyword requires coroutines to be in scope, add #include <coroutine>" 130 "coroutine keyword requires coroutines to be in scope, add #include <coroutine>", 131 true 128 132 ) 129 133 {} … … 155 159 "__mon", 156 160 "get_monitor", 157 "monitor keyword requires monitors to be in scope, add #include <monitor>" 161 "monitor keyword requires monitors to be in scope, add #include <monitor>", 162 false 158 163 ) 159 164 {} … … 198 203 }; 199 204 205 //----------------------------------------------------------------------------- 206 //Handles mutex routines definitions : 207 // void foo( A * mutex a, B * mutex b, int i ) { void foo( A * a, B * b, int i ) { 208 // monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) }; 209 // monitor_guard_t __guard = { __monitors, 2 }; 210 // /*Some code*/ => /*Some code*/ 211 // } } 212 // 213 class ThreadStarter final : public Visitor { 214 public: 215 216 using Visitor::visit; 217 virtual void visit( FunctionDecl * decl ) override final; 218 219 void addStartStatement( FunctionDecl * decl, DeclarationWithType * param ); 220 221 static void implement( std::list< Declaration * > & translationUnit ) { 222 ThreadStarter impl; 223 acceptAll( translationUnit, impl ); 224 } 225 }; 226 200 227 //============================================================================================= 201 228 // General entry routine … … 212 239 213 240 void implementThreadStarter( std::list< Declaration * > & translationUnit ) { 214 241 ThreadStarter ::implement( translationUnit ); 215 242 } 216 243 … … 246 273 forward->get_members().clear(); 247 274 248 FunctionType * type = new FunctionType( noQualifiers, false );275 FunctionType * get_type = new FunctionType( noQualifiers, false ); 249 276 ObjectDecl * this_decl = new ObjectDecl( 250 277 "this", … … 262 289 ); 263 290 264 type->get_parameters().push_back( this_decl );265 type->get_returnVals().push_back(291 get_type->get_parameters().push_back( this_decl ); 292 get_type->get_returnVals().push_back( 266 293 new ObjectDecl( 267 294 "ret", … … 284 311 Type::Static, 285 312 LinkageSpec::Cforall, 286 type,313 get_type, 287 314 nullptr, 288 315 noAttributes, … … 290 317 ); 291 318 319 FunctionDecl * main_decl = nullptr; 320 321 if( needs_main ) { 322 FunctionType * main_type = new FunctionType( noQualifiers, false ); 323 324 main_type->get_parameters().push_back( this_decl->clone() ); 325 326 main_decl = new FunctionDecl( 327 "main", 328 noStorage, 329 LinkageSpec::Cforall, 330 main_type, 331 nullptr 332 ); 333 } 334 292 335 declsToAdd.push_back( forward ); 336 if( needs_main ) declsToAdd.push_back( main_decl ); 293 337 declsToAdd.push_back( get_decl ); 294 338 … … 455 499 body->push_front( new DeclStmt( noLabels, monitors) ); 456 500 } 501 502 //============================================================================================= 503 // General entry routine 504 //============================================================================================= 505 void ThreadStarter::visit(FunctionDecl * decl) { 506 if( ! InitTweak::isConstructor(decl->get_name()) ) return; 507 508 DeclarationWithType * param = decl->get_functionType()->get_parameters().front(); 509 auto ptr = dynamic_cast< PointerType * >( param->get_type() ); 510 // if( ptr ) std::cerr << "FRED1" << std::endl; 511 auto type = dynamic_cast< StructInstType * >( ptr->get_base() ); 512 // if( type ) std::cerr << "FRED2" << std::endl; 513 if( type && type->get_baseStruct()->is_thread() ) { 514 addStartStatement( decl, param ); 515 } 516 } 517 518 void ThreadStarter::addStartStatement( FunctionDecl * decl, DeclarationWithType * param ) { 519 CompoundStmt * stmt = decl->get_statements(); 520 521 if( ! stmt ) return; 522 523 stmt->push_back( 524 new ExprStmt( 525 noLabels, 526 new UntypedExpr( 527 new NameExpr( "__thrd_start" ), 528 { new VariableExpr( param ) } 529 ) 530 ) 531 ); 532 } 457 533 };
Note: See TracChangeset
for help on using the changeset viewer.