r261217 - [Parse] Code complete expressions in bracket declarators.

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 18 07:30:24 PST 2016


Author: d0k
Date: Thu Feb 18 09:30:24 2016
New Revision: 261217

URL: http://llvm.org/viewvc/llvm-project?rev=261217&view=rev
Log:
[Parse] Code complete expressions in bracket declarators.

Currently we return no results when completing inside of the brackets in
a 'char foo[]' declaration. Let the generic expression completion code
handle it instead. We could get fancier here (e.g. filter non-constant
expressions in contexts where VLAs are not allowed), but it's a strict
improvement over the existing version.

Added:
    cfe/trunk/test/CodeCompletion/bracket-decl.c
Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=261217&r1=261216&r2=261217&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Feb 18 09:30:24 2016
@@ -8922,6 +8922,7 @@ public:
   void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
   void CodeCompleteTag(Scope *S, unsigned TagSpec);
   void CodeCompleteTypeQualifiers(DeclSpec &DS);
+  void CodeCompleteBracketDeclarator(Scope *S);
   void CodeCompleteCase(Scope *S);
   void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef<Expr *> Args);
   void CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=261217&r1=261216&r2=261217&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Feb 18 09:30:24 2016
@@ -6030,6 +6030,9 @@ void Parser::ParseBracketDeclarator(Decl
                                             T.getCloseLocation()),
                   attrs, T.getCloseLocation());
     return;
+  } else if (Tok.getKind() == tok::code_completion) {
+    Actions.CodeCompleteBracketDeclarator(getCurScope());
+    return cutOffParsing();
   }
 
   // If valid, this location is the position where we read the 'static' keyword.

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=261217&r1=261216&r2=261217&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Feb 18 09:30:24 2016
@@ -3818,6 +3818,10 @@ void Sema::CodeCompleteTypeQualifiers(De
                             Results.data(), Results.size());
 }
 
+void Sema::CodeCompleteBracketDeclarator(Scope *S) {
+  CodeCompleteExpression(S, QualType(getASTContext().getSizeType()));
+}
+
 void Sema::CodeCompleteCase(Scope *S) {
   if (getCurFunction()->SwitchStack.empty() || !CodeCompleter)
     return;

Added: cfe/trunk/test/CodeCompletion/bracket-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/bracket-decl.c?rev=261217&view=auto
==============================================================================
--- cfe/trunk/test/CodeCompletion/bracket-decl.c (added)
+++ cfe/trunk/test/CodeCompletion/bracket-decl.c Thu Feb 18 09:30:24 2016
@@ -0,0 +1,9 @@
+#define PATHSIZE 256
+
+static const int len = 1234;
+
+void foo() {
+  char arr[
+// RUN: %clang_cc1 -fsyntax-only -code-completion-macros -code-completion-at=%s:6:12 %s -o - | FileCheck %s
+// CHECK: COMPLETION: len
+// CHECK: COMPLETION: PATHSIZE




More information about the cfe-commits mailing list