source: src/GenPoly/GenPoly.h @ cc7bbe6

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since cc7bbe6 was 490fb92e, checked in by Fangren Yu <f37yu@…>, 4 years ago

move FixInit? to new ast

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