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 | // ScrubTypeVars.hpp -- Remove polymorphic types.
|
---|
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 : Wed Dec 7 16:57:00 2022
|
---|
13 | // Update Count : 5
|
---|
14 | //
|
---|
15 |
|
---|
16 | #pragma once
|
---|
17 |
|
---|
18 | #include <cassert> // for strict_dynamic_cast
|
---|
19 |
|
---|
20 | #include "AST/Fwd.hpp" // for Node
|
---|
21 | #include "GenPoly.hpp" // for TypeVarMap
|
---|
22 |
|
---|
23 | namespace GenPoly {
|
---|
24 |
|
---|
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 |
|
---|
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 *>(
|
---|
39 | scrubTypeVarsBase( target, &typeVars, ScrubMode::FromMap ) );
|
---|
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>
|
---|
46 | node_t const * scrubTypeVarsDynamic(
|
---|
47 | node_t const * target, const TypeVarMap & typeVars ) {
|
---|
48 | return strict_dynamic_cast<node_t const *>(
|
---|
49 | scrubTypeVarsBase( target, &typeVars, ScrubMode::DynamicFromMap ) );
|
---|
50 | }
|
---|
51 |
|
---|
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 ) {
|
---|
56 | return strict_dynamic_cast<node_t const *>(
|
---|
57 | scrubTypeVarsBase( target, nullptr, ScrubMode::All ) );
|
---|
58 | }
|
---|
59 |
|
---|
60 | } // namespace GenPoly
|
---|
61 |
|
---|
62 | // Local Variables: //
|
---|
63 | // tab-width: 4 //
|
---|
64 | // mode: c++ //
|
---|
65 | // compile-command: "make install" //
|
---|
66 | // End: //
|
---|