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