[llvm-branch-commits] [cfe-branch] r105039 - in /cfe/branches/Apple/whitney: lib/Sema/SemaCodeComplete.cpp test/Index/complete-at-directives.m test/Index/complete-exprs.c test/Index/complete-recovery.m

Daniel Dunbar daniel at zuster.org
Fri May 28 16:06:51 PDT 2010


Author: ddunbar
Date: Fri May 28 18:06:51 2010
New Revision: 105039

URL: http://llvm.org/viewvc/llvm-project?rev=105039&view=rev
Log:
Merge r104908:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Fri May 28 00:49:12 2010 +0000

    Do not produce types as valid code completions when we're in an
    expression context in C/Objective-C, or when we're in an
    @interface/@implementation/@protocol in Objective-C(++).

Modified:
    cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp
    cfe/branches/Apple/whitney/test/Index/complete-at-directives.m
    cfe/branches/Apple/whitney/test/Index/complete-exprs.c
    cfe/branches/Apple/whitney/test/Index/complete-recovery.m

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp?rev=105039&r1=105038&r2=105039&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp Fri May 28 18:06:51 2010
@@ -212,6 +212,7 @@
     /// 
     //@{
     bool IsOrdinaryName(NamedDecl *ND) const;
+    bool IsOrdinaryNonTypeName(NamedDecl *ND) const;
     bool IsOrdinaryNonValueName(NamedDecl *ND) const;
     bool IsNestedNameSpecifier(NamedDecl *ND) const;
     bool IsEnum(NamedDecl *ND) const;
@@ -646,6 +647,8 @@
 /// \brief Determines whether this given declaration will be found by
 /// ordinary name lookup.
 bool ResultBuilder::IsOrdinaryName(NamedDecl *ND) const {
+  ND = cast<NamedDecl>(ND->getUnderlyingDecl());
+
   unsigned IDNS = Decl::IDNS_Ordinary;
   if (SemaRef.getLangOptions().CPlusPlus)
     IDNS |= Decl::IDNS_Tag | Decl::IDNS_Namespace;
@@ -656,14 +659,33 @@
 }
 
 /// \brief Determines whether this given declaration will be found by
+/// ordinary name lookup but is not a type name.
+bool ResultBuilder::IsOrdinaryNonTypeName(NamedDecl *ND) const {
+  ND = cast<NamedDecl>(ND->getUnderlyingDecl());
+  if (isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND))
+    return false;
+  
+  unsigned IDNS = Decl::IDNS_Ordinary;
+  if (SemaRef.getLangOptions().CPlusPlus)
+    IDNS |= Decl::IDNS_Tag | Decl::IDNS_Namespace;
+  else if (SemaRef.getLangOptions().ObjC1 && isa<ObjCIvarDecl>(ND))
+    return true;
+  
+  return ND->getIdentifierNamespace() & IDNS;
+}
+
+/// \brief Determines whether this given declaration will be found by
 /// ordinary name lookup.
 bool ResultBuilder::IsOrdinaryNonValueName(NamedDecl *ND) const {
+  ND = cast<NamedDecl>(ND->getUnderlyingDecl());
+
   unsigned IDNS = Decl::IDNS_Ordinary;
   if (SemaRef.getLangOptions().CPlusPlus)
     IDNS |= Decl::IDNS_Tag | Decl::IDNS_Namespace;
   
   return (ND->getIdentifierNamespace() & IDNS) && 
-    !isa<ValueDecl>(ND) && !isa<FunctionTemplateDecl>(ND);
+    !isa<ValueDecl>(ND) && !isa<FunctionTemplateDecl>(ND) && 
+    !isa<ObjCPropertyDecl>(ND);
 }
 
 /// \brief Determines whether the given declaration is suitable as the 
@@ -973,6 +995,34 @@
   Results.AddResult(CodeCompleteConsumer::Result(Pattern));        
 }
 
+static bool WantTypesInContext(Action::CodeCompletionContext CCC,
+                               const LangOptions &LangOpts) {
+  if (LangOpts.CPlusPlus)
+    return true;
+  
+  switch (CCC) {
+  case Action::CCC_Namespace:
+  case Action::CCC_Class:
+  case Action::CCC_ObjCInstanceVariableList:
+  case Action::CCC_Template:
+  case Action::CCC_MemberTemplate:
+  case Action::CCC_Statement:
+  case Action::CCC_RecoveryInFunction:
+    return true;
+    
+  case Action::CCC_ObjCInterface:
+  case Action::CCC_ObjCImplementation:
+  case Action::CCC_Expression:
+  case Action::CCC_Condition:
+    return false;
+    
+  case Action::CCC_ForInit:
+    return LangOpts.ObjC1 || LangOpts.C99;
+  }
+  
+  return false;
+}
+
 /// \brief Add language constructs that show up for "ordinary" names.
 static void AddOrdinaryNameResults(Action::CodeCompletionContext CCC,
                                    Scope *S,
@@ -1431,7 +1481,8 @@
   }
   }
 
-  AddTypeSpecifierResults(SemaRef.getLangOptions(), Results);
+  if (WantTypesInContext(CCC, SemaRef.getLangOptions()))
+    AddTypeSpecifierResults(SemaRef.getLangOptions(), Results);
 
   if (SemaRef.getLangOptions().CPlusPlus)
     Results.AddResult(Result("operator"));
@@ -2057,7 +2108,10 @@
   case CCC_Statement:
   case CCC_ForInit:
   case CCC_Condition:
-    Results.setFilter(&ResultBuilder::IsOrdinaryName);
+    if (WantTypesInContext(CompletionContext, getLangOptions()))
+      Results.setFilter(&ResultBuilder::IsOrdinaryName);
+    else
+      Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
     break;
       
   case CCC_RecoveryInFunction:

Modified: cfe/branches/Apple/whitney/test/Index/complete-at-directives.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/complete-at-directives.m?rev=105039&r1=105038&r2=105039&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/complete-at-directives.m (original)
+++ cfe/branches/Apple/whitney/test/Index/complete-at-directives.m Fri May 28 18:06:51 2010
@@ -39,11 +39,6 @@
 // CHECK-CC5: {TypedText @optional}
 // CHECK-CC5: {TypedText @property}
 // CHECK-CC5: {TypedText @required}
-// CHECK-CC5: NotImplemented:{TypedText _Bool}
-// CHECK-CC5: TypedefDecl:{TypedText Class}
-// CHECK-CC5: TypedefDecl:{TypedText id}
-// CHECK-CC5: ObjCInterfaceDecl:{TypedText MyClass}
-// CHECK-CC5: TypedefDecl:{TypedText SEL}
 
 // RUN: c-index-test -code-completion-at=%s:2:23 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC6 %s
 // CHECK-CC6: NotImplemented:{TypedText package}

Modified: cfe/branches/Apple/whitney/test/Index/complete-exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/complete-exprs.c?rev=105039&r1=105038&r2=105039&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/complete-exprs.c (original)
+++ cfe/branches/Apple/whitney/test/Index/complete-exprs.c Fri May 28 18:06:51 2010
@@ -10,9 +10,15 @@
 // RUN: c-index-test -code-completion-at=%s:7:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
 // CHECK-CC1: macro definition:{TypedText __VERSION__} (70)
 // CHECK-CC1: FunctionDecl:{ResultType int}{TypedText f}{LeftParen (}{Placeholder int}{RightParen )} (50)
-// CHECK-CC1: NotImplemented:{TypedText float} (40)
+// CHECK-CC1-NOT: NotImplemented:{TypedText float} (40)
 // CHECK-CC1: ParmDecl:{ResultType int}{TypedText j} (8)
 // CHECK-CC1: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30)
 // RUN: c-index-test -code-completion-at=%s:7:14 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
 // RUN: c-index-test -code-completion-at=%s:7:18 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
 // RUN: c-index-test -code-completion-at=%s:7:22 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
+// RUN: c-index-test -code-completion-at=%s:7:2 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: macro definition:{TypedText __VERSION__} (70)
+// CHECK-CC2: FunctionDecl:{ResultType int}{TypedText f}{LeftParen (}{Placeholder int}{RightParen )} (50)
+// CHECK-CC2: NotImplemented:{TypedText float} (40)
+// CHECK-CC2: ParmDecl:{ResultType int}{TypedText j} (8)
+// CHECK-CC2: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (30)

Modified: cfe/branches/Apple/whitney/test/Index/complete-recovery.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/complete-recovery.m?rev=105039&r1=105038&r2=105039&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/complete-recovery.m (original)
+++ cfe/branches/Apple/whitney/test/Index/complete-recovery.m Fri May 28 18:06:51 2010
@@ -14,8 +14,12 @@
 // RUN: c-index-test -code-completion-at=%s:9:20 -Xclang -code-completion-patterns %s 2>%t | FileCheck -check-prefix=CHECK-CC1 %s
 // RUN: not grep error %t
 // CHECK-CC1: NotImplemented:{TypedText @encode}{LeftParen (}{Placeholder type-name}{RightParen )}
-// CHECK-CC1: NotImplemented:{TypedText _Bool}
+// CHECK-CC1-NOT: NotImplemented:{TypedText _Bool}
 // CHECK-CC1: VarDecl:{ResultType A *}{TypedText a}
 // CHECK-CC1: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )}
 
-// RUN: c-index-test -code-completion-at=%s:10:24 -Xclang -code-completion-patterns %s 2>%t | FileCheck -check-prefix=CHECK-CC1 %s
+// RUN: c-index-test -code-completion-at=%s:10:24 -Xclang -code-completion-patterns %s 2>%t | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: NotImplemented:{TypedText @encode}{LeftParen (}{Placeholder type-name}{RightParen )}
+// CHECK-CC2: NotImplemented:{TypedText _Bool}
+// CHECK-CC2: VarDecl:{ResultType A *}{TypedText a}
+// CHECK-CC2: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )}





More information about the llvm-branch-commits mailing list