[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
This commit is contained in:
Benjamin Kramer 2016-02-18 15:30:24 +00:00
parent 9ac4380629
commit 059e6e9ac2
4 changed files with 17 additions and 0 deletions

View 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,

View 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.

View 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;

View File

@ -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