class __attribute__((annotate("some_important_string"))) Foo {
public:
void do_something();
};
I want to find all the public methods in a class with a specific annotation. I have a matcher set up to get classes with annotations:
Matcher.addMatcher(cxxRecordDecl(anyOf(isStruct(), isClass()),
hasAttr(attr::Annotate)).bind("class")
but there doesn't seem to be any way to match on the exact string of the annotation.
So, in my MatchCallback::run method, I check for the attribute string by getting the attributes, dyn_cast
ing to AnnotateAttr
and checking the annotation string ref:
auto &attrs = decl->getAttrs();
...
auto attribute_attr = dyn_cast<AnnotateAttr>(attr);
auto string_ref = attribute_attr->getAnnotation();
but now I'd really rather do more matching, than AST tree traversal. My understanding is the matchers are more stable than the tree traversal functions, and they seem to be more straight forward, too.
So is there any way to go back to using matchers after filtering the class for an annotation string?
I am currently filtering based on the following code and it works ok, but it's not how I'd like to do it:
if (method->getAccess() != AS_public) {
if (PRINT_SKIPPED_EXPORT_REASONS) printf("%s**%s is not public, skipping\n", indentation.c_str(), method_name.c_str());
return;
}
if (method->isOverloadedOperator()) {
if (PRINT_SKIPPED_EXPORT_REASONS) printf("%s**skipping overloaded operator %s\n", indentation.c_str(), method_name.c_str());
return;
}
if (dyn_cast<CXXConstructorDecl>(method)) {
if (PRINT_SKIPPED_EXPORT_REASONS) printf("%s**skipping constructor %s\n", indentation.c_str(), method_name.c_str());
return;
}
if (dyn_cast<CXXDestructorDecl>(method)) {
if (PRINT_SKIPPED_EXPORT_REASONS) printf("%s**skipping destructor %s\n", indentation.c_str(), method_name.c_str());
return;
}
if (method->isPure()) {
assert(method->isVirtual());
if (PRINT_SKIPPED_EXPORT_REASONS) printf("%s**skipping pure virtual %s\n", indentation.c_str(), method_name.c_str());
return;
}