Changes in src/ResolvExpr/Unify.cc [f0ecf9b:ea6332d]
- File:
-
- 1 edited
-
src/ResolvExpr/Unify.cc (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
rf0ecf9b rea6332d 17 17 #include <iterator> // for back_insert_iterator, back_inserter 18 18 #include <map> // for _Rb_tree_const_iterator, _Rb_tree_i... 19 #include <memory> // for unique_ptr 19 #include <memory> // for unique_ptr, auto_ptr 20 20 #include <set> // for set 21 21 #include <string> // for string, operator==, operator!=, bas... 22 22 #include <utility> // for pair 23 23 24 #include "Common/PassVisitor.h" // for PassVisitor25 24 #include "FindOpenVars.h" // for findOpenVars 26 25 #include "Parser/LinkageSpec.h" // for C … … 54 53 virtual void visit(PointerType *pointerType); 55 54 virtual void visit(ArrayType *arrayType); 56 virtual void visit(ReferenceType *refType);57 55 virtual void visit(FunctionType *functionType); 58 56 virtual void visit(StructInstType *aggregateUseType); … … 138 136 bool tyVarCompatible( const TypeDecl::Data & data, Type *type ) { 139 137 switch ( data.kind ) { 138 case TypeDecl::Any: 140 139 case TypeDecl::Dtype: 141 140 // to bind to an object type variable, the type must not be a function type. … … 154 153 155 154 bool bindVar( TypeInstType *typeInst, Type *other, const TypeDecl::Data & data, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) { 156 // remove references from other, so that type variables can only bind to value types157 other = other->stripReferences();158 155 OpenVarSet::const_iterator tyvar = openVars.find( typeInst->get_name() ); 159 156 assert( tyvar != openVars.end() ); … … 169 166 Type *common = 0; 170 167 // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to 171 std:: unique_ptr< Type > newType( curClass.type->clone() );168 std::auto_ptr< Type > newType( curClass.type->clone() ); 172 169 newType->get_qualifiers() = typeInst->get_qualifiers(); 173 170 if ( unifyInexact( newType.get(), other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass.allowWidening, true ), indexer, common ) ) { … … 390 387 } // if 391 388 } else { 392 common = type1->clone();393 common->get_qualifiers() = tq1 | tq2;394 389 result = true; 395 390 } // if … … 444 439 } 445 440 446 void Unify::visit(ReferenceType *refType) {447 if ( ReferenceType *otherRef = dynamic_cast< ReferenceType* >( type2 ) ) {448 result = unifyExact( refType->get_base(), otherRef->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );449 markAssertions( haveAssertions, needAssertions, refType );450 markAssertions( haveAssertions, needAssertions, otherRef );451 } // if452 }453 454 441 void Unify::visit(ArrayType *arrayType) { 455 442 ArrayType *otherArray = dynamic_cast< ArrayType* >( type2 ); … … 457 444 // and must both have a dimension expression or not have a dimension 458 445 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) { 446 447 // not positive this is correct in all cases, but it's needed for typedefs 448 if ( arrayType->get_isVarLen() || otherArray->get_isVarLen() ) { 449 return; 450 } 459 451 460 452 if ( ! arrayType->get_isVarLen() && ! otherArray->get_isVarLen() && … … 532 524 /// If this isn't done then argument lists can have wildly different 533 525 /// size and structure, when they should be compatible. 534 struct TtypeExpander : public WithShortCircuiting { 535 TypeEnvironment & tenv; 536 TtypeExpander( TypeEnvironment & tenv ) : tenv( tenv ) {} 537 void premutate( TypeInstType * ) { visit_children = false; } 538 Type * postmutate( TypeInstType * typeInst ) { 526 struct TtypeExpander : public Mutator { 527 TypeEnvironment & env; 528 TtypeExpander( TypeEnvironment & env ) : env( env ) {} 529 Type * mutate( TypeInstType * typeInst ) { 539 530 EqvClass eqvClass; 540 if ( tenv.lookup( typeInst->get_name(), eqvClass ) ) {531 if ( env.lookup( typeInst->get_name(), eqvClass ) ) { 541 532 if ( eqvClass.data.kind == TypeDecl::Ttype ) { 542 533 // expand ttype parameter into its actual type … … 556 547 dst.clear(); 557 548 for ( DeclarationWithType * dcl : src ) { 558 PassVisitor<TtypeExpander>expander( env );549 TtypeExpander expander( env ); 559 550 dcl->acceptMutator( expander ); 560 551 std::list< Type * > types; … … 746 737 std::list<Type *> types1, types2; 747 738 748 PassVisitor<TtypeExpander>expander( env );739 TtypeExpander expander( env ); 749 740 flat1->acceptMutator( expander ); 750 741 flat2->acceptMutator( expander );
Note:
See TracChangeset
for help on using the changeset viewer.