source: src/ResolvExpr/typeops.h@ c8c03683

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since c8c03683 was db4977a, checked in by Aaron Moss <a3moss@…>, 10 years ago

Fix so void* does not have common type with function pointer

  • Property mode set to 100644
File size: 5.4 KB
Line 
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//
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
25namespace ResolvExpr {
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;
32
33 if ( begin == end ) {
34 *out++ = ListType();
35 return;
36 } // if
37
38 InputIterator current = begin;
39 begin++;
40
41 std::list< ListType > recursiveResult;
42 combos( begin, end, back_inserter( recursiveResult ) );
43
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 }
54
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 isFtype( Type *type, const SymTab::Indexer &indexer );
120 bool typesCompatible( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
121 bool typesCompatibleIgnoreQualifiers( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
122
123 inline bool typesCompatible( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
124 TypeEnvironment env;
125 return typesCompatible( t1, t2, indexer, env );
126 }
127
128 inline bool typesCompatibleIgnoreQualifiers( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
129 TypeEnvironment env;
130 return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
131 }
132
133 template< typename Container1, typename Container2 >
134 bool typesCompatibleList( Container1 &c1, Container2 &c2, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
135 typename Container1::iterator i1 = c1.begin();
136 typename Container2::iterator i2 = c2.begin();
137 for ( ; i1 != c1.end() && i2 != c2.end(); ++i1, ++i2 ) {
138 if ( ! typesCompatible( *i1, *i2, indexer ) ) {
139 return false;
140 } // if
141 }
142 return ( i1 == c1.end() ) && ( i2 == c2.end() );
143 }
144
145 // in CommonType.cc
146 Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
147
148 // in PolyCost.cc
149 int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
150
151 // in Occurs.cc
152 bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
153} // namespace ResolvExpr
154
155#endif // TYPEOPS_H
156
157// Local Variables: //
158// tab-width: 4 //
159// mode: c++ //
160// compile-command: "make install" //
161// End: //
Note: See TracBrowser for help on using the repository browser.