source: src/GenPoly/GenPoly.hpp @ 9d5eacb

Last change on this file since 9d5eacb was c92bdcc, checked in by Andrew Beach <ajbeach@…>, 6 months ago

Updated the rest of the names in src/ (except for the generated files).

  • Property mode set to 100644
File size: 5.2 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.hpp -- General GenPoly utilities.
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Andrew Beach
12// Last Modified On : Mon Oct 24 15:18:00 2022
13// Update Count     : 11
14//
15
16#pragma once
17
18#include <iostream>               // for ostream
19#include <string>                 // for string, allocator, operator+, basic...
20
21#include "ErasableScopedMap.hpp"  // for ErasableScopedMap
22#include "AST/Decl.hpp"           // for AggregateDecl
23#include "AST/Fwd.hpp"            // for ApplicationExpr, BaseInstType, Func...
24#include "SymTab/Mangler.hpp"     // for Mangler
25
26namespace ast {
27        struct TypeEnvKey;
28}
29
30namespace GenPoly {
31
32struct TypeVarMap : public ErasableScopedMap<ast::TypeEnvKey, ast::TypeData> {
33        TypeVarMap() : ErasableScopedMap( ast::TypeData() ) {}
34};
35
36/// Replaces a TypeInstType by its referrent in the environment, if applicable.
37const ast::Type * replaceTypeInst( const ast::Type *, const ast::TypeSubstitution * );
38
39/// Returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided.
40const ast::Type * isPolyType( const ast::Type * type, const ast::TypeSubstitution * subst = nullptr );
41
42/// Returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided.
43const ast::Type * isPolyType( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst = nullptr );
44
45/// Returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided.
46const ast::BaseInstType *isDynType( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst = 0 );
47
48/// Returns true iff function has dynamic-layout return type under the given type variable map.
49const ast::BaseInstType *isDynRet( const ast::FunctionType * type, const TypeVarMap & typeVars );
50
51/// Returns true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters.
52const ast::BaseInstType *isDynRet( const ast::FunctionType * func );
53
54/// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type.
55bool needsAdapter( ast::FunctionType const * adaptee, const TypeVarMap & typeVars );
56
57/// Returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided.
58const ast::Type * isPolyPtr( const ast::Type * type, const TypeVarMap & typeVars, const ast::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.
62const ast::Type * hasPolyBase( const ast::Type * type, const TypeVarMap & typeVars, int * levels = 0, const ast::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.
65const ast::FunctionType * getFunctionType( const ast::Type * ty );
66
67/// Returns true iff types are structurally identical, where TypeInstType's match any type.
68bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs );
69
70/// Returns true if arg requires boxing given typeVars.
71bool needsBoxing( const ast::Type * param, const ast::Type * arg, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst );
72
73/// Returns true if arg requires boxing in the call to appExpr.
74bool needsBoxing( const ast::Type * param, const ast::Type * arg, const ast::ApplicationExpr * expr, const ast::TypeSubstitution * subst );
75
76/// Adds the type variable `type` to `typeVars`.
77void addToTypeVarMap( const ast::TypeDecl * type, TypeVarMap & typeVars );
78void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars );
79
80/// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `typeVars`.
81void makeTypeVarMap( const ast::Type * type, TypeVarMap & typeVars );
82void makeTypeVarMap( const ast::FunctionDecl * decl, TypeVarMap & typeVars );
83
84/// Gets the name of the sizeof parameter for the type, given its mangled name.
85inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; }
86
87/// Gets the name of the alignof parameter for the type, given its mangled name.
88inline std::string alignofName( const std::string &name ) { return std::string( "_alignof_" ) + name; }
89
90/// Gets the name of the offsetof parameter for the type, given its mangled name.
91inline std::string offsetofName( const std::string &name ) { return std::string( "_offsetof_" ) + name; }
92
93/// Gets the name of the layout function for a given aggregate type, given its declaration.
94inline std::string layoutofName( ast::AggregateDecl const * decl ) {
95        return std::string( "_layoutof_" ) + decl->name;
96}
97
98} // namespace GenPoly
99
100// Local Variables: //
101// tab-width: 4 //
102// mode: c++ //
103// compile-command: "make install" //
104// End: //
Note: See TracBrowser for help on using the repository browser.