From 9092c3e0fa01f3139b016d05d267a89e3b07747a Mon Sep 17 00:00:00 2001 From: rdivacky Date: Wed, 14 Oct 2009 18:03:49 +0000 Subject: Update clang to r84119. --- lib/Index/DeclReferenceMap.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 lib/Index/DeclReferenceMap.cpp (limited to 'lib/Index/DeclReferenceMap.cpp') diff --git a/lib/Index/DeclReferenceMap.cpp b/lib/Index/DeclReferenceMap.cpp new file mode 100644 index 0000000..0e48a36 --- /dev/null +++ b/lib/Index/DeclReferenceMap.cpp @@ -0,0 +1,91 @@ +//===--- DeclReferenceMap.cpp - Map Decls to their references -------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// DeclReferenceMap creates a mapping from Decls to the ASTLocations that +// reference them. +// +//===----------------------------------------------------------------------===// + +#include "clang/Index/DeclReferenceMap.h" +#include "clang/Index/ASTLocation.h" +#include "ASTVisitor.h" +#include "llvm/Support/Compiler.h" +using namespace clang; +using namespace idx; + +namespace { + +class VISIBILITY_HIDDEN RefMapper : public ASTVisitor { + DeclReferenceMap::MapTy ⤅ + +public: + RefMapper(DeclReferenceMap::MapTy &map) : Map(map) { } + + void VisitDeclRefExpr(DeclRefExpr *Node); + void VisitMemberExpr(MemberExpr *Node); + void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node); + + void VisitTypedefLoc(TypedefLoc TL); + void VisitObjCInterfaceLoc(ObjCInterfaceLoc TL); +}; + +} // anonymous namespace + +//===----------------------------------------------------------------------===// +// RefMapper Implementation +//===----------------------------------------------------------------------===// + +void RefMapper::VisitDeclRefExpr(DeclRefExpr *Node) { + NamedDecl *PrimD = cast(Node->getDecl()->getCanonicalDecl()); + Map.insert(std::make_pair(PrimD, ASTLocation(CurrentDecl, Node))); +} + +void RefMapper::VisitMemberExpr(MemberExpr *Node) { + NamedDecl *PrimD = cast(Node->getMemberDecl()->getCanonicalDecl()); + Map.insert(std::make_pair(PrimD, ASTLocation(CurrentDecl, Node))); +} + +void RefMapper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { + Map.insert(std::make_pair(Node->getDecl(), ASTLocation(CurrentDecl, Node))); +} + +void RefMapper::VisitTypedefLoc(TypedefLoc TL) { + NamedDecl *ND = TL.getTypedefDecl(); + Map.insert(std::make_pair(ND, ASTLocation(CurrentDecl, ND, TL.getNameLoc()))); +} + +void RefMapper::VisitObjCInterfaceLoc(ObjCInterfaceLoc TL) { + NamedDecl *ND = TL.getIFaceDecl(); + Map.insert(std::make_pair(ND, ASTLocation(CurrentDecl, ND, TL.getNameLoc()))); +} + +//===----------------------------------------------------------------------===// +// DeclReferenceMap Implementation +//===----------------------------------------------------------------------===// + +DeclReferenceMap::DeclReferenceMap(ASTContext &Ctx) { + RefMapper(Map).Visit(Ctx.getTranslationUnitDecl()); +} + +DeclReferenceMap::astlocation_iterator +DeclReferenceMap::refs_begin(NamedDecl *D) const { + NamedDecl *Prim = cast(D->getCanonicalDecl()); + return astlocation_iterator(Map.lower_bound(Prim)); +} + +DeclReferenceMap::astlocation_iterator +DeclReferenceMap::refs_end(NamedDecl *D) const { + NamedDecl *Prim = cast(D->getCanonicalDecl()); + return astlocation_iterator(Map.upper_bound(Prim)); +} + +bool DeclReferenceMap::refs_empty(NamedDecl *D) const { + NamedDecl *Prim = cast(D->getCanonicalDecl()); + return refs_begin(Prim) == refs_end(Prim); +} -- cgit v1.1