Changeset 02ec390


Ignore:
Timestamp:
Nov 25, 2015, 2:53:22 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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, string, with_gc
Children:
7e23d0a
Parents:
70d4b4f
Message:

First attempt at properly resolving functions on generic types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r70d4b4f r02ec390  
    6161
    6262                template< typename RefType > void handleRefType( RefType *inst, Type *other );
     63                template< typename RefType > void handleGenericRefType( RefType *inst, Type *other );
    6364
    6465                bool result;
     
    464465
    465466        template< typename RefType >
    466         void Unify::handleRefType( RefType *inst, Type *other ) { 
     467        void Unify::handleRefType( RefType *inst, Type *other ) {
     468                // check that other type is compatible and named the same
    467469                RefType *otherStruct = dynamic_cast< RefType* >( other );
    468470                result = otherStruct && inst->get_name() == otherStruct->get_name();
    469         } 
     471        }
     472
     473        template< typename RefType >
     474        void Unify::handleGenericRefType( RefType *inst, Type *other ) {
     475                // Check that other type is compatible and named the same
     476                handleRefType( inst, other );
     477                if ( ! result ) return;
     478                // Check that parameters of type unify, if any
     479                std::list< Expression* > params = inst->get_parameters();
     480                if ( ! params.empty() ) {
     481                        std::list< TypeDecl* > *baseParams = inst->get_baseParameters();
     482                        if ( ! baseParams ) {
     483                                result = false;
     484                                return;
     485                        }
     486                        std::list< Expression* >::const_iterator it = params.begin();
     487                        std::list< TypeDecl* >::const_iterator baseIt = baseParams->begin();
     488                        while ( it != params.end() && baseIt != baseParams->end()) {
     489                                TypeExpr *param = dynamic_cast< TypeExpr* >(*it);
     490                                assert(param && "Aggregate parameters should be type expressions");
     491                                TypeInstType baseType(Type::Qualifiers(), (*baseIt)->get_name(), *baseIt);
     492                                if ( ! unifyExact( param->get_type(), &baseType, env, needAssertions, haveAssertions, openVars, WidenMode(false, false), indexer ) ) {
     493                                        result = false;
     494                                        return;
     495                                }
     496                               
     497                                ++it;
     498                                ++baseIt;
     499                        }
     500                        if ( it != params.end() || baseIt != baseParams->end() ) {
     501                                result = false;
     502                        }
     503                }
     504        }
    470505
    471506        void Unify::visit(StructInstType *structInst) {
    472                 handleRefType( structInst, type2 );
     507                handleGenericRefType( structInst, type2 );
    473508        }
    474509
    475510        void Unify::visit(UnionInstType *unionInst) {
    476                 handleRefType( unionInst, type2 );
     511                handleGenericRefType( unionInst, type2 );
    477512        }
    478513
Note: See TracChangeset for help on using the changeset viewer.