source: src/ResolvExpr/typeops.h@ f7cb0bc

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox 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 f7cb0bc was d7dc824, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Removed more warnings

  • Property mode set to 100644
File size: 5.5 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 /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function
57 void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
58
59 template< typename ForwardIterator >
60 void adjustExprTypeList( ForwardIterator begin, ForwardIterator end, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
61 while ( begin != end ) {
62 adjustExprType( *begin++, env, indexer );
63 } // while
64 }
65
66 // in CastCost.cc
67 Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
68
69 template< typename SrcIterator, typename DestIterator >
70 Cost castCostList( SrcIterator srcBegin, SrcIterator srcEnd, DestIterator destBegin, DestIterator destEnd, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
71 Cost ret;
72 if ( destBegin == destEnd ) {
73 if ( srcBegin == srcEnd ) {
74 return Cost::zero;
75 } else {
76 return Cost( 0, 0, 1 );
77 } // if
78 } // if
79 while ( srcBegin != srcEnd && destBegin != destEnd ) {
80 Cost thisCost = castCost( *srcBegin++, *destBegin++, indexer, env );
81 if ( thisCost == Cost::infinity ) {
82 return Cost::infinity;
83 } // if
84 ret += thisCost;
85 } // while
86 if ( srcBegin == srcEnd && destBegin == destEnd ) {
87 return ret;
88 } else {
89 return Cost::infinity;
90 } // if
91 }
92
93 // in ConversionCost.cc
94 Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
95
96 template< typename SrcIterator, typename DestIterator >
97 Cost conversionCostList( SrcIterator srcBegin, SrcIterator srcEnd, DestIterator destBegin, DestIterator destEnd, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
98 Cost ret;
99 while ( srcBegin != srcEnd && destBegin != destEnd ) {
100 Cost thisCost = conversionCost( *srcBegin++, *destBegin++, indexer, env );
101 if ( thisCost == Cost::infinity ) {
102 return Cost::infinity;
103 } // if
104 ret += thisCost;
105 } // while
106 if ( srcBegin == srcEnd && destBegin == destEnd ) {
107 return ret;
108 } else {
109 return Cost::infinity;
110 } // if
111 }
112
113 // in PtrsAssignable.cc
114 int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env );
115
116 // in PtrsCastable.cc
117 int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
118
119 // in Unify.cc
120 bool isFtype( Type *type );
121 bool typesCompatible( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
122 bool typesCompatibleIgnoreQualifiers( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
123
124 inline bool typesCompatible( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
125 TypeEnvironment env;
126 return typesCompatible( t1, t2, indexer, env );
127 }
128
129 inline bool typesCompatibleIgnoreQualifiers( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
130 TypeEnvironment env;
131 return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
132 }
133
134 /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
135 Type * extractResultType( FunctionType * functionType );
136
137 // in CommonType.cc
138 Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
139
140 // in PolyCost.cc
141 int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
142
143 // in Occurs.cc
144 bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
145
146 // flatten tuple type into list of types
147 template< typename OutputIterator >
148 void flatten( Type * type, OutputIterator out ) {
149 if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) {
150 for ( Type * t : tupleType->get_types() ) {
151 flatten( t, out );
152 }
153 } else {
154 *out++ = type->clone();
155 }
156 }
157} // namespace ResolvExpr
158
159#endif // TYPEOPS_H
160
161// Local Variables: //
162// tab-width: 4 //
163// mode: c++ //
164// compile-command: "make install" //
165// End: //
Note: See TracBrowser for help on using the repository browser.