[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 | // |
---|
[b8b5535] | 7 | // ScrubTyVars.h -- Remove polymorphic types. |
---|
[51587aa] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[3606fe4] | 11 | // Last Modified By : Andrew Beach |
---|
[ea2ed3a] | 12 | // Last Modified On : Wed Dec 7 16:57:00 2022 |
---|
| 13 | // Update Count : 5 |
---|
[51587aa] | 14 | // |
---|
[01aeade] | 15 | |
---|
[6b0b624] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[ea6332d] | 18 | #include <cassert> // for assert |
---|
[78dd0da] | 19 | |
---|
[3606fe4] | 20 | #include "AST/Fwd.hpp" // for Node |
---|
[b8b5535] | 21 | #include "GenPoly.h" // for TypeVarMap, isPolyType, isDynType |
---|
[51b7345] | 22 | |
---|
| 23 | namespace GenPoly { |
---|
[3bb195cb] | 24 | |
---|
[ea2ed3a] | 25 | // ScrubMode and scrubTypeVarsBase are internal. |
---|
| 26 | enum class ScrubMode { FromMap, DynamicFromMap, All }; |
---|
| 27 | |
---|
| 28 | const ast::Node * scrubTypeVarsBase( |
---|
| 29 | const ast::Node * target, const TypeVarMap * typeVars, ScrubMode mode ); |
---|
| 30 | |
---|
| 31 | |
---|
[c8837e5] | 32 | /// For all polymorphic types with type variables in `typeVars`, |
---|
| 33 | /// replaces generic types, dtypes, and ftypes with the appropriate void type, |
---|
| 34 | /// and sizeof/alignof expressions with the proper variable. |
---|
| 35 | template<typename node_t> |
---|
| 36 | node_t const * scrubTypeVars( |
---|
| 37 | node_t const * target, const TypeVarMap & typeVars ) { |
---|
| 38 | return strict_dynamic_cast<node_t const *>( |
---|
[ea2ed3a] | 39 | scrubTypeVarsBase( target, &typeVars, ScrubMode::FromMap ) ); |
---|
[c8837e5] | 40 | } |
---|
| 41 | |
---|
| 42 | /// For all dynamic-layout types with type variables in `typeVars`, |
---|
| 43 | /// replaces generic types, dtypes, and ftypes with the appropriate void type, |
---|
| 44 | /// and sizeof/alignof expressions with the proper variable. |
---|
| 45 | template<typename node_t> |
---|
[ea2ed3a] | 46 | node_t const * scrubTypeVarsDynamic( |
---|
[c8837e5] | 47 | node_t const * target, const TypeVarMap & typeVars ) { |
---|
| 48 | return strict_dynamic_cast<node_t const *>( |
---|
[ea2ed3a] | 49 | scrubTypeVarsBase( target, &typeVars, ScrubMode::DynamicFromMap ) ); |
---|
[c8837e5] | 50 | } |
---|
| 51 | |
---|
[3606fe4] | 52 | /// For all polymorphic types, replaces generic types, with the appropriate |
---|
| 53 | /// void type, and sizeof/alignof expressions with the proper variable. |
---|
| 54 | template<typename node_t> |
---|
| 55 | node_t const * scrubAllTypeVars( node_t const * target ) { |
---|
[c8837e5] | 56 | return strict_dynamic_cast<node_t const *>( |
---|
[ea2ed3a] | 57 | scrubTypeVarsBase( target, nullptr, ScrubMode::All ) ); |
---|
[3606fe4] | 58 | } |
---|
| 59 | |
---|
[51b7345] | 60 | } // namespace GenPoly |
---|
| 61 | |
---|
[51587aa] | 62 | // Local Variables: // |
---|
| 63 | // tab-width: 4 // |
---|
| 64 | // mode: c++ // |
---|
| 65 | // compile-command: "make install" // |
---|
| 66 | // End: // |
---|