blob: c3fcf1a6cc18fb9bc90252741b3098f38da8a684 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/**
** \file ast/non-object-visitor.hh
** \brief Provide aborting visits for object-related nodes.
*/
#pragma once
#include <ast/visitor.hh>
namespace ast
{
/** GenNonObjectVisitor<CONSTNESS-SELECTOR> provides aborting visit
methods for object-related nodes. This class is meant to factor
the code visiting object-related nodes in visitors bound to
process AST \em without objects.
ast::GenNonObjectVisitor inherits virtually from ast::GenVisitor
to allow diamond inheritance, notably for a ``compatibility''
purpose with ast::GenDefaultVisitor.
For instance, type::TypeChecker, a visitor that checks the types
of an AST without objects, inherits from ast::DefaultVisitor to
factor default (``empty'') traversal implementations, and from
ast::NonObjectVisitor to get an aborting behavior for
object-related nodes.
\verbatim
/ast::Visitor/
^
(virtual) | (virtual)
,--------------+--------------.
| |
| |
/ast::DefaultVisitor/ /ast::NonObjectVisitor/
^ ^
| |
`--------------+--------------'
|
|
type::TypeChecker
\endverbatim
*/
template <template <typename> class Const>
class GenNonObjectVisitor : virtual public GenVisitor<Const>
{
public:
/// Super class type.
using super_type = GenVisitor<Const>;
// Import overloaded virtual functions.
using super_type::operator();
/// Convenient abbreviation.
template <typename Type> using const_t = typename Const<Type>::type;
/** \name Ctor & dtor.
** \{ */
/// Construct a non-object visitor.
GenNonObjectVisitor();
/// Destroy a non-object visitor.
virtual ~GenNonObjectVisitor();
/** \} */
/// \name Object-related visits.
///
/// The methods should not be used, since this visitor is for the
/// non-object flavor of the language.
/// \{
void operator()(const_t<ClassTy>& e) override;
void operator()(const_t<MethodChunk>& e) override;
void operator()(const_t<MethodDec>& e) override;
void operator()(const_t<MethodCallExp>& e) override;
void operator()(const_t<ObjectExp>& e) override;
/// \}
};
/// Shorthand for a const visitor.
using NonObjectConstVisitor = GenNonObjectVisitor<misc::constify_traits>;
/// Shorthand for a non const visitor.
using NonObjectVisitor = GenNonObjectVisitor<misc::id_traits>;
#ifdef SWIG
%template(NonObjectConstVisitor) GenNonObjectVisitor<misc::constify_traits>;
%template(NonObjectVisitor) GenNonObjectVisitor<misc::id_traits>;
#endif
} // namespace ast
#include <ast/non-object-visitor.hxx>
|