叮当声:AST中不可见的自定义属性 [英] clang: custom attributes not visible in AST

查看:80
本文介绍了叮当声: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 访问新的属性类,但是即使我将 let ASTNode = 1 行添加到属性中,该属性也不会显示在AST中定义.

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;

所以现在可以正常工作了.

So it works fine now.

这篇关于叮当声:AST中不可见的自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆