-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathdebug_helper.cpp
56 lines (45 loc) · 1.59 KB
/
debug_helper.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
// Copyright (C) 2017-2023 Jonathan Müller and cppast contributors
// SPDX-License-Identifier: MIT
#include "debug_helper.hpp"
#include <cstdio>
#include <mutex>
#include "cxtokenizer.hpp"
using namespace cppast;
detail::cxstring detail::get_display_name(const CXCursor& cur) noexcept
{
return cxstring(clang_getCursorDisplayName(cur));
}
detail::cxstring detail::get_cursor_kind_spelling(const CXCursor& cur) noexcept
{
return cxstring(clang_getCursorKindSpelling(clang_getCursorKind(cur)));
}
detail::cxstring detail::get_type_kind_spelling(const CXType& type) noexcept
{
return cxstring(clang_getTypeKindSpelling(type.kind));
}
namespace
{
std::mutex mtx;
}
void detail::print_cursor_info(const CXCursor& cur) noexcept
{
std::lock_guard<std::mutex> lock(mtx);
std::fprintf(stderr, "[debug] cursor '%s' (%s): %s\n", get_display_name(cur).c_str(),
cxstring(clang_getCursorKindSpelling(cur.kind)).c_str(),
cxstring(clang_getCursorUSR(cur)).c_str());
}
void detail::print_type_info(const CXType& type) noexcept
{
std::lock_guard<std::mutex> lock(mtx);
std::fprintf(stderr, "[debug] type '%s' (%s)\n", cxstring(clang_getTypeSpelling(type)).c_str(),
get_type_kind_spelling(type).c_str());
}
void detail::print_tokens(const CXTranslationUnit& tu, const CXFile& file,
const CXCursor& cur) noexcept
{
std::lock_guard<std::mutex> lock(mtx);
detail::cxtokenizer tokenizer(tu, file, cur);
for (auto& token : tokenizer)
std::fprintf(stderr, "%s ", token.c_str());
std::fputs("\n", stderr);
}