source: src/ResolvExpr/typeops.h @ ded5f07

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since ded5f07 was 9236060, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Merge branch 'master' into references

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