4

给定一个具有不同命名空间的私有成员的类

namespace Test { namespace Cfg {
class ExampleApi {
public:
    ExampleApi() = default;
    int someVar;
};
}}

class Example {
public:
    Example() = default;
private:
   Test::Cfg::ExampleApi _cfgApi;
};

我正在尝试匹配 cxxConstructorExpr 的嵌套命名空间 Cfg,因为我的最终目标是从 ExampleApi 类中读取一些变量名

我可以_cfgApi通过执行以下操作来匹配:

cxxConstructExpr(hasType(asString("Test::Cfg::ExampleApi")))

但这还不够好,因为代码库会自动生成下面的类,Test::Cfg::*Api而且我还没有发现通配符谓词的用法。

我试着做一些事情:

nestedNameSpecificierLoc(hasPrefix(loc(specifiesNamespace(hasName("Test")))))

它匹配命名空间但不匹配嵌套命名空间。我认为在比赛发生后进行后期处理可能会产生太多噪音。

我正在和hasParentmatcher 一起玩,但到目前为止还没有运气。

所以我的问题是:我如何匹配嵌套命名空间以进行类初始化。

4

0 回答 0