[51587aa] | 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 | //
|
---|
[33a7b6d] | 7 | // GenPoly.h --
|
---|
[51587aa] | 8 | //
|
---|
| 9 | // Author : Richard C. Bilson
|
---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
---|
[3606fe4] | 11 | // Last Modified By : Andrew Beach
|
---|
| 12 | // Last Modified On : Fri Aug 19 16:03:00 2022
|
---|
| 13 | // Update Count : 8
|
---|
[51587aa] | 14 | //
|
---|
[51b73452] | 15 |
|
---|
[6b0b624] | 16 | #pragma once
|
---|
[b1a6d6b] | 17 |
|
---|
[08fc48f] | 18 | #include <iostream> // for ostream
|
---|
| 19 | #include <string> // for string, allocator, operator+, basic...
|
---|
[ffad73a] | 20 |
|
---|
[08fc48f] | 21 | #include "ErasableScopedMap.h" // for ErasableScopedMap
|
---|
[d76c588] | 22 | #include "AST/Fwd.hpp"
|
---|
[08fc48f] | 23 | #include "SymTab/Mangler.h" // for Mangler
|
---|
| 24 | #include "SynTree/Declaration.h" // for TypeDecl::Data, AggregateDecl, Type...
|
---|
| 25 | #include "SynTree/SynTree.h" // for Visitor Nodes
|
---|
[51b73452] | 26 |
|
---|
| 27 | namespace GenPoly {
|
---|
[bdf1954] | 28 |
|
---|
[3606fe4] | 29 | // TODO Via some tricks this works for ast::TypeDecl::Data as well.
|
---|
[490fb92e] | 30 | typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap;
|
---|
[3606fe4] | 31 |
|
---|
[c2ad3c9] | 32 | /// Replaces a TypeInstType by its referrent in the environment, if applicable
|
---|
| 33 | Type* replaceTypeInst( Type* type, const TypeSubstitution* env );
|
---|
[33a7b6d] | 34 |
|
---|
[ffad73a] | 35 | /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
|
---|
[0f889a77] | 36 | Type *isPolyType( Type *type, const TypeSubstitution *env = 0 );
|
---|
[490fb92e] | 37 | const ast::Type * isPolyType(const ast::Type * type, const ast::TypeSubstitution * env = nullptr);
|
---|
[33a7b6d] | 38 |
|
---|
[0f889a77] | 39 | /// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
|
---|
[ffad73a] | 40 | Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
|
---|
[490fb92e] | 41 | const ast::Type * isPolyType(const ast::Type * type, const TyVarMap & tyVars, const ast::TypeSubstitution * env = nullptr);
|
---|
[ffad73a] | 42 |
|
---|
[3bb195cb] | 43 | /// returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided
|
---|
[33a7b6d] | 44 | ReferenceToType *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
|
---|
[3606fe4] | 45 | const ast::BaseInstType *isDynType( const ast::Type *type, const TyVarMap &tyVars, const ast::TypeSubstitution *typeSubs = 0 );
|
---|
[3bb195cb] | 46 |
|
---|
| 47 | /// true iff function has dynamic-layout return type under the given type variable map
|
---|
| 48 | ReferenceToType *isDynRet( FunctionType *function, const TyVarMap &tyVars );
|
---|
| 49 |
|
---|
| 50 | /// true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters
|
---|
| 51 | ReferenceToType *isDynRet( FunctionType *function );
|
---|
| 52 |
|
---|
| 53 | /// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type
|
---|
| 54 | bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr );
|
---|
| 55 |
|
---|
[ffad73a] | 56 | /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided
|
---|
[0f889a77] | 57 | Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 );
|
---|
[33a7b6d] | 58 |
|
---|
[0f889a77] | 59 | /// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
|
---|
[ffad73a] | 60 | Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
|
---|
| 61 |
|
---|
[8488c715] | 62 | /// if the base type (after dereferencing N >= 0 pointers) is a polymorphic type, returns the base type, NULL otherwise;
|
---|
| 63 | /// N will be stored in levels, if provided, will look up substitution in env if provided
|
---|
| 64 | Type *hasPolyBase( Type *type, int *levels = 0, const TypeSubstitution *env = 0 );
|
---|
[05d47278] | 65 |
|
---|
[8488c715] | 66 | /// if the base type (after dereferencing N >= 0 pointers) is a polymorphic type in tyVars, returns the base type, NULL otherwise;
|
---|
| 67 | /// N will be stored in levels, if provided, will look up substitution in env if provided
|
---|
| 68 | Type *hasPolyBase( Type *type, const TyVarMap &tyVars, int *levels = 0, const TypeSubstitution *env = 0 );
|
---|
[05d47278] | 69 |
|
---|
[08fc48f] | 70 | /// true iff this type or some base of this type after dereferencing pointers is either polymorphic or a generic type with at least one
|
---|
[5a3ac84] | 71 | /// polymorphic parameter; will look up substitution in env if provided.
|
---|
| 72 | bool includesPolyType( Type *type, const TypeSubstitution *env = 0 );
|
---|
| 73 |
|
---|
[08fc48f] | 74 | /// true iff this type or some base of this type after dereferencing pointers is either polymorphic in tyVars, or a generic type with
|
---|
[5a3ac84] | 75 | /// at least one polymorphic parameter in tyVars; will look up substitution in env if provided.
|
---|
| 76 | bool includesPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
|
---|
| 77 |
|
---|
[7754cde] | 78 | /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
|
---|
[05d47278] | 79 | FunctionType *getFunctionType( Type *ty );
|
---|
[d76c588] | 80 | const ast::FunctionType * getFunctionType( const ast::Type * ty );
|
---|
[05d47278] | 81 |
|
---|
[8488c715] | 82 | /// If expr (after dereferencing N >= 0 pointers) is a variable expression, returns the variable expression, NULL otherwise;
|
---|
| 83 | /// N will be stored in levels, if provided
|
---|
| 84 | VariableExpr *getBaseVar( Expression *expr, int *levels = 0 );
|
---|
[7754cde] | 85 |
|
---|
[5a3ac84] | 86 | /// true iff types are structurally identical, where TypeInstType's match any type.
|
---|
| 87 | bool typesPolyCompatible( Type *aty, Type *bty );
|
---|
[3606fe4] | 88 | bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs );
|
---|
[5a3ac84] | 89 |
|
---|
[ae1b9ea] | 90 | /// true if arg requires boxing given exprTyVars
|
---|
[02fdb8e] | 91 | bool needsBoxing( Type * param, Type * arg, const TyVarMap &exprTyVars, const TypeSubstitution * env );
|
---|
[490fb92e] | 92 | bool needsBoxing( const ast::Type * param, const ast::Type * arg, const TyVarMap &exprTyVars, const ast::TypeSubstitution * env);
|
---|
[ae1b9ea] | 93 |
|
---|
| 94 | /// true if arg requires boxing in the call to appExpr
|
---|
[02fdb8e] | 95 | bool needsBoxing( Type * param, Type * arg, ApplicationExpr * appExpr, const TypeSubstitution * env );
|
---|
[490fb92e] | 96 | bool needsBoxing( const ast::Type * param, const ast::Type * arg, const ast::ApplicationExpr * appExpr, const ast::TypeSubstitution * env);
|
---|
[ae1b9ea] | 97 |
|
---|
[2c57025] | 98 | /// Adds the type variable `tyVar` to `tyVarMap`
|
---|
| 99 | void addToTyVarMap( TypeDecl * tyVar, TyVarMap &tyVarMap );
|
---|
| 100 |
|
---|
[aadc9a4] | 101 | /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap`
|
---|
| 102 | void makeTyVarMap( Type *type, TyVarMap &tyVarMap );
|
---|
[490fb92e] | 103 | void makeTyVarMap(const ast::Type * type, TyVarMap & tyVarMap);
|
---|
[33a7b6d] | 104 |
|
---|
[ffad73a] | 105 | /// Prints type variable map
|
---|
[01aeade] | 106 | void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
|
---|
[ffad73a] | 107 |
|
---|
[adc6781] | 108 | /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType().
|
---|
| 109 | inline std::string mangleType( Type *ty ) { return SymTab::Mangler::mangleType( ty ); }
|
---|
[33a7b6d] | 110 |
|
---|
[adc6781] | 111 | /// Gets the name of the sizeof parameter for the type, given its mangled name
|
---|
| 112 | inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; }
|
---|
| 113 |
|
---|
| 114 | /// Gets the name of the alignof parameter for the type, given its mangled name
|
---|
| 115 | inline std::string alignofName( const std::string &name ) { return std::string( "_alignof_" ) + name; }
|
---|
[ffad73a] | 116 |
|
---|
[adc6781] | 117 | /// Gets the name of the offsetof parameter for the type, given its mangled name
|
---|
| 118 | inline std::string offsetofName( const std::string &name ) { return std::string( "_offsetof_" ) + name; }
|
---|
[05d47278] | 119 |
|
---|
[adc6781] | 120 | /// Gets the name of the layout function for a given aggregate type, given its declaration
|
---|
| 121 | inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); }
|
---|
[33a7b6d] | 122 |
|
---|
[51b73452] | 123 | } // namespace GenPoly
|
---|
[b1a6d6b] | 124 |
|
---|
[51587aa] | 125 | // Local Variables: //
|
---|
| 126 | // tab-width: 4 //
|
---|
| 127 | // mode: c++ //
|
---|
| 128 | // compile-command: "make install" //
|
---|
| 129 | // End: //
|
---|