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 | // ForallSubstitutor.hpp -- |
---|
8 | // |
---|
9 | // Author : Aaron B. Moss |
---|
10 | // Created On : Wed Jun 26 15:00:00 2019 |
---|
11 | // Last Modified By : Aaron B. Moss |
---|
12 | // Last Modified On : Wed Jun 26 15:00:00 2019 |
---|
13 | // Update Count : 1 |
---|
14 | // |
---|
15 | |
---|
16 | #include "Pass.hpp" |
---|
17 | |
---|
18 | namespace ast { |
---|
19 | |
---|
20 | class Expr; |
---|
21 | |
---|
22 | /// Visitor that correctly substitutes TypeDecl while maintaining TypeInstType bindings. |
---|
23 | /// Also has some convenience methods to mutate fields. |
---|
24 | struct ForallSubstitutor : public WithForallSubstitutor, public WithVisitorRef<ForallSubstitutor> { |
---|
25 | /// Substitute TypeInstType base type |
---|
26 | readonly< TypeDecl > operator() ( const readonly< TypeDecl > & o ) { |
---|
27 | return subs.replace( o ); |
---|
28 | } |
---|
29 | |
---|
30 | /// Make new forall-list clone |
---|
31 | ParameterizedType::ForallList operator() ( const ParameterizedType::ForallList & o ) { |
---|
32 | return subs.clone( o, *visitor ); |
---|
33 | } |
---|
34 | |
---|
35 | template<typename node_t > |
---|
36 | std::vector<ptr<node_t>> operator() (const std::vector<ptr<node_t>> & o) { |
---|
37 | std::vector<ptr<node_t>> n; |
---|
38 | n.reserve(o.size()); |
---|
39 | for (const node_t * d : o) { n.emplace_back(d->accept(*visitor)); } |
---|
40 | return n; |
---|
41 | } |
---|
42 | |
---|
43 | /* |
---|
44 | |
---|
45 | /// Substitute parameter/return type |
---|
46 | std::vector< ptr< DeclWithType > > operator() ( const std::vector< ptr< DeclWithType > > & o ) { |
---|
47 | std::vector< ptr< DeclWithType > > n; |
---|
48 | n.reserve( o.size() ); |
---|
49 | for ( const DeclWithType * d : o ) { n.emplace_back( d->accept( *visitor ) ); } |
---|
50 | return n; |
---|
51 | } |
---|
52 | |
---|
53 | /// Substitute type parameter list |
---|
54 | std::vector< ptr< Expr > > operator() ( const std::vector< ptr< Expr > > & o ) { |
---|
55 | std::vector< ptr< Expr > > n; |
---|
56 | n.reserve( o.size() ); |
---|
57 | for ( const Expr * d : o ) { n.emplace_back( d->accept( *visitor ) ); } |
---|
58 | return n; |
---|
59 | } |
---|
60 | |
---|
61 | */ |
---|
62 | }; |
---|
63 | |
---|
64 | } // namespace ast |
---|
65 | |
---|
66 | // Local Variables: // |
---|
67 | // tab-width: 4 // |
---|
68 | // mode: c++ // |
---|
69 | // compile-command: "make install" // |
---|
70 | // End: // |
---|