Changeset b21c77a for src/ResolvExpr/TypeEnvironment.cc
- Timestamp:
- Jun 29, 2018, 4:14:15 PM (6 years ago)
- Branches:
- new-env
- Children:
- 184557e
- Parents:
- 97397a26 (diff), 28f3a19 (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/ResolvExpr/TypeEnvironment.cc
r97397a26 rb21c77a 7 7 // TypeEnvironment.cc -- 8 8 // 9 // Author : Richard C. Bilson9 // Author : Aaron B. Moss 10 10 // Created On : Sun May 17 12:19:47 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun May 17 12:23:36 201513 // Update Count : 311 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Fri Jun 29 15:51:00 2018 13 // Update Count : 5 14 14 // 15 15 … … 27 27 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution 28 28 #include "TypeEnvironment.h" 29 #include "typeops.h" // for occurs 29 30 #include "Unify.h" // for unifyInexact 30 31 … … 50 51 #if 0 51 52 void EqvClass::initialize( const EqvClass &src, EqvClass &dest ) { 53 initialize( src, dest, src.type ); 54 } 55 56 void EqvClass::initialize( const EqvClass &src, EqvClass &dest, const Type *ty ) { 52 57 dest.vars = src.vars; 53 dest.type = maybeClone( src.type);58 dest.type = maybeClone( ty ); 54 59 dest.allowWidening = src.allowWidening; 55 60 dest.data = src.data; 56 61 } 57 62 58 EqvClass::EqvClass() : vars(), type( 0 ), allowWidening( true ), data() {} 59 60 EqvClass::EqvClass( std::vector<interned_string>&& vs, BoundType&& bound ) 61 : vars( vs.begin(), vs.end() ), type( maybeClone( bound.type ) ), 62 allowWidening( bound.allowWidening ), data( bound.data ) {} 63 EqvClass::EqvClass() : type( nullptr ), allowWidening( true ) { 64 } 63 65 64 66 EqvClass::EqvClass( const EqvClass &other ) { 65 67 initialize( other, *this ); 68 } 69 70 EqvClass::EqvClass( const EqvClass &other, const Type *ty ) { 71 initialize( other, *this, ty ); 72 } 73 74 EqvClass::EqvClass( EqvClass &&other ) 75 : vars{std::move(other.vars)}, type{other.type}, 76 allowWidening{std::move(other.allowWidening)}, data{std::move(other.data)} { 77 other.type = nullptr; 66 78 } 67 79 … … 71 83 return *this; 72 84 } 85 86 EqvClass &EqvClass::operator=( EqvClass &&other ) { 87 if ( this == &other ) return *this; 88 89 vars = std::move(other.vars); 90 type = other.type; 91 allowWidening = std::move(other.allowWidening); 92 data = std::move(other.data); 93 94 return *this; 95 } 96 97 void EqvClass::set_type( Type* ty ) { type = ty; } 73 98 74 99 void EqvClass::print( std::ostream &os, Indenter indent ) const { … … 88 113 const EqvClass* TypeEnvironment::lookup( const std::string &var ) const { 89 114 for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i ) { 90 if ( i->vars.find( var ) != i->vars.end() ) { 91 /// std::cout << var << " is in class "; 92 /// i->print( std::cout ); 93 return &*i; 94 } 95 /// std::cout << var << " is not in class "; 96 /// i->print( std::cout ); 115 if ( i->vars.find( var ) != i->vars.end() ) return &*i; 97 116 } // for 98 117 return nullptr; … … 118 137 if ( root ) return { this, root }; 119 138 else return { nullptr, var }; 139 } 140 141 bool isFtype( Type *type ) { 142 if ( dynamic_cast< FunctionType* >( type ) ) { 143 return true; 144 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { 145 return typeInst->get_isFtype(); 146 } // if 147 return false; 120 148 } 121 149 … … 288 316 } 289 317 290 void TypeEnvironment::add( const EqvClass &eqvClass ) {291 filterOverlappingClasses( env, eqvClass );292 env.push_back( eqvClass );293 }294 295 318 void TypeEnvironment::add( EqvClass &&eqvClass ) { 296 319 filterOverlappingClasses( env, eqvClass ); … … 303 326 newClass.vars.insert( (*i)->get_name() ); 304 327 newClass.data = TypeDecl::Data{ (*i) }; 305 env.push_back( newClass);328 env.push_back( std::move(newClass) ); 306 329 } // for 307 330 } … … 317 340 // transition to TypeSubstitution 318 341 newClass.data = TypeDecl::Data{ TypeDecl::Dtype, false }; 319 add( newClass);342 add( std::move(newClass) ); 320 343 } 321 344 } … … 324 347 for ( std::list< EqvClass >::const_iterator theClass = env.begin(); theClass != env.end(); ++theClass ) { 325 348 for ( std::set< std::string >::const_iterator theVar = theClass->vars.begin(); theVar != theClass->vars.end(); ++theVar ) { 326 /// std::cerr << "adding " << *theVar;327 349 if ( theClass->type ) { 328 /// std::cerr << " bound to ";329 /// theClass->type->print( std::cerr );330 /// std::cerr << std::endl;331 350 sub.add( *theVar, theClass->type ); 332 351 } else if ( theVar != theClass->vars.begin() ) { 333 352 TypeInstType *newTypeInst = new TypeInstType( Type::Qualifiers(), *theClass->vars.begin(), theClass->data.kind == TypeDecl::Ftype ); 334 /// std::cerr << " bound to variable " << *theClass->vars.begin() << std::endl;335 353 sub.add( *theVar, newTypeInst ); 336 354 } // if 337 355 } // for 338 356 } // for 339 /// std::cerr << "input env is:" << std::endl;340 /// print( std::cerr, 8 );341 /// std::cerr << "sub is:" << std::endl;342 /// sub.print( std::cerr, 8 );343 357 sub.normalize(); 344 358 } 345 359 346 360 void TypeEnvironment::print( std::ostream &os, Indenter indent ) const { 347 for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i) {348 i->print( os, indent );361 for ( const EqvClass & theClass : env ) { 362 theClass.print( os, indent ); 349 363 } // for 350 364 } … … 352 366 std::list< EqvClass >::iterator TypeEnvironment::internal_lookup( const std::string &var ) { 353 367 for ( std::list< EqvClass >::iterator i = env.begin(); i != env.end(); ++i ) { 354 if ( i->vars.find( var ) == i->vars.end() ) { 355 return i; 356 } // if 368 if ( i->vars.count( var ) ) return i; 357 369 } // for 358 370 return env.end();
Note: See TracChangeset
for help on using the changeset viewer.