diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-29 23:40:14 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-29 23:40:14 +0000 |
commit | 91d3df0b53be36dfaeaf46521c430420a8b9646c (patch) | |
tree | 37bf1762b439c2a849228231ff18ee9f27a2c4c8 /clang/lib/Index/Analyzer.cpp | |
parent | a82e8848ee3a484e1cb1a51d21f5bed8eee88d9a (diff) | |
download | bcm5719-llvm-91d3df0b53be36dfaeaf46521c430420a8b9646c.tar.gz bcm5719-llvm-91d3df0b53be36dfaeaf46521c430420a8b9646c.zip |
-Introduce the idx::Analyzer class used for getting indexing information, like finding
references of a declaration across translation units.
-Modify the index-test tool to use it.
llvm-svn: 77536
Diffstat (limited to 'clang/lib/Index/Analyzer.cpp')
-rw-r--r-- | clang/lib/Index/Analyzer.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/clang/lib/Index/Analyzer.cpp b/clang/lib/Index/Analyzer.cpp new file mode 100644 index 00000000000..bd1d62c6687 --- /dev/null +++ b/clang/lib/Index/Analyzer.cpp @@ -0,0 +1,104 @@ +//===--- Analyzer.cpp - Analysis for indexing information -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the Analyzer interface. +// +//===----------------------------------------------------------------------===// + +#include "clang/Index/Analyzer.h" +#include "clang/Index/Entity.h" +#include "clang/Index/TranslationUnit.h" +#include "clang/Index/Handlers.h" +#include "clang/Index/ASTLocation.h" +#include "clang/Index/DeclReferenceMap.h" +#include "clang/Index/IndexProvider.h" +#include "clang/AST/Decl.h" +#include "llvm/Support/Compiler.h" +using namespace clang; +using namespace idx; + +namespace { + +//===----------------------------------------------------------------------===// +// DeclEntityAnalyzer Implementation +//===----------------------------------------------------------------------===// + +class VISIBILITY_HIDDEN DeclEntityAnalyzer : public TranslationUnitHandler { + Entity Ent; + TULocationHandler &TULocHandler; + +public: + DeclEntityAnalyzer(Entity ent, TULocationHandler &handler) + : Ent(ent), TULocHandler(handler) { } + + virtual void Handle(TranslationUnit *TU) { + assert(TU && "Passed null translation unit"); + + Decl *D = Ent.getDecl(TU->getASTContext()); + assert(D && "Couldn't resolve Entity"); + + for (Decl::redecl_iterator I = D->redecls_begin(), + E = D->redecls_end(); I != E; ++I) + TULocHandler.Handle(TULocation(TU, ASTLocation(*I))); + } +}; + +//===----------------------------------------------------------------------===// +// RefEntityAnalyzer Implementation +//===----------------------------------------------------------------------===// + +class VISIBILITY_HIDDEN RefEntityAnalyzer : public TranslationUnitHandler { + Entity Ent; + TULocationHandler &TULocHandler; + +public: + RefEntityAnalyzer(Entity ent, TULocationHandler &handler) + : Ent(ent), TULocHandler(handler) { } + + virtual void Handle(TranslationUnit *TU) { + assert(TU && "Passed null translation unit"); + + Decl *D = Ent.getDecl(TU->getASTContext()); + assert(D && "Couldn't resolve Entity"); + NamedDecl *ND = dyn_cast<NamedDecl>(D); + if (!ND) + return; + + DeclReferenceMap &RefMap = TU->getDeclReferenceMap(); + for (DeclReferenceMap::astlocation_iterator + I = RefMap.refs_begin(ND), E = RefMap.refs_end(ND); I != E; ++I) + TULocHandler.Handle(TULocation(TU, ASTLocation(*I))); + } +}; + +} // end anonymous namespace + +//===----------------------------------------------------------------------===// +// Analyzer Implementation +//===----------------------------------------------------------------------===// + +void Analyzer::FindDeclarations(Decl *D, TULocationHandler &Handler) { + assert(D && "Passed null declaration"); + Entity Ent = Entity::get(D, Prog); + if (Ent.isInvalid()) + return; + + DeclEntityAnalyzer DEA(Ent, Handler); + Idxer.GetTranslationUnitsFor(Ent, DEA); +} + +void Analyzer::FindReferences(Decl *D, TULocationHandler &Handler) { + assert(D && "Passed null declaration"); + Entity Ent = Entity::get(D, Prog); + if (Ent.isInvalid()) + return; + + RefEntityAnalyzer REA(Ent, Handler); + Idxer.GetTranslationUnitsFor(Ent, REA); +} |