Repository navigation
Expand file tree
/
Copy pathvisitor.cpp
More file actions
106 lines (96 loc) · 4.14 KB
/
Copy pathvisitor.cpp
File metadata and controls
106 lines (96 loc) · 4.14 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (C) 2017 Jonathan Müller <jonathanmueller.dev@gmail.com>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#include <cppast/visitor.hpp>
#include <cppast/cpp_alias_template.hpp>
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_class.hpp>
#include <cppast/cpp_class_template.hpp>
#include <cppast/cpp_enum.hpp>
#include <cppast/cpp_file.hpp>
#include <cppast/cpp_function_template.hpp>
#include <cppast/cpp_language_linkage.hpp>
#include <cppast/cpp_namespace.hpp>
#include <cppast/cpp_variable_template.hpp>
using namespace cppast;
namespace
{
template <typename T>
bool handle_container(const cpp_entity& e, detail::visitor_callback_t cb, void* functor,
bool last_child)
{
auto& container = static_cast<const T&>(e);
auto handle_children =
cb(functor, container, {visitor_info::container_entity_enter, last_child});
if (handle_children)
{
for (auto iter = container.begin(); iter != container.end();)
{
auto& cur = *iter;
++iter;
if (!detail::visit(cur, cb, functor, iter == container.end()))
return false;
}
}
return cb(functor, container, {visitor_info::container_entity_exit, last_child});
}
}
bool detail::visit(const cpp_entity& e, detail::visitor_callback_t cb, void* functor,
bool last_child)
{
switch (e.kind())
{
case cpp_entity_kind::file_t:
return handle_container<cpp_file>(e, cb, functor, last_child);
case cpp_entity_kind::language_linkage_t:
return handle_container<cpp_language_linkage>(e, cb, functor, last_child);
case cpp_entity_kind::namespace_t:
return handle_container<cpp_namespace>(e, cb, functor, last_child);
case cpp_entity_kind::enum_t:
return handle_container<cpp_enum>(e, cb, functor, last_child);
case cpp_entity_kind::class_t:
return handle_container<cpp_class>(e, cb, functor, last_child);
case cpp_entity_kind::alias_template_t:
return handle_container<cpp_alias_template>(e, cb, functor, last_child);
case cpp_entity_kind::variable_template_t:
return handle_container<cpp_variable_template>(e, cb, functor, last_child);
case cpp_entity_kind::function_template_t:
return handle_container<cpp_function_template>(e, cb, functor, last_child);
case cpp_entity_kind::function_template_specialization_t:
return handle_container<cpp_function_template_specialization>(e, cb, functor, last_child);
case cpp_entity_kind::class_template_t:
return handle_container<cpp_class_template>(e, cb, functor, last_child);
case cpp_entity_kind::class_template_specialization_t:
return handle_container<cpp_class_template_specialization>(e, cb, functor, last_child);
case cpp_entity_kind::macro_definition_t:
case cpp_entity_kind::include_directive_t:
case cpp_entity_kind::namespace_alias_t:
case cpp_entity_kind::using_directive_t:
case cpp_entity_kind::using_declaration_t:
case cpp_entity_kind::type_alias_t:
case cpp_entity_kind::enum_value_t:
case cpp_entity_kind::access_specifier_t:
case cpp_entity_kind::base_class_t:
case cpp_entity_kind::variable_t:
case cpp_entity_kind::member_variable_t:
case cpp_entity_kind::bitfield_t:
case cpp_entity_kind::function_parameter_t:
case cpp_entity_kind::function_t:
case cpp_entity_kind::member_function_t:
case cpp_entity_kind::conversion_op_t:
case cpp_entity_kind::constructor_t:
case cpp_entity_kind::destructor_t:
case cpp_entity_kind::friend_t:
case cpp_entity_kind::template_type_parameter_t:
case cpp_entity_kind::non_type_template_parameter_t:
case cpp_entity_kind::template_template_parameter_t:
case cpp_entity_kind::static_assert_t:
case cpp_entity_kind::unexposed_t:
return cb(functor, e, {visitor_info::leaf_entity, last_child});
case cpp_entity_kind::count:
break;
}
DEBUG_UNREACHABLE(detail::assert_handler{});
return true;
}