Changeset 36a2367
- Timestamp:
- Jan 17, 2018, 11:49:15 AM (6 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:
- 53452de
- Parents:
- d7d9a60
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
rd7d9a60 r36a2367 44 44 namespace ResolvExpr { 45 45 46 class Unify : public Visitor { 47 public: 46 struct Unify : public WithShortCircuiting { 48 47 Unify( Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ); 49 48 50 49 bool get_result() const { return result; } 50 51 void previsit( BaseSyntaxNode * ) { visit_children = false; } 52 53 void postvisit( VoidType * voidType ); 54 void postvisit( BasicType * basicType ); 55 void postvisit( PointerType * pointerType ); 56 void postvisit( ArrayType * arrayType ); 57 void postvisit( ReferenceType * refType ); 58 void postvisit( FunctionType * functionType ); 59 void postvisit( StructInstType * aggregateUseType ); 60 void postvisit( UnionInstType * aggregateUseType ); 61 void postvisit( EnumInstType * aggregateUseType ); 62 void postvisit( TraitInstType * aggregateUseType ); 63 void postvisit( TypeInstType * aggregateUseType ); 64 void postvisit( TupleType * tupleType ); 65 void postvisit( VarArgsType * varArgsType ); 66 void postvisit( ZeroType * zeroType ); 67 void postvisit( OneType * oneType ); 68 51 69 private: 52 virtual void visit(VoidType *voidType);53 virtual void visit(BasicType *basicType);54 virtual void visit(PointerType *pointerType);55 virtual void visit(ArrayType *arrayType);56 virtual void visit(ReferenceType *refType);57 virtual void visit(FunctionType *functionType);58 virtual void visit(StructInstType *aggregateUseType);59 virtual void visit(UnionInstType *aggregateUseType);60 virtual void visit(EnumInstType *aggregateUseType);61 virtual void visit(TraitInstType *aggregateUseType);62 virtual void visit(TypeInstType *aggregateUseType);63 virtual void visit(TupleType *tupleType);64 virtual void visit(VarArgsType *varArgsType);65 virtual void visit(ZeroType *zeroType);66 virtual void visit(OneType *oneType);67 68 70 template< typename RefType > void handleRefType( RefType *inst, Type *other ); 69 71 template< typename RefType > void handleGenericRefType( RefType *inst, Type *other ); … … 325 327 result = bindVar( var2, type1, entry2->second, env, needAssertions, haveAssertions, openVars, widenMode, indexer ); 326 328 } else { 327 Unifycomparator( type2, env, needAssertions, haveAssertions, openVars, widenMode, indexer );329 PassVisitor<Unify> comparator( type2, env, needAssertions, haveAssertions, openVars, widenMode, indexer ); 328 330 type1->accept( comparator ); 329 result = comparator. get_result();331 result = comparator.pass.get_result(); 330 332 } // if 331 333 #ifdef DEBUG … … 404 406 } 405 407 406 void Unify:: visit( __attribute__((unused)) VoidType *voidType) {408 void Unify::postvisit( __attribute__((unused)) VoidType *voidType) { 407 409 result = dynamic_cast< VoidType* >( type2 ); 408 410 } 409 411 410 void Unify:: visit(BasicType *basicType) {412 void Unify::postvisit(BasicType *basicType) { 411 413 if ( BasicType *otherBasic = dynamic_cast< BasicType* >( type2 ) ) { 412 414 result = basicType->get_kind() == otherBasic->get_kind(); … … 436 438 } 437 439 438 void Unify:: visit(PointerType *pointerType) {440 void Unify::postvisit(PointerType *pointerType) { 439 441 if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) { 440 442 result = unifyExact( pointerType->get_base(), otherPointer->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); … … 444 446 } 445 447 446 void Unify:: visit(ReferenceType *refType) {448 void Unify::postvisit(ReferenceType *refType) { 447 449 if ( ReferenceType *otherRef = dynamic_cast< ReferenceType* >( type2 ) ) { 448 450 result = unifyExact( refType->get_base(), otherRef->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); … … 452 454 } 453 455 454 void Unify:: visit(ArrayType *arrayType) {456 void Unify::postvisit(ArrayType *arrayType) { 455 457 ArrayType *otherArray = dynamic_cast< ArrayType* >( type2 ); 456 458 // to unify, array types must both be VLA or both not VLA … … 567 569 } 568 570 569 void Unify:: visit(FunctionType *functionType) {571 void Unify::postvisit(FunctionType *functionType) { 570 572 FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 ); 571 573 if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) { … … 669 671 } 670 672 671 void Unify:: visit(StructInstType *structInst) {673 void Unify::postvisit(StructInstType *structInst) { 672 674 handleGenericRefType( structInst, type2 ); 673 675 } 674 676 675 void Unify:: visit(UnionInstType *unionInst) {677 void Unify::postvisit(UnionInstType *unionInst) { 676 678 handleGenericRefType( unionInst, type2 ); 677 679 } 678 680 679 void Unify:: visit(EnumInstType *enumInst) {681 void Unify::postvisit(EnumInstType *enumInst) { 680 682 handleRefType( enumInst, type2 ); 681 683 } 682 684 683 void Unify:: visit(TraitInstType *contextInst) {685 void Unify::postvisit(TraitInstType *contextInst) { 684 686 handleRefType( contextInst, type2 ); 685 687 } 686 688 687 void Unify:: visit(TypeInstType *typeInst) {689 void Unify::postvisit(TypeInstType *typeInst) { 688 690 assert( openVars.find( typeInst->get_name() ) == openVars.end() ); 689 691 TypeInstType *otherInst = dynamic_cast< TypeInstType* >( type2 ); … … 740 742 } 741 743 742 void Unify:: visit(TupleType *tupleType) {744 void Unify::postvisit(TupleType *tupleType) { 743 745 if ( TupleType *otherTuple = dynamic_cast< TupleType* >( type2 ) ) { 744 746 std::unique_ptr<TupleType> flat1( tupleType->clone() ); … … 757 759 } 758 760 759 void Unify:: visit( __attribute__((unused)) VarArgsType *varArgsType ) {761 void Unify::postvisit( __attribute__((unused)) VarArgsType *varArgsType ) { 760 762 result = dynamic_cast< VarArgsType* >( type2 ); 761 763 } 762 764 763 void Unify:: visit( __attribute__((unused)) ZeroType *zeroType ) {765 void Unify::postvisit( __attribute__((unused)) ZeroType *zeroType ) { 764 766 result = dynamic_cast< ZeroType* >( type2 ); 765 767 } 766 768 767 void Unify:: visit( __attribute__((unused)) OneType *oneType ) {769 void Unify::postvisit( __attribute__((unused)) OneType *oneType ) { 768 770 result = dynamic_cast< OneType* >( type2 ); 769 771 }
Note: See TracChangeset
for help on using the changeset viewer.