source: src/ResolvExpr/typeops.h @ ff2a33e

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since ff2a33e was 7870799, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Cast cost and conversion cost now take constant parameters.
This required supporting visiting const node.
The PassVisitor? can now visit const nodes but not when using the Indexer

  • Property mode set to 100644
File size: 7.4 KB
RevLine 
[a32b204]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//
[906e24d]7// typeops.h --
[a32b204]8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 07:28:22 2015
11// Last Modified By : Peter A. Buhr
[0e66857]12// Last Modified On : Fri Feb  8 09:30:34 2019
13// Update Count     : 4
[a32b204]14//
[51b7345]15
[6b0b624]16#pragma once
[51b7345]17
[bd4f2e9]18#include <vector>
19
[f474e91]20#include "Cost.h"
21#include "TypeEnvironment.h"
22#include "WidenMode.h"
[d76c588]23#include "AST/Fwd.hpp"
[54e41b3]24#include "AST/Node.hpp"
[d76c588]25#include "AST/SymbolTable.hpp"
[54e41b3]26#include "AST/Type.hpp"
[d76c588]27#include "AST/TypeEnvironment.hpp"
[51b7345]28#include "SynTree/SynTree.h"
29#include "SynTree/Type.h"
30#include "SymTab/Indexer.h"
31
32namespace ResolvExpr {
[a32b204]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;
[bd4f2e9]38                typedef typename std::vector< typename SetType::value_type > ListType;
[906e24d]39
[a32b204]40                if ( begin == end )     {
41                        *out++ = ListType();
42                        return;
43                } // if
[906e24d]44
[a32b204]45                InputIterator current = begin;
46                begin++;
[51b7345]47
[bd4f2e9]48                std::vector< ListType > recursiveResult;
[a32b204]49                combos( begin, end, back_inserter( recursiveResult ) );
[906e24d]50
[bd4f2e9]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                }
[a32b204]58        }
[906e24d]59
[a32b204]60        // in AdjustExprType.cc
[2de162da]61        /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function
[a32b204]62        void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
63
[c20b0fea]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
[a32b204]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
[d57e349]74        /// Replaces array types with equivalent pointer, and function types with a pointer-to-function
[7870799]75        const ast::Type * adjustExprType(
[d57e349]76                const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab );
77
[a32b204]78        // in CastCost.cc
[7870799]79        Cost castCost( const Type * src, const Type * dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
80        Cost castCost(
81                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
[c8e4d2f8]82                const ast::TypeEnvironment & env );
[a32b204]83
84        // in ConversionCost.cc
[7870799]85        Cost conversionCost( const Type *src, const Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
86        Cost conversionCost(
87                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
[9d5089e]88                const ast::TypeEnvironment & env );
[a32b204]89
[fbecee5]90        // in AlternativeFinder.cc
[7870799]91        Cost computeConversionCost( Type *actualType, Type *formalType,
[fbecee5]92                const SymTab::Indexer &indexer, const TypeEnvironment &env );
93
[a32b204]94        // in PtrsAssignable.cc
[7870799]95        int ptrsAssignable( const Type * src, const Type * dest, const TypeEnvironment &env );
[fb2bde4]96        int ptrsAssignable( const ast::Type * src, const ast::Type * dst,
97                const ast::TypeEnvironment & env );
[a32b204]98
99        // in PtrsCastable.cc
[7870799]100        int ptrsCastable( const Type * src, const Type * dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
101        int ptrsCastable(
102                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
[3c89751]103                const ast::TypeEnvironment & env );
[a32b204]104
105        // in Unify.cc
106        bool typesCompatible( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
[7870799]107        bool typesCompatibleIgnoreQualifiers( const Type *, const Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
[a32b204]108
109        inline bool typesCompatible( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
110                TypeEnvironment env;
111                return typesCompatible( t1, t2, indexer, env );
112        }
113
[7870799]114        inline bool typesCompatibleIgnoreQualifiers( const Type * t1, const Type * t2, const SymTab::Indexer &indexer ) {
[a32b204]115                TypeEnvironment env;
116                return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
117        }
118
[7870799]119        bool typesCompatible(
120                const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},
[d76c588]121                const ast::TypeEnvironment & env = {} );
[7870799]122
[d76c588]123        bool typesCompatibleIgnoreQualifiers(
[7870799]124                const ast::Type *, const ast::Type *, const ast::SymbolTable &,
[d76c588]125                const ast::TypeEnvironment & env = {} );
126
[906e24d]127        /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
128        Type * extractResultType( FunctionType * functionType );
[54e41b3]129        /// Creates or extracts the type represented by the list of returns in a `FunctionType`.
130        ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func );
[906e24d]131
[a32b204]132        // in CommonType.cc
[0e66857]133        Type * commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
[ee574a2]134        ast::ptr< ast::Type > commonType(
[7870799]135                const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, WidenMode widen,
[f474e91]136                const ast::SymbolTable & symtab, ast::TypeEnvironment & env, const ast::OpenVarSet & open );
[a32b204]137
138        // in PolyCost.cc
139        int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
[7870799]140        int polyCost(
[9d5089e]141                const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
[a32b204]142
[1dd1bd2]143        // in SpecCost.cc
144        int specCost( Type *type );
[9d5089e]145        int specCost( const ast::Type * type );
[1dd1bd2]146
[a32b204]147        // in Occurs.cc
148        bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
[d76c588]149        // new AST version in TypeEnvironment.cpp (only place it was used in old AST)
[906e24d]150
[7870799]151        template<typename Iter>
[9ad2f9f]152        bool occursIn( Type* ty, Iter begin, Iter end, const TypeEnvironment &env ) {
153                while ( begin != end ) {
154                        if ( occurs( ty, *begin, env ) ) return true;
155                        ++begin;
156                }
157                return false;
158        }
159
[6d2f993]160        // in AlternativeFinder.cc
[a181494]161        void referenceToRvalueConversion( Expression *& expr, Cost & cost );
[9d5089e]162        // in CandidateFinder.cpp
[d76c588]163        const ast::Expr * referenceToRvalueConversion( const ast::Expr * expr, Cost & cost );
[6d2f993]164
[f474e91]165        /// flatten tuple type into list of types
[906e24d]166        template< typename OutputIterator >
167        void flatten( Type * type, OutputIterator out ) {
168                if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) {
169                        for ( Type * t : tupleType->get_types() ) {
170                                flatten( t, out );
171                        }
172                } else {
[6c3a988f]173                        *out++ = type->clone();
[906e24d]174                }
175        }
[f474e91]176
177        /// flatten tuple type into existing list of types
[7870799]178        static inline void flatten(
179                const ast::Type * type, std::vector< ast::ptr< ast::Type > > & out
[f474e91]180        ) {
[7870799]181                if ( auto tupleType = dynamic_cast< const ast::TupleType * >( type ) ) {
[f474e91]182                        for ( const ast::Type * t : tupleType->types ) {
183                                flatten( t, out );
184                        }
185                } else {
186                        out.emplace_back( type );
187                }
188        }
189
190        /// flatten tuple type into list of types
191        static inline std::vector< ast::ptr< ast::Type > > flatten( const ast::Type * type ) {
192                std::vector< ast::ptr< ast::Type > > out;
193                out.reserve( type->size() );
194                flatten( type, out );
195                return out;
196        }
[ee574a2]197
198        // in TypeEnvironment.cc
199        bool isFtype( Type *type );
[51b7345]200} // namespace ResolvExpr
201
[ee574a2]202namespace ast {
203        // in TypeEnvironment.cpp
204        bool isFtype( const ast::Type * type );
205} // namespace ast
206
[a32b204]207// Local Variables: //
208// tab-width: 4 //
209// mode: c++ //
210// compile-command: "make install" //
211// End: //
Note: See TracBrowser for help on using the repository browser.