- Timestamp:
- Jun 1, 2018, 7:53:55 PM (7 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, with_gc
- Children:
- d56cc219
- Parents:
- ecae5860 (diff), 262bd63 (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. - Location:
- src
- Files:
-
- 3 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AdjustExprType.cc
recae5860 radb6a4f1 66 66 67 67 Type * AdjustExprType::postmutate( ArrayType * arrayType ) { 68 PointerType *pointerType = new PointerType ( arrayType->get_qualifiers(), arrayType->base );68 PointerType *pointerType = new PointerType{ arrayType->get_qualifiers(), arrayType->base }; 69 69 arrayType->base = nullptr; 70 70 delete arrayType; … … 73 73 74 74 Type * AdjustExprType::postmutate( FunctionType * functionType ) { 75 return new PointerType ( Type::Qualifiers(), functionType );75 return new PointerType{ Type::Qualifiers(), functionType }; 76 76 } 77 77 78 78 Type * AdjustExprType::postmutate( TypeInstType * typeInst ) { 79 EqvClass eqvClass; 80 if ( env.lookup( typeInst->get_name(), eqvClass ) ) { 81 if ( eqvClass.data.kind == TypeDecl::Ftype ) { 82 PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); 83 return pointerType; 79 if ( const EqvClass* eqvClass = env.lookup( typeInst->get_name() ) ) { 80 if ( eqvClass->data.kind == TypeDecl::Ftype ) { 81 return new PointerType{ Type::Qualifiers(), typeInst }; 84 82 } 85 83 } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) { 86 84 if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) { 87 85 if ( tyDecl->get_kind() == TypeDecl::Ftype ) { 88 PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); 89 return pointerType; 86 return new PointerType{ Type::Qualifiers(), typeInst }; 90 87 } // if 91 88 } // if -
src/ResolvExpr/Alternative.cc
recae5860 radb6a4f1 27 27 28 28 namespace ResolvExpr { 29 Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0) {}29 Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ) {} 30 30 31 31 Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost ) … … 48 48 } 49 49 50 Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env) {50 Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( std::move( other.env ) ) { 51 51 other.expr = nullptr; 52 52 } … … 58 58 cvtCost = other.cvtCost; 59 59 expr = other.expr; 60 env = other.env;60 env = std::move( other.env ); 61 61 other.expr = nullptr; 62 62 return *this; -
src/ResolvExpr/AlternativeFinder.cc
recae5860 radb6a4f1 102 102 void addAnonConversions( const Alternative & alt ); 103 103 /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member 104 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member);104 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name ); 105 105 /// Adds alternatives for member expressions where the left side has tuple type 106 106 void addTupleMembers( TupleType * tupleType, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ); … … 307 307 308 308 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->result ) ) { 309 NameExpr nameExpr( "" ); 310 addAggMembers( structInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr ); 309 addAggMembers( structInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, "" ); 311 310 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->result ) ) { 312 NameExpr nameExpr( "" ); 313 addAggMembers( unionInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr ); 311 addAggMembers( unionInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, "" ); 314 312 } // if 315 313 } 316 314 317 315 template< typename StructOrUnionType > 318 void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ) { 319 // by this point, member must be a name expr 320 NameExpr * nameExpr = dynamic_cast< NameExpr * >( member ); 321 if ( ! nameExpr ) return; 322 const std::string & name = nameExpr->name; 316 void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name ) { 323 317 std::list< Declaration* > members; 324 318 aggInst->lookup( name, members ); 325 319 326 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 327 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) { 328 alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) ); 329 renameTypes( alternatives.back().expr ); 330 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression. 320 for ( Declaration * decl : members ) { 321 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) { 322 // addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so 323 // can't construct in place and use vector::back 324 Alternative newAlt( new MemberExpr( dwt, expr->clone() ), env, newCost ); 325 renameTypes( newAlt.expr ); 326 addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression. 327 alternatives.push_back( std::move(newAlt) ); 331 328 } else { 332 329 assert( false ); … … 469 466 } 470 467 471 // /// Map of declaration uniqueIds (intended to be the assertions in an AssertionSet) to their parents and the number of times they've been included472 //typedef std::unordered_map< UniqueId, std::unordered_map< UniqueId, unsigned > > AssertionParentSet;473 474 468 static const int recursionLimit = /*10*/ 4; ///< Limit to depth of recursion satisfaction 475 //static const unsigned recursionParentLimit = 1; ///< Limit to the number of times an assertion can recursively use itself476 469 477 470 void addToIndexer( AssertionSet &assertSet, SymTab::Indexer &indexer ) { … … 484 477 485 478 template< typename ForwardIterator, typename OutputIterator > 486 void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, /*const AssertionParentSet &needParents,*/ 487 int level, const SymTab::Indexer &indexer, OutputIterator out ) { 479 void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, int level, const SymTab::Indexer &indexer, OutputIterator out ) { 488 480 if ( begin == end ) { 489 481 if ( newNeed.empty() ) { … … 503 495 printAssertionSet( newNeed, std::cerr, 8 ); 504 496 ) 505 inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, /*needParents,*/level+1, indexer, out );497 inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, level+1, indexer, out ); 506 498 return; 507 499 } … … 510 502 ForwardIterator cur = begin++; 511 503 if ( ! cur->second.isUsed ) { 512 inferRecursive( begin, end, newAlt, openVars, decls, newNeed, /*needParents,*/level, indexer, out );504 inferRecursive( begin, end, newAlt, openVars, decls, newNeed, level, indexer, out ); 513 505 return; // xxx - should this continue? previously this wasn't here, and it looks like it should be 514 506 } … … 563 555 } 564 556 565 //AssertionParentSet newNeedParents( needParents );566 // skip repeatingly-self-recursive assertion satisfaction567 // DOESN'T WORK: grandchild nodes conflict with their cousins568 //if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue;569 570 557 Expression *varExpr = data.combine( newerAlt.cvtCost ); 571 558 delete varExpr->get_result(); … … 585 572 // XXX: this is a memory leak, but adjType can't be deleted because it might contain assertions 586 573 (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr ); 587 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, /*newNeedParents,*/level, indexer, out );574 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, level, indexer, out ); 588 575 } else { 589 576 delete adjType; … … 607 594 addToIndexer( have, decls ); 608 595 AssertionSet newNeed; 609 //AssertionParentSet needParents;610 596 PRINT( 611 597 std::cerr << "env is: " << std::endl; … … 614 600 ) 615 601 616 inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, /*needParents,*/0, indexer, out );602 inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, 0, indexer, out ); 617 603 // PRINT( 618 604 // std::cerr << "declaration 14 is "; … … 1093 1079 AlternativeFinder funcOpFinder( indexer, env ); 1094 1080 // it's ok if there aren't any defined function ops 1095 funcOpFinder.maybeFind( opExpr );1081 funcOpFinder.maybeFind( opExpr ); 1096 1082 PRINT( 1097 1083 std::cerr << "known function ops:" << std::endl; … … 1130 1116 } 1131 1117 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->result->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer) 1132 EqvClass eqvClass; 1133 if ( func->env.lookup( typeInst->name, eqvClass ) && eqvClass.type ) { 1134 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) { 1118 if ( const EqvClass *eqvClass = func->env.lookup( typeInst->name ) ) { 1119 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass->type ) ) { 1135 1120 Alternative newFunc( *func ); 1136 1121 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); … … 1347 1332 } 1348 1333 1334 namespace { 1335 /// Gets name from untyped member expression (member must be NameExpr) 1336 const std::string& get_member_name( UntypedMemberExpr *memberExpr ) { 1337 NameExpr * nameExpr = dynamic_cast< NameExpr * >( memberExpr->get_member() ); 1338 assert( nameExpr ); 1339 return nameExpr->get_name(); 1340 } 1341 } 1342 1349 1343 void AlternativeFinder::Finder::postvisit( UntypedMemberExpr *memberExpr ) { 1350 1344 AlternativeFinder funcFinder( indexer, env ); … … 1359 1353 // find member of the given type 1360 1354 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) { 1361 addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() );1355 addAggMembers( structInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) ); 1362 1356 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) { 1363 addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() );1357 addAggMembers( unionInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) ); 1364 1358 } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) { 1365 1359 addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() ); … … 1379 1373 Cost cost = Cost::zero; 1380 1374 Expression * newExpr = data.combine( cost ); 1381 alternatives.push_back( Alternative( newExpr, env, Cost::zero, cost ) ); 1375 1376 // addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so 1377 // can't construct in place and use vector::back 1378 Alternative newAlt( newExpr, env, Cost::zero, cost ); 1382 1379 PRINT( 1383 1380 std::cerr << "decl is "; … … 1388 1385 std::cerr << std::endl; 1389 1386 ) 1390 renameTypes( alternatives.back().expr ); 1391 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression. 1387 renameTypes( newAlt.expr ); 1388 addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression. 1389 alternatives.push_back( std::move(newAlt) ); 1392 1390 } // for 1393 1391 } -
src/ResolvExpr/CastCost.cc
recae5860 radb6a4f1 43 43 Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { 44 44 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) { 45 EqvClass eqvClass; 46 NamedTypeDecl *namedType; 47 if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) { 48 if ( eqvClass.type ) { 49 return castCost( src, eqvClass.type, indexer, env ); 45 if ( const EqvClass* eqvClass = env.lookup( destAsTypeInst->get_name() ) ) { 46 if ( eqvClass->type ) { 47 return castCost( src, eqvClass->type, indexer, env ); 50 48 } else { 51 49 return Cost::infinity; 52 50 } 53 } else if ( ( namedType = indexer.lookupType( destAsTypeInst->get_name()) ) ) {51 } else if ( NamedTypeDecl *namedType = indexer.lookupType( destAsTypeInst->get_name() ) ) { 54 52 // all typedefs should be gone by this point 55 53 TypeDecl *type = strict_dynamic_cast< TypeDecl* >( namedType ); -
src/ResolvExpr/ConversionCost.cc
recae5860 radb6a4f1 42 42 Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { 43 43 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) { 44 EqvClass eqvClass;45 NamedTypeDecl *namedType;46 44 PRINT( std::cerr << "type inst " << destAsTypeInst->name; ) 47 if ( env.lookup( destAsTypeInst->name, eqvClass) ) {48 if ( eqvClass .type ) {49 return conversionCost( src, eqvClass .type, indexer, env );45 if ( const EqvClass* eqvClass = env.lookup( destAsTypeInst->name ) ) { 46 if ( eqvClass->type ) { 47 return conversionCost( src, eqvClass->type, indexer, env ); 50 48 } else { 51 49 return Cost::infinity; 52 50 } 53 } else if ( ( namedType = indexer.lookupType( destAsTypeInst->name )) ) {51 } else if ( NamedTypeDecl *namedType = indexer.lookupType( destAsTypeInst->name ) ) { 54 52 PRINT( std::cerr << " found" << std::endl; ) 55 53 TypeDecl *type = dynamic_cast< TypeDecl* >( namedType ); … … 369 367 370 368 void ConversionCost::postvisit( TypeInstType *inst ) { 371 EqvClass eqvClass; 372 NamedTypeDecl *namedType; 373 if ( env.lookup( inst->name, eqvClass ) ) { 374 cost = costFunc( eqvClass.type, dest, indexer, env ); 369 if ( const EqvClass *eqvClass = env.lookup( inst->name ) ) { 370 cost = costFunc( eqvClass->type, dest, indexer, env ); 375 371 } else if ( TypeInstType *destAsInst = dynamic_cast< TypeInstType* >( dest ) ) { 376 372 if ( inst->name == destAsInst->name ) { 377 373 cost = Cost::zero; 378 374 } 379 } else if ( ( namedType = indexer.lookupType( inst->name )) ) {375 } else if ( NamedTypeDecl *namedType = indexer.lookupType( inst->name ) ) { 380 376 TypeDecl *type = dynamic_cast< TypeDecl* >( namedType ); 381 377 // all typedefs should be gone by this point -
src/ResolvExpr/Occurs.cc
recae5860 radb6a4f1 38 38 39 39 Occurs::Occurs( std::string varName, const TypeEnvironment & env ) : result( false ), tenv( env ) { 40 EqvClass eqvClass; 41 if ( tenv.lookup( varName, eqvClass ) ) { 42 eqvVars = eqvClass.vars; 40 if ( const EqvClass *eqvClass = tenv.lookup( varName ) ) { 41 eqvVars = eqvClass->vars; 43 42 } else { 44 43 eqvVars.insert( varName ); … … 47 46 48 47 void Occurs::previsit( TypeInstType * typeInst ) { 49 EqvClass eqvClass; 50 /// std::cerr << "searching for vars: "; 48 /// std::cerr << "searching for vars: "; 51 49 /// std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cerr, " " ) ); 52 50 /// std::cerr << std::endl; 53 51 if ( eqvVars.find( typeInst->get_name() ) != eqvVars.end() ) { 54 52 result = true; 55 } else if ( tenv.lookup( typeInst->get_name(), eqvClass) ) {56 if ( eqvClass .type ) {53 } else if ( const EqvClass *eqvClass = tenv.lookup( typeInst->get_name() ) ) { 54 if ( eqvClass->type ) { 57 55 /// std::cerr << typeInst->get_name() << " is bound to"; 58 56 /// eqvClass.type->print( std::cerr ); 59 57 /// std::cerr << std::endl; 60 eqvClass .type->accept( *visitor );58 eqvClass->type->accept( *visitor ); 61 59 } // if 62 60 } // if -
src/ResolvExpr/PolyCost.cc
recae5860 radb6a4f1 39 39 40 40 void PolyCost::previsit(TypeInstType * typeInst) { 41 EqvClass eqvClass; 42 if ( tenv.lookup( typeInst->name, eqvClass ) ) { 43 if ( eqvClass.type ) { 44 if ( TypeInstType * otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) { 41 if ( const EqvClass *eqvClass = tenv.lookup( typeInst->name ) ) { 42 if ( eqvClass->type ) { 43 if ( TypeInstType * otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass->type ) ) { 45 44 if ( indexer.lookupType( otherTypeInst->name ) ) { 46 45 // bound to opaque type -
src/ResolvExpr/PtrsAssignable.cc
recae5860 radb6a4f1 51 51 // std::cerr << "assignable: " << src << " | " << dest << std::endl; 52 52 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) { 53 EqvClass eqvClass; 54 if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) { 55 return ptrsAssignable( src, eqvClass.type, env ); 53 if ( const EqvClass *eqvClass = env.lookup( destAsTypeInst->get_name() ) ) { 54 return ptrsAssignable( src, eqvClass->type, env ); 56 55 } // if 57 56 } // if … … 95 94 void PtrsAssignable::postvisit( __attribute__((unused)) TraitInstType *inst ) {} 96 95 void PtrsAssignable::postvisit( TypeInstType *inst ) { 97 EqvClass eqvClass; 98 if ( env.lookup( inst->get_name(), eqvClass ) && eqvClass.type ) { 99 // T * = S * for any S depends on the type bound to T 100 result = ptrsAssignable( eqvClass.type, dest, env ); 96 if ( const EqvClass *eqvClass = env.lookup( inst->get_name() ) ) { 97 if ( eqvClass->type ) { 98 // T * = S * for any S depends on the type bound to T 99 result = ptrsAssignable( eqvClass->type, dest, env ); 100 } 101 101 } // if 102 102 } -
src/ResolvExpr/PtrsCastable.cc
recae5860 radb6a4f1 57 57 return -1; 58 58 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( src ) ) { 59 EqvClass eqvClass;60 59 if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) { 61 60 if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) { … … 64 63 } // if 65 64 } //if 66 } else if ( env.lookup( typeInst->get_name(), eqvClass) ) {67 if ( eqvClass .data.kind == TypeDecl::Ftype ) {65 } else if ( const EqvClass *eqvClass = env.lookup( typeInst->get_name() ) ) { 66 if ( eqvClass->data.kind == TypeDecl::Ftype ) { 68 67 return -1; 69 68 } // if … … 79 78 int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { 80 79 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) { 81 EqvClass eqvClass; 82 if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) { 80 if ( const EqvClass *eqvClass = env.lookup( destAsTypeInst->get_name() ) ) { 83 81 // xxx - should this be ptrsCastable? 84 return ptrsAssignable( src, eqvClass .type, env );82 return ptrsAssignable( src, eqvClass->type, env ); 85 83 } // if 86 84 } // if -
src/ResolvExpr/TypeEnvironment.cc
recae5860 radb6a4f1 17 17 #include <algorithm> // for copy, set_intersection 18 18 #include <iterator> // for ostream_iterator, insert_iterator 19 #include <utility> // for pair 19 #include <utility> // for pair, move 20 20 21 21 #include "Common/utility.h" // for maybeClone … … 44 44 45 45 void EqvClass::initialize( const EqvClass &src, EqvClass &dest ) { 46 initialize( src, dest, src.type ); 47 } 48 49 void EqvClass::initialize( const EqvClass &src, EqvClass &dest, const Type *ty ) { 46 50 dest.vars = src.vars; 47 dest.type = maybeClone( src.type);51 dest.type = maybeClone( ty ); 48 52 dest.allowWidening = src.allowWidening; 49 53 dest.data = src.data; 50 54 } 51 55 52 EqvClass::EqvClass() : type( 0), allowWidening( true ) {56 EqvClass::EqvClass() : type( nullptr ), allowWidening( true ) { 53 57 } 54 58 55 59 EqvClass::EqvClass( const EqvClass &other ) { 56 60 initialize( other, *this ); 61 } 62 63 EqvClass::EqvClass( const EqvClass &other, const Type *ty ) { 64 initialize( other, *this, ty ); 57 65 } 58 66 … … 82 90 } 83 91 84 bool TypeEnvironment::lookup( const std::string &var, EqvClass &eqvClass) const {92 const EqvClass* TypeEnvironment::lookup( const std::string &var ) const { 85 93 for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i ) { 86 94 if ( i->vars.find( var ) != i->vars.end() ) { 87 95 /// std::cout << var << " is in class "; 88 96 /// i->print( std::cout ); 89 eqvClass = *i; 90 return true; 97 return &*i; 91 98 } 92 99 /// std::cout << var << " is not in class "; 93 100 /// i->print( std::cout ); 94 101 } // for 95 return false; 102 return nullptr; 103 } 104 105 /// Removes any class from env that intersects eqvClass 106 void filterOverlappingClasses( std::list<EqvClass> &env, const EqvClass &eqvClass ) { 107 for ( auto i = env.begin(); i != env.end(); ) { 108 auto next = i; 109 ++next; 110 std::set<std::string> intersection; 111 std::set_intersection( i->vars.begin(), i->vars.end(), eqvClass.vars.begin(), eqvClass.vars.end(), 112 std::inserter( intersection, intersection.begin() ) ); 113 if ( ! intersection.empty() ) { env.erase( i ); } 114 i = next; 115 } 96 116 } 97 117 98 118 void TypeEnvironment::add( const EqvClass &eqvClass ) { 99 std::list< EqvClass >::iterator i = env.begin(); 100 while ( i != env.end() ) { 101 std::list< EqvClass >::iterator next = i; 102 next++; 103 std::set< std::string > intersection; 104 std::set_intersection( i->vars.begin(), i->vars.end(), eqvClass.vars.begin(), eqvClass.vars.end(), std::inserter( intersection, intersection.begin() ) ); 105 if ( ! intersection.empty() ) { 106 env.erase( i ); 107 } // if 108 i = next; 109 } // while 110 env.insert( env.end(), eqvClass ); 119 filterOverlappingClasses( env, eqvClass ); 120 env.push_back( eqvClass ); 121 } 122 123 void TypeEnvironment::add( EqvClass &&eqvClass ) { 124 filterOverlappingClasses( env, eqvClass ); 125 env.push_back( std::move(eqvClass) ); 111 126 } 112 127 … … 159 174 160 175 void TypeEnvironment::print( std::ostream &os, Indenter indent ) const { 161 for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i) {162 i->print( os, indent );176 for ( const EqvClass & theClass : env ) { 177 theClass.print( os, indent ); 163 178 } // for 164 179 } -
src/ResolvExpr/TypeEnvironment.h
recae5860 radb6a4f1 73 73 74 74 void initialize( const EqvClass &src, EqvClass &dest ); 75 void initialize( const EqvClass &src, EqvClass &dest, const Type *ty ); 75 76 EqvClass(); 76 77 EqvClass( const EqvClass &other ); 78 EqvClass( const EqvClass &other, const Type *ty ); 77 79 EqvClass &operator=( const EqvClass &other ); 78 80 ~EqvClass(); … … 82 84 class TypeEnvironment { 83 85 public: 84 bool lookup( const std::string &var, EqvClass &eqvClass) const;86 const EqvClass* lookup( const std::string &var ) const; 85 87 void add( const EqvClass &eqvClass ); 88 void add( EqvClass &&eqvClass ); 86 89 void add( const Type::ForallList &tyDecls ); 87 90 void add( const TypeSubstitution & sub ); -
src/ResolvExpr/Unify.cc
recae5860 radb6a4f1 20 20 #include <set> // for set 21 21 #include <string> // for string, operator==, operator!=, bas... 22 #include <utility> // for pair 22 #include <utility> // for pair, move 23 23 24 24 #include "Common/PassVisitor.h" // for PassVisitor … … 166 166 return false; 167 167 } // if 168 EqvClass curClass; 169 if ( env.lookup( typeInst->get_name(), curClass ) ) { 170 if ( curClass.type ) { 168 if ( const EqvClass *curClass = env.lookup( typeInst->get_name() ) ) { 169 if ( curClass->type ) { 171 170 Type *common = 0; 172 171 // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to 173 std::unique_ptr< Type > newType( curClass .type->clone() );172 std::unique_ptr< Type > newType( curClass->type->clone() ); 174 173 newType->get_qualifiers() = typeInst->get_qualifiers(); 175 if ( unifyInexact( newType.get(), other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass .allowWidening, true ), indexer, common ) ) {174 if ( unifyInexact( newType.get(), other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass->allowWidening, true ), indexer, common ) ) { 176 175 if ( common ) { 177 176 common->get_qualifiers() = Type::Qualifiers(); 178 delete curClass.type; 179 curClass.type = common; 180 env.add( curClass ); 177 env.add( EqvClass{ *curClass, common } ); 181 178 } // if 182 179 return true; … … 185 182 } // if 186 183 } else { 187 curClass.type = other->clone();188 curClass.type->get_qualifiers() = Type::Qualifiers();189 curClass.allowWidening = widenMode.widenFirst && widenMode.widenSecond;190 env.add( curClass);184 EqvClass newClass { *curClass, other }; 185 newClass.type->get_qualifiers() = Type::Qualifiers(); 186 newClass.allowWidening = widenMode.widenFirst && widenMode.widenSecond; 187 env.add( std::move(newClass) ); 191 188 } // if 192 189 } else { … … 204 201 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 ) { 205 202 bool result = true; 206 EqvClass class1, class2;207 bool hasClass1 = false, hasClass2 = false;203 const EqvClass *class1 = env.lookup( var1->get_name() ); 204 const EqvClass *class2 = env.lookup( var2->get_name() ); 208 205 bool widen1 = false, widen2 = false; 209 Type *type1 = 0, *type2 = 0; 210 211 if ( env.lookup( var1->get_name(), class1 ) ) { 212 hasClass1 = true; 213 if ( class1.type ) { 214 if ( occurs( class1.type, var2->get_name(), env ) ) { 206 Type *type1 = nullptr, *type2 = nullptr; 207 208 if ( class1 ) { 209 if ( class1->type ) { 210 if ( occurs( class1->type, var2->get_name(), env ) ) { 215 211 return false; 216 212 } // if 217 type1 = class1.type->clone(); 218 } // if 219 widen1 = widenMode.widenFirst && class1.allowWidening; 220 } // if 221 if ( env.lookup( var2->get_name(), class2 ) ) { 222 hasClass2 = true; 223 if ( class2.type ) { 224 if ( occurs( class2.type, var1->get_name(), env ) ) { 213 type1 = class1->type->clone(); 214 } // if 215 widen1 = widenMode.widenFirst && class1->allowWidening; 216 } // if 217 if ( class2 ) { 218 if ( class2->type ) { 219 if ( occurs( class2->type, var1->get_name(), env ) ) { 225 220 return false; 226 221 } // if 227 type2 = class2 .type->clone();228 } // if 229 widen2 = widenMode.widenSecond && class2 .allowWidening;222 type2 = class2->type->clone(); 223 } // if 224 widen2 = widenMode.widenSecond && class2->allowWidening; 230 225 } // if 231 226 … … 235 230 Type *common = 0; 236 231 if ( unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, newWidenMode, indexer, common ) ) { 237 class1.vars.insert( class2.vars.begin(), class2.vars.end() ); 238 class1.allowWidening = widen1 && widen2; 232 EqvClass newClass1 = *class1; 233 newClass1.vars.insert( class2->vars.begin(), class2->vars.end() ); 234 newClass1.allowWidening = widen1 && widen2; 239 235 if ( common ) { 240 236 common->get_qualifiers() = Type::Qualifiers(); 241 delete class1.type;242 class1.type = common;237 delete newClass1.type; 238 newClass1.type = common; 243 239 } // if 244 env.add( class1);240 env.add( std::move(newClass1) ); 245 241 } else { 246 242 result = false; 247 243 } // if 248 } else if ( hasClass1 && hasClass2 ) {244 } else if ( class1 && class2 ) { 249 245 if ( type1 ) { 250 class1.vars.insert( class2.vars.begin(), class2.vars.end() ); 251 class1.allowWidening = widen1; 252 env.add( class1 ); 246 EqvClass newClass1 = *class1; 247 newClass1.vars.insert( class2->vars.begin(), class2->vars.end() ); 248 newClass1.allowWidening = widen1; 249 env.add( std::move(newClass1) ); 253 250 } else { 254 class2.vars.insert( class1.vars.begin(), class1.vars.end() ); 255 class2.allowWidening = widen2; 256 env.add( class2 ); 257 } // if 258 } else if ( hasClass1 ) { 259 class1.vars.insert( var2->get_name() ); 260 class1.allowWidening = widen1; 261 env.add( class1 ); 262 } else if ( hasClass2 ) { 263 class2.vars.insert( var1->get_name() ); 264 class2.allowWidening = widen2; 265 env.add( class2 ); 251 EqvClass newClass2 = *class2; 252 newClass2.vars.insert( class1->vars.begin(), class1->vars.end() ); 253 newClass2.allowWidening = widen2; 254 env.add( std::move(newClass2) ); 255 } // if 256 } else if ( class1 ) { 257 EqvClass newClass1 = *class1; 258 newClass1.vars.insert( var2->get_name() ); 259 newClass1.allowWidening = widen1; 260 env.add( std::move(newClass1) ); 261 } else if ( class2 ) { 262 EqvClass newClass2 = *class2; 263 newClass2.vars.insert( var1->get_name() ); 264 newClass2.allowWidening = widen2; 265 env.add( std::move(newClass2) ); 266 266 } else { 267 267 EqvClass newClass; … … 539 539 void premutate( TypeInstType * ) { visit_children = false; } 540 540 Type * postmutate( TypeInstType * typeInst ) { 541 EqvClass eqvClass; 542 if ( tenv.lookup( typeInst->get_name(), eqvClass ) ) { 543 if ( eqvClass.data.kind == TypeDecl::Ttype ) { 544 // expand ttype parameter into its actual type 545 if ( eqvClass.type ) { 546 delete typeInst; 547 return eqvClass.type->clone(); 548 } 541 if ( const EqvClass *eqvClass = tenv.lookup( typeInst->get_name() ) ) { 542 // expand ttype parameter into its actual type 543 if ( eqvClass->data.kind == TypeDecl::Ttype && eqvClass->type ) { 544 delete typeInst; 545 return eqvClass->type->clone(); 549 546 } 550 547 } -
src/SynTree/ReferenceToType.cc
recae5860 radb6a4f1 50 50 51 51 namespace { 52 void doLookup( const std::list< Declaration * > &members, const std::string &name, std::list< Declaration* > &foundDecls ) {53 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i) {54 if ( (*i)->get_name()== name ) {55 foundDecls.push_back( *i);52 void doLookup( const std::list< Declaration * > & members, const std::string & name, std::list< Declaration* > & foundDecls ) { 53 for ( Declaration * decl : members ) { 54 if ( decl->name == name ) { 55 foundDecls.push_back( decl ); 56 56 } // if 57 57 } // for … … 60 60 61 61 StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) : 62 Parent( tq, baseStruct-> get_name(), attributes ), baseStruct( baseStruct ) {}62 Parent( tq, baseStruct->name, attributes ), baseStruct( baseStruct ) {} 63 63 64 64 std::string StructInstType::typeString() const { return "struct"; } … … 84 84 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 85 85 assert( baseStruct ); 86 doLookup( baseStruct-> get_members(), name, foundDecls );86 doLookup( baseStruct->members, name, foundDecls ); 87 87 } 88 88 … … 103 103 104 104 UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) : 105 Parent( tq, baseUnion-> get_name(), attributes ), baseUnion( baseUnion ) {}105 Parent( tq, baseUnion->name, attributes ), baseUnion( baseUnion ) {} 106 106 107 107 std::string UnionInstType::typeString() const { return "union"; } … … 127 127 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 128 128 assert( baseUnion ); 129 doLookup( baseUnion-> get_members(), name, foundDecls );129 doLookup( baseUnion->members, name, foundDecls ); 130 130 } 131 131 -
src/benchmark/Makefile.am
recae5860 radb6a4f1 96 96 ctxswitch-cfa_coroutine.run \ 97 97 ctxswitch-cfa_thread.run \ 98 ctxswitch-cfa_thread2.run \ 98 99 ctxswitch-upp_coroutine.run \ 99 100 ctxswitch-upp_thread.run \ 101 -ctxswitch-kos_fibre.run \ 102 -ctxswitch-kos_fibre2.run \ 100 103 ctxswitch-goroutine.run \ 101 104 ctxswitch-java_thread.run 102 105 106 ctxswitch-pthread$(EXEEXT): 107 @@BACKEND_CC@ ctxswitch/pthreads.c -DBENCH_N=50000000 -I. -lrt -pthread ${AM_CFLAGS} ${CFLAGS} ${ccflags} 108 103 109 ctxswitch-cfa_coroutine$(EXEEXT): 104 @${CC} ctxswitch/cfa_cor.c -DBENCH_N=50000000 -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}110 @${CC} ctxswitch/cfa_cor.c -DBENCH_N=50000000 -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 105 111 106 112 ctxswitch-cfa_thread$(EXEEXT): 107 @${CC} ctxswitch/cfa_thrd.c -DBENCH_N=50000000 -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 113 @${CC} ctxswitch/cfa_thrd.c -DBENCH_N=50000000 -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 114 115 ctxswitch-cfa_thread2$(EXEEXT): 116 @${CC} ctxswitch/cfa_thrd2.c -DBENCH_N=50000000 -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 108 117 109 118 ctxswitch-upp_coroutine$(EXEEXT): 110 @u++ ctxswitch/upp_cor.cc -DBENCH_N=50000000 -I. -nodebug -lrt -quiet ${AM_CFLAGS} ${CFLAGS} ${ccflags}119 @u++ ctxswitch/upp_cor.cc -DBENCH_N=50000000 -I. -nodebug -lrt -quiet ${AM_CFLAGS} ${CFLAGS} ${ccflags} 111 120 112 121 ctxswitch-upp_thread$(EXEEXT): 113 @u++ ctxswitch/upp_thrd.cc -DBENCH_N=50000000 -I. -nodebug -lrt -quiet ${AM_CFLAGS} ${CFLAGS} ${ccflags} 114 115 ctxswitch-pthread$(EXEEXT): 116 @@BACKEND_CC@ ctxswitch/pthreads.c -DBENCH_N=50000000 -I. -lrt -pthread ${AM_CFLAGS} ${CFLAGS} ${ccflags} 122 @u++ ctxswitch/upp_thrd.cc -DBENCH_N=50000000 -I. -nodebug -lrt -quiet ${AM_CFLAGS} ${CFLAGS} ${ccflags} 123 124 ctxswitch-kos_fibre$(EXEEXT): 125 @${CXX} ctxswitch/kos_fibre.cpp -DBENCH_N=50000000 -I. -I/home/tdelisle/software/KOS/src/ -g -O2 -lfibre -lpthread -lrt 126 127 ctxswitch-kos_fibre2$(EXEEXT): 128 @${CXX} ctxswitch/kos_fibre2.cpp -DBENCH_N=50000000 -I. -I/home/tdelisle/software/KOS/src/ -g -O2 -lfibre -lpthread -lrt 117 129 118 130 ctxswitch-goroutine$(EXEEXT): -
src/benchmark/Makefile.in
recae5860 radb6a4f1 509 509 ctxswitch-cfa_coroutine.run \ 510 510 ctxswitch-cfa_thread.run \ 511 ctxswitch-cfa_thread2.run \ 511 512 ctxswitch-upp_coroutine.run \ 512 513 ctxswitch-upp_thread.run \ 514 -ctxswitch-kos_fibre.run \ 515 -ctxswitch-kos_fibre2.run \ 513 516 ctxswitch-goroutine.run \ 514 517 ctxswitch-java_thread.run 515 518 519 ctxswitch-pthread$(EXEEXT): 520 @@BACKEND_CC@ ctxswitch/pthreads.c -DBENCH_N=50000000 -I. -lrt -pthread ${AM_CFLAGS} ${CFLAGS} ${ccflags} 521 516 522 ctxswitch-cfa_coroutine$(EXEEXT): 517 @${CC} ctxswitch/cfa_cor.c -DBENCH_N=50000000 -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}523 @${CC} ctxswitch/cfa_cor.c -DBENCH_N=50000000 -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 518 524 519 525 ctxswitch-cfa_thread$(EXEEXT): 520 @${CC} ctxswitch/cfa_thrd.c -DBENCH_N=50000000 -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 526 @${CC} ctxswitch/cfa_thrd.c -DBENCH_N=50000000 -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 527 528 ctxswitch-cfa_thread2$(EXEEXT): 529 @${CC} ctxswitch/cfa_thrd2.c -DBENCH_N=50000000 -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 521 530 522 531 ctxswitch-upp_coroutine$(EXEEXT): 523 @u++ ctxswitch/upp_cor.cc -DBENCH_N=50000000 -I. -nodebug -lrt -quiet ${AM_CFLAGS} ${CFLAGS} ${ccflags}532 @u++ ctxswitch/upp_cor.cc -DBENCH_N=50000000 -I. -nodebug -lrt -quiet ${AM_CFLAGS} ${CFLAGS} ${ccflags} 524 533 525 534 ctxswitch-upp_thread$(EXEEXT): 526 @u++ ctxswitch/upp_thrd.cc -DBENCH_N=50000000 -I. -nodebug -lrt -quiet ${AM_CFLAGS} ${CFLAGS} ${ccflags} 527 528 ctxswitch-pthread$(EXEEXT): 529 @@BACKEND_CC@ ctxswitch/pthreads.c -DBENCH_N=50000000 -I. -lrt -pthread ${AM_CFLAGS} ${CFLAGS} ${ccflags} 535 @u++ ctxswitch/upp_thrd.cc -DBENCH_N=50000000 -I. -nodebug -lrt -quiet ${AM_CFLAGS} ${CFLAGS} ${ccflags} 536 537 ctxswitch-kos_fibre$(EXEEXT): 538 @${CXX} ctxswitch/kos_fibre.cpp -DBENCH_N=50000000 -I. -I/home/tdelisle/software/KOS/src/ -g -O2 -lfibre -lpthread -lrt 539 540 ctxswitch-kos_fibre2$(EXEEXT): 541 @${CXX} ctxswitch/kos_fibre2.cpp -DBENCH_N=50000000 -I. -I/home/tdelisle/software/KOS/src/ -g -O2 -lfibre -lpthread -lrt 530 542 531 543 ctxswitch-goroutine$(EXEEXT): … … 682 694 683 695 compile-io$(EXEEXT): 684 @${CC} -quiet -fsyntax-only -w ../tests/io .c@CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}696 @${CC} -quiet -fsyntax-only -w ../tests/io1.c @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 685 697 686 698 compile-monitor$(EXEEXT): 687 @${CC} -quiet -fsyntax-only -w ../tests/concurrent/monitor.c 699 @${CC} -quiet -fsyntax-only -w ../tests/concurrent/monitor.c @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 688 700 689 701 compile-operators$(EXEEXT): … … 694 706 695 707 compile-typeof$(EXEEXT): 696 @${CC} -quiet -fsyntax-only -w ../tests/typeof.c 708 @${CC} -quiet -fsyntax-only -w ../tests/typeof.c @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags} 697 709 698 710 # Tell versions [3.59,3.63) of GNU make to not export all variables. -
src/libcfa/concurrency/invoke.h
recae5860 radb6a4f1 10 10 // Created On : Tue Jan 17 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 30 22:33:59201813 // Update Count : 3 012 // Last Modified On : Sat May 19 08:23:21 2018 13 // Update Count : 31 14 14 // 15 15 … … 18 18 #include "bits/locks.h" 19 19 20 #define TL_GET( member ) kernelTLS.member21 #define TL_SET( member, value ) kernelTLS.member = value;22 23 20 #ifdef __cforall 24 21 extern "C" { … … 28 25 #ifndef _INVOKE_H_ 29 26 #define _INVOKE_H_ 27 28 #ifdef __ARM_ARCH 29 // function prototypes are only really used by these macros on ARM 30 void disable_global_interrupts(); 31 void enable_global_interrupts(); 32 33 #define TL_GET( member ) ( { __typeof__( kernelTLS.member ) target; \ 34 disable_global_interrupts(); \ 35 target = kernelTLS.member; \ 36 enable_global_interrupts(); \ 37 target; } ) 38 #define TL_SET( member, value ) disable_global_interrupts(); \ 39 kernelTLS.member = value; \ 40 enable_global_interrupts(); 41 #else 42 #define TL_GET( member ) kernelTLS.member 43 #define TL_SET( member, value ) kernelTLS.member = value; 44 #endif 30 45 31 46 #ifdef __cforall
Note: See TracChangeset
for help on using the changeset viewer.