| [a32b204] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
| [66f8528] | 7 | // Unify.h -- | 
|---|
| [a32b204] | 8 | // | 
|---|
|  | 9 | // Author           : Richard C. Bilson | 
|---|
|  | 10 | // Created On       : Sun May 17 13:09:04 2015 | 
|---|
|  | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [6b0b624] | 12 | // Last Modified On : Fri Jul 21 23:09:34 2017 | 
|---|
|  | 13 | // Update Count     : 3 | 
|---|
| [a32b204] | 14 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
| [6b0b624] | 16 | #pragma once | 
|---|
| [51b73452] | 17 |  | 
|---|
| [ea6332d] | 18 | #include <list>                   // for list | 
|---|
|  | 19 |  | 
|---|
|  | 20 | #include "Common/utility.h"       // for deleteAll | 
|---|
|  | 21 | #include "SynTree/Declaration.h"  // for TypeDecl, TypeDecl::Data | 
|---|
|  | 22 | #include "TypeEnvironment.h"      // for AssertionSet, OpenVarSet | 
|---|
|  | 23 |  | 
|---|
|  | 24 | class Type; | 
|---|
|  | 25 | class TypeInstType; | 
|---|
|  | 26 | namespace SymTab { | 
|---|
|  | 27 | class Indexer; | 
|---|
|  | 28 | }  // namespace SymTab | 
|---|
| [51b73452] | 29 |  | 
|---|
|  | 30 | namespace ResolvExpr { | 
|---|
| [a2a77af] | 31 | struct WidenMode { | 
|---|
|  | 32 | WidenMode( bool widenFirst, bool widenSecond ): widenFirst( widenFirst ), widenSecond( widenSecond ) {} | 
|---|
|  | 33 | WidenMode &operator|=( const WidenMode &other ) { widenFirst |= other.widenFirst; widenSecond |= other.widenSecond; return *this; } | 
|---|
|  | 34 | WidenMode &operator&=( const WidenMode &other ) { widenFirst &= other.widenFirst; widenSecond &= other.widenSecond; return *this; } | 
|---|
|  | 35 | WidenMode operator|( const WidenMode &other ) { WidenMode newWM( *this ); newWM |= other; return newWM; } | 
|---|
|  | 36 | WidenMode operator&( const WidenMode &other ) { WidenMode newWM( *this ); newWM &= other; return newWM; } | 
|---|
|  | 37 | operator bool() { return widenFirst && widenSecond; } | 
|---|
|  | 38 |  | 
|---|
|  | 39 | bool widenFirst : 1, widenSecond : 1; | 
|---|
|  | 40 | }; | 
|---|
| [66f8528] | 41 |  | 
|---|
|  | 42 | 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 ); | 
|---|
| [a32b204] | 43 | bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ); | 
|---|
|  | 44 | bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer, Type *&commonType ); | 
|---|
|  | 45 | bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ); | 
|---|
| [51b73452] | 46 |  | 
|---|
| [a32b204] | 47 | template< typename Iterator1, typename Iterator2 > | 
|---|
|  | 48 | 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 ) { | 
|---|
|  | 49 | for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) { | 
|---|
|  | 50 | Type *commonType = 0; | 
|---|
|  | 51 | if ( ! unify( *list1Begin, *list2Begin, env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) { | 
|---|
|  | 52 | return false; | 
|---|
|  | 53 | } // if | 
|---|
|  | 54 | commonTypes.push_back( commonType ); | 
|---|
|  | 55 | } // for | 
|---|
|  | 56 | if ( list1Begin != list1End || list2Begin != list2End ) { | 
|---|
|  | 57 | return false; | 
|---|
|  | 58 | } else { | 
|---|
|  | 59 | return true; | 
|---|
|  | 60 | } // if | 
|---|
|  | 61 | } | 
|---|
|  | 62 |  | 
|---|
|  | 63 | template< typename Iterator1, typename Iterator2 > | 
|---|
|  | 64 | bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ) { | 
|---|
|  | 65 | std::list< Type* > commonTypes; | 
|---|
|  | 66 | if ( unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes ) ) { | 
|---|
|  | 67 | deleteAll( commonTypes ); | 
|---|
|  | 68 | return true; | 
|---|
|  | 69 | } else { | 
|---|
|  | 70 | return false; | 
|---|
|  | 71 | } // if | 
|---|
|  | 72 | } | 
|---|
| [51b73452] | 73 |  | 
|---|
|  | 74 | } // namespace ResolvExpr | 
|---|
|  | 75 |  | 
|---|
| [a32b204] | 76 | // Local Variables: // | 
|---|
|  | 77 | // tab-width: 4 // | 
|---|
|  | 78 | // mode: c++ // | 
|---|
|  | 79 | // compile-command: "make install" // | 
|---|
|  | 80 | // End: // | 
|---|