clang API Documentation
00001 //===--- TypeVisitor.h - Visitor for Type subclasses ------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the TypeVisitor interface. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_AST_TYPEVISITOR_H 00015 #define LLVM_CLANG_AST_TYPEVISITOR_H 00016 00017 #include "clang/AST/Type.h" 00018 00019 namespace clang { 00020 00021 #define DISPATCH(CLASS) \ 00022 return static_cast<ImplClass*>(this)-> \ 00023 Visit##CLASS(static_cast<const CLASS*>(T)) 00024 00025 template<typename ImplClass, typename RetTy=void> 00026 class TypeVisitor { 00027 public: 00028 RetTy Visit(const Type *T) { 00029 // Top switch stmt: dispatch to VisitFooType for each FooType. 00030 switch (T->getTypeClass()) { 00031 #define ABSTRACT_TYPE(CLASS, PARENT) 00032 #define TYPE(CLASS, PARENT) case Type::CLASS: DISPATCH(CLASS##Type); 00033 #include "clang/AST/TypeNodes.def" 00034 } 00035 llvm_unreachable("Unknown type class!"); 00036 } 00037 00038 // If the implementation chooses not to implement a certain visit method, fall 00039 // back on superclass. 00040 #define TYPE(CLASS, PARENT) RetTy Visit##CLASS##Type(const CLASS##Type *T) { \ 00041 DISPATCH(PARENT); \ 00042 } 00043 #include "clang/AST/TypeNodes.def" 00044 00045 // Base case, ignore it. :) 00046 RetTy VisitType(const Type*) { return RetTy(); } 00047 }; 00048 00049 #undef DISPATCH 00050 00051 } // end namespace clang 00052 00053 #endif