[cfe-commits] r82481 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseDecl.cpp lib/Parse/ParseExpr.cpp lib/Parse/ParseStmt.cpp lib/Parse/Parser.cpp lib/Sema/Sema.h lib/Sema/SemaCodeComplete.cpp test/CodeCompletion/ordinary-name.c
Douglas Gregor
dgregor at apple.com
Mon Sep 21 13:51:26 PDT 2009
Author: dgregor
Date: Mon Sep 21 15:51:25 2009
New Revision: 82481
URL: http://llvm.org/viewvc/llvm-project?rev=82481&view=rev
Log:
Code completion for ordinary names when we're starting a declaration, expression, or statement
Added:
cfe/trunk/test/CodeCompletion/ordinary-name.c
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=82481&r1=82480&r2=82481&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Mon Sep 21 15:51:25 2009
@@ -2192,9 +2192,19 @@
/// found at a point in the grammar where the Action implementation is
/// likely to be able to provide a list of possible completions, e.g.,
/// after the "." or "->" of a member access expression.
- ///
+ ///
+ /// \todo Code completion for designated field initializers
+ /// \todo Code completion for call arguments after a function template-id
+ /// \todo Code completion within a call expression, object construction, etc.
+ /// \todo Code completion within a template argument list.
//@{
+ /// \brief Code completion for an ordinary name that occurs within the given
+ /// scope.
+ ///
+ /// \param S the scope in which the name occurs.
+ virtual void CodeCompleteOrdinaryName(Scope *S) { }
+
/// \brief Code completion for a member access expression.
///
/// This code completion action is invoked when the code-completion token
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=82481&r1=82480&r2=82481&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Sep 21 15:51:25 2009
@@ -710,6 +710,11 @@
const ParsedTemplateInfo &TemplateInfo,
AccessSpecifier AS,
DeclSpecContext DSContext) {
+ if (Tok.is(tok::code_completion)) {
+ Actions.CodeCompleteOrdinaryName(CurScope);
+ ConsumeToken();
+ }
+
DS.SetRangeStart(Tok.getLocation());
while (1) {
bool isInvalid = false;
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=82481&r1=82480&r2=82481&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Mon Sep 21 15:51:25 2009
@@ -200,6 +200,11 @@
/// expression ',' assignment-expression
///
Parser::OwningExprResult Parser::ParseExpression() {
+ if (Tok.is(tok::code_completion)) {
+ Actions.CodeCompleteOrdinaryName(CurScope);
+ ConsumeToken();
+ }
+
OwningExprResult LHS(ParseAssignmentExpression());
if (LHS.isInvalid()) return move(LHS);
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=82481&r1=82480&r2=82481&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Mon Sep 21 15:51:25 2009
@@ -90,6 +90,11 @@
return ParseObjCAtStatement(AtLoc);
}
+ case tok::code_completion:
+ Actions.CodeCompleteOrdinaryName(CurScope);
+ ConsumeToken();
+ return ParseStatementOrDeclaration(OnlyStatement);
+
case tok::identifier:
if (NextToken().is(tok::colon)) { // C99 6.8.1: labeled-statement
// identifier ':' statement
@@ -918,6 +923,11 @@
OwningStmtResult FirstPart(Actions);
OwningExprResult SecondPart(Actions), ThirdPart(Actions);
+ if (Tok.is(tok::code_completion)) {
+ Actions.CodeCompleteOrdinaryName(CurScope);
+ ConsumeToken();
+ }
+
// Parse the first part of the for specifier.
if (Tok.is(tok::semi)) { // for (;
// no first part, eat the ';'.
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=82481&r1=82480&r2=82481&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Mon Sep 21 15:51:25 2009
@@ -442,6 +442,10 @@
}
SingleDecl = ParseObjCMethodDefinition();
break;
+ case tok::code_completion:
+ Actions.CodeCompleteOrdinaryName(CurScope);
+ ConsumeToken();
+ return ParseExternalDeclaration();
case tok::kw_using:
case tok::kw_namespace:
case tok::kw_typedef:
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=82481&r1=82480&r2=82481&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon Sep 21 15:51:25 2009
@@ -3629,6 +3629,7 @@
/// \name Code completion
//@{
void setCodeCompleteConsumer(CodeCompleteConsumer *CCC);
+ virtual void CodeCompleteOrdinaryName(Scope *S);
virtual void CodeCompleteMemberReferenceExpr(Scope *S, ExprTy *Base,
SourceLocation OpLoc,
bool IsArrow);
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=82481&r1=82480&r2=82481&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Sep 21 15:51:25 2009
@@ -104,6 +104,7 @@
/// results of name lookup. All of the predicates have the same type, so that
///
//@{
+ bool IsOrdinaryName(NamedDecl *ND) const;
bool IsNestedNameSpecifier(NamedDecl *ND) const;
bool IsEnum(NamedDecl *ND) const;
bool IsClassOrStruct(NamedDecl *ND) const;
@@ -316,6 +317,16 @@
ShadowMaps.pop_back();
}
+/// \brief Determines whether this given declaration will be found by
+/// ordinary name lookup.
+bool ResultBuilder::IsOrdinaryName(NamedDecl *ND) const {
+ unsigned IDNS = Decl::IDNS_Ordinary;
+ if (SemaRef.getLangOptions().CPlusPlus)
+ IDNS |= Decl::IDNS_Tag;
+
+ return ND->getIdentifierNamespace() & IDNS;
+}
+
/// \brief Determines whether the given declaration is suitable as the
/// start of a C++ nested-name-specifier, e.g., a class or namespace.
bool ResultBuilder::IsNestedNameSpecifier(NamedDecl *ND) const {
@@ -874,6 +885,13 @@
CodeCompleter->ProcessCodeCompleteResults(Results, NumResults);
}
+void Sema::CodeCompleteOrdinaryName(Scope *S) {
+ ResultBuilder Results(*this, &ResultBuilder::IsOrdinaryName);
+ CollectLookupResults(S, Context.getTranslationUnitDecl(), 0, CurContext,
+ Results);
+ HandleCodeCompleteResults(CodeCompleter, Results.data(), Results.size());
+}
+
void Sema::CodeCompleteMemberReferenceExpr(Scope *S, ExprTy *BaseE,
SourceLocation OpLoc,
bool IsArrow) {
Added: cfe/trunk/test/CodeCompletion/ordinary-name.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/ordinary-name.c?rev=82481&view=auto
==============================================================================
--- cfe/trunk/test/CodeCompletion/ordinary-name.c (added)
+++ cfe/trunk/test/CodeCompletion/ordinary-name.c Mon Sep 21 15:51:25 2009
@@ -0,0 +1,12 @@
+// RUN: clang-cc -fsyntax-only -code-completion-dump=1 %s -o - | FileCheck -check-prefix=CC1 %s &&
+// RUN: true
+
+struct X { int x; };
+
+typedef struct X TYPEDEF;
+
+void foo() {
+ int y;
+ // CHECK-CC1: y : 0
+ // CHECK-NEXT-CC1: TYPEDEF : 2
+ // CHECK-NEXT-CC1: foo : 2
More information about the cfe-commits
mailing list