| [e0e9a0b] | 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 | /// Substitute parameter/return type | 
|---|
|  | 36 | std::vector< ptr< DeclWithType > > operator() ( const std::vector< ptr< DeclWithType > > & o ) { | 
|---|
|  | 37 | std::vector< ptr< DeclWithType > > n; | 
|---|
|  | 38 | n.reserve( o.size() ); | 
|---|
|  | 39 | for ( const DeclWithType * d : o ) { n.emplace_back( d->accept( *visitor ) ); } | 
|---|
|  | 40 | return n; | 
|---|
|  | 41 | } | 
|---|
|  | 42 |  | 
|---|
|  | 43 | /// Substitute type parameter list | 
|---|
|  | 44 | std::vector< ptr< Expr > > operator() ( const std::vector< ptr< Expr > > & o ) { | 
|---|
|  | 45 | std::vector< ptr< Expr > > n; | 
|---|
|  | 46 | n.reserve( o.size() ); | 
|---|
|  | 47 | for ( const Expr * d : o ) { n.emplace_back( d->accept( *visitor ) ); } | 
|---|
|  | 48 | return n; | 
|---|
|  | 49 | } | 
|---|
|  | 50 | }; | 
|---|
|  | 51 |  | 
|---|
|  | 52 | } // namespace ast | 
|---|
|  | 53 |  | 
|---|
|  | 54 | // Local Variables: // | 
|---|
|  | 55 | // tab-width: 4 // | 
|---|
|  | 56 | // mode: c++ // | 
|---|
|  | 57 | // compile-command: "make install" // | 
|---|
|  | 58 | // End: // | 
|---|