Changeset 3c70d38 for translator/SymTab/Validate.cc
- Timestamp:
- Nov 20, 2014, 9:50:35 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- ea3eb06
- Parents:
- 1db2c5be
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SymTab/Validate.cc
r1db2c5be r3c70d38 117 117 virtual void visit( TypeDecl *typeDecl ); 118 118 virtual void visit( ContextDecl *ctxDecl ); 119 virtual void visit( FunctionDecl *functionDecl ); 119 120 120 121 virtual void visit( FunctionType *ftype ); … … 129 130 virtual void visit( CaseStmt *caseStmt ); 130 131 virtual void visit( CatchStmt *catchStmt ); 132 133 AddStructAssignment() : functionNesting( 0 ) {} 131 134 private: 132 135 template< typename StmtClass > void visitStatement( StmtClass *stmt ); … … 134 137 std::list< Declaration * > declsToAdd; 135 138 std::set< std::string > structsDone; 139 unsigned int functionNesting; // current level of nested functions 136 140 }; 137 141 … … 194 198 } 195 199 196 void filter( std::list< Declaration * > &declList, bool (*pred 200 void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) { 197 201 std::list< Declaration * >::iterator i = declList.begin(); 198 202 while ( i != declList.end() ) { … … 216 220 void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) { 217 221 if ( inStruct ) { 218 declsToAdd.push_back( aggregateDecl ); 222 // Add elements in stack order corresponding to nesting structure. 223 declsToAdd.push_front( aggregateDecl ); 219 224 Visitor::visit( aggregateDecl ); 220 225 } else { … … 222 227 Visitor::visit( aggregateDecl ); 223 228 inStruct = false; 224 filter( aggregateDecl->get_members(), isStructOrUnion, false ); 225 } 229 } 230 // Always remove the hoisted aggregate from the inner structure. 231 filter( aggregateDecl->get_members(), isStructOrUnion, false ); 226 232 } 227 233 … … 523 529 } 524 530 525 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType ) {531 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 526 532 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 527 533 … … 534 540 ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 ); 535 541 assignType->get_parameters().push_back( srcParam ); 536 537 FunctionDecl *assignDecl = new FunctionDecl( "?=?", Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true ); 542 543 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 544 // because each unit generates copies of the default routines for each aggregate. 545 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true ); 538 546 assignDecl->fixUniqueId(); 539 547 … … 552 560 } 553 561 554 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType ) {562 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 555 563 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 556 564 … … 564 572 assignType->get_parameters().push_back( srcParam ); 565 573 566 FunctionDecl *assignDecl = new FunctionDecl( "?=?", Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true ); 574 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 575 // because each unit generates copies of the default routines for each aggregate. 576 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true ); 567 577 assignDecl->fixUniqueId(); 568 578 … … 582 592 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() ); 583 593 structInst->set_baseStruct( structDecl ); 584 declsToAdd.push_back( makeStructAssignment( structDecl, structInst ) );594 declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) ); 585 595 structsDone.insert( structDecl->get_name() ); 586 596 } … … 591 601 UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() ); 592 602 unionInst->set_baseUnion( unionDecl ); 593 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst ) );603 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) ); 594 604 } 595 605 } … … 647 657 } 648 658 659 void AddStructAssignment::visit( FunctionDecl *functionDecl ) { 660 maybeAccept( functionDecl->get_functionType(), *this ); 661 acceptAll( functionDecl->get_oldDecls(), *this ); 662 functionNesting += 1; 663 maybeAccept( functionDecl->get_statements(), *this ); 664 functionNesting -= 1; 665 } 666 649 667 void AddStructAssignment::visit( CompoundStmt *compoundStmt ) { 650 668 visitStatement( compoundStmt );
Note: See TracChangeset
for help on using the changeset viewer.