Changeset a8e8c67
- Timestamp:
- Jan 31, 2023, 2:59:20 PM (22 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 757099e
- Parents:
- 96ddc62
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Actors.cpp
r96ddc62 ra8e8c67 36 36 StructDecl * parentDecl; 37 37 bool insideStruct = false; 38 38 bool namedDecl = false; 39 40 // finds and sets a ptr to the Allocation enum, which is needed in the next pass 39 41 void previsit( const EnumDecl * decl ) { 40 42 if( decl->name == "Allocation" ) *allocationDecl = decl; 41 43 } 42 44 45 // finds and sets a ptr to the actor, message, and request structs, which are needed in the next pass 43 46 void previsit( const StructDecl * decl ) { 44 47 GuardValue(insideStruct); … … 47 50 if( decl->name == "actor" ) *actorDecl = decl; 48 51 if( decl->name == "message" ) *msgDecl = decl; 49 if( decl->name == "request" ) *requestDecl = decl; 52 if( decl->name == "request" ) *requestDecl = decl; 50 53 } 51 54 55 // this catches structs of the form: 56 // struct dummy_actor { actor a; }; 57 // since they should be: 58 // struct dummy_actor { inline actor; }; 59 void previsit ( const ObjectDecl * decl ) { 60 if ( insideStruct && ! decl->name.empty() ) { 61 GuardValue(namedDecl); 62 namedDecl = true; 63 } 64 } 65 66 // this collects the valid actor and message struct decl pts 52 67 void postvisit( const StructInstType * node ) { 53 68 if ( ! *actorDecl || ! *msgDecl ) return; 54 if ( insideStruct ) {55 if ( node->aggr() == *actorDecl ) { // C_TODO: see if we need to check for empty name69 if ( insideStruct && !namedDecl ) { 70 if ( node->aggr() == *actorDecl ) { 56 71 actorStructDecls.insert( parentDecl ); 57 72 } else if ( node->aggr() == *msgDecl ) { … … 100 115 iter->second.emplace( make_pair( otherDecl, data ) ); 101 116 } else { // else create inner map for key 102 map.emplace( make_pair( decl, unordered_map<const StructDecl *, FwdDeclData *>( { make_pair( otherDecl, data ) } ) ) ); // C_TODO: maybe emplace?117 map.emplace( make_pair( decl, unordered_map<const StructDecl *, FwdDeclData *>( { make_pair( otherDecl, data ) } ) ) ); 103 118 } 104 119 } … … 118 133 unordered_map<const StructDecl *, unordered_map<const StructDecl *, FwdDeclData *>> & otherMap = isMsg ? actorMap : msgMap; 119 134 auto iter = map.find( decl ); 120 121 135 list<FunctionDecl *> toInsertAfter; // this is populated with decls that are ready to insert 122 136 if ( iter == map.end() ) return toInsertAfter; 123 137 138 // iterate over inner map 124 139 unordered_map<const StructDecl *, FwdDeclData *> & currInnerMap = iter->second; 125 126 cout << "a" << endl;127 // iterate over inner map128 140 for ( auto innerIter = currInnerMap.begin(); innerIter != currInnerMap.end(); ) { 129 cout << "b: " << decl->name << endl;130 141 FwdDeclData * currentDatum = innerIter->second; 131 printf("P: %p\n", currentDatum->fwdDecl );132 133 142 bool readyToInsert = isMsg ? currentDatum->foundMsg() : currentDatum->foundActor(); 134 143 if ( ! readyToInsert ) { ++innerIter; continue; } 135 144 136 cout << "c" << endl;137 145 // readyToInsert is true so we are good to insert the forward decl of the message fn 138 146 toInsertAfter.push_back( currentDatum->fwdDecl ); 139 147 140 cout << "d" << endl;141 148 // need to remove from other map before deleting 149 // find inner map in other map ( other map is actor map if original is msg map and vice versa ) 142 150 const StructDecl * otherDecl = isMsg ? currentDatum->actorDecl : currentDatum->msgDecl; 143 144 // need to remove from other map before deleting145 // find inner map of FwdDeclData in other map ( other map is actor map if original is msg map and vice versa )146 151 auto otherMapIter = otherMap.find( otherDecl ); 147 152 148 153 unordered_map<const StructDecl *, FwdDeclData *> & otherInnerMap = otherMapIter->second; 149 154 150 cout << "e" << endl;151 155 // find the FwdDeclData we need to remove in the other inner map 152 156 auto otherInnerIter = otherInnerMap.find( decl ); 153 157 154 cout << "f" << endl;155 // now we are safe to delete the FwdDeclData since we are done with it156 // have to delete before we invalidate the iterator157 delete currentDatum; // C_TODO: move down since this no longer iterator dependant158 159 cout << "g" << endl;160 158 // remove references to deleted FwdDeclData from current inner map 161 159 innerIter = currInnerMap.erase( innerIter ); // this does the increment so no explicit inc needed 162 160 163 cout << "h" << endl;164 161 // remove references to deleted FwdDeclData from other inner map 165 162 otherInnerMap.erase( otherInnerIter ); … … 168 165 if ( otherInnerMap.empty() ) 169 166 otherMap.erase( otherDecl ); 167 168 // now we are safe to delete the FwdDeclData since we are done with it 169 // and we have removed all references to it from our data structures 170 delete currentDatum; 170 171 } 171 172
Note: See TracChangeset
for help on using the changeset viewer.