summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-02-16 14:29:28 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-02-16 14:29:28 +0000
commitafe24c881890e98d22bbd58e940c5433f870637c (patch)
treef000ed849d07889ada938a06cbe9cddb5ec7d0bf /clang/lib/AST/DeclBase.cpp
parentac152f1a1ae6830d77b8ec9cb1dabdf1b15df315 (diff)
downloadbcm5719-llvm-afe24c881890e98d22bbd58e940c5433f870637c.tar.gz
bcm5719-llvm-afe24c881890e98d22bbd58e940c5433f870637c.zip
DeclContext had its "casting machinery" inside the class definition so that if a new declaration context Decl appeared, the necessary changes
would be in one place. Since, now, only DeclNodes.def needs to be modified, move things out-of-line and simplify the DeclContext class. llvm-svn: 64630
Diffstat (limited to 'clang/lib/AST/DeclBase.cpp')
-rw-r--r--clang/lib/AST/DeclBase.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 91f2bf2765e..a8ca34dca54 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -213,17 +213,61 @@ void Decl::Destroy(ASTContext& C) {
}
Decl *Decl::castFromDeclContext (const DeclContext *D) {
- return DeclContext::CastTo<Decl>(D);
+ Decl::Kind DK = D->getDeclKind();
+ switch(DK) {
+#define DECL_CONTEXT(Name) \
+ case Decl::Name: \
+ return static_cast<Name##Decl*>(const_cast<DeclContext*>(D));
+#define DECL_CONTEXT_BASE(Name)
+#include "clang/AST/DeclNodes.def"
+ default:
+#define DECL_CONTEXT_BASE(Name) \
+ if (DK >= Decl::Name##First && DK <= Decl::Name##Last) \
+ return static_cast<Name##Decl*>(const_cast<DeclContext*>(D));
+#include "clang/AST/DeclNodes.def"
+ assert(false && "a decl that inherits DeclContext isn't handled");
+ return 0;
+ }
}
DeclContext *Decl::castToDeclContext(const Decl *D) {
- return DeclContext::CastTo<DeclContext>(D);
+ Decl::Kind DK = D->getKind();
+ switch(DK) {
+#define DECL_CONTEXT(Name) \
+ case Decl::Name: \
+ return static_cast<Name##Decl*>(const_cast<Decl*>(D));
+#define DECL_CONTEXT_BASE(Name)
+#include "clang/AST/DeclNodes.def"
+ default:
+#define DECL_CONTEXT_BASE(Name) \
+ if (DK >= Decl::Name##First && DK <= Decl::Name##Last) \
+ return static_cast<Name##Decl*>(const_cast<Decl*>(D));
+#include "clang/AST/DeclNodes.def"
+ assert(false && "a decl that inherits DeclContext isn't handled");
+ return 0;
+ }
}
//===----------------------------------------------------------------------===//
// DeclContext Implementation
//===----------------------------------------------------------------------===//
+bool DeclContext::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:
+#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;
+ }
+}
+
const DeclContext *DeclContext::getParent() const {
if (const Decl *D = dyn_cast<Decl>(this))
return D->getDeclContext();
OpenPOWER on IntegriCloud