Added basic variadic template class support

This commit is contained in:
Bartek Kryza
2021-03-13 18:22:14 +01:00
parent 86945b11d4
commit ca9927ecc9
7 changed files with 109 additions and 3 deletions

View File

@@ -234,8 +234,32 @@ public:
return clang_getSpecializedCursorTemplate(m_cursor);
}
CXTranslationUnit translation_unit() const
{
return clang_Cursor_getTranslationUnit(m_cursor);
}
std::string usr() const { return to_string(clang_getCursorUSR(m_cursor)); }
CXSourceRange extent() const { return clang_getCursorExtent(m_cursor); }
std::vector<std::string> tokenize() const
{
auto range = extent();
std::vector<std::string> res;
CXToken *toks;
unsigned toks_count{0};
auto tu = translation_unit();
clang_tokenize(tu, range, &toks, &toks_count);
for (int i = 0; i < toks_count; i++) {
res.push_back(to_string(clang_getTokenSpelling(tu, toks[i])));
}
return res;
}
const CXCursor &get() const { return m_cursor; }
private:

View File

@@ -110,6 +110,7 @@ struct class_template {
std::string name;
std::string type;
std::string default_value;
bool is_variadic{false};
};
class class_ : public element {

View File

@@ -330,12 +330,16 @@ static enum CXChildVisitResult class_visitor(
ret = CXChildVisit_Continue;
break;
case CXCursor_TemplateTypeParameter: {
spdlog::info("Found template type parameter: {}: {}",
cursor.spelling(), cursor.type());
const auto &tokens = cursor.tokenize();
spdlog::info("Found template type parameter: {}: {}, [{}]", cursor,
cursor.type(), fmt::join(tokens, ", "));
class_template ct;
ct.type = "";
ct.name = cursor.spelling();
ct.default_value = "";
ct.is_variadic = tokens.size() > 2 && tokens[1] == "...";
ct.name = cursor.spelling();
if (ct.is_variadic)
ct.name += "...";
ctx->element.templates.emplace_back(std::move(ct));
ret = CXChildVisit_Continue;