[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 |
---|
[6b0b624] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Sat Jul 22 09:22:57 2017 |
---|
| 13 | // Update Count : 7 |
---|
[51587aa] | 14 | // |
---|
[51b7345] | 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 |
---|
| 22 | #include "SymTab/Mangler.h" // for Mangler |
---|
| 23 | #include "SynTree/Declaration.h" // for TypeDecl::Data, AggregateDecl, Type... |
---|
| 24 | #include "SynTree/SynTree.h" // for Visitor Nodes |
---|
[51b7345] | 25 | |
---|
| 26 | namespace GenPoly { |
---|
[2c57025] | 27 | typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap; |
---|
[bdf1954] | 28 | |
---|
[c2ad3c9] | 29 | /// Replaces a TypeInstType by its referrent in the environment, if applicable |
---|
| 30 | Type* replaceTypeInst( Type* type, const TypeSubstitution* env ); |
---|
[33a7b6d] | 31 | |
---|
[ffad73a] | 32 | /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided |
---|
[0f889a77] | 33 | Type *isPolyType( Type *type, const TypeSubstitution *env = 0 ); |
---|
[33a7b6d] | 34 | |
---|
[0f889a77] | 35 | /// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided |
---|
[ffad73a] | 36 | Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); |
---|
| 37 | |
---|
[3bb195cb] | 38 | /// returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided |
---|
[33a7b6d] | 39 | ReferenceToType *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); |
---|
[3bb195cb] | 40 | |
---|
| 41 | /// true iff function has dynamic-layout return type under the given type variable map |
---|
| 42 | ReferenceToType *isDynRet( FunctionType *function, const TyVarMap &tyVars ); |
---|
| 43 | |
---|
| 44 | /// true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters |
---|
| 45 | ReferenceToType *isDynRet( FunctionType *function ); |
---|
| 46 | |
---|
| 47 | /// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type |
---|
| 48 | bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr ); |
---|
| 49 | |
---|
[ffad73a] | 50 | /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided |
---|
[0f889a77] | 51 | Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 ); |
---|
[33a7b6d] | 52 | |
---|
[0f889a77] | 53 | /// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided |
---|
[ffad73a] | 54 | Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); |
---|
| 55 | |
---|
[8488c715] | 56 | /// if the base type (after dereferencing N >= 0 pointers) is a polymorphic type, returns the base type, NULL otherwise; |
---|
| 57 | /// N will be stored in levels, if provided, will look up substitution in env if provided |
---|
| 58 | Type *hasPolyBase( Type *type, int *levels = 0, const TypeSubstitution *env = 0 ); |
---|
[05d47278] | 59 | |
---|
[8488c715] | 60 | /// if the base type (after dereferencing N >= 0 pointers) is a polymorphic type in tyVars, returns the base type, NULL otherwise; |
---|
| 61 | /// N will be stored in levels, if provided, will look up substitution in env if provided |
---|
| 62 | Type *hasPolyBase( Type *type, const TyVarMap &tyVars, int *levels = 0, const TypeSubstitution *env = 0 ); |
---|
[05d47278] | 63 | |
---|
[08fc48f] | 64 | /// 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] | 65 | /// polymorphic parameter; will look up substitution in env if provided. |
---|
| 66 | bool includesPolyType( Type *type, const TypeSubstitution *env = 0 ); |
---|
| 67 | |
---|
[08fc48f] | 68 | /// true iff this type or some base of this type after dereferencing pointers is either polymorphic in tyVars, or a generic type with |
---|
[5a3ac84] | 69 | /// at least one polymorphic parameter in tyVars; will look up substitution in env if provided. |
---|
| 70 | bool includesPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); |
---|
| 71 | |
---|
[7754cde] | 72 | /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise |
---|
[05d47278] | 73 | FunctionType *getFunctionType( Type *ty ); |
---|
| 74 | |
---|
[8488c715] | 75 | /// If expr (after dereferencing N >= 0 pointers) is a variable expression, returns the variable expression, NULL otherwise; |
---|
| 76 | /// N will be stored in levels, if provided |
---|
| 77 | VariableExpr *getBaseVar( Expression *expr, int *levels = 0 ); |
---|
[7754cde] | 78 | |
---|
[5a3ac84] | 79 | /// true iff types are structurally identical, where TypeInstType's match any type. |
---|
| 80 | bool typesPolyCompatible( Type *aty, Type *bty ); |
---|
| 81 | |
---|
[2c57025] | 82 | /// Adds the type variable `tyVar` to `tyVarMap` |
---|
| 83 | void addToTyVarMap( TypeDecl * tyVar, TyVarMap &tyVarMap ); |
---|
| 84 | |
---|
[aadc9a4] | 85 | /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap` |
---|
| 86 | void makeTyVarMap( Type *type, TyVarMap &tyVarMap ); |
---|
[33a7b6d] | 87 | |
---|
[ffad73a] | 88 | /// Prints type variable map |
---|
[01aeade] | 89 | void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); |
---|
[ffad73a] | 90 | |
---|
[adc6781] | 91 | /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType(). |
---|
| 92 | inline std::string mangleType( Type *ty ) { return SymTab::Mangler::mangleType( ty ); } |
---|
[33a7b6d] | 93 | |
---|
[adc6781] | 94 | /// Gets the name of the sizeof parameter for the type, given its mangled name |
---|
| 95 | inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; } |
---|
| 96 | |
---|
| 97 | /// Gets the name of the alignof parameter for the type, given its mangled name |
---|
| 98 | inline std::string alignofName( const std::string &name ) { return std::string( "_alignof_" ) + name; } |
---|
[ffad73a] | 99 | |
---|
[adc6781] | 100 | /// Gets the name of the offsetof parameter for the type, given its mangled name |
---|
| 101 | inline std::string offsetofName( const std::string &name ) { return std::string( "_offsetof_" ) + name; } |
---|
[05d47278] | 102 | |
---|
[adc6781] | 103 | /// Gets the name of the layout function for a given aggregate type, given its declaration |
---|
| 104 | inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); } |
---|
[33a7b6d] | 105 | |
---|
[51b7345] | 106 | } // namespace GenPoly |
---|
[b1a6d6b] | 107 | |
---|
[51587aa] | 108 | // Local Variables: // |
---|
| 109 | // tab-width: 4 // |
---|
| 110 | // mode: c++ // |
---|
| 111 | // compile-command: "make install" // |
---|
| 112 | // End: // |
---|