-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathcpp_entity.cpp
72 lines (61 loc) · 2.14 KB
/
cpp_entity.cpp
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
// Copyright (C) 2017-2023 Jonathan Müller and cppast contributors
// SPDX-License-Identifier: MIT
#include <cppast/cpp_entity.hpp>
#include <cppast/cpp_entity_index.hpp>
#include <cppast/cpp_entity_kind.hpp>
#include <cppast/cpp_template.hpp>
using namespace cppast;
cpp_scope_name::cpp_scope_name(type_safe::object_ref<const cpp_entity> entity) : entity_(entity)
{
if (cppast::is_templated(*entity))
{
auto& templ = static_cast<const cpp_template&>(entity->parent().value());
if (!templ.parameters().empty())
templ_ = type_safe::ref(templ);
}
else if (is_template(entity->kind()))
{
auto& templ = static_cast<const cpp_template&>(*entity);
if (!templ.parameters().empty())
templ_ = type_safe::ref(templ);
}
}
const std::string& cpp_scope_name::name() const noexcept
{
return entity_->name();
}
detail::iteratable_intrusive_list<cpp_template_parameter> cpp_scope_name::template_parameters()
const noexcept
{
DEBUG_ASSERT(is_templated(), detail::precondition_error_handler{});
return templ_.value().parameters();
}
cpp_entity_kind cpp_unexposed_entity::kind() noexcept
{
return cpp_entity_kind::unexposed_t;
}
std::unique_ptr<cpp_entity> cpp_unexposed_entity::build(const cpp_entity_index& index,
cpp_entity_id id, std::string name,
cpp_token_string spelling)
{
std::unique_ptr<cpp_entity> result(
new cpp_unexposed_entity(std::move(name), std::move(spelling)));
index.register_forward_declaration(id, type_safe::ref(*result));
return result;
}
std::unique_ptr<cpp_entity> cpp_unexposed_entity::build(cpp_token_string spelling)
{
return std::unique_ptr<cpp_entity>(new cpp_unexposed_entity("", std::move(spelling)));
}
cpp_entity_kind cpp_unexposed_entity::do_get_entity_kind() const noexcept
{
return kind();
}
bool cppast::is_templated(const cpp_entity& e) noexcept
{
if (!e.parent())
return false;
else if (!is_template(e.parent().value().kind()))
return false;
return e.parent().value().name() == e.name();
}