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