Changeset fe26fbf for src/SymTab
- Timestamp:
- Feb 7, 2017, 1:01:34 PM (8 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, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 35b1bf4
- Parents:
- dbe8f244 (diff), b4d65c7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/SymTab
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/AddVisit.h
rdbe8f244 rfe26fbf 10 10 // Created On : Sun May 17 16:14:32 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 4 11:22:01 201613 // Update Count : 912 // Last Modified On : Thu Feb 2 16:36:02 2017 13 // Update Count : 14 14 14 // 15 15 … … 18 18 19 19 template< typename Visitor > 20 inline void addVisitStatementList( std::list< Statement* > &statements, Visitor &visitor ) { 21 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 22 addDecls( visitor.get_declsToAdd(), statements, i ); 23 (*i)->accept( visitor ); 24 } // for 25 addDecls( visitor.get_declsToAdd(), statements, statements.end() ); 20 inline void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor ) { 21 for ( std::list< Statement* >::iterator stmt = stmts.begin(); ; ++stmt ) { 22 // add any new declarations after the previous statement 23 for ( std::list< Declaration* >::iterator decl = visitor.declsToAddAfter.begin(); decl != visitor.declsToAddAfter.end(); ++decl ) { 24 DeclStmt *declStmt = new DeclStmt( noLabels, *decl ); 25 stmts.insert( stmt, declStmt ); 26 } 27 visitor.declsToAddAfter.clear(); 28 29 if ( stmt == stmts.end() ) break; 30 31 // run mutator on statement 32 maybeAccept( *stmt, visitor ); 33 34 // add any new declarations before the statement 35 for ( std::list< Declaration* >::iterator decl = visitor.declsToAdd.begin(); decl != visitor.declsToAdd.end(); ++decl ) { 36 DeclStmt *declStmt = new DeclStmt( noLabels, *decl ); 37 stmts.insert( stmt, declStmt ); 38 } 39 visitor.declsToAdd.clear(); 40 } 26 41 } 27 42 … … 38 53 39 54 template< typename Visitor > 40 void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) { 41 std::list< Declaration * >::iterator i = translationUnit.begin(); 42 while ( i != translationUnit.end() ) { 43 (*i)->accept( visitor ); 44 std::list< Declaration * >::iterator next = i; 45 next++; 46 if ( ! visitor.get_declsToAdd().empty() ) { 47 translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() ); 48 } // if 49 i = next; 50 } // while 55 void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ) { 56 for ( std::list< Declaration* >::iterator decl = translationUnit.begin(); ; ++decl ) { 57 // splice in new declarations after previous decl 58 translationUnit.splice( decl, visitor.declsToAddAfter ); 59 60 if ( decl == translationUnit.end() ) break; 61 62 // run mutator on declaration 63 maybeAccept( *decl, visitor ); 64 65 // splice in new declarations before current decl 66 translationUnit.splice( decl, visitor.declsToAdd ); 67 } 51 68 } 52 69 -
src/SymTab/Autogen.cc
rdbe8f244 rfe26fbf 10 10 // Created On : Thu Mar 03 15:45:56 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Jul 12 17:47:17 201613 // Update Count : 212 // Last Modified On : Thu Feb 2 18:04:40 2017 13 // Update Count : 11 14 14 // 15 15 … … 43 43 44 44 class AutogenerateRoutines final : public Visitor { 45 template< typename Visitor > 46 friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ); 47 template< typename Visitor > 48 friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor ); 45 49 public: 46 50 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } … … 67 71 template< typename StmtClass > void visitStatement( StmtClass *stmt ); 68 72 69 std::list< Declaration * > declsToAdd ;73 std::list< Declaration * > declsToAdd, declsToAddAfter; 70 74 std::set< std::string > structsDone; 71 75 unsigned int functionNesting = 0; // current level of nested functions … … 98 102 void autogenerateRoutines( std::list< Declaration * > &translationUnit ) { 99 103 AutogenerateRoutines generator; 100 acceptAndAdd( translationUnit, generator , false);104 acceptAndAdd( translationUnit, generator ); 101 105 102 106 // needs to be done separately because AutogenerateRoutines skips types that appear as function arguments, etc. … … 567 571 EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() ); 568 572 // enumInst->set_baseEnum( enumDecl ); 569 // declsToAdd.push_back( 570 makeEnumFunctions( enumDecl, enumInst, functionNesting, declsToAdd ); 573 makeEnumFunctions( enumDecl, enumInst, functionNesting, declsToAddAfter ); 571 574 } 572 575 } … … 581 584 } 582 585 structInst.set_baseStruct( structDecl ); 583 makeStructFunctions( structDecl, &structInst, functionNesting, declsToAdd , data );586 makeStructFunctions( structDecl, &structInst, functionNesting, declsToAddAfter, data ); 584 587 structsDone.insert( structDecl->get_name() ); 585 588 } // if … … 593 596 unionInst.get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) ); 594 597 } 595 makeUnionFunctions( unionDecl, &unionInst, functionNesting, declsToAdd );598 makeUnionFunctions( unionDecl, &unionInst, functionNesting, declsToAddAfter ); 596 599 } // if 597 600 } … … 618 621 FunctionDecl *func = genFunc( "?=?", type, functionNesting ); 619 622 func->get_statements()->get_kids() = stmts; 620 declsToAdd .push_back( func );623 declsToAddAfter.push_back( func ); 621 624 } 622 625 … … 763 766 } 764 767 } // SymTab 768 769 // Local Variables: // 770 // tab-width: 4 // 771 // mode: c++ // 772 // compile-command: "make install" // 773 // End: // -
src/SymTab/Autogen.h
rdbe8f244 rfe26fbf 9 9 // Author : Rob Schluntz 10 10 // Created On : Sun May 17 21:53:34 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue May 19 16:49:43 201513 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 1 16:31:00 2017 13 // Update Count : 2 14 14 // 15 15 … … 58 58 assert( type ); 59 59 Type * castType = type->clone(); 60 castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true , true);60 castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true); 61 61 castType->set_isLvalue( true ); // xxx - might not need this 62 62 dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) ); -
src/SymTab/Validate.cc
rdbe8f244 rfe26fbf 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Jul 12 17:49:21 201613 // Update Count : 29812 // Last Modified On : Thu Feb 2 17:47:54 2017 13 // Update Count : 312 14 14 // 15 15 … … 67 67 namespace SymTab { 68 68 class HoistStruct final : public Visitor { 69 template< typename Visitor > 70 friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ); 71 template< typename Visitor > 72 friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor ); 69 73 public: 70 74 /// Flattens nested struct types … … 73 77 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } 74 78 79 virtual void visit( EnumInstType *enumInstType ); 80 virtual void visit( StructInstType *structInstType ); 81 virtual void visit( UnionInstType *unionInstType ); 75 82 virtual void visit( StructDecl *aggregateDecl ); 76 83 virtual void visit( UnionDecl *aggregateDecl ); … … 83 90 template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl ); 84 91 85 std::list< Declaration * > declsToAdd ;92 std::list< Declaration * > declsToAdd, declsToAddAfter; 86 93 bool inStruct; 87 94 }; … … 115 122 private: 116 123 using Parent::visit; 124 void visit( EnumInstType *enumInst ) final; 117 125 void visit( StructInstType *structInst ) final; 118 126 void visit( UnionInstType *unionInst ) final; 119 127 void visit( TraitInstType *contextInst ) final; 128 void visit( EnumDecl *enumDecl ) final; 120 129 void visit( StructDecl *structDecl ) final; 121 130 void visit( UnionDecl *unionDecl ) final; … … 124 133 const Indexer *indexer; 125 134 135 typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType; 126 136 typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType; 127 137 typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType; 138 ForwardEnumsType forwardEnums; 128 139 ForwardStructsType forwardStructs; 129 140 ForwardUnionsType forwardUnions; … … 236 247 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) { 237 248 HoistStruct hoister; 238 acceptAndAdd( translationUnit, hoister , true);249 acceptAndAdd( translationUnit, hoister ); 239 250 } 240 251 … … 260 271 return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl ); 261 272 } 262 // xxx - shouldn't this be declsToAddBefore? 273 263 274 template< typename AggDecl > 264 275 void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) { … … 276 287 } 277 288 289 void HoistStruct::visit( EnumInstType *structInstType ) { 290 if ( structInstType->get_baseEnum() ) { 291 declsToAdd.push_front( structInstType->get_baseEnum() ); 292 } 293 } 294 295 void HoistStruct::visit( StructInstType *structInstType ) { 296 if ( structInstType->get_baseStruct() ) { 297 declsToAdd.push_front( structInstType->get_baseStruct() ); 298 } 299 } 300 301 void HoistStruct::visit( UnionInstType *structInstType ) { 302 if ( structInstType->get_baseUnion() ) { 303 declsToAdd.push_front( structInstType->get_baseUnion() ); 304 } 305 } 306 278 307 void HoistStruct::visit( StructDecl *aggregateDecl ) { 279 308 handleAggregate( aggregateDecl ); … … 297 326 ObjectDecl * obj = dynamic_cast< ObjectDecl * >( *i ); 298 327 assert( obj ); 299 obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false, false , false), enumDecl->get_name() ) );328 obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false, false ), enumDecl->get_name() ) ); 300 329 } // for 301 330 Parent::visit( enumDecl ); … … 349 378 } 350 379 380 void LinkReferenceToTypes::visit( EnumInstType *enumInst ) { 381 Parent::visit( enumInst ); 382 EnumDecl *st = indexer->lookupEnum( enumInst->get_name() ); 383 // it's not a semantic error if the enum is not found, just an implicit forward declaration 384 if ( st ) { 385 //assert( ! enumInst->get_baseEnum() || enumInst->get_baseEnum()->get_members().empty() || ! st->get_members().empty() ); 386 enumInst->set_baseEnum( st ); 387 } // if 388 if ( ! st || st->get_members().empty() ) { 389 // use of forward declaration 390 forwardEnums[ enumInst->get_name() ].push_back( enumInst ); 391 } // if 392 } 393 351 394 void LinkReferenceToTypes::visit( StructInstType *structInst ) { 352 395 Parent::visit( structInst ); … … 419 462 } 420 463 } 464 } 465 466 void LinkReferenceToTypes::visit( EnumDecl *enumDecl ) { 467 // visit enum members first so that the types of self-referencing members are updated properly 468 Parent::visit( enumDecl ); 469 if ( ! enumDecl->get_members().empty() ) { 470 ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->get_name() ); 471 if ( fwds != forwardEnums.end() ) { 472 for ( std::list< EnumInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) { 473 (*inst )->set_baseEnum( enumDecl ); 474 } // for 475 forwardEnums.erase( fwds ); 476 } // if 477 } // if 421 478 } 422 479
Note: See TracChangeset
for help on using the changeset viewer.