source: src/GenPoly/GenPoly.h@ ae4038d

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since ae4038d was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

change #ifndef to #pragma once

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