Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.h

    r7b5694d r2773ab8  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 13:09:04 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jan 17 11:12:00 2023
    13 // Update Count     : 5
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Mon Jun 18 11:58:00 2018
     13// Update Count     : 4
    1414//
    1515
     
    3737
    3838namespace ResolvExpr {
     39        bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer );
     40        bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer, Type *&commonType );
     41        bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer );
     42        bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer, Type *&common );
    3943
    40 bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer );
    41 bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer, Type *&commonType );
    42 bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer );
    43 bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer, Type *&common );
     44        template< typename Iterator1, typename Iterator2 >
     45        bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer, std::list< Type* > &commonTypes ) {
     46                for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) {
     47                        Type *commonType = 0;
     48                        if ( ! unify( *list1Begin, *list2Begin, env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
     49                                return false;
     50                        } // if
     51                        commonTypes.push_back( commonType );
     52                } // for
     53                if ( list1Begin != list1End || list2Begin != list2End ) {
     54                        return false;
     55                } else {
     56                        return true;
     57                } // if
     58        }
    4459
    45 bool typesCompatible( const Type *, const Type *, const SymTab::Indexer & indexer, const TypeEnvironment & env );
    46 bool typesCompatibleIgnoreQualifiers( const Type *, const Type *, const SymTab::Indexer & indexer, const TypeEnvironment & env );
     60        template< typename Iterator1, typename Iterator2 >
     61        bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ) {
     62                std::list< Type* > commonTypes;
     63                if ( unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes ) ) {
     64                        deleteAll( commonTypes );
     65                        return true;
     66                } else {
     67                        return false;
     68                } // if
     69        }
    4770
    48 inline bool typesCompatible( const Type * t1, const Type * t2, const SymTab::Indexer & indexer ) {
    49         TypeEnvironment env;
    50         return typesCompatible( t1, t2, indexer, env );
    51 }
     71        bool unify(
     72                const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
     73                ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
     74                ast::OpenVarSet & open, const ast::SymbolTable & symtab );
    5275
    53 inline bool typesCompatibleIgnoreQualifiers( const Type * t1, const Type * t2, const SymTab::Indexer & indexer ) {
    54         TypeEnvironment env;
    55         return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
    56 }
     76        bool unify(
     77                const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
     78                ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
     79                ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common );
    5780
    58 bool unify(
    59         const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    60         ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    61         ast::OpenVarSet & open, const ast::SymbolTable & symtab );
     81        bool unifyExact(
     82                const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
     83                ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
     84                WidenMode widen, const ast::SymbolTable & symtab );
    6285
    63 bool unify(
    64         const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    65         ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    66         ast::OpenVarSet & open, const ast::SymbolTable & symtab, ast::ptr<ast::Type> & common );
    67 
    68 bool unifyExact(
    69         const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env,
    70         ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open,
    71         WidenMode widen, const ast::SymbolTable & symtab );
    72 
    73 bool unifyInexact(
    74         const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
    75         ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
    76         const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab,
    77         ast::ptr<ast::Type> & common );
    78 
    79 bool typesCompatible(
    80         const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},
    81         const ast::TypeEnvironment & env = {} );
    82 
    83 bool typesCompatibleIgnoreQualifiers(
    84         const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},
    85         const ast::TypeEnvironment & env = {} );
    86 
    87 /// Creates the type represented by the list of returnVals in a FunctionType.
    88 /// The caller owns the return value.
    89 Type * extractResultType( FunctionType * functionType );
    90 /// Creates or extracts the type represented by returns in a `FunctionType`.
    91 ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func );
    92 
    93 std::vector<ast::ptr<ast::Type>> flattenList(
    94         const std::vector<ast::ptr<ast::Type>> & src, ast::TypeEnvironment & env
    95 );
     86        bool unifyInexact(
     87                const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
     88                ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have,
     89                const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab,
     90                ast::ptr<ast::Type> & common );
    9691
    9792} // namespace ResolvExpr
Note: See TracChangeset for help on using the changeset viewer.