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 | // |
---|
7 | // Unify.h -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Sun May 17 13:09:04 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Fri Jul 21 23:09:34 2017 |
---|
13 | // Update Count : 3 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
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 |
---|
29 | |
---|
30 | namespace ResolvExpr { |
---|
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 | }; |
---|
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 ); |
---|
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 ); |
---|
46 | |
---|
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 | return unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes ); |
---|
67 | } |
---|
68 | |
---|
69 | } // namespace ResolvExpr |
---|
70 | |
---|
71 | // Local Variables: // |
---|
72 | // tab-width: 4 // |
---|
73 | // mode: c++ // |
---|
74 | // compile-command: "make install" // |
---|
75 | // End: // |
---|