Changeset 2c57025 for src/ResolvExpr
- 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
- Location:
- src/ResolvExpr
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/ResolvExpr/AdjustExprType.cc ¶
r186fd86 r2c57025 97 97 EqvClass eqvClass; 98 98 if ( env.lookup( typeInst->get_name(), eqvClass ) ) { 99 if ( eqvClass. kind == TypeDecl::Ftype ) {99 if ( eqvClass.data.kind == TypeDecl::Ftype ) { 100 100 PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); 101 101 return pointerType; -
TabularUnified src/ResolvExpr/AlternativeFinder.cc ¶
r186fd86 r2c57025 373 373 void makeUnifiableVars( Type *type, OpenVarSet &unifiableVars, AssertionSet &needAssertions ) { 374 374 for ( Type::ForallList::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) { 375 unifiableVars[ (*tyvar)->get_name() ] = (*tyvar)->get_kind();375 unifiableVars[ (*tyvar)->get_name() ] = TypeDecl::Data{ *tyvar }; 376 376 for ( std::list< DeclarationWithType* >::iterator assert = (*tyvar)->get_assertions().begin(); assert != (*tyvar)->get_assertions().end(); ++assert ) { 377 377 needAssertions[ *assert ] = true; -
TabularUnified src/ResolvExpr/CommonType.cc ¶
r186fd86 r2c57025 57 57 Type *result = visitor.get_result(); 58 58 if ( ! result ) { 59 // this appears to be handling for opaque type declarations 59 60 if ( widenSecond ) { 60 TypeInstType *inst = dynamic_cast< TypeInstType* >( type2 ); 61 if ( inst ) { 62 NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ); 63 if ( nt ) { 64 TypeDecl *type = dynamic_cast< TypeDecl* >( nt ); 65 assert( type ); 61 if ( TypeInstType *inst = dynamic_cast< TypeInstType* >( type2 ) ) { 62 if ( NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ) ) { 63 TypeDecl *type = safe_dynamic_cast< TypeDecl* >( nt ); 66 64 if ( type->get_base() ) { 67 65 Type::Qualifiers tq1 = type1->get_qualifiers(), tq2 = type2->get_qualifiers(); … … 145 143 } 146 144 145 /// true if a common type for t must be a complete type 146 bool requiredComplete( Type * t ) { 147 if ( TypeInstType * inst = dynamic_cast< TypeInstType * > ( t ) ) { 148 return inst->get_baseType()->isComplete(); 149 } 150 return false; 151 } 152 147 153 void CommonType::visit( PointerType *pointerType ) { 148 154 if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) { 149 if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base(), indexer) ) { 155 // Note: relationship between formal and actual types is antisymmetric 156 // void free(void *); 157 // forall(otype T) void foo(T *); 158 // 159 // should be able to pass T* to free, but should not be able to pass a void* to foo. 160 // because of this, the requiredComplete check occurs only on the first, since it corresponds 161 // to the formal parameter type (though this may be incorrect in some cases, in which case 162 // perhaps the widen mode needs to incorporate another bit for whether this is a formal or actual context) 163 if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base(), indexer) && ! requiredComplete( pointerType->get_base() ) ) { 150 164 result = otherPointer->clone(); 151 165 result->get_qualifiers() += pointerType->get_qualifiers(); … … 211 225 NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ); 212 226 if ( nt ) { 213 TypeDecl *type = dynamic_cast< TypeDecl* >( nt ); 214 assert( type ); 227 TypeDecl *type = safe_dynamic_cast< TypeDecl* >( nt ); 215 228 if ( type->get_base() ) { 216 229 Type::Qualifiers tq1 = inst->get_qualifiers(), tq2 = type2->get_qualifiers(); -
TabularUnified src/ResolvExpr/FindOpenVars.cc ¶
r186fd86 r2c57025 48 48 if ( nextIsOpen ) { 49 49 for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) { 50 openVars[ (*i)->get_name() ] = (*i)->get_kind();50 openVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) }; 51 51 for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) { 52 52 needAssertions[ *assert ] = false; … … 57 57 } else { 58 58 for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) { 59 closedVars[ (*i)->get_name() ] = (*i)->get_kind();59 closedVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) }; 60 60 for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) { 61 61 haveAssertions[ *assert ] = false; -
TabularUnified src/ResolvExpr/PtrsCastable.cc ¶
r186fd86 r2c57025 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // PtrsCastable.cc -- 7 // PtrsCastable.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 25 25 public: 26 26 PtrsCastable( Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ); 27 27 28 28 int get_result() const { return result; } 29 29 … … 61 61 } //if 62 62 } else if ( env.lookup( typeInst->get_name(), eqvClass ) ) { 63 if ( eqvClass. kind == TypeDecl::Ftype ) {63 if ( eqvClass.data.kind == TypeDecl::Ftype ) { 64 64 return -1; 65 65 } // if -
TabularUnified src/ResolvExpr/TypeEnvironment.cc ¶
r186fd86 r2c57025 94 94 dest.type = maybeClone( src.type ); 95 95 dest.allowWidening = src.allowWidening; 96 dest. kind = src.kind;96 dest.data = src.data; 97 97 } 98 98 … … 162 162 EqvClass newClass; 163 163 newClass.vars.insert( (*i)->get_name() ); 164 newClass. kind = (*i)->get_kind();164 newClass.data = TypeDecl::Data{ (*i) }; 165 165 env.push_back( newClass ); 166 166 } // for … … 177 177 sub.add( *theVar, theClass->type ); 178 178 } else if ( theVar != theClass->vars.begin() ) { 179 TypeInstType *newTypeInst = new TypeInstType( Type::Qualifiers(), *theClass->vars.begin(), theClass-> kind == TypeDecl::Ftype );179 TypeInstType *newTypeInst = new TypeInstType( Type::Qualifiers(), *theClass->vars.begin(), theClass->data.kind == TypeDecl::Ftype ); 180 180 /// std::cout << " bound to variable " << *theClass->vars.begin() << std::endl; 181 181 sub.add( *theVar, newTypeInst ); … … 243 243 for ( std::list< EqvClass >::const_iterator eqvClass = env.begin(); eqvClass != env.end(); ++eqvClass ) { 244 244 for ( std::set< std::string >::const_iterator var = eqvClass->vars.begin(); var != eqvClass->vars.end(); ++var ) { 245 openVars[ *var ] = eqvClass-> kind;245 openVars[ *var ] = eqvClass->data; 246 246 } // for 247 247 } // for -
TabularUnified src/ResolvExpr/TypeEnvironment.h ¶
r186fd86 r2c57025 32 32 }; 33 33 typedef std::map< DeclarationWithType*, bool, AssertCompare > AssertionSet; 34 typedef std::map< std::string, TypeDecl:: Kind> OpenVarSet;34 typedef std::map< std::string, TypeDecl::Data > OpenVarSet; 35 35 36 36 void printAssertionSet( const AssertionSet &, std::ostream &, int indent = 0 ); … … 41 41 Type *type; 42 42 bool allowWidening; 43 TypeDecl:: Kind kind;43 TypeDecl::Data data; 44 44 45 45 void initialize( const EqvClass &src, EqvClass &dest ); -
TabularUnified 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.