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
以下是我怀疑的观察结果:

  • clang_isConstQualifiedType仅针对常量T返回true,而不针对常量T(&、*、&&)
  • clang_Type_getCXXRefQualifier对于任何类型都始终为false
  • clangg_getPointeeType为T(,&,&&&)返回T,为常数T(,&,&&)返回常数T
  • 这些api似乎不像预期的那样工作。有没有办法为CXType获得正确的const reference volatile限定符状态

  • 三,<代码>常量T(&,*,&&&)确实不是
    常量
    限定类型,它是指向
    常量
    限定类型的(引用、指针、r值引用)
    const T*const
    将是一个
    const
    限定指针,指向
    const
    限定类型
    T
    。 您可以查看更多详细信息

  • 来自Libblang的:

  • 检索函数或方法的ref限定符类型

    REF限定符返回C++函数或方法。对于其他类型或非C++声明,将返回CXRefQualifier\u None

    也许你在找别的东西。检查
    CXType::kind
    (代码段中的
    \cur\u type.kind
    )中的
    CXType\u指针
    CXType\u左值引用
    CXType\u右值引用


    我希望这是有用的。用叮当声愉快地进行黑客攻击

    经过半天的反复试验,我终于找到了这些api的真正含义。libclang应该提供类似cppreference的引用。