Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Clang AstMatcher获取所有构造函数初始值设定项?_Clang - Fatal编程技术网

如何使用Clang AstMatcher获取所有构造函数初始值设定项?

如何使用Clang AstMatcher获取所有构造函数初始值设定项?,clang,Clang,我是新来的clangastmatcher。我已经阅读了一些教程,并试图获得所有的c'tor初始化 输入代码 Person(char性别):m_性别(性别) ^^^^^^^^^^^^^^^^您应该尝试一下clang查询。使用它,您可以交互式地查询加载的AST,并轻松尝试不同的匹配器 无论如何,你想要的可能是: constructorDecl(forEachConstructorInitializer(ctorInitializer().bind(“ctorInitializer”)) 您应该尝试一

我是新来的
clangastmatcher
。我已经阅读了一些教程,并试图获得所有的c'tor初始化

输入代码
Person(char性别):m_性别(性别)

^^^^^^^^^^^^^^^^您应该尝试一下clang查询。使用它,您可以交互式地查询加载的AST,并轻松尝试不同的匹配器

无论如何,你想要的可能是: constructorDecl(forEachConstructorInitializer(ctorInitializer().bind(“ctorInitializer”))


您应该尝试一下clang查询。使用它,您可以交互式地查询加载的AST,并轻松尝试不同的匹配器

无论如何,你想要的可能是: constructorDecl(forEachConstructorInitializer(ctorInitializer().bind(“ctorInitializer”))


非常感谢。我注意到有这么一个好的工具
clangquery
(但在我的linux上编译失败)谢谢。我注意到有这么一个好的工具
clangquery
(但在我的linux上编译失败)
Person(char gender) : m_gender(gender)
                      ^^^^^^^^^^^^^^^^ <= I need to get those codes.
{
    ...
}
| |-CXXConstructorDecl 0x4678ad0 <line:9:5, col:45> col:5 Person 'void (char)'
| | |-ParmVarDecl 0x4678a10 <col:12, col:17> col:17 used gender 'char'
| | |-CXXCtorInitializer Field 0x4678dd0 'm_gender' 'int'
     ...
StatementMatcher CtorInitMatcher =
    clang::ast_matchers::ctorInitializer().bind("ctor_init");

...

class LoopPrinter : public MatchFinder::MatchCallback
{
public :
    virtual void run(const MatchFinder::MatchResult& result)
    {
        if (const clang::Stmt* stmt
            = result.Nodes.getNodeAs<clang::Stmt>("ctor_init"))
        {
            std::cout << "===== found: CXXCtorInit. =====" << std::endl;
            stmt->dump();
            std::cout << std::endl;
        }


    }
};
ex03.cc:27:60: error: conversion from ‘clang::ast_matchers::internal::Matcher<clang::CXXCtorInitializer>’ to non-scalar type ‘clang::ast_matchers::StatementMatcher {aka clang::ast_matchers::internal::Matcher<clang::Stmt>}’ requested
     clang::ast_matchers::ctorInitializer().bind("ctor_init");
clang-query> set output diag
clang-query> match constructorDecl(forEachConstructorInitializer(ctorInitializer().bind("ctorInitializer")))

Match #1:
/tmp/test.cpp:3:36: note: "ctorInitializer" binds here
    Person(char gender, int age) : m_gender(gender), m_age(age)
                                   ^~~~~~~~~~~~~~~~

Match #2:
/tmp/test.cpp:3:54: note: "ctorInitializer" binds here
    Person(char gender, int age) : m_gender(gender), m_age(age)
                                                     ^~~~~~~~~~

2 Matches.