source: src/GenPoly/GenPoly.h @ 89a8bab

Last change on this file since 89a8bab was c6b4432, checked in by Andrew Beach <ajbeach@…>, 12 months ago

Remove BaseSyntaxNode? and clean-up.

  • Property mode set to 100644
File size: 5.1 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
[3606fe4]11// Last Modified By : Andrew Beach
[63d1ebe]12// Last Modified On : Mon Oct 24 15:18:00 2022
13// Update Count     : 11
[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
[82a90d4]22#include "AST/Decl.hpp"           // for AggregateDecl
[c8837e5]23#include "AST/Fwd.hpp"            // for ApplicationExpr, BaseInstType, Func...
[08fc48f]24#include "SymTab/Mangler.h"       // for Mangler
[51b7345]25
[82a90d4]26namespace ast {
27        struct TypeEnvKey;
28}
29
[51b7345]30namespace GenPoly {
[bdf1954]31
[52a5262e]32        struct TypeVarMap : public ErasableScopedMap<ast::TypeEnvKey, ast::TypeData> {
33                TypeVarMap() : ErasableScopedMap( ast::TypeData() ) {}
34        };
[3606fe4]35
[c2ad3c9]36        /// Replaces a TypeInstType by its referrent in the environment, if applicable
[63d1ebe]37        const ast::Type * replaceTypeInst( const ast::Type *, const ast::TypeSubstitution * );
[33a7b6d]38
[ffad73a]39        /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
[490fb92e]40        const ast::Type * isPolyType(const ast::Type * type, const ast::TypeSubstitution * env = nullptr);
[33a7b6d]41
[0f889a77]42        /// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
[c8837e5]43        const ast::Type * isPolyType( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst = nullptr );
[ffad73a]44
[3bb195cb]45        /// returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided
[c8837e5]46        const ast::BaseInstType *isDynType( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst = 0 );
[3bb195cb]47
48        /// true iff function has dynamic-layout return type under the given type variable map
[c8837e5]49        const ast::BaseInstType *isDynRet( const ast::FunctionType * type, const TypeVarMap & typeVars );
[3bb195cb]50
51        /// true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters
[63d1ebe]52        const ast::BaseInstType *isDynRet( const ast::FunctionType * func );
[3bb195cb]53
54        /// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type
[c8837e5]55        bool needsAdapter( ast::FunctionType const * adaptee, const TypeVarMap & typeVars );
[3bb195cb]56
[0f889a77]57        /// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
[c8837e5]58        const ast::Type * isPolyPtr( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * env = 0 );
[ffad73a]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
[c8837e5]62        const ast::Type * hasPolyBase( const ast::Type * type, const TypeVarMap & typeVars, int * levels = 0, const ast::TypeSubstitution * env = 0 );
[05d47278]63
[7754cde]64        /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
[d76c588]65        const ast::FunctionType * getFunctionType( const ast::Type * ty );
[05d47278]66
[5a3ac84]67        /// true iff types are structurally identical, where TypeInstType's match any type.
[3606fe4]68        bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs );
[5a3ac84]69
[ae1b9ea]70        /// true if arg requires boxing given exprTyVars
[c8837e5]71        bool needsBoxing( const ast::Type * param, const ast::Type * arg, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst );
[ae1b9ea]72
73        /// true if arg requires boxing in the call to appExpr
[c8837e5]74        bool needsBoxing( const ast::Type * param, const ast::Type * arg, const ast::ApplicationExpr * expr, const ast::TypeSubstitution * subst );
[ae1b9ea]75
[2c57025]76        /// Adds the type variable `tyVar` to `tyVarMap`
[c8837e5]77        void addToTypeVarMap( const ast::TypeDecl * type, TypeVarMap & typeVars );
[c97b448]78        void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars );
[2c57025]79
[aadc9a4]80        /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap`
[c8837e5]81        void makeTypeVarMap( const ast::Type * type, TypeVarMap & typeVars );
[c97b448]82        void makeTypeVarMap( const ast::FunctionDecl * decl, TypeVarMap & typeVars );
[33a7b6d]83
[adc6781]84        /// Gets the name of the sizeof parameter for the type, given its mangled name
85        inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; }
86
87        /// Gets the name of the alignof parameter for the type, given its mangled name
88        inline std::string alignofName( const std::string &name ) { return std::string( "_alignof_" ) + name; }
[ffad73a]89
[adc6781]90        /// Gets the name of the offsetof parameter for the type, given its mangled name
91        inline std::string offsetofName( const std::string &name ) { return std::string( "_offsetof_" ) + name; }
[05d47278]92
[adc6781]93        /// Gets the name of the layout function for a given aggregate type, given its declaration
[63d1ebe]94        inline std::string layoutofName( ast::AggregateDecl const * decl ) {
95                return std::string( "_layoutof_" ) + decl->name;
96        }
[33a7b6d]97
[51b7345]98} // namespace GenPoly
[b1a6d6b]99
[51587aa]100// Local Variables: //
101// tab-width: 4 //
102// mode: c++ //
103// compile-command: "make install" //
104// End: //
Note: See TracBrowser for help on using the repository browser.