Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r4040425 rd3b7937  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Unify.cc --
     7// Unify.cc -- 
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:27:10 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:37:05 2016
    13 // Update Count     : 37
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Sep 02 14:43:22 2015
     13// Update Count     : 36
    1414//
    1515
     
    3838                WidenMode operator&( const WidenMode &other ) { WidenMode newWM( *this ); newWM &= other; return newWM; }
    3939                operator bool() { return widenFirst && widenSecond; }
    40 
     40 
    4141                bool widenFirst : 1, widenSecond : 1;
    4242        };
     
    4545          public:
    4646                Unify( Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer );
    47 
     47 
    4848                bool get_result() const { return result; }
    4949          private:
     
    5656                virtual void visit(UnionInstType *aggregateUseType);
    5757                virtual void visit(EnumInstType *aggregateUseType);
    58                 virtual void visit(TraitInstType *aggregateUseType);
     58                virtual void visit(ContextInstType *aggregateUseType);
    5959                virtual void visit(TypeInstType *aggregateUseType);
    6060                virtual void visit(TupleType *tupleType);
    61                 virtual void visit(VarArgsType *varArgsType);
    6261
    6362                template< typename RefType > void handleRefType( RefType *inst, Type *other );
     
    7978        bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer, Type *&common );
    8079        bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer );
    81 
     80 
    8281        bool typesCompatible( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    8382                TypeEnvironment newEnv;
     
    137136                  case TypeDecl::Dtype:
    138137                        return ! isFtype( type, indexer );
    139 
     138 
    140139                  case TypeDecl::Ftype:
    141140                        return isFtype( type, indexer );
     
    196195                bool widen1 = false, widen2 = false;
    197196                Type *type1 = 0, *type2 = 0;
    198 
     197 
    199198                if ( env.lookup( var1->get_name(), class1 ) ) {
    200199                        hasClass1 = true;
     
    217216                        widen2 = widenMode.widenSecond && class2.allowWidening;
    218217                } // if
    219 
     218 
    220219                if ( type1 && type2 ) {
    221220//    std::cout << "has type1 && type2" << std::endl;
     
    436435                // to unify, array types must both be VLA or both not VLA
    437436                // and must both have a dimension expression or not have a dimension
    438                 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) {
     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))) {
    439440
    440441                        // not positive this is correct in all cases, but it's needed for typedefs
     
    447448                                ConstantExpr * ce1 = dynamic_cast< ConstantExpr * >( arrayType->get_dimension() );
    448449                                ConstantExpr * ce2 = dynamic_cast< ConstantExpr * >( otherArray->get_dimension() );
    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                                         }
     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;
    460458                                }
    461459                        }
     
    486484
    487485                        if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
    488 
     486       
    489487                                if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
    490488
     
    541539        }
    542540
    543         void Unify::visit(TraitInstType *contextInst) {
     541        void Unify::visit(ContextInstType *contextInst) {
    544542                handleRefType( contextInst, type2 );
    545543        }
     
    584582        }
    585583
    586         void Unify::visit(VarArgsType *varArgsType) {
    587                 result = dynamic_cast< VarArgsType* >( type2 );
    588         }
    589 
    590584} // namespace ResolvExpr
    591585
Note: See TracChangeset for help on using the changeset viewer.