source: src/ResolvExpr/typeops.h@ d76c588

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since d76c588 was d76c588, checked in by Aaron Moss <a3moss@…>, 7 years ago

Stubs for new resolver, implementation of new indexer, type environment

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