]> granicus.if.org Git - clang/commitdiff
When code-completing within a list of declaration specifiers,
authorDouglas Gregor <dgregor@apple.com>
Tue, 15 Feb 2011 20:33:25 +0000 (20:33 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 15 Feb 2011 20:33:25 +0000 (20:33 +0000)
separately handle the case of a local declaration-specifier list,
including all types in the set of options. Fixes
<rdar://problem/8790735> and <rdar://problem/8662831>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125594 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/CodeCompleteConsumer.h
include/clang/Sema/Sema.h
lib/Parse/ParseDecl.cpp
lib/Sema/SemaCodeComplete.cpp
test/Index/complete-declarators.m

index 00e76eadaf83ba8c9f48f54236b8c22da2f56e17..4f28fb2cca641d3701b27b882823ce8307eab0f7 100644 (file)
@@ -146,7 +146,7 @@ class Sema;
 class CodeCompletionContext {
 public:
   enum Kind {
-    /// \brief An unspecified code-completion context, where the 
+    /// \brief An unspecified code-completion context.
     CCC_Other,
     /// \brief Code completion occurred within a "top-level" completion context,
     /// e.g., at namespace or global scope.
index 79362ce7107b14e2c1ff9922a57a9f636a0bb325..80b7952ad98324c65fd2c7b2c4da24fdfe741768 100644 (file)
@@ -4938,7 +4938,10 @@ public:
     PCC_Type,
     /// \brief Code completion occurs in a parenthesized expression, which
     /// might also be a type cast.
-    PCC_ParenthesizedExpression
+    PCC_ParenthesizedExpression,
+    /// \brief Code completion occurs within a sequence of declaration 
+    /// specifiers within a function, method, or block.
+    PCC_LocalDeclarationSpecifiers
   };
 
   void CodeCompleteOrdinaryName(Scope *S,
index b815031939833e082e196b6dd38c7c281593e651..bff4e184c2ae241f7cc60dc08e4ca220f4846dff 100644 (file)
@@ -920,7 +920,9 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
         return;
       } 
       
-      if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
+      if (getCurScope()->getFnParent() || getCurScope()->getBlockParent())
+        CCC = Sema::PCC_LocalDeclarationSpecifiers;
+      else if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
         CCC = DSContext == DSC_class? Sema::PCC_MemberTemplate 
                                     : Sema::PCC_Template;
       else if (DSContext == DSC_class)
index cf088007c88072442ed6a960bbed2ca97afe82e7..e7a9a8d83865d04018bcb041019fcdffd3b7a5ef 100644 (file)
@@ -1286,6 +1286,7 @@ static void AddFunctionSpecifiers(Sema::ParserCompletionContext CCC,
   case Sema::PCC_RecoveryInFunction:
   case Sema::PCC_Type:
   case Sema::PCC_ParenthesizedExpression:
+  case Sema::PCC_LocalDeclarationSpecifiers:
     break;
   }
 }
@@ -1325,6 +1326,7 @@ static bool WantTypesInContext(Sema::ParserCompletionContext CCC,
   case Sema::PCC_RecoveryInFunction:
   case Sema::PCC_Type:
   case Sema::PCC_ParenthesizedExpression:
+  case Sema::PCC_LocalDeclarationSpecifiers:
     return true;
     
   case Sema::PCC_Expression:
@@ -1768,6 +1770,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC,
   }
       
   case Sema::PCC_Type:
+  case Sema::PCC_LocalDeclarationSpecifiers:
     break;
   }
 
@@ -2719,6 +2722,9 @@ static enum CodeCompletionContext::Kind mapCodeCompletionContext(Sema &S,
 
   case Sema::PCC_ParenthesizedExpression:
     return CodeCompletionContext::CCC_ParenthesizedExpression;
+      
+  case Sema::PCC_LocalDeclarationSpecifiers:
+    return CodeCompletionContext::CCC_Type;
   }
   
   return CodeCompletionContext::CCC_Other;
@@ -2818,6 +2824,7 @@ void Sema::CodeCompleteOrdinaryName(Scope *S,
   case PCC_Template:
   case PCC_MemberTemplate:
   case PCC_Type:
+  case PCC_LocalDeclarationSpecifiers:
     Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
     break;
 
@@ -2873,6 +2880,7 @@ void Sema::CodeCompleteOrdinaryName(Scope *S,
   case PCC_ForInit:
   case PCC_Condition:
   case PCC_Type:
+  case PCC_LocalDeclarationSpecifiers:
     break;
   }
   
index bff5afd0f43cc87e846c56c720bb9c01d4c7657c..747da018af50e04b9a109c12133f021951b096df 100644 (file)
@@ -19,6 +19,8 @@
   for(q in param1) {
     int y;
   }
+
+  static P *p = 0;
 }
 @end
 
 // CHECK-CC4-NOT: VarDecl:{ResultType int}{TypedText q2}
 // CHECK-CC4: NotImplemented:{ResultType A *}{TypedText self} (34)
 // CHECK-CC4: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (40)
+// RUN: c-index-test -code-completion-at=%s:23:10 %s | FileCheck -check-prefix=CHECK-CC5 %s
+// CHECK-CC5: NotImplemented:{TypedText _Bool} (50)
+// CHECK-CC5: NotImplemented:{TypedText _Complex} (50)
+// CHECK-CC5: NotImplemented:{TypedText _Imaginary} (50)
+// CHECK-CC5: ObjCInterfaceDecl:{TypedText A} (50)
+// CHECK-CC5: NotImplemented:{TypedText char} (50)
+// CHECK-CC5: TypedefDecl:{TypedText Class} (50)
+// CHECK-CC5: NotImplemented:{TypedText const} (50)
+// CHECK-CC5: NotImplemented:{TypedText double} (50)
+// CHECK-CC5: NotImplemented:{TypedText enum} (50)
+// CHECK-CC5: NotImplemented:{TypedText float} (50)
+// CHECK-CC5: TypedefDecl:{TypedText id} (50)
+// CHECK-CC5: NotImplemented:{TypedText int} (50)
+// CHECK-CC5: NotImplemented:{TypedText long} (50)
+// CHECK-CC5: NotImplemented:{TypedText restrict} (50)
+// CHECK-CC5: TypedefDecl:{TypedText SEL} (50)
+// CHECK-CC5: NotImplemented:{TypedText short} (50)
+// CHECK-CC5: NotImplemented:{TypedText signed} (50)
+// CHECK-CC5: NotImplemented:{TypedText struct} (50)
+// CHECK-CC5: NotImplemented:{TypedText typeof}{HorizontalSpace  }{Placeholder expression} (40)
+// CHECK-CC5: NotImplemented:{TypedText typeof}{LeftParen (}{Placeholder type}{RightParen )} (40)
+// CHECK-CC5: NotImplemented:{TypedText union} (50)
+// CHECK-CC5: NotImplemented:{TypedText unsigned} (50)
+// CHECK-CC5: NotImplemented:{TypedText void} (50)
+// CHECK-CC5: NotImplemented:{TypedText volatile} (50)