Changeset 2c57025 for src/ResolvExpr/Unify.cc
- Timestamp:
- Nov 25, 2016, 6:11:03 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 0f35657
- Parents:
- 186fd86
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
r186fd86 r2c57025 109 109 newFirst->get_qualifiers() = Type::Qualifiers(); 110 110 newSecond->get_qualifiers() = Type::Qualifiers(); 111 /// std::c out<< "first is ";112 /// first->print( std::c out);113 /// std::c out<< std::endl << "second is ";114 /// second->print( std::c out);115 /// std::c out<< std::endl << "newFirst is ";116 /// newFirst->print( std::c out);117 /// std::c out<< std::endl << "newSecond is ";118 /// newSecond->print( std::c out);119 /// std::c out<< std::endl;111 /// std::cerr << "first is "; 112 /// first->print( std::cerr ); 113 /// std::cerr << std::endl << "second is "; 114 /// second->print( std::cerr ); 115 /// std::cerr << std::endl << "newFirst is "; 116 /// newFirst->print( std::cerr ); 117 /// std::cerr << std::endl << "newSecond is "; 118 /// newSecond->print( std::cerr ); 119 /// std::cerr << std::endl; 120 120 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 121 121 delete newFirst; … … 133 133 } 134 134 135 bool tyVarCompatible( TypeDecl::Kind kind, Type *type, const SymTab::Indexer &indexer ) { 136 switch ( kind ) { 135 struct CompleteTypeChecker : public Visitor { 136 virtual void visit( VoidType *basicType ) { status = false; } 137 virtual void visit( BasicType *basicType ) {} 138 virtual void visit( PointerType *pointerType ) {} 139 virtual void visit( ArrayType *arrayType ) { status = ! arrayType->get_isVarLen(); } 140 virtual void visit( FunctionType *functionType ) {} 141 virtual void visit( StructInstType *aggregateUseType ) { status = aggregateUseType->get_baseStruct()->has_body(); } 142 virtual void visit( UnionInstType *aggregateUseType ) { status = aggregateUseType->get_baseUnion()->has_body(); } 143 // xxx - enum inst does not currently contain a pointer to base, this should be fixed. 144 virtual void visit( EnumInstType *aggregateUseType ) { /* status = aggregateUseType->get_baseEnum()->hasBody(); */ } 145 virtual void visit( TraitInstType *aggregateUseType ) { assert( false ); } 146 virtual void visit( TypeInstType *aggregateUseType ) { status = aggregateUseType->get_baseType()->isComplete(); } 147 virtual void visit( TupleType *tupleType ) {} // xxx - not sure if this is right, might need to recursively check complete-ness 148 virtual void visit( TypeofType *typeofType ) { assert( false ); } 149 virtual void visit( AttrType *attrType ) { assert( false ); } // xxx - not sure what to do here 150 virtual void visit( VarArgsType *varArgsType ){} // xxx - is this right? 151 virtual void visit( ZeroType *zeroType ) {} 152 virtual void visit( OneType *oneType ) {} 153 bool status = true; 154 }; 155 bool isComplete( Type * type ) { 156 CompleteTypeChecker checker; 157 assert( type ); 158 type->accept( checker ); 159 return checker.status; 160 } 161 162 bool tyVarCompatible( const TypeDecl::Data & data, Type *type, const SymTab::Indexer &indexer ) { 163 switch ( data.kind ) { 137 164 case TypeDecl::Any: 138 165 case TypeDecl::Dtype: 139 return ! isFtype( type, indexer ); 140 166 // to bind to an object type variable, the type must not be a function type. 167 // if the type variable is specified to be a complete type then the incoming 168 // type must also be complete 169 return ! isFtype( type, indexer ) && (! data.isComplete || isComplete( type )); 141 170 case TypeDecl::Ftype: 142 171 return isFtype( type, indexer ); … … 146 175 } 147 176 148 bool bindVar( TypeInstType *typeInst, Type *other, TypeDecl::Kind kind, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) {177 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 ) { 149 178 OpenVarSet::const_iterator tyvar = openVars.find( typeInst->get_name() ); 150 179 assert( tyvar != openVars.end() ); … … 185 214 newClass.type->get_qualifiers() = Type::Qualifiers(); 186 215 newClass.allowWidening = widenMode.widenFirst && widenMode.widenSecond; 187 newClass. kind = kind;216 newClass.data = data; 188 217 env.add( newClass ); 189 218 } // if … … 191 220 } 192 221 193 bool bindVarToVar( TypeInstType *var1, TypeInstType *var2, TypeDecl::Kind kind, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) {222 bool bindVarToVar( TypeInstType *var1, TypeInstType *var2, const TypeDecl::Data & data, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) { 194 223 bool result = true; 195 224 EqvClass class1, class2; … … 220 249 221 250 if ( type1 && type2 ) { 222 // std::c out<< "has type1 && type2" << std::endl;251 // std::cerr << "has type1 && type2" << std::endl; 223 252 WidenMode newWidenMode ( widen1, widen2 ); 224 253 Type *common = 0; … … 258 287 newClass.vars.insert( var2->get_name() ); 259 288 newClass.allowWidening = widen1 && widen2; 260 newClass. kind = kind;289 newClass.data = data; 261 290 env.add( newClass ); 262 291 } // if … … 321 350 } // if 322 351 #ifdef DEBUG 323 std::c out<< "============ unifyExact" << std::endl;324 std::c out<< "type1 is ";325 type1->print( std::c out);326 std::c out<< std::endl << "type2 is ";327 type2->print( std::c out);328 std::c out<< std::endl << "openVars are ";329 printOpenVarSet( openVars, std::c out, 8 );330 std::c out<< std::endl << "input env is " << std::endl;331 debugEnv.print( std::c out, 8 );332 std::c out<< std::endl << "result env is " << std::endl;333 env.print( std::c out, 8 );334 std::c out<< "result is " << result << std::endl;352 std::cerr << "============ unifyExact" << std::endl; 353 std::cerr << "type1 is "; 354 type1->print( std::cerr ); 355 std::cerr << std::endl << "type2 is "; 356 type2->print( std::cerr ); 357 std::cerr << std::endl << "openVars are "; 358 printOpenVarSet( openVars, std::cerr, 8 ); 359 std::cerr << std::endl << "input env is " << std::endl; 360 debugEnv.print( std::cerr, 8 ); 361 std::cerr << std::endl << "result env is " << std::endl; 362 env.print( std::cerr, 8 ); 363 std::cerr << "result is " << result << std::endl; 335 364 #endif 336 365 return result; … … 347 376 bool result; 348 377 #ifdef DEBUG 349 std::c out<< "unifyInexact type 1 is ";350 type1->print( std::c out);351 std::c out<< "type 2 is ";352 type2->print( std::c out);353 std::c out<< std::endl;378 std::cerr << "unifyInexact type 1 is "; 379 type1->print( std::cerr ); 380 std::cerr << "type 2 is "; 381 type2->print( std::cerr ); 382 std::cerr << std::endl; 354 383 #endif 355 384 if ( ! unifyExact( type1, type2, env, needAssertions, haveAssertions, openVars, widenMode, indexer ) ) { 356 385 #ifdef DEBUG 357 std::c out<< "unifyInexact: no exact unification found" << std::endl;386 std::cerr << "unifyInexact: no exact unification found" << std::endl; 358 387 #endif 359 388 if ( ( common = commonType( type1, type2, widenMode.widenFirst, widenMode.widenSecond, indexer, env, openVars ) ) ) { 360 389 common->get_qualifiers() = tq1 + tq2; 361 390 #ifdef DEBUG 362 std::c out<< "unifyInexact: common type is ";363 common->print( std::c out);364 std::c out<< std::endl;391 std::cerr << "unifyInexact: common type is "; 392 common->print( std::cerr ); 393 std::cerr << std::endl; 365 394 #endif 366 395 result = true; 367 396 } else { 368 397 #ifdef DEBUG 369 std::c out<< "unifyInexact: no common type found" << std::endl;398 std::cerr << "unifyInexact: no common type found" << std::endl; 370 399 #endif 371 400 result = false; … … 404 433 405 434 void markAssertionSet( AssertionSet &assertions, DeclarationWithType *assert ) { 406 /// std::c out<< "assertion set is" << std::endl;407 /// printAssertionSet( assertions, std::c out, 8 );408 /// std::c out<< "looking for ";409 /// assert->print( std::c out);410 /// std::c out<< std::endl;435 /// std::cerr << "assertion set is" << std::endl; 436 /// printAssertionSet( assertions, std::cerr, 8 ); 437 /// std::cerr << "looking for "; 438 /// assert->print( std::cerr ); 439 /// std::cerr << std::endl; 411 440 AssertionSet::iterator i = assertions.find( assert ); 412 441 if ( i != assertions.end() ) { 413 /// std::c out<< "found it!" << std::endl;442 /// std::cerr << "found it!" << std::endl; 414 443 i->second = true; 415 444 } // if
Note: See TracChangeset
for help on using the changeset viewer.