| 39 | #include <deque> |
| 40 | |
| 41 | struct BrowserASTVisitor : clang::RecursiveASTVisitor<BrowserASTVisitor> { |
| 42 | typedef clang::RecursiveASTVisitor<BrowserASTVisitor> Base; |
| 43 | Annotator &annotator; |
| 44 | clang::NamedDecl *currentContext = nullptr; |
| 45 | int recursionCount = 0; // Used to avoid a stack overflow |
| 46 | |
| 47 | struct : std::deque<clang::Expr *> { |
| 48 | clang::Expr *topExpr = 0; |
| 49 | Annotator::DeclType topType = Annotator::Use; |
| 50 | } expr_stack; |
| 51 | |
| 52 | BrowserASTVisitor(Annotator &R) : annotator(R) {} |
| 53 | |
| 54 | bool VisitTypedefNameDecl(clang::TypedefNameDecl *d) { |
| 55 | annotator.registerReference(d, d->getLocation(), Annotator::Typedef, Annotator::Declaration, |
| 56 | annotator.getTypeRef(d->getUnderlyingType())); |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | bool VisitTagDecl(clang::TagDecl *d) { |
| 61 | if(!shouldProcess(d)) return false; |
| 62 | if (d->isThisDeclarationADefinition()) { |
| 63 | if (clang::CXXRecordDecl* cxx = llvm::dyn_cast<clang::CXXRecordDecl>(d)) { |
| 64 | for (auto it = cxx->bases_begin(); it != cxx->bases_end(); ++it) { |
| 65 | if (! it->getType()->getAsCXXRecordDecl()) { |
| 66 | // std::cerr << " INHERITING but not from a CXXRecrod " << std::endl; |
| 67 | // it->getType().dump(); |
| 68 | // probably template type... FIXME |
| 69 | continue; |
| 70 | } |
| 71 | annotator.registerOverride(d, it->getType()->getAsCXXRecordDecl(), d->getLocation()); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | annotator.registerReference(d, d->getLocation(), Annotator::Type, |
| 76 | d->isThisDeclarationADefinition() ? Annotator::Definition : Annotator::Declaration); |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | bool VisitNamespaceDecl(clang::NamespaceDecl *d) { |
| 81 | annotator.registerReference(d, d->getLocation(), Annotator::Namespace, Annotator::Declaration); |
| 82 | return true; |
| 83 | } |
| 84 | bool VisitNamespaceAliasDecl(clang::NamespaceAliasDecl *d) { |
| 85 | annotator.registerReference(d, d->getLocation(), Annotator::Namespace, Annotator::Declaration); |
| 86 | annotator.registerReference(d, d->getTargetNameLoc() , Annotator::Namespace); |
| 87 | return true; |
| 88 | } |
| 89 | bool VisitFunctionDecl(clang::FunctionDecl *d) { |
| 90 | if(!shouldProcess(d)) return false; |
| 91 | std::string typeText; |
| 92 | { |
| 93 | llvm::raw_string_ostream typeTextStream(typeText); |
| 94 | |
| 95 | bool isConst = false; |
| 96 | if (clang::CXXMethodDecl *cxx = llvm::dyn_cast<clang::CXXMethodDecl>(d)) { |
| 97 | if (cxx->isStatic()) |
| 98 | typeTextStream << "static "; |
nothing calls this directly
no outgoing calls
no test coverage detected