Ignore:
Timestamp:
Nov 13, 2023, 3:43:43 AM (23 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
25f2798
Parents:
0030b508 (diff), 2174191 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.h

    r0030b508 rfc12f05  
    2323#include "AST/Fwd.hpp"            // for ApplicationExpr, BaseInstType, Func...
    2424#include "SymTab/Mangler.h"       // for Mangler
    25 #include "SynTree/Declaration.h"  // for TypeDecl::Data, AggregateDecl, Type...
    26 #include "SynTree/SynTree.h"      // for Visitor Nodes
    2725
    2826namespace ast {
     
    3230namespace GenPoly {
    3331
    34         typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap;
    35         using TypeVarMap = ErasableScopedMap< ast::TypeEnvKey, ast::TypeData >;
     32        struct TypeVarMap : public ErasableScopedMap<ast::TypeEnvKey, ast::TypeData> {
     33                TypeVarMap() : ErasableScopedMap( ast::TypeData() ) {}
     34        };
    3635
    3736        /// Replaces a TypeInstType by its referrent in the environment, if applicable
    38         Type* replaceTypeInst( Type* type, const TypeSubstitution* env );
    39         const Type* replaceTypeInst( const Type* type, const TypeSubstitution* env );
    4037        const ast::Type * replaceTypeInst( const ast::Type *, const ast::TypeSubstitution * );
    4138
    4239        /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
    43         Type *isPolyType( Type *type, const TypeSubstitution *env = 0 );
    4440        const ast::Type * isPolyType(const ast::Type * type, const ast::TypeSubstitution * env = nullptr);
    4541
    4642        /// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
    47         Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
    4843        const ast::Type * isPolyType( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst = nullptr );
    4944
    5045        /// returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided
    51         ReferenceToType *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
    5246        const ast::BaseInstType *isDynType( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst = 0 );
    5347
    5448        /// true iff function has dynamic-layout return type under the given type variable map
    55         ReferenceToType *isDynRet( FunctionType *function, const TyVarMap &tyVars );
    5649        const ast::BaseInstType *isDynRet( const ast::FunctionType * type, const TypeVarMap & typeVars );
    5750
    5851        /// true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters
    59         ReferenceToType *isDynRet( FunctionType *function );
    6052        const ast::BaseInstType *isDynRet( const ast::FunctionType * func );
    6153
    6254        /// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type
    63         bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr );
    6455        bool needsAdapter( ast::FunctionType const * adaptee, const TypeVarMap & typeVars );
    6556
    66         /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided
    67         Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 );
    68 
    6957        /// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
    70         Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
    7158        const ast::Type * isPolyPtr( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * env = 0 );
    72 
    73         /// if the base type (after dereferencing N >= 0 pointers) is a polymorphic type, returns the base type, NULL otherwise;
    74         /// N will be stored in levels, if provided, will look up substitution in env if provided
    75         Type *hasPolyBase( Type *type, int *levels = 0, const TypeSubstitution *env = 0 );
    7659
    7760        /// if the base type (after dereferencing N >= 0 pointers) is a polymorphic type in tyVars, returns the base type, NULL otherwise;
    7861        /// N will be stored in levels, if provided, will look up substitution in env if provided
    79         Type *hasPolyBase( Type *type, const TyVarMap &tyVars, int *levels = 0, const TypeSubstitution *env = 0 );
    8062        const ast::Type * hasPolyBase( const ast::Type * type, const TypeVarMap & typeVars, int * levels = 0, const ast::TypeSubstitution * env = 0 );
    8163
    82         /// true iff this type or some base of this type after dereferencing pointers is either polymorphic or a generic type with at least one
    83         /// polymorphic parameter; will look up substitution in env if provided.
    84         bool includesPolyType( Type *type, const TypeSubstitution *env = 0 );
    85 
    86         /// true iff this type or some base of this type after dereferencing pointers is either polymorphic in tyVars, or a generic type with
    87         /// at least one polymorphic parameter in tyVars; will look up substitution in env if provided.
    88         bool includesPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
    89 
    9064        /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
    91         FunctionType *getFunctionType( Type *ty );
    9265        const ast::FunctionType * getFunctionType( const ast::Type * ty );
    9366
    94         /// If expr (after dereferencing N >= 0 pointers) is a variable expression, returns the variable expression, NULL otherwise;
    95         /// N will be stored in levels, if provided
    96         VariableExpr *getBaseVar( Expression *expr, int *levels = 0 );
    97 
    9867        /// true iff types are structurally identical, where TypeInstType's match any type.
    99         bool typesPolyCompatible( Type *aty, Type *bty );
    10068        bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs );
    10169
    10270        /// true if arg requires boxing given exprTyVars
    103         bool needsBoxing( Type * param, Type * arg, const TyVarMap &exprTyVars, const TypeSubstitution * env );
    10471        bool needsBoxing( const ast::Type * param, const ast::Type * arg, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst );
    10572
    10673        /// true if arg requires boxing in the call to appExpr
    107         bool needsBoxing( Type * param, Type * arg, ApplicationExpr * appExpr, const TypeSubstitution * env );
    10874        bool needsBoxing( const ast::Type * param, const ast::Type * arg, const ast::ApplicationExpr * expr, const ast::TypeSubstitution * subst );
    10975
    11076        /// Adds the type variable `tyVar` to `tyVarMap`
    111         void addToTyVarMap( TypeDecl * tyVar, TyVarMap &tyVarMap );
    11277        void addToTypeVarMap( const ast::TypeDecl * type, TypeVarMap & typeVars );
    11378        void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars );
    11479
    11580        /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap`
    116         void makeTyVarMap( Type *type, TyVarMap &tyVarMap );
    11781        void makeTypeVarMap( const ast::Type * type, TypeVarMap & typeVars );
    11882        void makeTypeVarMap( const ast::FunctionDecl * decl, TypeVarMap & typeVars );
    119 
    120         /// Prints type variable map
    121         void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
    122 
    123         /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType().
    124         inline std::string mangleType( const Type *ty ) { return SymTab::Mangler::mangleType( ty ); }
    12583
    12684        /// Gets the name of the sizeof parameter for the type, given its mangled name
     
    13492
    13593        /// Gets the name of the layout function for a given aggregate type, given its declaration
    136         inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); }
    13794        inline std::string layoutofName( ast::AggregateDecl const * decl ) {
    13895                return std::string( "_layoutof_" ) + decl->name;
Note: See TracChangeset for help on using the changeset viewer.