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