-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathlanguage_linkage_parser.cpp
38 lines (29 loc) · 1.27 KB
/
language_linkage_parser.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
// Copyright (C) 2017-2023 Jonathan Müller and cppast contributors
// SPDX-License-Identifier: MIT
#include "parse_functions.hpp"
#include <clang-c/Index.h>
#include <cppast/cpp_language_linkage.hpp>
#include "libclang_visitor.hpp"
using namespace cppast;
std::unique_ptr<cpp_entity> detail::try_parse_cpp_language_linkage(const parse_context& context,
const CXCursor& cur)
{
DEBUG_ASSERT(cur.kind == CXCursor_UnexposedDecl,
detail::assert_handler{}); // not exposed currently
detail::cxtokenizer tokenizer(context.tu, context.file, cur);
detail::cxtoken_stream stream(tokenizer, cur);
// extern <name> ...
if (!detail::skip_if(stream, "extern"))
return nullptr;
// unexposed variable starting with extern - must be a language linkage
// (function, variables are not unexposed)
auto& name = stream.get().value();
auto builder = cpp_language_linkage::builder(name.c_str());
context.comments.match(builder.get(), cur);
detail::visit_children(cur, [&](const CXCursor& child) {
auto entity = parse_entity(context, &builder.get(), child);
if (entity)
builder.add_child(std::move(entity));
});
return builder.finish();
}