]> granicus.if.org Git - clang/commitdiff
[Parse] Code complete expressions in bracket declarators.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 18 Feb 2016 15:30:24 +0000 (15:30 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 18 Feb 2016 15:30:24 +0000 (15:30 +0000)
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.

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

include/clang/Sema/Sema.h
lib/Parse/ParseDecl.cpp
lib/Sema/SemaCodeComplete.cpp
test/CodeCompletion/bracket-decl.c [new file with mode: 0644]

index daea39bd1a03a0be870c3a394801c6406d15315f..c5b9578b3900073bdb350db035947079d24d3632 100644 (file)
@@ -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,
index c766ef30e627a7729ed17496be5845af45b53a30..64f00bfcfa5b798486bd95f73d864e3598a995a2 100644 (file)
@@ -6030,6 +6030,9 @@ void Parser::ParseBracketDeclarator(Declarator &D) {
                                             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.
index 12aec6caba904a0960117ba7f88e0c0b8eb3ce3f..ab2e718c851ad68d759002e65f10c12baafb2496 100644 (file)
@@ -3818,6 +3818,10 @@ void Sema::CodeCompleteTypeQualifiers(DeclSpec &DS) {
                             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;
diff --git a/test/CodeCompletion/bracket-decl.c b/test/CodeCompletion/bracket-decl.c
new file mode 100644 (file)
index 0000000..cf80b42
--- /dev/null
@@ -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