From: Argyrios Kyrtzidis Date: Tue, 29 Sep 2009 21:26:53 +0000 (+0000) Subject: Keep track of type references in DeclReferenceMap. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b11688485a696a31136bb2e63fc8739c945178a3;p=clang Keep track of type references in DeclReferenceMap. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83111 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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 class ASTVisitor : public DeclVisitor, - public StmtVisitor { + public StmtVisitor, + public TypeLocVisitor { public: ASTVisitor() : CurrentDecl(0) { } @@ -33,6 +35,7 @@ public: typedef ASTVisitor Base; typedef DeclVisitor BaseDeclVisitor; typedef StmtVisitor BaseStmtVisitor; + typedef TypeLocVisitor 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 //===----------------------------------------------------------------------===//