1 //= CFGRecStmtDeclVisitor - Recursive visitor of CFG stmts/decls -*- C++ --*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the template class CFGRecStmtDeclVisitor, which extends
11 // CFGRecStmtVisitor by implementing (typed) visitation of decls.
13 // FIXME: This may not be fully complete. We currently explore only subtypes
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_CLANG_ANALYSIS_CFG_REC_STMT_DECL_VISITOR_H
18 #define LLVM_CLANG_ANALYSIS_CFG_REC_STMT_DECL_VISITOR_H
20 #include "clang/Analysis/Visitors/CFGRecStmtVisitor.h"
21 #include "clang/AST/Decl.h"
22 #include "clang/AST/DeclObjC.h"
23 #include "clang/AST/DeclCXX.h"
25 #define DISPATCH_CASE(CLASS) \
27 static_cast<ImplClass*>(this)->Visit##CLASS##Decl( \
28 static_cast<CLASS##Decl*>(D)); \
31 #define DEFAULT_DISPATCH(CLASS) void Visit##CLASS##Decl(CLASS##Decl *D) {}
32 #define DEFAULT_DISPATCH_VARDECL(CLASS) void Visit##CLASS##Decl(CLASS##Decl *D)\
33 { static_cast<ImplClass*>(this)->VisitVarDecl(D); }
37 template <typename ImplClass>
38 class CFGRecStmtDeclVisitor : public CFGRecStmtVisitor<ImplClass> {
41 void VisitDeclRefExpr(DeclRefExpr *DR) {
42 static_cast<ImplClass*>(this)->VisitDecl(DR->getDecl());
45 void VisitDeclStmt(DeclStmt *DS) {
46 for (DeclStmt::decl_iterator DI = DS->decl_begin(), DE = DS->decl_end();
49 static_cast<ImplClass*>(this)->VisitDecl(D);
50 // Visit the initializer.
51 if (VarDecl *VD = dyn_cast<VarDecl>(D))
52 if (Expr *I = VD->getInit())
53 static_cast<ImplClass*>(this)->Visit(I);
57 void VisitDecl(Decl *D) {
58 switch (D->getKind()) {
59 DISPATCH_CASE(Function)
60 DISPATCH_CASE(CXXMethod)
62 DISPATCH_CASE(ParmVar) // FIXME: (same)
63 DISPATCH_CASE(ImplicitParam)
64 DISPATCH_CASE(EnumConstant)
65 DISPATCH_CASE(Typedef)
66 DISPATCH_CASE(Record) // FIXME: Refine. VisitStructDecl?
67 DISPATCH_CASE(CXXRecord)
69 DISPATCH_CASE(UsingDirective)
72 llvm_unreachable("Subtype of ScopedDecl not handled.");
77 DEFAULT_DISPATCH(Function)
78 DEFAULT_DISPATCH(CXXMethod)
79 DEFAULT_DISPATCH_VARDECL(ParmVar)
80 DEFAULT_DISPATCH(ImplicitParam)
81 DEFAULT_DISPATCH(EnumConstant)
82 DEFAULT_DISPATCH(Typedef)
83 DEFAULT_DISPATCH(Record)
84 DEFAULT_DISPATCH(Enum)
85 DEFAULT_DISPATCH(ObjCInterface)
86 DEFAULT_DISPATCH(ObjCClass)
87 DEFAULT_DISPATCH(ObjCMethod)
88 DEFAULT_DISPATCH(ObjCProtocol)
89 DEFAULT_DISPATCH(ObjCCategory)
90 DEFAULT_DISPATCH(UsingDirective)
91 DEFAULT_DISPATCH(Using)
93 void VisitCXXRecordDecl(CXXRecordDecl *D) {
94 static_cast<ImplClass*>(this)->VisitRecordDecl(D);
98 } // end namespace clang
101 #undef DEFAULT_DISPATCH