Changeset 44f6341
- Timestamp:
- Sep 2, 2016, 1:30:36 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, 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:
- 85517ddb
- Parents:
- 4d4882a
- git-author:
- Rob Schluntz <rschlunt@…> (09/01/16 17:14:32)
- git-committer:
- Rob Schluntz <rschlunt@…> (09/02/16 13:30:36)
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
r4d4882a r44f6341 260 260 }; 261 261 262 template< typename T > 263 struct ReverseIter { 264 T& ref; 265 266 ReverseIter( T & ref ) : ref(ref) {} 267 268 typedef typename T::reverse_iterator iterator; 269 iterator begin() { return ref.rbegin(); } 270 iterator end() { return ref.rend(); } 271 }; 272 273 template< typename T > 274 ReverseIter< T > ReverseIterate( T & ref ) { 275 return ReverseIter< T >( ref ); 276 } 277 262 278 #endif // _UTILITY_H 263 279 -
src/InitTweak/FixInit.cc
r4d4882a r44f6341 200 200 ObjectDecl * thisParam = 0; 201 201 bool isCtor = false; // true if current function is a constructor 202 StructDecl * structDecl = 0; 202 203 }; 203 204 … … 744 745 ValueGuard< ObjectDecl * > oldThisParam( thisParam ); 745 746 ValueGuard< bool > oldIsCtor( isCtor ); 747 ValueGuard< StructDecl * > oldStructDecl( structDecl ); 746 748 747 749 // need to start with fresh sets … … 758 760 StructInstType * structType = dynamic_cast< StructInstType * >( ptrType->get_base() ); 759 761 if ( structType ) { 760 StructDecl *structDecl = structType->get_baseStruct();762 structDecl = structType->get_baseStruct(); 761 763 for ( Declaration * member : structDecl->get_members() ) { 762 764 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { … … 775 777 std::set_difference( usedUninit.begin(), usedUninit.end(), unhandled.begin(), unhandled.end(), std::inserter( diff, diff.begin() ) ); 776 778 for ( DeclarationWithType * member : diff ) { 777 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", member", member->get_name(), " used before being constructed" );779 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field ", member->get_name(), " used before being constructed" ); 778 780 } 779 781 … … 782 784 enterScope(); 783 785 // maybeAccept( function->get_functionType(), *this ); 784 for ( DeclarationWithType * member : unhandled ) { 785 // insert and resolve default/copy constructor call for each member that's unhandled 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 786 797 std::list< Statement * > stmt; 787 798 UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) ); … … 790 801 Expression * arg2 = 0; 791 802 if ( isCopyConstructor( function ) ) { 792 // if copy ctor, need to pass second-param-of-this-function. member803 // if copy ctor, need to pass second-param-of-this-function.field 793 804 std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters(); 794 805 assert( params.size() == 2 ); 795 arg2 = new MemberExpr( member, new VariableExpr( params.back() ) );806 arg2 = new MemberExpr( field, new VariableExpr( params.back() ) ); 796 807 } 797 808 InitExpander srcParam( arg2 ); 798 SymTab::genImplicitCall( srcParam, new MemberExpr( member, deref ), function->get_name(), back_inserter( stmt ), member, isCtor );809 SymTab::genImplicitCall( srcParam, new MemberExpr( field, deref ), function->get_name(), back_inserter( stmt ), field, isCtor ); 799 810 800 811 assert( stmt.size() <= 1 ); … … 813 824 } 814 825 } catch ( SemanticError & error ) { 815 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 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" ); 816 827 } 817 828 } -
src/tests/.expect/memberCtors-ERR1.txt
r4d4882a r44f6341 1 1 CFA Version 1.0.0 (debug) 2 Error: in void ?{}(struct B *b), membera2 used before being constructed2 Error: in void ?{}(struct B *b), field a2 used before being constructed 3 3 make: *** [memberCtors-ERR1] Error 1 -
src/tests/.expect/memberCtors.txt
r4d4882a r44f6341 1 Before declaration of b1 1 2 constructing int 2 3 constructing int … … 16 17 destructing int: 0 17 18 destructing int: 1001 19 Before declaration of b2 18 20 copy constructing int: 0 19 21 copy constructing int: 0 … … 25 27 copy constructing int: 0 26 28 copy constructing int: 0 29 End of main 27 30 constructing int 28 31 constructing int … … 37 40 destructing int: 0 38 41 destructing int: 0 39 destructing int: 99940 42 destructing int: 0 41 43 destructing int: 0 42 44 destructing int: 0 45 destructing int: 999 43 46 constructing int 44 47 constructing int … … 53 56 destructing int: 0 54 57 destructing int: 0 55 destructing int: 99956 58 destructing int: 0 57 59 destructing int: 0 58 60 destructing int: 0 61 destructing int: 999 -
src/tests/memberCtors.c
r4d4882a r44f6341 59 59 60 60 int main() { 61 printf("Before declaration of b1\n"); 61 62 B b1; 63 printf("Before declaration of b2\n"); 62 64 B b2 = b1; 65 printf("End of main\n"); 63 66 }
Note: See TracChangeset
for help on using the changeset viewer.