| [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 | 
|---|
| [d286cf68] | 11 | // Last Modified By : Aaron B. Moss | 
|---|
|  | 12 | // Last Modified On : Mon Jun 18 11:58:00 2018 | 
|---|
|  | 13 | // Update Count     : 4 | 
|---|
| [a32b204] | 14 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
| [6b0b624] | 16 | #pragma once | 
|---|
| [51b73452] | 17 |  | 
|---|
| [ea6332d] | 18 | #include <list>                   // for list | 
|---|
|  | 19 |  | 
|---|
| [f474e91] | 20 | #include "AST/Node.hpp"             // for ptr | 
|---|
| [d76c588] | 21 | #include "AST/TypeEnvironment.hpp"  // for TypeEnvironment, AssertionSet, OpenVarSet | 
|---|
| [ea6332d] | 22 | #include "Common/utility.h"       // for deleteAll | 
|---|
|  | 23 | #include "SynTree/Declaration.h"  // for TypeDecl, TypeDecl::Data | 
|---|
|  | 24 | #include "TypeEnvironment.h"      // for AssertionSet, OpenVarSet | 
|---|
| [d76c588] | 25 | #include "WidenMode.h"              // for WidenMode | 
|---|
| [ea6332d] | 26 |  | 
|---|
|  | 27 | class Type; | 
|---|
|  | 28 | class TypeInstType; | 
|---|
|  | 29 | namespace SymTab { | 
|---|
| [d76c588] | 30 | class Indexer; | 
|---|
|  | 31 | } | 
|---|
|  | 32 |  | 
|---|
|  | 33 | namespace ast { | 
|---|
|  | 34 | class SymbolTable; | 
|---|
|  | 35 | class Type; | 
|---|
|  | 36 | } | 
|---|
| [51b73452] | 37 |  | 
|---|
|  | 38 | namespace ResolvExpr { | 
|---|
| [a32b204] | 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 ); | 
|---|
| [f474e91] | 42 | bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widen, const SymTab::Indexer &indexer, Type *&common ); | 
|---|
| [51b73452] | 43 |  | 
|---|
| [a32b204] | 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 | } | 
|---|
|  | 59 |  | 
|---|
|  | 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 | } | 
|---|
| [51b73452] | 70 |  | 
|---|
| [2773ab8] | 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 ); | 
|---|
|  | 75 |  | 
|---|
| [ee574a2] | 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 ); | 
|---|
|  | 80 |  | 
|---|
| [f474e91] | 81 | bool unifyExact( | 
|---|
| [d76c588] | 82 | const ast::Type * type1, const ast::Type * type2, ast::TypeEnvironment & env, | 
|---|
| [ee574a2] | 83 | ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, | 
|---|
|  | 84 | WidenMode widen, const ast::SymbolTable & symtab ); | 
|---|
| [f474e91] | 85 |  | 
|---|
|  | 86 | bool unifyInexact( | 
|---|
| [ee574a2] | 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 ); | 
|---|
| [d76c588] | 91 |  | 
|---|
| [51b73452] | 92 | } // namespace ResolvExpr | 
|---|
|  | 93 |  | 
|---|
| [a32b204] | 94 | // Local Variables: // | 
|---|
|  | 95 | // tab-width: 4 // | 
|---|
|  | 96 | // mode: c++ // | 
|---|
|  | 97 | // compile-command: "make install" // | 
|---|
|  | 98 | // End: // | 
|---|