Changeset 29f9e20
- Timestamp:
- Jun 14, 2018, 4:43:52 PM (6 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, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- c5d7701
- Parents:
- 589a70b
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r589a70b r29f9e20 80 80 81 81 namespace SymTab { 82 struct LinkNestedTypes final : public WithDeclsToAdd { 83 void previsit( AggregateDecl * aggr ); 84 85 void previsit( SizeofExpr * ); 86 void previsit( AlignofExpr * ); 87 void previsit( UntypedOffsetofExpr * ); 88 void handleType( Type * ); 89 }; 90 82 91 struct HoistStruct final : public WithDeclsToAdd, public WithGuards { 83 92 /// Flattens nested struct types 84 93 static void hoistStruct( std::list< Declaration * > &translationUnit ); 85 94 86 void previsit( EnumInstType * enumInstType );87 void previsit( StructInstType * structInstType );88 void previsit( UnionInstType * unionInstType );89 95 void previsit( StructDecl * aggregateDecl ); 90 96 void previsit( UnionDecl * aggregateDecl ); … … 263 269 PassVisitor<FindSpecialDeclarations> finder; 264 270 PassVisitor<LabelAddressFixer> labelAddrFixer; 265 271 PassVisitor<LinkNestedTypes> nestedTypes; 272 273 acceptAll( translationUnit, nestedTypes ); 266 274 EliminateTypedef::eliminateTypedef( translationUnit ); 267 HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order268 275 ReturnTypeFixer::fix( translationUnit ); // must happen before autogen 269 276 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes because it is an indexer and needs correct types for mangling 270 277 acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions 278 HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order 271 279 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes 272 280 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors … … 294 302 } 295 303 304 305 void LinkNestedTypes::previsit( AggregateDecl * aggr ) { 306 for ( auto it = aggr->members.begin(); it != aggr->members.end(); ) { 307 auto current = it++; 308 Declaration * member = *current; 309 if ( AggregateDecl * child = dynamic_cast<AggregateDecl *>( member ) ) { 310 child->parent = aggr; 311 } 312 } 313 } 314 315 void LinkNestedTypes::handleType( Type * type ) { 316 // some type declarations are buried in expressions and not easy to hoist during parsing; hoist them here 317 AggregateDecl * aggr = nullptr; 318 if ( StructInstType * inst = dynamic_cast< StructInstType * >( type ) ) { 319 aggr = inst->baseStruct; 320 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( type ) ) { 321 aggr = inst->baseUnion; 322 } else if ( EnumInstType * inst = dynamic_cast< EnumInstType * >( type ) ) { 323 aggr = inst->baseEnum; 324 } 325 if ( aggr && aggr->body ) { 326 declsToAddBefore.push_front( aggr ); 327 } 328 } 329 330 void LinkNestedTypes::previsit( SizeofExpr * expr ) { 331 handleType( expr->type ); 332 } 333 334 void LinkNestedTypes::previsit( AlignofExpr * expr ) { 335 handleType( expr->type ); 336 } 337 338 void LinkNestedTypes::previsit( UntypedOffsetofExpr * expr ) { 339 handleType( expr->type ); 340 } 341 342 296 343 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) { 297 344 PassVisitor<HoistStruct> hoister; … … 316 363 } 317 364 318 void HoistStruct::previsit( EnumInstType * inst ) {319 if ( inst->baseEnum && inst->baseEnum->body ) {320 declsToAddBefore.push_front( inst->baseEnum );321 }322 }323 324 void HoistStruct::previsit( StructInstType * inst ) {325 if ( inst->baseStruct && inst->baseStruct->body ) {326 declsToAddBefore.push_front( inst->baseStruct );327 }328 }329 330 void HoistStruct::previsit( UnionInstType * inst ) {331 if ( inst->baseUnion && inst->baseUnion->body ) {332 declsToAddBefore.push_front( inst->baseUnion );333 }334 }335 336 365 void HoistStruct::previsit( StaticAssertDecl * assertDecl ) { 337 366 if ( parentAggr ) { … … 398 427 // it's not a semantic error if the enum is not found, just an implicit forward declaration 399 428 if ( st ) { 400 //assert( ! enumInst->get_baseEnum() || enumInst->get_baseEnum()->get_members().empty() || ! st->get_members().empty() );401 429 enumInst->baseEnum = st; 402 430 } // if 403 if ( ! st || st->members.empty()) {431 if ( ! st || ! st->body ) { 404 432 // use of forward declaration 405 433 forwardEnums[ enumInst->name ].push_back( enumInst ); … … 419 447 // it's not a semantic error if the struct is not found, just an implicit forward declaration 420 448 if ( st ) { 421 //assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );422 449 structInst->baseStruct = st; 423 450 } // if 424 if ( ! st || st->members.empty()) {451 if ( ! st || ! st->body ) { 425 452 // use of forward declaration 426 453 forwardStructs[ structInst->name ].push_back( structInst ); … … 435 462 unionInst->baseUnion = un; 436 463 } // if 437 if ( ! un || un->members.empty()) {464 if ( ! un || ! un->body ) { 438 465 // use of forward declaration 439 466 forwardUnions[ unionInst->name ].push_back( unionInst ); -
src/SynTree/Declaration.h
r589a70b r29f9e20 266 266 bool body; 267 267 std::list< Attribute * > attributes; 268 AggregateDecl * parent = nullptr; 268 269 269 270 AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
Note: See TracChangeset
for help on using the changeset viewer.