source: src/ResolvExpr/typeops.h@ c9c9fd7e

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 c9c9fd7e was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

change #ifndef to #pragma once

  • 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 : Sat Jul 22 09:36:18 2017
13// Update Count : 3
14//
15
16#pragma once
17
18#include "SynTree/SynTree.h"
19#include "SynTree/Type.h"
20#include "SymTab/Indexer.h"
21#include "Cost.h"
22#include "TypeEnvironment.h"
23
24namespace ResolvExpr {
25 // combos: takes a list of sets and returns a set of lists representing every possible way of forming a list by
26 // picking one element out of each set
27 template< typename InputIterator, typename OutputIterator >
28 void combos( InputIterator begin, InputIterator end, OutputIterator out ) {
29 typedef typename InputIterator::value_type SetType;
30 typedef typename std::list< typename SetType::value_type > ListType;
31
32 if ( begin == end ) {
33 *out++ = ListType();
34 return;
35 } // if
36
37 InputIterator current = begin;
38 begin++;
39
40 std::list< ListType > recursiveResult;
41 combos( begin, end, back_inserter( recursiveResult ) );
42
43 for ( typename std::list< ListType >::const_iterator i = recursiveResult.begin(); i != recursiveResult.end(); ++i ) {
44 for ( typename ListType::const_iterator j = current->begin(); j != current->end(); ++j ) {
45 ListType result;
46 std::back_insert_iterator< ListType > inserter = back_inserter( result );
47 *inserter++ = *j;
48 std::copy( i->begin(), i->end(), inserter );
49 *out++ = result;
50 } // for
51 } // for
52 }
53
54 // in AdjustExprType.cc
55 /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function
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 );
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 /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
134 Type * extractResultType( FunctionType * functionType );
135
136 // in CommonType.cc
137 Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
138
139 // in PolyCost.cc
140 int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
141
142 // in Occurs.cc
143 bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
144
145 // flatten tuple type into list of types
146 template< typename OutputIterator >
147 void flatten( Type * type, OutputIterator out ) {
148 if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) {
149 for ( Type * t : tupleType->get_types() ) {
150 flatten( t, out );
151 }
152 } else {
153 *out++ = type->clone();
154 }
155 }
156} // namespace ResolvExpr
157
158// Local Variables: //
159// tab-width: 4 //
160// mode: c++ //
161// compile-command: "make install" //
162// End: //
Note: See TracBrowser for help on using the repository browser.