Repository navigation
Expand file tree
/
Copy pathnamespace_parser.cpp
More file actions
96 lines (79 loc) · 3.6 KB
/
Copy pathnamespace_parser.cpp
File metadata and controls
96 lines (79 loc) · 3.6 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
// Copyright (C) 2017-2021 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 "parse_functions.hpp"
#include <cppast/cpp_namespace.hpp>
using namespace cppast;
std::unique_ptr<cpp_entity> astdump_detail::parse_namespace(parse_context& context,
dom::object entity)
{
auto id = get_entity_id(context, entity);
auto name = [&] {
auto field = entity["name"].get_string();
if (field.error() != simdjson::error_code::NO_SUCH_FIELD)
return field.value();
else
return std::string_view("");
}();
auto inline_ = [&] {
auto field = entity["isInline"].get_bool();
if (field.error() != simdjson::error_code::NO_SUCH_FIELD)
return field.value();
else
return false;
}();
// TODO: Nested namespaces are not detected.
auto nested = false;
cpp_namespace::builder builder(std::string{name}, inline_, nested);
auto children = entity["inner"];
if (children.error() != simdjson::error_code::NO_SUCH_FIELD)
for (dom::object child : children.value())
{
auto e = astdump_detail::parse_entity(context, builder.get(), child);
if (e)
builder.add_child(std::move(e));
}
return builder.finish(*context.idx, id);
}
std::unique_ptr<cpp_entity> astdump_detail::parse_namespace_alias(parse_context& context,
dom::object entity)
{
auto id = get_entity_id(context, entity);
auto name = entity["name"].get_string().value();
auto target = entity["aliasedNamespace"].get_object().value();
auto target_id = get_entity_id(context, target);
// TODO: target name is a simplification and not the exact spelling as in the source.
auto target_name = target["name"].get_string().value();
auto result
= cpp_namespace_alias::build(*context.idx, id, std::string(name),
cpp_namespace_ref(target_id, std::string(target_name)));
handle_comment_child(context, *result, entity);
return result;
}
std::unique_ptr<cpp_entity> astdump_detail::parse_using_directive(parse_context& context,
dom::object entity)
{
auto target = entity["nominatedNamespace"].get_object().value();
auto target_id = get_entity_id(context, target);
// TODO: target name is a simplification and not the exact spelling as in the source.
auto target_name = target["name"].get_string().value();
auto result
= cpp_using_directive::build(cpp_namespace_ref(target_id, std::string(target_name)));
handle_comment_child(context, *result, entity);
return result;
}
std::unique_ptr<cpp_entity> astdump_detail::parse_using_declaration(parse_context& context,
dom::object entity)
{
auto name = entity["name"].get_string().value();
auto result = cpp_using_declaration::build(cpp_entity_ref({}, std::string(name)));
handle_comment_child(context, *result, entity);
context.last_using_decl = type_safe::ref(*result);
return result;
}
void astdump_detail::parse_shadow_using_declaration(parse_context& context, dom::object entity)
{
auto target = entity["target"].get_object().value();
auto target_id = get_entity_id(context, target);
context.last_using_decl.value().add_target(target_id);
}