Attributes are stored in the AST only if they are already known by Clang, which are most of the GCC attributes and those defined by Clang. However, you can (kind of) add your own attributes using the hints from this link . This allows you to define any new attribute and then process it in ast as follows: For example, you took a line of code from the link above
__attribute__((annotate("async"))) uint c;
Then in your instance of RecursiveASTVisitor you can do the following:
bool MyRecursiveASTVisitor::VisitVarDecl(VarDecl* v) { v->dump(); if(v->hasAttrs()){ clang::AttrVec vec = v->getAttrs(); printf("%s\n",vec[0]->getSpelling()); printf("%s\n", Lexer::getSourceText( CharSourceRange::getTokenRange( vec[0]->getRange()), compiler.getSourceManager(), langOpts).str().c_str()); } return true; }
The first printf only prints "annotate", since it is the original attribute, to get the value that is interesting to use, we get the actual token from the lexer as a string.
Since we did not create a new attribute, we only get the attribute type append, but we can dig further and distinguish our new attribute. Not as elegant as the attribute just created (which may require changing the frog code itself), but it still works
source share