From 4a6835e650ff24e19ce08a3bd347c0ad186777fd Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Thu, 10 Sep 2009 23:38:47 +0000 Subject: Add stricter GlobalDecl constructors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81480 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.h') diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 607f2a172c..d5b0bfa6a8 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -70,23 +70,31 @@ namespace CodeGen { /// GlobalDecl - represents a global declaration. This can either be a /// CXXConstructorDecl and the constructor type (Base, Complete). /// a CXXDestructorDecl and the destructor type (Base, Complete) or -// a regular VarDecl or a FunctionDecl. +/// a VarDecl, a FunctionDecl or a BlockDecl. class GlobalDecl { - llvm::PointerIntPair Value; + llvm::PointerIntPair Value; + void init(const Decl *D) { + assert(!isa(D) && "Use other ctor with ctor decls!"); + assert(!isa(D) && "Use other ctor with dtor decls!"); + assert(isa(D) || isa(D) + && "Invalid decl type passed to GlobalDecl ctor!"); + + Value.setPointer(D); + } + public: GlobalDecl() {} - explicit GlobalDecl(const ValueDecl *VD) : Value(VD, 0) { - assert(!isa(VD) && "Use other ctor with ctor decls!"); - assert(!isa(VD) && "Use other ctor with dtor decls!"); - } + GlobalDecl(const VarDecl *D) { init(D);} + GlobalDecl(const FunctionDecl *D) { init(D); } + GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {} GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {} - const ValueDecl *getDecl() const { return Value.getPointer(); } + const Decl *getDecl() const { return Value.getPointer(); } CXXCtorType getCtorType() const { assert(isa(getDecl()) && "Decl is not a ctor!"); -- cgit v1.2.3