#include "clang/AST/DeclVisitor.h"
#include "clang/AST/StmtVisitor.h"
+#include "clang/AST/TypeLoc.h"
namespace clang {
/// \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) { }
typedef ASTVisitor<ImplClass> Base;
typedef DeclVisitor<ImplClass> BaseDeclVisitor;
typedef StmtVisitor<ImplClass> BaseStmtVisitor;
+ typedef TypeLocVisitor<ImplClass> BaseTypeLocVisitor;
using BaseStmtVisitor::Visit;
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);
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
void VisitDeclRefExpr(DeclRefExpr *Node);
void VisitMemberExpr(MemberExpr *Node);
void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
+
+ void VisitTypedefLoc(TypedefLoc TL);
+ void VisitObjCInterfaceLoc(ObjCInterfaceLoc TL);
};
} // anonymous namespace
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
//===----------------------------------------------------------------------===//