source: src/ResolvExpr/typeops.h @ da48183

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since da48183 was 9ad2f9f, checked in by Aaron Moss <a3moss@…>, 5 years ago

TypeEnvironment::combine -- compiles, untested

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