aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-09-29 21:26:53 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-09-29 21:26:53 +0000
commitb11688485a696a31136bb2e63fc8739c945178a3 (patch)
tree07b2d06de45b644a379ecea6be0c95807f49143a /lib
parent09d8a957d3708d42fa26c1a024a36a4ae460d009 (diff)
Keep track of type references in DeclReferenceMap.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83111 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Index/ASTVisitor.h33
-rw-r--r--lib/Index/DeclReferenceMap.cpp13
2 files changed, 45 insertions, 1 deletions
diff --git a/lib/Index/ASTVisitor.h b/lib/Index/ASTVisitor.h
index fe0db40d20..4da1888095 100644
--- a/lib/Index/ASTVisitor.h
+++ b/lib/Index/ASTVisitor.h
@@ -16,6 +16,7 @@
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/StmtVisitor.h"
+#include "clang/AST/TypeLoc.h"
namespace clang {
@@ -24,7 +25,8 @@ namespace idx {
/// \brief Traverses the full AST, both Decls and Stmts.
template<typename ImplClass>
class ASTVisitor : public DeclVisitor<ImplClass>,
- public StmtVisitor<ImplClass> {
+ public StmtVisitor<ImplClass>,
+ public TypeLocVisitor<ImplClass> {
public:
ASTVisitor() : CurrentDecl(0) { }
@@ -33,6 +35,7 @@ public:
typedef ASTVisitor<ImplClass> Base;
typedef DeclVisitor<ImplClass> BaseDeclVisitor;
typedef StmtVisitor<ImplClass> BaseStmtVisitor;
+ typedef TypeLocVisitor<ImplClass> BaseTypeLocVisitor;
using BaseStmtVisitor::Visit;
@@ -46,6 +49,12 @@ public:
BaseDeclVisitor::Visit(D);
CurrentDecl = PrevDecl;
}
+
+ void VisitDeclaratorDecl(DeclaratorDecl *D) {
+ BaseDeclVisitor::VisitDeclaratorDecl(D);
+ if (DeclaratorInfo *DInfo = D->getDeclaratorInfo())
+ Visit(DInfo->getTypeLoc());
+ }
void VisitFunctionDecl(FunctionDecl *D) {
BaseDeclVisitor::VisitFunctionDecl(D);
@@ -104,6 +113,28 @@ public:
if (*I)
Visit(*I);
}
+
+ //===--------------------------------------------------------------------===//
+ // TypeLocVisitor
+ //===--------------------------------------------------------------------===//
+
+ void Visit(TypeLoc TL) {
+ for (; TL; TL = TL.getNextTypeLoc())
+ BaseTypeLocVisitor::Visit(TL);
+ }
+
+ void VisitArrayLoc(ArrayLoc TL) {
+ BaseTypeLocVisitor::VisitArrayLoc(TL);
+ if (TL.getSizeExpr())
+ Visit(TL.getSizeExpr());
+ }
+
+ void VisitFunctionLoc(FunctionLoc TL) {
+ BaseTypeLocVisitor::VisitFunctionLoc(TL);
+ for (unsigned i = 0; i != TL.getNumArgs(); ++i)
+ Visit(TL.getArg(i));
+ }
+
};
} // namespace idx
diff --git a/lib/Index/DeclReferenceMap.cpp b/lib/Index/DeclReferenceMap.cpp
index 0aee2a40ec..0e48a369d5 100644
--- a/lib/Index/DeclReferenceMap.cpp
+++ b/lib/Index/DeclReferenceMap.cpp
@@ -30,6 +30,9 @@ public:
void VisitDeclRefExpr(DeclRefExpr *Node);
void VisitMemberExpr(MemberExpr *Node);
void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
+
+ void VisitTypedefLoc(TypedefLoc TL);
+ void VisitObjCInterfaceLoc(ObjCInterfaceLoc TL);
};
} // anonymous namespace
@@ -52,6 +55,16 @@ 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
//===----------------------------------------------------------------------===//