clang:自定义属性在 AST 中不可见 [英] clang: custom attributes not visible in AST
问题描述
我在 clang 中实现了一个自定义属性,如官方手册中所述:http://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute
i implemented a custom attribute in clang as described in the official manual: http://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute
所以我在 Attr.td 中添加了以下代码:
So i added the following Code to Attr.td:
def MyAttr: InheritableAttr {
let Spellings = [GNU<"my_attr">, CXX11<"me", "my_attr">, GCC<"my_attr">, Declspec<"my_attr">];
let Subjects = SubjectList<[Var, Function, CXXRecord]>;
let Documentation = [MyAttrDocs];
}
以及AttrDocs.td 的文档.重建 clang 后,它显然知道该属性,因为我在使用它时没有收到未知属性警告.我什至可以使用 libtooling 访问新的属性类,但是该属性没有显示在 AST 中,即使我将 let ASTNode = 1
行添加到该属性中定义.
and the documentation to AttrDocs.td. After rebuilding clang, it obviously knows the attribute because i don't get an unknown attribute warning when using it. I can even access the new attribute class with libtooling, but the attribute doesn't show up in the AST, even if i add the line let ASTNode = 1
to the attribute definition.
还有什么我需要考虑的或者可能是什么问题吗?
Is there something else i need to consider or what could be the problem?
推荐答案
不幸的是,这是我的错,缺少的步骤在手册样板"部分中有描述:我只需要在 SemaDeclAttr 中实现属性的语义处理.cpp 添加一个新案例:
Unfortunately this was my fault, the missing step is described in the manual in section "Boilerplate": i just had to implement the semantic processing of the attribute in SemaDeclAttr.cpp by adding a new case:
case AttributeList::AT_MyAttr:
handleSimpleAttribute<MyAttrAttr>(S, D, Attr);
break;
所以它现在工作正常.
这篇关于clang:自定义属性在 AST 中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!