Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    rf0ecf9b rea6332d  
    1717#include <iterator>               // for back_insert_iterator, back_inserter
    1818#include <map>                    // for _Rb_tree_const_iterator, _Rb_tree_i...
    19 #include <memory>                 // for unique_ptr
     19#include <memory>                 // for unique_ptr, auto_ptr
    2020#include <set>                    // for set
    2121#include <string>                 // for string, operator==, operator!=, bas...
    2222#include <utility>                // for pair
    2323
    24 #include "Common/PassVisitor.h"   // for PassVisitor
    2524#include "FindOpenVars.h"         // for findOpenVars
    2625#include "Parser/LinkageSpec.h"   // for C
     
    5453                virtual void visit(PointerType *pointerType);
    5554                virtual void visit(ArrayType *arrayType);
    56                 virtual void visit(ReferenceType *refType);
    5755                virtual void visit(FunctionType *functionType);
    5856                virtual void visit(StructInstType *aggregateUseType);
     
    138136        bool tyVarCompatible( const TypeDecl::Data & data, Type *type ) {
    139137                switch ( data.kind ) {
     138                  case TypeDecl::Any:
    140139                  case TypeDecl::Dtype:
    141140                        // to bind to an object type variable, the type must not be a function type.
     
    154153
    155154        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 ) {
    156                 // remove references from other, so that type variables can only bind to value types
    157                 other = other->stripReferences();
    158155                OpenVarSet::const_iterator tyvar = openVars.find( typeInst->get_name() );
    159156                assert( tyvar != openVars.end() );
     
    169166                                Type *common = 0;
    170167                                // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to
    171                                 std::unique_ptr< Type > newType( curClass.type->clone() );
     168                                std::auto_ptr< Type > newType( curClass.type->clone() );
    172169                                newType->get_qualifiers() = typeInst->get_qualifiers();
    173170                                if ( unifyInexact( newType.get(), other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass.allowWidening, true ), indexer, common ) ) {
     
    390387                                } // if
    391388                        } else {
    392                                 common = type1->clone();
    393                                 common->get_qualifiers() = tq1 | tq2;
    394389                                result = true;
    395390                        } // if
     
    444439        }
    445440
    446         void Unify::visit(ReferenceType *refType) {
    447                 if ( ReferenceType *otherRef = dynamic_cast< ReferenceType* >( type2 ) ) {
    448                         result = unifyExact( refType->get_base(), otherRef->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    449                         markAssertions( haveAssertions, needAssertions, refType );
    450                         markAssertions( haveAssertions, needAssertions, otherRef );
    451                 } // if
    452         }
    453 
    454441        void Unify::visit(ArrayType *arrayType) {
    455442                ArrayType *otherArray = dynamic_cast< ArrayType* >( type2 );
     
    457444                // and must both have a dimension expression or not have a dimension
    458445                if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) {
     446
     447                        // not positive this is correct in all cases, but it's needed for typedefs
     448                        if ( arrayType->get_isVarLen() || otherArray->get_isVarLen() ) {
     449                                return;
     450                        }
    459451
    460452                        if ( ! arrayType->get_isVarLen() && ! otherArray->get_isVarLen() &&
     
    532524        /// If this isn't done then argument lists can have wildly different
    533525        /// size and structure, when they should be compatible.
    534         struct TtypeExpander : public WithShortCircuiting {
    535                 TypeEnvironment & tenv;
    536                 TtypeExpander( TypeEnvironment & tenv ) : tenv( tenv ) {}
    537                 void premutate( TypeInstType * ) { visit_children = false; }
    538                 Type * postmutate( TypeInstType * typeInst ) {
     526        struct TtypeExpander : public Mutator {
     527                TypeEnvironment & env;
     528                TtypeExpander( TypeEnvironment & env ) : env( env ) {}
     529                Type * mutate( TypeInstType * typeInst ) {
    539530                        EqvClass eqvClass;
    540                         if ( tenv.lookup( typeInst->get_name(), eqvClass ) ) {
     531                        if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
    541532                                if ( eqvClass.data.kind == TypeDecl::Ttype ) {
    542533                                        // expand ttype parameter into its actual type
     
    556547                dst.clear();
    557548                for ( DeclarationWithType * dcl : src ) {
    558                         PassVisitor<TtypeExpander> expander( env );
     549                        TtypeExpander expander( env );
    559550                        dcl->acceptMutator( expander );
    560551                        std::list< Type * > types;
     
    746737                        std::list<Type *> types1, types2;
    747738
    748                         PassVisitor<TtypeExpander> expander( env );
     739                        TtypeExpander expander( env );
    749740                        flat1->acceptMutator( expander );
    750741                        flat2->acceptMutator( expander );
Note: See TracChangeset for help on using the changeset viewer.