source: src/ResolvExpr/typeops.h@ 4e13e2a

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 4e13e2a was 85dac33, checked in by Andrew Beach <ajbeach@…>, 6 years ago

Added 'const' in some leaf positions where it doesn't seem to effect much.

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