Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.h

    r843054c2 rc2ad3c9  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:38:34 2015
    13 // Update Count     : 1
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Nov 24 15:24:38 2015
     13// Update Count     : 6
    1414//
    1515
     
    1717#define GENPOLY_H
    1818
    19 #include <map>
    2019#include <string>
    2120#include <iostream>
     21#include <utility>
     22
     23#include "ErasableScopedMap.h"
     24
     25#include "SymTab/Mangler.h"
     26
    2227#include "SynTree/Declaration.h"
     28#include "SynTree/Type.h"
     29#include "SynTree/TypeSubstitution.h"
    2330
    2431namespace GenPoly {
    25         typedef std::map< std::string, TypeDecl::Kind > TyVarMap;
     32        typedef ErasableScopedMap< std::string, TypeDecl::Kind > TyVarMap;
     33       
     34        /// A function needs an adapter if it returns a polymorphic value or if any of its
     35        /// parameters have polymorphic type
     36        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr );
    2637
    27         // considerAllTyVars allows ignoring the contents of the TyVarMap parameter, for the situations where
    28         // it is important only that a TypeInstType node exists.
     38        /// true iff function has polymorphic return type
     39        ReferenceToType *isPolyRet( FunctionType *function );
    2940
    30         bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr );
    31         bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars );
    32         bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars );
    33         bool isPolyVal( Type *type, const TyVarMap &tyVars );
    34         bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars );
     41        /// Replaces a TypeInstType by its referrent in the environment, if applicable
     42        Type* replaceTypeInst( Type* type, const TypeSubstitution* env );
     43       
     44        /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
     45        Type *isPolyType( Type *type, const TypeSubstitution *env = 0 );
     46       
     47        /// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
     48        Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
     49
     50        /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided
     51        Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 );
     52       
     53        /// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
     54        Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
     55
     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 );
     59
     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 );
     63
     64        /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
     65        FunctionType *getFunctionType( Type *ty );
     66
     67        /// If expr (after dereferencing N >= 0 pointers) is a variable expression, returns the variable expression, NULL otherwise;
     68        /// N will be stored in levels, if provided
     69        VariableExpr *getBaseVar( Expression *expr, int *levels = 0 );
     70
     71        /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap`
     72        void makeTyVarMap( Type *type, TyVarMap &tyVarMap );
     73       
     74        /// Prints type variable map
    3575        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
     76
     77        /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType().
     78        inline std::string mangleType( Type *ty ) { return SymTab::Mangler::mangleType( ty ); }
     79       
     80        /// Gets the name of the sizeof parameter for the type, given its mangled name
     81        inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; }
     82
     83        /// Gets the name of the alignof parameter for the type, given its mangled name
     84        inline std::string alignofName( const std::string &name ) { return std::string( "_alignof_" ) + name; }
     85
     86        /// Gets the name of the offsetof parameter for the type, given its mangled name
     87        inline std::string offsetofName( const std::string &name ) { return std::string( "_offsetof_" ) + name; }
     88
     89        /// Gets the name of the layout function for a given aggregate type, given its declaration
     90        inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); }
     91       
    3692} // namespace GenPoly
    3793
Note: See TracChangeset for help on using the changeset viewer.