[cfe-commits] r112274 - in /cfe/trunk: include/clang/Sema/CodeCompleteConsumer.h include/clang/Sema/Sema.h lib/Frontend/ASTUnit.cpp lib/Parse/ParseDecl.cpp lib/Sema/SemaCodeComplete.cpp test/Index/complete-memfunc-cvquals.cpp
Douglas Gregor
dgregor at apple.com
Fri Aug 27 10:35:51 PDT 2010
Author: dgregor
Date: Fri Aug 27 12:35:51 2010
New Revision: 112274
URL: http://llvm.org/viewvc/llvm-project?rev=112274&view=rev
Log:
Suggest "const" and "volatile" code completions after a function
declarator, the very definition of "low-hanging fruit".
Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/Index/complete-memfunc-cvquals.cpp
Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=112274&r1=112273&r2=112274&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Fri Aug 27 12:35:51 2010
@@ -201,7 +201,9 @@
/// unless they come from an appropriate natural-language dictionary.
CCC_NaturalLanguage,
/// \brief Code completion for a selector, as in an @selector expression.
- CCC_SelectorName
+ CCC_SelectorName,
+ /// \brief Code completion within a type-qualifier list.
+ CCC_TypeQualifiers
};
private:
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=112274&r1=112273&r2=112274&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Aug 27 12:35:51 2010
@@ -4332,6 +4332,7 @@
SourceLocation OpLoc,
bool IsArrow);
virtual void CodeCompleteTag(Scope *S, unsigned TagSpec);
+ virtual void CodeCompleteTypeQualifiers(DeclSpec &DS);
virtual void CodeCompleteCase(Scope *S);
virtual void CodeCompleteCall(Scope *S, Expr *Fn,
Expr **Args, unsigned NumArgs);
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=112274&r1=112273&r2=112274&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Aug 27 12:35:51 2010
@@ -1555,6 +1555,7 @@
case CodeCompletionContext::CCC_PreprocessorDirective:
case CodeCompletionContext::CCC_NaturalLanguage:
case CodeCompletionContext::CCC_SelectorName:
+ case CodeCompletionContext::CCC_TypeQualifiers:
// We're looking for nothing, or we're looking for names that cannot
// be hidden.
return;
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=112274&r1=112273&r2=112274&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Aug 27 12:35:51 2010
@@ -2442,6 +2442,11 @@
SourceLocation Loc = Tok.getLocation();
switch (Tok.getKind()) {
+ case tok::code_completion:
+ Actions.CodeCompleteTypeQualifiers(DS);
+ ConsumeCodeCompletionToken();
+ break;
+
case tok::kw_const:
isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec, DiagID,
getLang());
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=112274&r1=112273&r2=112274&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Aug 27 12:35:51 2010
@@ -2761,6 +2761,22 @@
Results.data(),Results.size());
}
+void Sema::CodeCompleteTypeQualifiers(DeclSpec &DS) {
+ ResultBuilder Results(*this);
+ Results.EnterNewScope();
+ if (!(DS.getTypeQualifiers() & DeclSpec::TQ_const))
+ Results.AddResult("const");
+ if (!(DS.getTypeQualifiers() & DeclSpec::TQ_volatile))
+ Results.AddResult("volatile");
+ if (getLangOptions().C99 &&
+ !(DS.getTypeQualifiers() & DeclSpec::TQ_restrict))
+ Results.AddResult("restrict");
+ Results.ExitScope();
+ HandleCodeCompleteResults(this, CodeCompleter,
+ CodeCompletionContext::CCC_TypeQualifiers,
+ Results.data(), Results.size());
+}
+
void Sema::CodeCompleteCase(Scope *S) {
if (getCurFunction()->SwitchStack.empty() || !CodeCompleter)
return;
Modified: cfe/trunk/test/Index/complete-memfunc-cvquals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-memfunc-cvquals.cpp?rev=112274&r1=112273&r2=112274&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-memfunc-cvquals.cpp (original)
+++ cfe/trunk/test/Index/complete-memfunc-cvquals.cpp Fri Aug 27 12:35:51 2010
@@ -76,3 +76,11 @@
// CHECK-IMPLICIT-VOLATILE: FunctionDecl:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (15)
// CHECK-IMPLICIT-VOLATILE-NOT: baz
// CHECK-IMPLICIT-VOLATILE: FunctionDecl:{ResultType void}{TypedText bingo}{LeftParen (}{RightParen )}{Informative volatile} (14)
+
+// RUN: c-index-test -code-completion-at=%s:4:17 %s | FileCheck -check-prefix=CHECK-CVQUAL-AFTER %s
+// CHECK-CVQUAL-AFTER: NotImplemented:{TypedText const} (30)
+// CHECK-CVQUAL-AFTER: NotImplemented:{TypedText volatile} (30)
+
+// RUN: c-index-test -code-completion-at=%s:4:23 %s | FileCheck -check-prefix=CHECK-CVQUAL-AFTER2 %s
+// CHECK-CVQUAL-AFTER2-NOT: NotImplemented:{TypedText const} (30)
+// CHECK-CVQUAL-AFTER2: NotImplemented:{TypedText volatile} (30)
More information about the cfe-commits
mailing list