Changes in src/InitTweak/FixInit.cc [b16898e:c8dfcd3]
- File:
-
- 1 edited
-
src/InitTweak/FixInit.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
rb16898e rc8dfcd3 200 200 ObjectDecl * thisParam = 0; 201 201 bool isCtor = false; // true if current function is a constructor 202 StructDecl * structDecl = 0;203 202 }; 204 203 … … 745 744 ValueGuard< ObjectDecl * > oldThisParam( thisParam ); 746 745 ValueGuard< bool > oldIsCtor( isCtor ); 747 ValueGuard< StructDecl * > oldStructDecl( structDecl );748 746 749 747 // need to start with fresh sets … … 760 758 StructInstType * structType = dynamic_cast< StructInstType * >( ptrType->get_base() ); 761 759 if ( structType ) { 762 structDecl = structType->get_baseStruct();760 StructDecl * structDecl = structType->get_baseStruct(); 763 761 for ( Declaration * member : structDecl->get_members() ) { 764 762 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { … … 777 775 std::set_difference( usedUninit.begin(), usedUninit.end(), unhandled.begin(), unhandled.end(), std::inserter( diff, diff.begin() ) ); 778 776 for ( DeclarationWithType * member : diff ) { 779 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field", member->get_name(), " used before being constructed" );777 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", member ", member->get_name(), " used before being constructed" ); 780 778 } 781 779 … … 783 781 // need to explicitly re-add function parameters in order to resolve copy constructors 784 782 enterScope(); 785 maybeAccept( function->get_functionType(), *this ); 786 787 // need to iterate through members in reverse in order for 788 // ctor/dtor statements to come out in the right order 789 for ( Declaration * member : reverseIterate( structDecl->get_members() ) ) { 790 DeclarationWithType * field = dynamic_cast< DeclarationWithType * >( member ); 791 // skip non-DWT members 792 if ( ! field ) continue; 793 // skip handled members 794 if ( ! unhandled.count( field ) ) continue; 795 796 // insert and resolve default/copy constructor call for each field that's unhandled 783 // maybeAccept( function->get_functionType(), *this ); 784 for ( DeclarationWithType * member : unhandled ) { 785 // insert and resolve default/copy constructor call for each member that's unhandled 797 786 std::list< Statement * > stmt; 798 787 UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) ); 799 788 deref->get_args().push_back( new VariableExpr( thisParam ) ); 800 801 Expression * arg2 = 0; 802 if ( isCopyConstructor( function ) ) { 803 // if copy ctor, need to pass second-param-of-this-function.field 804 std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters(); 805 assert( params.size() == 2 ); 806 arg2 = new MemberExpr( field, new VariableExpr( params.back() ) ); 807 } 808 InitExpander srcParam( arg2 ); 809 SymTab::genImplicitCall( srcParam, new MemberExpr( field, deref ), function->get_name(), back_inserter( stmt ), field, isCtor ); 789 InitExpander srcParam( (Initializer *)NULL ); // xxx - if copy ctor, need to pass appropriate argument - second param of this function dot member 790 SymTab::genImplicitCall( srcParam, new MemberExpr( member, deref ), function->get_name(), back_inserter( stmt ), member, isCtor ); 810 791 811 792 assert( stmt.size() <= 1 ); … … 815 796 MutatingResolver resolver( *this ); 816 797 try { 798 // xxx - these should be in field declaration order 817 799 callStmt->acceptMutator( resolver ); 818 800 if ( isCtor ) { … … 823 805 } 824 806 } catch ( SemanticError & error ) { 825 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field ", field->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed", " and no ", isCtor ? "default constructor" : "destructor", " found" );807 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", member ", member->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed", " and no ", isCtor ? "default constructor" : "destructor", " found" ); 826 808 } 827 809 } … … 850 832 handleFirstParam( firstParam ); 851 833 } 834 } else if ( fname == "?=?" && isIntrinsicCallExpr( appExpr ) ) { 835 // forgive use of intrinsic assignment to construct, since instrinsic constructors 836 // codegen as assignment anyway. 837 assert( appExpr->get_args().size() == 2 ); 838 handleFirstParam( appExpr->get_args().front() ); 852 839 } 853 840
Note:
See TracChangeset
for help on using the changeset viewer.