Changeset e4d6335
- Timestamp:
- Sep 21, 2017, 1:16:26 PM (6 years ago)
- Branches:
- aaron-thesis, arm-eh, 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:
- 22bc276
- Parents:
- 47b5b63
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r47b5b63 re4d6335 819 819 assert( ! ctorInit->get_ctor() || ! ctorInit->get_init() ); 820 820 Statement * dtor = ctorInit->get_dtor(); 821 // don't need to call intrinsic dtor, because it does nothing, but 822 // non-intrinsic dtors must be called 821 823 if ( dtor && ! isIntrinsicSingleArgCallStmt( dtor ) ) { 822 // don't need to call intrinsic dtor, because it does nothing, but823 // non-intrinsic dtors must be called824 // set dtor location to the object's location for error messages 825 ctorInit->dtor->location = objDecl->location; 824 826 reverseDeclOrder.front().push_front( objDecl ); 825 827 } // if -
src/SymTab/Autogen.cc
r47b5b63 re4d6335 27 27 #include "AddVisit.h" // for addVisit 28 28 #include "CodeGen/OperatorTable.h" // for isCtorDtor, isCtorDtorAssign 29 #include "Common/PassVisitor.h" // for PassVisitor 29 30 #include "Common/ScopedMap.h" // for ScopedMap<>::const_iterator, Scope... 30 31 #include "Common/utility.h" // for cloneAll, operator+ … … 53 54 }; 54 55 55 class AutogenerateRoutines final : public Visitor { 56 template< typename Visitor > 57 friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ); 58 template< typename Visitor > 59 friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor ); 60 public: 61 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } 62 63 typedef Visitor Parent; 64 using Parent::visit; 65 56 struct AutogenerateRoutines final : public WithDeclsToAdd, public WithVisitorRef<AutogenerateRoutines>, public WithGuards, public WithShortCircuiting { 66 57 AutogenerateRoutines(); 67 58 68 virtual void visit( EnumDecl *enumDecl ); 69 virtual void visit( StructDecl *structDecl ); 70 virtual void visit( UnionDecl *structDecl ); 71 virtual void visit( TypeDecl *typeDecl ); 72 virtual void visit( TraitDecl *ctxDecl ); 73 virtual void visit( FunctionDecl *functionDecl ); 74 75 virtual void visit( FunctionType *ftype ); 76 virtual void visit( PointerType *ftype ); 77 78 virtual void visit( CompoundStmt *compoundStmt ); 79 virtual void visit( SwitchStmt *switchStmt ); 59 void previsit( EnumDecl * enumDecl ); 60 void previsit( StructDecl * structDecl ); 61 void previsit( UnionDecl * structDecl ); 62 void previsit( TypeDecl * typeDecl ); 63 void previsit( TraitDecl * traitDecl ); 64 void previsit( FunctionDecl * functionDecl ); 65 66 void previsit( FunctionType * ftype ); 67 void previsit( PointerType * ptype ); 68 69 void previsit( CompoundStmt * compoundStmt ); 80 70 81 71 private: 82 template< typename StmtClass > void visitStatement( StmtClass *stmt ); 83 84 std::list< Declaration * > declsToAdd, declsToAddAfter; 85 std::set< std::string > structsDone; 72 GenPoly::ScopedSet< std::string > structsDone; 86 73 unsigned int functionNesting = 0; // current level of nested functions 87 74 /// Note: the following maps could be ScopedSets, but it should be easier to work … … 112 99 113 100 void autogenerateRoutines( std::list< Declaration * > &translationUnit ) { 114 AutogenerateRoutinesgenerator;115 acceptA ndAdd( translationUnit, generator );101 PassVisitor<AutogenerateRoutines> generator; 102 acceptAll( translationUnit, generator ); 116 103 117 104 // needs to be done separately because AutogenerateRoutines skips types that appear as function arguments, etc. … … 572 559 // the order here determines the order that these functions are generated. 573 560 // assignment should come last since it uses copy constructor in return. 574 data.push_back( FuncData( "?{}", genDefaultType, constructable ) ); 575 data.push_back( FuncData( "?{}", genCopyType, copyable ) ); 576 data.push_back( FuncData( "^?{}", genDefaultType, destructable ) ); 577 data.push_back( FuncData( "?=?", genAssignType, assignable ) ); 578 } 579 580 void AutogenerateRoutines::visit( EnumDecl *enumDecl ) { 561 data.emplace_back( "?{}", genDefaultType, constructable ); 562 data.emplace_back( "?{}", genCopyType, copyable ); 563 data.emplace_back( "^?{}", genDefaultType, destructable ); 564 data.emplace_back( "?=?", genAssignType, assignable ); 565 } 566 567 void AutogenerateRoutines::previsit( EnumDecl *enumDecl ) { 568 visit_children = false; 581 569 if ( ! enumDecl->get_members().empty() ) { 582 570 EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() ); … … 586 574 } 587 575 588 void AutogenerateRoutines::visit( StructDecl *structDecl ) { 576 void AutogenerateRoutines::previsit( StructDecl *structDecl ) { 577 visit_children = false; 589 578 if ( structDecl->has_body() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 590 579 StructInstType structInst( Type::Qualifiers(), structDecl->get_name() ); 591 580 for ( TypeDecl * typeDecl : structDecl->get_parameters() ) { 592 581 // need to visit assertions so that they are added to the appropriate maps 593 acceptAll( typeDecl->get_assertions(), * this);582 acceptAll( typeDecl->get_assertions(), *visitor ); 594 583 structInst.get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) ); 595 584 } … … 600 589 } 601 590 602 void AutogenerateRoutines::visit( UnionDecl *unionDecl ) { 591 void AutogenerateRoutines::previsit( UnionDecl *unionDecl ) { 592 visit_children = false; 603 593 if ( ! unionDecl->get_members().empty() ) { 604 594 UnionInstType unionInst( Type::Qualifiers(), unionDecl->get_name() ); … … 619 609 620 610 // generate ctor/dtors/assign for typedecls, e.g., otype T = int *; 621 void AutogenerateRoutines::visit( TypeDecl *typeDecl ) { 611 void AutogenerateRoutines::previsit( TypeDecl *typeDecl ) { 612 visit_children = false; 622 613 if ( ! typeDecl->base ) return; 623 614 … … 664 655 } 665 656 666 void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) { 667 for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) { 668 statements.insert( i, new DeclStmt( noLabels, *decl ) ); 669 } // for 670 declsToAdd.clear(); 671 } 672 673 void AutogenerateRoutines::visit( FunctionType *) { 657 void AutogenerateRoutines::previsit( FunctionType *) { 674 658 // ensure that we don't add assignment ops for types defined as part of the function 675 } 676 677 void AutogenerateRoutines::visit( PointerType *) { 659 visit_children = false; 660 } 661 662 void AutogenerateRoutines::previsit( PointerType *) { 678 663 // ensure that we don't add assignment ops for types defined as part of the pointer 679 } 680 681 void AutogenerateRoutines::visit( TraitDecl *) { 664 visit_children = false; 665 } 666 667 void AutogenerateRoutines::previsit( TraitDecl * ) { 682 668 // ensure that we don't add assignment ops for types defined as part of the trait 683 } 684 685 template< typename StmtClass > 686 inline void AutogenerateRoutines::visitStatement( StmtClass *stmt ) { 687 std::set< std::string > oldStructs = structsDone; 688 addVisit( stmt, *this ); 689 structsDone = oldStructs; 690 } 691 692 void AutogenerateRoutines::visit( FunctionDecl *functionDecl ) { 669 visit_children = false; 670 } 671 672 void AutogenerateRoutines::previsit( FunctionDecl * functionDecl ) { 673 visit_children = false; 693 674 // record the existence of this function as appropriate 694 675 insert( functionDecl, constructable, InitTweak::isDefaultConstructor ); … … 697 678 insert( functionDecl, destructable, InitTweak::isDestructor ); 698 679 699 maybeAccept( functionDecl->get_functionType(), * this);680 maybeAccept( functionDecl->get_functionType(), *visitor ); 700 681 functionNesting += 1; 701 maybeAccept( functionDecl->get_statements(), * this);682 maybeAccept( functionDecl->get_statements(), *visitor ); 702 683 functionNesting -= 1; 703 684 } 704 685 705 void AutogenerateRoutines::visit( CompoundStmt *compoundStmt ) { 706 constructable.beginScope(); 707 assignable.beginScope(); 708 copyable.beginScope(); 709 destructable.beginScope(); 710 visitStatement( compoundStmt ); 711 constructable.endScope(); 712 assignable.endScope(); 713 copyable.endScope(); 714 destructable.endScope(); 715 } 716 717 void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) { 718 visitStatement( switchStmt ); 686 void AutogenerateRoutines::previsit( CompoundStmt * ) { 687 GuardScope( constructable ); 688 GuardScope( assignable ); 689 GuardScope( copyable ); 690 GuardScope( destructable ); 691 GuardScope( structsDone ); 719 692 } 720 693 -
src/main.cc
r47b5b63 re4d6335 239 239 } // if 240 240 241 // OPTPRINT( "Concurrency" )242 // Concurrency::applyKeywords( translationUnit );243 244 241 // add the assignment statement after the initialization of a type parameter 245 242 OPTPRINT( "validate" )
Note: See TracChangeset
for help on using the changeset viewer.