Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang: custom attributes not visible in AST

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

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];

}

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?

like image 945
Jimbei Avatar asked Jul 15 '16 08:07

Jimbei


1 Answers

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.

like image 160
Jimbei Avatar answered Oct 15 '22 13:10

Jimbei