Currentlty. Я работаю над проектом по выводу информации о классе для кода c ++ с помощью libclang. И есть некоторый печальный опыт в отношении классификаторов типов: const, volatile, &, && и их комбинации. Вот пример кода для вывода типа параметров функции удаления.
auto _cur_cursor = one_node->get_cursor();
auto _cur_type = clang_getCursorType(_cur_cursor);
auto is_const = clang_isConstQualifiedType(_cur_type);
auto is_refer = clang_Type_getCXXRefQualifier(_cur_type);
auto is_volatile = clang_isVolatileQualifiedType(_cur_type);
auto is_pointer = clang_getPointeeType(_cur_type);
auto is_const_ref = false;
if (is_pointer.kind)
{
is_const_ref = clang_isConstQualifiedType(is_pointer);
}
the_logger.info("get parameter name {} type {} is_const {} is_reference {} is volatile {} is_pointer {} is_const_ref {}", utils::to_string(clang_getCursorSpelling(_cur_cursor)), utils::to_string(clang_getTypeSpelling(_cur_type)), is_const, is_refer, is_volatile, utils::to_string(is_pointer), is_const_ref);
мой тест ниже
int test_1(const std::vector<std::unordered_map<int, int>>& a, std::vector<int>&& b, std::vector<std::uint32_t>& c)
{
return b.size();
}
и вывод для этой функции
[2019-06-01 23:14:18.171] [meta] [info] get parameter name a type const std::vector<std::unordered_map<int, int> > & is_const 0 is_reference 0 is volatile 0 is_pointer const std::vector<std::unordered_map<int, int> > is_const_ref true
[2019-06-01 23:14:18.171] [meta] [info] get parameter name b type std::vector<int> && is_const 0 is_reference 0 is volatile 0 is_pointer std::vector<int> is_const_ref false
[2019-06-01 23:14:18.171] [meta] [info] get parameter name c type std::vector<std::uint32_t> & is_const 0 is_reference 0 is volatile 0 is_pointer std::vector<std::uint32_t> is_const_ref false
И вот эти наблюдения, которые мне кажутся подозрительными:
- clang_isConstQualifiedType возвращает true только для const T, а не для const T (&, *, &&)
- clang_Type_getCXXRefQualifier всегда false для любого типа
- clang_getPointeeType возвращает T для T (, &, &&), возвращает const T для const T (, &, &&)
Эти API, кажется, не действуют, как ожидалось. Любые идеи, чтобы получить правильный постоянный ссылочный статус изменяемого квалификатора для CXType?