From: Benjamin Kramer Date: Thu, 18 Feb 2016 15:30:24 +0000 (+0000) Subject: [Parse] Code complete expressions in bracket declarators. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=059e6e9ac25d4f748f86ef0ef7a6c26a35551f11;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261217 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index daea39bd1a..c5b9578b39 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -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 Args); void CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc, diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index c766ef30e6..64f00bfcfa 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -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. diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 12aec6caba..ab2e718c85 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -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 index 0000000000..cf80b424d1 --- /dev/null +++ b/test/CodeCompletion/bracket-decl.c @@ -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