[cfe-commits] r83111 - in /cfe/trunk/lib/Index: ASTVisitor.h DeclReferenceMap.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Tue Sep 29 14:26:53 PDT 2009
Author: akirtzidis
Date: Tue Sep 29 16:26:53 2009
New Revision: 83111
URL: http://llvm.org/viewvc/llvm-project?rev=83111&view=rev
Log:
Keep track of type references in DeclReferenceMap.
Modified:
cfe/trunk/lib/Index/ASTVisitor.h
cfe/trunk/lib/Index/DeclReferenceMap.cpp
Modified: cfe/trunk/lib/Index/ASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/ASTVisitor.h?rev=83111&r1=83110&r2=83111&view=diff
==============================================================================
--- cfe/trunk/lib/Index/ASTVisitor.h (original)
+++ cfe/trunk/lib/Index/ASTVisitor.h Tue Sep 29 16:26:53 2009
@@ -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 @@
/// \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 @@
typedef ASTVisitor<ImplClass> Base;
typedef DeclVisitor<ImplClass> BaseDeclVisitor;
typedef StmtVisitor<ImplClass> BaseStmtVisitor;
+ typedef TypeLocVisitor<ImplClass> BaseTypeLocVisitor;
using BaseStmtVisitor::Visit;
@@ -46,6 +49,12 @@
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 @@
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
Modified: cfe/trunk/lib/Index/DeclReferenceMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/DeclReferenceMap.cpp?rev=83111&r1=83110&r2=83111&view=diff
==============================================================================
--- cfe/trunk/lib/Index/DeclReferenceMap.cpp (original)
+++ cfe/trunk/lib/Index/DeclReferenceMap.cpp Tue Sep 29 16:26:53 2009
@@ -30,6 +30,9 @@
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 @@
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
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list