зеркало из https://github.com/microsoft/clang-1.git
Keep track of type references in DeclReferenceMap.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83111 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
09d8a957d3
Коммит
b11688485a
|
@ -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
|
||||
|
|
|
@ -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
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
Загрузка…
Ссылка в новой задаче