From: John McCall Date: Fri, 29 Jan 2010 01:45:37 +0000 (+0000) Subject: Do a little magic and a little greasework to make it much more efficient X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=80cd64a8450d8e2c079dc134d9711cd45ba89d63;p=clang 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(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94786 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 6489a32a10..9f555a2f5e 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -75,8 +75,9 @@ public: 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(const_cast(D)); } @@ -221,10 +222,9 @@ public: return const_cast(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 @@ public: 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(const_cast(D)); } @@ -326,10 +327,9 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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(const_cast(D)); } @@ -1351,10 +1352,9 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: } // 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 @@ public: 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(const_cast(D)); @@ -1682,8 +1682,9 @@ public: 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 @@ public: /// 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 @@ public: 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 @@ public: 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(const_cast(D)); } diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 775bce2a15..a407a16277 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -480,6 +480,7 @@ public: // 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 @@ inline bool Decl::isTemplateParameter() const { getKind() == TemplateTemplateParm; } + +// Specialization selected when ToTy is not a known subclass of DeclContext. +template ::value> +struct cast_convert_decl_context { + static const ToTy *doit(const DeclContext *Val) { + return static_cast(Decl::castFromDeclContext(Val)); + } + + static ToTy *doit(DeclContext *Val) { + return static_cast(Decl::castFromDeclContext(Val)); + } +}; + +// Specialization selected when ToTy is a known subclass of DeclContext. +template +struct cast_convert_decl_context { + static const ToTy *doit(const DeclContext *Val) { + return static_cast(Val); + } + + static ToTy *doit(DeclContext *Val) { + return static_cast(Val); + } +}; + + } // end clang. namespace llvm { -/// Implement a isa_impl_wrap specialization to check whether a DeclContext is -/// a specific Decl. +/// isa(DeclContext*) template struct isa_impl_wrap { static bool doit(const ::clang::DeclContext &Val) { - return ToTy::classof(::clang::Decl::castFromDeclContext(&Val)); + return ToTy::classofKind(Val.getDeclKind()); } }; template @@ -1038,6 +1065,34 @@ struct isa_impl_wrap : public isa_impl_wrap {}; +/// cast(DeclContext*) +template +struct cast_convert_val { + static const ToTy &doit(const ::clang::DeclContext &Val) { + return *::clang::cast_convert_decl_context::doit(&Val); + } +}; +template +struct cast_convert_val { + static ToTy &doit(::clang::DeclContext &Val) { + return *::clang::cast_convert_decl_context::doit(&Val); + } +}; +template +struct cast_convert_val { + static const ToTy *doit(const ::clang::DeclContext *Val) { + return ::clang::cast_convert_decl_context::doit(Val); + } +}; +template +struct cast_convert_val { + static ToTy *doit(::clang::DeclContext *Val) { + return ::clang::cast_convert_decl_context::doit(Val); + } +}; + /// Implement cast_convert_val for Decl -> DeclContext conversions. template struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { @@ -1067,31 +1122,6 @@ struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { } }; -/// Implement cast_convert_val for DeclContext -> Decl conversions. -template -struct cast_convert_val { - static ToTy &doit(const ::clang::DeclContext &Val) { - return *reinterpret_cast(ToTy::castFromDeclContext(&Val)); - } -}; -template -struct cast_convert_val - : public cast_convert_val {}; - -template -struct cast_convert_val { - static ToTy *doit(const ::clang::DeclContext *Val) { - return reinterpret_cast(ToTy::castFromDeclContext(Val)); - } -}; -template -struct cast_convert_val - : public cast_convert_val {}; - } // end namespace llvm #endif diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 63862b6f9c..30a4e96904 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -826,10 +826,11 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: } // 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 @@ public: 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 @@ public: /// 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(const_cast(D)); } @@ -1554,10 +1551,9 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index d12f3fbaa3..994d68b445 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -280,8 +280,9 @@ public: 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(const_cast(D)); } @@ -386,11 +387,12 @@ public: } // 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(const_cast(D)); @@ -587,8 +589,9 @@ public: 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 @@ public: } // 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: } 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 diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index d8b004a049..ced174716c 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -247,13 +247,14 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: } // 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 @@ public: } // 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 @@ public: 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 @@ public: // 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 @@ public: } // 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 @@ public: } // 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; } };