libclang为类型限定符提供错误的结果 CurrnLty:我正在研究一个项目,用LIbCLANK转储C++代码的类信息。关于类型限定符,有一些痛苦的经历: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);
下面是我的测试用例libclang为类型限定符提供错误的结果 CurrnLty:我正在研究一个项目,用LIbCLANK转储C++代码的类信息。关于类型限定符,有一些痛苦的经历: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);,c++,clang,llvm-clang,libclang,C++,Clang,Llvm Clang,Libclang,下面是我的测试用例 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(); } int test_1(常量std::vector&a,std::vector&b,std::vector&c)
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();
}
int test_1(常量std::vector&a,std::vector&b,std::vector&c)
{
返回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
[2019-06-01 23:14:18.171][meta][info]获取参数名称类型const std::vector&is_const 0 is_reference 0 is volatile 0 is_pointer const std::vector is_const\u ref true
[2019-06-01 23:14:18.171][meta][info]获取参数名b类型std::vector&&is_const 0是_引用0是易失性0是_指针std::vector是_const_ref false
[2019-06-01 23:14:18.171][meta][info]获取参数名c类型std::vector&is_const 0 is_reference 0 is volatile 0 is_指针std::vector is_const_ref false
以下是我怀疑的观察结果:
常量
限定类型,它是指向常量
限定类型的(引用、指针、r值引用)const T*const
将是一个const
限定指针,指向const
限定类型T
。
您可以查看更多详细信息
REF限定符返回C++函数或方法。对于其他类型或非C++声明,将返回CXRefQualifier\u None
也许你在找别的东西。检查CXType::kind
(代码段中的\cur\u type.kind
)中的CXType\u指针
、CXType\u左值引用
和CXType\u右值引用
我希望这是有用的。用叮当声愉快地进行黑客攻击 经过半天的反复试验,我终于找到了这些api的真正含义。libclang应该提供类似cppreference的引用。