-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thanks for writing this, it's very impressive! #1
Comments
I'm not some kind of expert on libclang, I had not heard of |
Ahh got it -- I am in much the same boat. The documentation I agree is terrible. You might find this useful though, this is the a class where you declare which kinds of nodes you want to visit and it extends https://clang.llvm.org/docs/RAVFrontendAction.html class FindNamedClassVisitor
: public RecursiveASTVisitor<FindNamedClassVisitor> {
public:
explicit FindNamedClassVisitor(ASTContext *Context)
: Context(Context) {}
bool VisitCXXRecordDecl(CXXRecordDecl *Declaration) {
if (Declaration->getQualifiedNameAsString() == "n::m::C") {
FullSourceLoc FullLocation = Context->getFullLoc(Declaration->getBeginLoc());
if (FullLocation.isValid())
llvm::outs() << "Found declaration at "
<< FullLocation.getSpellingLineNumber() << ":"
<< FullLocation.getSpellingColumnNumber() << "\n";
}
return true;
}
private:
ASTContext *Context;
};
class FindNamedClassConsumer : public clang::ASTConsumer {
public:
explicit FindNamedClassConsumer(ASTContext *Context)
: Visitor(Context) {}
virtual void HandleTranslationUnit(clang::ASTContext &Context) {
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
}
private:
FindNamedClassVisitor Visitor;
}; |
I have just built the lib and seen the generated output in
build/examples/geom
, this is really impressive!The code is fairly concise + easy to read as well 😃
One question I had from browsing the source -- I notice you use an
ASTConsumer
instead of aRecursiveASTVisitor
. Is this easier?Have been investigating doing some codegen from C++ headers and would be curious to hear your opinion
The text was updated successfully, but these errors were encountered: