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 <map> |
---|
20 | #include <string> |
---|
21 | #include <iostream> |
---|
22 | #include <utility> |
---|
23 | |
---|
24 | #include "SynTree/Declaration.h" |
---|
25 | #include "SynTree/Type.h" |
---|
26 | #include "SynTree/TypeSubstitution.h" |
---|
27 | |
---|
28 | namespace GenPoly { |
---|
29 | typedef std::map< std::string, TypeDecl::Kind > TyVarMap; |
---|
30 | |
---|
31 | /// A function needs an adapter if it returns a polymorphic value or if any of its |
---|
32 | /// parameters have polymorphic type |
---|
33 | bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr ); |
---|
34 | |
---|
35 | /// true iff function has polymorphic return type |
---|
36 | ReferenceToType *isPolyRet( FunctionType *function ); |
---|
37 | |
---|
38 | /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided |
---|
39 | Type *isPolyType( Type *type, const TypeSubstitution *env = 0 ); |
---|
40 | |
---|
41 | /// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided |
---|
42 | Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); |
---|
43 | |
---|
44 | /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided |
---|
45 | Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 ); |
---|
46 | |
---|
47 | /// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided |
---|
48 | Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); |
---|
49 | |
---|
50 | /// if the base type (after dereferencing N >= 0 pointers) is a polymorphic type, returns the base type, NULL otherwise; |
---|
51 | /// N will be stored in levels, if provided, will look up substitution in env if provided |
---|
52 | Type *hasPolyBase( Type *type, int *levels = 0, const TypeSubstitution *env = 0 ); |
---|
53 | |
---|
54 | /// if the base type (after dereferencing N >= 0 pointers) is a polymorphic type in tyVars, returns the base type, NULL otherwise; |
---|
55 | /// N will be stored in levels, if provided, will look up substitution in env if provided |
---|
56 | Type *hasPolyBase( Type *type, const TyVarMap &tyVars, int *levels = 0, const TypeSubstitution *env = 0 ); |
---|
57 | |
---|
58 | /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise |
---|
59 | FunctionType *getFunctionType( Type *ty ); |
---|
60 | |
---|
61 | /// If expr (after dereferencing N >= 0 pointers) is a variable expression, returns the variable expression, NULL otherwise; |
---|
62 | /// N will be stored in levels, if provided |
---|
63 | VariableExpr *getBaseVar( Expression *expr, int *levels = 0 ); |
---|
64 | |
---|
65 | /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap` |
---|
66 | void makeTyVarMap( Type *type, TyVarMap &tyVarMap ); |
---|
67 | |
---|
68 | /// Prints type variable map |
---|
69 | void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); |
---|
70 | |
---|
71 | /// Gets the name of the sizeof parameter for the type |
---|
72 | std::string sizeofName( Type *ty ); |
---|
73 | |
---|
74 | /// Gets the name of the alignof parameter for the type |
---|
75 | std::string alignofName( Type *ty ); |
---|
76 | |
---|
77 | /// Gets the name of the offsetof parameter for the type |
---|
78 | std::string offsetofName( Type *ty ); |
---|
79 | } // namespace GenPoly |
---|
80 | |
---|
81 | #endif // GENPOLY_H |
---|
82 | |
---|
83 | // Local Variables: // |
---|
84 | // tab-width: 4 // |
---|
85 | // mode: c++ // |
---|
86 | // compile-command: "make install" // |
---|
87 | // End: // |
---|