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
This commit is contained in:
parent
7b1c6c09f7
commit
ac152f1a1a
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(ObjCMethod)
|
||||
DECL_CONTEXT(ObjCContainer)
|
||||
DECL_CONTEXT(ObjCInterface)
|
||||
DECL_CONTEXT(ObjCProtocol)
|
||||
DECL_CONTEXT(ObjCCategory)
|
||||
DECL_CONTEXT(ObjCCategoryImpl)
|
||||
DECL_CONTEXT(LinkageSpec)
|
||||
DECL_CONTEXT(ObjCMethod)
|
||||
DECL_CONTEXT(ObjCCategoryImpl)
|
||||
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
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue