[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 | // |
---|
| 7 | // typeops.h -- |
---|
| 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 07:28:22 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Sun May 17 07:33:11 2015 |
---|
| 13 | // Update Count : 2 |
---|
| 14 | // |
---|
[51b7345] | 15 | |
---|
| 16 | #ifndef TYPEOPS_H |
---|
| 17 | #define TYPEOPS_H |
---|
| 18 | |
---|
| 19 | #include "SynTree/SynTree.h" |
---|
| 20 | #include "SynTree/Type.h" |
---|
| 21 | #include "SymTab/Indexer.h" |
---|
| 22 | #include "Cost.h" |
---|
| 23 | #include "TypeEnvironment.h" |
---|
| 24 | |
---|
| 25 | namespace ResolvExpr { |
---|
[a32b204] | 26 | // combos: takes a list of sets and returns a set of lists representing every possible way of forming a list by |
---|
| 27 | // picking one element out of each set |
---|
| 28 | template< typename InputIterator, typename OutputIterator > |
---|
| 29 | void combos( InputIterator begin, InputIterator end, OutputIterator out ) { |
---|
| 30 | typedef typename InputIterator::value_type SetType; |
---|
| 31 | typedef typename std::list< typename SetType::value_type > ListType; |
---|
[51b7345] | 32 | |
---|
[a32b204] | 33 | if ( begin == end ) { |
---|
| 34 | *out++ = ListType(); |
---|
| 35 | return; |
---|
| 36 | } // if |
---|
[51b7345] | 37 | |
---|
[a32b204] | 38 | InputIterator current = begin; |
---|
| 39 | begin++; |
---|
[51b7345] | 40 | |
---|
[a32b204] | 41 | std::list< ListType > recursiveResult; |
---|
| 42 | combos( begin, end, back_inserter( recursiveResult ) ); |
---|
[51b7345] | 43 | |
---|
[a32b204] | 44 | for ( typename std::list< ListType >::const_iterator i = recursiveResult.begin(); i != recursiveResult.end(); ++i ) { |
---|
| 45 | for ( typename ListType::const_iterator j = current->begin(); j != current->end(); ++j ) { |
---|
| 46 | ListType result; |
---|
| 47 | std::back_insert_iterator< ListType > inserter = back_inserter( result ); |
---|
| 48 | *inserter++ = *j; |
---|
| 49 | std::copy( i->begin(), i->end(), inserter ); |
---|
| 50 | *out++ = result; |
---|
| 51 | } // for |
---|
| 52 | } // for |
---|
| 53 | } |
---|
[51b7345] | 54 | |
---|
[a32b204] | 55 | // in AdjustExprType.cc |
---|
| 56 | void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ); |
---|
| 57 | |
---|
| 58 | template< typename ForwardIterator > |
---|
| 59 | void adjustExprTypeList( ForwardIterator begin, ForwardIterator end, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { |
---|
| 60 | while ( begin != end ) { |
---|
| 61 | adjustExprType( *begin++, env, indexer ); |
---|
| 62 | } // while |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | // in CastCost.cc |
---|
| 66 | Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ); |
---|
| 67 | |
---|
| 68 | template< typename SrcIterator, typename DestIterator > |
---|
| 69 | Cost castCostList( SrcIterator srcBegin, SrcIterator srcEnd, DestIterator destBegin, DestIterator destEnd, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { |
---|
| 70 | Cost ret; |
---|
| 71 | if ( destBegin == destEnd ) { |
---|
| 72 | if ( srcBegin == srcEnd ) { |
---|
| 73 | return Cost::zero; |
---|
| 74 | } else { |
---|
| 75 | return Cost( 0, 0, 1 ); |
---|
| 76 | } // if |
---|
| 77 | } // if |
---|
| 78 | while ( srcBegin != srcEnd && destBegin != destEnd ) { |
---|
| 79 | Cost thisCost = castCost( *srcBegin++, *destBegin++, indexer, env ); |
---|
| 80 | if ( thisCost == Cost::infinity ) { |
---|
| 81 | return Cost::infinity; |
---|
| 82 | } // if |
---|
| 83 | ret += thisCost; |
---|
| 84 | } // while |
---|
| 85 | if ( srcBegin == srcEnd && destBegin == destEnd ) { |
---|
| 86 | return ret; |
---|
| 87 | } else { |
---|
| 88 | return Cost::infinity; |
---|
| 89 | } // if |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | // in ConversionCost.cc |
---|
| 93 | Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ); |
---|
| 94 | |
---|
| 95 | template< typename SrcIterator, typename DestIterator > |
---|
| 96 | Cost conversionCostList( SrcIterator srcBegin, SrcIterator srcEnd, DestIterator destBegin, DestIterator destEnd, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { |
---|
| 97 | Cost ret; |
---|
| 98 | while ( srcBegin != srcEnd && destBegin != destEnd ) { |
---|
| 99 | Cost thisCost = conversionCost( *srcBegin++, *destBegin++, indexer, env ); |
---|
| 100 | if ( thisCost == Cost::infinity ) { |
---|
| 101 | return Cost::infinity; |
---|
| 102 | } // if |
---|
| 103 | ret += thisCost; |
---|
| 104 | } // while |
---|
| 105 | if ( srcBegin == srcEnd && destBegin == destEnd ) { |
---|
| 106 | return ret; |
---|
| 107 | } else { |
---|
| 108 | return Cost::infinity; |
---|
| 109 | } // if |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | // in PtrsAssignable.cc |
---|
| 113 | int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env ); |
---|
| 114 | |
---|
| 115 | // in PtrsCastable.cc |
---|
| 116 | int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ); |
---|
| 117 | |
---|
| 118 | // in Unify.cc |
---|
| 119 | bool typesCompatible( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env ); |
---|
| 120 | bool typesCompatibleIgnoreQualifiers( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env ); |
---|
| 121 | |
---|
| 122 | inline bool typesCompatible( Type *t1, Type *t2, const SymTab::Indexer &indexer ) { |
---|
| 123 | TypeEnvironment env; |
---|
| 124 | return typesCompatible( t1, t2, indexer, env ); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | inline bool typesCompatibleIgnoreQualifiers( Type *t1, Type *t2, const SymTab::Indexer &indexer ) { |
---|
| 128 | TypeEnvironment env; |
---|
| 129 | return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env ); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | template< typename Container1, typename Container2 > |
---|
| 133 | bool typesCompatibleList( Container1 &c1, Container2 &c2, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { |
---|
| 134 | typename Container1::iterator i1 = c1.begin(); |
---|
| 135 | typename Container2::iterator i2 = c2.begin(); |
---|
| 136 | for ( ; i1 != c1.end() && i2 != c2.end(); ++i1, ++i2 ) { |
---|
| 137 | if ( ! typesCompatible( *i1, *i2, indexer ) ) { |
---|
| 138 | return false; |
---|
| 139 | } // if |
---|
| 140 | } |
---|
| 141 | return ( i1 == c1.end() ) && ( i2 == c2.end() ); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | // in CommonType.cc |
---|
| 145 | Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ); |
---|
| 146 | |
---|
| 147 | // in PolyCost.cc |
---|
| 148 | int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer ); |
---|
| 149 | |
---|
| 150 | // in Occurs.cc |
---|
| 151 | bool occurs( Type *type, std::string varName, const TypeEnvironment &env ); |
---|
[51b7345] | 152 | } // namespace ResolvExpr |
---|
| 153 | |
---|
[a32b204] | 154 | #endif // TYPEOPS_H |
---|
| 155 | |
---|
| 156 | // Local Variables: // |
---|
| 157 | // tab-width: 4 // |
---|
| 158 | // mode: c++ // |
---|
| 159 | // compile-command: "make install" // |
---|
| 160 | // End: // |
---|