Hi Clang list,
I am implementing a RecursiveASTVisitor so I can rely on a preorder traversal.
In some of the Visit* callbacks I would like to pass some information downwards
and do something like this:
bool VisitFunctionDecl(const FunctionDecl *d) {
…
d->getBody()->attachToContext(myAdditionalData);
…
}
So that I can access it when the callback for the body is called:
bool VisitCompoundStmt(const CompoundStmt *n) {
…
MyAdditionalData *myData = n->getFromContext();
…
}
Right now I am using a std::map with the pointer as key, i.e.
bool VisitFunctionDecl(const FunctionDecl *d) {
…
myMap[d->getBody()] = myAdditionalData;
…
}
and then
bool VisitCompoundStmt(const CompoundStmt *n) {
…
MyAdditionalData *myData = myMap[n];
…
}
That works, but it does not seem to be the right thing.
Is there a way to attach additional information to AST nodes?
Or should I approach that in a completely different way?
Thank you and best regards,
Benedikt