Changes in src/SymTab/Validate.cc [37a3b8f9:f066321]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r37a3b8f9 rf066321 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T ue Aug 11 16:59:35 201513 // Update Count : 19 611 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Nov 19 10:44:55 2015 13 // Update Count : 199 14 14 // 15 15 … … 54 54 #include "MakeLibCfa.h" 55 55 #include "TypeEquality.h" 56 #include "ResolvExpr/typeops.h" 56 57 57 58 #define debugPrint( x ) if ( doDebug ) { std::cout << x; } … … 125 126 }; 126 127 127 class A ddStructAssignment: public Visitor {128 class AutogenerateRoutines : public Visitor { 128 129 public: 129 130 /// Generates assignment operators for aggregate types as required 130 static void a ddStructAssignment( std::list< Declaration * > &translationUnit );131 static void autogenerateRoutines( std::list< Declaration * > &translationUnit ); 131 132 132 133 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } … … 151 152 virtual void visit( CatchStmt *catchStmt ); 152 153 153 A ddStructAssignment() : functionNesting( 0 ) {}154 AutogenerateRoutines() : functionNesting( 0 ) {} 154 155 private: 155 156 template< typename StmtClass > void visitStatement( StmtClass *stmt ); … … 195 196 acceptAll( translationUnit, pass1 ); 196 197 acceptAll( translationUnit, pass2 ); 197 // need to collect all of the assignment operators prior to 198 // this point and only generate assignment operators if one doesn't exist 199 AddStructAssignment::addStructAssignment( translationUnit ); 198 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 200 199 acceptAll( translationUnit, pass3 ); 201 200 } … … 501 500 static const std::list< std::string > noLabels; 502 501 503 void A ddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {504 A ddStructAssignmentvisitor;502 void AutogenerateRoutines::autogenerateRoutines( std::list< Declaration * > &translationUnit ) { 503 AutogenerateRoutines visitor; 505 504 acceptAndAdd( translationUnit, visitor, false ); 506 505 } … … 629 628 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 630 629 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 631 632 // Make function polymorphic in same parameters as generic struct, if applicable633 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();634 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {635 assignType->get_forall().push_back( (*param)->clone() );636 }637 630 638 631 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); … … 704 697 } 705 698 706 void A ddStructAssignment::visit( EnumDecl *enumDecl ) {699 void AutogenerateRoutines::visit( EnumDecl *enumDecl ) { 707 700 if ( ! enumDecl->get_members().empty() ) { 708 701 EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() ); … … 713 706 } 714 707 715 void A ddStructAssignment::visit( StructDecl *structDecl ) {708 void AutogenerateRoutines::visit( StructDecl *structDecl ) { 716 709 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 717 710 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() ); … … 722 715 } 723 716 724 void A ddStructAssignment::visit( UnionDecl *unionDecl ) {717 void AutogenerateRoutines::visit( UnionDecl *unionDecl ) { 725 718 if ( ! unionDecl->get_members().empty() ) { 726 719 UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() ); … … 730 723 } 731 724 732 void A ddStructAssignment::visit( TypeDecl *typeDecl ) {725 void AutogenerateRoutines::visit( TypeDecl *typeDecl ) { 733 726 CompoundStmt *stmts = 0; 734 727 TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false ); … … 758 751 } 759 752 760 void A ddStructAssignment::visit( FunctionType *) {753 void AutogenerateRoutines::visit( FunctionType *) { 761 754 // ensure that we don't add assignment ops for types defined as part of the function 762 755 } 763 756 764 void A ddStructAssignment::visit( PointerType *) {757 void AutogenerateRoutines::visit( PointerType *) { 765 758 // ensure that we don't add assignment ops for types defined as part of the pointer 766 759 } 767 760 768 void A ddStructAssignment::visit( ContextDecl *) {761 void AutogenerateRoutines::visit( ContextDecl *) { 769 762 // ensure that we don't add assignment ops for types defined as part of the context 770 763 } 771 764 772 765 template< typename StmtClass > 773 inline void A ddStructAssignment::visitStatement( StmtClass *stmt ) {766 inline void AutogenerateRoutines::visitStatement( StmtClass *stmt ) { 774 767 std::set< std::string > oldStructs = structsDone; 775 768 addVisit( stmt, *this ); … … 777 770 } 778 771 779 void A ddStructAssignment::visit( FunctionDecl *functionDecl ) {772 void AutogenerateRoutines::visit( FunctionDecl *functionDecl ) { 780 773 maybeAccept( functionDecl->get_functionType(), *this ); 781 774 acceptAll( functionDecl->get_oldDecls(), *this ); … … 785 778 } 786 779 787 void A ddStructAssignment::visit( CompoundStmt *compoundStmt ) {780 void AutogenerateRoutines::visit( CompoundStmt *compoundStmt ) { 788 781 visitStatement( compoundStmt ); 789 782 } 790 783 791 void A ddStructAssignment::visit( IfStmt *ifStmt ) {784 void AutogenerateRoutines::visit( IfStmt *ifStmt ) { 792 785 visitStatement( ifStmt ); 793 786 } 794 787 795 void A ddStructAssignment::visit( WhileStmt *whileStmt ) {788 void AutogenerateRoutines::visit( WhileStmt *whileStmt ) { 796 789 visitStatement( whileStmt ); 797 790 } 798 791 799 void A ddStructAssignment::visit( ForStmt *forStmt ) {792 void AutogenerateRoutines::visit( ForStmt *forStmt ) { 800 793 visitStatement( forStmt ); 801 794 } 802 795 803 void A ddStructAssignment::visit( SwitchStmt *switchStmt ) {796 void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) { 804 797 visitStatement( switchStmt ); 805 798 } 806 799 807 void A ddStructAssignment::visit( ChooseStmt *switchStmt ) {800 void AutogenerateRoutines::visit( ChooseStmt *switchStmt ) { 808 801 visitStatement( switchStmt ); 809 802 } 810 803 811 void A ddStructAssignment::visit( CaseStmt *caseStmt ) {804 void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 812 805 visitStatement( caseStmt ); 813 806 } 814 807 815 void A ddStructAssignment::visit( CatchStmt *cathStmt ) {808 void AutogenerateRoutines::visit( CatchStmt *cathStmt ) { 816 809 visitStatement( cathStmt ); 817 810 } … … 857 850 Type * t1 = tyDecl->get_base(); 858 851 Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base(); 859 if ( ! typeEquals( t1, t2, true) ) {852 if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) { 860 853 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() ); 861 854 }
Note: See TracChangeset
for help on using the changeset viewer.