| [51b73452] | 1 | /* | 
|---|
|  | 2 | * This file is part of the Cforall project | 
|---|
|  | 3 | * | 
|---|
|  | 4 | * $Id: Unify.h,v 1.4 2005/08/29 20:14:16 rcbilson Exp $ | 
|---|
|  | 5 | * | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef UNIFY_H | 
|---|
|  | 9 | #define UNIFY_H | 
|---|
|  | 10 |  | 
|---|
|  | 11 | #include <map> | 
|---|
|  | 12 | #include <list> | 
|---|
|  | 13 | #include "SynTree/SynTree.h" | 
|---|
|  | 14 | #include "SynTree/Type.h" | 
|---|
|  | 15 | #include "SynTree/Declaration.h" | 
|---|
|  | 16 | #include "SymTab/Indexer.h" | 
|---|
|  | 17 | #include "TypeEnvironment.h" | 
|---|
|  | 18 | #include "utility.h" | 
|---|
|  | 19 |  | 
|---|
|  | 20 | namespace ResolvExpr { | 
|---|
|  | 21 |  | 
|---|
|  | 22 | bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ); | 
|---|
|  | 23 | bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer, Type *&commonType ); | 
|---|
|  | 24 | bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ); | 
|---|
|  | 25 |  | 
|---|
|  | 26 | template< typename Iterator1, typename Iterator2 > | 
|---|
|  | 27 | bool | 
|---|
|  | 28 | 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 ) { | 
|---|
|  | 29 | for( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) { | 
|---|
|  | 30 | Type *commonType = 0; | 
|---|
|  | 31 | if( !unify( *list1Begin, *list2Begin, env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) { | 
|---|
|  | 32 | return false; | 
|---|
|  | 33 | } | 
|---|
|  | 34 | commonTypes.push_back( commonType ); | 
|---|
|  | 35 | } | 
|---|
|  | 36 | if( list1Begin != list1End || list2Begin != list2End ) { | 
|---|
|  | 37 | return false; | 
|---|
|  | 38 | } else { | 
|---|
|  | 39 | return true; | 
|---|
|  | 40 | } | 
|---|
|  | 41 | } | 
|---|
|  | 42 |  | 
|---|
|  | 43 | template< typename Iterator1, typename Iterator2 > | 
|---|
|  | 44 | bool | 
|---|
|  | 45 | unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ) { | 
|---|
|  | 46 | std::list< Type* > commonTypes; | 
|---|
|  | 47 | if( unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes ) ) { | 
|---|
|  | 48 | deleteAll( commonTypes ); | 
|---|
|  | 49 | return true; | 
|---|
|  | 50 | } else { | 
|---|
|  | 51 | return false; | 
|---|
|  | 52 | } | 
|---|
|  | 53 | } | 
|---|
|  | 54 |  | 
|---|
|  | 55 | } // namespace ResolvExpr | 
|---|
|  | 56 |  | 
|---|
|  | 57 | #endif /* #ifndef UNIFY_H */ | 
|---|