From: Alp Toker Date: Mon, 30 Jun 2014 01:33:53 +0000 (+0000) Subject: Extract an isReservedName() function X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ec95c85e71e9c9360c9e3fd8c984432bbbec1f5;p=clang Extract an isReservedName() function We'll want to share the implementation if anything else decides to check for reserved names in future, so make this little snippet of code more discoverable. Also remove the __va_list_tag and __builtin_va_list special-case checks. They're leftovers from before when the reserved name logic was added. No change in functionality. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212006 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index f441befcfb..e2149eddd4 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -480,6 +480,16 @@ getRequiredQualification(ASTContext &Context, return Result; } +/// Determine whether \p Id is a name reserved for the implementation (C99 +/// 7.1.3, C++ [lib.global.names]). +static bool isReservedName(const IdentifierInfo *Id) { + if (Id->getLength() < 2) + return false; + const char *Name = Id->getNameStart(); + return Name[0] == '_' && + (Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z')); +} + bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, bool &AsNestedNameSpecifier) const { AsNestedNameSpecifier = false; @@ -506,25 +516,15 @@ bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, return false; // Some declarations have reserved names that we don't want to ever show. - if (const IdentifierInfo *Id = ND->getIdentifier()) { - // __va_list_tag is a freak of nature. Find it and skip it. - if (Id->isStr("__va_list_tag") || Id->isStr("__builtin_va_list")) - return false; - - // Filter out names reserved for the implementation (C99 7.1.3, - // C++ [lib.global.names]) if they come from a system header. - // - // FIXME: Add predicate for this. - if (Id->getLength() >= 2) { - const char *Name = Id->getNameStart(); - if (Name[0] == '_' && - (Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z')) && - (ND->getLocation().isInvalid() || - SemaRef.SourceMgr.isInSystemHeader( - SemaRef.SourceMgr.getSpellingLoc(ND->getLocation())))) + // Filter out names reserved for the implementation if they come from a + // system header. + // TODO: Add a predicate for this. + if (const IdentifierInfo *Id = ND->getIdentifier()) + if (isReservedName(Id) && + (ND->getLocation().isInvalid() || + SemaRef.SourceMgr.isInSystemHeader( + SemaRef.SourceMgr.getSpellingLoc(ND->getLocation())))) return false; - } - } if (Filter == &ResultBuilder::IsNestedNameSpecifier || ((isa(ND) || isa(ND)) &&