[cfe-commits] r94786 - in /cfe/trunk/include/clang/AST: Decl.h DeclBase.h DeclCXX.h DeclObjC.h DeclTemplate.h

John McCall rjmccall at apple.com
Thu Jan 28 17:45:37 PST 2010


Author: rjmccall
Date: Thu Jan 28 19:45:37 2010
New Revision: 94786

URL: http://llvm.org/viewvc/llvm-project?rev=94786&view=rev
Log:
Do a little magic and a little greasework to make it much more efficient
to cast a DeclContext down to a specific implementation class.

There are still lots of calls to Decl::castFromDeclContext left, mostly
arising from DeclContext::getParent().


Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/AST/DeclTemplate.h

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=94786&r1=94785&r2=94786&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Jan 28 19:45:37 2010
@@ -75,8 +75,9 @@
 
   static TranslationUnitDecl *Create(ASTContext &C);
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == TranslationUnit; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const TranslationUnitDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == TranslationUnit; }
   static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
     return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
   }
@@ -221,10 +222,9 @@
     return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
   }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const NamedDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K >= NamedFirst && K <= NamedLast; }
 };
 
 /// NamespaceDecl - Represent a C++ namespace.
@@ -301,8 +301,9 @@
   void setRBracLoc(SourceLocation RBrace) { RBracLoc = RBrace; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == Namespace; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const NamespaceDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Namespace; }
   static DeclContext *castToDeclContext(const NamespaceDecl *D) {
     return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
   }
@@ -326,10 +327,9 @@
   void setType(QualType newType) { DeclType = newType; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() >= ValueFirst && D->getKind() <= ValueLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ValueDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K >= ValueFirst && K <= ValueLast; }
 };
 
 /// \brief Represents a ValueDecl that came out of a declarator.
@@ -349,10 +349,11 @@
   SourceLocation getTypeSpecStartLoc() const;
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() >= DeclaratorFirst && D->getKind() <= DeclaratorLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const DeclaratorDecl *D) { return true; }
+  static bool classofKind(Kind K) {
+    return K >= DeclaratorFirst && K <= DeclaratorLast;
+  }
 };
 
 /// \brief Structure used to store a statement, the constant value to
@@ -758,10 +759,9 @@
                         SourceLocation PointOfInstantiation = SourceLocation());
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() >= VarFirst && D->getKind() <= VarLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const VarDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K >= VarFirst && K <= VarLast; }
 };
 
 class ImplicitParamDecl : public VarDecl {
@@ -775,7 +775,8 @@
                                    QualType T);
   // Implement isa/cast/dyncast/etc.
   static bool classof(const ImplicitParamDecl *D) { return true; }
-  static bool classof(const Decl *D) { return D->getKind() == ImplicitParam; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classofKind(Kind K) { return K == ImplicitParam; }
 };
 
 /// ParmVarDecl - Represent a parameter to a function.
@@ -881,10 +882,9 @@
   void setOwningFunction(DeclContext *FD) { setDeclContext(FD); }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return (D->getKind() == ParmVar);
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ParmVarDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ParmVar; }
 };
 
 /// FunctionDecl - An instance of this class is created to represent a
@@ -1298,10 +1298,11 @@
   bool isOutOfLine() const;
                        
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() >= FunctionFirst && D->getKind() <= FunctionLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const FunctionDecl *D) { return true; }
+  static bool classofKind(Kind K) {
+    return K >= FunctionFirst && K <= FunctionLast;
+  }
   static DeclContext *castToDeclContext(const FunctionDecl *D) {
     return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
   }
@@ -1351,10 +1352,9 @@
   void setBitWidth(Expr *BW) { BitWidth = BW; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() >= FieldFirst && D->getKind() <= FieldLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const FieldDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K >= FieldFirst && K <= FieldLast; }
 };
 
 /// EnumConstantDecl - An instance of this object exists for each enum constant
@@ -1388,8 +1388,9 @@
   void setInitVal(const llvm::APSInt &V) { Val = V; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == EnumConstant; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const EnumConstantDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == EnumConstant; }
 
   friend class StmtIteratorBase;
 };
@@ -1421,10 +1422,9 @@
   void setTypeForDecl(Type *TD) { TypeForDecl = TD; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() >= TypeFirst && D->getKind() <= TypeLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const TypeDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K >= TypeFirst && K <= TypeLast; }
 };
 
 
@@ -1463,8 +1463,9 @@
   }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == Typedef; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const TypedefDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Typedef; }
 };
 
 class TypedefDecl;
@@ -1588,10 +1589,9 @@
   void setTypedefForAnonDecl(TypedefDecl *TDD) { TypedefForAnonDecl = TDD; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() >= TagFirst && D->getKind() <= TagLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const TagDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K >= TagFirst && K <= TagLast; }
 
   static DeclContext *castToDeclContext(const TagDecl *D) {
     return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
@@ -1682,8 +1682,9 @@
 
   void setInstantiationOfMemberEnum(EnumDecl *IF) { InstantiatedFrom = IF; }
 
-  static bool classof(const Decl *D) { return D->getKind() == Enum; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const EnumDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Enum; }
 };
 
 
@@ -1792,10 +1793,11 @@
   /// now complete.
   void completeDefinition(ASTContext& C);
 
-  static bool classof(const Decl *D) {
-    return D->getKind() >= RecordFirst && D->getKind() <= RecordLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const RecordDecl *D) { return true; }
+  static bool classofKind(Kind K) {
+    return K >= RecordFirst && K <= RecordLast;
+  }
 };
 
 class FileScopeAsmDecl : public Decl {
@@ -1810,10 +1812,9 @@
   StringLiteral *getAsmString() { return AsmString; }
   void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == FileScopeAsm;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const FileScopeAsmDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == FileScopeAsm; }
 };
 
 /// BlockDecl - This represents a block literal declaration, which is like an
@@ -1875,8 +1876,9 @@
   void setParams(ASTContext& C, ParmVarDecl **NewParamInfo, unsigned NumParams);
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == Block; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const BlockDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Block; }
   static DeclContext *castToDeclContext(const BlockDecl *D) {
     return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
   }

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=94786&r1=94785&r2=94786&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Jan 28 19:45:37 2010
@@ -480,6 +480,7 @@
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *) { return true; }
+  static bool classofKind(Kind K) { return true; }
   static DeclContext *castToDeclContext(const Decl *);
   static Decl *castFromDeclContext(const DeclContext *);
 
@@ -1020,17 +1021,43 @@
          getKind() == TemplateTemplateParm;
 }
 
+
+// Specialization selected when ToTy is not a known subclass of DeclContext.
+template <class ToTy,
+          bool IsKnownSubtype = ::llvm::is_base_of< DeclContext, ToTy>::value>
+struct cast_convert_decl_context {
+  static const ToTy *doit(const DeclContext *Val) {
+    return static_cast<const ToTy*>(Decl::castFromDeclContext(Val));
+  }
+
+  static ToTy *doit(DeclContext *Val) {
+    return static_cast<ToTy*>(Decl::castFromDeclContext(Val));
+  }
+};
+
+// Specialization selected when ToTy is a known subclass of DeclContext.
+template <class ToTy>
+struct cast_convert_decl_context<ToTy, true> {
+  static const ToTy *doit(const DeclContext *Val) {
+    return static_cast<const ToTy*>(Val);
+  }
+
+  static ToTy *doit(DeclContext *Val) {
+    return static_cast<ToTy*>(Val);
+  }
+};
+
+
 } // end clang.
 
 namespace llvm {
 
-/// Implement a isa_impl_wrap specialization to check whether a DeclContext is
-/// a specific Decl.
+/// isa<T>(DeclContext*)
 template<class ToTy>
 struct isa_impl_wrap<ToTy,
                      const ::clang::DeclContext,const ::clang::DeclContext> {
   static bool doit(const ::clang::DeclContext &Val) {
-    return ToTy::classof(::clang::Decl::castFromDeclContext(&Val));
+    return ToTy::classofKind(Val.getDeclKind());
   }
 };
 template<class ToTy>
@@ -1038,6 +1065,34 @@
   : public isa_impl_wrap<ToTy,
                       const ::clang::DeclContext,const ::clang::DeclContext> {};
 
+/// cast<T>(DeclContext*)
+template<class ToTy>
+struct cast_convert_val<ToTy,
+                        const ::clang::DeclContext,const ::clang::DeclContext> {
+  static const ToTy &doit(const ::clang::DeclContext &Val) {
+    return *::clang::cast_convert_decl_context<ToTy>::doit(&Val);
+  }
+};
+template<class ToTy>
+struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> {
+  static ToTy &doit(::clang::DeclContext &Val) {
+    return *::clang::cast_convert_decl_context<ToTy>::doit(&Val);
+  }
+};
+template<class ToTy>
+struct cast_convert_val<ToTy,
+                     const ::clang::DeclContext*, const ::clang::DeclContext*> {
+  static const ToTy *doit(const ::clang::DeclContext *Val) {
+    return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
+  }
+};
+template<class ToTy>
+struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> {
+  static ToTy *doit(::clang::DeclContext *Val) {
+    return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
+  }
+};
+
 /// Implement cast_convert_val for Decl -> DeclContext conversions.
 template<class FromTy>
 struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> {
@@ -1067,31 +1122,6 @@
   }
 };
 
-/// Implement cast_convert_val for DeclContext -> Decl conversions.
-template<class ToTy>
-struct cast_convert_val<ToTy,
-                        const ::clang::DeclContext,const ::clang::DeclContext> {
-  static ToTy &doit(const ::clang::DeclContext &Val) {
-    return *reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(&Val));
-  }
-};
-template<class ToTy>
-struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext>
-  : public cast_convert_val<ToTy,
-                      const ::clang::DeclContext,const ::clang::DeclContext> {};
-
-template<class ToTy>
-struct cast_convert_val<ToTy,
-                     const ::clang::DeclContext*, const ::clang::DeclContext*> {
-  static ToTy *doit(const ::clang::DeclContext *Val) {
-    return reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(Val));
-  }
-};
-template<class ToTy>
-struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*>
-  : public cast_convert_val<ToTy,
-                    const ::clang::DeclContext*,const ::clang::DeclContext*> {};
-
 } // end namespace llvm
 
 #endif

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=94786&r1=94785&r2=94786&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Jan 28 19:45:37 2010
@@ -826,10 +826,11 @@
     return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
   }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == CXXRecord ||
-           D->getKind() == ClassTemplateSpecialization ||
-           D->getKind() == ClassTemplatePartialSpecialization;
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classofKind(Kind K) {
+    return K == CXXRecord ||
+           K == ClassTemplateSpecialization ||
+           K == ClassTemplatePartialSpecialization;
   }
   static bool classof(const CXXRecordDecl *D) { return true; }
   static bool classof(const ClassTemplateSpecializationDecl *D) {
@@ -911,10 +912,11 @@
   bool hasInlineBody() const;
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() >= CXXMethod && D->getKind() <= CXXConversion;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const CXXMethodDecl *D) { return true; }
+  static bool classofKind(Kind K) {
+    return K >= CXXMethod && K <= CXXConversion;
+  }
 };
 
 /// CXXBaseOrMemberInitializer - Represents a C++ base or member
@@ -1221,10 +1223,9 @@
   bool isCopyConstructorLikeSpecialization() const;
   
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() == CXXConstructor;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const CXXConstructorDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == CXXConstructor; }
 };
 
 /// CXXDestructorDecl - Represents a C++ destructor within a
@@ -1283,10 +1284,9 @@
   const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() == CXXDestructor;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const CXXDestructorDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == CXXDestructor; }
 };
 
 /// CXXConversionDecl - Represents a C++ conversion function within a
@@ -1336,10 +1336,9 @@
   }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() == CXXConversion;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const CXXConversionDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == CXXConversion; }
 };
 
 /// FriendDecl - Represents the declaration of a friend entity,
@@ -1408,10 +1407,9 @@
   void setSpecialization(bool WS) { WasSpecialization = WS; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() == Decl::Friend;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const FriendDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Decl::Friend; }
 };
 
 /// LinkageSpecDecl - This represents a linkage specification.  For example:
@@ -1449,10 +1447,9 @@
   /// braces in its syntactic form.
   bool hasBraces() const { return HadBraces; }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == LinkageSpec;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const LinkageSpecDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == LinkageSpec; }
   static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
     return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
   }
@@ -1554,10 +1551,9 @@
                                     NamedDecl *Nominated,
                                     DeclContext *CommonAncestor);
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == Decl::UsingDirective;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const UsingDirectiveDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Decl::UsingDirective; }
 
   // Friend for getUsingDirectiveName.
   friend class DeclContext;
@@ -1627,10 +1623,9 @@
                                     SourceLocation IdentLoc,
                                     NamedDecl *Namespace);
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == Decl::NamespaceAlias;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const NamespaceAliasDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Decl::NamespaceAlias; }
 };
 
 /// UsingShadowDecl - Represents a shadow declaration introduced into
@@ -1677,10 +1672,9 @@
     return Using;
   }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == Decl::UsingShadow;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const UsingShadowDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
 };
 
 /// UsingDecl - Represents a C++ using-declaration. For example:
@@ -1749,10 +1743,9 @@
       SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL,
       NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg);
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == Decl::Using;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const UsingDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Decl::Using; }
 };
 
 /// UnresolvedUsingValueDecl - Represents a dependent using
@@ -1801,10 +1794,9 @@
            SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
            SourceLocation TargetNameLoc, DeclarationName TargetName);
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == Decl::UnresolvedUsingValue;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingValue; }
 };
 
 /// UnresolvedUsingTypenameDecl - Represents a dependent using
@@ -1860,10 +1852,9 @@
            SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
            SourceLocation TargetNameLoc, DeclarationName TargetName);
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == Decl::UnresolvedUsingTypename;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingTypename; }
 };
 
 /// StaticAssertDecl - Represents a C++0x static_assert declaration.
@@ -1889,10 +1880,9 @@
   virtual ~StaticAssertDecl();
   virtual void Destroy(ASTContext& C);
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == Decl::StaticAssert;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(StaticAssertDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == Decl::StaticAssert; }
 };
 
 /// Insertion operator for diagnostics.  This allows sending AccessSpecifier's

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=94786&r1=94785&r2=94786&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Jan 28 19:45:37 2010
@@ -280,8 +280,9 @@
   bool isThisDeclarationADefinition() const { return Body; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == ObjCMethod; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCMethodDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCMethod; }
   static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
     return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
   }
@@ -386,11 +387,12 @@
   }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() >= ObjCContainerFirst &&
-           D->getKind() <= ObjCContainerLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCContainerDecl *D) { return true; }
+  static bool classofKind(Kind K) {
+    return K >= ObjCContainerFirst &&
+           K <= ObjCContainerLast;
+  }
 
   static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
     return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
@@ -587,8 +589,9 @@
   Type *getTypeForDecl() const { return TypeForDecl; }
   void setTypeForDecl(Type *TD) const { TypeForDecl = TD; }
 
-  static bool classof(const Decl *D) { return D->getKind() == ObjCInterface; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCInterfaceDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCInterface; }
 };
 
 /// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC
@@ -633,8 +636,9 @@
   }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == ObjCIvar; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCIvarDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCIvar; }
 private:
   // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum
   unsigned DeclAccess : 3;
@@ -660,8 +664,9 @@
   virtual void Destroy(ASTContext& C);
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) { return D->getKind() == ObjCAtDefsField; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
 };
 
 /// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
@@ -752,8 +757,9 @@
   SourceLocation getLocEnd() const { return EndLoc; }
   void setLocEnd(SourceLocation LE) { EndLoc = LE; }
 
-  static bool classof(const Decl *D) { return D->getKind() == ObjCProtocol; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCProtocolDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCProtocol; }
 };
 
 /// ObjCClassDecl - Specifies a list of forward class declarations. For example:
@@ -799,8 +805,9 @@
   void setClassList(ASTContext &C, ObjCInterfaceDecl*const*List,
                     const SourceLocation *Locs, unsigned Num);
 
-  static bool classof(const Decl *D) { return D->getKind() == ObjCClass; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCClassDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCClass; }
 };
 
 /// ObjCForwardProtocolDecl - Specifies a list of forward protocol declarations.
@@ -849,10 +856,9 @@
                        const SourceLocation *Locs, ASTContext &C) {
     ReferencedProtocols.set(List, Num, Locs, C);
   }
-  static bool classof(const Decl *D) {
-    return D->getKind() == ObjCForwardProtocol;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCForwardProtocolDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCForwardProtocol; }
 };
 
 /// ObjCCategoryDecl - Represents a category declaration. A category allows
@@ -953,8 +959,9 @@
     return SourceRange(AtLoc, getAtEndRange().getEnd());
   }
 
-  static bool classof(const Decl *D) { return D->getKind() == ObjCCategory; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCCategoryDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCCategory; }
 };
 
 class ObjCImplDecl : public ObjCContainerDecl {
@@ -1000,10 +1007,11 @@
     return propimpl_iterator(decls_end());
   }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() >= ObjCImplFirst && D->getKind() <= ObjCImplLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCImplDecl *D) { return true; }
+  static bool classofKind(Kind K) {
+    return K >= ObjCImplFirst && K <= ObjCImplLast;
+  }
 };
 
 /// ObjCCategoryImplDecl - An object of this class encapsulates a category
@@ -1071,8 +1079,9 @@
     return getName();
   }
 
-  static bool classof(const Decl *D) { return D->getKind() == ObjCCategoryImpl;}
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCCategoryImplDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
 };
 
 /// ObjCImplementationDecl - Represents a class definition - this is where
@@ -1155,10 +1164,9 @@
     return ivar_begin() == ivar_end();
   }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == ObjCImplementation;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCImplementationDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCImplementation; }
 };
 
 /// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
@@ -1179,10 +1187,9 @@
   ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
   void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == ObjCCompatibleAlias;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCCompatibleAliasDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
 
 };
 
@@ -1297,10 +1304,9 @@
     return PropertyIvarDecl;
   }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == ObjCProperty;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCPropertyDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ObjCProperty; }
 };
 
 /// ObjCPropertyImplDecl - Represents implementation declaration of a property
@@ -1357,10 +1363,9 @@
   }
   void setPropertyIvarDecl(ObjCIvarDecl *Ivar) { PropertyIvarDecl = Ivar; }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == ObjCPropertyImpl;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCPropertyImplDecl *D) { return true; }
+  static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
 };
 
 }  // end namespace clang

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=94786&r1=94785&r2=94786&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Thu Jan 28 19:45:37 2010
@@ -247,13 +247,14 @@
   NamedDecl *getTemplatedDecl() const { return TemplatedDecl; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-      return D->getKind() >= TemplateFirst && D->getKind() <= TemplateLast;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const TemplateDecl *D) { return true; }
   static bool classof(const FunctionTemplateDecl *D) { return true; }
   static bool classof(const ClassTemplateDecl *D) { return true; }
   static bool classof(const TemplateTemplateParmDecl *D) { return true; }
+  static bool classofKind(Kind K) {
+    return K >= TemplateFirst && K <= TemplateLast;
+  }
 
 protected:
   NamedDecl *TemplatedDecl;
@@ -510,10 +511,9 @@
                                       NamedDecl *Decl);
 
   // Implement isa/cast/dyncast support
-  static bool classof(const Decl *D)
-  { return D->getKind() == FunctionTemplate; }
-  static bool classof(const FunctionTemplateDecl *D)
-  { return true; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classof(const FunctionTemplateDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == FunctionTemplate; }
 };
 
 //===----------------------------------------------------------------------===//
@@ -634,10 +634,9 @@
   bool isParameterPack() const { return ParameterPack; }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() == TemplateTypeParm;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const TemplateTypeParmDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == TemplateTypeParm; }
 };
 
 /// NonTypeTemplateParmDecl - Declares a non-type template parameter,
@@ -682,10 +681,9 @@
   }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() == NonTypeTemplateParm;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const NonTypeTemplateParmDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == NonTypeTemplateParm; }
 };
 
 /// TemplateTemplateParmDecl - Declares a template template parameter,
@@ -735,10 +733,9 @@
   }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() == TemplateTemplateParm;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const TemplateTemplateParmDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == TemplateTemplateParm; }
 };
 
 /// \brief Represents a class template specialization, which refers to
@@ -903,9 +900,10 @@
       TemplateArgs[Arg].Profile(ID, Context);
   }
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == ClassTemplateSpecialization ||
-           D->getKind() == ClassTemplatePartialSpecialization;
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classofKind(Kind K) {
+    return K == ClassTemplateSpecialization ||
+           K == ClassTemplatePartialSpecialization;
   }
 
   static bool classof(const ClassTemplateSpecializationDecl *) {
@@ -1039,8 +1037,9 @@
     
   // FIXME: Add Profile support!
 
-  static bool classof(const Decl *D) {
-    return D->getKind() == ClassTemplatePartialSpecialization;
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classofKind(Kind K) {
+    return K == ClassTemplatePartialSpecialization;
   }
 
   static bool classof(const ClassTemplatePartialSpecializationDecl *) {
@@ -1212,10 +1211,9 @@
   }
   
   // Implement isa/cast/dyncast support
-  static bool classof(const Decl *D)
-  { return D->getKind() == ClassTemplate; }
-  static bool classof(const ClassTemplateDecl *D)
-  { return true; }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classof(const ClassTemplateDecl *D) { return true; }
+  static bool classofKind(Kind K) { return K == ClassTemplate; }
 
   virtual void Destroy(ASTContext& C);
 };
@@ -1293,9 +1291,8 @@
   }
 
   // Implement isa/cast/dyncast/etc.
-  static bool classof(const Decl *D) {
-    return D->getKind() == Decl::FriendTemplate;
-  }
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classofKind(Kind K) { return K == Decl::FriendTemplate; }
   static bool classof(const FriendTemplateDecl *D) { return true; }
 };
 





More information about the cfe-commits mailing list