Changes in src/SymTab/Validate.cc [c0aa336:dbe8f244]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
rc0aa336 rdbe8f244 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Feb 2 17:47:54 201713 // Update Count : 31212 // Last Modified On : Tue Jul 12 17:49:21 2016 13 // Update Count : 298 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 );73 69 public: 74 70 /// Flattens nested struct types … … 77 73 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } 78 74 79 virtual void visit( EnumInstType *enumInstType );80 virtual void visit( StructInstType *structInstType );81 virtual void visit( UnionInstType *unionInstType );82 75 virtual void visit( StructDecl *aggregateDecl ); 83 76 virtual void visit( UnionDecl *aggregateDecl ); … … 90 83 template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl ); 91 84 92 std::list< Declaration * > declsToAdd , declsToAddAfter;85 std::list< Declaration * > declsToAdd; 93 86 bool inStruct; 94 87 }; … … 122 115 private: 123 116 using Parent::visit; 124 void visit( EnumInstType *enumInst ) final;125 117 void visit( StructInstType *structInst ) final; 126 118 void visit( UnionInstType *unionInst ) final; 127 119 void visit( TraitInstType *contextInst ) final; 128 void visit( EnumDecl *enumDecl ) final;129 120 void visit( StructDecl *structDecl ) final; 130 121 void visit( UnionDecl *unionDecl ) final; … … 133 124 const Indexer *indexer; 134 125 135 typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;136 126 typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType; 137 127 typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType; 138 ForwardEnumsType forwardEnums;139 128 ForwardStructsType forwardStructs; 140 129 ForwardUnionsType forwardUnions; … … 247 236 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) { 248 237 HoistStruct hoister; 249 acceptAndAdd( translationUnit, hoister );238 acceptAndAdd( translationUnit, hoister, true ); 250 239 } 251 240 … … 271 260 return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl ); 272 261 } 273 262 // xxx - shouldn't this be declsToAddBefore? 274 263 template< typename AggDecl > 275 264 void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) { … … 287 276 } 288 277 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 307 278 void HoistStruct::visit( StructDecl *aggregateDecl ) { 308 279 handleAggregate( aggregateDecl ); … … 326 297 ObjectDecl * obj = dynamic_cast< ObjectDecl * >( *i ); 327 298 assert( obj ); 328 obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false, false ), enumDecl->get_name() ) );299 obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false, false, false ), enumDecl->get_name() ) ); 329 300 } // for 330 301 Parent::visit( enumDecl ); … … 378 349 } 379 350 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 declaration384 if ( st ) {385 //assert( ! enumInst->get_baseEnum() || enumInst->get_baseEnum()->get_members().empty() || ! st->get_members().empty() );386 enumInst->set_baseEnum( st );387 } // if388 if ( ! st || st->get_members().empty() ) {389 // use of forward declaration390 forwardEnums[ enumInst->get_name() ].push_back( enumInst );391 } // if392 }393 394 351 void LinkReferenceToTypes::visit( StructInstType *structInst ) { 395 352 Parent::visit( structInst ); … … 462 419 } 463 420 } 464 }465 466 void LinkReferenceToTypes::visit( EnumDecl *enumDecl ) {467 // visit enum members first so that the types of self-referencing members are updated properly468 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 } // for475 forwardEnums.erase( fwds );476 } // if477 } // if478 421 } 479 422 … … 696 639 FunctionDecl * newDecl = new FunctionDecl( ret->get_name(), ret->get_storageClass(), ret->get_linkage(), funtype, 0, ret->get_isInline(), ret->get_isNoreturn(), objDecl->get_attributes() ); 697 640 objDecl->get_attributes().clear(); 641 objDecl->set_type( nullptr ); 698 642 delete objDecl; 699 643 return newDecl;
Note: See TracChangeset
for help on using the changeset viewer.