Changes in src/SymTab/Validate.cc [dbe8f244:fb7dca0]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
rdbe8f244 rfb7dca0 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 … … 572 629 } else { 573 630 TypeDeclMap::const_iterator base = typedeclNames.find( typeInst->get_name() ); 574 assert ( base != typedeclNames.end() );631 assertf( base != typedeclNames.end(), "Can't find name %s", typeInst->get_name().c_str() ); 575 632 typeInst->set_baseType( base->second ); 576 633 } // if
Note:
See TracChangeset
for help on using the changeset viewer.