From: Benjamin Kramer Date: Sat, 19 May 2012 16:03:58 +0000 (+0000) Subject: Simplify some users of DeclarationName::getNameKind. Fold getFETokenInfoAsVoid into... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c470442fe144b93c2877134559d0067b3215289d;p=clang Simplify some users of DeclarationName::getNameKind. Fold getFETokenInfoAsVoid into its only caller. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157116 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclarationName.h b/include/clang/AST/DeclarationName.h index f359499b14..6146525406 100644 --- a/include/clang/AST/DeclarationName.h +++ b/include/clang/AST/DeclarationName.h @@ -109,8 +109,8 @@ private: /// CXXSpecialName, returns a pointer to it. Otherwise, returns /// a NULL pointer. CXXSpecialName *getAsCXXSpecialName() const { - if (getNameKind() >= CXXConstructorName && - getNameKind() <= CXXConversionFunctionName) + NameKind Kind = getNameKind(); + if (Kind >= CXXConstructorName && Kind <= CXXConversionFunctionName) return reinterpret_cast(Ptr & ~PtrMask); return 0; } @@ -156,14 +156,8 @@ private: friend class DeclarationNameTable; friend class NamedDecl; - /// getFETokenInfoAsVoid - Retrieves the front end-specified pointer - /// for this name as a void pointer. - void *getFETokenInfoAsVoid() const { - if (getNameKind() == Identifier) - return getAsIdentifierInfo()->getFETokenInfo(); - return getFETokenInfoAsVoidSlow(); - } - + /// getFETokenInfoAsVoidSlow - Retrieves the front end-specified pointer + /// for this name as a void pointer if it's not an identifier. void *getFETokenInfoAsVoidSlow() const; public: @@ -273,7 +267,11 @@ public: /// declaration names, including normal identifiers and C++ /// constructors, destructors, and conversion functions. template - T *getFETokenInfo() const { return static_cast(getFETokenInfoAsVoid()); } + T *getFETokenInfo() const { + if (const IdentifierInfo *Info = getAsIdentifierInfo()) + return Info->getFETokenInfo(); + return static_cast(getFETokenInfoAsVoidSlow()); + } void setFETokenInfo(void *T); diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index 9eadf32543..28188d91c1 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -281,7 +281,7 @@ IdentifierInfo *DeclarationName::getCXXLiteralIdentifier() const { void *DeclarationName::getFETokenInfoAsVoidSlow() const { switch (getNameKind()) { case Identifier: - llvm_unreachable("Handled by getFETokenInfoAsVoid()"); + llvm_unreachable("Handled by getFETokenInfo()"); case CXXConstructorName: case CXXDestructorName: diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 9143eb282f..3e1899c762 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1504,15 +1504,14 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, Decl *Member; if (isInstField) { CXXScopeSpec &SS = D.getCXXScopeSpec(); + IdentifierInfo *II = Name.getAsIdentifierInfo(); // Data members must have identifiers for names. - if (Name.getNameKind() != DeclarationName::Identifier) { + if (!II) { Diag(Loc, diag::err_bad_variable_name) << Name; return 0; } - - IdentifierInfo *II = Name.getAsIdentifierInfo(); // Member field could not be with "template" keyword. // So TemplateParameterLists should be empty in this case. @@ -4469,7 +4468,7 @@ void Sema::DiagnoseHiddenVirtualMethods(CXXRecordDecl *DC, CXXMethodDecl *MD) { if (Diags.getDiagnosticLevel(diag::warn_overloaded_virtual, MD->getLocation()) == DiagnosticsEngine::Ignored) return; - if (MD->getDeclName().getNameKind() != DeclarationName::Identifier) + if (!MD->getDeclName().isIdentifier()) return; CXXBasePaths Paths(/*FindAmbiguities=*/true, // true to look in all bases. diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 0fbfc2a278..3a4f3dd883 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -1398,14 +1398,14 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, bool Super) { const ObjCInterfaceType *IFaceT = OPT->getInterfaceType(); ObjCInterfaceDecl *IFace = IFaceT->getDecl(); - - if (MemberName.getNameKind() != DeclarationName::Identifier) { + + IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); + if (!Member) { Diag(MemberLoc, diag::err_invalid_property_name) << MemberName << QualType(OPT, 0); return ExprError(); } - IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); SourceRange BaseRange = Super? SourceRange(SuperLoc) : BaseExpr->getSourceRange(); if (RequireCompleteType(MemberLoc, OPT->getPointeeType(),