]> granicus.if.org Git - clang/commitdiff
Extract an isReservedName() function
authorAlp Toker <alp@nuanti.com>
Mon, 30 Jun 2014 01:33:53 +0000 (01:33 +0000)
committerAlp Toker <alp@nuanti.com>
Mon, 30 Jun 2014 01:33:53 +0000 (01:33 +0000)
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

lib/Sema/SemaCodeComplete.cpp

index f441befcfbf95b2b179c26a19d123d43c7ca7d2a..e2149eddd4494a7c2ad792f7fe62964e1b74e5cd 100644 (file)
@@ -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<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND)) &&