source: src/ResolvExpr/typeops.h@ 9d5089e

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum stuck-waitfor-destruct
Last change on this file since 9d5089e was 9d5089e, checked in by Aaron Moss <a3moss@…>, 7 years ago

Port CandidateFinder::makeFunctionCandidates() and deps

  • Property mode set to 100644
File size: 6.9 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 : Fri Feb 8 09:30:34 2019
13// Update Count : 4
14//
15
16#pragma once
17
18#include <vector>
19
20#include "Cost.h"
21#include "TypeEnvironment.h"
22#include "WidenMode.h"
23#include "AST/Fwd.hpp"
24#include "AST/Node.hpp"
25#include "AST/SymbolTable.hpp"
26#include "AST/Type.hpp"
27#include "AST/TypeEnvironment.hpp"
28#include "SynTree/SynTree.h"
29#include "SynTree/Type.h"
30#include "SymTab/Indexer.h"
31
32namespace ResolvExpr {
33 // combos: takes a list of sets and returns a set of lists representing every possible way of forming a list by
34 // picking one element out of each set
35 template< typename InputIterator, typename OutputIterator >
36 void combos( InputIterator begin, InputIterator end, OutputIterator out ) {
37 typedef typename InputIterator::value_type SetType;
38 typedef typename std::vector< typename SetType::value_type > ListType;
39
40 if ( begin == end ) {
41 *out++ = ListType();
42 return;
43 } // if
44
45 InputIterator current = begin;
46 begin++;
47
48 std::vector< ListType > recursiveResult;
49 combos( begin, end, back_inserter( recursiveResult ) );
50
51 for ( const auto& i : recursiveResult ) for ( const auto& j : *current ) {
52 ListType result;
53 std::back_insert_iterator< ListType > inserter = back_inserter( result );
54 *inserter++ = j;
55 std::copy( i.begin(), i.end(), inserter );
56 *out++ = result;
57 }
58 }
59
60 // in AdjustExprType.cc
61 /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function
62 void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
63
64 /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function using empty TypeEnvironment and Indexer
65 void adjustExprType( Type *& type );
66
67 template< typename ForwardIterator >
68 void adjustExprTypeList( ForwardIterator begin, ForwardIterator end, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
69 while ( begin != end ) {
70 adjustExprType( *begin++, env, indexer );
71 } // while
72 }
73
74 /// Replaces array types with equivalent pointer, and function types with a pointer-to-function
75 const ast::Type * adjustExprType(
76 const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab );
77
78 // in CastCost.cc
79 Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
80
81 // in ConversionCost.cc
82 Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
83 Cost conversionCost(
84 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
85 const ast::TypeEnvironment & env );
86
87 // in AlternativeFinder.cc
88 Cost computeConversionCost( Type *actualType, Type *formalType,
89 const SymTab::Indexer &indexer, const TypeEnvironment &env );
90
91 // in PtrsAssignable.cc
92 int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env );
93
94 // in PtrsCastable.cc
95 int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
96
97 // in Unify.cc
98 bool typesCompatible( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
99 bool typesCompatibleIgnoreQualifiers( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
100
101 inline bool typesCompatible( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
102 TypeEnvironment env;
103 return typesCompatible( t1, t2, indexer, env );
104 }
105
106 inline bool typesCompatibleIgnoreQualifiers( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
107 TypeEnvironment env;
108 return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
109 }
110
111 bool typesCompatible(
112 const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},
113 const ast::TypeEnvironment & env = {} );
114
115 bool typesCompatibleIgnoreQualifiers(
116 const ast::Type *, const ast::Type *, const ast::SymbolTable &,
117 const ast::TypeEnvironment & env = {} );
118
119 /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
120 Type * extractResultType( FunctionType * functionType );
121 /// Creates or extracts the type represented by the list of returns in a `FunctionType`.
122 ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func );
123
124 // in CommonType.cc
125 Type * commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
126 ast::ptr< ast::Type > commonType(
127 const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, WidenMode widen,
128 const ast::SymbolTable & symtab, ast::TypeEnvironment & env, const ast::OpenVarSet & open );
129
130 // in PolyCost.cc
131 int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
132 int polyCost(
133 const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
134
135 // in SpecCost.cc
136 int specCost( Type *type );
137 int specCost( const ast::Type * type );
138
139 // in Occurs.cc
140 bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
141 // new AST version in TypeEnvironment.cpp (only place it was used in old AST)
142
143 template<typename Iter>
144 bool occursIn( Type* ty, Iter begin, Iter end, const TypeEnvironment &env ) {
145 while ( begin != end ) {
146 if ( occurs( ty, *begin, env ) ) return true;
147 ++begin;
148 }
149 return false;
150 }
151
152 // in AlternativeFinder.cc
153 void referenceToRvalueConversion( Expression *& expr, Cost & cost );
154 // in CandidateFinder.cpp
155 const ast::Expr * referenceToRvalueConversion( const ast::Expr * expr, Cost & cost );
156
157 /// flatten tuple type into list of types
158 template< typename OutputIterator >
159 void flatten( Type * type, OutputIterator out ) {
160 if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) {
161 for ( Type * t : tupleType->get_types() ) {
162 flatten( t, out );
163 }
164 } else {
165 *out++ = type->clone();
166 }
167 }
168
169 /// flatten tuple type into existing list of types
170 static inline void flatten(
171 const ast::Type * type, std::vector< ast::ptr< ast::Type > > & out
172 ) {
173 if ( auto tupleType = dynamic_cast< const ast::TupleType * >( type ) ) {
174 for ( const ast::Type * t : tupleType->types ) {
175 flatten( t, out );
176 }
177 } else {
178 out.emplace_back( type );
179 }
180 }
181
182 /// flatten tuple type into list of types
183 static inline std::vector< ast::ptr< ast::Type > > flatten( const ast::Type * type ) {
184 std::vector< ast::ptr< ast::Type > > out;
185 out.reserve( type->size() );
186 flatten( type, out );
187 return out;
188 }
189
190 // in TypeEnvironment.cc
191 bool isFtype( Type *type );
192} // namespace ResolvExpr
193
194namespace ast {
195 // in TypeEnvironment.cpp
196 bool isFtype( const ast::Type * type );
197} // namespace ast
198
199// Local Variables: //
200// tab-width: 4 //
201// mode: c++ //
202// compile-command: "make install" //
203// End: //
Note: See TracBrowser for help on using the repository browser.