Changeset a172972 for src/SymTab
- Timestamp:
- Feb 23, 2016, 11:20:39 AM (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, with_gc
- Children:
- ae42f2a
- Parents:
- 7528ba1 (diff), 6ce67ce (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r7528ba1 ra172972 396 396 // it's not a semantic error if the struct is not found, just an implicit forward declaration 397 397 if ( st ) { 398 assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );398 //assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() ); 399 399 structInst->set_baseStruct( st ); 400 400 } // if … … 673 673 } 674 674 675 /// Creates a new type decl that's the same as src, but renamed and with only the ?=? assertion (for complete types only) 676 TypeDecl *cloneAndRename( TypeDecl *src, const std::string &name ) { 677 TypeDecl *dst = new TypeDecl( name, src->get_storageClass(), 0, src->get_kind() ); 678 679 if ( src->get_kind() == TypeDecl::Any ) { 680 // just include assignment operator assertion 681 TypeInstType *assignParamType = new TypeInstType( Type::Qualifiers(), name, dst ); 682 FunctionType *assignFunctionType = new FunctionType( Type::Qualifiers(), false ); 683 assignFunctionType->get_returnVals().push_back( 684 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, assignParamType->clone(), 0 ) ); 685 assignFunctionType->get_parameters().push_back( 686 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), assignParamType->clone() ), 0 ) ); 687 assignFunctionType->get_parameters().push_back( 688 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, assignParamType, 0 ) ); 689 FunctionDecl *assignAssert = new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignFunctionType, 0, false, false ); 690 dst->get_assertions().push_back( assignAssert ); 691 } 692 693 return dst; 694 } 695 675 696 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 676 697 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); … … 680 701 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 681 702 std::list< Expression* > structParams; // List of matching parameters to put on types 703 TypeSubstitution genericSubs; // Substitutions to make to member types of struct 682 704 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 683 705 isGeneric = true; 684 TypeDecl *typeParam = (*param)->clone();706 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 685 707 assignType->get_forall().push_back( typeParam ); 686 structParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) ); 708 TypeInstType *newParamType = new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ); 709 genericSubs.add( (*param)->get_name(), newParamType ); 710 structParams.push_back( new TypeExpr( newParamType ) ); 687 711 } 688 712 … … 715 739 } 716 740 717 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) { 718 makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 719 if ( isGeneric ) makeArrayAssignment( srcParam, returnVal, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 741 if ( isGeneric ) { 742 // rewrite member type in terms of the type variables on this operator 743 DeclarationWithType *fixedMember = dwt->clone(); 744 genericSubs.apply( fixedMember ); 745 746 // assign to both destination and return value 747 if ( ArrayType *array = dynamic_cast< ArrayType * >( fixedMember->get_type() ) ) { 748 makeArrayAssignment( srcParam, dstParam, fixedMember, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 749 makeArrayAssignment( srcParam, returnVal, fixedMember, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 750 } else { 751 makeScalarAssignment( srcParam, dstParam, fixedMember, back_inserter( assignDecl->get_statements()->get_kids() ) ); 752 makeScalarAssignment( srcParam, returnVal, fixedMember, back_inserter( assignDecl->get_statements()->get_kids() ) ); 753 } // if 720 754 } else { 721 makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 722 if ( isGeneric ) makeScalarAssignment( srcParam, returnVal, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 755 // assign to destination 756 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) { 757 makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 758 } else { 759 makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 760 } // if 723 761 } // if 724 762 } // if … … 799 837 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 800 838 isGeneric = true; 801 TypeDecl *typeParam = (*param)->clone();839 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 802 840 assignType->get_forall().push_back( typeParam ); 803 841 unionParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) );
Note: See TracChangeset
for help on using the changeset viewer.