source: src/ResolvExpr/typeops.h @ 558d13b

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 558d13b was 99d4584, checked in by Aaron Moss <a3moss@…>, 5 years ago

Further stubs for resolver port

  • also switched order of constructor params on Indenter
  • Property mode set to 100644
File size: 6.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
74        // in CastCost.cc
75        Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
76
77        // in ConversionCost.cc
78        Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
79
[fbecee5]80        // in AlternativeFinder.cc
81        Cost computeConversionCost( Type *actualType, Type *formalType, 
82                const SymTab::Indexer &indexer, const TypeEnvironment &env );
83
[a32b204]84        // in PtrsAssignable.cc
85        int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env );
86
87        // in PtrsCastable.cc
88        int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
89
90        // in Unify.cc
91        bool typesCompatible( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
92        bool typesCompatibleIgnoreQualifiers( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
93
94        inline bool typesCompatible( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
95                TypeEnvironment env;
96                return typesCompatible( t1, t2, indexer, env );
97        }
98
99        inline bool typesCompatibleIgnoreQualifiers( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
100                TypeEnvironment env;
101                return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
102        }
103
[d76c588]104        bool typesCompatible( 
[99d4584]105                const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {}, 
[d76c588]106                const ast::TypeEnvironment & env = {} );
107       
108        bool typesCompatibleIgnoreQualifiers(
109                const ast::Type *, const ast::Type *, const ast::SymbolTable &, 
110                const ast::TypeEnvironment & env = {} );
111
[906e24d]112        /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
113        Type * extractResultType( FunctionType * functionType );
[54e41b3]114        /// Creates or extracts the type represented by the list of returns in a `FunctionType`.
115        ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func );
[906e24d]116
[a32b204]117        // in CommonType.cc
[0e66857]118        Type * commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
[ee574a2]119        ast::ptr< ast::Type > commonType(
120                const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, WidenMode widen, 
[f474e91]121                const ast::SymbolTable & symtab, ast::TypeEnvironment & env, const ast::OpenVarSet & open );
[a32b204]122
123        // in PolyCost.cc
124        int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
125
[1dd1bd2]126        // in SpecCost.cc
127        int specCost( Type *type );
128
[a32b204]129        // in Occurs.cc
130        bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
[d76c588]131        // new AST version in TypeEnvironment.cpp (only place it was used in old AST)
[906e24d]132
[9ad2f9f]133        template<typename Iter> 
134        bool occursIn( Type* ty, Iter begin, Iter end, const TypeEnvironment &env ) {
135                while ( begin != end ) {
136                        if ( occurs( ty, *begin, env ) ) return true;
137                        ++begin;
138                }
139                return false;
140        }
141
[6d2f993]142        // in AlternativeFinder.cc
[a181494]143        void referenceToRvalueConversion( Expression *& expr, Cost & cost );
[d76c588]144        const ast::Expr * referenceToRvalueConversion( const ast::Expr * expr, Cost & cost );
[6d2f993]145
[f474e91]146        /// flatten tuple type into list of types
[906e24d]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 {
[6c3a988f]154                        *out++ = type->clone();
[906e24d]155                }
156        }
[f474e91]157
158        /// flatten tuple type into existing list of types
159        static inline void flatten( 
160                const ast::Type * type, std::vector< ast::ptr< ast::Type > > & out
161        ) {
162                if ( auto tupleType = dynamic_cast< const ast::TupleType * >( type ) ) {       
163                        for ( const ast::Type * t : tupleType->types ) {
164                                flatten( t, out );
165                        }
166                } else {
167                        out.emplace_back( type );
168                }
169        }
170
171        /// flatten tuple type into list of types
172        static inline std::vector< ast::ptr< ast::Type > > flatten( const ast::Type * type ) {
173                std::vector< ast::ptr< ast::Type > > out;
174                out.reserve( type->size() );
175                flatten( type, out );
176                return out;
177        }
[ee574a2]178
179        // in TypeEnvironment.cc
180        bool isFtype( Type *type );
[51b7345]181} // namespace ResolvExpr
182
[ee574a2]183namespace ast {
184        // in TypeEnvironment.cpp
185        bool isFtype( const ast::Type * type );
186} // namespace ast
187
[a32b204]188// Local Variables: //
189// tab-width: 4 //
190// mode: c++ //
191// compile-command: "make install" //
192// End: //
Note: See TracBrowser for help on using the repository browser.