Changeset c14cff1 for src/ResolvExpr
- Timestamp:
- Feb 25, 2016, 5:16:15 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 071a31a
- Parents:
- a9a259c (diff), ac1ed49 (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/ResolvExpr
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AdjustExprType.cc
ra9a259c rc14cff1 36 36 virtual Type* mutate( TypeInstType *aggregateUseType ); 37 37 virtual Type* mutate( TupleType *tupleType ); 38 virtual Type* mutate( VarArgsType *varArgsType ); 38 39 39 40 const TypeEnvironment &env; … … 111 112 return tupleType; 112 113 } 114 115 Type *AdjustExprType::mutate( VarArgsType *varArgsType ) { 116 return varArgsType; 117 } 113 118 } // namespace ResolvExpr 114 119 -
src/ResolvExpr/AlternativeFinder.cc
ra9a259c rc14cff1 572 572 573 573 AltList candidates; 574 SemanticError errors; 574 575 575 576 for ( AltList::const_iterator func = funcFinder.alternatives.begin(); func != funcFinder.alternatives.end(); ++func ) { 576 PRINT( 577 std::cerr << "working on alternative: " << std::endl; 578 func->print( std::cerr, 8 ); 579 ) 580 // check if the type is pointer to function 581 PointerType *pointer; 582 if ( func->expr->get_results().size() == 1 && ( pointer = dynamic_cast< PointerType* >( func->expr->get_results().front() ) ) ) { 583 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 584 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 585 // XXX 586 //Designators::check_alternative( function, *actualAlt ); 587 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) ); 588 } 589 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( pointer->get_base() ) ) { 590 EqvClass eqvClass; 591 if ( func->env.lookup( typeInst->get_name(), eqvClass ) && eqvClass.type ) { 592 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) { 593 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 594 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) ); 595 } // for 577 try { 578 PRINT( 579 std::cerr << "working on alternative: " << std::endl; 580 func->print( std::cerr, 8 ); 581 ) 582 // check if the type is pointer to function 583 PointerType *pointer; 584 if ( func->expr->get_results().size() == 1 && ( pointer = dynamic_cast< PointerType* >( func->expr->get_results().front() ) ) ) { 585 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 586 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 587 // XXX 588 //Designators::check_alternative( function, *actualAlt ); 589 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) ); 590 } 591 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( pointer->get_base() ) ) { 592 EqvClass eqvClass; 593 if ( func->env.lookup( typeInst->get_name(), eqvClass ) && eqvClass.type ) { 594 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) { 595 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 596 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) ); 597 } // for 598 } // if 596 599 } // if 597 600 } // if 601 } else { 602 // seek a function operator that's compatible 603 if ( ! doneInit ) { 604 doneInit = true; 605 NameExpr *opExpr = new NameExpr( "?()" ); 606 try { 607 funcOpFinder.findWithAdjustment( opExpr ); 608 } catch( SemanticError &e ) { 609 // it's ok if there aren't any defined function ops 610 } 611 PRINT( 612 std::cerr << "known function ops:" << std::endl; 613 printAlts( funcOpFinder.alternatives, std::cerr, 8 ); 614 ) 615 } 616 617 for ( AltList::const_iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) { 618 // check if the type is pointer to function 619 PointerType *pointer; 620 if ( funcOp->expr->get_results().size() == 1 621 && ( pointer = dynamic_cast< PointerType* >( funcOp->expr->get_results().front() ) ) ) { 622 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 623 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 624 AltList currentAlt; 625 currentAlt.push_back( *func ); 626 currentAlt.insert( currentAlt.end(), actualAlt->begin(), actualAlt->end() ); 627 makeFunctionAlternatives( *funcOp, function, currentAlt, std::back_inserter( candidates ) ); 628 } // for 629 } // if 630 } // if 631 } // for 598 632 } // if 599 } else { 600 // seek a function operator that's compatible 601 if ( ! doneInit ) { 602 doneInit = true; 603 NameExpr *opExpr = new NameExpr( "?()" ); 604 try { 605 funcOpFinder.findWithAdjustment( opExpr ); 606 } catch( SemanticError &e ) { 607 // it's ok if there aren't any defined function ops 608 } 609 PRINT( 610 std::cerr << "known function ops:" << std::endl; 611 printAlts( funcOpFinder.alternatives, std::cerr, 8 ); 612 ) 613 } 614 615 for ( AltList::const_iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) { 616 // check if the type is pointer to function 617 PointerType *pointer; 618 if ( funcOp->expr->get_results().size() == 1 619 && ( pointer = dynamic_cast< PointerType* >( funcOp->expr->get_results().front() ) ) ) { 620 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 621 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 622 AltList currentAlt; 623 currentAlt.push_back( *func ); 624 currentAlt.insert( currentAlt.end(), actualAlt->begin(), actualAlt->end() ); 625 makeFunctionAlternatives( *funcOp, function, currentAlt, std::back_inserter( candidates ) ); 626 } // for 627 } // if 628 } // if 629 } // for 630 } // if 631 } // for 633 } catch ( SemanticError &e ) { 634 errors.append( e ); 635 } 636 } // for 637 638 // Implement SFINAE; resolution errors are only errors if there aren't any non-erroneous resolutions 639 if ( candidates.empty() && ! errors.isEmpty() ) { throw errors; } 632 640 633 641 for ( AltList::iterator withFunc = candidates.begin(); withFunc != candidates.end(); ++withFunc ) { -
src/ResolvExpr/CommonType.cc
ra9a259c rc14cff1 38 38 virtual void visit( TypeInstType *aggregateUseType ); 39 39 virtual void visit( TupleType *tupleType ); 40 virtual void visit( VarArgsType *varArgsType ); 40 41 41 42 template< typename RefType > void handleRefType( RefType *inst, Type *other ); … … 213 214 void CommonType::visit( TupleType *tupleType ) { 214 215 } 216 217 void CommonType::visit( VarArgsType *varArgsType ) { 218 } 215 219 } // namespace ResolvExpr 216 220 -
src/ResolvExpr/ConversionCost.cc
ra9a259c rc14cff1 247 247 } // if 248 248 } 249 250 void ConversionCost::visit(VarArgsType *varArgsType) { 251 if ( VarArgsType *destAsVarArgs = dynamic_cast< VarArgsType* >( dest ) ) { 252 cost = Cost::zero; 253 } 254 } 249 255 } // namespace ResolvExpr 250 256 -
src/ResolvExpr/ConversionCost.h
ra9a259c rc14cff1 40 40 virtual void visit(TypeInstType *aggregateUseType); 41 41 virtual void visit(TupleType *tupleType); 42 virtual void visit(VarArgsType *varArgsType); 42 43 protected: 43 44 Type *dest; -
src/ResolvExpr/PtrsAssignable.cc
ra9a259c rc14cff1 38 38 virtual void visit( TypeInstType *inst ); 39 39 virtual void visit( TupleType *tupleType ); 40 virtual void visit( VarArgsType *varArgsType ); 40 41 private: 41 42 Type *dest; … … 137 138 /// } 138 139 } 140 141 void PtrsAssignable::visit( VarArgsType *varArgsType ) { 142 } 139 143 } // namespace ResolvExpr 140 144 -
src/ResolvExpr/PtrsCastable.cc
ra9a259c rc14cff1 39 39 virtual void visit(TypeInstType *inst); 40 40 virtual void visit(TupleType *tupleType); 41 virtual void visit(VarArgsType *varArgsType); 41 42 private: 42 43 Type *dest; … … 139 140 result = objectCast( dest, env, indexer ); 140 141 } 142 143 void PtrsCastable::visit(VarArgsType *varArgsType) { 144 result = objectCast( dest, env, indexer ); 145 } 141 146 } // namespace ResolvExpr 142 147 -
src/ResolvExpr/RenameVars.cc
ra9a259c rc14cff1 113 113 } 114 114 115 void RenameVars::visit( VarArgsType *varArgsType ) { 116 typeBefore( varArgsType ); 117 typeAfter( varArgsType ); 118 } 119 115 120 void RenameVars::typeBefore( Type *type ) { 116 121 if ( ! type->get_forall().empty() ) { -
src/ResolvExpr/RenameVars.h
ra9a259c rc14cff1 43 43 virtual void visit( TypeInstType *aggregateUseType ); 44 44 virtual void visit( TupleType *tupleType ); 45 virtual void visit( VarArgsType *varArgsType ); 45 46 46 47 void typeBefore( Type *type ); -
src/ResolvExpr/Unify.cc
ra9a259c rc14cff1 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Unify.cc -- 7 // Unify.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 38 38 WidenMode operator&( const WidenMode &other ) { WidenMode newWM( *this ); newWM &= other; return newWM; } 39 39 operator bool() { return widenFirst && widenSecond; } 40 40 41 41 bool widenFirst : 1, widenSecond : 1; 42 42 }; … … 45 45 public: 46 46 Unify( Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ); 47 47 48 48 bool get_result() const { return result; } 49 49 private: … … 59 59 virtual void visit(TypeInstType *aggregateUseType); 60 60 virtual void visit(TupleType *tupleType); 61 virtual void visit(VarArgsType *varArgsType); 61 62 62 63 template< typename RefType > void handleRefType( RefType *inst, Type *other ); … … 78 79 bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer, Type *&common ); 79 80 bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ); 80 81 81 82 bool typesCompatible( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { 82 83 TypeEnvironment newEnv; … … 136 137 case TypeDecl::Dtype: 137 138 return ! isFtype( type, indexer ); 138 139 139 140 case TypeDecl::Ftype: 140 141 return isFtype( type, indexer ); … … 195 196 bool widen1 = false, widen2 = false; 196 197 Type *type1 = 0, *type2 = 0; 197 198 198 199 if ( env.lookup( var1->get_name(), class1 ) ) { 199 200 hasClass1 = true; … … 216 217 widen2 = widenMode.widenSecond && class2.allowWidening; 217 218 } // if 218 219 219 220 if ( type1 && type2 ) { 220 221 // std::cout << "has type1 && type2" << std::endl; … … 435 436 // to unify, array types must both be VLA or both not VLA 436 437 // and must both have a dimension expression or not have a dimension 437 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() 438 && ((arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0) 439 || (arrayType->get_dimension() == 0 && otherArray->get_dimension() == 0))) { 438 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) { 440 439 441 440 // not positive this is correct in all cases, but it's needed for typedefs … … 448 447 ConstantExpr * ce1 = dynamic_cast< ConstantExpr * >( arrayType->get_dimension() ); 449 448 ConstantExpr * ce2 = dynamic_cast< ConstantExpr * >( otherArray->get_dimension() ); 450 assert(ce1 && ce2); 451 452 Constant * c1 = ce1->get_constant(); 453 Constant * c2 = ce2->get_constant(); 454 455 if ( c1->get_value() != c2->get_value() ) { 456 // does not unify if the dimension is different 457 return; 449 // see C11 Reference Manual 6.7.6.2.6 450 // two array types with size specifiers that are integer constant expressions are 451 // compatible if both size specifiers have the same constant value 452 if ( ce1 && ce2 ) { 453 Constant * c1 = ce1->get_constant(); 454 Constant * c2 = ce2->get_constant(); 455 456 if ( c1->get_value() != c2->get_value() ) { 457 // does not unify if the dimension is different 458 return; 459 } 458 460 } 459 461 } … … 484 486 485 487 if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 486 488 487 489 if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 488 490 … … 582 584 } 583 585 586 void Unify::visit(VarArgsType *varArgsType) { 587 result = dynamic_cast< VarArgsType* >( type2 ); 588 } 589 584 590 } // namespace ResolvExpr 585 591
Note:
See TracChangeset
for help on using the changeset viewer.