Changeset 98735ef
- Timestamp:
- Feb 11, 2016, 3:28:23 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- cce7872
- Parents:
- 408d460
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r408d460 r98735ef 1399 1399 delete memberExpr; 1400 1400 return fieldLoc; 1401 } else if ( UnionInstType *unionType =dynamic_cast< UnionInstType* >( objectType ) ) {1401 } else if ( dynamic_cast< UnionInstType* >( objectType ) ) { 1402 1402 // union members are all at offset zero, so build appropriately-dereferenced variable 1403 1403 Expression *derefdVar = makeDerefdVar( varExpr->clone(), varDepth ); -
src/SymTab/Validate.cc
r408d460 r98735ef 382 382 // it's not a semantic error if the struct is not found, just an implicit forward declaration 383 383 if ( st ) { 384 assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );384 //assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() ); 385 385 structInst->set_baseStruct( st ); 386 386 } // if … … 659 659 } 660 660 661 /// Creates a new type decl that's the same as src, but renamed and with only the ?=? assertion (for complete types only) 662 TypeDecl *cloneAndRename( TypeDecl *src, const std::string &name ) { 663 TypeDecl *dst = new TypeDecl( name, src->get_storageClass(), 0, src->get_kind() ); 664 665 if ( src->get_kind() == TypeDecl::Any ) { 666 // just include assignment operator assertion 667 TypeInstType *assignParamType = new TypeInstType( Type::Qualifiers(), name, dst ); 668 FunctionType *assignFunctionType = new FunctionType( Type::Qualifiers(), false ); 669 assignFunctionType->get_returnVals().push_back( 670 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, assignParamType->clone(), 0 ) ); 671 assignFunctionType->get_parameters().push_back( 672 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), assignParamType->clone() ), 0 ) ); 673 assignFunctionType->get_parameters().push_back( 674 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, assignParamType, 0 ) ); 675 FunctionDecl *assignAssert = new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignFunctionType, 0, false, false ); 676 dst->get_assertions().push_back( assignAssert ); 677 } 678 679 return dst; 680 } 681 661 682 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 662 683 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); … … 666 687 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 667 688 std::list< Expression* > structParams; // List of matching parameters to put on types 689 TypeSubstitution genericSubs; // Substitutions to make to member types of struct 668 690 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 669 691 isGeneric = true; 670 TypeDecl *typeParam = (*param)->clone();692 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 671 693 assignType->get_forall().push_back( typeParam ); 672 structParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) ); 694 TypeInstType *newParamType = new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ); 695 genericSubs.add( (*param)->get_name(), newParamType ); 696 structParams.push_back( new TypeExpr( newParamType ) ); 673 697 } 674 698 … … 701 725 } 702 726 703 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) { 704 makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 705 if ( isGeneric ) makeArrayAssignment( srcParam, returnVal, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 727 if ( isGeneric ) { 728 // rewrite member type in terms of the type variables on this operator 729 DeclarationWithType *fixedMember = dwt->clone(); 730 genericSubs.apply( fixedMember ); 731 732 // assign to both destination and return value 733 if ( ArrayType *array = dynamic_cast< ArrayType * >( fixedMember->get_type() ) ) { 734 makeArrayAssignment( srcParam, dstParam, fixedMember, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 735 makeArrayAssignment( srcParam, returnVal, fixedMember, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 736 } else { 737 makeScalarAssignment( srcParam, dstParam, fixedMember, back_inserter( assignDecl->get_statements()->get_kids() ) ); 738 makeScalarAssignment( srcParam, returnVal, fixedMember, back_inserter( assignDecl->get_statements()->get_kids() ) ); 739 } // if 706 740 } else { 707 makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 708 if ( isGeneric ) makeScalarAssignment( srcParam, returnVal, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 741 // assign to destination 742 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) { 743 makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 744 } else { 745 makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 746 } // if 709 747 } // if 710 748 } // if … … 724 762 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 725 763 isGeneric = true; 726 TypeDecl *typeParam = (*param)->clone();764 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 727 765 assignType->get_forall().push_back( typeParam ); 728 766 unionParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) );
Note: See TracChangeset
for help on using the changeset viewer.