Initial implementation of a code-completion interface in Clang. In
essence, code completion is triggered by a magic "code completion"
token produced by the lexer [*], which the parser recognizes at
certain points in the grammar. The parser then calls into the Action
object with the appropriate CodeCompletionXXX action.
Sema implements the CodeCompletionXXX callbacks by performing minimal
translation, then forwarding them to a CodeCompletionConsumer
subclass, which uses the results of semantic analysis to provide
code-completion results. At present, only a single, "printing" code
completion consumer is available, for regression testing and
debugging. However, the design is meant to permit other
code-completion consumers.
This initial commit contains two code-completion actions: one for
member access, e.g., "x." or "p->", and one for
nested-name-specifiers, e.g., "std::". More code-completion actions
will follow, along with improved gathering of code-completion results
for the various contexts.
[*] In the current -code-completion-dump testing/debugging mode, the
file is truncated at the completion point and EOF is translated into
"code completion".
llvm-svn: 82166
2009-09-18 05:32:03 +08:00
|
|
|
//===---------------- SemaCodeComplete.cpp - Code Completion ----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the code-completion semantic actions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "Sema.h"
|
|
|
|
#include "clang/Sema/CodeCompleteConsumer.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
/// \brief Set the code-completion consumer for semantic analysis.
|
|
|
|
void Sema::setCodeCompleteConsumer(CodeCompleteConsumer *CCC) {
|
|
|
|
assert(((CodeCompleter != 0) != (CCC != 0)) &&
|
|
|
|
"Already set or cleared a code-completion consumer?");
|
|
|
|
CodeCompleter = CCC;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteMemberReferenceExpr(Scope *S, ExprTy *BaseE,
|
|
|
|
SourceLocation OpLoc,
|
|
|
|
bool IsArrow) {
|
|
|
|
if (!BaseE || !CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Expr *Base = static_cast<Expr *>(BaseE);
|
|
|
|
QualType BaseType = Base->getType();
|
|
|
|
|
|
|
|
CodeCompleter->CodeCompleteMemberReferenceExpr(S, BaseType, IsArrow);
|
|
|
|
}
|
|
|
|
|
2009-09-18 23:37:17 +08:00
|
|
|
void Sema::CodeCompleteTag(Scope *S, unsigned TagSpec) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TagDecl::TagKind TK;
|
|
|
|
switch ((DeclSpec::TST)TagSpec) {
|
|
|
|
case DeclSpec::TST_enum:
|
|
|
|
TK = TagDecl::TK_enum;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclSpec::TST_union:
|
|
|
|
TK = TagDecl::TK_union;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclSpec::TST_struct:
|
|
|
|
TK = TagDecl::TK_struct;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclSpec::TST_class:
|
|
|
|
TK = TagDecl::TK_class;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(false && "Unknown type specifier kind in CodeCompleteTag");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CodeCompleter->CodeCompleteTag(S, TK);
|
|
|
|
}
|
|
|
|
|
Initial implementation of a code-completion interface in Clang. In
essence, code completion is triggered by a magic "code completion"
token produced by the lexer [*], which the parser recognizes at
certain points in the grammar. The parser then calls into the Action
object with the appropriate CodeCompletionXXX action.
Sema implements the CodeCompletionXXX callbacks by performing minimal
translation, then forwarding them to a CodeCompletionConsumer
subclass, which uses the results of semantic analysis to provide
code-completion results. At present, only a single, "printing" code
completion consumer is available, for regression testing and
debugging. However, the design is meant to permit other
code-completion consumers.
This initial commit contains two code-completion actions: one for
member access, e.g., "x." or "p->", and one for
nested-name-specifiers, e.g., "std::". More code-completion actions
will follow, along with improved gathering of code-completion results
for the various contexts.
[*] In the current -code-completion-dump testing/debugging mode, the
file is truncated at the completion point and EOF is translated into
"code completion".
llvm-svn: 82166
2009-09-18 05:32:03 +08:00
|
|
|
void Sema::CodeCompleteQualifiedId(Scope *S, const CXXScopeSpec &SS,
|
|
|
|
bool EnteringContext) {
|
|
|
|
if (!SS.getScopeRep() || !CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CodeCompleter->CodeCompleteQualifiedId(S,
|
|
|
|
(NestedNameSpecifier *)SS.getScopeRep(),
|
|
|
|
EnteringContext);
|
|
|
|
}
|
2009-09-19 03:03:04 +08:00
|
|
|
|
|
|
|
void Sema::CodeCompleteUsing(Scope *S) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CodeCompleter->CodeCompleteUsing(S);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteUsingDirective(Scope *S) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CodeCompleter->CodeCompleteUsingDirective(S);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteNamespaceDecl(Scope *S) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CodeCompleter->CodeCompleteNamespaceDecl(S);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteNamespaceAliasDecl(Scope *S) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CodeCompleter->CodeCompleteNamespaceAliasDecl(S);
|
|
|
|
}
|
|
|
|
|
|
|
|
|