#include "clang/Index/IndexProvider.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/DenseMap.h"
#include <map>
namespace clang {
+ class ASTContext;
namespace idx {
class Program;
class Indexer : public IndexProvider {
public:
typedef llvm::SmallPtrSet<TranslationUnit *, 4> TUSetTy;
+ typedef llvm::DenseMap<ASTContext *, TranslationUnit *> CtxTUMapTy;
typedef std::map<Entity, TUSetTy> MapTy;
explicit Indexer(Program &prog) : Prog(prog) { }
return Entity(D);
// FIXME: Only works for DeclarationNames that are identifiers.
+ // Treats other DeclarationNames as internal Decls for now..
DeclarationName Name = D->getDeclName();
if (!Name.isIdentifier())
- return Entity();
+ return Entity(D);
IdentifierInfo *II = Name.getAsIdentifierInfo();
if (!II)
#include "clang/Index/Entity.h"
#include "clang/Index/Handlers.h"
#include "clang/Index/TranslationUnit.h"
+#include "clang/AST/DeclBase.h"
using namespace clang;
using namespace idx;
void Indexer::IndexAST(TranslationUnit *TU) {
assert(TU && "Passed null TranslationUnit");
+ CtxTUMap[&TU->getASTContext()] = TU;
EntityIndexer Idx(TU, Map);
Prog.FindEntities(TU->getASTContext(), Idx);
}
void Indexer::GetTranslationUnitsFor(Entity Ent,
TranslationUnitHandler &Handler) {
assert(Ent.isValid() && "Expected valid Entity");
- assert(!Ent.isInternalToTU() &&
- "Expected an Entity visible outside of its translation unit");
+
+ if (Ent.isInternalToTU()) {
+ Decl *D = Ent.getInternalDecl();
+ CtxTUMapTy::iterator I = CtxTUMap.find(&D->getASTContext());
+ if (I != CtxTUMap.end())
+ Handler.Handle(I->second);
+ return;
+ }
MapTy::iterator I = Map.find(Ent);
if (I == Map.end())