C++:源代码中的元数据信息。看透AST

C++ : meta-data information in source code. To see through AST

解析后,我想获取源代码字段或方法的元数据。

这样做的目的是收集解析后的源码信息

在java中,我使用了注解。 解析后,我在 class、字段或方法上找到了用户定义的注释。 下面的代码是示例。

@BizObject //By this annotation I could understand this class is related with bissness.
public class biz ... {
    @DI //this field needs Dependency Injection.
    public Logger logger;
}

通过解析,我想收集源的用户指定的元信息。 用户如何在源代码上编写元数据??喜欢 java 注释。

我知道在 C++ 中没有用于此目的的直接属性。 我只是想知道如何使用其他东西间接标记元数据。

自我回复。

我使用 属性说明符解决了这个问题。 类似于Java的注解

http://en.cppreference.com/w/cpp/language/attributes http://www.codesynthesis.com/~boris/blog/2012/04/18/cxx11-generalized-attributes/ https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html

通过使用属性说明符和 CDT 解析器,我可以获得元数据相关语法的节点。

CDT 解析器支持 GNU。