source: src/GenPoly/GenPoly.h @ a104311

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since a104311 was 490fb92e, checked in by Fangren Yu <f37yu@…>, 4 years ago

move FixInit? to new ast

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