source: src/ResolvExpr/typeops.h @ 17a0228a

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 17a0228a was 54e41b3, checked in by Aaron Moss <a3moss@…>, 5 years ago

Add first half of ast::Expr subclasses

  • Property mode set to 100644
File size: 4.9 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
[54e41b3]20#include "AST/Node.hpp"
21#include "AST/Type.hpp"
[51b7345]22#include "SynTree/SynTree.h"
23#include "SynTree/Type.h"
24#include "SymTab/Indexer.h"
25#include "Cost.h"
26#include "TypeEnvironment.h"
27
28namespace ResolvExpr {
[a32b204]29        // combos: takes a list of sets and returns a set of lists representing every possible way of forming a list by
30        // picking one element out of each set
31        template< typename InputIterator, typename OutputIterator >
32        void combos( InputIterator begin, InputIterator end, OutputIterator out ) {
33                typedef typename InputIterator::value_type SetType;
[bd4f2e9]34                typedef typename std::vector< typename SetType::value_type > ListType;
[906e24d]35
[a32b204]36                if ( begin == end )     {
37                        *out++ = ListType();
38                        return;
39                } // if
[906e24d]40
[a32b204]41                InputIterator current = begin;
42                begin++;
[51b7345]43
[bd4f2e9]44                std::vector< ListType > recursiveResult;
[a32b204]45                combos( begin, end, back_inserter( recursiveResult ) );
[906e24d]46
[bd4f2e9]47                for ( const auto& i : recursiveResult ) for ( const auto& j : *current ) {
48                        ListType result;
49                        std::back_insert_iterator< ListType > inserter = back_inserter( result );
50                        *inserter++ = j;
51                        std::copy( i.begin(), i.end(), inserter );
52                        *out++ = result;
53                }
[a32b204]54        }
[906e24d]55
[a32b204]56        // in AdjustExprType.cc
[2de162da]57        /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function
[a32b204]58        void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
59
[c20b0fea]60        /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function using empty TypeEnvironment and Indexer
61        void adjustExprType( Type *& type );
62
[a32b204]63        template< typename ForwardIterator >
64        void adjustExprTypeList( ForwardIterator begin, ForwardIterator end, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
65                while ( begin != end ) {
66                        adjustExprType( *begin++, env, indexer );
67                } // while
68        }
69
70        // in CastCost.cc
71        Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
72
73        // in ConversionCost.cc
74        Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
75
[fbecee5]76        // in AlternativeFinder.cc
77        Cost computeConversionCost( Type *actualType, Type *formalType, 
78                const SymTab::Indexer &indexer, const TypeEnvironment &env );
79
[a32b204]80        // in PtrsAssignable.cc
81        int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env );
82
83        // in PtrsCastable.cc
84        int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
85
86        // in Unify.cc
[d7dc824]87        bool isFtype( Type *type );
[a32b204]88        bool typesCompatible( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
89        bool typesCompatibleIgnoreQualifiers( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
90
91        inline bool typesCompatible( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
92                TypeEnvironment env;
93                return typesCompatible( t1, t2, indexer, env );
94        }
95
96        inline bool typesCompatibleIgnoreQualifiers( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
97                TypeEnvironment env;
98                return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
99        }
100
[906e24d]101        /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
102        Type * extractResultType( FunctionType * functionType );
[54e41b3]103        /// Creates or extracts the type represented by the list of returns in a `FunctionType`.
104        ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func );
[906e24d]105
[a32b204]106        // in CommonType.cc
[0e66857]107        Type * commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
[a32b204]108
109        // in PolyCost.cc
110        int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
111
[1dd1bd2]112        // in SpecCost.cc
113        int specCost( Type *type );
114
[a32b204]115        // in Occurs.cc
116        bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
[906e24d]117
[9ad2f9f]118        template<typename Iter> 
119        bool occursIn( Type* ty, Iter begin, Iter end, const TypeEnvironment &env ) {
120                while ( begin != end ) {
121                        if ( occurs( ty, *begin, env ) ) return true;
122                        ++begin;
123                }
124                return false;
125        }
126
[6d2f993]127        // in AlternativeFinder.cc
[a181494]128        void referenceToRvalueConversion( Expression *& expr, Cost & cost );
[6d2f993]129
[906e24d]130        // flatten tuple type into list of types
131        template< typename OutputIterator >
132        void flatten( Type * type, OutputIterator out ) {
133                if ( TupleType * tupleType = dynamic_cast< TupleType * >( type ) ) {
134                        for ( Type * t : tupleType->get_types() ) {
135                                flatten( t, out );
136                        }
137                } else {
[6c3a988f]138                        *out++ = type->clone();
[906e24d]139                }
140        }
[51b7345]141} // namespace ResolvExpr
142
[a32b204]143// Local Variables: //
144// tab-width: 4 //
145// mode: c++ //
146// compile-command: "make install" //
147// End: //
Note: See TracBrowser for help on using the repository browser.