source: translator/ResolvExpr/typeops.h @ 02e9ae2

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 02e9ae2 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

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