source: src/GenPoly/GenPoly.h @ 1744e6d

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 1744e6d was 5a3ac84, checked in by Aaron Moss <a3moss@…>, 8 years ago

Fixed Box(T*) generic instantiation bug

  • Property mode set to 100644
File size: 5.6 KB
Line 
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//
7// GenPoly.h --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Rob Schluntz
12// Last Modified On : Tue Nov 24 15:24:38 2015
13// Update Count     : 6
14//
15
16#ifndef GENPOLY_H
17#define GENPOLY_H
18
19#include <string>
20#include <iostream>
21#include <utility>
22
23#include "ErasableScopedMap.h"
24
25#include "SymTab/Mangler.h"
26
27#include "SynTree/Declaration.h"
28#include "SynTree/Type.h"
29#include "SynTree/TypeSubstitution.h"
30
31namespace GenPoly {
32        typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap;
33
34        /// Replaces a TypeInstType by its referrent in the environment, if applicable
35        Type* replaceTypeInst( Type* type, const TypeSubstitution* env );
36
37        /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
38        Type *isPolyType( Type *type, const TypeSubstitution *env = 0 );
39
40        /// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
41        Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
42
43        /// returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided
44        ReferenceToType *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
45
46        /// true iff function has dynamic-layout return type under the given type variable map
47        ReferenceToType *isDynRet( FunctionType *function, const TyVarMap &tyVars );
48
49        /// true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters
50        ReferenceToType *isDynRet( FunctionType *function );
51
52        /// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type
53        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr );
54
55        /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided
56        Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 );
57
58        /// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
59        Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
60
61        /// if the base type (after dereferencing N >= 0 pointers) is a polymorphic type, 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, int *levels = 0, const TypeSubstitution *env = 0 );
64
65        /// if the base type (after dereferencing N >= 0 pointers) is a polymorphic type in tyVars, returns the base type, NULL otherwise;
66        /// N will be stored in levels, if provided, will look up substitution in env if provided
67        Type *hasPolyBase( Type *type, const TyVarMap &tyVars, int *levels = 0, const TypeSubstitution *env = 0 );
68
69        /// true iff this type or some base of this type after dereferencing pointers is either polymorphic or a generic type with at least one
70        /// polymorphic parameter; will look up substitution in env if provided.
71        bool includesPolyType( Type *type, const TypeSubstitution *env = 0 );
72
73        /// true iff this type or some base of this type after dereferencing pointers is either polymorphic in tyVars, or a generic type with
74        /// at least one polymorphic parameter in tyVars; will look up substitution in env if provided.
75        bool includesPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
76
77        /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
78        FunctionType *getFunctionType( Type *ty );
79
80        /// If expr (after dereferencing N >= 0 pointers) is a variable expression, returns the variable expression, NULL otherwise;
81        /// N will be stored in levels, if provided
82        VariableExpr *getBaseVar( Expression *expr, int *levels = 0 );
83
84        /// true iff types are structurally identical, where TypeInstType's match any type.
85        bool typesPolyCompatible( Type *aty, Type *bty );
86
87        /// Adds the type variable `tyVar` to `tyVarMap`
88        void addToTyVarMap( TypeDecl * tyVar, TyVarMap &tyVarMap );
89
90        /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap`
91        void makeTyVarMap( Type *type, TyVarMap &tyVarMap );
92
93        /// Prints type variable map
94        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
95
96        /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType().
97        inline std::string mangleType( Type *ty ) { return SymTab::Mangler::mangleType( ty ); }
98
99        /// Gets the name of the sizeof parameter for the type, given its mangled name
100        inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; }
101
102        /// Gets the name of the alignof parameter for the type, given its mangled name
103        inline std::string alignofName( const std::string &name ) { return std::string( "_alignof_" ) + name; }
104
105        /// Gets the name of the offsetof parameter for the type, given its mangled name
106        inline std::string offsetofName( const std::string &name ) { return std::string( "_offsetof_" ) + name; }
107
108        /// Gets the name of the layout function for a given aggregate type, given its declaration
109        inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); }
110
111} // namespace GenPoly
112
113#endif // GENPOLY_H
114
115// Local Variables: //
116// tab-width: 4 //
117// mode: c++ //
118// compile-command: "make install" //
119// End: //
Note: See TracBrowser for help on using the repository browser.