source: src/Common/PassVisitor.proto.h @ 3fb9a83

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 3fb9a83 was 3fb9a83, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Fixed implementation of env, some optim needed

  • Property mode set to 100644
File size: 4.3 KB
Line 
1#pragma once
2
3//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4// Deep magic (a.k.a template meta programming) to make the templated visitor work
5// Basically the goal is to make 2 previsit_impl
6// 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of
7//     'pass.previsit( node )' that compiles will be used for that node for that type
8//     This requires that this option only compile for passes that actually define an appropriate visit.
9//     SFINAE will make sure the compilation errors in this function don't halt the build.
10//     See http://en.cppreference.com/w/cpp/language/sfinae for details on SFINAE
11// 2 - Since the first implementation might not be specilizable, the second implementation exists and does nothing.
12//     This is needed only to eliminate the need for passes to specify any kind of handlers.
13//     The second implementation only works because it has a lower priority. This is due to the bogus last parameter.
14//     The second implementation takes a long while the first takes an int. Since the caller always passes an literal 0
15//     the first implementation takes priority in regards to overloading.
16// Mutator functions work along the same principal
17//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
18// Visit
19template<typename pass_type, typename node_type>
20static inline auto previsit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.previsit( node ), void() ) {
21        pass.previsit( node );
22}
23
24template<typename pass_type, typename node_type>
25static inline void previsit_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {}
26
27
28template<typename pass_type, typename node_type>
29static inline auto postvisit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.postvisit( node ), void() ) {
30        pass.postvisit( node );
31}
32
33template<typename pass_type, typename node_type>
34static inline void postvisit_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {}
35
36// Mutate
37template<typename pass_type, typename node_type>
38static inline auto premutate_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.premutate( node ), void() ) {
39        return pass.premutate( node );
40}
41
42template<typename pass_type, typename node_type>
43static inline void premutate_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) {}
44
45
46template<typename return_type, typename pass_type, typename node_type>
47static inline auto postmutate_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.postmutate( node ) ) {
48        return pass.postmutate( node );
49}
50
51template<typename return_type, typename pass_type, typename node_type>
52static inline return_type postmutate_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) { return node; }
53
54// Begin/End scope
55template<typename pass_type>
56static inline auto begin_scope_impl( pass_type& pass, __attribute__((unused)) int unused ) ->decltype( pass.beginScope(), void() ) {
57        pass.beginScope();
58}
59
60template<typename pass_type>
61static inline void begin_scope_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) long unused ) {}
62
63
64template<typename pass_type>
65static inline auto end_scope_impl( pass_type& pass, __attribute__((unused)) int unused ) ->decltype( pass.endScope(), void() ) {
66        pass.endScope();
67}
68
69template<typename pass_type>
70static inline void end_scope_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) long unused ) {}
71
72// Env
73template<typename pass_type>
74static inline auto set_env_impl( pass_type& pass, TypeSubstitution * env, __attribute__((unused)) int unused ) ->decltype( pass.env, void() ) {
75        pass.env = env;
76}
77
78template<typename pass_type>
79static inline void set_env_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) TypeSubstitution * env, __attribute__((unused)) long unused ) {}
Note: See TracBrowser for help on using the repository browser.