[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 | // |
---|
[906e24d] | 7 | // typeops.h -- |
---|
[a32b204] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 07:28:22 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[0e66857] | 12 | // Last Modified On : Fri Feb 8 09:30:34 2019 |
---|
| 13 | // Update Count : 4 |
---|
[a32b204] | 14 | // |
---|
[51b7345] | 15 | |
---|
[6b0b624] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[bd4f2e9] | 18 | #include <vector> |
---|
| 19 | |
---|
[51b7345] | 20 | #include "SynTree/SynTree.h" |
---|
| 21 | #include "SynTree/Type.h" |
---|
| 22 | #include "SymTab/Indexer.h" |
---|
| 23 | #include "Cost.h" |
---|
| 24 | #include "TypeEnvironment.h" |
---|
| 25 | |
---|
| 26 | namespace ResolvExpr { |
---|
[a32b204] | 27 | // combos: takes a list of sets and returns a set of lists representing every possible way of forming a list by |
---|
| 28 | // picking one element out of each set |
---|
| 29 | template< typename InputIterator, typename OutputIterator > |
---|
| 30 | void combos( InputIterator begin, InputIterator end, OutputIterator out ) { |
---|
| 31 | typedef typename InputIterator::value_type SetType; |
---|
[bd4f2e9] | 32 | typedef typename std::vector< typename SetType::value_type > ListType; |
---|
[906e24d] | 33 | |
---|
[a32b204] | 34 | if ( begin == end ) { |
---|
| 35 | *out++ = ListType(); |
---|
| 36 | return; |
---|
| 37 | } // if |
---|
[906e24d] | 38 | |
---|
[a32b204] | 39 | InputIterator current = begin; |
---|
| 40 | begin++; |
---|
[51b7345] | 41 | |
---|
[bd4f2e9] | 42 | std::vector< ListType > recursiveResult; |
---|
[a32b204] | 43 | combos( begin, end, back_inserter( recursiveResult ) ); |
---|
[906e24d] | 44 | |
---|
[bd4f2e9] | 45 | for ( const auto& i : recursiveResult ) for ( const auto& j : *current ) { |
---|
| 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 | } |
---|
[a32b204] | 52 | } |
---|
[906e24d] | 53 | |
---|
[a32b204] | 54 | // in AdjustExprType.cc |
---|
[2de162da] | 55 | /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function |
---|
[a32b204] | 56 | void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ); |
---|
| 57 | |
---|
[c20b0fea] | 58 | /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function using empty TypeEnvironment and Indexer |
---|
| 59 | void adjustExprType( Type *& type ); |
---|
| 60 | |
---|
[a32b204] | 61 | template< typename ForwardIterator > |
---|
| 62 | void adjustExprTypeList( ForwardIterator begin, ForwardIterator end, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { |
---|
| 63 | while ( begin != end ) { |
---|
| 64 | adjustExprType( *begin++, env, indexer ); |
---|
| 65 | } // while |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | // in CastCost.cc |
---|
| 69 | Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ); |
---|
| 70 | |
---|
| 71 | // in ConversionCost.cc |
---|
| 72 | Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ); |
---|
| 73 | |
---|
[fbecee5] | 74 | // in AlternativeFinder.cc |
---|
| 75 | Cost computeConversionCost( Type *actualType, Type *formalType, |
---|
| 76 | const SymTab::Indexer &indexer, const TypeEnvironment &env ); |
---|
| 77 | |
---|
[a32b204] | 78 | // in PtrsAssignable.cc |
---|
| 79 | int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env ); |
---|
| 80 | |
---|
| 81 | // in PtrsCastable.cc |
---|
| 82 | int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ); |
---|
| 83 | |
---|
| 84 | // in Unify.cc |
---|
[d7dc824] | 85 | bool isFtype( Type *type ); |
---|
[a32b204] | 86 | bool typesCompatible( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env ); |
---|
| 87 | bool typesCompatibleIgnoreQualifiers( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env ); |
---|
| 88 | |
---|
| 89 | inline bool typesCompatible( Type *t1, Type *t2, const SymTab::Indexer &indexer ) { |
---|
| 90 | TypeEnvironment env; |
---|
| 91 | return typesCompatible( t1, t2, indexer, env ); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | inline bool typesCompatibleIgnoreQualifiers( Type *t1, Type *t2, const SymTab::Indexer &indexer ) { |
---|
| 95 | TypeEnvironment env; |
---|
| 96 | return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env ); |
---|
| 97 | } |
---|
| 98 | |
---|
[906e24d] | 99 | /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value. |
---|
| 100 | Type * extractResultType( FunctionType * functionType ); |
---|
| 101 | |
---|
[a32b204] | 102 | // in CommonType.cc |
---|
[0e66857] | 103 | Type * commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ); |
---|
[a32b204] | 104 | |
---|
| 105 | // in PolyCost.cc |
---|
| 106 | int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer ); |
---|
| 107 | |
---|
[1dd1bd2] | 108 | // in SpecCost.cc |
---|
| 109 | int specCost( Type *type ); |
---|
| 110 | |
---|
[a32b204] | 111 | // in Occurs.cc |
---|
| 112 | bool occurs( Type *type, std::string varName, const TypeEnvironment &env ); |
---|
[906e24d] | 113 | |
---|
[9ad2f9f] | 114 | template<typename Iter> |
---|
| 115 | bool occursIn( Type* ty, Iter begin, Iter end, const TypeEnvironment &env ) { |
---|
| 116 | while ( begin != end ) { |
---|
| 117 | if ( occurs( ty, *begin, env ) ) return true; |
---|
| 118 | ++begin; |
---|
| 119 | } |
---|
| 120 | return false; |
---|
| 121 | } |
---|
| 122 | |
---|
[6d2f993] | 123 | // in AlternativeFinder.cc |
---|
[a181494] | 124 | void referenceToRvalueConversion( Expression *& expr, Cost & cost ); |
---|
[6d2f993] | 125 | |
---|
[906e24d] | 126 | // flatten tuple type into list of types |
---|
| 127 | template< typename OutputIterator > |
---|
| 128 | void flatten( Type * type, OutputIterator out ) { |
---|
| 129 | if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) { |
---|
| 130 | for ( Type * t : tupleType->get_types() ) { |
---|
| 131 | flatten( t, out ); |
---|
| 132 | } |
---|
| 133 | } else { |
---|
[6c3a988f] | 134 | *out++ = type->clone(); |
---|
[906e24d] | 135 | } |
---|
| 136 | } |
---|
[51b7345] | 137 | } // namespace ResolvExpr |
---|
| 138 | |
---|
[a32b204] | 139 | // Local Variables: // |
---|
| 140 | // tab-width: 4 // |
---|
| 141 | // mode: c++ // |
---|
| 142 | // compile-command: "make install" // |
---|
| 143 | // End: // |
---|