Ignore:
Timestamp:
Nov 25, 2016, 6:11:03 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
0f35657
Parents:
186fd86
Message:

add support for built-in sized trait which decouples size/alignment information from otype parameters, add test for sized trait

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r186fd86 r2c57025  
    109109                newFirst->get_qualifiers() = Type::Qualifiers();
    110110                newSecond->get_qualifiers() = Type::Qualifiers();
    111 ///   std::cout << "first is ";
    112 ///   first->print( std::cout );
    113 ///   std::cout << std::endl << "second is ";
    114 ///   second->print( std::cout );
    115 ///   std::cout << std::endl << "newFirst is ";
    116 ///   newFirst->print( std::cout );
    117 ///   std::cout << std::endl << "newSecond is ";
    118 ///   newSecond->print( std::cout );
    119 ///   std::cout << std::endl;
     111///   std::cerr << "first is ";
     112///   first->print( std::cerr );
     113///   std::cerr << std::endl << "second is ";
     114///   second->print( std::cerr );
     115///   std::cerr << std::endl << "newFirst is ";
     116///   newFirst->print( std::cerr );
     117///   std::cerr << std::endl << "newSecond is ";
     118///   newSecond->print( std::cerr );
     119///   std::cerr << std::endl;
    120120                bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    121121                delete newFirst;
     
    133133        }
    134134
    135         bool tyVarCompatible( TypeDecl::Kind kind, Type *type, const SymTab::Indexer &indexer ) {
    136                 switch ( kind ) {
     135        struct CompleteTypeChecker : public Visitor {
     136                virtual void visit( VoidType *basicType ) { status = false; }
     137                virtual void visit( BasicType *basicType ) {}
     138                virtual void visit( PointerType *pointerType ) {}
     139                virtual void visit( ArrayType *arrayType ) { status = ! arrayType->get_isVarLen(); }
     140                virtual void visit( FunctionType *functionType ) {}
     141                virtual void visit( StructInstType *aggregateUseType ) { status = aggregateUseType->get_baseStruct()->has_body(); }
     142                virtual void visit( UnionInstType *aggregateUseType ) { status = aggregateUseType->get_baseUnion()->has_body(); }
     143                // xxx - enum inst does not currently contain a pointer to base, this should be fixed.
     144                virtual void visit( EnumInstType *aggregateUseType ) { /* status = aggregateUseType->get_baseEnum()->hasBody(); */ }
     145                virtual void visit( TraitInstType *aggregateUseType ) { assert( false ); }
     146                virtual void visit( TypeInstType *aggregateUseType ) { status = aggregateUseType->get_baseType()->isComplete(); }
     147                virtual void visit( TupleType *tupleType ) {} // xxx - not sure if this is right, might need to recursively check complete-ness
     148                virtual void visit( TypeofType *typeofType ) { assert( false ); }
     149                virtual void visit( AttrType *attrType ) { assert( false ); } // xxx - not sure what to do here
     150                virtual void visit( VarArgsType *varArgsType ){} // xxx - is this right?
     151                virtual void visit( ZeroType *zeroType ) {}
     152                virtual void visit( OneType *oneType ) {}
     153                bool status = true;
     154        };
     155        bool isComplete( Type * type ) {
     156                CompleteTypeChecker checker;
     157                assert( type );
     158                type->accept( checker );
     159                return checker.status;
     160        }
     161
     162        bool tyVarCompatible( const TypeDecl::Data & data, Type *type, const SymTab::Indexer &indexer ) {
     163                switch ( data.kind ) {
    137164                  case TypeDecl::Any:
    138165                  case TypeDecl::Dtype:
    139                         return ! isFtype( type, indexer );
    140 
     166                        // to bind to an object type variable, the type must not be a function type.
     167                        // if the type variable is specified to be a complete type then the incoming
     168                        // type must also be complete
     169                        return ! isFtype( type, indexer ) && (! data.isComplete || isComplete( type ));
    141170                  case TypeDecl::Ftype:
    142171                        return isFtype( type, indexer );
     
    146175        }
    147176
    148         bool bindVar( TypeInstType *typeInst, Type *other, TypeDecl::Kind kind, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) {
     177        bool bindVar( TypeInstType *typeInst, Type *other, const TypeDecl::Data & data, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) {
    149178                OpenVarSet::const_iterator tyvar = openVars.find( typeInst->get_name() );
    150179                assert( tyvar != openVars.end() );
     
    185214                        newClass.type->get_qualifiers() = Type::Qualifiers();
    186215                        newClass.allowWidening = widenMode.widenFirst && widenMode.widenSecond;
    187                         newClass.kind = kind;
     216                        newClass.data = data;
    188217                        env.add( newClass );
    189218                } // if
     
    191220        }
    192221
    193         bool bindVarToVar( TypeInstType *var1, TypeInstType *var2, TypeDecl::Kind kind, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) {
     222        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 ) {
    194223                bool result = true;
    195224                EqvClass class1, class2;
     
    220249
    221250                if ( type1 && type2 ) {
    222 //    std::cout << "has type1 && type2" << std::endl;
     251//    std::cerr << "has type1 && type2" << std::endl;
    223252                        WidenMode newWidenMode ( widen1, widen2 );
    224253                        Type *common = 0;
     
    258287                        newClass.vars.insert( var2->get_name() );
    259288                        newClass.allowWidening = widen1 && widen2;
    260                         newClass.kind = kind;
     289                        newClass.data = data;
    261290                        env.add( newClass );
    262291                } // if
     
    321350                } // if
    322351#ifdef DEBUG
    323                 std::cout << "============ unifyExact" << std::endl;
    324                 std::cout << "type1 is ";
    325                 type1->print( std::cout );
    326                 std::cout << std::endl << "type2 is ";
    327                 type2->print( std::cout );
    328                 std::cout << std::endl << "openVars are ";
    329                 printOpenVarSet( openVars, std::cout, 8 );
    330                 std::cout << std::endl << "input env is " << std::endl;
    331                 debugEnv.print( std::cout, 8 );
    332                 std::cout << std::endl << "result env is " << std::endl;
    333                 env.print( std::cout, 8 );
    334                 std::cout << "result is " << result << std::endl;
     352                std::cerr << "============ unifyExact" << std::endl;
     353                std::cerr << "type1 is ";
     354                type1->print( std::cerr );
     355                std::cerr << std::endl << "type2 is ";
     356                type2->print( std::cerr );
     357                std::cerr << std::endl << "openVars are ";
     358                printOpenVarSet( openVars, std::cerr, 8 );
     359                std::cerr << std::endl << "input env is " << std::endl;
     360                debugEnv.print( std::cerr, 8 );
     361                std::cerr << std::endl << "result env is " << std::endl;
     362                env.print( std::cerr, 8 );
     363                std::cerr << "result is " << result << std::endl;
    335364#endif
    336365                return result;
     
    347376                bool result;
    348377#ifdef DEBUG
    349                 std::cout << "unifyInexact type 1 is ";
    350                 type1->print( std::cout );
    351                 std::cout << "type 2 is ";
    352                 type2->print( std::cout );
    353                 std::cout << std::endl;
     378                std::cerr << "unifyInexact type 1 is ";
     379                type1->print( std::cerr );
     380                std::cerr << "type 2 is ";
     381                type2->print( std::cerr );
     382                std::cerr << std::endl;
    354383#endif
    355384                if ( ! unifyExact( type1, type2, env, needAssertions, haveAssertions, openVars, widenMode, indexer ) ) {
    356385#ifdef DEBUG
    357                         std::cout << "unifyInexact: no exact unification found" << std::endl;
     386                        std::cerr << "unifyInexact: no exact unification found" << std::endl;
    358387#endif
    359388                        if ( ( common = commonType( type1, type2, widenMode.widenFirst, widenMode.widenSecond, indexer, env, openVars ) ) ) {
    360389                                common->get_qualifiers() = tq1 + tq2;
    361390#ifdef DEBUG
    362                                 std::cout << "unifyInexact: common type is ";
    363                                 common->print( std::cout );
    364                                 std::cout << std::endl;
     391                                std::cerr << "unifyInexact: common type is ";
     392                                common->print( std::cerr );
     393                                std::cerr << std::endl;
    365394#endif
    366395                                result = true;
    367396                        } else {
    368397#ifdef DEBUG
    369                                 std::cout << "unifyInexact: no common type found" << std::endl;
     398                                std::cerr << "unifyInexact: no common type found" << std::endl;
    370399#endif
    371400                                result = false;
     
    404433
    405434        void markAssertionSet( AssertionSet &assertions, DeclarationWithType *assert ) {
    406 ///   std::cout << "assertion set is" << std::endl;
    407 ///   printAssertionSet( assertions, std::cout, 8 );
    408 ///   std::cout << "looking for ";
    409 ///   assert->print( std::cout );
    410 ///   std::cout << std::endl;
     435///   std::cerr << "assertion set is" << std::endl;
     436///   printAssertionSet( assertions, std::cerr, 8 );
     437///   std::cerr << "looking for ";
     438///   assert->print( std::cerr );
     439///   std::cerr << std::endl;
    411440                AssertionSet::iterator i = assertions.find( assert );
    412441                if ( i != assertions.end() ) {
    413 ///     std::cout << "found it!" << std::endl;
     442///     std::cerr << "found it!" << std::endl;
    414443                        i->second = true;
    415444                } // if
Note: See TracChangeset for help on using the changeset viewer.