diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-02-16 14:28:33 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-02-16 14:28:33 +0000 |
commit | ac152f1a1ae6830d77b8ec9cb1dabdf1b15df315 (patch) | |
tree | 15cd49a8d17509780f77e30bfba1fe390214dba9 | |
parent | 7b1c6c09f79284aaf970f39668049923592a027a (diff) | |
download | bcm5719-llvm-ac152f1a1ae6830d77b8ec9cb1dabdf1b15df315.tar.gz bcm5719-llvm-ac152f1a1ae6830d77b8ec9cb1dabdf1b15df315.zip |
Make DeclContexts maintenance a bit easier.
-In DeclNodes.def, only mark as DeclContexts the top classes that directly derive from DeclContext. If the Decl has subclasses,
it should be marked with DECL_CONTEXT_BASE.
-Use DeclNodes.def to automate the DeclContext::classof and DeclContext::CastTo definitions.
llvm-svn: 64629
-rw-r--r-- | clang/include/clang/AST/DeclBase.h | 56 | ||||
-rw-r--r-- | clang/include/clang/AST/DeclNodes.def | 20 | ||||
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 2 |
3 files changed, 32 insertions, 46 deletions
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index 89ef3b86c81..8172ab22c73 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -326,17 +326,20 @@ protected: }; /// DeclContext - This is used only as base class of specific decl types that -/// can act as declaration contexts. These decls are: +/// can act as declaration contexts. These decls are (only the top classes +/// that directly derive from DeclContext are mentioned, not their subclasses): /// /// TranslationUnitDecl /// NamespaceDecl /// FunctionDecl -/// RecordDecl/CXXRecordDecl -/// EnumDecl +/// TagDecl /// ObjCMethodDecl -/// ObjCInterfaceDecl +/// ObjCContainerDecl +/// ObjCCategoryImplDecl +/// ObjCImplementationDecl /// LinkageSpecDecl /// BlockDecl +/// class DeclContext { /// DeclKind - This indicates which class this is. Decl::Kind DeclKind : 8; @@ -380,36 +383,16 @@ class DeclContext { static To *CastTo(const From *D) { Decl::Kind DK = KindTrait<From>::getKind(D); switch(DK) { - case Decl::TranslationUnit: - return static_cast<TranslationUnitDecl*>(const_cast<From*>(D)); - case Decl::Namespace: - return static_cast<NamespaceDecl*>(const_cast<From*>(D)); - case Decl::Enum: - return static_cast<EnumDecl*>(const_cast<From*>(D)); - case Decl::Record: - return static_cast<RecordDecl*>(const_cast<From*>(D)); - case Decl::CXXRecord: - return static_cast<CXXRecordDecl*>(const_cast<From*>(D)); - case Decl::ObjCMethod: - return static_cast<ObjCMethodDecl*>(const_cast<From*>(D)); - case Decl::ObjCInterface: - return static_cast<ObjCInterfaceDecl*>(const_cast<From*>(D)); - case Decl::ObjCCategory: - return static_cast<ObjCCategoryDecl*>(const_cast<From*>(D)); - case Decl::ObjCProtocol: - return static_cast<ObjCProtocolDecl*>(const_cast<From*>(D)); - case Decl::ObjCImplementation: - return static_cast<ObjCImplementationDecl*>(const_cast<From*>(D)); - case Decl::ObjCCategoryImpl: - return static_cast<ObjCCategoryImplDecl*>(const_cast<From*>(D)); - case Decl::LinkageSpec: - return static_cast<LinkageSpecDecl*>(const_cast<From*>(D)); - case Decl::Block: - return static_cast<BlockDecl*>(const_cast<From*>(D)); +#define DECL_CONTEXT(Name) \ + case Decl::Name: \ + return static_cast<Name##Decl*>(const_cast<From*>(D)); +#define DECL_CONTEXT_BASE(Name) +#include "clang/AST/DeclNodes.def" default: - if (DK >= Decl::FunctionFirst && DK <= Decl::FunctionLast) - return static_cast<FunctionDecl*>(const_cast<From*>(D)); - +#define DECL_CONTEXT_BASE(Name) \ + if (DK >= Decl::Name##First && DK <= Decl::Name##Last) \ + return static_cast<Name##Decl*>(const_cast<From*>(D)); +#include "clang/AST/DeclNodes.def" assert(false && "a decl that inherits DeclContext isn't handled"); return 0; } @@ -800,12 +783,15 @@ public: static bool classof(const Decl *D) { switch (D->getKind()) { #define DECL_CONTEXT(Name) case Decl::Name: +#define DECL_CONTEXT_BASE(Name) #include "clang/AST/DeclNodes.def" return true; default: - if (D->getKind() >= Decl::FunctionFirst && - D->getKind() <= Decl::FunctionLast) +#define DECL_CONTEXT_BASE(Name) \ + if (D->getKind() >= Decl::Name##First && \ + D->getKind() <= Decl::Name##Last) \ return true; +#include "clang/AST/DeclNodes.def" return false; } } diff --git a/clang/include/clang/AST/DeclNodes.def b/clang/include/clang/AST/DeclNodes.def index 602c37e5e68..a22fa70b8b5 100644 --- a/clang/include/clang/AST/DeclNodes.def +++ b/clang/include/clang/AST/DeclNodes.def @@ -56,6 +56,10 @@ # define DECL_CONTEXT(Decl) #endif +#ifndef DECL_CONTEXT_BASE +# define DECL_CONTEXT_BASE(Decl) DECL_CONTEXT(Decl) +#endif + #ifndef LAST_DECL_CONTEXT # define LAST_DECL_CONTEXT(Decl) DECL_CONTEXT(Decl) #endif @@ -117,21 +121,16 @@ DECL(ObjCClass, Decl) DECL(FileScopeAsm, Decl) LAST_DECL(Block, Decl) -// Declaration contexts +// Declaration contexts. DECL_CONTEXT_BASE indicates that it has subclasses. DECL_CONTEXT(TranslationUnit) DECL_CONTEXT(Namespace) -DECL_CONTEXT(Enum) -DECL_CONTEXT(Record) -DECL_CONTEXT(CXXRecord) -DECL_CONTEXT(Function) +DECL_CONTEXT(LinkageSpec) DECL_CONTEXT(ObjCMethod) -DECL_CONTEXT(ObjCContainer) -DECL_CONTEXT(ObjCInterface) -DECL_CONTEXT(ObjCProtocol) -DECL_CONTEXT(ObjCCategory) DECL_CONTEXT(ObjCCategoryImpl) -DECL_CONTEXT(LinkageSpec) DECL_CONTEXT(ObjCImplementation) +DECL_CONTEXT_BASE(Tag) +DECL_CONTEXT_BASE(Function) +DECL_CONTEXT_BASE(ObjCContainer) LAST_DECL_CONTEXT(Block) // Declaration ranges @@ -149,6 +148,7 @@ LAST_DECL_RANGE(Var, Var, NonTypeTemplateParm) #undef LAST_DECL_RANGE #undef DECL_RANGE #undef LAST_DECL_CONTEXT +#undef DECL_CONTEXT_BASE #undef DECL_CONTEXT #undef ABSTRACT_DECL #undef LAST_DECL diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 1e3683c8576..91f2bf2765e 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -50,7 +50,7 @@ const char *Decl::getDeclKindName() const { const char *DeclContext::getDeclKindName() const { switch (DeclKind) { default: assert(0 && "Declaration context not in DeclNodes.def!"); -#define DECL_CONTEXT(Node) case Decl::Node: return #Node; +#define DECL(Derived, Base) case Decl::Derived: return #Derived; #include "clang/AST/DeclNodes.def" } } |