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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-08-26 06:03:47 +08:00
|
|
|
#include "clang/Sema/SemaInternal.h"
|
2010-08-13 04:07:10 +08:00
|
|
|
#include "clang/Sema/Lookup.h"
|
2010-08-25 04:38:10 +08:00
|
|
|
#include "clang/Sema/Overload.h"
|
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
|
|
|
#include "clang/Sema/CodeCompleteConsumer.h"
|
2010-04-07 01:30:22 +08:00
|
|
|
#include "clang/Sema/ExternalSemaSource.h"
|
2010-08-24 16:50:51 +08:00
|
|
|
#include "clang/Sema/Scope.h"
|
2010-08-25 16:40:02 +08:00
|
|
|
#include "clang/Sema/ScopeInfo.h"
|
2010-08-24 15:21:54 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2009-09-22 03:57:38 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2009-11-18 01:59:40 +08:00
|
|
|
#include "clang/AST/ExprObjC.h"
|
2009-10-31 00:50:04 +08:00
|
|
|
#include "clang/Lex/MacroInfo.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2010-09-17 00:06:31 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2009-09-22 00:56:56 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2009-09-28 11:51:44 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2010-04-07 03:22:33 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2010-08-26 23:07:07 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2009-09-22 00:56:56 +08:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
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
|
|
|
|
|
|
|
using namespace clang;
|
2010-08-25 16:40:02 +08:00
|
|
|
using namespace sema;
|
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
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
namespace {
|
|
|
|
/// \brief A container of code-completion results.
|
|
|
|
class ResultBuilder {
|
|
|
|
public:
|
|
|
|
/// \brief The type of a name-lookup filter, which can be provided to the
|
|
|
|
/// name-lookup routines to specify which declarations should be included in
|
|
|
|
/// the result set (when it returns true) and which declarations should be
|
|
|
|
/// filtered out (returns false).
|
|
|
|
typedef bool (ResultBuilder::*LookupFilter)(NamedDecl *) const;
|
|
|
|
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// \brief The actual results we have found.
|
|
|
|
std::vector<Result> Results;
|
|
|
|
|
|
|
|
/// \brief A record of all of the declarations we have found and placed
|
|
|
|
/// into the result set, used to ensure that no declaration ever gets into
|
|
|
|
/// the result set twice.
|
|
|
|
llvm::SmallPtrSet<Decl*, 16> AllDeclsFound;
|
|
|
|
|
2009-12-07 04:23:50 +08:00
|
|
|
typedef std::pair<NamedDecl *, unsigned> DeclIndexPair;
|
|
|
|
|
|
|
|
/// \brief An entry in the shadow map, which is optimized to store
|
|
|
|
/// a single (declaration, index) mapping (the common case) but
|
|
|
|
/// can also store a list of (declaration, index) mappings.
|
|
|
|
class ShadowMapEntry {
|
|
|
|
typedef llvm::SmallVector<DeclIndexPair, 4> DeclIndexPairVector;
|
|
|
|
|
|
|
|
/// \brief Contains either the solitary NamedDecl * or a vector
|
|
|
|
/// of (declaration, index) pairs.
|
|
|
|
llvm::PointerUnion<NamedDecl *, DeclIndexPairVector*> DeclOrVector;
|
|
|
|
|
|
|
|
/// \brief When the entry contains a single declaration, this is
|
|
|
|
/// the index associated with that entry.
|
|
|
|
unsigned SingleDeclIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ShadowMapEntry() : DeclOrVector(), SingleDeclIndex(0) { }
|
|
|
|
|
|
|
|
void Add(NamedDecl *ND, unsigned Index) {
|
|
|
|
if (DeclOrVector.isNull()) {
|
|
|
|
// 0 - > 1 elements: just set the single element information.
|
|
|
|
DeclOrVector = ND;
|
|
|
|
SingleDeclIndex = Index;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NamedDecl *PrevND = DeclOrVector.dyn_cast<NamedDecl *>()) {
|
|
|
|
// 1 -> 2 elements: create the vector of results and push in the
|
|
|
|
// existing declaration.
|
|
|
|
DeclIndexPairVector *Vec = new DeclIndexPairVector;
|
|
|
|
Vec->push_back(DeclIndexPair(PrevND, SingleDeclIndex));
|
|
|
|
DeclOrVector = Vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the new element to the end of the vector.
|
|
|
|
DeclOrVector.get<DeclIndexPairVector*>()->push_back(
|
|
|
|
DeclIndexPair(ND, Index));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Destroy() {
|
|
|
|
if (DeclIndexPairVector *Vec
|
|
|
|
= DeclOrVector.dyn_cast<DeclIndexPairVector *>()) {
|
|
|
|
delete Vec;
|
|
|
|
DeclOrVector = ((NamedDecl *)0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iteration.
|
|
|
|
class iterator;
|
|
|
|
iterator begin() const;
|
|
|
|
iterator end() const;
|
|
|
|
};
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \brief A mapping from declaration names to the declarations that have
|
|
|
|
/// this name within a particular scope and their index within the list of
|
|
|
|
/// results.
|
2009-12-07 04:23:50 +08:00
|
|
|
typedef llvm::DenseMap<DeclarationName, ShadowMapEntry> ShadowMap;
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
/// \brief The semantic analysis object for which results are being
|
|
|
|
/// produced.
|
|
|
|
Sema &SemaRef;
|
|
|
|
|
|
|
|
/// \brief If non-NULL, a filter function used to remove any code-completion
|
|
|
|
/// results that are not desirable.
|
|
|
|
LookupFilter Filter;
|
2010-01-14 11:21:49 +08:00
|
|
|
|
|
|
|
/// \brief Whether we should allow declarations as
|
|
|
|
/// nested-name-specifiers that would otherwise be filtered out.
|
|
|
|
bool AllowNestedNameSpecifiers;
|
|
|
|
|
2010-05-30 09:49:25 +08:00
|
|
|
/// \brief If set, the type that we would prefer our resulting value
|
|
|
|
/// declarations to have.
|
|
|
|
///
|
|
|
|
/// Closely matching the preferred type gives a boost to a result's
|
|
|
|
/// priority.
|
|
|
|
CanQualType PreferredType;
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \brief A list of shadow maps, which is used to model name hiding at
|
|
|
|
/// different levels of, e.g., the inheritance hierarchy.
|
|
|
|
std::list<ShadowMap> ShadowMaps;
|
|
|
|
|
2010-08-27 00:36:48 +08:00
|
|
|
/// \brief If we're potentially referring to a C++ member function, the set
|
|
|
|
/// of qualifiers applied to the object type.
|
|
|
|
Qualifiers ObjectTypeQualifiers;
|
|
|
|
|
|
|
|
/// \brief Whether the \p ObjectTypeQualifiers field is active.
|
|
|
|
bool HasObjectTypeQualifiers;
|
|
|
|
|
2010-08-27 23:29:55 +08:00
|
|
|
/// \brief The selector that we prefer.
|
|
|
|
Selector PreferredSelector;
|
|
|
|
|
2010-11-03 04:36:02 +08:00
|
|
|
/// \brief The completion context in which we are gathering results.
|
2010-09-21 06:39:41 +08:00
|
|
|
CodeCompletionContext CompletionContext;
|
|
|
|
|
2010-11-03 04:36:02 +08:00
|
|
|
/// \brief If we are in an instance method definition, the @implementation
|
|
|
|
/// object.
|
|
|
|
ObjCImplementationDecl *ObjCImplementation;
|
|
|
|
|
2010-09-21 06:39:41 +08:00
|
|
|
void AdjustResultPriorityForDecl(Result &R);
|
2010-07-09 07:20:03 +08:00
|
|
|
|
2010-09-22 00:06:22 +08:00
|
|
|
void MaybeAddConstructorResults(Result R);
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
public:
|
2010-09-24 07:01:17 +08:00
|
|
|
explicit ResultBuilder(Sema &SemaRef,
|
|
|
|
const CodeCompletionContext &CompletionContext,
|
|
|
|
LookupFilter Filter = 0)
|
2010-08-27 00:36:48 +08:00
|
|
|
: SemaRef(SemaRef), Filter(Filter), AllowNestedNameSpecifiers(false),
|
2010-09-21 06:39:41 +08:00
|
|
|
HasObjectTypeQualifiers(false),
|
2010-11-03 04:36:02 +08:00
|
|
|
CompletionContext(CompletionContext),
|
|
|
|
ObjCImplementation(0)
|
|
|
|
{
|
|
|
|
// If this is an Objective-C instance method definition, dig out the
|
|
|
|
// corresponding implementation.
|
|
|
|
switch (CompletionContext.getKind()) {
|
|
|
|
case CodeCompletionContext::CCC_Expression:
|
|
|
|
case CodeCompletionContext::CCC_ObjCMessageReceiver:
|
|
|
|
case CodeCompletionContext::CCC_ParenthesizedExpression:
|
|
|
|
case CodeCompletionContext::CCC_Statement:
|
|
|
|
case CodeCompletionContext::CCC_Recovery:
|
|
|
|
if (ObjCMethodDecl *Method = SemaRef.getCurMethodDecl())
|
|
|
|
if (Method->isInstanceMethod())
|
|
|
|
if (ObjCInterfaceDecl *Interface = Method->getClassInterface())
|
|
|
|
ObjCImplementation = Interface->getImplementation();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2010-05-26 05:41:55 +08:00
|
|
|
/// \brief Whether we should include code patterns in the completion
|
|
|
|
/// results.
|
|
|
|
bool includeCodePatterns() const {
|
|
|
|
return SemaRef.CodeCompleter &&
|
2010-08-28 05:18:54 +08:00
|
|
|
SemaRef.CodeCompleter->includeCodePatterns();
|
2010-05-26 05:41:55 +08:00
|
|
|
}
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \brief Set the filter used for code-completion results.
|
|
|
|
void setFilter(LookupFilter Filter) {
|
|
|
|
this->Filter = Filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result *data() { return Results.empty()? 0 : &Results.front(); }
|
|
|
|
unsigned size() const { return Results.size(); }
|
|
|
|
bool empty() const { return Results.empty(); }
|
|
|
|
|
2010-05-30 09:49:25 +08:00
|
|
|
/// \brief Specify the preferred type.
|
|
|
|
void setPreferredType(QualType T) {
|
|
|
|
PreferredType = SemaRef.Context.getCanonicalType(T);
|
|
|
|
}
|
|
|
|
|
2010-08-27 00:36:48 +08:00
|
|
|
/// \brief Set the cv-qualifiers on the object type, for us in filtering
|
|
|
|
/// calls to member functions.
|
|
|
|
///
|
|
|
|
/// When there are qualifiers in this set, they will be used to filter
|
|
|
|
/// out member functions that aren't available (because there will be a
|
|
|
|
/// cv-qualifier mismatch) or prefer functions with an exact qualifier
|
|
|
|
/// match.
|
|
|
|
void setObjectTypeQualifiers(Qualifiers Quals) {
|
|
|
|
ObjectTypeQualifiers = Quals;
|
|
|
|
HasObjectTypeQualifiers = true;
|
|
|
|
}
|
|
|
|
|
2010-08-27 23:29:55 +08:00
|
|
|
/// \brief Set the preferred selector.
|
|
|
|
///
|
|
|
|
/// When an Objective-C method declaration result is added, and that
|
|
|
|
/// method's selector matches this preferred selector, we give that method
|
|
|
|
/// a slight priority boost.
|
|
|
|
void setPreferredSelector(Selector Sel) {
|
|
|
|
PreferredSelector = Sel;
|
|
|
|
}
|
2010-11-03 04:36:02 +08:00
|
|
|
|
2010-09-21 06:39:41 +08:00
|
|
|
/// \brief Retrieve the code-completion context for which results are
|
|
|
|
/// being collected.
|
|
|
|
const CodeCompletionContext &getCompletionContext() const {
|
|
|
|
return CompletionContext;
|
|
|
|
}
|
|
|
|
|
2010-01-14 11:21:49 +08:00
|
|
|
/// \brief Specify whether nested-name-specifiers are allowed.
|
|
|
|
void allowNestedNameSpecifiers(bool Allow = true) {
|
|
|
|
AllowNestedNameSpecifiers = Allow;
|
|
|
|
}
|
|
|
|
|
2010-09-21 08:03:25 +08:00
|
|
|
/// \brief Return the semantic analysis object for which we are collecting
|
|
|
|
/// code completion results.
|
|
|
|
Sema &getSema() const { return SemaRef; }
|
|
|
|
|
2010-01-14 08:20:49 +08:00
|
|
|
/// \brief Determine whether the given declaration is at all interesting
|
|
|
|
/// as a code-completion result.
|
2010-01-14 11:21:49 +08:00
|
|
|
///
|
|
|
|
/// \param ND the declaration that we are inspecting.
|
|
|
|
///
|
|
|
|
/// \param AsNestedNameSpecifier will be set true if this declaration is
|
|
|
|
/// only interesting when it is a nested-name-specifier.
|
|
|
|
bool isInterestingDecl(NamedDecl *ND, bool &AsNestedNameSpecifier) const;
|
2010-01-14 08:41:07 +08:00
|
|
|
|
|
|
|
/// \brief Check whether the result is hidden by the Hiding declaration.
|
|
|
|
///
|
|
|
|
/// \returns true if the result is hidden and cannot be found, false if
|
|
|
|
/// the hidden result could still be found. When false, \p R may be
|
|
|
|
/// modified to describe how the result can be found (e.g., via extra
|
|
|
|
/// qualification).
|
|
|
|
bool CheckHiddenResult(Result &R, DeclContext *CurContext,
|
|
|
|
NamedDecl *Hiding);
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \brief Add a new result to this result set (if it isn't already in one
|
|
|
|
/// of the shadow maps), or replace an existing result (for, e.g., a
|
|
|
|
/// redeclaration).
|
2009-09-22 04:12:40 +08:00
|
|
|
///
|
2010-01-14 09:09:38 +08:00
|
|
|
/// \param CurContext the result to add (if it is unique).
|
2009-09-22 04:12:40 +08:00
|
|
|
///
|
|
|
|
/// \param R the context in which this result will be named.
|
|
|
|
void MaybeAddResult(Result R, DeclContext *CurContext = 0);
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2010-01-14 09:09:38 +08:00
|
|
|
/// \brief Add a new result to this result set, where we already know
|
|
|
|
/// the hiding declation (if any).
|
|
|
|
///
|
|
|
|
/// \param R the result to add (if it is unique).
|
|
|
|
///
|
|
|
|
/// \param CurContext the context in which this result will be named.
|
|
|
|
///
|
|
|
|
/// \param Hiding the declaration that hides the result.
|
2010-01-14 23:47:35 +08:00
|
|
|
///
|
|
|
|
/// \param InBaseClass whether the result was found in a base
|
|
|
|
/// class of the searched context.
|
|
|
|
void AddResult(Result R, DeclContext *CurContext, NamedDecl *Hiding,
|
|
|
|
bool InBaseClass);
|
2010-01-14 09:09:38 +08:00
|
|
|
|
2010-01-15 00:01:26 +08:00
|
|
|
/// \brief Add a new non-declaration result to this result set.
|
|
|
|
void AddResult(Result R);
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \brief Enter into a new scope.
|
|
|
|
void EnterNewScope();
|
|
|
|
|
|
|
|
/// \brief Exit from the current scope.
|
|
|
|
void ExitScope();
|
|
|
|
|
2009-11-18 12:19:12 +08:00
|
|
|
/// \brief Ignore this declaration, if it is seen again.
|
|
|
|
void Ignore(Decl *D) { AllDeclsFound.insert(D->getCanonicalDecl()); }
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \name Name lookup predicates
|
|
|
|
///
|
|
|
|
/// These predicates can be passed to the name lookup functions to filter the
|
|
|
|
/// results of name lookup. All of the predicates have the same type, so that
|
|
|
|
///
|
|
|
|
//@{
|
2009-09-22 04:51:25 +08:00
|
|
|
bool IsOrdinaryName(NamedDecl *ND) const;
|
2010-05-28 08:49:12 +08:00
|
|
|
bool IsOrdinaryNonTypeName(NamedDecl *ND) const;
|
2010-07-29 05:50:18 +08:00
|
|
|
bool IsIntegralConstantValue(NamedDecl *ND) const;
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
bool IsOrdinaryNonValueName(NamedDecl *ND) const;
|
2009-09-22 00:56:56 +08:00
|
|
|
bool IsNestedNameSpecifier(NamedDecl *ND) const;
|
|
|
|
bool IsEnum(NamedDecl *ND) const;
|
|
|
|
bool IsClassOrStruct(NamedDecl *ND) const;
|
|
|
|
bool IsUnion(NamedDecl *ND) const;
|
|
|
|
bool IsNamespace(NamedDecl *ND) const;
|
|
|
|
bool IsNamespaceOrAlias(NamedDecl *ND) const;
|
|
|
|
bool IsType(NamedDecl *ND) const;
|
2009-09-24 06:26:46 +08:00
|
|
|
bool IsMember(NamedDecl *ND) const;
|
2010-01-15 00:08:12 +08:00
|
|
|
bool IsObjCIvar(NamedDecl *ND) const;
|
2010-05-28 07:06:34 +08:00
|
|
|
bool IsObjCMessageReceiver(NamedDecl *ND) const;
|
2010-08-24 05:17:50 +08:00
|
|
|
bool IsObjCCollection(NamedDecl *ND) const;
|
2010-09-24 07:01:17 +08:00
|
|
|
bool IsImpossibleToSatisfy(NamedDecl *ND) const;
|
2009-09-22 00:56:56 +08:00
|
|
|
//@}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-12-07 04:23:50 +08:00
|
|
|
class ResultBuilder::ShadowMapEntry::iterator {
|
|
|
|
llvm::PointerUnion<NamedDecl*, const DeclIndexPair*> DeclOrIterator;
|
|
|
|
unsigned SingleDeclIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef DeclIndexPair value_type;
|
|
|
|
typedef value_type reference;
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
typedef std::input_iterator_tag iterator_category;
|
|
|
|
|
|
|
|
class pointer {
|
|
|
|
DeclIndexPair Value;
|
|
|
|
|
|
|
|
public:
|
|
|
|
pointer(const DeclIndexPair &Value) : Value(Value) { }
|
|
|
|
|
|
|
|
const DeclIndexPair *operator->() const {
|
|
|
|
return &Value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
iterator() : DeclOrIterator((NamedDecl *)0), SingleDeclIndex(0) { }
|
|
|
|
|
|
|
|
iterator(NamedDecl *SingleDecl, unsigned Index)
|
|
|
|
: DeclOrIterator(SingleDecl), SingleDeclIndex(Index) { }
|
|
|
|
|
|
|
|
iterator(const DeclIndexPair *Iterator)
|
|
|
|
: DeclOrIterator(Iterator), SingleDeclIndex(0) { }
|
|
|
|
|
|
|
|
iterator &operator++() {
|
|
|
|
if (DeclOrIterator.is<NamedDecl *>()) {
|
|
|
|
DeclOrIterator = (NamedDecl *)0;
|
|
|
|
SingleDeclIndex = 0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DeclIndexPair *I = DeclOrIterator.get<const DeclIndexPair*>();
|
|
|
|
++I;
|
|
|
|
DeclOrIterator = I;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-09-05 02:12:20 +08:00
|
|
|
/*iterator operator++(int) {
|
2009-12-07 04:23:50 +08:00
|
|
|
iterator tmp(*this);
|
|
|
|
++(*this);
|
|
|
|
return tmp;
|
2010-09-05 02:12:20 +08:00
|
|
|
}*/
|
2009-12-07 04:23:50 +08:00
|
|
|
|
|
|
|
reference operator*() const {
|
|
|
|
if (NamedDecl *ND = DeclOrIterator.dyn_cast<NamedDecl *>())
|
|
|
|
return reference(ND, SingleDeclIndex);
|
|
|
|
|
2009-12-07 05:27:58 +08:00
|
|
|
return *DeclOrIterator.get<const DeclIndexPair*>();
|
2009-12-07 04:23:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pointer operator->() const {
|
|
|
|
return pointer(**this);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator==(const iterator &X, const iterator &Y) {
|
2009-12-07 05:27:58 +08:00
|
|
|
return X.DeclOrIterator.getOpaqueValue()
|
|
|
|
== Y.DeclOrIterator.getOpaqueValue() &&
|
2009-12-07 04:23:50 +08:00
|
|
|
X.SingleDeclIndex == Y.SingleDeclIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator!=(const iterator &X, const iterator &Y) {
|
2009-12-07 05:27:58 +08:00
|
|
|
return !(X == Y);
|
2009-12-07 04:23:50 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ResultBuilder::ShadowMapEntry::iterator
|
|
|
|
ResultBuilder::ShadowMapEntry::begin() const {
|
|
|
|
if (DeclOrVector.isNull())
|
|
|
|
return iterator();
|
|
|
|
|
|
|
|
if (NamedDecl *ND = DeclOrVector.dyn_cast<NamedDecl *>())
|
|
|
|
return iterator(ND, SingleDeclIndex);
|
|
|
|
|
|
|
|
return iterator(DeclOrVector.get<DeclIndexPairVector *>()->begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultBuilder::ShadowMapEntry::iterator
|
|
|
|
ResultBuilder::ShadowMapEntry::end() const {
|
|
|
|
if (DeclOrVector.is<NamedDecl *>() || DeclOrVector.isNull())
|
|
|
|
return iterator();
|
|
|
|
|
|
|
|
return iterator(DeclOrVector.get<DeclIndexPairVector *>()->end());
|
|
|
|
}
|
|
|
|
|
2009-09-22 04:12:40 +08:00
|
|
|
/// \brief Compute the qualification required to get from the current context
|
|
|
|
/// (\p CurContext) to the target context (\p TargetContext).
|
|
|
|
///
|
|
|
|
/// \param Context the AST context in which the qualification will be used.
|
|
|
|
///
|
|
|
|
/// \param CurContext the context where an entity is being named, which is
|
|
|
|
/// typically based on the current scope.
|
|
|
|
///
|
|
|
|
/// \param TargetContext the context in which the named entity actually
|
|
|
|
/// resides.
|
|
|
|
///
|
|
|
|
/// \returns a nested name specifier that refers into the target context, or
|
|
|
|
/// NULL if no qualification is needed.
|
|
|
|
static NestedNameSpecifier *
|
|
|
|
getRequiredQualification(ASTContext &Context,
|
|
|
|
DeclContext *CurContext,
|
|
|
|
DeclContext *TargetContext) {
|
|
|
|
llvm::SmallVector<DeclContext *, 4> TargetParents;
|
|
|
|
|
|
|
|
for (DeclContext *CommonAncestor = TargetContext;
|
|
|
|
CommonAncestor && !CommonAncestor->Encloses(CurContext);
|
|
|
|
CommonAncestor = CommonAncestor->getLookupParent()) {
|
|
|
|
if (CommonAncestor->isTransparentContext() ||
|
|
|
|
CommonAncestor->isFunctionOrMethod())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
TargetParents.push_back(CommonAncestor);
|
|
|
|
}
|
|
|
|
|
|
|
|
NestedNameSpecifier *Result = 0;
|
|
|
|
while (!TargetParents.empty()) {
|
|
|
|
DeclContext *Parent = TargetParents.back();
|
|
|
|
TargetParents.pop_back();
|
|
|
|
|
2010-08-24 05:17:50 +08:00
|
|
|
if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Parent)) {
|
|
|
|
if (!Namespace->getIdentifier())
|
|
|
|
continue;
|
|
|
|
|
2009-09-22 04:12:40 +08:00
|
|
|
Result = NestedNameSpecifier::Create(Context, Result, Namespace);
|
2010-08-24 05:17:50 +08:00
|
|
|
}
|
2009-09-22 04:12:40 +08:00
|
|
|
else if (TagDecl *TD = dyn_cast<TagDecl>(Parent))
|
|
|
|
Result = NestedNameSpecifier::Create(Context, Result,
|
|
|
|
false,
|
|
|
|
Context.getTypeDeclType(TD).getTypePtr());
|
2009-11-07 08:00:49 +08:00
|
|
|
}
|
2009-09-22 04:12:40 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-01-14 11:21:49 +08:00
|
|
|
bool ResultBuilder::isInterestingDecl(NamedDecl *ND,
|
|
|
|
bool &AsNestedNameSpecifier) const {
|
|
|
|
AsNestedNameSpecifier = false;
|
|
|
|
|
2010-01-14 08:20:49 +08:00
|
|
|
ND = ND->getUnderlyingDecl();
|
|
|
|
unsigned IDNS = ND->getIdentifierNamespace();
|
2009-10-10 06:16:47 +08:00
|
|
|
|
|
|
|
// Skip unnamed entities.
|
2010-01-14 08:20:49 +08:00
|
|
|
if (!ND->getDeclName())
|
|
|
|
return false;
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
// Friend declarations and declarations introduced due to friends are never
|
|
|
|
// added as results.
|
2010-03-11 15:50:04 +08:00
|
|
|
if (IDNS & (Decl::IDNS_OrdinaryFriend | Decl::IDNS_TagFriend))
|
2010-01-14 08:20:49 +08:00
|
|
|
return false;
|
|
|
|
|
2009-12-12 01:31:05 +08:00
|
|
|
// Class template (partial) specializations are never added as results.
|
2010-01-14 08:20:49 +08:00
|
|
|
if (isa<ClassTemplateSpecializationDecl>(ND) ||
|
|
|
|
isa<ClassTemplatePartialSpecializationDecl>(ND))
|
|
|
|
return false;
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2009-12-12 01:31:05 +08:00
|
|
|
// Using declarations themselves are never added as results.
|
2010-01-14 08:20:49 +08:00
|
|
|
if (isa<UsingDecl>(ND))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Some declarations have reserved names that we don't want to ever show.
|
|
|
|
if (const IdentifierInfo *Id = ND->getIdentifier()) {
|
2009-09-22 00:56:56 +08:00
|
|
|
// __va_list_tag is a freak of nature. Find it and skip it.
|
|
|
|
if (Id->isStr("__va_list_tag") || Id->isStr("__builtin_va_list"))
|
2010-01-14 08:20:49 +08:00
|
|
|
return false;
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2009-10-10 06:16:47 +08:00
|
|
|
// Filter out names reserved for the implementation (C99 7.1.3,
|
2010-07-15 01:44:04 +08:00
|
|
|
// C++ [lib.global.names]) if they come from a system header.
|
2009-10-19 04:26:12 +08:00
|
|
|
//
|
|
|
|
// FIXME: Add predicate for this.
|
2009-10-10 06:16:47 +08:00
|
|
|
if (Id->getLength() >= 2) {
|
2009-10-19 04:26:12 +08:00
|
|
|
const char *Name = Id->getNameStart();
|
2009-10-10 06:16:47 +08:00
|
|
|
if (Name[0] == '_' &&
|
2010-07-15 01:44:04 +08:00
|
|
|
(Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z')) &&
|
|
|
|
(ND->getLocation().isInvalid() ||
|
|
|
|
SemaRef.SourceMgr.isInSystemHeader(
|
|
|
|
SemaRef.SourceMgr.getSpellingLoc(ND->getLocation()))))
|
2010-01-14 08:20:49 +08:00
|
|
|
return false;
|
2009-10-10 06:16:47 +08:00
|
|
|
}
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
2010-09-22 00:06:22 +08:00
|
|
|
|
2010-11-09 11:59:40 +08:00
|
|
|
// Skip out-of-line declarations and definitions.
|
|
|
|
// NOTE: Unless it's an Objective-C property, method, or ivar, where
|
|
|
|
// the contexts can be messy.
|
|
|
|
if (!ND->getDeclContext()->Equals(ND->getLexicalDeclContext()) &&
|
|
|
|
!(isa<ObjCPropertyDecl>(ND) || isa<ObjCIvarDecl>(ND) ||
|
|
|
|
isa<ObjCMethodDecl>(ND)))
|
|
|
|
return false;
|
|
|
|
|
2010-08-17 07:05:20 +08:00
|
|
|
if (Filter == &ResultBuilder::IsNestedNameSpecifier ||
|
|
|
|
((isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND)) &&
|
|
|
|
Filter != &ResultBuilder::IsNamespace &&
|
2010-09-24 07:01:17 +08:00
|
|
|
Filter != &ResultBuilder::IsNamespaceOrAlias &&
|
|
|
|
Filter != 0))
|
2010-08-17 07:05:20 +08:00
|
|
|
AsNestedNameSpecifier = true;
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
// Filter out any unwanted results.
|
2010-01-14 11:21:49 +08:00
|
|
|
if (Filter && !(this->*Filter)(ND)) {
|
|
|
|
// Check whether it is interesting as a nested-name-specifier.
|
|
|
|
if (AllowNestedNameSpecifiers && SemaRef.getLangOptions().CPlusPlus &&
|
|
|
|
IsNestedNameSpecifier(ND) &&
|
|
|
|
(Filter != &ResultBuilder::IsMember ||
|
|
|
|
(isa<CXXRecordDecl>(ND) &&
|
|
|
|
cast<CXXRecordDecl>(ND)->isInjectedClassName()))) {
|
|
|
|
AsNestedNameSpecifier = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-14 08:20:49 +08:00
|
|
|
return false;
|
2010-08-17 07:05:20 +08:00
|
|
|
}
|
2010-01-14 08:20:49 +08:00
|
|
|
// ... then it must be interesting!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-14 08:41:07 +08:00
|
|
|
bool ResultBuilder::CheckHiddenResult(Result &R, DeclContext *CurContext,
|
|
|
|
NamedDecl *Hiding) {
|
|
|
|
// In C, there is no way to refer to a hidden name.
|
|
|
|
// FIXME: This isn't true; we can find a tag name hidden by an ordinary
|
|
|
|
// name if we introduce the tag type.
|
|
|
|
if (!SemaRef.getLangOptions().CPlusPlus)
|
|
|
|
return true;
|
|
|
|
|
2010-08-31 08:36:30 +08:00
|
|
|
DeclContext *HiddenCtx = R.Declaration->getDeclContext()->getRedeclContext();
|
2010-01-14 08:41:07 +08:00
|
|
|
|
|
|
|
// There is no way to qualify a name declared in a function or method.
|
|
|
|
if (HiddenCtx->isFunctionOrMethod())
|
|
|
|
return true;
|
|
|
|
|
2010-08-31 08:36:30 +08:00
|
|
|
if (HiddenCtx == Hiding->getDeclContext()->getRedeclContext())
|
2010-01-14 08:41:07 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// We can refer to the result with the appropriate qualification. Do it.
|
|
|
|
R.Hidden = true;
|
|
|
|
R.QualifierIsInformative = false;
|
|
|
|
|
|
|
|
if (!R.Qualifier)
|
|
|
|
R.Qualifier = getRequiredQualification(SemaRef.Context,
|
|
|
|
CurContext,
|
|
|
|
R.Declaration->getDeclContext());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-09 07:20:03 +08:00
|
|
|
/// \brief A simplified classification of types used to determine whether two
|
|
|
|
/// types are "similar enough" when adjusting priorities.
|
2010-08-17 00:18:59 +08:00
|
|
|
SimplifiedTypeClass clang::getSimplifiedTypeClass(CanQualType T) {
|
2010-07-09 07:20:03 +08:00
|
|
|
switch (T->getTypeClass()) {
|
|
|
|
case Type::Builtin:
|
|
|
|
switch (cast<BuiltinType>(T)->getKind()) {
|
|
|
|
case BuiltinType::Void:
|
|
|
|
return STC_Void;
|
|
|
|
|
|
|
|
case BuiltinType::NullPtr:
|
|
|
|
return STC_Pointer;
|
|
|
|
|
|
|
|
case BuiltinType::Overload:
|
|
|
|
case BuiltinType::Dependent:
|
|
|
|
case BuiltinType::UndeducedAuto:
|
|
|
|
return STC_Other;
|
|
|
|
|
|
|
|
case BuiltinType::ObjCId:
|
|
|
|
case BuiltinType::ObjCClass:
|
|
|
|
case BuiltinType::ObjCSel:
|
|
|
|
return STC_ObjectiveC;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return STC_Arithmetic;
|
|
|
|
}
|
|
|
|
return STC_Other;
|
|
|
|
|
|
|
|
case Type::Complex:
|
|
|
|
return STC_Arithmetic;
|
|
|
|
|
|
|
|
case Type::Pointer:
|
|
|
|
return STC_Pointer;
|
|
|
|
|
|
|
|
case Type::BlockPointer:
|
|
|
|
return STC_Block;
|
|
|
|
|
|
|
|
case Type::LValueReference:
|
|
|
|
case Type::RValueReference:
|
|
|
|
return getSimplifiedTypeClass(T->getAs<ReferenceType>()->getPointeeType());
|
|
|
|
|
|
|
|
case Type::ConstantArray:
|
|
|
|
case Type::IncompleteArray:
|
|
|
|
case Type::VariableArray:
|
|
|
|
case Type::DependentSizedArray:
|
|
|
|
return STC_Array;
|
|
|
|
|
|
|
|
case Type::DependentSizedExtVector:
|
|
|
|
case Type::Vector:
|
|
|
|
case Type::ExtVector:
|
|
|
|
return STC_Arithmetic;
|
|
|
|
|
|
|
|
case Type::FunctionProto:
|
|
|
|
case Type::FunctionNoProto:
|
|
|
|
return STC_Function;
|
|
|
|
|
|
|
|
case Type::Record:
|
|
|
|
return STC_Record;
|
|
|
|
|
|
|
|
case Type::Enum:
|
|
|
|
return STC_Arithmetic;
|
|
|
|
|
|
|
|
case Type::ObjCObject:
|
|
|
|
case Type::ObjCInterface:
|
|
|
|
case Type::ObjCObjectPointer:
|
|
|
|
return STC_ObjectiveC;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return STC_Other;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Get the type that a given expression will have if this declaration
|
|
|
|
/// is used as an expression in its "typical" code-completion form.
|
2010-08-17 00:18:59 +08:00
|
|
|
QualType clang::getDeclUsageType(ASTContext &C, NamedDecl *ND) {
|
2010-07-09 07:20:03 +08:00
|
|
|
ND = cast<NamedDecl>(ND->getUnderlyingDecl());
|
|
|
|
|
|
|
|
if (TypeDecl *Type = dyn_cast<TypeDecl>(ND))
|
|
|
|
return C.getTypeDeclType(Type);
|
|
|
|
if (ObjCInterfaceDecl *Iface = dyn_cast<ObjCInterfaceDecl>(ND))
|
|
|
|
return C.getObjCInterfaceType(Iface);
|
|
|
|
|
|
|
|
QualType T;
|
|
|
|
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND))
|
2010-07-13 16:18:22 +08:00
|
|
|
T = Function->getCallResultType();
|
2010-07-09 07:20:03 +08:00
|
|
|
else if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND))
|
2010-07-13 16:18:22 +08:00
|
|
|
T = Method->getSendResultType();
|
2010-07-09 07:20:03 +08:00
|
|
|
else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND))
|
2010-07-13 16:18:22 +08:00
|
|
|
T = FunTmpl->getTemplatedDecl()->getCallResultType();
|
2010-07-09 07:20:03 +08:00
|
|
|
else if (EnumConstantDecl *Enumerator = dyn_cast<EnumConstantDecl>(ND))
|
|
|
|
T = C.getTypeDeclType(cast<EnumDecl>(Enumerator->getDeclContext()));
|
|
|
|
else if (ObjCPropertyDecl *Property = dyn_cast<ObjCPropertyDecl>(ND))
|
|
|
|
T = Property->getType();
|
|
|
|
else if (ValueDecl *Value = dyn_cast<ValueDecl>(ND))
|
|
|
|
T = Value->getType();
|
|
|
|
else
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return T.getNonReferenceType();
|
|
|
|
}
|
|
|
|
|
2010-09-21 06:39:41 +08:00
|
|
|
void ResultBuilder::AdjustResultPriorityForDecl(Result &R) {
|
|
|
|
// If this is an Objective-C method declaration whose selector matches our
|
|
|
|
// preferred selector, give it a priority boost.
|
|
|
|
if (!PreferredSelector.isNull())
|
|
|
|
if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(R.Declaration))
|
|
|
|
if (PreferredSelector == Method->getSelector())
|
|
|
|
R.Priority += CCD_SelectorMatch;
|
2010-09-21 07:11:55 +08:00
|
|
|
|
2010-09-21 06:39:41 +08:00
|
|
|
// If we have a preferred type, adjust the priority for results with exactly-
|
|
|
|
// matching or nearly-matching types.
|
|
|
|
if (!PreferredType.isNull()) {
|
|
|
|
QualType T = getDeclUsageType(SemaRef.Context, R.Declaration);
|
|
|
|
if (!T.isNull()) {
|
|
|
|
CanQualType TC = SemaRef.Context.getCanonicalType(T);
|
|
|
|
// Check for exactly-matching types (modulo qualifiers).
|
|
|
|
if (SemaRef.Context.hasSameUnqualifiedType(PreferredType, TC))
|
|
|
|
R.Priority /= CCF_ExactTypeMatch;
|
|
|
|
// Check for nearly-matching types, based on classification of each.
|
|
|
|
else if ((getSimplifiedTypeClass(PreferredType)
|
2010-07-09 07:20:03 +08:00
|
|
|
== getSimplifiedTypeClass(TC)) &&
|
2010-09-21 06:39:41 +08:00
|
|
|
!(PreferredType->isEnumeralType() && TC->isEnumeralType()))
|
|
|
|
R.Priority /= CCF_SimilarTypeMatch;
|
|
|
|
}
|
|
|
|
}
|
2010-07-09 07:20:03 +08:00
|
|
|
}
|
|
|
|
|
2010-09-22 00:06:22 +08:00
|
|
|
void ResultBuilder::MaybeAddConstructorResults(Result R) {
|
|
|
|
if (!SemaRef.getLangOptions().CPlusPlus || !R.Declaration ||
|
|
|
|
!CompletionContext.wantConstructorResults())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ASTContext &Context = SemaRef.Context;
|
|
|
|
NamedDecl *D = R.Declaration;
|
|
|
|
CXXRecordDecl *Record = 0;
|
|
|
|
if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(D))
|
|
|
|
Record = ClassTemplate->getTemplatedDecl();
|
|
|
|
else if ((Record = dyn_cast<CXXRecordDecl>(D))) {
|
|
|
|
// Skip specializations and partial specializations.
|
|
|
|
if (isa<ClassTemplateSpecializationDecl>(Record))
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// There are no constructors here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Record = Record->getDefinition();
|
|
|
|
if (!Record)
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
QualType RecordTy = Context.getTypeDeclType(Record);
|
|
|
|
DeclarationName ConstructorName
|
|
|
|
= Context.DeclarationNames.getCXXConstructorName(
|
|
|
|
Context.getCanonicalType(RecordTy));
|
|
|
|
for (DeclContext::lookup_result Ctors = Record->lookup(ConstructorName);
|
|
|
|
Ctors.first != Ctors.second; ++Ctors.first) {
|
|
|
|
R.Declaration = *Ctors.first;
|
|
|
|
R.CursorKind = getCursorKindForDecl(R.Declaration);
|
|
|
|
Results.push_back(R);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-14 08:20:49 +08:00
|
|
|
void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) {
|
|
|
|
assert(!ShadowMaps.empty() && "Must enter into a results scope");
|
|
|
|
|
|
|
|
if (R.Kind != Result::RK_Declaration) {
|
|
|
|
// For non-declaration results, just add the result.
|
|
|
|
Results.push_back(R);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look through using declarations.
|
|
|
|
if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) {
|
|
|
|
MaybeAddResult(Result(Using->getTargetDecl(), R.Qualifier), CurContext);
|
2009-09-22 00:56:56 +08:00
|
|
|
return;
|
2010-01-14 08:20:49 +08:00
|
|
|
}
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2010-01-14 08:20:49 +08:00
|
|
|
Decl *CanonDecl = R.Declaration->getCanonicalDecl();
|
|
|
|
unsigned IDNS = CanonDecl->getIdentifierNamespace();
|
|
|
|
|
2010-01-14 11:21:49 +08:00
|
|
|
bool AsNestedNameSpecifier = false;
|
|
|
|
if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier))
|
2010-01-14 08:20:49 +08:00
|
|
|
return;
|
|
|
|
|
2010-09-22 00:06:22 +08:00
|
|
|
// C++ constructors are never found by name lookup.
|
|
|
|
if (isa<CXXConstructorDecl>(R.Declaration))
|
|
|
|
return;
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
ShadowMap &SMap = ShadowMaps.back();
|
2009-12-07 04:23:50 +08:00
|
|
|
ShadowMapEntry::iterator I, IEnd;
|
|
|
|
ShadowMap::iterator NamePos = SMap.find(R.Declaration->getDeclName());
|
|
|
|
if (NamePos != SMap.end()) {
|
|
|
|
I = NamePos->second.begin();
|
|
|
|
IEnd = NamePos->second.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; I != IEnd; ++I) {
|
|
|
|
NamedDecl *ND = I->first;
|
|
|
|
unsigned Index = I->second;
|
2009-09-22 00:56:56 +08:00
|
|
|
if (ND->getCanonicalDecl() == CanonDecl) {
|
|
|
|
// This is a redeclaration. Always pick the newer declaration.
|
|
|
|
Results[Index].Declaration = R.Declaration;
|
|
|
|
|
|
|
|
// We're done.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a new declaration in this scope. However, check whether this
|
|
|
|
// declaration name is hidden by a similarly-named declaration in an outer
|
|
|
|
// scope.
|
|
|
|
std::list<ShadowMap>::iterator SM, SMEnd = ShadowMaps.end();
|
|
|
|
--SMEnd;
|
|
|
|
for (SM = ShadowMaps.begin(); SM != SMEnd; ++SM) {
|
2009-12-07 04:23:50 +08:00
|
|
|
ShadowMapEntry::iterator I, IEnd;
|
|
|
|
ShadowMap::iterator NamePos = SM->find(R.Declaration->getDeclName());
|
|
|
|
if (NamePos != SM->end()) {
|
|
|
|
I = NamePos->second.begin();
|
|
|
|
IEnd = NamePos->second.end();
|
|
|
|
}
|
|
|
|
for (; I != IEnd; ++I) {
|
2009-09-22 00:56:56 +08:00
|
|
|
// A tag declaration does not hide a non-tag declaration.
|
2010-04-24 02:46:30 +08:00
|
|
|
if (I->first->hasTagIdentifierNamespace() &&
|
2009-09-22 00:56:56 +08:00
|
|
|
(IDNS & (Decl::IDNS_Member | Decl::IDNS_Ordinary |
|
|
|
|
Decl::IDNS_ObjCProtocol)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Protocols are in distinct namespaces from everything else.
|
2009-12-07 04:23:50 +08:00
|
|
|
if (((I->first->getIdentifierNamespace() & Decl::IDNS_ObjCProtocol)
|
2009-09-22 00:56:56 +08:00
|
|
|
|| (IDNS & Decl::IDNS_ObjCProtocol)) &&
|
2009-12-07 04:23:50 +08:00
|
|
|
I->first->getIdentifierNamespace() != IDNS)
|
2009-09-22 00:56:56 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// The newly-added result is hidden by an entry in the shadow map.
|
2010-01-14 08:41:07 +08:00
|
|
|
if (CheckHiddenResult(R, CurContext, I->first))
|
2009-09-22 00:56:56 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that any given declaration only shows up in the result set once.
|
|
|
|
if (!AllDeclsFound.insert(CanonDecl))
|
|
|
|
return;
|
2010-08-27 23:29:55 +08:00
|
|
|
|
2009-09-24 06:26:46 +08:00
|
|
|
// If the filter is for nested-name-specifiers, then this result starts a
|
|
|
|
// nested-name-specifier.
|
2010-05-27 06:00:08 +08:00
|
|
|
if (AsNestedNameSpecifier) {
|
2009-09-24 06:26:46 +08:00
|
|
|
R.StartsNestedNameSpecifier = true;
|
2010-05-27 06:00:08 +08:00
|
|
|
R.Priority = CCP_NestedNameSpecifier;
|
2010-09-21 06:39:41 +08:00
|
|
|
} else
|
|
|
|
AdjustResultPriorityForDecl(R);
|
2010-08-27 23:29:55 +08:00
|
|
|
|
2009-09-23 07:15:58 +08:00
|
|
|
// If this result is supposed to have an informative qualifier, add one.
|
2009-09-24 06:26:46 +08:00
|
|
|
if (R.QualifierIsInformative && !R.Qualifier &&
|
|
|
|
!R.StartsNestedNameSpecifier) {
|
2009-09-23 07:15:58 +08:00
|
|
|
DeclContext *Ctx = R.Declaration->getDeclContext();
|
|
|
|
if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx))
|
|
|
|
R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, Namespace);
|
|
|
|
else if (TagDecl *Tag = dyn_cast<TagDecl>(Ctx))
|
|
|
|
R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, false,
|
|
|
|
SemaRef.Context.getTypeDeclType(Tag).getTypePtr());
|
|
|
|
else
|
|
|
|
R.QualifierIsInformative = false;
|
|
|
|
}
|
2009-09-24 06:26:46 +08:00
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
// Insert this result into the set of results and into the current shadow
|
|
|
|
// map.
|
2009-12-07 04:23:50 +08:00
|
|
|
SMap[R.Declaration->getDeclName()].Add(R.Declaration, Results.size());
|
2009-09-22 00:56:56 +08:00
|
|
|
Results.push_back(R);
|
2010-09-22 00:06:22 +08:00
|
|
|
|
|
|
|
if (!AsNestedNameSpecifier)
|
|
|
|
MaybeAddConstructorResults(R);
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
|
2010-01-14 09:09:38 +08:00
|
|
|
void ResultBuilder::AddResult(Result R, DeclContext *CurContext,
|
2010-01-14 23:47:35 +08:00
|
|
|
NamedDecl *Hiding, bool InBaseClass = false) {
|
2010-01-15 00:01:26 +08:00
|
|
|
if (R.Kind != Result::RK_Declaration) {
|
|
|
|
// For non-declaration results, just add the result.
|
|
|
|
Results.push_back(R);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-14 09:09:38 +08:00
|
|
|
// Look through using declarations.
|
|
|
|
if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) {
|
|
|
|
AddResult(Result(Using->getTargetDecl(), R.Qualifier), CurContext, Hiding);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-14 11:21:49 +08:00
|
|
|
bool AsNestedNameSpecifier = false;
|
|
|
|
if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier))
|
2010-01-14 09:09:38 +08:00
|
|
|
return;
|
|
|
|
|
2010-09-22 00:06:22 +08:00
|
|
|
// C++ constructors are never found by name lookup.
|
|
|
|
if (isa<CXXConstructorDecl>(R.Declaration))
|
|
|
|
return;
|
|
|
|
|
2010-01-14 09:09:38 +08:00
|
|
|
if (Hiding && CheckHiddenResult(R, CurContext, Hiding))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Make sure that any given declaration only shows up in the result set once.
|
|
|
|
if (!AllDeclsFound.insert(R.Declaration->getCanonicalDecl()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If the filter is for nested-name-specifiers, then this result starts a
|
|
|
|
// nested-name-specifier.
|
2010-05-27 06:00:08 +08:00
|
|
|
if (AsNestedNameSpecifier) {
|
2010-01-14 09:09:38 +08:00
|
|
|
R.StartsNestedNameSpecifier = true;
|
2010-05-27 06:00:08 +08:00
|
|
|
R.Priority = CCP_NestedNameSpecifier;
|
|
|
|
}
|
2010-01-14 23:47:35 +08:00
|
|
|
else if (Filter == &ResultBuilder::IsMember && !R.Qualifier && InBaseClass &&
|
|
|
|
isa<CXXRecordDecl>(R.Declaration->getDeclContext()
|
2010-08-31 08:36:30 +08:00
|
|
|
->getRedeclContext()))
|
2010-01-14 23:47:35 +08:00
|
|
|
R.QualifierIsInformative = true;
|
|
|
|
|
2010-01-14 09:09:38 +08:00
|
|
|
// If this result is supposed to have an informative qualifier, add one.
|
|
|
|
if (R.QualifierIsInformative && !R.Qualifier &&
|
|
|
|
!R.StartsNestedNameSpecifier) {
|
|
|
|
DeclContext *Ctx = R.Declaration->getDeclContext();
|
|
|
|
if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx))
|
|
|
|
R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, Namespace);
|
|
|
|
else if (TagDecl *Tag = dyn_cast<TagDecl>(Ctx))
|
|
|
|
R.Qualifier = NestedNameSpecifier::Create(SemaRef.Context, 0, false,
|
2010-01-14 11:21:49 +08:00
|
|
|
SemaRef.Context.getTypeDeclType(Tag).getTypePtr());
|
2010-01-14 09:09:38 +08:00
|
|
|
else
|
|
|
|
R.QualifierIsInformative = false;
|
|
|
|
}
|
|
|
|
|
2010-05-27 06:00:08 +08:00
|
|
|
// Adjust the priority if this result comes from a base class.
|
|
|
|
if (InBaseClass)
|
|
|
|
R.Priority += CCD_InBaseClass;
|
|
|
|
|
2010-09-21 06:39:41 +08:00
|
|
|
AdjustResultPriorityForDecl(R);
|
2010-05-30 09:49:25 +08:00
|
|
|
|
2010-08-27 00:36:48 +08:00
|
|
|
if (HasObjectTypeQualifiers)
|
|
|
|
if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(R.Declaration))
|
|
|
|
if (Method->isInstance()) {
|
|
|
|
Qualifiers MethodQuals
|
|
|
|
= Qualifiers::fromCVRMask(Method->getTypeQualifiers());
|
|
|
|
if (ObjectTypeQualifiers == MethodQuals)
|
|
|
|
R.Priority += CCD_ObjectQualifierMatch;
|
|
|
|
else if (ObjectTypeQualifiers - MethodQuals) {
|
|
|
|
// The method cannot be invoked, because doing so would drop
|
|
|
|
// qualifiers.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-14 09:09:38 +08:00
|
|
|
// Insert this result into the set of results.
|
|
|
|
Results.push_back(R);
|
2010-09-22 00:06:22 +08:00
|
|
|
|
|
|
|
if (!AsNestedNameSpecifier)
|
|
|
|
MaybeAddConstructorResults(R);
|
2010-01-14 09:09:38 +08:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:01:26 +08:00
|
|
|
void ResultBuilder::AddResult(Result R) {
|
|
|
|
assert(R.Kind != Result::RK_Declaration &&
|
|
|
|
"Declaration results need more context");
|
|
|
|
Results.push_back(R);
|
|
|
|
}
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \brief Enter into a new scope.
|
|
|
|
void ResultBuilder::EnterNewScope() {
|
|
|
|
ShadowMaps.push_back(ShadowMap());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Exit from the current scope.
|
|
|
|
void ResultBuilder::ExitScope() {
|
2009-12-07 04:23:50 +08:00
|
|
|
for (ShadowMap::iterator E = ShadowMaps.back().begin(),
|
|
|
|
EEnd = ShadowMaps.back().end();
|
|
|
|
E != EEnd;
|
|
|
|
++E)
|
|
|
|
E->second.Destroy();
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
ShadowMaps.pop_back();
|
|
|
|
}
|
|
|
|
|
2009-09-22 04:51:25 +08:00
|
|
|
/// \brief Determines whether this given declaration will be found by
|
|
|
|
/// ordinary name lookup.
|
|
|
|
bool ResultBuilder::IsOrdinaryName(NamedDecl *ND) const {
|
2010-05-28 08:49:12 +08:00
|
|
|
ND = cast<NamedDecl>(ND->getUnderlyingDecl());
|
|
|
|
|
2009-09-22 04:51:25 +08:00
|
|
|
unsigned IDNS = Decl::IDNS_Ordinary;
|
|
|
|
if (SemaRef.getLangOptions().CPlusPlus)
|
2010-06-16 04:26:51 +08:00
|
|
|
IDNS |= Decl::IDNS_Tag | Decl::IDNS_Namespace | Decl::IDNS_Member;
|
2010-11-03 04:36:02 +08:00
|
|
|
else if (SemaRef.getLangOptions().ObjC1) {
|
|
|
|
if (isa<ObjCIvarDecl>(ND))
|
|
|
|
return true;
|
|
|
|
if (isa<ObjCPropertyDecl>(ND) &&
|
|
|
|
SemaRef.canSynthesizeProvisionalIvar(cast<ObjCPropertyDecl>(ND)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-22 04:51:25 +08:00
|
|
|
return ND->getIdentifierNamespace() & IDNS;
|
|
|
|
}
|
|
|
|
|
2010-05-28 08:49:12 +08:00
|
|
|
/// \brief Determines whether this given declaration will be found by
|
|
|
|
/// ordinary name lookup but is not a type name.
|
|
|
|
bool ResultBuilder::IsOrdinaryNonTypeName(NamedDecl *ND) const {
|
|
|
|
ND = cast<NamedDecl>(ND->getUnderlyingDecl());
|
|
|
|
if (isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned IDNS = Decl::IDNS_Ordinary;
|
|
|
|
if (SemaRef.getLangOptions().CPlusPlus)
|
2010-06-16 04:26:51 +08:00
|
|
|
IDNS |= Decl::IDNS_Tag | Decl::IDNS_Namespace | Decl::IDNS_Member;
|
2010-11-03 04:36:02 +08:00
|
|
|
else if (SemaRef.getLangOptions().ObjC1) {
|
|
|
|
if (isa<ObjCIvarDecl>(ND))
|
|
|
|
return true;
|
|
|
|
if (isa<ObjCPropertyDecl>(ND) &&
|
|
|
|
SemaRef.canSynthesizeProvisionalIvar(cast<ObjCPropertyDecl>(ND)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-28 08:49:12 +08:00
|
|
|
return ND->getIdentifierNamespace() & IDNS;
|
|
|
|
}
|
|
|
|
|
2010-07-29 05:50:18 +08:00
|
|
|
bool ResultBuilder::IsIntegralConstantValue(NamedDecl *ND) const {
|
|
|
|
if (!IsOrdinaryNonTypeName(ND))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ValueDecl *VD = dyn_cast<ValueDecl>(ND->getUnderlyingDecl()))
|
|
|
|
if (VD->getType()->isIntegralOrEnumerationType())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
/// \brief Determines whether this given declaration will be found by
|
|
|
|
/// ordinary name lookup.
|
|
|
|
bool ResultBuilder::IsOrdinaryNonValueName(NamedDecl *ND) const {
|
2010-05-28 08:49:12 +08:00
|
|
|
ND = cast<NamedDecl>(ND->getUnderlyingDecl());
|
|
|
|
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
unsigned IDNS = Decl::IDNS_Ordinary;
|
|
|
|
if (SemaRef.getLangOptions().CPlusPlus)
|
2010-04-24 02:46:30 +08:00
|
|
|
IDNS |= Decl::IDNS_Tag | Decl::IDNS_Namespace;
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
|
|
|
return (ND->getIdentifierNamespace() & IDNS) &&
|
2010-05-28 08:49:12 +08:00
|
|
|
!isa<ValueDecl>(ND) && !isa<FunctionTemplateDecl>(ND) &&
|
|
|
|
!isa<ObjCPropertyDecl>(ND);
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \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 {
|
|
|
|
// Allow us to find class templates, too.
|
|
|
|
if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
|
|
|
|
ND = ClassTemplate->getTemplatedDecl();
|
|
|
|
|
|
|
|
return SemaRef.isAcceptableNestedNameSpecifier(ND);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determines whether the given declaration is an enumeration.
|
|
|
|
bool ResultBuilder::IsEnum(NamedDecl *ND) const {
|
|
|
|
return isa<EnumDecl>(ND);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determines whether the given declaration is a class or struct.
|
|
|
|
bool ResultBuilder::IsClassOrStruct(NamedDecl *ND) const {
|
|
|
|
// Allow us to find class templates, too.
|
|
|
|
if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
|
|
|
|
ND = ClassTemplate->getTemplatedDecl();
|
|
|
|
|
|
|
|
if (RecordDecl *RD = dyn_cast<RecordDecl>(ND))
|
2010-05-12 05:36:43 +08:00
|
|
|
return RD->getTagKind() == TTK_Class ||
|
|
|
|
RD->getTagKind() == TTK_Struct;
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determines whether the given declaration is a union.
|
|
|
|
bool ResultBuilder::IsUnion(NamedDecl *ND) const {
|
|
|
|
// Allow us to find class templates, too.
|
|
|
|
if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
|
|
|
|
ND = ClassTemplate->getTemplatedDecl();
|
|
|
|
|
|
|
|
if (RecordDecl *RD = dyn_cast<RecordDecl>(ND))
|
2010-05-12 05:36:43 +08:00
|
|
|
return RD->getTagKind() == TTK_Union;
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determines whether the given declaration is a namespace.
|
|
|
|
bool ResultBuilder::IsNamespace(NamedDecl *ND) const {
|
|
|
|
return isa<NamespaceDecl>(ND);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determines whether the given declaration is a namespace or
|
|
|
|
/// namespace alias.
|
|
|
|
bool ResultBuilder::IsNamespaceOrAlias(NamedDecl *ND) const {
|
|
|
|
return isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND);
|
|
|
|
}
|
|
|
|
|
2009-12-12 01:31:05 +08:00
|
|
|
/// \brief Determines whether the given declaration is a type.
|
2009-09-22 00:56:56 +08:00
|
|
|
bool ResultBuilder::IsType(NamedDecl *ND) const {
|
2010-08-24 09:06:58 +08:00
|
|
|
if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(ND))
|
|
|
|
ND = Using->getTargetDecl();
|
|
|
|
|
|
|
|
return isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND);
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
|
2009-12-12 01:31:05 +08:00
|
|
|
/// \brief Determines which members of a class should be visible via
|
|
|
|
/// "." or "->". Only value declarations, nested name specifiers, and
|
|
|
|
/// using declarations thereof should show up.
|
2009-09-24 06:26:46 +08:00
|
|
|
bool ResultBuilder::IsMember(NamedDecl *ND) const {
|
2009-12-12 01:31:05 +08:00
|
|
|
if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(ND))
|
|
|
|
ND = Using->getTargetDecl();
|
|
|
|
|
2009-12-12 02:14:22 +08:00
|
|
|
return isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND) ||
|
|
|
|
isa<ObjCPropertyDecl>(ND);
|
2009-09-24 06:26:46 +08:00
|
|
|
}
|
|
|
|
|
2010-05-28 07:06:34 +08:00
|
|
|
static bool isObjCReceiverType(ASTContext &C, QualType T) {
|
|
|
|
T = C.getCanonicalType(T);
|
|
|
|
switch (T->getTypeClass()) {
|
|
|
|
case Type::ObjCObject:
|
|
|
|
case Type::ObjCInterface:
|
|
|
|
case Type::ObjCObjectPointer:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case Type::Builtin:
|
|
|
|
switch (cast<BuiltinType>(T)->getKind()) {
|
|
|
|
case BuiltinType::ObjCId:
|
|
|
|
case BuiltinType::ObjCClass:
|
|
|
|
case BuiltinType::ObjCSel:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!C.getLangOptions().CPlusPlus)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// FIXME: We could perform more analysis here to determine whether a
|
|
|
|
// particular class type has any conversions to Objective-C types. For now,
|
|
|
|
// just accept all class types.
|
|
|
|
return T->isDependentType() || T->isRecordType();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ResultBuilder::IsObjCMessageReceiver(NamedDecl *ND) const {
|
|
|
|
QualType T = getDeclUsageType(SemaRef.Context, ND);
|
|
|
|
if (T.isNull())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
T = SemaRef.Context.getBaseElementType(T);
|
|
|
|
return isObjCReceiverType(SemaRef.Context, T);
|
|
|
|
}
|
|
|
|
|
2010-08-24 05:17:50 +08:00
|
|
|
bool ResultBuilder::IsObjCCollection(NamedDecl *ND) const {
|
|
|
|
if ((SemaRef.getLangOptions().CPlusPlus && !IsOrdinaryName(ND)) ||
|
|
|
|
(!SemaRef.getLangOptions().CPlusPlus && !IsOrdinaryNonTypeName(ND)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QualType T = getDeclUsageType(SemaRef.Context, ND);
|
|
|
|
if (T.isNull())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
T = SemaRef.Context.getBaseElementType(T);
|
|
|
|
return T->isObjCObjectType() || T->isObjCObjectPointerType() ||
|
|
|
|
T->isObjCIdType() ||
|
|
|
|
(SemaRef.getLangOptions().CPlusPlus && T->isRecordType());
|
|
|
|
}
|
2010-05-28 07:06:34 +08:00
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
bool ResultBuilder::IsImpossibleToSatisfy(NamedDecl *ND) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-15 00:08:12 +08:00
|
|
|
/// \rief Determines whether the given declaration is an Objective-C
|
|
|
|
/// instance variable.
|
|
|
|
bool ResultBuilder::IsObjCIvar(NamedDecl *ND) const {
|
|
|
|
return isa<ObjCIvarDecl>(ND);
|
|
|
|
}
|
|
|
|
|
2010-01-14 09:09:38 +08:00
|
|
|
namespace {
|
|
|
|
/// \brief Visible declaration consumer that adds a code-completion result
|
|
|
|
/// for each visible declaration.
|
|
|
|
class CodeCompletionDeclConsumer : public VisibleDeclConsumer {
|
|
|
|
ResultBuilder &Results;
|
|
|
|
DeclContext *CurContext;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CodeCompletionDeclConsumer(ResultBuilder &Results, DeclContext *CurContext)
|
|
|
|
: Results(Results), CurContext(CurContext) { }
|
|
|
|
|
2010-01-14 23:47:35 +08:00
|
|
|
virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, bool InBaseClass) {
|
|
|
|
Results.AddResult(ND, CurContext, Hiding, InBaseClass);
|
2010-01-14 09:09:38 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \brief Add type specifiers for the current language as keyword results.
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddTypeSpecifierResults(const LangOptions &LangOpts,
|
2009-09-22 00:56:56 +08:00
|
|
|
ResultBuilder &Results) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-05-27 06:00:08 +08:00
|
|
|
Results.AddResult(Result("short", CCP_Type));
|
|
|
|
Results.AddResult(Result("long", CCP_Type));
|
|
|
|
Results.AddResult(Result("signed", CCP_Type));
|
|
|
|
Results.AddResult(Result("unsigned", CCP_Type));
|
|
|
|
Results.AddResult(Result("void", CCP_Type));
|
|
|
|
Results.AddResult(Result("char", CCP_Type));
|
|
|
|
Results.AddResult(Result("int", CCP_Type));
|
|
|
|
Results.AddResult(Result("float", CCP_Type));
|
|
|
|
Results.AddResult(Result("double", CCP_Type));
|
|
|
|
Results.AddResult(Result("enum", CCP_Type));
|
|
|
|
Results.AddResult(Result("struct", CCP_Type));
|
|
|
|
Results.AddResult(Result("union", CCP_Type));
|
|
|
|
Results.AddResult(Result("const", CCP_Type));
|
|
|
|
Results.AddResult(Result("volatile", CCP_Type));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
if (LangOpts.C99) {
|
|
|
|
// C99-specific
|
2010-05-27 06:00:08 +08:00
|
|
|
Results.AddResult(Result("_Complex", CCP_Type));
|
|
|
|
Results.AddResult(Result("_Imaginary", CCP_Type));
|
|
|
|
Results.AddResult(Result("_Bool", CCP_Type));
|
|
|
|
Results.AddResult(Result("restrict", CCP_Type));
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (LangOpts.CPlusPlus) {
|
|
|
|
// C++-specific
|
2010-09-21 05:11:48 +08:00
|
|
|
Results.AddResult(Result("bool", CCP_Type +
|
|
|
|
(LangOpts.ObjC1? CCD_bool_in_ObjC : 0)));
|
2010-05-27 06:00:08 +08:00
|
|
|
Results.AddResult(Result("class", CCP_Type));
|
|
|
|
Results.AddResult(Result("wchar_t", CCP_Type));
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// typename qualified-id
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("typename");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("qualifier");
|
|
|
|
Pattern->AddTextChunk("::");
|
|
|
|
Pattern->AddPlaceholderChunk("name");
|
|
|
|
Results.AddResult(Result(Pattern));
|
2010-05-26 05:41:55 +08:00
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
if (LangOpts.CPlusPlus0x) {
|
2010-05-27 06:00:08 +08:00
|
|
|
Results.AddResult(Result("auto", CCP_Type));
|
|
|
|
Results.AddResult(Result("char16_t", CCP_Type));
|
|
|
|
Results.AddResult(Result("char32_t", CCP_Type));
|
2010-05-28 08:22:41 +08:00
|
|
|
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("decltype");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GNU extensions
|
|
|
|
if (LangOpts.GNUMode) {
|
|
|
|
// FIXME: Enable when we actually support decimal floating point.
|
2010-01-15 00:01:26 +08:00
|
|
|
// Results.AddResult(Result("_Decimal32"));
|
|
|
|
// Results.AddResult(Result("_Decimal64"));
|
|
|
|
// Results.AddResult(Result("_Decimal128"));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("typeof");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("typeof");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("type");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
static void AddStorageSpecifiers(Sema::ParserCompletionContext CCC,
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
const LangOptions &LangOpts,
|
|
|
|
ResultBuilder &Results) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
// Note: we don't suggest either "auto" or "register", because both
|
|
|
|
// are pointless as storage specifiers. Elsewhere, we suggest "auto"
|
|
|
|
// in C++0x as a type specifier.
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result("extern"));
|
|
|
|
Results.AddResult(Result("static"));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
static void AddFunctionSpecifiers(Sema::ParserCompletionContext CCC,
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
const LangOptions &LangOpts,
|
|
|
|
ResultBuilder &Results) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
switch (CCC) {
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Class:
|
|
|
|
case Sema::PCC_MemberTemplate:
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
if (LangOpts.CPlusPlus) {
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result("explicit"));
|
|
|
|
Results.AddResult(Result("friend"));
|
|
|
|
Results.AddResult(Result("mutable"));
|
|
|
|
Results.AddResult(Result("virtual"));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
// Fall through
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ObjCInterface:
|
|
|
|
case Sema::PCC_ObjCImplementation:
|
|
|
|
case Sema::PCC_Namespace:
|
|
|
|
case Sema::PCC_Template:
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
if (LangOpts.CPlusPlus || LangOpts.C99)
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result("inline"));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
break;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ObjCInstanceVariableList:
|
|
|
|
case Sema::PCC_Expression:
|
|
|
|
case Sema::PCC_Statement:
|
|
|
|
case Sema::PCC_ForInit:
|
|
|
|
case Sema::PCC_Condition:
|
|
|
|
case Sema::PCC_RecoveryInFunction:
|
|
|
|
case Sema::PCC_Type:
|
2010-09-15 07:59:36 +08:00
|
|
|
case Sema::PCC_ParenthesizedExpression:
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt);
|
|
|
|
static void AddObjCStatementResults(ResultBuilder &Results, bool NeedAt);
|
|
|
|
static void AddObjCVisibilityResults(const LangOptions &LangOpts,
|
2010-01-14 05:54:15 +08:00
|
|
|
ResultBuilder &Results,
|
|
|
|
bool NeedAt);
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddObjCImplementationResults(const LangOptions &LangOpts,
|
2010-01-14 05:24:21 +08:00
|
|
|
ResultBuilder &Results,
|
|
|
|
bool NeedAt);
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddObjCInterfaceResults(const LangOptions &LangOpts,
|
2010-01-14 05:24:21 +08:00
|
|
|
ResultBuilder &Results,
|
|
|
|
bool NeedAt);
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddObjCTopLevelResults(ResultBuilder &Results, bool NeedAt);
|
2010-01-14 05:24:21 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
static void AddTypedefResult(ResultBuilder &Results) {
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("typedef");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("type");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("name");
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult(Pattern));
|
2010-05-28 08:22:41 +08:00
|
|
|
}
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
static bool WantTypesInContext(Sema::ParserCompletionContext CCC,
|
2010-05-28 08:49:12 +08:00
|
|
|
const LangOptions &LangOpts) {
|
|
|
|
switch (CCC) {
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Namespace:
|
|
|
|
case Sema::PCC_Class:
|
|
|
|
case Sema::PCC_ObjCInstanceVariableList:
|
|
|
|
case Sema::PCC_Template:
|
|
|
|
case Sema::PCC_MemberTemplate:
|
|
|
|
case Sema::PCC_Statement:
|
|
|
|
case Sema::PCC_RecoveryInFunction:
|
|
|
|
case Sema::PCC_Type:
|
2010-09-15 07:59:36 +08:00
|
|
|
case Sema::PCC_ParenthesizedExpression:
|
2010-05-28 08:49:12 +08:00
|
|
|
return true;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Expression:
|
|
|
|
case Sema::PCC_Condition:
|
2010-09-15 07:59:36 +08:00
|
|
|
return LangOpts.CPlusPlus;
|
|
|
|
|
|
|
|
case Sema::PCC_ObjCInterface:
|
|
|
|
case Sema::PCC_ObjCImplementation:
|
2010-05-28 08:49:12 +08:00
|
|
|
return false;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ForInit:
|
2010-09-15 07:59:36 +08:00
|
|
|
return LangOpts.CPlusPlus || LangOpts.ObjC1 || LangOpts.C99;
|
2010-05-28 08:49:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
/// \brief Add language constructs that show up for "ordinary" names.
|
2010-08-27 07:41:50 +08:00
|
|
|
static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC,
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
Scope *S,
|
|
|
|
Sema &SemaRef,
|
|
|
|
ResultBuilder &Results) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
switch (CCC) {
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Namespace:
|
2010-05-28 08:22:41 +08:00
|
|
|
if (SemaRef.getLangOptions().CPlusPlus) {
|
|
|
|
CodeCompletionString *Pattern = 0;
|
|
|
|
|
|
|
|
if (Results.includeCodePatterns()) {
|
|
|
|
// namespace <identifier> { declarations }
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("namespace");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("identifier");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddPlaceholderChunk("declarations");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
}
|
|
|
|
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
// namespace identifier = identifier ;
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("namespace");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
2010-05-28 08:22:41 +08:00
|
|
|
Pattern->AddPlaceholderChunk("name");
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_Equal);
|
2010-05-28 08:22:41 +08:00
|
|
|
Pattern->AddPlaceholderChunk("namespace");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
|
|
|
// Using directives
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("using");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddTextChunk("namespace");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("identifier");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
|
|
|
// asm(string-literal)
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("asm");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("string-literal");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
if (Results.includeCodePatterns()) {
|
|
|
|
// Explicit template instantiation
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("template");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("declaration");
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
}
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
2010-01-14 05:24:21 +08:00
|
|
|
|
|
|
|
if (SemaRef.getLangOptions().ObjC1)
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCTopLevelResults(Results, true);
|
2010-01-14 05:24:21 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
AddTypedefResult(Results);
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
// Fall through
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Class:
|
2010-05-28 08:22:41 +08:00
|
|
|
if (SemaRef.getLangOptions().CPlusPlus) {
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
// Using declaration
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("using");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
2010-05-28 08:22:41 +08:00
|
|
|
Pattern->AddPlaceholderChunk("qualifier");
|
|
|
|
Pattern->AddTextChunk("::");
|
|
|
|
Pattern->AddPlaceholderChunk("name");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// using typename qualifier::name (only in a dependent context)
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
if (SemaRef.CurContext->isDependentContext()) {
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("using");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddTextChunk("typename");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
2010-05-28 08:22:41 +08:00
|
|
|
Pattern->AddPlaceholderChunk("qualifier");
|
|
|
|
Pattern->AddTextChunk("::");
|
|
|
|
Pattern->AddPlaceholderChunk("name");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
if (CCC == Sema::PCC_Class) {
|
2010-05-28 08:22:41 +08:00
|
|
|
AddTypedefResult(Results);
|
|
|
|
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
// public:
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("public");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_Colon);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
|
|
|
// protected:
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("protected");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_Colon);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
|
|
|
// private:
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("private");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_Colon);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Fall through
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Template:
|
|
|
|
case Sema::PCC_MemberTemplate:
|
2010-05-26 05:41:55 +08:00
|
|
|
if (SemaRef.getLangOptions().CPlusPlus && Results.includeCodePatterns()) {
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
// template < parameters >
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("template");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftAngle);
|
|
|
|
Pattern->AddPlaceholderChunk("parameters");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightAngle);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
2010-01-14 07:51:12 +08:00
|
|
|
AddStorageSpecifiers(CCC, SemaRef.getLangOptions(), Results);
|
|
|
|
AddFunctionSpecifiers(CCC, SemaRef.getLangOptions(), Results);
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
break;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ObjCInterface:
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCInterfaceResults(SemaRef.getLangOptions(), Results, true);
|
|
|
|
AddStorageSpecifiers(CCC, SemaRef.getLangOptions(), Results);
|
|
|
|
AddFunctionSpecifiers(CCC, SemaRef.getLangOptions(), Results);
|
2010-01-14 05:24:21 +08:00
|
|
|
break;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ObjCImplementation:
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCImplementationResults(SemaRef.getLangOptions(), Results, true);
|
|
|
|
AddStorageSpecifiers(CCC, SemaRef.getLangOptions(), Results);
|
|
|
|
AddFunctionSpecifiers(CCC, SemaRef.getLangOptions(), Results);
|
2010-01-14 05:24:21 +08:00
|
|
|
break;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ObjCInstanceVariableList:
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCVisibilityResults(SemaRef.getLangOptions(), Results, true);
|
2010-01-14 05:54:15 +08:00
|
|
|
break;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_RecoveryInFunction:
|
|
|
|
case Sema::PCC_Statement: {
|
2010-05-28 08:22:41 +08:00
|
|
|
AddTypedefResult(Results);
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
|
|
|
CodeCompletionString *Pattern = 0;
|
2010-05-26 05:41:55 +08:00
|
|
|
if (SemaRef.getLangOptions().CPlusPlus && Results.includeCodePatterns()) {
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("try");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Pattern->AddTextChunk("catch");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("declaration");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
2010-01-14 05:24:21 +08:00
|
|
|
if (SemaRef.getLangOptions().ObjC1)
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCStatementResults(Results, true);
|
2010-01-14 05:24:21 +08:00
|
|
|
|
2010-05-26 05:41:55 +08:00
|
|
|
if (Results.includeCodePatterns()) {
|
|
|
|
// if (condition) { statements }
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("if");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
if (SemaRef.getLangOptions().CPlusPlus)
|
|
|
|
Pattern->AddPlaceholderChunk("condition");
|
|
|
|
else
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-26 05:41:55 +08:00
|
|
|
// switch (condition) { }
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("switch");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
if (SemaRef.getLangOptions().CPlusPlus)
|
|
|
|
Pattern->AddPlaceholderChunk("condition");
|
|
|
|
else
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
}
|
|
|
|
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
// Switch-specific statements.
|
2010-08-25 16:40:02 +08:00
|
|
|
if (!SemaRef.getCurFunction()->SwitchStack.empty()) {
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
// case expression:
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("case");
|
2010-05-28 08:22:41 +08:00
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_Colon);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
|
|
|
// default:
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("default");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_Colon);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
2010-05-26 05:41:55 +08:00
|
|
|
if (Results.includeCodePatterns()) {
|
|
|
|
/// while (condition) { statements }
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("while");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
if (SemaRef.getLangOptions().CPlusPlus)
|
|
|
|
Pattern->AddPlaceholderChunk("condition");
|
|
|
|
else
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-26 05:41:55 +08:00
|
|
|
// do { statements } while ( expression );
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("do");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Pattern->AddTextChunk("while");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-26 05:41:55 +08:00
|
|
|
// for ( for-init-statement ; condition ; expression ) { statements }
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("for");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
if (SemaRef.getLangOptions().CPlusPlus || SemaRef.getLangOptions().C99)
|
|
|
|
Pattern->AddPlaceholderChunk("init-statement");
|
|
|
|
else
|
|
|
|
Pattern->AddPlaceholderChunk("init-expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
|
|
|
|
Pattern->AddPlaceholderChunk("condition");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
|
|
|
|
Pattern->AddPlaceholderChunk("inc-expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
2010-10-09 04:39:29 +08:00
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
2010-05-26 05:41:55 +08:00
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
}
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
|
|
|
if (S->getContinueParent()) {
|
|
|
|
// continue ;
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("continue");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (S->getBreakParent()) {
|
|
|
|
// break ;
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("break");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// "return expression ;" or "return ;", depending on whether we
|
|
|
|
// know the function is void or not.
|
|
|
|
bool isVoid = false;
|
|
|
|
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(SemaRef.CurContext))
|
|
|
|
isVoid = Function->getResultType()->isVoidType();
|
|
|
|
else if (ObjCMethodDecl *Method
|
|
|
|
= dyn_cast<ObjCMethodDecl>(SemaRef.CurContext))
|
|
|
|
isVoid = Method->getResultType()->isVoidType();
|
Keep an explicit stack of function and block scopes, each element of
which has the label map, switch statement stack, etc. Previously, we
had a single set of maps in Sema (for the function) along with a stack
of block scopes. However, this lead to funky behavior with nested
functions, e.g., in the member functions of local classes.
The explicit-stack approach is far cleaner, and we retain a 1-element
cache so that we're not malloc/free'ing every time we enter a
function. Fixes PR6382.
Also, tweaked the unused-variable warning suppression logic to look at
errors within a given Scope rather than within a given function. The
prior code wasn't looking at the right number-of-errors count when
dealing with blocks, since the block's count would be deallocated
before we got to ActOnPopScope. This approach works with nested
blocks/functions, and gives tighter error recovery.
llvm-svn: 97518
2010-03-02 07:15:13 +08:00
|
|
|
else if (SemaRef.getCurBlock() &&
|
|
|
|
!SemaRef.getCurBlock()->ReturnType.isNull())
|
|
|
|
isVoid = SemaRef.getCurBlock()->ReturnType->isVoidType();
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("return");
|
2010-02-18 12:06:48 +08:00
|
|
|
if (!isVoid) {
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
2010-02-18 12:06:48 +08:00
|
|
|
}
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// goto identifier ;
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("goto");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("label");
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// Using directives
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("using");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddTextChunk("namespace");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("identifier");
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fall through (for statement expressions).
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ForInit:
|
|
|
|
case Sema::PCC_Condition:
|
2010-01-14 07:51:12 +08:00
|
|
|
AddStorageSpecifiers(CCC, SemaRef.getLangOptions(), Results);
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
// Fall through: conditions and statements can have expressions.
|
|
|
|
|
2010-09-15 07:59:36 +08:00
|
|
|
case Sema::PCC_ParenthesizedExpression:
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Expression: {
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
CodeCompletionString *Pattern = 0;
|
|
|
|
if (SemaRef.getLangOptions().CPlusPlus) {
|
|
|
|
// 'this', if we're in a non-static member function.
|
|
|
|
if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(SemaRef.CurContext))
|
|
|
|
if (!Method->isStatic())
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result("this"));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
|
|
|
// true, false
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result("true"));
|
|
|
|
Results.AddResult(Result("false"));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// dynamic_cast < type-id > ( expression )
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("dynamic_cast");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftAngle);
|
|
|
|
Pattern->AddPlaceholderChunk("type");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightAngle);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
|
|
|
|
// static_cast < type-id > ( expression )
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("static_cast");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftAngle);
|
|
|
|
Pattern->AddPlaceholderChunk("type");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightAngle);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
2010-05-26 05:41:55 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// reinterpret_cast < type-id > ( expression )
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("reinterpret_cast");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftAngle);
|
|
|
|
Pattern->AddPlaceholderChunk("type");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightAngle);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
2010-05-26 05:41:55 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// const_cast < type-id > ( expression )
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("const_cast");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftAngle);
|
|
|
|
Pattern->AddPlaceholderChunk("type");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightAngle);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
2010-05-26 05:41:55 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// typeid ( expression-or-type )
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("typeid");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expression-or-type");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// new T ( ... )
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("new");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("type");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expressions");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// new T [ ] ( ... )
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("new");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("type");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBracket);
|
|
|
|
Pattern->AddPlaceholderChunk("size");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBracket);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expressions");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// delete expression
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("delete");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// delete [] expression
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("delete");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBracket);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBracket);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
|
|
|
|
// throw expression
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("throw");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Results.AddResult(Result(Pattern));
|
2010-05-27 06:00:08 +08:00
|
|
|
|
|
|
|
// FIXME: Rethrow?
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SemaRef.getLangOptions().ObjC1) {
|
|
|
|
// Add "super", if we're in an Objective-C class with a superclass.
|
2010-06-01 05:43:10 +08:00
|
|
|
if (ObjCMethodDecl *Method = SemaRef.getCurMethodDecl()) {
|
|
|
|
// The interface can be NULL.
|
|
|
|
if (ObjCInterfaceDecl *ID = Method->getClassInterface())
|
|
|
|
if (ID->getSuperClass())
|
|
|
|
Results.AddResult(Result("super"));
|
|
|
|
}
|
|
|
|
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCExpressionResults(Results, true);
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// sizeof expression
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("sizeof");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expression-or-type");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Result(Pattern));
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
break;
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
2010-08-24 09:06:58 +08:00
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Type:
|
2010-08-24 09:06:58 +08:00
|
|
|
break;
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
2010-05-28 08:49:12 +08:00
|
|
|
if (WantTypesInContext(CCC, SemaRef.getLangOptions()))
|
|
|
|
AddTypeSpecifierResults(SemaRef.getLangOptions(), Results);
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
if (SemaRef.getLangOptions().CPlusPlus && CCC != Sema::PCC_Type)
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result("operator"));
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
|
2009-12-19 02:53:37 +08:00
|
|
|
/// \brief If the given declaration has an associated type, add it as a result
|
|
|
|
/// type chunk.
|
|
|
|
static void AddResultTypeChunk(ASTContext &Context,
|
|
|
|
NamedDecl *ND,
|
|
|
|
CodeCompletionString *Result) {
|
|
|
|
if (!ND)
|
|
|
|
return;
|
2010-09-22 00:06:22 +08:00
|
|
|
|
|
|
|
// Skip constructors and conversion functions, which have their return types
|
|
|
|
// built into their names.
|
|
|
|
if (isa<CXXConstructorDecl>(ND) || isa<CXXConversionDecl>(ND))
|
|
|
|
return;
|
|
|
|
|
2009-12-19 02:53:37 +08:00
|
|
|
// Determine the type of the declaration (if it has a type).
|
2010-09-22 00:06:22 +08:00
|
|
|
QualType T;
|
2009-12-19 02:53:37 +08:00
|
|
|
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND))
|
|
|
|
T = Function->getResultType();
|
|
|
|
else if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND))
|
|
|
|
T = Method->getResultType();
|
|
|
|
else if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND))
|
|
|
|
T = FunTmpl->getTemplatedDecl()->getResultType();
|
|
|
|
else if (EnumConstantDecl *Enumerator = dyn_cast<EnumConstantDecl>(ND))
|
|
|
|
T = Context.getTypeDeclType(cast<TypeDecl>(Enumerator->getDeclContext()));
|
|
|
|
else if (isa<UnresolvedUsingValueDecl>(ND)) {
|
|
|
|
/* Do nothing: ignore unresolved using declarations*/
|
|
|
|
} else if (ValueDecl *Value = dyn_cast<ValueDecl>(ND))
|
|
|
|
T = Value->getType();
|
|
|
|
else if (ObjCPropertyDecl *Property = dyn_cast<ObjCPropertyDecl>(ND))
|
|
|
|
T = Property->getType();
|
|
|
|
|
|
|
|
if (T.isNull() || Context.hasSameType(T, Context.DependentTy))
|
|
|
|
return;
|
|
|
|
|
2010-04-06 05:25:31 +08:00
|
|
|
PrintingPolicy Policy(Context.PrintingPolicy);
|
|
|
|
Policy.AnonymousTagLocations = false;
|
|
|
|
|
2009-12-19 02:53:37 +08:00
|
|
|
std::string TypeStr;
|
2010-04-06 05:25:31 +08:00
|
|
|
T.getAsStringInternal(TypeStr, Policy);
|
2009-12-19 02:53:37 +08:00
|
|
|
Result->AddResultTypeChunk(TypeStr);
|
|
|
|
}
|
|
|
|
|
2010-08-24 07:51:41 +08:00
|
|
|
static void MaybeAddSentinel(ASTContext &Context, NamedDecl *FunctionOrMethod,
|
|
|
|
CodeCompletionString *Result) {
|
|
|
|
if (SentinelAttr *Sentinel = FunctionOrMethod->getAttr<SentinelAttr>())
|
|
|
|
if (Sentinel->getSentinel() == 0) {
|
|
|
|
if (Context.getLangOptions().ObjC1 &&
|
|
|
|
Context.Idents.get("nil").hasMacroDefinition())
|
|
|
|
Result->AddTextChunk(", nil");
|
|
|
|
else if (Context.Idents.get("NULL").hasMacroDefinition())
|
|
|
|
Result->AddTextChunk(", NULL");
|
|
|
|
else
|
|
|
|
Result->AddTextChunk(", (void*)0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-25 00:15:59 +08:00
|
|
|
static std::string FormatFunctionParameter(ASTContext &Context,
|
2010-08-30 03:47:46 +08:00
|
|
|
ParmVarDecl *Param,
|
|
|
|
bool SuppressName = false) {
|
2010-08-25 00:15:59 +08:00
|
|
|
bool ObjCMethodParam = isa<ObjCMethodDecl>(Param->getDeclContext());
|
|
|
|
if (Param->getType()->isDependentType() ||
|
|
|
|
!Param->getType()->isBlockPointerType()) {
|
|
|
|
// The argument for a dependent or non-block parameter is a placeholder
|
|
|
|
// containing that parameter's type.
|
|
|
|
std::string Result;
|
|
|
|
|
2010-08-30 03:47:46 +08:00
|
|
|
if (Param->getIdentifier() && !ObjCMethodParam && !SuppressName)
|
2010-08-25 00:15:59 +08:00
|
|
|
Result = Param->getIdentifier()->getName();
|
|
|
|
|
|
|
|
Param->getType().getAsStringInternal(Result,
|
|
|
|
Context.PrintingPolicy);
|
|
|
|
|
|
|
|
if (ObjCMethodParam) {
|
|
|
|
Result = "(" + Result;
|
|
|
|
Result += ")";
|
2010-08-30 03:47:46 +08:00
|
|
|
if (Param->getIdentifier() && !SuppressName)
|
2010-08-25 00:15:59 +08:00
|
|
|
Result += Param->getIdentifier()->getName();
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The argument for a block pointer parameter is a block literal with
|
|
|
|
// the appropriate type.
|
|
|
|
FunctionProtoTypeLoc *Block = 0;
|
|
|
|
TypeLoc TL;
|
|
|
|
if (TypeSourceInfo *TSInfo = Param->getTypeSourceInfo()) {
|
|
|
|
TL = TSInfo->getTypeLoc().getUnqualifiedLoc();
|
|
|
|
while (true) {
|
|
|
|
// Look through typedefs.
|
|
|
|
if (TypedefTypeLoc *TypedefTL = dyn_cast<TypedefTypeLoc>(&TL)) {
|
|
|
|
if (TypeSourceInfo *InnerTSInfo
|
|
|
|
= TypedefTL->getTypedefDecl()->getTypeSourceInfo()) {
|
|
|
|
TL = InnerTSInfo->getTypeLoc().getUnqualifiedLoc();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look through qualified types
|
|
|
|
if (QualifiedTypeLoc *QualifiedTL = dyn_cast<QualifiedTypeLoc>(&TL)) {
|
|
|
|
TL = QualifiedTL->getUnqualifiedLoc();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to get the function prototype behind the block pointer type,
|
|
|
|
// then we're done.
|
|
|
|
if (BlockPointerTypeLoc *BlockPtr
|
|
|
|
= dyn_cast<BlockPointerTypeLoc>(&TL)) {
|
|
|
|
TL = BlockPtr->getPointeeLoc();
|
|
|
|
Block = dyn_cast<FunctionProtoTypeLoc>(&TL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Block) {
|
|
|
|
// We were unable to find a FunctionProtoTypeLoc with parameter names
|
|
|
|
// for the block; just use the parameter type as a placeholder.
|
|
|
|
std::string Result;
|
|
|
|
Param->getType().getUnqualifiedType().
|
|
|
|
getAsStringInternal(Result, Context.PrintingPolicy);
|
|
|
|
|
|
|
|
if (ObjCMethodParam) {
|
|
|
|
Result = "(" + Result;
|
|
|
|
Result += ")";
|
|
|
|
if (Param->getIdentifier())
|
|
|
|
Result += Param->getIdentifier()->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have the function prototype behind the block pointer type, as it was
|
|
|
|
// written in the source.
|
2010-09-09 06:47:51 +08:00
|
|
|
std::string Result;
|
|
|
|
QualType ResultType = Block->getTypePtr()->getResultType();
|
|
|
|
if (!ResultType->isVoidType())
|
|
|
|
ResultType.getAsStringInternal(Result, Context.PrintingPolicy);
|
|
|
|
|
|
|
|
Result = '^' + Result;
|
|
|
|
if (Block->getNumArgs() == 0) {
|
|
|
|
if (Block->getTypePtr()->isVariadic())
|
|
|
|
Result += "(...)";
|
2010-10-03 07:49:58 +08:00
|
|
|
else
|
|
|
|
Result += "(void)";
|
2010-09-09 06:47:51 +08:00
|
|
|
} else {
|
|
|
|
Result += "(";
|
|
|
|
for (unsigned I = 0, N = Block->getNumArgs(); I != N; ++I) {
|
|
|
|
if (I)
|
|
|
|
Result += ", ";
|
|
|
|
Result += FormatFunctionParameter(Context, Block->getArg(I));
|
|
|
|
|
|
|
|
if (I == N - 1 && Block->getTypePtr()->isVariadic())
|
|
|
|
Result += ", ...";
|
|
|
|
}
|
|
|
|
Result += ")";
|
2010-08-31 13:13:43 +08:00
|
|
|
}
|
2010-09-09 06:47:51 +08:00
|
|
|
|
2010-10-03 07:49:58 +08:00
|
|
|
if (Param->getIdentifier())
|
|
|
|
Result += Param->getIdentifier()->getName();
|
|
|
|
|
2010-08-25 00:15:59 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \brief Add function parameter chunks to the given code completion string.
|
|
|
|
static void AddFunctionParameterChunks(ASTContext &Context,
|
|
|
|
FunctionDecl *Function,
|
|
|
|
CodeCompletionString *Result) {
|
2009-11-07 08:00:49 +08:00
|
|
|
typedef CodeCompletionString::Chunk Chunk;
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
CodeCompletionString *CCStr = Result;
|
|
|
|
|
|
|
|
for (unsigned P = 0, N = Function->getNumParams(); P != N; ++P) {
|
|
|
|
ParmVarDecl *Param = Function->getParamDecl(P);
|
|
|
|
|
|
|
|
if (Param->hasDefaultArg()) {
|
|
|
|
// When we see an optional default argument, put that argument and
|
|
|
|
// the remaining default arguments into a new, optional string.
|
|
|
|
CodeCompletionString *Opt = new CodeCompletionString;
|
|
|
|
CCStr->AddOptionalChunk(std::auto_ptr<CodeCompletionString>(Opt));
|
|
|
|
CCStr = Opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (P != 0)
|
2009-11-07 08:00:49 +08:00
|
|
|
CCStr->AddChunk(Chunk(CodeCompletionString::CK_Comma));
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
// Format the placeholder string.
|
2010-08-25 00:15:59 +08:00
|
|
|
std::string PlaceholderStr = FormatFunctionParameter(Context, Param);
|
|
|
|
|
2010-08-31 13:13:43 +08:00
|
|
|
if (Function->isVariadic() && P == N - 1)
|
|
|
|
PlaceholderStr += ", ...";
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
// Add the placeholder string.
|
2009-11-30 04:18:50 +08:00
|
|
|
CCStr->AddPlaceholderChunk(PlaceholderStr);
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
2009-09-23 05:42:17 +08:00
|
|
|
|
|
|
|
if (const FunctionProtoType *Proto
|
|
|
|
= Function->getType()->getAs<FunctionProtoType>())
|
2010-08-24 07:51:41 +08:00
|
|
|
if (Proto->isVariadic()) {
|
2010-08-31 13:13:43 +08:00
|
|
|
if (Proto->getNumArgs() == 0)
|
|
|
|
CCStr->AddPlaceholderChunk("...");
|
2010-08-24 07:51:41 +08:00
|
|
|
|
|
|
|
MaybeAddSentinel(Context, Function, CCStr);
|
|
|
|
}
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Add template parameter chunks to the given code completion string.
|
|
|
|
static void AddTemplateParameterChunks(ASTContext &Context,
|
|
|
|
TemplateDecl *Template,
|
|
|
|
CodeCompletionString *Result,
|
|
|
|
unsigned MaxParameters = 0) {
|
2009-11-07 08:00:49 +08:00
|
|
|
typedef CodeCompletionString::Chunk Chunk;
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
CodeCompletionString *CCStr = Result;
|
|
|
|
bool FirstParameter = true;
|
|
|
|
|
|
|
|
TemplateParameterList *Params = Template->getTemplateParameters();
|
|
|
|
TemplateParameterList::iterator PEnd = Params->end();
|
|
|
|
if (MaxParameters)
|
|
|
|
PEnd = Params->begin() + MaxParameters;
|
|
|
|
for (TemplateParameterList::iterator P = Params->begin(); P != PEnd; ++P) {
|
|
|
|
bool HasDefaultArg = false;
|
|
|
|
std::string PlaceholderStr;
|
|
|
|
if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) {
|
|
|
|
if (TTP->wasDeclaredWithTypename())
|
|
|
|
PlaceholderStr = "typename";
|
|
|
|
else
|
|
|
|
PlaceholderStr = "class";
|
|
|
|
|
|
|
|
if (TTP->getIdentifier()) {
|
|
|
|
PlaceholderStr += ' ';
|
|
|
|
PlaceholderStr += TTP->getIdentifier()->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
HasDefaultArg = TTP->hasDefaultArgument();
|
|
|
|
} else if (NonTypeTemplateParmDecl *NTTP
|
|
|
|
= dyn_cast<NonTypeTemplateParmDecl>(*P)) {
|
|
|
|
if (NTTP->getIdentifier())
|
|
|
|
PlaceholderStr = NTTP->getIdentifier()->getName();
|
|
|
|
NTTP->getType().getAsStringInternal(PlaceholderStr,
|
|
|
|
Context.PrintingPolicy);
|
|
|
|
HasDefaultArg = NTTP->hasDefaultArgument();
|
|
|
|
} else {
|
|
|
|
assert(isa<TemplateTemplateParmDecl>(*P));
|
|
|
|
TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P);
|
|
|
|
|
|
|
|
// Since putting the template argument list into the placeholder would
|
|
|
|
// be very, very long, we just use an abbreviation.
|
|
|
|
PlaceholderStr = "template<...> class";
|
|
|
|
if (TTP->getIdentifier()) {
|
|
|
|
PlaceholderStr += ' ';
|
|
|
|
PlaceholderStr += TTP->getIdentifier()->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
HasDefaultArg = TTP->hasDefaultArgument();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HasDefaultArg) {
|
|
|
|
// When we see an optional default argument, put that argument and
|
|
|
|
// the remaining default arguments into a new, optional string.
|
|
|
|
CodeCompletionString *Opt = new CodeCompletionString;
|
|
|
|
CCStr->AddOptionalChunk(std::auto_ptr<CodeCompletionString>(Opt));
|
|
|
|
CCStr = Opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FirstParameter)
|
|
|
|
FirstParameter = false;
|
|
|
|
else
|
2009-11-07 08:00:49 +08:00
|
|
|
CCStr->AddChunk(Chunk(CodeCompletionString::CK_Comma));
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
// Add the placeholder string.
|
2009-11-30 04:18:50 +08:00
|
|
|
CCStr->AddPlaceholderChunk(PlaceholderStr);
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 03:57:38 +08:00
|
|
|
/// \brief Add a qualifier to the given code-completion string, if the
|
|
|
|
/// provided nested-name-specifier is non-NULL.
|
2009-12-12 02:44:16 +08:00
|
|
|
static void
|
|
|
|
AddQualifierToCompletionString(CodeCompletionString *Result,
|
|
|
|
NestedNameSpecifier *Qualifier,
|
|
|
|
bool QualifierIsInformative,
|
|
|
|
ASTContext &Context) {
|
2009-09-22 03:57:38 +08:00
|
|
|
if (!Qualifier)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string PrintedNNS;
|
|
|
|
{
|
|
|
|
llvm::raw_string_ostream OS(PrintedNNS);
|
|
|
|
Qualifier->print(OS, Context.PrintingPolicy);
|
|
|
|
}
|
2009-09-23 07:15:58 +08:00
|
|
|
if (QualifierIsInformative)
|
2009-11-30 04:18:50 +08:00
|
|
|
Result->AddInformativeChunk(PrintedNNS);
|
2009-09-23 07:15:58 +08:00
|
|
|
else
|
2009-11-30 04:18:50 +08:00
|
|
|
Result->AddTextChunk(PrintedNNS);
|
2009-09-22 03:57:38 +08:00
|
|
|
}
|
|
|
|
|
2009-12-12 02:44:16 +08:00
|
|
|
static void AddFunctionTypeQualsToCompletionString(CodeCompletionString *Result,
|
|
|
|
FunctionDecl *Function) {
|
|
|
|
const FunctionProtoType *Proto
|
|
|
|
= Function->getType()->getAs<FunctionProtoType>();
|
|
|
|
if (!Proto || !Proto->getTypeQuals())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string QualsStr;
|
|
|
|
if (Proto->getTypeQuals() & Qualifiers::Const)
|
|
|
|
QualsStr += " const";
|
|
|
|
if (Proto->getTypeQuals() & Qualifiers::Volatile)
|
|
|
|
QualsStr += " volatile";
|
|
|
|
if (Proto->getTypeQuals() & Qualifiers::Restrict)
|
|
|
|
QualsStr += " restrict";
|
|
|
|
Result->AddInformativeChunk(QualsStr);
|
|
|
|
}
|
|
|
|
|
2010-09-22 00:06:22 +08:00
|
|
|
/// \brief Add the name of the given declaration
|
|
|
|
static void AddTypedNameChunk(ASTContext &Context, NamedDecl *ND,
|
|
|
|
CodeCompletionString *Result) {
|
|
|
|
typedef CodeCompletionString::Chunk Chunk;
|
|
|
|
|
|
|
|
DeclarationName Name = ND->getDeclName();
|
|
|
|
if (!Name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (Name.getNameKind()) {
|
|
|
|
case DeclarationName::Identifier:
|
|
|
|
case DeclarationName::CXXConversionFunctionName:
|
|
|
|
case DeclarationName::CXXOperatorName:
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
case DeclarationName::CXXLiteralOperatorName:
|
|
|
|
Result->AddTypedTextChunk(ND->getNameAsString());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclarationName::CXXUsingDirective:
|
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclarationName::CXXConstructorName: {
|
|
|
|
CXXRecordDecl *Record = 0;
|
|
|
|
QualType Ty = Name.getCXXNameType();
|
|
|
|
if (const RecordType *RecordTy = Ty->getAs<RecordType>())
|
|
|
|
Record = cast<CXXRecordDecl>(RecordTy->getDecl());
|
|
|
|
else if (const InjectedClassNameType *InjectedTy
|
|
|
|
= Ty->getAs<InjectedClassNameType>())
|
|
|
|
Record = InjectedTy->getDecl();
|
|
|
|
else {
|
|
|
|
Result->AddTypedTextChunk(ND->getNameAsString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result->AddTypedTextChunk(Record->getNameAsString());
|
|
|
|
if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) {
|
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
|
|
|
|
AddTemplateParameterChunks(Context, Template, Result);
|
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
/// \brief If possible, create a new code completion string for the given
|
|
|
|
/// result.
|
|
|
|
///
|
|
|
|
/// \returns Either a new, heap-allocated code completion string describing
|
|
|
|
/// how to use this result, or NULL to indicate that the string or name of the
|
|
|
|
/// result is all that is needed.
|
|
|
|
CodeCompletionString *
|
2010-08-25 14:19:51 +08:00
|
|
|
CodeCompletionResult::CreateCodeCompletionString(Sema &S,
|
2010-09-22 00:06:22 +08:00
|
|
|
CodeCompletionString *Result) {
|
2009-11-07 08:00:49 +08:00
|
|
|
typedef CodeCompletionString::Chunk Chunk;
|
|
|
|
|
2009-12-01 13:55:20 +08:00
|
|
|
if (Kind == RK_Pattern)
|
2010-08-05 00:47:14 +08:00
|
|
|
return Pattern->Clone(Result);
|
2009-12-01 13:55:20 +08:00
|
|
|
|
2010-08-05 00:47:14 +08:00
|
|
|
if (!Result)
|
|
|
|
Result = new CodeCompletionString;
|
2009-12-01 13:55:20 +08:00
|
|
|
|
|
|
|
if (Kind == RK_Keyword) {
|
|
|
|
Result->AddTypedTextChunk(Keyword);
|
|
|
|
return Result;
|
|
|
|
}
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2009-10-31 00:50:04 +08:00
|
|
|
if (Kind == RK_Macro) {
|
|
|
|
MacroInfo *MI = S.PP.getMacroInfo(Macro);
|
2009-12-01 13:55:20 +08:00
|
|
|
assert(MI && "Not a macro?");
|
|
|
|
|
|
|
|
Result->AddTypedTextChunk(Macro->getName());
|
|
|
|
|
|
|
|
if (!MI->isFunctionLike())
|
|
|
|
return Result;
|
2009-10-31 00:50:04 +08:00
|
|
|
|
|
|
|
// Format a function-like macro with placeholders for the arguments.
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
|
2009-10-31 00:50:04 +08:00
|
|
|
for (MacroInfo::arg_iterator A = MI->arg_begin(), AEnd = MI->arg_end();
|
|
|
|
A != AEnd; ++A) {
|
|
|
|
if (A != MI->arg_begin())
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_Comma));
|
2009-10-31 00:50:04 +08:00
|
|
|
|
|
|
|
if (!MI->isVariadic() || A != AEnd - 1) {
|
|
|
|
// Non-variadic argument.
|
2009-11-30 04:18:50 +08:00
|
|
|
Result->AddPlaceholderChunk((*A)->getName());
|
2009-10-31 00:50:04 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Variadic argument; cope with the different between GNU and C99
|
|
|
|
// variadic macros, providing a single placeholder for the rest of the
|
|
|
|
// arguments.
|
|
|
|
if ((*A)->isStr("__VA_ARGS__"))
|
|
|
|
Result->AddPlaceholderChunk("...");
|
|
|
|
else {
|
|
|
|
std::string Arg = (*A)->getName();
|
|
|
|
Arg += "...";
|
2009-11-30 04:18:50 +08:00
|
|
|
Result->AddPlaceholderChunk(Arg);
|
2009-10-31 00:50:04 +08:00
|
|
|
}
|
|
|
|
}
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
|
2009-10-31 00:50:04 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-05-26 05:41:55 +08:00
|
|
|
assert(Kind == RK_Declaration && "Missed a result kind?");
|
2009-09-22 00:56:56 +08:00
|
|
|
NamedDecl *ND = Declaration;
|
|
|
|
|
2009-11-07 08:00:49 +08:00
|
|
|
if (StartsNestedNameSpecifier) {
|
2009-11-30 04:18:50 +08:00
|
|
|
Result->AddTypedTextChunk(ND->getNameAsString());
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddTextChunk("::");
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2009-12-19 02:53:37 +08:00
|
|
|
AddResultTypeChunk(S.Context, ND, Result);
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) {
|
2009-09-23 07:15:58 +08:00
|
|
|
AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
|
|
|
|
S.Context);
|
2010-09-22 00:06:22 +08:00
|
|
|
AddTypedNameChunk(S.Context, ND, Result);
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
|
2009-09-22 00:56:56 +08:00
|
|
|
AddFunctionParameterChunks(S.Context, Function, Result);
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
|
2009-12-12 02:44:16 +08:00
|
|
|
AddFunctionTypeQualsToCompletionString(Result, Function);
|
2009-09-22 00:56:56 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(ND)) {
|
2009-09-23 07:15:58 +08:00
|
|
|
AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
|
|
|
|
S.Context);
|
2009-09-22 00:56:56 +08:00
|
|
|
FunctionDecl *Function = FunTmpl->getTemplatedDecl();
|
2010-09-22 00:06:22 +08:00
|
|
|
AddTypedNameChunk(S.Context, Function, Result);
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
// Figure out which template parameters are deduced (or have default
|
|
|
|
// arguments).
|
|
|
|
llvm::SmallVector<bool, 16> Deduced;
|
|
|
|
S.MarkDeducedTemplateParameters(FunTmpl, Deduced);
|
|
|
|
unsigned LastDeducibleArgument;
|
|
|
|
for (LastDeducibleArgument = Deduced.size(); LastDeducibleArgument > 0;
|
|
|
|
--LastDeducibleArgument) {
|
|
|
|
if (!Deduced[LastDeducibleArgument - 1]) {
|
|
|
|
// C++0x: Figure out if the template argument has a default. If so,
|
|
|
|
// the user doesn't need to type this argument.
|
|
|
|
// FIXME: We need to abstract template parameters better!
|
|
|
|
bool HasDefaultArg = false;
|
|
|
|
NamedDecl *Param = FunTmpl->getTemplateParameters()->getParam(
|
|
|
|
LastDeducibleArgument - 1);
|
|
|
|
if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
|
|
|
|
HasDefaultArg = TTP->hasDefaultArgument();
|
|
|
|
else if (NonTypeTemplateParmDecl *NTTP
|
|
|
|
= dyn_cast<NonTypeTemplateParmDecl>(Param))
|
|
|
|
HasDefaultArg = NTTP->hasDefaultArgument();
|
|
|
|
else {
|
|
|
|
assert(isa<TemplateTemplateParmDecl>(Param));
|
|
|
|
HasDefaultArg
|
2009-11-07 08:00:49 +08:00
|
|
|
= cast<TemplateTemplateParmDecl>(Param)->hasDefaultArgument();
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!HasDefaultArg)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LastDeducibleArgument) {
|
|
|
|
// Some of the function template arguments cannot be deduced from a
|
|
|
|
// function call, so we introduce an explicit template argument list
|
|
|
|
// containing all of the arguments up to the first deducible argument.
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
|
2009-09-22 00:56:56 +08:00
|
|
|
AddTemplateParameterChunks(S.Context, FunTmpl, Result,
|
|
|
|
LastDeducibleArgument);
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the function parameters
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
|
2009-09-22 00:56:56 +08:00
|
|
|
AddFunctionParameterChunks(S.Context, Function, Result);
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
|
2009-12-12 02:44:16 +08:00
|
|
|
AddFunctionTypeQualsToCompletionString(Result, Function);
|
2009-09-22 00:56:56 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TemplateDecl *Template = dyn_cast<TemplateDecl>(ND)) {
|
2009-09-23 07:15:58 +08:00
|
|
|
AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
|
|
|
|
S.Context);
|
2009-11-30 04:18:50 +08:00
|
|
|
Result->AddTypedTextChunk(Template->getNameAsString());
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_LeftAngle));
|
2009-09-22 00:56:56 +08:00
|
|
|
AddTemplateParameterChunks(S.Context, Template, Result);
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_RightAngle));
|
2009-09-22 00:56:56 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2009-11-18 00:44:22 +08:00
|
|
|
if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(ND)) {
|
|
|
|
Selector Sel = Method->getSelector();
|
|
|
|
if (Sel.isUnarySelector()) {
|
|
|
|
Result->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2009-11-19 09:08:35 +08:00
|
|
|
std::string SelName = Sel.getIdentifierInfoForSlot(0)->getName().str();
|
|
|
|
SelName += ':';
|
|
|
|
if (StartParameter == 0)
|
|
|
|
Result->AddTypedTextChunk(SelName);
|
|
|
|
else {
|
|
|
|
Result->AddInformativeChunk(SelName);
|
|
|
|
|
|
|
|
// If there is only one parameter, and we're past it, add an empty
|
|
|
|
// typed-text chunk since there is nothing to type.
|
|
|
|
if (Method->param_size() == 1)
|
|
|
|
Result->AddTypedTextChunk("");
|
|
|
|
}
|
2009-11-18 00:44:22 +08:00
|
|
|
unsigned Idx = 0;
|
|
|
|
for (ObjCMethodDecl::param_iterator P = Method->param_begin(),
|
|
|
|
PEnd = Method->param_end();
|
|
|
|
P != PEnd; (void)++P, ++Idx) {
|
|
|
|
if (Idx > 0) {
|
2009-11-19 09:08:35 +08:00
|
|
|
std::string Keyword;
|
|
|
|
if (Idx > StartParameter)
|
2010-01-12 14:38:28 +08:00
|
|
|
Result->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
2009-11-18 00:44:22 +08:00
|
|
|
if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Idx))
|
|
|
|
Keyword += II->getName().str();
|
|
|
|
Keyword += ":";
|
2010-07-09 07:20:03 +08:00
|
|
|
if (Idx < StartParameter || AllParametersAreInformative)
|
2009-11-19 09:08:35 +08:00
|
|
|
Result->AddInformativeChunk(Keyword);
|
2010-10-19 05:05:04 +08:00
|
|
|
else
|
2009-11-19 09:08:35 +08:00
|
|
|
Result->AddTypedTextChunk(Keyword);
|
2009-11-18 00:44:22 +08:00
|
|
|
}
|
2009-11-19 09:08:35 +08:00
|
|
|
|
|
|
|
// If we're before the starting parameter, skip the placeholder.
|
|
|
|
if (Idx < StartParameter)
|
|
|
|
continue;
|
2009-11-18 00:44:22 +08:00
|
|
|
|
|
|
|
std::string Arg;
|
2010-08-25 00:15:59 +08:00
|
|
|
|
|
|
|
if ((*P)->getType()->isBlockPointerType() && !DeclaringEntity)
|
2010-08-30 03:47:46 +08:00
|
|
|
Arg = FormatFunctionParameter(S.Context, *P, true);
|
2010-08-25 00:15:59 +08:00
|
|
|
else {
|
|
|
|
(*P)->getType().getAsStringInternal(Arg, S.Context.PrintingPolicy);
|
|
|
|
Arg = "(" + Arg + ")";
|
|
|
|
if (IdentifierInfo *II = (*P)->getIdentifier())
|
2010-08-30 03:47:46 +08:00
|
|
|
if (DeclaringEntity || AllParametersAreInformative)
|
|
|
|
Arg += II->getName().str();
|
2010-08-25 00:15:59 +08:00
|
|
|
}
|
|
|
|
|
2010-08-31 13:13:43 +08:00
|
|
|
if (Method->isVariadic() && (P + 1) == PEnd)
|
|
|
|
Arg += ", ...";
|
|
|
|
|
2010-07-09 07:20:03 +08:00
|
|
|
if (DeclaringEntity)
|
|
|
|
Result->AddTextChunk(Arg);
|
|
|
|
else if (AllParametersAreInformative)
|
2009-11-19 15:41:15 +08:00
|
|
|
Result->AddInformativeChunk(Arg);
|
|
|
|
else
|
|
|
|
Result->AddPlaceholderChunk(Arg);
|
2009-11-18 00:44:22 +08:00
|
|
|
}
|
|
|
|
|
2009-12-23 08:21:46 +08:00
|
|
|
if (Method->isVariadic()) {
|
2010-08-31 13:13:43 +08:00
|
|
|
if (Method->param_size() == 0) {
|
|
|
|
if (DeclaringEntity)
|
|
|
|
Result->AddTextChunk(", ...");
|
|
|
|
else if (AllParametersAreInformative)
|
|
|
|
Result->AddInformativeChunk(", ...");
|
|
|
|
else
|
|
|
|
Result->AddPlaceholderChunk(", ...");
|
|
|
|
}
|
2010-08-24 07:51:41 +08:00
|
|
|
|
|
|
|
MaybeAddSentinel(S.Context, Method, Result);
|
2009-12-23 08:21:46 +08:00
|
|
|
}
|
|
|
|
|
2009-11-18 00:44:22 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2009-12-01 13:55:20 +08:00
|
|
|
if (Qualifier)
|
2009-09-23 07:15:58 +08:00
|
|
|
AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
|
|
|
|
S.Context);
|
2009-12-01 13:55:20 +08:00
|
|
|
|
|
|
|
Result->AddTypedTextChunk(ND->getNameAsString());
|
|
|
|
return Result;
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
|
2009-09-23 08:34:09 +08:00
|
|
|
CodeCompletionString *
|
|
|
|
CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
|
|
|
|
unsigned CurrentArg,
|
2010-10-12 05:37:58 +08:00
|
|
|
Sema &S,
|
|
|
|
CodeCompletionString *Result) const {
|
2009-11-07 08:00:49 +08:00
|
|
|
typedef CodeCompletionString::Chunk Chunk;
|
|
|
|
|
2010-10-12 05:37:58 +08:00
|
|
|
if (!Result)
|
|
|
|
Result = new CodeCompletionString;
|
2009-09-23 08:34:09 +08:00
|
|
|
FunctionDecl *FDecl = getFunction();
|
2009-12-19 02:53:37 +08:00
|
|
|
AddResultTypeChunk(S.Context, FDecl, Result);
|
2009-09-23 08:34:09 +08:00
|
|
|
const FunctionProtoType *Proto
|
|
|
|
= dyn_cast<FunctionProtoType>(getFunctionType());
|
|
|
|
if (!FDecl && !Proto) {
|
|
|
|
// Function without a prototype. Just give the return type and a
|
|
|
|
// highlighted ellipsis.
|
|
|
|
const FunctionType *FT = getFunctionType();
|
|
|
|
Result->AddTextChunk(
|
2009-11-30 04:18:50 +08:00
|
|
|
FT->getResultType().getAsString(S.Context.PrintingPolicy));
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
|
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter, "..."));
|
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
|
2009-09-23 08:34:09 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FDecl)
|
2009-11-30 04:18:50 +08:00
|
|
|
Result->AddTextChunk(FDecl->getNameAsString());
|
2009-09-23 08:34:09 +08:00
|
|
|
else
|
|
|
|
Result->AddTextChunk(
|
2009-11-30 04:18:50 +08:00
|
|
|
Proto->getResultType().getAsString(S.Context.PrintingPolicy));
|
2009-09-23 08:34:09 +08:00
|
|
|
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
|
2009-09-23 08:34:09 +08:00
|
|
|
unsigned NumParams = FDecl? FDecl->getNumParams() : Proto->getNumArgs();
|
|
|
|
for (unsigned I = 0; I != NumParams; ++I) {
|
|
|
|
if (I)
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_Comma));
|
2009-09-23 08:34:09 +08:00
|
|
|
|
|
|
|
std::string ArgString;
|
|
|
|
QualType ArgType;
|
|
|
|
|
|
|
|
if (FDecl) {
|
|
|
|
ArgString = FDecl->getParamDecl(I)->getNameAsString();
|
|
|
|
ArgType = FDecl->getParamDecl(I)->getOriginalType();
|
|
|
|
} else {
|
|
|
|
ArgType = Proto->getArgType(I);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArgType.getAsStringInternal(ArgString, S.Context.PrintingPolicy);
|
|
|
|
|
|
|
|
if (I == CurrentArg)
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter,
|
2009-11-30 04:18:50 +08:00
|
|
|
ArgString));
|
2009-09-23 08:34:09 +08:00
|
|
|
else
|
2009-11-30 04:18:50 +08:00
|
|
|
Result->AddTextChunk(ArgString);
|
2009-09-23 08:34:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Proto && Proto->isVariadic()) {
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_Comma));
|
2009-09-23 08:34:09 +08:00
|
|
|
if (CurrentArg < NumParams)
|
|
|
|
Result->AddTextChunk("...");
|
|
|
|
else
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_CurrentParameter, "..."));
|
2009-09-23 08:34:09 +08:00
|
|
|
}
|
2009-11-07 08:00:49 +08:00
|
|
|
Result->AddChunk(Chunk(CodeCompletionString::CK_RightParen));
|
2009-09-23 08:34:09 +08:00
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-08-17 00:18:59 +08:00
|
|
|
unsigned clang::getMacroUsagePriority(llvm::StringRef MacroName,
|
2010-09-21 05:11:48 +08:00
|
|
|
const LangOptions &LangOpts,
|
2010-08-17 00:18:59 +08:00
|
|
|
bool PreferredTypeIsPointer) {
|
|
|
|
unsigned Priority = CCP_Macro;
|
|
|
|
|
2010-09-21 05:11:48 +08:00
|
|
|
// Treat the "nil", "Nil" and "NULL" macros as null pointer constants.
|
|
|
|
if (MacroName.equals("nil") || MacroName.equals("NULL") ||
|
|
|
|
MacroName.equals("Nil")) {
|
2010-08-17 00:18:59 +08:00
|
|
|
Priority = CCP_Constant;
|
|
|
|
if (PreferredTypeIsPointer)
|
|
|
|
Priority = Priority / CCF_SimilarTypeMatch;
|
2010-09-21 05:11:48 +08:00
|
|
|
}
|
|
|
|
// Treat "YES", "NO", "true", and "false" as constants.
|
|
|
|
else if (MacroName.equals("YES") || MacroName.equals("NO") ||
|
|
|
|
MacroName.equals("true") || MacroName.equals("false"))
|
|
|
|
Priority = CCP_Constant;
|
|
|
|
// Treat "bool" as a type.
|
|
|
|
else if (MacroName.equals("bool"))
|
|
|
|
Priority = CCP_Type + (LangOpts.ObjC1? CCD_bool_in_ObjC : 0);
|
|
|
|
|
2010-08-17 00:18:59 +08:00
|
|
|
|
|
|
|
return Priority;
|
|
|
|
}
|
|
|
|
|
2010-09-04 07:30:36 +08:00
|
|
|
CXCursorKind clang::getCursorKindForDecl(Decl *D) {
|
|
|
|
if (!D)
|
|
|
|
return CXCursor_UnexposedDecl;
|
|
|
|
|
|
|
|
switch (D->getKind()) {
|
|
|
|
case Decl::Enum: return CXCursor_EnumDecl;
|
|
|
|
case Decl::EnumConstant: return CXCursor_EnumConstantDecl;
|
|
|
|
case Decl::Field: return CXCursor_FieldDecl;
|
|
|
|
case Decl::Function:
|
|
|
|
return CXCursor_FunctionDecl;
|
|
|
|
case Decl::ObjCCategory: return CXCursor_ObjCCategoryDecl;
|
|
|
|
case Decl::ObjCCategoryImpl: return CXCursor_ObjCCategoryImplDecl;
|
|
|
|
case Decl::ObjCClass:
|
|
|
|
// FIXME
|
|
|
|
return CXCursor_UnexposedDecl;
|
|
|
|
case Decl::ObjCForwardProtocol:
|
|
|
|
// FIXME
|
|
|
|
return CXCursor_UnexposedDecl;
|
|
|
|
case Decl::ObjCImplementation: return CXCursor_ObjCImplementationDecl;
|
|
|
|
case Decl::ObjCInterface: return CXCursor_ObjCInterfaceDecl;
|
|
|
|
case Decl::ObjCIvar: return CXCursor_ObjCIvarDecl;
|
|
|
|
case Decl::ObjCMethod:
|
|
|
|
return cast<ObjCMethodDecl>(D)->isInstanceMethod()
|
|
|
|
? CXCursor_ObjCInstanceMethodDecl : CXCursor_ObjCClassMethodDecl;
|
|
|
|
case Decl::CXXMethod: return CXCursor_CXXMethod;
|
|
|
|
case Decl::CXXConstructor: return CXCursor_Constructor;
|
|
|
|
case Decl::CXXDestructor: return CXCursor_Destructor;
|
|
|
|
case Decl::CXXConversion: return CXCursor_ConversionFunction;
|
|
|
|
case Decl::ObjCProperty: return CXCursor_ObjCPropertyDecl;
|
|
|
|
case Decl::ObjCProtocol: return CXCursor_ObjCProtocolDecl;
|
|
|
|
case Decl::ParmVar: return CXCursor_ParmDecl;
|
|
|
|
case Decl::Typedef: return CXCursor_TypedefDecl;
|
|
|
|
case Decl::Var: return CXCursor_VarDecl;
|
|
|
|
case Decl::Namespace: return CXCursor_Namespace;
|
|
|
|
case Decl::NamespaceAlias: return CXCursor_NamespaceAlias;
|
|
|
|
case Decl::TemplateTypeParm: return CXCursor_TemplateTypeParameter;
|
|
|
|
case Decl::NonTypeTemplateParm:return CXCursor_NonTypeTemplateParameter;
|
|
|
|
case Decl::TemplateTemplateParm:return CXCursor_TemplateTemplateParameter;
|
|
|
|
case Decl::FunctionTemplate: return CXCursor_FunctionTemplate;
|
|
|
|
case Decl::ClassTemplate: return CXCursor_ClassTemplate;
|
|
|
|
case Decl::ClassTemplatePartialSpecialization:
|
|
|
|
return CXCursor_ClassTemplatePartialSpecialization;
|
|
|
|
case Decl::UsingDirective: return CXCursor_UsingDirective;
|
|
|
|
|
|
|
|
case Decl::Using:
|
|
|
|
case Decl::UnresolvedUsingValue:
|
|
|
|
case Decl::UnresolvedUsingTypename:
|
|
|
|
return CXCursor_UsingDeclaration;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
|
|
|
|
switch (TD->getTagKind()) {
|
|
|
|
case TTK_Struct: return CXCursor_StructDecl;
|
|
|
|
case TTK_Class: return CXCursor_ClassDecl;
|
|
|
|
case TTK_Union: return CXCursor_UnionDecl;
|
|
|
|
case TTK_Enum: return CXCursor_EnumDecl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CXCursor_UnexposedDecl;
|
|
|
|
}
|
|
|
|
|
2010-07-09 04:55:51 +08:00
|
|
|
static void AddMacroResults(Preprocessor &PP, ResultBuilder &Results,
|
|
|
|
bool TargetTypeIsPointer = false) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-07-09 04:55:51 +08:00
|
|
|
|
2009-10-31 00:50:04 +08:00
|
|
|
Results.EnterNewScope();
|
2010-10-19 05:05:04 +08:00
|
|
|
|
2009-11-07 08:00:49 +08:00
|
|
|
for (Preprocessor::macro_iterator M = PP.macro_begin(),
|
|
|
|
MEnd = PP.macro_end();
|
2010-07-09 04:55:51 +08:00
|
|
|
M != MEnd; ++M) {
|
2010-08-17 00:18:59 +08:00
|
|
|
Results.AddResult(Result(M->first,
|
|
|
|
getMacroUsagePriority(M->first->getName(),
|
2010-09-21 05:11:48 +08:00
|
|
|
PP.getLangOptions(),
|
2010-08-17 00:18:59 +08:00
|
|
|
TargetTypeIsPointer)));
|
2010-07-09 04:55:51 +08:00
|
|
|
}
|
2010-10-19 05:05:04 +08:00
|
|
|
|
2009-10-31 00:50:04 +08:00
|
|
|
Results.ExitScope();
|
2010-10-19 05:05:04 +08:00
|
|
|
|
2009-10-31 00:50:04 +08:00
|
|
|
}
|
|
|
|
|
2010-08-24 05:54:33 +08:00
|
|
|
static void AddPrettyFunctionResults(const LangOptions &LangOpts,
|
|
|
|
ResultBuilder &Results) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-08-24 05:54:33 +08:00
|
|
|
|
|
|
|
Results.EnterNewScope();
|
2010-10-19 05:05:04 +08:00
|
|
|
|
2010-08-24 05:54:33 +08:00
|
|
|
Results.AddResult(Result("__PRETTY_FUNCTION__", CCP_Constant));
|
|
|
|
Results.AddResult(Result("__FUNCTION__", CCP_Constant));
|
|
|
|
if (LangOpts.C99 || LangOpts.CPlusPlus0x)
|
|
|
|
Results.AddResult(Result("__func__", CCP_Constant));
|
|
|
|
Results.ExitScope();
|
|
|
|
}
|
|
|
|
|
2009-11-13 16:58:20 +08:00
|
|
|
static void HandleCodeCompleteResults(Sema *S,
|
|
|
|
CodeCompleteConsumer *CodeCompleter,
|
2010-08-12 05:23:17 +08:00
|
|
|
CodeCompletionContext Context,
|
2010-08-25 14:19:51 +08:00
|
|
|
CodeCompletionResult *Results,
|
2010-08-12 05:23:17 +08:00
|
|
|
unsigned NumResults) {
|
2009-09-22 00:56:56 +08:00
|
|
|
if (CodeCompleter)
|
2010-08-12 05:23:17 +08:00
|
|
|
CodeCompleter->ProcessCodeCompleteResults(*S, Context, Results, NumResults);
|
2009-11-19 08:01:57 +08:00
|
|
|
|
|
|
|
for (unsigned I = 0; I != NumResults; ++I)
|
|
|
|
Results[I].Destroy();
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
static enum CodeCompletionContext::Kind mapCodeCompletionContext(Sema &S,
|
|
|
|
Sema::ParserCompletionContext PCC) {
|
|
|
|
switch (PCC) {
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Namespace:
|
2010-08-12 05:23:17 +08:00
|
|
|
return CodeCompletionContext::CCC_TopLevel;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Class:
|
2010-08-12 05:23:17 +08:00
|
|
|
return CodeCompletionContext::CCC_ClassStructUnion;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ObjCInterface:
|
2010-08-12 05:23:17 +08:00
|
|
|
return CodeCompletionContext::CCC_ObjCInterface;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ObjCImplementation:
|
2010-08-12 05:23:17 +08:00
|
|
|
return CodeCompletionContext::CCC_ObjCImplementation;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ObjCInstanceVariableList:
|
2010-08-12 05:23:17 +08:00
|
|
|
return CodeCompletionContext::CCC_ObjCIvarList;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Template:
|
|
|
|
case Sema::PCC_MemberTemplate:
|
2010-09-24 07:01:17 +08:00
|
|
|
if (S.CurContext->isFileContext())
|
|
|
|
return CodeCompletionContext::CCC_TopLevel;
|
|
|
|
else if (S.CurContext->isRecord())
|
|
|
|
return CodeCompletionContext::CCC_ClassStructUnion;
|
|
|
|
else
|
|
|
|
return CodeCompletionContext::CCC_Other;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_RecoveryInFunction:
|
2010-09-24 07:01:17 +08:00
|
|
|
return CodeCompletionContext::CCC_Recovery;
|
2010-10-19 06:01:46 +08:00
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_ForInit:
|
2010-10-19 06:01:46 +08:00
|
|
|
if (S.getLangOptions().CPlusPlus || S.getLangOptions().C99 ||
|
|
|
|
S.getLangOptions().ObjC1)
|
|
|
|
return CodeCompletionContext::CCC_ParenthesizedExpression;
|
|
|
|
else
|
|
|
|
return CodeCompletionContext::CCC_Expression;
|
|
|
|
|
|
|
|
case Sema::PCC_Expression:
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Condition:
|
2010-08-12 05:23:17 +08:00
|
|
|
return CodeCompletionContext::CCC_Expression;
|
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Statement:
|
2010-08-12 05:23:17 +08:00
|
|
|
return CodeCompletionContext::CCC_Statement;
|
2010-08-24 09:11:00 +08:00
|
|
|
|
2010-08-27 07:41:50 +08:00
|
|
|
case Sema::PCC_Type:
|
2010-08-24 09:11:00 +08:00
|
|
|
return CodeCompletionContext::CCC_Type;
|
2010-09-15 07:59:36 +08:00
|
|
|
|
|
|
|
case Sema::PCC_ParenthesizedExpression:
|
|
|
|
return CodeCompletionContext::CCC_ParenthesizedExpression;
|
2010-08-12 05:23:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return CodeCompletionContext::CCC_Other;
|
|
|
|
}
|
|
|
|
|
2010-08-28 05:18:54 +08:00
|
|
|
/// \brief If we're in a C++ virtual member function, add completion results
|
|
|
|
/// that invoke the functions we override, since it's common to invoke the
|
|
|
|
/// overridden function as well as adding new functionality.
|
|
|
|
///
|
|
|
|
/// \param S The semantic analysis object for which we are generating results.
|
|
|
|
///
|
|
|
|
/// \param InContext This context in which the nested-name-specifier preceding
|
|
|
|
/// the code-completion point
|
|
|
|
static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext,
|
|
|
|
ResultBuilder &Results) {
|
|
|
|
// Look through blocks.
|
|
|
|
DeclContext *CurContext = S.CurContext;
|
|
|
|
while (isa<BlockDecl>(CurContext))
|
|
|
|
CurContext = CurContext->getParent();
|
|
|
|
|
|
|
|
|
|
|
|
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(CurContext);
|
|
|
|
if (!Method || !Method->isVirtual())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We need to have names for all of the parameters, if we're going to
|
|
|
|
// generate a forwarding call.
|
|
|
|
for (CXXMethodDecl::param_iterator P = Method->param_begin(),
|
|
|
|
PEnd = Method->param_end();
|
|
|
|
P != PEnd;
|
|
|
|
++P) {
|
|
|
|
if (!(*P)->getDeclName())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CXXMethodDecl::method_iterator M = Method->begin_overridden_methods(),
|
|
|
|
MEnd = Method->end_overridden_methods();
|
|
|
|
M != MEnd; ++M) {
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
CXXMethodDecl *Overridden = const_cast<CXXMethodDecl *>(*M);
|
|
|
|
if (Overridden->getCanonicalDecl() == Method->getCanonicalDecl())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If we need a nested-name-specifier, add one now.
|
|
|
|
if (!InContext) {
|
|
|
|
NestedNameSpecifier *NNS
|
|
|
|
= getRequiredQualification(S.Context, CurContext,
|
|
|
|
Overridden->getDeclContext());
|
|
|
|
if (NNS) {
|
|
|
|
std::string Str;
|
|
|
|
llvm::raw_string_ostream OS(Str);
|
|
|
|
NNS->print(OS, S.Context.PrintingPolicy);
|
|
|
|
Pattern->AddTextChunk(OS.str());
|
|
|
|
}
|
|
|
|
} else if (!InContext->Equals(Overridden->getDeclContext()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Pattern->AddTypedTextChunk(Overridden->getNameAsString());
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
bool FirstParam = true;
|
|
|
|
for (CXXMethodDecl::param_iterator P = Method->param_begin(),
|
|
|
|
PEnd = Method->param_end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
if (FirstParam)
|
|
|
|
FirstParam = false;
|
|
|
|
else
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_Comma);
|
|
|
|
|
|
|
|
Pattern->AddPlaceholderChunk((*P)->getIdentifier()->getName());
|
|
|
|
}
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(CodeCompletionResult(Pattern,
|
|
|
|
CCP_SuperCompletion,
|
|
|
|
CXCursor_CXXMethod));
|
|
|
|
Results.Ignore(Overridden);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
void Sema::CodeCompleteOrdinaryName(Scope *S,
|
2010-08-12 05:23:17 +08:00
|
|
|
ParserCompletionContext CompletionContext) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this,
|
|
|
|
mapCodeCompletionContext(*this, CompletionContext));
|
2010-08-28 05:18:54 +08:00
|
|
|
Results.EnterNewScope();
|
2010-09-21 06:39:41 +08:00
|
|
|
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
// Determine how to filter results, e.g., so that the names of
|
|
|
|
// values (functions, enumerators, function templates, etc.) are
|
|
|
|
// only allowed where we can have an expression.
|
|
|
|
switch (CompletionContext) {
|
2010-08-12 05:23:17 +08:00
|
|
|
case PCC_Namespace:
|
|
|
|
case PCC_Class:
|
|
|
|
case PCC_ObjCInterface:
|
|
|
|
case PCC_ObjCImplementation:
|
|
|
|
case PCC_ObjCInstanceVariableList:
|
|
|
|
case PCC_Template:
|
|
|
|
case PCC_MemberTemplate:
|
2010-08-24 09:11:00 +08:00
|
|
|
case PCC_Type:
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
|
|
|
|
break;
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
case PCC_Statement:
|
2010-09-15 07:59:36 +08:00
|
|
|
case PCC_ParenthesizedExpression:
|
2010-08-25 07:58:17 +08:00
|
|
|
case PCC_Expression:
|
2010-08-12 05:23:17 +08:00
|
|
|
case PCC_ForInit:
|
|
|
|
case PCC_Condition:
|
2010-05-28 08:49:12 +08:00
|
|
|
if (WantTypesInContext(CompletionContext, getLangOptions()))
|
|
|
|
Results.setFilter(&ResultBuilder::IsOrdinaryName);
|
|
|
|
else
|
|
|
|
Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
|
2010-08-28 05:18:54 +08:00
|
|
|
|
|
|
|
if (getLangOptions().CPlusPlus)
|
|
|
|
MaybeAddOverrideCalls(*this, /*InContext=*/0, Results);
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
break;
|
2010-05-25 13:58:43 +08:00
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
case PCC_RecoveryInFunction:
|
2010-05-25 13:58:43 +08:00
|
|
|
// Unfiltered
|
|
|
|
break;
|
Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for
static_cast<type>(expr)
when we can have an expression, or
using namespace identifier;
when we can have a using directive.
Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.
llvm-svn: 93134
2010-01-11 07:08:15 +08:00
|
|
|
}
|
|
|
|
|
2010-08-27 00:36:48 +08:00
|
|
|
// If we are in a C++ non-static member function, check the qualifiers on
|
|
|
|
// the member function to filter/prioritize the results list.
|
|
|
|
if (CXXMethodDecl *CurMethod = dyn_cast<CXXMethodDecl>(CurContext))
|
|
|
|
if (CurMethod->isInstance())
|
|
|
|
Results.setObjectTypeQualifiers(
|
|
|
|
Qualifiers::fromCVRMask(CurMethod->getTypeQualifiers()));
|
|
|
|
|
2010-01-14 09:09:38 +08:00
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
2010-08-15 14:18:01 +08:00
|
|
|
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2009-12-07 17:54:55 +08:00
|
|
|
|
2010-01-14 07:51:12 +08:00
|
|
|
AddOrdinaryNameResults(CompletionContext, S, *this, Results);
|
2009-12-07 17:54:55 +08:00
|
|
|
Results.ExitScope();
|
|
|
|
|
2010-08-24 05:54:33 +08:00
|
|
|
switch (CompletionContext) {
|
2010-09-15 07:59:36 +08:00
|
|
|
case PCC_ParenthesizedExpression:
|
2010-08-24 09:11:00 +08:00
|
|
|
case PCC_Expression:
|
|
|
|
case PCC_Statement:
|
|
|
|
case PCC_RecoveryInFunction:
|
|
|
|
if (S->getFnParent())
|
|
|
|
AddPrettyFunctionResults(PP.getLangOptions(), Results);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCC_Namespace:
|
|
|
|
case PCC_Class:
|
|
|
|
case PCC_ObjCInterface:
|
|
|
|
case PCC_ObjCImplementation:
|
|
|
|
case PCC_ObjCInstanceVariableList:
|
|
|
|
case PCC_Template:
|
|
|
|
case PCC_MemberTemplate:
|
|
|
|
case PCC_ForInit:
|
|
|
|
case PCC_Condition:
|
|
|
|
case PCC_Type:
|
|
|
|
break;
|
2010-08-24 05:54:33 +08:00
|
|
|
}
|
|
|
|
|
2009-11-07 08:00:49 +08:00
|
|
|
if (CodeCompleter->includeMacros())
|
2010-01-14 07:51:12 +08:00
|
|
|
AddMacroResults(PP, Results);
|
2010-08-24 05:54:33 +08:00
|
|
|
|
2010-09-21 06:39:41 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(),Results.size());
|
2009-09-22 04:51:25 +08:00
|
|
|
}
|
|
|
|
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
static void AddClassMessageCompletions(Sema &SemaRef, Scope *S,
|
|
|
|
ParsedType Receiver,
|
|
|
|
IdentifierInfo **SelIdents,
|
|
|
|
unsigned NumSelIdents,
|
2010-09-21 07:34:21 +08:00
|
|
|
bool AtArgumentExpression,
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
bool IsSuper,
|
|
|
|
ResultBuilder &Results);
|
|
|
|
|
|
|
|
void Sema::CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
|
|
|
|
bool AllowNonIdentifiers,
|
|
|
|
bool AllowNestedNameSpecifiers) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this,
|
|
|
|
AllowNestedNameSpecifiers
|
|
|
|
? CodeCompletionContext::CCC_PotentiallyQualifiedName
|
|
|
|
: CodeCompletionContext::CCC_Name);
|
2010-08-24 02:23:48 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// Type qualifiers can come after names.
|
|
|
|
Results.AddResult(Result("const"));
|
|
|
|
Results.AddResult(Result("volatile"));
|
|
|
|
if (getLangOptions().C99)
|
|
|
|
Results.AddResult(Result("restrict"));
|
|
|
|
|
|
|
|
if (getLangOptions().CPlusPlus) {
|
|
|
|
if (AllowNonIdentifiers) {
|
|
|
|
Results.AddResult(Result("operator"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add nested-name-specifiers.
|
|
|
|
if (AllowNestedNameSpecifiers) {
|
|
|
|
Results.allowNestedNameSpecifiers();
|
2010-09-24 07:01:17 +08:00
|
|
|
Results.setFilter(&ResultBuilder::IsImpossibleToSatisfy);
|
2010-08-24 02:23:48 +08:00
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
|
|
|
LookupVisibleDecls(S, LookupNestedNameSpecifierName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2010-09-24 07:01:17 +08:00
|
|
|
Results.setFilter(0);
|
2010-08-24 02:23:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Results.ExitScope();
|
|
|
|
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
// If we're in a context where we might have an expression (rather than a
|
|
|
|
// declaration), and what we've seen so far is an Objective-C type that could
|
|
|
|
// be a receiver of a class message, this may be a class message send with
|
|
|
|
// the initial opening bracket '[' missing. Add appropriate completions.
|
|
|
|
if (AllowNonIdentifiers && !AllowNestedNameSpecifiers &&
|
|
|
|
DS.getTypeSpecType() == DeclSpec::TST_typename &&
|
|
|
|
DS.getStorageClassSpecAsWritten() == DeclSpec::SCS_unspecified &&
|
|
|
|
!DS.isThreadSpecified() && !DS.isExternInLinkageSpec() &&
|
|
|
|
DS.getTypeSpecComplex() == DeclSpec::TSC_unspecified &&
|
|
|
|
DS.getTypeSpecSign() == DeclSpec::TSS_unspecified &&
|
|
|
|
DS.getTypeQualifiers() == 0 &&
|
|
|
|
S &&
|
|
|
|
(S->getFlags() & Scope::DeclScope) != 0 &&
|
|
|
|
(S->getFlags() & (Scope::ClassScope | Scope::TemplateParamScope |
|
|
|
|
Scope::FunctionPrototypeScope |
|
|
|
|
Scope::AtCatchScope)) == 0) {
|
|
|
|
ParsedType T = DS.getRepAsType();
|
|
|
|
if (!T.get().isNull() && T.get()->isObjCObjectOrInterfaceType())
|
2010-09-21 07:34:21 +08:00
|
|
|
AddClassMessageCompletions(*this, S, T, 0, 0, false, false, Results);
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
}
|
|
|
|
|
2010-08-24 12:59:56 +08:00
|
|
|
// Note that we intentionally suppress macro results here, since we do not
|
|
|
|
// encourage using macros to produce the names of entities.
|
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
Results.getCompletionContext(),
|
2010-08-24 02:23:48 +08:00
|
|
|
Results.data(), Results.size());
|
|
|
|
}
|
|
|
|
|
2010-08-24 05:17:50 +08:00
|
|
|
struct Sema::CodeCompleteExpressionData {
|
|
|
|
CodeCompleteExpressionData(QualType PreferredType = QualType())
|
|
|
|
: PreferredType(PreferredType), IntegralConstantExpression(false),
|
|
|
|
ObjCCollection(false) { }
|
|
|
|
|
|
|
|
QualType PreferredType;
|
|
|
|
bool IntegralConstantExpression;
|
|
|
|
bool ObjCCollection;
|
|
|
|
llvm::SmallVector<Decl *, 4> IgnoreDecls;
|
|
|
|
};
|
|
|
|
|
2010-05-30 09:49:25 +08:00
|
|
|
/// \brief Perform code-completion in an expression context when we know what
|
|
|
|
/// type we're looking for.
|
2010-07-29 05:50:18 +08:00
|
|
|
///
|
|
|
|
/// \param IntegralConstantExpression Only permit integral constant
|
|
|
|
/// expressions.
|
2010-08-24 05:17:50 +08:00
|
|
|
void Sema::CodeCompleteExpression(Scope *S,
|
|
|
|
const CodeCompleteExpressionData &Data) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Expression);
|
2010-08-24 05:17:50 +08:00
|
|
|
if (Data.ObjCCollection)
|
|
|
|
Results.setFilter(&ResultBuilder::IsObjCCollection);
|
|
|
|
else if (Data.IntegralConstantExpression)
|
2010-07-29 05:50:18 +08:00
|
|
|
Results.setFilter(&ResultBuilder::IsIntegralConstantValue);
|
2010-08-12 05:23:17 +08:00
|
|
|
else if (WantTypesInContext(PCC_Expression, getLangOptions()))
|
2010-05-30 09:49:25 +08:00
|
|
|
Results.setFilter(&ResultBuilder::IsOrdinaryName);
|
|
|
|
else
|
|
|
|
Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
|
2010-08-24 05:17:50 +08:00
|
|
|
|
|
|
|
if (!Data.PreferredType.isNull())
|
|
|
|
Results.setPreferredType(Data.PreferredType.getNonReferenceType());
|
|
|
|
|
|
|
|
// Ignore any declarations that we were told that we don't care about.
|
|
|
|
for (unsigned I = 0, N = Data.IgnoreDecls.size(); I != N; ++I)
|
|
|
|
Results.Ignore(Data.IgnoreDecls[I]);
|
2010-05-30 09:49:25 +08:00
|
|
|
|
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
2010-08-15 14:18:01 +08:00
|
|
|
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2010-05-30 09:49:25 +08:00
|
|
|
|
|
|
|
Results.EnterNewScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
AddOrdinaryNameResults(PCC_Expression, S, *this, Results);
|
2010-05-30 09:49:25 +08:00
|
|
|
Results.ExitScope();
|
|
|
|
|
2010-07-09 04:55:51 +08:00
|
|
|
bool PreferredTypeIsPointer = false;
|
2010-08-24 05:17:50 +08:00
|
|
|
if (!Data.PreferredType.isNull())
|
|
|
|
PreferredTypeIsPointer = Data.PreferredType->isAnyPointerType()
|
|
|
|
|| Data.PreferredType->isMemberPointerType()
|
|
|
|
|| Data.PreferredType->isBlockPointerType();
|
2010-07-09 04:55:51 +08:00
|
|
|
|
2010-08-24 05:54:33 +08:00
|
|
|
if (S->getFnParent() &&
|
|
|
|
!Data.ObjCCollection &&
|
|
|
|
!Data.IntegralConstantExpression)
|
|
|
|
AddPrettyFunctionResults(PP.getLangOptions(), Results);
|
|
|
|
|
2010-05-30 09:49:25 +08:00
|
|
|
if (CodeCompleter->includeMacros())
|
2010-07-09 04:55:51 +08:00
|
|
|
AddMacroResults(PP, Results, PreferredTypeIsPointer);
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
2010-08-24 05:17:50 +08:00
|
|
|
CodeCompletionContext(CodeCompletionContext::CCC_Expression,
|
|
|
|
Data.PreferredType),
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(),Results.size());
|
2010-05-30 09:49:25 +08:00
|
|
|
}
|
|
|
|
|
2010-09-18 09:28:11 +08:00
|
|
|
void Sema::CodeCompletePostfixExpression(Scope *S, ExprResult E) {
|
|
|
|
if (E.isInvalid())
|
|
|
|
CodeCompleteOrdinaryName(S, PCC_RecoveryInFunction);
|
|
|
|
else if (getLangOptions().ObjC1)
|
|
|
|
CodeCompleteObjCInstanceMessage(S, E.take(), 0, 0, false);
|
2010-09-16 00:23:04 +08:00
|
|
|
}
|
2010-05-30 09:49:25 +08:00
|
|
|
|
2009-11-18 09:29:26 +08:00
|
|
|
static void AddObjCProperties(ObjCContainerDecl *Container,
|
2009-11-19 06:32:06 +08:00
|
|
|
bool AllowCategories,
|
2009-11-18 09:29:26 +08:00
|
|
|
DeclContext *CurContext,
|
|
|
|
ResultBuilder &Results) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-11-18 09:29:26 +08:00
|
|
|
|
|
|
|
// Add properties in this container.
|
|
|
|
for (ObjCContainerDecl::prop_iterator P = Container->prop_begin(),
|
|
|
|
PEnd = Container->prop_end();
|
|
|
|
P != PEnd;
|
|
|
|
++P)
|
|
|
|
Results.MaybeAddResult(Result(*P, 0), CurContext);
|
|
|
|
|
|
|
|
// Add properties in referenced protocols.
|
|
|
|
if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
|
|
|
|
for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(),
|
|
|
|
PEnd = Protocol->protocol_end();
|
|
|
|
P != PEnd; ++P)
|
2009-11-19 06:32:06 +08:00
|
|
|
AddObjCProperties(*P, AllowCategories, CurContext, Results);
|
2009-11-18 09:29:26 +08:00
|
|
|
} else if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container)){
|
2009-11-19 06:32:06 +08:00
|
|
|
if (AllowCategories) {
|
|
|
|
// Look through categories.
|
|
|
|
for (ObjCCategoryDecl *Category = IFace->getCategoryList();
|
|
|
|
Category; Category = Category->getNextClassCategory())
|
|
|
|
AddObjCProperties(Category, AllowCategories, CurContext, Results);
|
|
|
|
}
|
2009-11-18 09:29:26 +08:00
|
|
|
|
|
|
|
// Look through protocols.
|
2010-09-01 09:21:15 +08:00
|
|
|
for (ObjCInterfaceDecl::all_protocol_iterator
|
|
|
|
I = IFace->all_referenced_protocol_begin(),
|
|
|
|
E = IFace->all_referenced_protocol_end(); I != E; ++I)
|
2009-11-19 06:32:06 +08:00
|
|
|
AddObjCProperties(*I, AllowCategories, CurContext, Results);
|
2009-11-18 09:29:26 +08:00
|
|
|
|
|
|
|
// Look in the superclass.
|
|
|
|
if (IFace->getSuperClass())
|
2009-11-19 06:32:06 +08:00
|
|
|
AddObjCProperties(IFace->getSuperClass(), AllowCategories, CurContext,
|
|
|
|
Results);
|
2009-11-18 09:29:26 +08:00
|
|
|
} else if (const ObjCCategoryDecl *Category
|
|
|
|
= dyn_cast<ObjCCategoryDecl>(Container)) {
|
|
|
|
// Look through protocols.
|
2010-09-01 09:21:15 +08:00
|
|
|
for (ObjCCategoryDecl::protocol_iterator P = Category->protocol_begin(),
|
|
|
|
PEnd = Category->protocol_end();
|
2009-11-18 09:29:26 +08:00
|
|
|
P != PEnd; ++P)
|
2009-11-19 06:32:06 +08:00
|
|
|
AddObjCProperties(*P, AllowCategories, CurContext, Results);
|
2009-11-18 09:29:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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::CodeCompleteMemberReferenceExpr(Scope *S, ExprTy *BaseE,
|
|
|
|
SourceLocation OpLoc,
|
|
|
|
bool IsArrow) {
|
|
|
|
if (!BaseE || !CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-09-22 00:56:56 +08:00
|
|
|
|
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
|
|
|
Expr *Base = static_cast<Expr *>(BaseE);
|
|
|
|
QualType BaseType = Base->getType();
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
if (IsArrow) {
|
|
|
|
if (const PointerType *Ptr = BaseType->getAs<PointerType>())
|
|
|
|
BaseType = Ptr->getPointeeType();
|
|
|
|
else if (BaseType->isObjCObjectPointerType())
|
2010-08-27 00:36:48 +08:00
|
|
|
/*Do nothing*/ ;
|
2009-09-22 00:56:56 +08:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this,
|
|
|
|
CodeCompletionContext(CodeCompletionContext::CCC_MemberAccess,
|
|
|
|
BaseType),
|
|
|
|
&ResultBuilder::IsMember);
|
2009-11-18 09:29:26 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
if (const RecordType *Record = BaseType->getAs<RecordType>()) {
|
2010-08-27 00:36:48 +08:00
|
|
|
// Indicate that we are performing a member access, and the cv-qualifiers
|
|
|
|
// for the base object type.
|
|
|
|
Results.setObjectTypeQualifiers(BaseType.getQualifiers());
|
|
|
|
|
2009-11-18 09:29:26 +08:00
|
|
|
// Access to a C/C++ class, struct, or union.
|
2010-01-14 11:21:49 +08:00
|
|
|
Results.allowNestedNameSpecifiers();
|
2010-01-14 23:47:35 +08:00
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
2010-08-15 14:18:01 +08:00
|
|
|
LookupVisibleDecls(Record->getDecl(), LookupMemberName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2009-11-13 16:58:20 +08:00
|
|
|
|
2009-11-18 09:29:26 +08:00
|
|
|
if (getLangOptions().CPlusPlus) {
|
|
|
|
if (!Results.empty()) {
|
|
|
|
// The "template" keyword can follow "->" or "." in the grammar.
|
|
|
|
// However, we only want to suggest the template keyword if something
|
|
|
|
// is dependent.
|
|
|
|
bool IsDependent = BaseType->isDependentType();
|
|
|
|
if (!IsDependent) {
|
|
|
|
for (Scope *DepScope = S; DepScope; DepScope = DepScope->getParent())
|
|
|
|
if (DeclContext *Ctx = (DeclContext *)DepScope->getEntity()) {
|
|
|
|
IsDependent = Ctx->isDependentContext();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-13 16:58:20 +08:00
|
|
|
|
2009-11-18 09:29:26 +08:00
|
|
|
if (IsDependent)
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result("template"));
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
2009-11-18 09:29:26 +08:00
|
|
|
}
|
|
|
|
} else if (!IsArrow && BaseType->getAsObjCInterfacePointerType()) {
|
|
|
|
// Objective-C property reference.
|
|
|
|
|
|
|
|
// Add property results based on our interface.
|
|
|
|
const ObjCObjectPointerType *ObjCPtr
|
|
|
|
= BaseType->getAsObjCInterfacePointerType();
|
|
|
|
assert(ObjCPtr && "Non-NULL pointer guaranteed above!");
|
2009-11-19 06:32:06 +08:00
|
|
|
AddObjCProperties(ObjCPtr->getInterfaceDecl(), true, CurContext, Results);
|
2009-11-18 09:29:26 +08:00
|
|
|
|
|
|
|
// Add properties from the protocols in a qualified interface.
|
|
|
|
for (ObjCObjectPointerType::qual_iterator I = ObjCPtr->qual_begin(),
|
|
|
|
E = ObjCPtr->qual_end();
|
|
|
|
I != E; ++I)
|
2009-11-19 06:32:06 +08:00
|
|
|
AddObjCProperties(*I, true, CurContext, Results);
|
2009-11-18 09:29:26 +08:00
|
|
|
} else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||
|
2010-05-15 19:32:37 +08:00
|
|
|
(!IsArrow && BaseType->isObjCObjectType())) {
|
2009-11-18 09:29:26 +08:00
|
|
|
// Objective-C instance variable access.
|
|
|
|
ObjCInterfaceDecl *Class = 0;
|
|
|
|
if (const ObjCObjectPointerType *ObjCPtr
|
|
|
|
= BaseType->getAs<ObjCObjectPointerType>())
|
|
|
|
Class = ObjCPtr->getInterfaceDecl();
|
|
|
|
else
|
2010-05-15 19:32:37 +08:00
|
|
|
Class = BaseType->getAs<ObjCObjectType>()->getInterface();
|
2009-11-18 09:29:26 +08:00
|
|
|
|
|
|
|
// Add all ivars from this class and its superclasses.
|
2010-01-15 00:08:12 +08:00
|
|
|
if (Class) {
|
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
|
|
|
Results.setFilter(&ResultBuilder::IsObjCIvar);
|
2010-08-15 14:18:01 +08:00
|
|
|
LookupVisibleDecls(Class, LookupMemberName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
}
|
2009-11-18 09:29:26 +08:00
|
|
|
|
|
|
|
// FIXME: How do we cope with isa?
|
|
|
|
|
|
|
|
Results.ExitScope();
|
2009-11-13 16:58:20 +08:00
|
|
|
|
|
|
|
// Hand off the results found for code completion.
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
2010-09-24 07:01:17 +08:00
|
|
|
Results.getCompletionContext(),
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(),Results.size());
|
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
|
|
|
}
|
|
|
|
|
2009-09-18 23:37:17 +08:00
|
|
|
void Sema::CodeCompleteTag(Scope *S, unsigned TagSpec) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-09-22 00:56:56 +08:00
|
|
|
ResultBuilder::LookupFilter Filter = 0;
|
2010-08-12 05:23:17 +08:00
|
|
|
enum CodeCompletionContext::Kind ContextKind
|
|
|
|
= CodeCompletionContext::CCC_Other;
|
2009-09-18 23:37:17 +08:00
|
|
|
switch ((DeclSpec::TST)TagSpec) {
|
|
|
|
case DeclSpec::TST_enum:
|
2009-09-22 00:56:56 +08:00
|
|
|
Filter = &ResultBuilder::IsEnum;
|
2010-08-12 05:23:17 +08:00
|
|
|
ContextKind = CodeCompletionContext::CCC_EnumTag;
|
2009-09-18 23:37:17 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclSpec::TST_union:
|
2009-09-22 00:56:56 +08:00
|
|
|
Filter = &ResultBuilder::IsUnion;
|
2010-08-12 05:23:17 +08:00
|
|
|
ContextKind = CodeCompletionContext::CCC_UnionTag;
|
2009-09-18 23:37:17 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclSpec::TST_struct:
|
|
|
|
case DeclSpec::TST_class:
|
2009-09-22 00:56:56 +08:00
|
|
|
Filter = &ResultBuilder::IsClassOrStruct;
|
2010-08-12 05:23:17 +08:00
|
|
|
ContextKind = CodeCompletionContext::CCC_ClassOrStructTag;
|
2009-09-18 23:37:17 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(false && "Unknown type specifier kind in CodeCompleteTag");
|
|
|
|
return;
|
|
|
|
}
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, ContextKind);
|
2010-01-14 11:27:13 +08:00
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
2010-04-24 02:46:30 +08:00
|
|
|
|
|
|
|
// First pass: look for tags.
|
|
|
|
Results.setFilter(Filter);
|
2010-08-15 14:18:01 +08:00
|
|
|
LookupVisibleDecls(S, LookupTagName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2010-04-24 02:46:30 +08:00
|
|
|
|
2010-08-15 14:18:01 +08:00
|
|
|
if (CodeCompleter->includeGlobals()) {
|
|
|
|
// Second pass: look for nested name specifiers.
|
|
|
|
Results.setFilter(&ResultBuilder::IsNestedNameSpecifier);
|
|
|
|
LookupVisibleDecls(S, LookupNestedNameSpecifierName, Consumer);
|
|
|
|
}
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(),Results.size());
|
2009-09-18 23:37:17 +08:00
|
|
|
}
|
|
|
|
|
2010-08-28 01:35:51 +08:00
|
|
|
void Sema::CodeCompleteTypeQualifiers(DeclSpec &DS) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_TypeQualifiers);
|
2010-08-28 01:35:51 +08:00
|
|
|
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,
|
2010-09-24 07:01:17 +08:00
|
|
|
Results.getCompletionContext(),
|
2010-08-28 01:35:51 +08:00
|
|
|
Results.data(), Results.size());
|
|
|
|
}
|
|
|
|
|
2009-09-22 02:10:23 +08:00
|
|
|
void Sema::CodeCompleteCase(Scope *S) {
|
2010-08-25 16:40:02 +08:00
|
|
|
if (getCurFunction()->SwitchStack.empty() || !CodeCompleter)
|
2009-09-22 02:10:23 +08:00
|
|
|
return;
|
|
|
|
|
2010-08-25 16:40:02 +08:00
|
|
|
SwitchStmt *Switch = getCurFunction()->SwitchStack.back();
|
2010-07-29 05:50:18 +08:00
|
|
|
if (!Switch->getCond()->getType()->isEnumeralType()) {
|
2010-08-24 05:17:50 +08:00
|
|
|
CodeCompleteExpressionData Data(Switch->getCond()->getType());
|
|
|
|
Data.IntegralConstantExpression = true;
|
|
|
|
CodeCompleteExpression(S, Data);
|
2009-09-22 02:10:23 +08:00
|
|
|
return;
|
2010-07-29 05:50:18 +08:00
|
|
|
}
|
2009-09-22 02:10:23 +08:00
|
|
|
|
|
|
|
// Code-complete the cases of a switch statement over an enumeration type
|
|
|
|
// by providing the list of
|
|
|
|
EnumDecl *Enum = Switch->getCond()->getType()->getAs<EnumType>()->getDecl();
|
|
|
|
|
|
|
|
// Determine which enumerators we have already seen in the switch statement.
|
|
|
|
// FIXME: Ideally, we would also be able to look *past* the code-completion
|
|
|
|
// token, in case we are code-completing in the middle of the switch and not
|
|
|
|
// at the end. However, we aren't able to do so at the moment.
|
|
|
|
llvm::SmallPtrSet<EnumConstantDecl *, 8> EnumeratorsSeen;
|
2009-09-22 03:57:38 +08:00
|
|
|
NestedNameSpecifier *Qualifier = 0;
|
2009-09-22 02:10:23 +08:00
|
|
|
for (SwitchCase *SC = Switch->getSwitchCaseList(); SC;
|
|
|
|
SC = SC->getNextSwitchCase()) {
|
|
|
|
CaseStmt *Case = dyn_cast<CaseStmt>(SC);
|
|
|
|
if (!Case)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Expr *CaseVal = Case->getLHS()->IgnoreParenCasts();
|
|
|
|
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CaseVal))
|
|
|
|
if (EnumConstantDecl *Enumerator
|
|
|
|
= dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
|
|
|
|
// We look into the AST of the case statement to determine which
|
|
|
|
// enumerator was named. Alternatively, we could compute the value of
|
|
|
|
// the integral constant expression, then compare it against the
|
|
|
|
// values of each enumerator. However, value-based approach would not
|
|
|
|
// work as well with C++ templates where enumerators declared within a
|
|
|
|
// template are type- and value-dependent.
|
|
|
|
EnumeratorsSeen.insert(Enumerator);
|
|
|
|
|
2009-09-22 03:57:38 +08:00
|
|
|
// If this is a qualified-id, keep track of the nested-name-specifier
|
|
|
|
// so that we can reproduce it as part of code completion, e.g.,
|
2009-09-22 02:10:23 +08:00
|
|
|
//
|
|
|
|
// switch (TagD.getKind()) {
|
|
|
|
// case TagDecl::TK_enum:
|
|
|
|
// break;
|
|
|
|
// case XXX
|
|
|
|
//
|
2009-09-22 03:57:38 +08:00
|
|
|
// At the XXX, our completions are TagDecl::TK_union,
|
2009-09-22 02:10:23 +08:00
|
|
|
// TagDecl::TK_struct, and TagDecl::TK_class, rather than TK_union,
|
|
|
|
// TK_struct, and TK_class.
|
2009-10-24 02:54:35 +08:00
|
|
|
Qualifier = DRE->getQualifier();
|
2009-09-22 02:10:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 03:57:38 +08:00
|
|
|
if (getLangOptions().CPlusPlus && !Qualifier && EnumeratorsSeen.empty()) {
|
|
|
|
// If there are no prior enumerators in C++, check whether we have to
|
|
|
|
// qualify the names of the enumerators that we suggest, because they
|
|
|
|
// may not be visible in this scope.
|
|
|
|
Qualifier = getRequiredQualification(Context, CurContext,
|
|
|
|
Enum->getDeclContext());
|
|
|
|
|
|
|
|
// FIXME: Scoped enums need to start with "EnumDecl" as the context!
|
|
|
|
}
|
|
|
|
|
2009-09-22 02:10:23 +08:00
|
|
|
// Add any enumerators that have not yet been mentioned.
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Expression);
|
2009-09-22 02:10:23 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
for (EnumDecl::enumerator_iterator E = Enum->enumerator_begin(),
|
|
|
|
EEnd = Enum->enumerator_end();
|
|
|
|
E != EEnd; ++E) {
|
|
|
|
if (EnumeratorsSeen.count(*E))
|
|
|
|
continue;
|
|
|
|
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult(*E, Qualifier),
|
2010-01-15 00:14:35 +08:00
|
|
|
CurContext, 0, false);
|
2009-09-22 02:10:23 +08:00
|
|
|
}
|
|
|
|
Results.ExitScope();
|
2010-04-07 04:02:15 +08:00
|
|
|
|
2009-11-07 08:00:49 +08:00
|
|
|
if (CodeCompleter->includeMacros())
|
2010-01-14 07:51:12 +08:00
|
|
|
AddMacroResults(PP, Results);
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Expression,
|
|
|
|
Results.data(),Results.size());
|
2009-09-22 02:10:23 +08:00
|
|
|
}
|
|
|
|
|
2009-09-22 23:41:20 +08:00
|
|
|
namespace {
|
|
|
|
struct IsBetterOverloadCandidate {
|
|
|
|
Sema &S;
|
2010-02-09 07:07:23 +08:00
|
|
|
SourceLocation Loc;
|
2009-09-22 23:41:20 +08:00
|
|
|
|
|
|
|
public:
|
2010-02-09 07:07:23 +08:00
|
|
|
explicit IsBetterOverloadCandidate(Sema &S, SourceLocation Loc)
|
|
|
|
: S(S), Loc(Loc) { }
|
2009-09-22 23:41:20 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
operator()(const OverloadCandidate &X, const OverloadCandidate &Y) const {
|
2010-08-25 04:38:10 +08:00
|
|
|
return isBetterOverloadCandidate(S, X, Y, Loc);
|
2009-09-22 23:41:20 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-05-30 14:10:08 +08:00
|
|
|
static bool anyNullArguments(Expr **Args, unsigned NumArgs) {
|
|
|
|
if (NumArgs && !Args)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (unsigned I = 0; I != NumArgs; ++I)
|
|
|
|
if (!Args[I])
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-22 23:41:20 +08:00
|
|
|
void Sema::CodeCompleteCall(Scope *S, ExprTy *FnIn,
|
|
|
|
ExprTy **ArgsIn, unsigned NumArgs) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
2009-12-12 03:06:04 +08:00
|
|
|
|
|
|
|
// When we're code-completing for a call, we fall back to ordinary
|
|
|
|
// name code-completion whenever we can't produce specific
|
|
|
|
// results. We may want to revisit this strategy in the future,
|
|
|
|
// e.g., by merging the two kinds of results.
|
|
|
|
|
2009-09-22 23:41:20 +08:00
|
|
|
Expr *Fn = (Expr *)FnIn;
|
|
|
|
Expr **Args = (Expr **)ArgsIn;
|
2009-12-12 03:06:04 +08:00
|
|
|
|
2009-09-22 23:41:20 +08:00
|
|
|
// Ignore type-dependent call expressions entirely.
|
2010-05-30 14:10:08 +08:00
|
|
|
if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args, NumArgs) ||
|
2009-12-12 03:06:04 +08:00
|
|
|
Expr::hasAnyTypeDependentArguments(Args, NumArgs)) {
|
2010-08-12 05:23:17 +08:00
|
|
|
CodeCompleteOrdinaryName(S, PCC_Expression);
|
2009-09-22 23:41:20 +08:00
|
|
|
return;
|
2009-12-12 03:06:04 +08:00
|
|
|
}
|
2009-09-22 23:41:20 +08:00
|
|
|
|
2009-12-16 20:17:52 +08:00
|
|
|
// Build an overload candidate set based on the functions we find.
|
2010-02-09 07:07:23 +08:00
|
|
|
SourceLocation Loc = Fn->getExprLoc();
|
|
|
|
OverloadCandidateSet CandidateSet(Loc);
|
2009-12-16 20:17:52 +08:00
|
|
|
|
2009-09-22 23:41:20 +08:00
|
|
|
// FIXME: What if we're calling something that isn't a function declaration?
|
|
|
|
// FIXME: What if we're calling a pseudo-destructor?
|
|
|
|
// FIXME: What if we're calling a member function?
|
|
|
|
|
2010-01-21 23:46:19 +08:00
|
|
|
typedef CodeCompleteConsumer::OverloadCandidate ResultCandidate;
|
|
|
|
llvm::SmallVector<ResultCandidate, 8> Results;
|
|
|
|
|
2009-12-16 20:17:52 +08:00
|
|
|
Expr *NakedFn = Fn->IgnoreParenCasts();
|
|
|
|
if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(NakedFn))
|
|
|
|
AddOverloadedCallCandidates(ULE, Args, NumArgs, CandidateSet,
|
|
|
|
/*PartialOverloading=*/ true);
|
|
|
|
else if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(NakedFn)) {
|
|
|
|
FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
|
2010-01-21 23:46:19 +08:00
|
|
|
if (FDecl) {
|
2010-05-30 14:10:08 +08:00
|
|
|
if (!getLangOptions().CPlusPlus ||
|
|
|
|
!FDecl->getType()->getAs<FunctionProtoType>())
|
2010-01-21 23:46:19 +08:00
|
|
|
Results.push_back(ResultCandidate(FDecl));
|
|
|
|
else
|
2010-01-26 09:37:31 +08:00
|
|
|
// FIXME: access?
|
2010-03-19 15:35:19 +08:00
|
|
|
AddOverloadCandidate(FDecl, DeclAccessPair::make(FDecl, AS_none),
|
|
|
|
Args, NumArgs, CandidateSet,
|
2010-04-17 01:41:49 +08:00
|
|
|
false, /*PartialOverloading*/true);
|
2010-01-21 23:46:19 +08:00
|
|
|
}
|
2009-12-16 20:17:52 +08:00
|
|
|
}
|
2009-09-22 23:41:20 +08:00
|
|
|
|
2010-05-30 09:49:25 +08:00
|
|
|
QualType ParamType;
|
|
|
|
|
2010-01-21 23:46:19 +08:00
|
|
|
if (!CandidateSet.empty()) {
|
|
|
|
// Sort the overload candidate set by placing the best overloads first.
|
|
|
|
std::stable_sort(CandidateSet.begin(), CandidateSet.end(),
|
2010-02-09 07:07:23 +08:00
|
|
|
IsBetterOverloadCandidate(*this, Loc));
|
2010-01-21 23:46:19 +08:00
|
|
|
|
|
|
|
// Add the remaining viable overload candidates as code-completion reslults.
|
|
|
|
for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(),
|
|
|
|
CandEnd = CandidateSet.end();
|
|
|
|
Cand != CandEnd; ++Cand) {
|
|
|
|
if (Cand->Viable)
|
|
|
|
Results.push_back(ResultCandidate(Cand->Function));
|
|
|
|
}
|
2010-05-30 09:49:25 +08:00
|
|
|
|
|
|
|
// From the viable candidates, try to determine the type of this parameter.
|
|
|
|
for (unsigned I = 0, N = Results.size(); I != N; ++I) {
|
|
|
|
if (const FunctionType *FType = Results[I].getFunctionType())
|
|
|
|
if (const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FType))
|
|
|
|
if (NumArgs < Proto->getNumArgs()) {
|
|
|
|
if (ParamType.isNull())
|
|
|
|
ParamType = Proto->getArgType(NumArgs);
|
|
|
|
else if (!Context.hasSameUnqualifiedType(
|
|
|
|
ParamType.getNonReferenceType(),
|
|
|
|
Proto->getArgType(NumArgs).getNonReferenceType())) {
|
|
|
|
ParamType = QualType();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Try to determine the parameter type from the type of the expression
|
|
|
|
// being called.
|
|
|
|
QualType FunctionType = Fn->getType();
|
|
|
|
if (const PointerType *Ptr = FunctionType->getAs<PointerType>())
|
|
|
|
FunctionType = Ptr->getPointeeType();
|
|
|
|
else if (const BlockPointerType *BlockPtr
|
|
|
|
= FunctionType->getAs<BlockPointerType>())
|
|
|
|
FunctionType = BlockPtr->getPointeeType();
|
|
|
|
else if (const MemberPointerType *MemPtr
|
|
|
|
= FunctionType->getAs<MemberPointerType>())
|
|
|
|
FunctionType = MemPtr->getPointeeType();
|
|
|
|
|
|
|
|
if (const FunctionProtoType *Proto
|
|
|
|
= FunctionType->getAs<FunctionProtoType>()) {
|
|
|
|
if (NumArgs < Proto->getNumArgs())
|
|
|
|
ParamType = Proto->getArgType(NumArgs);
|
|
|
|
}
|
2009-09-22 23:41:20 +08:00
|
|
|
}
|
2009-12-12 03:06:04 +08:00
|
|
|
|
2010-05-30 09:49:25 +08:00
|
|
|
if (ParamType.isNull())
|
2010-08-12 05:23:17 +08:00
|
|
|
CodeCompleteOrdinaryName(S, PCC_Expression);
|
2010-05-30 09:49:25 +08:00
|
|
|
else
|
|
|
|
CodeCompleteExpression(S, ParamType);
|
|
|
|
|
2010-04-07 04:19:47 +08:00
|
|
|
if (!Results.empty())
|
2009-12-12 03:06:04 +08:00
|
|
|
CodeCompleter->ProcessOverloadCandidates(*this, NumArgs, Results.data(),
|
|
|
|
Results.size());
|
2009-09-22 23:41:20 +08:00
|
|
|
}
|
|
|
|
|
2010-08-21 17:40:31 +08:00
|
|
|
void Sema::CodeCompleteInitializer(Scope *S, Decl *D) {
|
|
|
|
ValueDecl *VD = dyn_cast_or_null<ValueDecl>(D);
|
2010-05-30 09:49:25 +08:00
|
|
|
if (!VD) {
|
2010-08-12 05:23:17 +08:00
|
|
|
CodeCompleteOrdinaryName(S, PCC_Expression);
|
2010-05-30 09:49:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeCompleteExpression(S, VD->getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteReturn(Scope *S) {
|
|
|
|
QualType ResultType;
|
|
|
|
if (isa<BlockDecl>(CurContext)) {
|
|
|
|
if (BlockScopeInfo *BSI = getCurBlock())
|
|
|
|
ResultType = BSI->ReturnType;
|
|
|
|
} else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(CurContext))
|
|
|
|
ResultType = Function->getResultType();
|
|
|
|
else if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(CurContext))
|
|
|
|
ResultType = Method->getResultType();
|
|
|
|
|
|
|
|
if (ResultType.isNull())
|
2010-08-12 05:23:17 +08:00
|
|
|
CodeCompleteOrdinaryName(S, PCC_Expression);
|
2010-05-30 09:49:25 +08:00
|
|
|
else
|
|
|
|
CodeCompleteExpression(S, ResultType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteAssignmentRHS(Scope *S, ExprTy *LHS) {
|
|
|
|
if (LHS)
|
|
|
|
CodeCompleteExpression(S, static_cast<Expr *>(LHS)->getType());
|
|
|
|
else
|
2010-08-12 05:23:17 +08:00
|
|
|
CodeCompleteOrdinaryName(S, PCC_Expression);
|
2010-05-30 09:49:25 +08:00
|
|
|
}
|
|
|
|
|
2010-04-09 00:38:48 +08:00
|
|
|
void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
|
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
|
|
|
bool EnteringContext) {
|
|
|
|
if (!SS.getScopeRep() || !CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
DeclContext *Ctx = computeDeclContext(SS, EnteringContext);
|
|
|
|
if (!Ctx)
|
|
|
|
return;
|
2009-12-12 02:28:39 +08:00
|
|
|
|
|
|
|
// Try to instantiate any non-dependent declaration contexts before
|
|
|
|
// we look in them.
|
2010-05-01 08:40:08 +08:00
|
|
|
if (!isDependentScopeSpecifier(SS) && RequireCompleteDeclContext(SS, Ctx))
|
2009-12-12 02:28:39 +08:00
|
|
|
return;
|
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Name);
|
2010-08-28 05:18:54 +08:00
|
|
|
Results.EnterNewScope();
|
2010-09-24 07:01:17 +08:00
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
// The "template" keyword can follow "::" in the grammar, but only
|
|
|
|
// put it into the grammar if the nested-name-specifier is dependent.
|
|
|
|
NestedNameSpecifier *NNS = (NestedNameSpecifier *)SS.getScopeRep();
|
|
|
|
if (!Results.empty() && NNS->isDependent())
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult("template");
|
2010-08-28 05:18:54 +08:00
|
|
|
|
|
|
|
// Add calls to overridden virtual functions, if there are any.
|
|
|
|
//
|
|
|
|
// FIXME: This isn't wonderful, because we don't know whether we're actually
|
|
|
|
// in a context that permits expressions. This is a general issue with
|
|
|
|
// qualified-id completions.
|
|
|
|
if (!EnteringContext)
|
|
|
|
MaybeAddOverrideCalls(*this, Ctx, Results);
|
|
|
|
Results.ExitScope();
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2010-08-28 05:18:54 +08:00
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
|
|
|
LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer);
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
2010-08-28 05:18:54 +08:00
|
|
|
CodeCompletionContext::CCC_Name,
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(),Results.size());
|
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
|
|
|
}
|
2009-09-19 03:03:04 +08:00
|
|
|
|
|
|
|
void Sema::CodeCompleteUsing(Scope *S) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this,
|
|
|
|
CodeCompletionContext::CCC_PotentiallyQualifiedName,
|
|
|
|
&ResultBuilder::IsNestedNameSpecifier);
|
2009-09-23 07:31:26 +08:00
|
|
|
Results.EnterNewScope();
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
// If we aren't in class scope, we could see the "namespace" keyword.
|
|
|
|
if (!S->isClassScope())
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult("namespace"));
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
// After "using", we can see anything that would start a
|
|
|
|
// nested-name-specifier.
|
2010-01-14 11:27:13 +08:00
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
2010-08-15 14:18:01 +08:00
|
|
|
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2009-09-23 07:31:26 +08:00
|
|
|
Results.ExitScope();
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
2010-09-24 07:01:17 +08:00
|
|
|
CodeCompletionContext::CCC_PotentiallyQualifiedName,
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(),Results.size());
|
2009-09-19 03:03:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteUsingDirective(Scope *S) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
// After "using namespace", we expect to see a namespace name or namespace
|
|
|
|
// alias.
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Namespace,
|
|
|
|
&ResultBuilder::IsNamespaceOrAlias);
|
2009-09-23 07:31:26 +08:00
|
|
|
Results.EnterNewScope();
|
2010-01-14 11:27:13 +08:00
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
2010-08-15 14:18:01 +08:00
|
|
|
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2009-09-23 07:31:26 +08:00
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
2010-08-15 14:18:01 +08:00
|
|
|
CodeCompletionContext::CCC_Namespace,
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(),Results.size());
|
2009-09-19 03:03:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteNamespaceDecl(Scope *S) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
DeclContext *Ctx = (DeclContext *)S->getEntity();
|
|
|
|
if (!S->getParent())
|
|
|
|
Ctx = Context.getTranslationUnitDecl();
|
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
bool SuppressedGlobalResults
|
|
|
|
= Ctx && !CodeCompleter->includeGlobals() && isa<TranslationUnitDecl>(Ctx);
|
|
|
|
|
|
|
|
ResultBuilder Results(*this,
|
|
|
|
SuppressedGlobalResults
|
|
|
|
? CodeCompletionContext::CCC_Namespace
|
|
|
|
: CodeCompletionContext::CCC_Other,
|
|
|
|
&ResultBuilder::IsNamespace);
|
|
|
|
|
|
|
|
if (Ctx && Ctx->isFileContext() && !SuppressedGlobalResults) {
|
2009-09-22 00:56:56 +08:00
|
|
|
// We only want to see those namespaces that have already been defined
|
|
|
|
// within this scope, because its likely that the user is creating an
|
|
|
|
// extended namespace declaration. Keep track of the most recent
|
|
|
|
// definition of each namespace.
|
|
|
|
std::map<NamespaceDecl *, NamespaceDecl *> OrigToLatest;
|
|
|
|
for (DeclContext::specific_decl_iterator<NamespaceDecl>
|
|
|
|
NS(Ctx->decls_begin()), NSEnd(Ctx->decls_end());
|
|
|
|
NS != NSEnd; ++NS)
|
|
|
|
OrigToLatest[NS->getOriginalNamespace()] = *NS;
|
|
|
|
|
|
|
|
// Add the most recent definition (or extended definition) of each
|
|
|
|
// namespace to the list of results.
|
2009-09-23 07:31:26 +08:00
|
|
|
Results.EnterNewScope();
|
2009-09-22 00:56:56 +08:00
|
|
|
for (std::map<NamespaceDecl *, NamespaceDecl *>::iterator
|
|
|
|
NS = OrigToLatest.begin(), NSEnd = OrigToLatest.end();
|
|
|
|
NS != NSEnd; ++NS)
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult(NS->second, 0),
|
2010-01-15 00:14:35 +08:00
|
|
|
CurContext, 0, false);
|
2009-09-23 07:31:26 +08:00
|
|
|
Results.ExitScope();
|
2009-09-22 00:56:56 +08:00
|
|
|
}
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
2010-09-24 07:01:17 +08:00
|
|
|
Results.getCompletionContext(),
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(),Results.size());
|
2009-09-19 03:03:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteNamespaceAliasDecl(Scope *S) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
|
|
|
|
2009-09-22 00:56:56 +08:00
|
|
|
// After "namespace", we expect to see a namespace or alias.
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Namespace,
|
|
|
|
&ResultBuilder::IsNamespaceOrAlias);
|
2010-01-14 11:27:13 +08:00
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
2010-08-15 14:18:01 +08:00
|
|
|
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
2010-09-24 07:01:17 +08:00
|
|
|
Results.getCompletionContext(),
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(),Results.size());
|
2009-09-19 03:03:04 +08:00
|
|
|
}
|
|
|
|
|
2009-09-19 04:05:18 +08:00
|
|
|
void Sema::CodeCompleteOperatorName(Scope *S) {
|
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
2009-09-22 00:56:56 +08:00
|
|
|
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Type,
|
|
|
|
&ResultBuilder::IsType);
|
2009-09-23 07:31:26 +08:00
|
|
|
Results.EnterNewScope();
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
// Add the names of overloadable operators.
|
|
|
|
#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
|
|
|
|
if (std::strcmp(Spelling, "?")) \
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Spelling));
|
2009-09-22 00:56:56 +08:00
|
|
|
#include "clang/Basic/OperatorKinds.def"
|
|
|
|
|
|
|
|
// Add any type names visible from the current scope
|
2010-01-14 11:21:49 +08:00
|
|
|
Results.allowNestedNameSpecifiers();
|
2010-01-14 11:27:13 +08:00
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
2010-08-15 14:18:01 +08:00
|
|
|
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2009-09-22 00:56:56 +08:00
|
|
|
|
|
|
|
// Add any type specifiers
|
2010-01-14 07:51:12 +08:00
|
|
|
AddTypeSpecifierResults(getLangOptions(), Results);
|
2009-09-23 07:31:26 +08:00
|
|
|
Results.ExitScope();
|
2009-09-19 04:05:18 +08:00
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
2010-08-15 14:18:01 +08:00
|
|
|
CodeCompletionContext::CCC_Type,
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(),Results.size());
|
2009-12-07 17:27:33 +08:00
|
|
|
}
|
|
|
|
|
2010-08-28 08:00:50 +08:00
|
|
|
void Sema::CodeCompleteConstructorInitializer(Decl *ConstructorD,
|
|
|
|
CXXBaseOrMemberInitializer** Initializers,
|
|
|
|
unsigned NumInitializers) {
|
|
|
|
CXXConstructorDecl *Constructor
|
|
|
|
= static_cast<CXXConstructorDecl *>(ConstructorD);
|
|
|
|
if (!Constructor)
|
|
|
|
return;
|
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this,
|
|
|
|
CodeCompletionContext::CCC_PotentiallyQualifiedName);
|
2010-08-28 08:00:50 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// Fill in any already-initialized fields or base classes.
|
|
|
|
llvm::SmallPtrSet<FieldDecl *, 4> InitializedFields;
|
|
|
|
llvm::SmallPtrSet<CanQualType, 4> InitializedBases;
|
|
|
|
for (unsigned I = 0; I != NumInitializers; ++I) {
|
|
|
|
if (Initializers[I]->isBaseInitializer())
|
|
|
|
InitializedBases.insert(
|
|
|
|
Context.getCanonicalType(QualType(Initializers[I]->getBaseClass(), 0)));
|
|
|
|
else
|
2010-12-04 17:14:42 +08:00
|
|
|
InitializedFields.insert(cast<FieldDecl>(
|
|
|
|
Initializers[I]->getAnyMember()));
|
2010-08-28 08:00:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add completions for base classes.
|
2010-08-30 03:27:27 +08:00
|
|
|
bool SawLastInitializer = (NumInitializers == 0);
|
2010-08-28 08:00:50 +08:00
|
|
|
CXXRecordDecl *ClassDecl = Constructor->getParent();
|
|
|
|
for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(),
|
|
|
|
BaseEnd = ClassDecl->bases_end();
|
|
|
|
Base != BaseEnd; ++Base) {
|
2010-08-30 03:27:27 +08:00
|
|
|
if (!InitializedBases.insert(Context.getCanonicalType(Base->getType()))) {
|
|
|
|
SawLastInitializer
|
|
|
|
= NumInitializers > 0 &&
|
|
|
|
Initializers[NumInitializers - 1]->isBaseInitializer() &&
|
|
|
|
Context.hasSameUnqualifiedType(Base->getType(),
|
|
|
|
QualType(Initializers[NumInitializers - 1]->getBaseClass(), 0));
|
2010-08-28 08:00:50 +08:00
|
|
|
continue;
|
2010-08-30 03:27:27 +08:00
|
|
|
}
|
2010-08-28 08:00:50 +08:00
|
|
|
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(
|
|
|
|
Base->getType().getAsString(Context.PrintingPolicy));
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("args");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
2010-08-30 03:27:27 +08:00
|
|
|
Results.AddResult(CodeCompletionResult(Pattern,
|
|
|
|
SawLastInitializer? CCP_NextInitializer
|
|
|
|
: CCP_MemberDeclaration));
|
|
|
|
SawLastInitializer = false;
|
2010-08-28 08:00:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add completions for virtual base classes.
|
|
|
|
for (CXXRecordDecl::base_class_iterator Base = ClassDecl->vbases_begin(),
|
|
|
|
BaseEnd = ClassDecl->vbases_end();
|
|
|
|
Base != BaseEnd; ++Base) {
|
2010-08-30 03:27:27 +08:00
|
|
|
if (!InitializedBases.insert(Context.getCanonicalType(Base->getType()))) {
|
|
|
|
SawLastInitializer
|
|
|
|
= NumInitializers > 0 &&
|
|
|
|
Initializers[NumInitializers - 1]->isBaseInitializer() &&
|
|
|
|
Context.hasSameUnqualifiedType(Base->getType(),
|
|
|
|
QualType(Initializers[NumInitializers - 1]->getBaseClass(), 0));
|
2010-08-28 08:00:50 +08:00
|
|
|
continue;
|
2010-08-30 03:27:27 +08:00
|
|
|
}
|
2010-08-28 08:00:50 +08:00
|
|
|
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(
|
|
|
|
Base->getType().getAsString(Context.PrintingPolicy));
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("args");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
2010-08-30 03:27:27 +08:00
|
|
|
Results.AddResult(CodeCompletionResult(Pattern,
|
|
|
|
SawLastInitializer? CCP_NextInitializer
|
|
|
|
: CCP_MemberDeclaration));
|
|
|
|
SawLastInitializer = false;
|
2010-08-28 08:00:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add completions for members.
|
|
|
|
for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
|
|
|
|
FieldEnd = ClassDecl->field_end();
|
|
|
|
Field != FieldEnd; ++Field) {
|
2010-08-30 03:27:27 +08:00
|
|
|
if (!InitializedFields.insert(cast<FieldDecl>(Field->getCanonicalDecl()))) {
|
|
|
|
SawLastInitializer
|
|
|
|
= NumInitializers > 0 &&
|
2010-12-04 17:14:42 +08:00
|
|
|
Initializers[NumInitializers - 1]->isAnyMemberInitializer() &&
|
|
|
|
Initializers[NumInitializers - 1]->getAnyMember() == *Field;
|
2010-08-28 08:00:50 +08:00
|
|
|
continue;
|
2010-08-30 03:27:27 +08:00
|
|
|
}
|
2010-08-28 08:00:50 +08:00
|
|
|
|
|
|
|
if (!Field->getDeclName())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(Field->getIdentifier()->getName());
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("args");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
2010-08-30 03:27:27 +08:00
|
|
|
Results.AddResult(CodeCompletionResult(Pattern,
|
|
|
|
SawLastInitializer? CCP_NextInitializer
|
2010-09-10 05:42:20 +08:00
|
|
|
: CCP_MemberDeclaration,
|
|
|
|
CXCursor_MemberRef));
|
2010-08-30 03:27:27 +08:00
|
|
|
SawLastInitializer = false;
|
2010-08-28 08:00:50 +08:00
|
|
|
}
|
|
|
|
Results.ExitScope();
|
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
|
2010-08-28 08:00:50 +08:00
|
|
|
Results.data(), Results.size());
|
|
|
|
}
|
|
|
|
|
2010-01-14 05:24:21 +08:00
|
|
|
// Macro that expands to @Keyword or Keyword, depending on whether NeedAt is
|
|
|
|
// true or false.
|
|
|
|
#define OBJC_AT_KEYWORD_NAME(NeedAt,Keyword) NeedAt? "@" #Keyword : #Keyword
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddObjCImplementationResults(const LangOptions &LangOpts,
|
2010-01-14 05:24:21 +08:00
|
|
|
ResultBuilder &Results,
|
|
|
|
bool NeedAt) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-01-14 05:24:21 +08:00
|
|
|
// Since we have an implementation, we can end it.
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,end)));
|
2010-01-14 05:24:21 +08:00
|
|
|
|
|
|
|
CodeCompletionString *Pattern = 0;
|
|
|
|
if (LangOpts.ObjC2) {
|
|
|
|
// @dynamic
|
2009-12-07 17:27:33 +08:00
|
|
|
Pattern = new CodeCompletionString;
|
2010-01-14 05:24:21 +08:00
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,dynamic));
|
2010-01-12 14:38:28 +08:00
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
2010-01-14 05:24:21 +08:00
|
|
|
Pattern->AddPlaceholderChunk("property");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
2010-01-14 05:24:21 +08:00
|
|
|
|
|
|
|
// @synthesize
|
2009-12-07 17:27:33 +08:00
|
|
|
Pattern = new CodeCompletionString;
|
2010-01-14 05:24:21 +08:00
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,synthesize));
|
2010-01-12 14:38:28 +08:00
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
2010-01-14 05:24:21 +08:00
|
|
|
Pattern->AddPlaceholderChunk("property");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
2010-01-14 05:24:21 +08:00
|
|
|
}
|
|
|
|
}
|
2009-12-07 17:27:33 +08:00
|
|
|
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddObjCInterfaceResults(const LangOptions &LangOpts,
|
2010-01-14 05:24:21 +08:00
|
|
|
ResultBuilder &Results,
|
|
|
|
bool NeedAt) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-01-14 05:24:21 +08:00
|
|
|
|
|
|
|
// Since we have an interface or protocol, we can end it.
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,end)));
|
2010-01-14 05:24:21 +08:00
|
|
|
|
|
|
|
if (LangOpts.ObjC2) {
|
|
|
|
// @property
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,property)));
|
2010-01-14 05:24:21 +08:00
|
|
|
|
|
|
|
// @required
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,required)));
|
2010-01-14 05:24:21 +08:00
|
|
|
|
|
|
|
// @optional
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,optional)));
|
2010-01-14 05:24:21 +08:00
|
|
|
}
|
|
|
|
}
|
2010-01-12 14:38:28 +08:00
|
|
|
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddObjCTopLevelResults(ResultBuilder &Results, bool NeedAt) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-01-14 05:24:21 +08:00
|
|
|
CodeCompletionString *Pattern = 0;
|
|
|
|
|
|
|
|
// @class name ;
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,class));
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
2010-05-28 08:22:41 +08:00
|
|
|
Pattern->AddPlaceholderChunk("name");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
2010-01-14 05:24:21 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
if (Results.includeCodePatterns()) {
|
|
|
|
// @interface name
|
|
|
|
// FIXME: Could introduce the whole pattern, including superclasses and
|
|
|
|
// such.
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,interface));
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("class");
|
|
|
|
Results.AddResult(Result(Pattern));
|
2010-01-14 05:24:21 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
// @protocol name
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,protocol));
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("protocol");
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
|
|
|
|
// @implementation name
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,implementation));
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("class");
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
}
|
2010-01-14 05:24:21 +08:00
|
|
|
|
|
|
|
// @compatibility_alias name
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,compatibility_alias));
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("alias");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("class");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
2010-01-14 05:24:21 +08:00
|
|
|
}
|
2010-01-12 14:38:28 +08:00
|
|
|
|
2010-08-21 17:40:31 +08:00
|
|
|
void Sema::CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl,
|
2010-01-14 05:24:21 +08:00
|
|
|
bool InInterface) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2010-01-14 05:24:21 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
if (ObjCImpDecl)
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCImplementationResults(getLangOptions(), Results, false);
|
2010-01-14 05:24:21 +08:00
|
|
|
else if (InInterface)
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCInterfaceResults(getLangOptions(), Results, false);
|
2010-01-14 05:24:21 +08:00
|
|
|
else
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCTopLevelResults(Results, false);
|
2009-12-07 17:27:33 +08:00
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-12-07 17:51:25 +08:00
|
|
|
}
|
|
|
|
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-12-07 17:51:25 +08:00
|
|
|
CodeCompletionString *Pattern = 0;
|
|
|
|
|
|
|
|
// @encode ( type-name )
|
|
|
|
Pattern = new CodeCompletionString;
|
2010-01-14 05:24:21 +08:00
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,encode));
|
2009-12-07 17:51:25 +08:00
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("type-name");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
2009-12-07 17:51:25 +08:00
|
|
|
|
|
|
|
// @protocol ( protocol-name )
|
|
|
|
Pattern = new CodeCompletionString;
|
2010-01-14 05:24:21 +08:00
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,protocol));
|
2009-12-07 17:51:25 +08:00
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("protocol-name");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
2009-12-07 17:51:25 +08:00
|
|
|
|
|
|
|
// @selector ( selector )
|
|
|
|
Pattern = new CodeCompletionString;
|
2010-01-14 05:24:21 +08:00
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,selector));
|
2009-12-07 17:51:25 +08:00
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("selector");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
2009-12-07 17:51:25 +08:00
|
|
|
}
|
|
|
|
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddObjCStatementResults(ResultBuilder &Results, bool NeedAt) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-12-07 17:51:25 +08:00
|
|
|
CodeCompletionString *Pattern = 0;
|
2010-01-14 05:24:21 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
if (Results.includeCodePatterns()) {
|
|
|
|
// @try { statements } @catch ( declaration ) { statements } @finally
|
|
|
|
// { statements }
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,try));
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Pattern->AddTextChunk("@catch");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("parameter");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Pattern->AddTextChunk("@finally");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
}
|
2010-01-14 05:24:21 +08:00
|
|
|
|
2009-12-07 17:51:25 +08:00
|
|
|
// @throw
|
|
|
|
Pattern = new CodeCompletionString;
|
2010-01-14 05:24:21 +08:00
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,throw));
|
2010-01-12 14:38:28 +08:00
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
2009-12-07 17:51:25 +08:00
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(Pattern));
|
2010-01-14 05:24:21 +08:00
|
|
|
|
2010-05-28 08:22:41 +08:00
|
|
|
if (Results.includeCodePatterns()) {
|
|
|
|
// @synchronized ( expression ) { statements }
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,synchronized));
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
Results.AddResult(Result(Pattern));
|
|
|
|
}
|
2010-01-14 05:24:21 +08:00
|
|
|
}
|
2009-12-07 17:51:25 +08:00
|
|
|
|
2010-01-14 07:51:12 +08:00
|
|
|
static void AddObjCVisibilityResults(const LangOptions &LangOpts,
|
2010-01-14 05:54:15 +08:00
|
|
|
ResultBuilder &Results,
|
|
|
|
bool NeedAt) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,private)));
|
|
|
|
Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,protected)));
|
|
|
|
Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,public)));
|
2010-01-14 05:54:15 +08:00
|
|
|
if (LangOpts.ObjC2)
|
2010-01-15 00:01:26 +08:00
|
|
|
Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,package)));
|
2010-01-14 05:54:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCAtVisibility(Scope *S) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2010-01-14 05:54:15 +08:00
|
|
|
Results.EnterNewScope();
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCVisibilityResults(getLangOptions(), Results, false);
|
2010-01-14 05:54:15 +08:00
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2010-01-14 05:54:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCAtStatement(Scope *S) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2010-01-14 05:24:21 +08:00
|
|
|
Results.EnterNewScope();
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCStatementResults(Results, false);
|
|
|
|
AddObjCExpressionResults(Results, false);
|
2009-12-07 17:51:25 +08:00
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-12-07 17:51:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCAtExpression(Scope *S) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-12-07 17:51:25 +08:00
|
|
|
Results.EnterNewScope();
|
2010-01-14 07:51:12 +08:00
|
|
|
AddObjCExpressionResults(Results, false);
|
2009-12-07 17:51:25 +08:00
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-09-19 04:05:18 +08:00
|
|
|
}
|
2009-09-19 03:03:04 +08:00
|
|
|
|
2009-11-19 08:14:45 +08:00
|
|
|
/// \brief Determine whether the addition of the given flag to an Objective-C
|
|
|
|
/// property's attributes will cause a conflict.
|
|
|
|
static bool ObjCPropertyFlagConflicts(unsigned Attributes, unsigned NewFlag) {
|
|
|
|
// Check if we've already added this flag.
|
|
|
|
if (Attributes & NewFlag)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Attributes |= NewFlag;
|
|
|
|
|
|
|
|
// Check for collisions with "readonly".
|
|
|
|
if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
|
|
|
|
(Attributes & (ObjCDeclSpec::DQ_PR_readwrite |
|
|
|
|
ObjCDeclSpec::DQ_PR_assign |
|
|
|
|
ObjCDeclSpec::DQ_PR_copy |
|
|
|
|
ObjCDeclSpec::DQ_PR_retain)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Check for more than one of { assign, copy, retain }.
|
|
|
|
unsigned AssignCopyRetMask = Attributes & (ObjCDeclSpec::DQ_PR_assign |
|
|
|
|
ObjCDeclSpec::DQ_PR_copy |
|
|
|
|
ObjCDeclSpec::DQ_PR_retain);
|
|
|
|
if (AssignCopyRetMask &&
|
|
|
|
AssignCopyRetMask != ObjCDeclSpec::DQ_PR_assign &&
|
|
|
|
AssignCopyRetMask != ObjCDeclSpec::DQ_PR_copy &&
|
|
|
|
AssignCopyRetMask != ObjCDeclSpec::DQ_PR_retain)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-19 07:08:07 +08:00
|
|
|
void Sema::CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS) {
|
2009-10-09 05:55:05 +08:00
|
|
|
if (!CodeCompleter)
|
|
|
|
return;
|
2009-11-19 09:08:35 +08:00
|
|
|
|
2009-10-09 05:55:05 +08:00
|
|
|
unsigned Attributes = ODS.getPropertyAttributes();
|
|
|
|
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-10-09 05:55:05 +08:00
|
|
|
Results.EnterNewScope();
|
2009-11-19 08:14:45 +08:00
|
|
|
if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_readonly))
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult("readonly"));
|
2009-11-19 08:14:45 +08:00
|
|
|
if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_assign))
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult("assign"));
|
2009-11-19 08:14:45 +08:00
|
|
|
if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_readwrite))
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult("readwrite"));
|
2009-11-19 08:14:45 +08:00
|
|
|
if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_retain))
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult("retain"));
|
2009-11-19 08:14:45 +08:00
|
|
|
if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_copy))
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult("copy"));
|
2009-11-19 08:14:45 +08:00
|
|
|
if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_nonatomic))
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult("nonatomic"));
|
2009-11-19 08:14:45 +08:00
|
|
|
if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_setter)) {
|
2009-11-19 08:01:57 +08:00
|
|
|
CodeCompletionString *Setter = new CodeCompletionString;
|
|
|
|
Setter->AddTypedTextChunk("setter");
|
|
|
|
Setter->AddTextChunk(" = ");
|
|
|
|
Setter->AddPlaceholderChunk("method");
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult(Setter));
|
2009-11-19 08:01:57 +08:00
|
|
|
}
|
2009-11-19 08:14:45 +08:00
|
|
|
if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_getter)) {
|
2009-11-19 08:01:57 +08:00
|
|
|
CodeCompletionString *Getter = new CodeCompletionString;
|
|
|
|
Getter->AddTypedTextChunk("getter");
|
|
|
|
Getter->AddTextChunk(" = ");
|
|
|
|
Getter->AddPlaceholderChunk("method");
|
2010-08-25 14:19:51 +08:00
|
|
|
Results.AddResult(CodeCompletionResult(Getter));
|
2009-11-19 08:01:57 +08:00
|
|
|
}
|
2009-10-09 05:55:05 +08:00
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-10-09 05:55:05 +08:00
|
|
|
}
|
2009-11-07 10:08:14 +08:00
|
|
|
|
2009-11-19 15:41:15 +08:00
|
|
|
/// \brief Descripts the kind of Objective-C method that we want to find
|
|
|
|
/// via code completion.
|
|
|
|
enum ObjCMethodKind {
|
|
|
|
MK_Any, //< Any kind of method, provided it means other specified criteria.
|
|
|
|
MK_ZeroArgSelector, //< Zero-argument (unary) selector.
|
|
|
|
MK_OneArgSelector //< One-argument selector.
|
|
|
|
};
|
|
|
|
|
2010-08-26 23:07:07 +08:00
|
|
|
static bool isAcceptableObjCSelector(Selector Sel,
|
|
|
|
ObjCMethodKind WantKind,
|
|
|
|
IdentifierInfo **SelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
unsigned NumSelIdents,
|
|
|
|
bool AllowSameLength = true) {
|
2009-11-19 15:41:15 +08:00
|
|
|
if (NumSelIdents > Sel.getNumArgs())
|
|
|
|
return false;
|
2010-08-26 23:07:07 +08:00
|
|
|
|
2009-11-19 15:41:15 +08:00
|
|
|
switch (WantKind) {
|
2010-08-26 23:07:07 +08:00
|
|
|
case MK_Any: break;
|
|
|
|
case MK_ZeroArgSelector: return Sel.isUnarySelector();
|
|
|
|
case MK_OneArgSelector: return Sel.getNumArgs() == 1;
|
2009-11-19 15:41:15 +08:00
|
|
|
}
|
2010-08-26 23:07:07 +08:00
|
|
|
|
2010-11-18 05:36:08 +08:00
|
|
|
if (!AllowSameLength && NumSelIdents && NumSelIdents == Sel.getNumArgs())
|
|
|
|
return false;
|
|
|
|
|
2009-11-19 15:41:15 +08:00
|
|
|
for (unsigned I = 0; I != NumSelIdents; ++I)
|
|
|
|
if (SelIdents[I] != Sel.getIdentifierInfoForSlot(I))
|
|
|
|
return false;
|
2010-08-26 23:07:07 +08:00
|
|
|
|
2009-11-19 15:41:15 +08:00
|
|
|
return true;
|
|
|
|
}
|
2010-08-26 23:07:07 +08:00
|
|
|
|
|
|
|
static bool isAcceptableObjCMethod(ObjCMethodDecl *Method,
|
|
|
|
ObjCMethodKind WantKind,
|
|
|
|
IdentifierInfo **SelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
unsigned NumSelIdents,
|
|
|
|
bool AllowSameLength = true) {
|
2010-08-26 23:07:07 +08:00
|
|
|
return isAcceptableObjCSelector(Method->getSelector(), WantKind, SelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
NumSelIdents, AllowSameLength);
|
2010-08-26 23:07:07 +08:00
|
|
|
}
|
2010-09-17 00:06:31 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
/// \brief A set of selectors, which is used to avoid introducing multiple
|
|
|
|
/// completions with the same selector into the result set.
|
|
|
|
typedef llvm::SmallPtrSet<Selector, 16> VisitedSelectorSet;
|
|
|
|
}
|
|
|
|
|
2009-11-18 07:22:23 +08:00
|
|
|
/// \brief Add all of the Objective-C methods in the given Objective-C
|
|
|
|
/// container to the set of results.
|
|
|
|
///
|
|
|
|
/// The container will be a class, protocol, category, or implementation of
|
|
|
|
/// any of the above. This mether will recurse to include methods from
|
|
|
|
/// the superclasses of classes along with their categories, protocols, and
|
|
|
|
/// implementations.
|
|
|
|
///
|
|
|
|
/// \param Container the container in which we'll look to find methods.
|
|
|
|
///
|
|
|
|
/// \param WantInstance whether to add instance methods (only); if false, this
|
|
|
|
/// routine will add factory methods (only).
|
|
|
|
///
|
|
|
|
/// \param CurContext the context in which we're performing the lookup that
|
|
|
|
/// finds methods.
|
|
|
|
///
|
2010-11-18 05:36:08 +08:00
|
|
|
/// \param AllowSameLength Whether we allow a method to be added to the list
|
|
|
|
/// when it has the same number of parameters as we have selector identifiers.
|
|
|
|
///
|
2009-11-18 07:22:23 +08:00
|
|
|
/// \param Results the structure into which we'll add results.
|
|
|
|
static void AddObjCMethods(ObjCContainerDecl *Container,
|
|
|
|
bool WantInstanceMethods,
|
2009-11-19 15:41:15 +08:00
|
|
|
ObjCMethodKind WantKind,
|
2009-11-19 09:08:35 +08:00
|
|
|
IdentifierInfo **SelIdents,
|
|
|
|
unsigned NumSelIdents,
|
2009-11-18 07:22:23 +08:00
|
|
|
DeclContext *CurContext,
|
2010-09-17 00:06:31 +08:00
|
|
|
VisitedSelectorSet &Selectors,
|
2010-11-18 05:36:08 +08:00
|
|
|
bool AllowSameLength,
|
2010-08-25 09:08:01 +08:00
|
|
|
ResultBuilder &Results,
|
|
|
|
bool InOriginalClass = true) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-11-18 07:22:23 +08:00
|
|
|
for (ObjCContainerDecl::method_iterator M = Container->meth_begin(),
|
|
|
|
MEnd = Container->meth_end();
|
|
|
|
M != MEnd; ++M) {
|
2009-11-19 09:08:35 +08:00
|
|
|
if ((*M)->isInstanceMethod() == WantInstanceMethods) {
|
|
|
|
// Check whether the selector identifiers we've been given are a
|
|
|
|
// subset of the identifiers for this particular method.
|
2010-11-18 05:36:08 +08:00
|
|
|
if (!isAcceptableObjCMethod(*M, WantKind, SelIdents, NumSelIdents,
|
|
|
|
AllowSameLength))
|
2009-11-19 09:08:35 +08:00
|
|
|
continue;
|
2009-11-19 15:41:15 +08:00
|
|
|
|
2010-09-17 00:06:31 +08:00
|
|
|
if (!Selectors.insert((*M)->getSelector()))
|
|
|
|
continue;
|
|
|
|
|
2009-11-19 09:08:35 +08:00
|
|
|
Result R = Result(*M, 0);
|
|
|
|
R.StartParameter = NumSelIdents;
|
2009-11-19 15:41:15 +08:00
|
|
|
R.AllParametersAreInformative = (WantKind != MK_Any);
|
2010-08-25 09:08:01 +08:00
|
|
|
if (!InOriginalClass)
|
|
|
|
R.Priority += CCD_InBaseClass;
|
2009-11-19 09:08:35 +08:00
|
|
|
Results.MaybeAddResult(R, CurContext);
|
|
|
|
}
|
2009-11-18 07:22:23 +08:00
|
|
|
}
|
|
|
|
|
2010-09-16 23:34:59 +08:00
|
|
|
// Visit the protocols of protocols.
|
|
|
|
if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
|
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols
|
|
|
|
= Protocol->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
|
|
|
|
E = Protocols.end();
|
|
|
|
I != E; ++I)
|
|
|
|
AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, NumSelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
CurContext, Selectors, AllowSameLength, Results, false);
|
2010-09-16 23:34:59 +08:00
|
|
|
}
|
|
|
|
|
2009-11-18 07:22:23 +08:00
|
|
|
ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container);
|
|
|
|
if (!IFace)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Add methods in protocols.
|
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols= IFace->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
|
|
|
|
E = Protocols.end();
|
|
|
|
I != E; ++I)
|
2009-11-19 15:41:15 +08:00
|
|
|
AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, NumSelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
CurContext, Selectors, AllowSameLength, Results, false);
|
2009-11-18 07:22:23 +08:00
|
|
|
|
|
|
|
// Add methods in categories.
|
|
|
|
for (ObjCCategoryDecl *CatDecl = IFace->getCategoryList(); CatDecl;
|
|
|
|
CatDecl = CatDecl->getNextClassCategory()) {
|
2009-11-19 15:41:15 +08:00
|
|
|
AddObjCMethods(CatDecl, WantInstanceMethods, WantKind, SelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
NumSelIdents, CurContext, Selectors, AllowSameLength,
|
|
|
|
Results, InOriginalClass);
|
2009-11-18 07:22:23 +08:00
|
|
|
|
|
|
|
// Add a categories protocol methods.
|
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols
|
|
|
|
= CatDecl->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
|
|
|
|
E = Protocols.end();
|
|
|
|
I != E; ++I)
|
2009-11-19 15:41:15 +08:00
|
|
|
AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
NumSelIdents, CurContext, Selectors, AllowSameLength,
|
|
|
|
Results, false);
|
2009-11-18 07:22:23 +08:00
|
|
|
|
|
|
|
// Add methods in category implementations.
|
|
|
|
if (ObjCCategoryImplDecl *Impl = CatDecl->getImplementation())
|
2009-11-19 15:41:15 +08:00
|
|
|
AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
NumSelIdents, CurContext, Selectors, AllowSameLength,
|
|
|
|
Results, InOriginalClass);
|
2009-11-18 07:22:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add methods in superclass.
|
|
|
|
if (IFace->getSuperClass())
|
2009-11-19 15:41:15 +08:00
|
|
|
AddObjCMethods(IFace->getSuperClass(), WantInstanceMethods, WantKind,
|
2010-11-18 05:36:08 +08:00
|
|
|
SelIdents, NumSelIdents, CurContext, Selectors,
|
|
|
|
AllowSameLength, Results, false);
|
2009-11-18 07:22:23 +08:00
|
|
|
|
|
|
|
// Add methods in our implementation, if any.
|
|
|
|
if (ObjCImplementationDecl *Impl = IFace->getImplementation())
|
2009-11-19 15:41:15 +08:00
|
|
|
AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
NumSelIdents, CurContext, Selectors, AllowSameLength,
|
|
|
|
Results, InOriginalClass);
|
2009-11-19 15:41:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-21 17:40:31 +08:00
|
|
|
void Sema::CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl,
|
|
|
|
Decl **Methods,
|
2009-11-19 15:41:15 +08:00
|
|
|
unsigned NumMethods) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-11-19 15:41:15 +08:00
|
|
|
|
|
|
|
// Try to find the interface where getters might live.
|
2010-08-21 17:40:31 +08:00
|
|
|
ObjCInterfaceDecl *Class = dyn_cast_or_null<ObjCInterfaceDecl>(ClassDecl);
|
2009-11-19 15:41:15 +08:00
|
|
|
if (!Class) {
|
|
|
|
if (ObjCCategoryDecl *Category
|
2010-08-21 17:40:31 +08:00
|
|
|
= dyn_cast_or_null<ObjCCategoryDecl>(ClassDecl))
|
2009-11-19 15:41:15 +08:00
|
|
|
Class = Category->getClassInterface();
|
|
|
|
|
|
|
|
if (!Class)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find all of the potential getters.
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-11-19 15:41:15 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// FIXME: We need to do this because Objective-C methods don't get
|
|
|
|
// pushed into DeclContexts early enough. Argh!
|
|
|
|
for (unsigned I = 0; I != NumMethods; ++I) {
|
|
|
|
if (ObjCMethodDecl *Method
|
2010-08-21 17:40:31 +08:00
|
|
|
= dyn_cast_or_null<ObjCMethodDecl>(Methods[I]))
|
2009-11-19 15:41:15 +08:00
|
|
|
if (Method->isInstanceMethod() &&
|
|
|
|
isAcceptableObjCMethod(Method, MK_ZeroArgSelector, 0, 0)) {
|
|
|
|
Result R = Result(Method, 0);
|
|
|
|
R.AllParametersAreInformative = true;
|
|
|
|
Results.MaybeAddResult(R, CurContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 00:06:31 +08:00
|
|
|
VisitedSelectorSet Selectors;
|
|
|
|
AddObjCMethods(Class, true, MK_ZeroArgSelector, 0, 0, CurContext, Selectors,
|
2010-11-18 05:36:08 +08:00
|
|
|
/*AllowSameLength=*/true, Results);
|
2009-11-19 15:41:15 +08:00
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-11-19 15:41:15 +08:00
|
|
|
}
|
|
|
|
|
2010-08-21 17:40:31 +08:00
|
|
|
void Sema::CodeCompleteObjCPropertySetter(Scope *S, Decl *ObjCImplDecl,
|
|
|
|
Decl **Methods,
|
2009-11-19 15:41:15 +08:00
|
|
|
unsigned NumMethods) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-11-19 15:41:15 +08:00
|
|
|
|
|
|
|
// Try to find the interface where setters might live.
|
|
|
|
ObjCInterfaceDecl *Class
|
2010-08-21 17:40:31 +08:00
|
|
|
= dyn_cast_or_null<ObjCInterfaceDecl>(ObjCImplDecl);
|
2009-11-19 15:41:15 +08:00
|
|
|
if (!Class) {
|
|
|
|
if (ObjCCategoryDecl *Category
|
2010-08-21 17:40:31 +08:00
|
|
|
= dyn_cast_or_null<ObjCCategoryDecl>(ObjCImplDecl))
|
2009-11-19 15:41:15 +08:00
|
|
|
Class = Category->getClassInterface();
|
|
|
|
|
|
|
|
if (!Class)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find all of the potential getters.
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-11-19 15:41:15 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// FIXME: We need to do this because Objective-C methods don't get
|
|
|
|
// pushed into DeclContexts early enough. Argh!
|
|
|
|
for (unsigned I = 0; I != NumMethods; ++I) {
|
|
|
|
if (ObjCMethodDecl *Method
|
2010-08-21 17:40:31 +08:00
|
|
|
= dyn_cast_or_null<ObjCMethodDecl>(Methods[I]))
|
2009-11-19 15:41:15 +08:00
|
|
|
if (Method->isInstanceMethod() &&
|
|
|
|
isAcceptableObjCMethod(Method, MK_OneArgSelector, 0, 0)) {
|
|
|
|
Result R = Result(Method, 0);
|
|
|
|
R.AllParametersAreInformative = true;
|
|
|
|
Results.MaybeAddResult(R, CurContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 00:06:31 +08:00
|
|
|
VisitedSelectorSet Selectors;
|
|
|
|
AddObjCMethods(Class, true, MK_OneArgSelector, 0, 0, CurContext,
|
2010-11-18 05:36:08 +08:00
|
|
|
Selectors, /*AllowSameLength=*/true, Results);
|
2009-11-19 15:41:15 +08:00
|
|
|
|
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-11-18 07:22:23 +08:00
|
|
|
}
|
|
|
|
|
2010-08-24 09:06:58 +08:00
|
|
|
void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Type);
|
2010-08-24 09:06:58 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// Add context-sensitive, Objective-C parameter-passing keywords.
|
|
|
|
bool AddedInOut = false;
|
|
|
|
if ((DS.getObjCDeclQualifier() &
|
|
|
|
(ObjCDeclSpec::DQ_In | ObjCDeclSpec::DQ_Inout)) == 0) {
|
|
|
|
Results.AddResult("in");
|
|
|
|
Results.AddResult("inout");
|
|
|
|
AddedInOut = true;
|
|
|
|
}
|
|
|
|
if ((DS.getObjCDeclQualifier() &
|
|
|
|
(ObjCDeclSpec::DQ_Out | ObjCDeclSpec::DQ_Inout)) == 0) {
|
|
|
|
Results.AddResult("out");
|
|
|
|
if (!AddedInOut)
|
|
|
|
Results.AddResult("inout");
|
|
|
|
}
|
|
|
|
if ((DS.getObjCDeclQualifier() &
|
|
|
|
(ObjCDeclSpec::DQ_Bycopy | ObjCDeclSpec::DQ_Byref |
|
|
|
|
ObjCDeclSpec::DQ_Oneway)) == 0) {
|
|
|
|
Results.AddResult("bycopy");
|
|
|
|
Results.AddResult("byref");
|
|
|
|
Results.AddResult("oneway");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add various builtin type names and specifiers.
|
|
|
|
AddOrdinaryNameResults(PCC_Type, S, *this, Results);
|
|
|
|
Results.ExitScope();
|
|
|
|
|
|
|
|
// Add the various type names
|
|
|
|
Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
|
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
|
|
|
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
|
|
|
|
|
|
|
if (CodeCompleter->includeMacros())
|
|
|
|
AddMacroResults(PP, Results);
|
|
|
|
|
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Type,
|
|
|
|
Results.data(), Results.size());
|
|
|
|
}
|
|
|
|
|
2010-04-07 03:22:33 +08:00
|
|
|
/// \brief When we have an expression with type "id", we may assume
|
|
|
|
/// that it has some more-specific class type based on knowledge of
|
|
|
|
/// common uses of Objective-C. This routine returns that class type,
|
|
|
|
/// or NULL if no better result could be determined.
|
|
|
|
static ObjCInterfaceDecl *GetAssumedMessageSendExprType(Expr *E) {
|
2010-09-16 00:23:04 +08:00
|
|
|
ObjCMessageExpr *Msg = dyn_cast_or_null<ObjCMessageExpr>(E);
|
2010-04-07 03:22:33 +08:00
|
|
|
if (!Msg)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
Selector Sel = Msg->getSelector();
|
|
|
|
if (Sel.isNull())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
IdentifierInfo *Id = Sel.getIdentifierInfoForSlot(0);
|
|
|
|
if (!Id)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ObjCMethodDecl *Method = Msg->getMethodDecl();
|
|
|
|
if (!Method)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Determine the class that we're sending the message to.
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
llvm-svn: 101972
2010-04-21 08:45:42 +08:00
|
|
|
ObjCInterfaceDecl *IFace = 0;
|
|
|
|
switch (Msg->getReceiverKind()) {
|
|
|
|
case ObjCMessageExpr::Class:
|
2010-05-15 19:32:37 +08:00
|
|
|
if (const ObjCObjectType *ObjType
|
|
|
|
= Msg->getClassReceiver()->getAs<ObjCObjectType>())
|
|
|
|
IFace = ObjType->getInterface();
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
llvm-svn: 101972
2010-04-21 08:45:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ObjCMessageExpr::Instance: {
|
|
|
|
QualType T = Msg->getInstanceReceiver()->getType();
|
|
|
|
if (const ObjCObjectPointerType *Ptr = T->getAs<ObjCObjectPointerType>())
|
|
|
|
IFace = Ptr->getInterfaceDecl();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ObjCMessageExpr::SuperInstance:
|
|
|
|
case ObjCMessageExpr::SuperClass:
|
|
|
|
break;
|
2010-04-07 03:22:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!IFace)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ObjCInterfaceDecl *Super = IFace->getSuperClass();
|
|
|
|
if (Method->isInstanceMethod())
|
|
|
|
return llvm::StringSwitch<ObjCInterfaceDecl *>(Id->getName())
|
|
|
|
.Case("retain", IFace)
|
|
|
|
.Case("autorelease", IFace)
|
|
|
|
.Case("copy", IFace)
|
|
|
|
.Case("copyWithZone", IFace)
|
|
|
|
.Case("mutableCopy", IFace)
|
|
|
|
.Case("mutableCopyWithZone", IFace)
|
|
|
|
.Case("awakeFromCoder", IFace)
|
|
|
|
.Case("replacementObjectFromCoder", IFace)
|
|
|
|
.Case("class", IFace)
|
|
|
|
.Case("classForCoder", IFace)
|
|
|
|
.Case("superclass", Super)
|
|
|
|
.Default(0);
|
|
|
|
|
|
|
|
return llvm::StringSwitch<ObjCInterfaceDecl *>(Id->getName())
|
|
|
|
.Case("new", IFace)
|
|
|
|
.Case("alloc", IFace)
|
|
|
|
.Case("allocWithZone", IFace)
|
|
|
|
.Case("class", IFace)
|
|
|
|
.Case("superclass", Super)
|
|
|
|
.Default(0);
|
|
|
|
}
|
|
|
|
|
2010-08-27 23:10:57 +08:00
|
|
|
// Add a special completion for a message send to "super", which fills in the
|
|
|
|
// most likely case of forwarding all of our arguments to the superclass
|
|
|
|
// function.
|
|
|
|
///
|
|
|
|
/// \param S The semantic analysis object.
|
|
|
|
///
|
|
|
|
/// \param S NeedSuperKeyword Whether we need to prefix this completion with
|
|
|
|
/// the "super" keyword. Otherwise, we just need to provide the arguments.
|
|
|
|
///
|
|
|
|
/// \param SelIdents The identifiers in the selector that have already been
|
|
|
|
/// provided as arguments for a send to "super".
|
|
|
|
///
|
|
|
|
/// \param NumSelIdents The number of identifiers in \p SelIdents.
|
|
|
|
///
|
|
|
|
/// \param Results The set of results to augment.
|
|
|
|
///
|
|
|
|
/// \returns the Objective-C method declaration that would be invoked by
|
|
|
|
/// this "super" completion. If NULL, no completion was added.
|
|
|
|
static ObjCMethodDecl *AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword,
|
|
|
|
IdentifierInfo **SelIdents,
|
|
|
|
unsigned NumSelIdents,
|
|
|
|
ResultBuilder &Results) {
|
|
|
|
ObjCMethodDecl *CurMethod = S.getCurMethodDecl();
|
|
|
|
if (!CurMethod)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ObjCInterfaceDecl *Class = CurMethod->getClassInterface();
|
|
|
|
if (!Class)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Try to find a superclass method with the same selector.
|
|
|
|
ObjCMethodDecl *SuperMethod = 0;
|
|
|
|
while ((Class = Class->getSuperClass()) && !SuperMethod)
|
|
|
|
SuperMethod = Class->getMethod(CurMethod->getSelector(),
|
|
|
|
CurMethod->isInstanceMethod());
|
|
|
|
|
|
|
|
if (!SuperMethod)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Check whether the superclass method has the same signature.
|
|
|
|
if (CurMethod->param_size() != SuperMethod->param_size() ||
|
|
|
|
CurMethod->isVariadic() != SuperMethod->isVariadic())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (ObjCMethodDecl::param_iterator CurP = CurMethod->param_begin(),
|
|
|
|
CurPEnd = CurMethod->param_end(),
|
|
|
|
SuperP = SuperMethod->param_begin();
|
|
|
|
CurP != CurPEnd; ++CurP, ++SuperP) {
|
|
|
|
// Make sure the parameter types are compatible.
|
|
|
|
if (!S.Context.hasSameUnqualifiedType((*CurP)->getType(),
|
|
|
|
(*SuperP)->getType()))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Make sure we have a parameter name to forward!
|
|
|
|
if (!(*CurP)->getIdentifier())
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have a superclass method. Now, form the send-to-super completion.
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
|
|
|
|
// Give this completion a return type.
|
|
|
|
AddResultTypeChunk(S.Context, SuperMethod, Pattern);
|
|
|
|
|
|
|
|
// If we need the "super" keyword, add it (plus some spacing).
|
|
|
|
if (NeedSuperKeyword) {
|
|
|
|
Pattern->AddTypedTextChunk("super");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
}
|
|
|
|
|
|
|
|
Selector Sel = CurMethod->getSelector();
|
|
|
|
if (Sel.isUnarySelector()) {
|
|
|
|
if (NeedSuperKeyword)
|
|
|
|
Pattern->AddTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
|
|
|
|
else
|
|
|
|
Pattern->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
|
|
|
|
} else {
|
|
|
|
ObjCMethodDecl::param_iterator CurP = CurMethod->param_begin();
|
|
|
|
for (unsigned I = 0, N = Sel.getNumArgs(); I != N; ++I, ++CurP) {
|
|
|
|
if (I > NumSelIdents)
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
|
|
|
|
if (I < NumSelIdents)
|
|
|
|
Pattern->AddInformativeChunk(
|
|
|
|
Sel.getIdentifierInfoForSlot(I)->getName().str() + ":");
|
|
|
|
else if (NeedSuperKeyword || I > NumSelIdents) {
|
|
|
|
Pattern->AddTextChunk(
|
|
|
|
Sel.getIdentifierInfoForSlot(I)->getName().str() + ":");
|
|
|
|
Pattern->AddPlaceholderChunk((*CurP)->getIdentifier()->getName());
|
|
|
|
} else {
|
|
|
|
Pattern->AddTypedTextChunk(
|
|
|
|
Sel.getIdentifierInfoForSlot(I)->getName().str() + ":");
|
|
|
|
Pattern->AddPlaceholderChunk((*CurP)->getIdentifier()->getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Results.AddResult(CodeCompletionResult(Pattern, CCP_SuperCompletion,
|
|
|
|
SuperMethod->isInstanceMethod()
|
|
|
|
? CXCursor_ObjCInstanceMethodDecl
|
|
|
|
: CXCursor_ObjCClassMethodDecl));
|
|
|
|
return SuperMethod;
|
|
|
|
}
|
|
|
|
|
2010-05-28 07:06:34 +08:00
|
|
|
void Sema::CodeCompleteObjCMessageReceiver(Scope *S) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_ObjCMessageReceiver,
|
|
|
|
&ResultBuilder::IsObjCMessageReceiver);
|
2010-05-28 07:06:34 +08:00
|
|
|
|
|
|
|
CodeCompletionDeclConsumer Consumer(Results, CurContext);
|
|
|
|
Results.EnterNewScope();
|
2010-08-15 14:18:01 +08:00
|
|
|
LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
|
|
|
|
CodeCompleter->includeGlobals());
|
2010-05-28 07:06:34 +08:00
|
|
|
|
|
|
|
// If we are in an Objective-C method inside a class that has a superclass,
|
|
|
|
// add "super" as an option.
|
|
|
|
if (ObjCMethodDecl *Method = getCurMethodDecl())
|
|
|
|
if (ObjCInterfaceDecl *Iface = Method->getClassInterface())
|
2010-08-27 23:10:57 +08:00
|
|
|
if (Iface->getSuperClass()) {
|
2010-05-28 07:06:34 +08:00
|
|
|
Results.AddResult(Result("super"));
|
2010-08-27 23:10:57 +08:00
|
|
|
|
|
|
|
AddSuperSendCompletion(*this, /*NeedSuperKeyword=*/true, 0, 0, Results);
|
|
|
|
}
|
2010-05-28 07:06:34 +08:00
|
|
|
|
|
|
|
Results.ExitScope();
|
|
|
|
|
|
|
|
if (CodeCompleter->includeMacros())
|
|
|
|
AddMacroResults(PP, Results);
|
2010-09-21 06:39:41 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
|
2010-08-12 05:23:17 +08:00
|
|
|
Results.data(), Results.size());
|
2010-05-28 07:06:34 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
|
2009-11-19 09:08:35 +08:00
|
|
|
IdentifierInfo **SelIdents,
|
2010-09-21 07:34:21 +08:00
|
|
|
unsigned NumSelIdents,
|
|
|
|
bool AtArgumentExpression) {
|
2009-11-18 01:59:40 +08:00
|
|
|
ObjCInterfaceDecl *CDecl = 0;
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
if (ObjCMethodDecl *CurMethod = getCurMethodDecl()) {
|
|
|
|
// Figure out which interface we're in.
|
|
|
|
CDecl = CurMethod->getClassInterface();
|
|
|
|
if (!CDecl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Find the superclass of this class.
|
|
|
|
CDecl = CDecl->getSuperClass();
|
|
|
|
if (!CDecl)
|
|
|
|
return;
|
2009-11-18 01:59:40 +08:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
if (CurMethod->isInstanceMethod()) {
|
|
|
|
// We are inside an instance method, which means that the message
|
|
|
|
// send [super ...] is actually calling an instance method on the
|
2010-10-14 05:24:53 +08:00
|
|
|
// current object.
|
|
|
|
return CodeCompleteObjCInstanceMessage(S, 0,
|
2010-08-27 23:10:57 +08:00
|
|
|
SelIdents, NumSelIdents,
|
2010-09-21 07:34:21 +08:00
|
|
|
AtArgumentExpression,
|
2010-10-14 05:24:53 +08:00
|
|
|
CDecl);
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
}
|
2009-11-18 01:59:40 +08:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
// Fall through to send to the superclass in CDecl.
|
|
|
|
} else {
|
|
|
|
// "super" may be the name of a type or variable. Figure out which
|
|
|
|
// it is.
|
|
|
|
IdentifierInfo *Super = &Context.Idents.get("super");
|
|
|
|
NamedDecl *ND = LookupSingleName(S, Super, SuperLoc,
|
|
|
|
LookupOrdinaryName);
|
|
|
|
if ((CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(ND))) {
|
|
|
|
// "super" names an interface. Use it.
|
|
|
|
} else if (TypeDecl *TD = dyn_cast_or_null<TypeDecl>(ND)) {
|
2010-05-15 19:32:37 +08:00
|
|
|
if (const ObjCObjectType *Iface
|
|
|
|
= Context.getTypeDeclType(TD)->getAs<ObjCObjectType>())
|
|
|
|
CDecl = Iface->getInterface();
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
} else if (ND && isa<UnresolvedUsingTypenameDecl>(ND)) {
|
|
|
|
// "super" names an unresolved type; we can't be more specific.
|
|
|
|
} else {
|
|
|
|
// Assume that "super" names some kind of value and parse that way.
|
|
|
|
CXXScopeSpec SS;
|
|
|
|
UnqualifiedId id;
|
|
|
|
id.setIdentifier(Super, SuperLoc);
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult SuperExpr = ActOnIdExpression(S, SS, id, false, false);
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
return CodeCompleteObjCInstanceMessage(S, (Expr *)SuperExpr.get(),
|
2010-09-21 07:34:21 +08:00
|
|
|
SelIdents, NumSelIdents,
|
|
|
|
AtArgumentExpression);
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
}
|
2009-11-18 01:59:40 +08:00
|
|
|
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
// Fall through
|
2009-11-18 01:59:40 +08:00
|
|
|
}
|
|
|
|
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType Receiver;
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
if (CDecl)
|
2010-08-24 13:47:05 +08:00
|
|
|
Receiver = ParsedType::make(Context.getObjCInterfaceType(CDecl));
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
return CodeCompleteObjCClassMessage(S, Receiver, SelIdents,
|
2010-09-21 07:34:21 +08:00
|
|
|
NumSelIdents, AtArgumentExpression,
|
|
|
|
/*IsSuper=*/true);
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
}
|
|
|
|
|
2010-09-21 08:03:25 +08:00
|
|
|
/// \brief Given a set of code-completion results for the argument of a message
|
|
|
|
/// send, determine the preferred type (if any) for that argument expression.
|
|
|
|
static QualType getPreferredArgumentTypeForMessageSend(ResultBuilder &Results,
|
|
|
|
unsigned NumSelIdents) {
|
|
|
|
typedef CodeCompletionResult Result;
|
|
|
|
ASTContext &Context = Results.getSema().Context;
|
|
|
|
|
|
|
|
QualType PreferredType;
|
|
|
|
unsigned BestPriority = CCP_Unlikely * 2;
|
|
|
|
Result *ResultsData = Results.data();
|
|
|
|
for (unsigned I = 0, N = Results.size(); I != N; ++I) {
|
|
|
|
Result &R = ResultsData[I];
|
|
|
|
if (R.Kind == Result::RK_Declaration &&
|
|
|
|
isa<ObjCMethodDecl>(R.Declaration)) {
|
|
|
|
if (R.Priority <= BestPriority) {
|
|
|
|
ObjCMethodDecl *Method = cast<ObjCMethodDecl>(R.Declaration);
|
|
|
|
if (NumSelIdents <= Method->param_size()) {
|
|
|
|
QualType MyPreferredType = Method->param_begin()[NumSelIdents - 1]
|
|
|
|
->getType();
|
|
|
|
if (R.Priority < BestPriority || PreferredType.isNull()) {
|
|
|
|
BestPriority = R.Priority;
|
|
|
|
PreferredType = MyPreferredType;
|
|
|
|
} else if (!Context.hasSameUnqualifiedType(PreferredType,
|
|
|
|
MyPreferredType)) {
|
|
|
|
PreferredType = QualType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PreferredType;
|
|
|
|
}
|
|
|
|
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
static void AddClassMessageCompletions(Sema &SemaRef, Scope *S,
|
|
|
|
ParsedType Receiver,
|
|
|
|
IdentifierInfo **SelIdents,
|
|
|
|
unsigned NumSelIdents,
|
2010-09-21 07:34:21 +08:00
|
|
|
bool AtArgumentExpression,
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
bool IsSuper,
|
|
|
|
ResultBuilder &Results) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
ObjCInterfaceDecl *CDecl = 0;
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
|
2009-11-18 01:59:40 +08:00
|
|
|
// If the given name refers to an interface type, retrieve the
|
|
|
|
// corresponding declaration.
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
if (Receiver) {
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
QualType T = SemaRef.GetTypeFromParser(Receiver, 0);
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
if (!T.isNull())
|
2010-05-15 19:32:37 +08:00
|
|
|
if (const ObjCObjectType *Interface = T->getAs<ObjCObjectType>())
|
|
|
|
CDecl = Interface->getInterface();
|
2009-11-18 01:59:40 +08:00
|
|
|
}
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
|
2009-11-18 07:22:23 +08:00
|
|
|
// Add all of the factory methods in this Objective-C class, its protocols,
|
|
|
|
// superclasses, categories, implementation, etc.
|
2009-11-07 10:08:14 +08:00
|
|
|
Results.EnterNewScope();
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
|
2010-08-27 23:10:57 +08:00
|
|
|
// If this is a send-to-super, try to add the special "super" send
|
|
|
|
// completion.
|
|
|
|
if (IsSuper) {
|
|
|
|
if (ObjCMethodDecl *SuperMethod
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
= AddSuperSendCompletion(SemaRef, false, SelIdents, NumSelIdents,
|
|
|
|
Results))
|
2010-08-27 23:10:57 +08:00
|
|
|
Results.Ignore(SuperMethod);
|
|
|
|
}
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
|
2010-08-27 23:29:55 +08:00
|
|
|
// If we're inside an Objective-C method definition, prefer its selector to
|
|
|
|
// others.
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
if (ObjCMethodDecl *CurMethod = SemaRef.getCurMethodDecl())
|
2010-08-27 23:29:55 +08:00
|
|
|
Results.setPreferredSelector(CurMethod->getSelector());
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
|
2010-09-17 00:06:31 +08:00
|
|
|
VisitedSelectorSet Selectors;
|
2010-04-07 00:40:00 +08:00
|
|
|
if (CDecl)
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
AddObjCMethods(CDecl, false, MK_Any, SelIdents, NumSelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
SemaRef.CurContext, Selectors, AtArgumentExpression,
|
|
|
|
Results);
|
Rework the Parser-Sema interaction for Objective-C message
sends. Major changes include:
- Expanded the interface from two actions (ActOnInstanceMessage,
ActOnClassMessage), where ActOnClassMessage also handled sends to
"super" by checking whether the identifier was "super", to three
actions (ActOnInstanceMessage, ActOnClassMessage,
ActOnSuperMessage). Code completion has the same changes.
- The parser now resolves the type to which we are sending a class
message, so ActOnClassMessage now accepts a TypeTy* (rather than
an IdentifierInfo *). This opens the door to more interesting
types (for Objective-C++ support).
- Split ActOnInstanceMessage and ActOnClassMessage into parser
action functions (with their original names) and semantic
functions (BuildInstanceMessage and BuildClassMessage,
respectively). At present, this split is onyl used by
ActOnSuperMessage, which decides which kind of super message it
has and forwards to the appropriate Build*Message. In the future,
Build*Message will be used by template instantiation.
- Use getObjCMessageKind() within the disambiguation of Objective-C
message sends vs. array designators.
Two notes about substandard bits in this patch:
- There is some redundancy in the code in ParseObjCMessageExpr and
ParseInitializerWithPotentialDesignator; this will be addressed
shortly by centralizing the mapping from identifiers to type names
for the message receiver.
- There is some #if 0'd code that won't likely ever be used---it
handles the use of 'super' in methods whose class does not have a
superclass---but could be used to model GCC's behavior more
closely. This code will die in my next check-in, but I want it in
Subversion.
llvm-svn: 102021
2010-04-22 03:57:20 +08:00
|
|
|
else {
|
2010-04-07 00:40:00 +08:00
|
|
|
// We're messaging "id" as a type; provide all class/factory methods.
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
|
2010-04-07 01:30:22 +08:00
|
|
|
// If we have an external source, load the entire class method
|
2010-08-19 07:57:06 +08:00
|
|
|
// pool from the AST file.
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
if (SemaRef.ExternalSource) {
|
|
|
|
for (uint32_t I = 0,
|
|
|
|
N = SemaRef.ExternalSource->GetNumExternalSelectors();
|
2010-06-01 17:23:16 +08:00
|
|
|
I != N; ++I) {
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
Selector Sel = SemaRef.ExternalSource->GetExternalSelector(I);
|
|
|
|
if (Sel.isNull() || SemaRef.MethodPool.count(Sel))
|
2010-04-07 01:30:22 +08:00
|
|
|
continue;
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
|
|
|
|
SemaRef.ReadMethodPool(Sel);
|
2010-04-07 01:30:22 +08:00
|
|
|
}
|
|
|
|
}
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
|
|
|
|
for (Sema::GlobalMethodPool::iterator M = SemaRef.MethodPool.begin(),
|
|
|
|
MEnd = SemaRef.MethodPool.end();
|
2010-08-03 07:18:59 +08:00
|
|
|
M != MEnd; ++M) {
|
|
|
|
for (ObjCMethodList *MethList = &M->second.second;
|
|
|
|
MethList && MethList->Method;
|
2010-04-07 00:40:00 +08:00
|
|
|
MethList = MethList->Next) {
|
|
|
|
if (!isAcceptableObjCMethod(MethList->Method, MK_Any, SelIdents,
|
|
|
|
NumSelIdents))
|
|
|
|
continue;
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
|
2010-04-07 00:40:00 +08:00
|
|
|
Result R(MethList->Method, 0);
|
|
|
|
R.StartParameter = NumSelIdents;
|
|
|
|
R.AllParametersAreInformative = false;
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
Results.MaybeAddResult(R, SemaRef.CurContext);
|
2010-04-07 00:40:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
|
|
|
|
Results.ExitScope();
|
|
|
|
}
|
2010-04-07 00:40:00 +08:00
|
|
|
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
void Sema::CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
|
|
|
|
IdentifierInfo **SelIdents,
|
|
|
|
unsigned NumSelIdents,
|
2010-09-21 07:34:21 +08:00
|
|
|
bool AtArgumentExpression,
|
Implement code completion for Objective-C class message sends that are
missing the opening bracket '[', e.g.,
NSArray <CC>
at function scope. Previously, we would only give trivial completions
(const, volatile, etc.), because we're in a "declaration name"
scope. Now, we also provide completions for class methods of NSArray,
e.g.,
alloc
Note that we already had support for this after the first argument,
e.g.,
NSArray method:x <CC>
would get code completion for class methods of NSArray whose selector
starts with "method:". This was already present because we recover
as if NSArray method:x were a class message send missing the opening
bracket (which was committed in r114057).
llvm-svn: 114078
2010-09-16 23:14:18 +08:00
|
|
|
bool IsSuper) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2010-09-21 07:34:21 +08:00
|
|
|
AddClassMessageCompletions(*this, S, Receiver, SelIdents, NumSelIdents,
|
|
|
|
AtArgumentExpression, IsSuper, Results);
|
2010-09-21 08:03:25 +08:00
|
|
|
|
|
|
|
// If we're actually at the argument expression (rather than prior to the
|
|
|
|
// selector), we're actually performing code completion for an expression.
|
|
|
|
// Determine whether we have a single, best method. If so, we can
|
|
|
|
// code-complete the expression using the corresponding parameter type as
|
|
|
|
// our preferred type, improving completion results.
|
|
|
|
if (AtArgumentExpression) {
|
|
|
|
QualType PreferredType = getPreferredArgumentTypeForMessageSend(Results,
|
|
|
|
NumSelIdents);
|
|
|
|
if (PreferredType.isNull())
|
|
|
|
CodeCompleteOrdinaryName(S, PCC_Expression);
|
|
|
|
else
|
|
|
|
CodeCompleteExpression(S, PreferredType);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
2010-08-27 23:10:57 +08:00
|
|
|
Results.data(), Results.size());
|
2009-11-07 10:08:14 +08:00
|
|
|
}
|
|
|
|
|
2010-08-27 23:10:57 +08:00
|
|
|
void Sema::CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver,
|
|
|
|
IdentifierInfo **SelIdents,
|
|
|
|
unsigned NumSelIdents,
|
2010-09-21 07:34:21 +08:00
|
|
|
bool AtArgumentExpression,
|
2010-10-14 05:24:53 +08:00
|
|
|
ObjCInterfaceDecl *Super) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-11-07 10:08:14 +08:00
|
|
|
|
|
|
|
Expr *RecExpr = static_cast<Expr *>(Receiver);
|
|
|
|
|
2009-11-18 07:22:23 +08:00
|
|
|
// If necessary, apply function/array conversion to the receiver.
|
|
|
|
// C99 6.7.5.3p[7,8].
|
2010-09-16 00:23:04 +08:00
|
|
|
if (RecExpr)
|
|
|
|
DefaultFunctionArrayLvalueConversion(RecExpr);
|
2010-10-14 05:24:53 +08:00
|
|
|
QualType ReceiverType = RecExpr? RecExpr->getType()
|
|
|
|
: Super? Context.getObjCObjectPointerType(
|
|
|
|
Context.getObjCInterfaceType(Super))
|
|
|
|
: Context.getObjCIdType();
|
2009-11-07 10:08:14 +08:00
|
|
|
|
2010-11-09 05:12:30 +08:00
|
|
|
// If we're messaging an expression with type "id" or "Class", check
|
|
|
|
// whether we know something special about the receiver that allows
|
|
|
|
// us to assume a more-specific receiver type.
|
|
|
|
if (ReceiverType->isObjCIdType() || ReceiverType->isObjCClassType())
|
|
|
|
if (ObjCInterfaceDecl *IFace = GetAssumedMessageSendExprType(RecExpr)) {
|
|
|
|
if (ReceiverType->isObjCClassType())
|
|
|
|
return CodeCompleteObjCClassMessage(S,
|
|
|
|
ParsedType::make(Context.getObjCInterfaceType(IFace)),
|
|
|
|
SelIdents, NumSelIdents,
|
|
|
|
AtArgumentExpression, Super);
|
|
|
|
|
|
|
|
ReceiverType = Context.getObjCObjectPointerType(
|
|
|
|
Context.getObjCInterfaceType(IFace));
|
|
|
|
}
|
|
|
|
|
2009-11-18 07:22:23 +08:00
|
|
|
// Build the set of methods we can see.
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-11-18 07:22:23 +08:00
|
|
|
Results.EnterNewScope();
|
2010-04-07 03:22:33 +08:00
|
|
|
|
2010-08-27 23:10:57 +08:00
|
|
|
// If this is a send-to-super, try to add the special "super" send
|
|
|
|
// completion.
|
2010-10-14 05:24:53 +08:00
|
|
|
if (Super) {
|
2010-08-27 23:10:57 +08:00
|
|
|
if (ObjCMethodDecl *SuperMethod
|
|
|
|
= AddSuperSendCompletion(*this, false, SelIdents, NumSelIdents,
|
|
|
|
Results))
|
|
|
|
Results.Ignore(SuperMethod);
|
|
|
|
}
|
|
|
|
|
2010-08-27 23:29:55 +08:00
|
|
|
// If we're inside an Objective-C method definition, prefer its selector to
|
|
|
|
// others.
|
|
|
|
if (ObjCMethodDecl *CurMethod = getCurMethodDecl())
|
|
|
|
Results.setPreferredSelector(CurMethod->getSelector());
|
2009-11-18 07:22:23 +08:00
|
|
|
|
2010-09-17 00:06:31 +08:00
|
|
|
// Keep track of the selectors we've already added.
|
|
|
|
VisitedSelectorSet Selectors;
|
|
|
|
|
2009-11-18 08:06:18 +08:00
|
|
|
// Handle messages to Class. This really isn't a message to an instance
|
|
|
|
// method, so we treat it the same way we would treat a message send to a
|
|
|
|
// class method.
|
|
|
|
if (ReceiverType->isObjCClassType() ||
|
|
|
|
ReceiverType->isObjCQualifiedClassType()) {
|
|
|
|
if (ObjCMethodDecl *CurMethod = getCurMethodDecl()) {
|
|
|
|
if (ObjCInterfaceDecl *ClassDecl = CurMethod->getClassInterface())
|
2009-11-19 15:41:15 +08:00
|
|
|
AddObjCMethods(ClassDecl, false, MK_Any, SelIdents, NumSelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
CurContext, Selectors, AtArgumentExpression, Results);
|
2009-11-18 08:06:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Handle messages to a qualified ID ("id<foo>").
|
|
|
|
else if (const ObjCObjectPointerType *QualID
|
|
|
|
= ReceiverType->getAsObjCQualifiedIdType()) {
|
|
|
|
// Search protocols for instance methods.
|
|
|
|
for (ObjCObjectPointerType::qual_iterator I = QualID->qual_begin(),
|
|
|
|
E = QualID->qual_end();
|
|
|
|
I != E; ++I)
|
2009-11-19 15:41:15 +08:00
|
|
|
AddObjCMethods(*I, true, MK_Any, SelIdents, NumSelIdents, CurContext,
|
2010-11-18 05:36:08 +08:00
|
|
|
Selectors, AtArgumentExpression, Results);
|
2009-11-18 08:06:18 +08:00
|
|
|
}
|
|
|
|
// Handle messages to a pointer to interface type.
|
|
|
|
else if (const ObjCObjectPointerType *IFacePtr
|
|
|
|
= ReceiverType->getAsObjCInterfacePointerType()) {
|
|
|
|
// Search the class, its superclasses, etc., for instance methods.
|
2009-11-19 15:41:15 +08:00
|
|
|
AddObjCMethods(IFacePtr->getInterfaceDecl(), true, MK_Any, SelIdents,
|
2010-11-18 05:36:08 +08:00
|
|
|
NumSelIdents, CurContext, Selectors, AtArgumentExpression,
|
|
|
|
Results);
|
2009-11-18 08:06:18 +08:00
|
|
|
|
|
|
|
// Search protocols for instance methods.
|
|
|
|
for (ObjCObjectPointerType::qual_iterator I = IFacePtr->qual_begin(),
|
|
|
|
E = IFacePtr->qual_end();
|
|
|
|
I != E; ++I)
|
2009-11-19 15:41:15 +08:00
|
|
|
AddObjCMethods(*I, true, MK_Any, SelIdents, NumSelIdents, CurContext,
|
2010-11-18 05:36:08 +08:00
|
|
|
Selectors, AtArgumentExpression, Results);
|
2009-11-18 08:06:18 +08:00
|
|
|
}
|
2010-04-07 00:40:00 +08:00
|
|
|
// Handle messages to "id".
|
|
|
|
else if (ReceiverType->isObjCIdType()) {
|
2010-04-07 01:30:22 +08:00
|
|
|
// We're messaging "id", so provide all instance methods we know
|
|
|
|
// about as code-completion results.
|
|
|
|
|
|
|
|
// If we have an external source, load the entire class method
|
2010-08-19 07:57:06 +08:00
|
|
|
// pool from the AST file.
|
2010-04-07 01:30:22 +08:00
|
|
|
if (ExternalSource) {
|
2010-06-01 17:23:16 +08:00
|
|
|
for (uint32_t I = 0, N = ExternalSource->GetNumExternalSelectors();
|
|
|
|
I != N; ++I) {
|
|
|
|
Selector Sel = ExternalSource->GetExternalSelector(I);
|
2010-08-03 07:18:59 +08:00
|
|
|
if (Sel.isNull() || MethodPool.count(Sel))
|
2010-04-07 01:30:22 +08:00
|
|
|
continue;
|
|
|
|
|
2010-08-03 07:18:59 +08:00
|
|
|
ReadMethodPool(Sel);
|
2010-04-07 01:30:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 07:18:59 +08:00
|
|
|
for (GlobalMethodPool::iterator M = MethodPool.begin(),
|
|
|
|
MEnd = MethodPool.end();
|
|
|
|
M != MEnd; ++M) {
|
|
|
|
for (ObjCMethodList *MethList = &M->second.first;
|
|
|
|
MethList && MethList->Method;
|
2010-04-07 00:40:00 +08:00
|
|
|
MethList = MethList->Next) {
|
|
|
|
if (!isAcceptableObjCMethod(MethList->Method, MK_Any, SelIdents,
|
|
|
|
NumSelIdents))
|
|
|
|
continue;
|
2010-09-17 00:06:31 +08:00
|
|
|
|
|
|
|
if (!Selectors.insert(MethList->Method->getSelector()))
|
|
|
|
continue;
|
|
|
|
|
2010-04-07 00:40:00 +08:00
|
|
|
Result R(MethList->Method, 0);
|
|
|
|
R.StartParameter = NumSelIdents;
|
|
|
|
R.AllParametersAreInformative = false;
|
|
|
|
Results.MaybeAddResult(R, CurContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-18 08:06:18 +08:00
|
|
|
Results.ExitScope();
|
2010-09-21 08:03:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
// If we're actually at the argument expression (rather than prior to the
|
|
|
|
// selector), we're actually performing code completion for an expression.
|
|
|
|
// Determine whether we have a single, best method. If so, we can
|
|
|
|
// code-complete the expression using the corresponding parameter type as
|
|
|
|
// our preferred type, improving completion results.
|
|
|
|
if (AtArgumentExpression) {
|
|
|
|
QualType PreferredType = getPreferredArgumentTypeForMessageSend(Results,
|
|
|
|
NumSelIdents);
|
|
|
|
if (PreferredType.isNull())
|
|
|
|
CodeCompleteOrdinaryName(S, PCC_Expression);
|
|
|
|
else
|
|
|
|
CodeCompleteExpression(S, PreferredType);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-11-07 10:08:14 +08:00
|
|
|
}
|
2009-11-18 12:19:12 +08:00
|
|
|
|
2010-08-24 05:17:50 +08:00
|
|
|
void Sema::CodeCompleteObjCForCollection(Scope *S,
|
|
|
|
DeclGroupPtrTy IterationVar) {
|
|
|
|
CodeCompleteExpressionData Data;
|
|
|
|
Data.ObjCCollection = true;
|
|
|
|
|
|
|
|
if (IterationVar.getAsOpaquePtr()) {
|
|
|
|
DeclGroupRef DG = IterationVar.getAsVal<DeclGroupRef>();
|
|
|
|
for (DeclGroupRef::iterator I = DG.begin(), End = DG.end(); I != End; ++I) {
|
|
|
|
if (*I)
|
|
|
|
Data.IgnoreDecls.push_back(*I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeCompleteExpression(S, Data);
|
|
|
|
}
|
|
|
|
|
2010-08-26 23:07:07 +08:00
|
|
|
void Sema::CodeCompleteObjCSelector(Scope *S, IdentifierInfo **SelIdents,
|
|
|
|
unsigned NumSelIdents) {
|
|
|
|
// If we have an external source, load the entire class method
|
|
|
|
// pool from the AST file.
|
|
|
|
if (ExternalSource) {
|
|
|
|
for (uint32_t I = 0, N = ExternalSource->GetNumExternalSelectors();
|
|
|
|
I != N; ++I) {
|
|
|
|
Selector Sel = ExternalSource->GetExternalSelector(I);
|
|
|
|
if (Sel.isNull() || MethodPool.count(Sel))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ReadMethodPool(Sel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_SelectorName);
|
2010-08-26 23:07:07 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
for (GlobalMethodPool::iterator M = MethodPool.begin(),
|
|
|
|
MEnd = MethodPool.end();
|
|
|
|
M != MEnd; ++M) {
|
|
|
|
|
|
|
|
Selector Sel = M->first;
|
|
|
|
if (!isAcceptableObjCSelector(Sel, MK_Any, SelIdents, NumSelIdents))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
if (Sel.isUnarySelector()) {
|
|
|
|
Pattern->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-08-27 00:46:39 +08:00
|
|
|
std::string Accumulator;
|
2010-08-26 23:07:07 +08:00
|
|
|
for (unsigned I = 0, N = Sel.getNumArgs(); I != N; ++I) {
|
2010-08-27 00:46:39 +08:00
|
|
|
if (I == NumSelIdents) {
|
|
|
|
if (!Accumulator.empty()) {
|
|
|
|
Pattern->AddInformativeChunk(Accumulator);
|
|
|
|
Accumulator.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Accumulator += Sel.getIdentifierInfoForSlot(I)->getName().str();
|
|
|
|
Accumulator += ':';
|
2010-08-26 23:07:07 +08:00
|
|
|
}
|
2010-08-27 00:46:39 +08:00
|
|
|
Pattern->AddTypedTextChunk(Accumulator);
|
2010-08-26 23:07:07 +08:00
|
|
|
Results.AddResult(Pattern);
|
|
|
|
}
|
|
|
|
Results.ExitScope();
|
|
|
|
|
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_SelectorName,
|
|
|
|
Results.data(), Results.size());
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:19:12 +08:00
|
|
|
/// \brief Add all of the protocol declarations that we find in the given
|
|
|
|
/// (translation unit) context.
|
|
|
|
static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext,
|
2009-11-18 12:49:41 +08:00
|
|
|
bool OnlyForwardDeclarations,
|
2009-11-18 12:19:12 +08:00
|
|
|
ResultBuilder &Results) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-11-18 12:19:12 +08:00
|
|
|
|
|
|
|
for (DeclContext::decl_iterator D = Ctx->decls_begin(),
|
|
|
|
DEnd = Ctx->decls_end();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
// Record any protocols we find.
|
|
|
|
if (ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(*D))
|
2009-11-18 12:49:41 +08:00
|
|
|
if (!OnlyForwardDeclarations || Proto->isForwardDecl())
|
2010-01-15 00:14:35 +08:00
|
|
|
Results.AddResult(Result(Proto, 0), CurContext, 0, false);
|
2009-11-18 12:19:12 +08:00
|
|
|
|
|
|
|
// Record any forward-declared protocols we find.
|
|
|
|
if (ObjCForwardProtocolDecl *Forward
|
|
|
|
= dyn_cast<ObjCForwardProtocolDecl>(*D)) {
|
|
|
|
for (ObjCForwardProtocolDecl::protocol_iterator
|
|
|
|
P = Forward->protocol_begin(),
|
|
|
|
PEnd = Forward->protocol_end();
|
|
|
|
P != PEnd; ++P)
|
2009-11-18 12:49:41 +08:00
|
|
|
if (!OnlyForwardDeclarations || (*P)->isForwardDecl())
|
2010-01-15 00:14:35 +08:00
|
|
|
Results.AddResult(Result(*P, 0), CurContext, 0, false);
|
2009-11-18 12:19:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
|
|
|
|
unsigned NumProtocols) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_ObjCProtocolName);
|
2009-11-18 12:19:12 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// Tell the result set to ignore all of the protocols we have
|
|
|
|
// already seen.
|
|
|
|
for (unsigned I = 0; I != NumProtocols; ++I)
|
2010-04-16 06:33:43 +08:00
|
|
|
if (ObjCProtocolDecl *Protocol = LookupProtocol(Protocols[I].first,
|
|
|
|
Protocols[I].second))
|
2009-11-18 12:19:12 +08:00
|
|
|
Results.Ignore(Protocol);
|
|
|
|
|
|
|
|
// Add all protocols.
|
2009-11-18 12:49:41 +08:00
|
|
|
AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, false,
|
|
|
|
Results);
|
|
|
|
|
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_ObjCProtocolName,
|
|
|
|
Results.data(),Results.size());
|
2009-11-18 12:49:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCProtocolDecl(Scope *) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_ObjCProtocolName);
|
2009-11-18 12:49:41 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// Add all protocols.
|
|
|
|
AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, true,
|
|
|
|
Results);
|
2009-11-18 12:19:12 +08:00
|
|
|
|
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_ObjCProtocolName,
|
|
|
|
Results.data(),Results.size());
|
2009-11-18 12:19:12 +08:00
|
|
|
}
|
2009-11-19 00:26:39 +08:00
|
|
|
|
|
|
|
/// \brief Add all of the Objective-C interface declarations that we find in
|
|
|
|
/// the given (translation unit) context.
|
|
|
|
static void AddInterfaceResults(DeclContext *Ctx, DeclContext *CurContext,
|
|
|
|
bool OnlyForwardDeclarations,
|
|
|
|
bool OnlyUnimplemented,
|
|
|
|
ResultBuilder &Results) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-11-19 00:26:39 +08:00
|
|
|
|
|
|
|
for (DeclContext::decl_iterator D = Ctx->decls_begin(),
|
|
|
|
DEnd = Ctx->decls_end();
|
|
|
|
D != DEnd; ++D) {
|
2010-08-11 20:19:30 +08:00
|
|
|
// Record any interfaces we find.
|
|
|
|
if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(*D))
|
|
|
|
if ((!OnlyForwardDeclarations || Class->isForwardDecl()) &&
|
|
|
|
(!OnlyUnimplemented || !Class->getImplementation()))
|
|
|
|
Results.AddResult(Result(Class, 0), CurContext, 0, false);
|
2009-11-19 00:26:39 +08:00
|
|
|
|
|
|
|
// Record any forward-declared interfaces we find.
|
|
|
|
if (ObjCClassDecl *Forward = dyn_cast<ObjCClassDecl>(*D)) {
|
|
|
|
for (ObjCClassDecl::iterator C = Forward->begin(), CEnd = Forward->end();
|
2010-08-11 20:19:30 +08:00
|
|
|
C != CEnd; ++C)
|
|
|
|
if ((!OnlyForwardDeclarations || C->getInterface()->isForwardDecl()) &&
|
|
|
|
(!OnlyUnimplemented || !C->getInterface()->getImplementation()))
|
|
|
|
Results.AddResult(Result(C->getInterface(), 0), CurContext,
|
2010-01-15 00:14:35 +08:00
|
|
|
0, false);
|
2009-11-19 00:26:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCInterfaceDecl(Scope *S) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-11-19 00:26:39 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// Add all classes.
|
|
|
|
AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, true,
|
|
|
|
false, Results);
|
|
|
|
|
|
|
|
Results.ExitScope();
|
2010-09-24 07:01:17 +08:00
|
|
|
// FIXME: Add a special context for this, use cached global completion
|
|
|
|
// results.
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-11-19 00:26:39 +08:00
|
|
|
}
|
|
|
|
|
2010-04-16 06:33:43 +08:00
|
|
|
void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName,
|
|
|
|
SourceLocation ClassNameLoc) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-11-19 00:26:39 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// Make sure that we ignore the class we're currently defining.
|
|
|
|
NamedDecl *CurClass
|
2010-04-16 06:33:43 +08:00
|
|
|
= LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName);
|
2009-11-19 03:08:43 +08:00
|
|
|
if (CurClass && isa<ObjCInterfaceDecl>(CurClass))
|
2009-11-19 00:26:39 +08:00
|
|
|
Results.Ignore(CurClass);
|
|
|
|
|
|
|
|
// Add all classes.
|
|
|
|
AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false,
|
|
|
|
false, Results);
|
|
|
|
|
|
|
|
Results.ExitScope();
|
2010-09-24 07:01:17 +08:00
|
|
|
// FIXME: Add a special context for this, use cached global completion
|
|
|
|
// results.
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-11-19 00:26:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCImplementationDecl(Scope *S) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-11-19 00:26:39 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// Add all unimplemented classes.
|
|
|
|
AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false,
|
|
|
|
true, Results);
|
|
|
|
|
|
|
|
Results.ExitScope();
|
2010-09-24 07:01:17 +08:00
|
|
|
// FIXME: Add a special context for this, use cached global completion
|
|
|
|
// results.
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-11-19 00:26:39 +08:00
|
|
|
}
|
2009-11-19 03:08:43 +08:00
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCInterfaceCategory(Scope *S,
|
2010-04-16 06:33:43 +08:00
|
|
|
IdentifierInfo *ClassName,
|
|
|
|
SourceLocation ClassNameLoc) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-11-19 03:08:43 +08:00
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-11-19 03:08:43 +08:00
|
|
|
|
|
|
|
// Ignore any categories we find that have already been implemented by this
|
|
|
|
// interface.
|
|
|
|
llvm::SmallPtrSet<IdentifierInfo *, 16> CategoryNames;
|
|
|
|
NamedDecl *CurClass
|
2010-04-16 06:33:43 +08:00
|
|
|
= LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName);
|
2009-11-19 03:08:43 +08:00
|
|
|
if (ObjCInterfaceDecl *Class = dyn_cast_or_null<ObjCInterfaceDecl>(CurClass))
|
|
|
|
for (ObjCCategoryDecl *Category = Class->getCategoryList(); Category;
|
|
|
|
Category = Category->getNextClassCategory())
|
|
|
|
CategoryNames.insert(Category->getIdentifier());
|
|
|
|
|
|
|
|
// Add all of the categories we know about.
|
|
|
|
Results.EnterNewScope();
|
|
|
|
TranslationUnitDecl *TU = Context.getTranslationUnitDecl();
|
|
|
|
for (DeclContext::decl_iterator D = TU->decls_begin(),
|
|
|
|
DEnd = TU->decls_end();
|
|
|
|
D != DEnd; ++D)
|
|
|
|
if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(*D))
|
|
|
|
if (CategoryNames.insert(Category->getIdentifier()))
|
2010-01-15 00:14:35 +08:00
|
|
|
Results.AddResult(Result(Category, 0), CurContext, 0, false);
|
2009-11-19 03:08:43 +08:00
|
|
|
Results.ExitScope();
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-11-19 03:08:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCImplementationCategory(Scope *S,
|
2010-04-16 06:33:43 +08:00
|
|
|
IdentifierInfo *ClassName,
|
|
|
|
SourceLocation ClassNameLoc) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2009-11-19 03:08:43 +08:00
|
|
|
|
|
|
|
// Find the corresponding interface. If we couldn't find the interface, the
|
|
|
|
// program itself is ill-formed. However, we'll try to be helpful still by
|
|
|
|
// providing the list of all of the categories we know about.
|
|
|
|
NamedDecl *CurClass
|
2010-04-16 06:33:43 +08:00
|
|
|
= LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName);
|
2009-11-19 03:08:43 +08:00
|
|
|
ObjCInterfaceDecl *Class = dyn_cast_or_null<ObjCInterfaceDecl>(CurClass);
|
|
|
|
if (!Class)
|
2010-04-16 06:33:43 +08:00
|
|
|
return CodeCompleteObjCInterfaceCategory(S, ClassName, ClassNameLoc);
|
2009-11-19 03:08:43 +08:00
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-11-19 03:08:43 +08:00
|
|
|
|
|
|
|
// Add all of the categories that have have corresponding interface
|
|
|
|
// declarations in this class and any of its superclasses, except for
|
|
|
|
// already-implemented categories in the class itself.
|
|
|
|
llvm::SmallPtrSet<IdentifierInfo *, 16> CategoryNames;
|
|
|
|
Results.EnterNewScope();
|
|
|
|
bool IgnoreImplemented = true;
|
|
|
|
while (Class) {
|
|
|
|
for (ObjCCategoryDecl *Category = Class->getCategoryList(); Category;
|
|
|
|
Category = Category->getNextClassCategory())
|
|
|
|
if ((!IgnoreImplemented || !Category->getImplementation()) &&
|
|
|
|
CategoryNames.insert(Category->getIdentifier()))
|
2010-01-15 00:14:35 +08:00
|
|
|
Results.AddResult(Result(Category, 0), CurContext, 0, false);
|
2009-11-19 03:08:43 +08:00
|
|
|
|
|
|
|
Class = Class->getSuperClass();
|
|
|
|
IgnoreImplemented = false;
|
|
|
|
}
|
|
|
|
Results.ExitScope();
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-11-19 03:08:43 +08:00
|
|
|
}
|
2009-11-19 06:32:06 +08:00
|
|
|
|
2010-08-21 17:40:31 +08:00
|
|
|
void Sema::CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-11-19 06:32:06 +08:00
|
|
|
|
|
|
|
// Figure out where this @synthesize lives.
|
|
|
|
ObjCContainerDecl *Container
|
2010-08-21 17:40:31 +08:00
|
|
|
= dyn_cast_or_null<ObjCContainerDecl>(ObjCImpDecl);
|
2009-11-19 06:32:06 +08:00
|
|
|
if (!Container ||
|
|
|
|
(!isa<ObjCImplementationDecl>(Container) &&
|
|
|
|
!isa<ObjCCategoryImplDecl>(Container)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ignore any properties that have already been implemented.
|
|
|
|
for (DeclContext::decl_iterator D = Container->decls_begin(),
|
|
|
|
DEnd = Container->decls_end();
|
|
|
|
D != DEnd; ++D)
|
|
|
|
if (ObjCPropertyImplDecl *PropertyImpl = dyn_cast<ObjCPropertyImplDecl>(*D))
|
|
|
|
Results.Ignore(PropertyImpl->getPropertyDecl());
|
|
|
|
|
|
|
|
// Add any properties that we find.
|
|
|
|
Results.EnterNewScope();
|
|
|
|
if (ObjCImplementationDecl *ClassImpl
|
|
|
|
= dyn_cast<ObjCImplementationDecl>(Container))
|
|
|
|
AddObjCProperties(ClassImpl->getClassInterface(), false, CurContext,
|
|
|
|
Results);
|
|
|
|
else
|
|
|
|
AddObjCProperties(cast<ObjCCategoryImplDecl>(Container)->getCategoryDecl(),
|
|
|
|
false, CurContext, Results);
|
|
|
|
Results.ExitScope();
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-11-19 06:32:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
|
|
|
|
IdentifierInfo *PropertyName,
|
2010-08-21 17:40:31 +08:00
|
|
|
Decl *ObjCImpDecl) {
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2009-11-19 06:32:06 +08:00
|
|
|
|
|
|
|
// Figure out where this @synthesize lives.
|
|
|
|
ObjCContainerDecl *Container
|
2010-08-21 17:40:31 +08:00
|
|
|
= dyn_cast_or_null<ObjCContainerDecl>(ObjCImpDecl);
|
2009-11-19 06:32:06 +08:00
|
|
|
if (!Container ||
|
|
|
|
(!isa<ObjCImplementationDecl>(Container) &&
|
|
|
|
!isa<ObjCCategoryImplDecl>(Container)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Figure out which interface we're looking into.
|
|
|
|
ObjCInterfaceDecl *Class = 0;
|
|
|
|
if (ObjCImplementationDecl *ClassImpl
|
|
|
|
= dyn_cast<ObjCImplementationDecl>(Container))
|
|
|
|
Class = ClassImpl->getClassInterface();
|
|
|
|
else
|
|
|
|
Class = cast<ObjCCategoryImplDecl>(Container)->getCategoryDecl()
|
|
|
|
->getClassInterface();
|
|
|
|
|
|
|
|
// Add all of the instance variables in this class and its superclasses.
|
|
|
|
Results.EnterNewScope();
|
|
|
|
for(; Class; Class = Class->getSuperClass()) {
|
|
|
|
// FIXME: We could screen the type of each ivar for compatibility with
|
|
|
|
// the property, but is that being too paternal?
|
|
|
|
for (ObjCInterfaceDecl::ivar_iterator IVar = Class->ivar_begin(),
|
|
|
|
IVarEnd = Class->ivar_end();
|
|
|
|
IVar != IVarEnd; ++IVar)
|
2010-01-15 00:14:35 +08:00
|
|
|
Results.AddResult(Result(*IVar, 0), CurContext, 0, false);
|
2009-11-19 06:32:06 +08:00
|
|
|
}
|
|
|
|
Results.ExitScope();
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2009-11-19 06:32:06 +08:00
|
|
|
}
|
2010-04-07 08:21:17 +08:00
|
|
|
|
2010-08-25 09:08:01 +08:00
|
|
|
// Mapping from selectors to the methods that implement that selector, along
|
|
|
|
// with the "in original class" flag.
|
|
|
|
typedef llvm::DenseMap<Selector, std::pair<ObjCMethodDecl *, bool> >
|
|
|
|
KnownMethodsMap;
|
2010-04-07 08:21:17 +08:00
|
|
|
|
|
|
|
/// \brief Find all of the methods that reside in the given container
|
|
|
|
/// (and its superclasses, protocols, etc.) that meet the given
|
|
|
|
/// criteria. Insert those methods into the map of known methods,
|
|
|
|
/// indexed by selector so they can be easily found.
|
|
|
|
static void FindImplementableMethods(ASTContext &Context,
|
|
|
|
ObjCContainerDecl *Container,
|
|
|
|
bool WantInstanceMethods,
|
|
|
|
QualType ReturnType,
|
2010-08-25 09:08:01 +08:00
|
|
|
KnownMethodsMap &KnownMethods,
|
|
|
|
bool InOriginalClass = true) {
|
2010-04-07 08:21:17 +08:00
|
|
|
if (ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container)) {
|
|
|
|
// Recurse into protocols.
|
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols
|
|
|
|
= IFace->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
|
2010-10-19 02:21:28 +08:00
|
|
|
E = Protocols.end();
|
2010-04-07 08:21:17 +08:00
|
|
|
I != E; ++I)
|
|
|
|
FindImplementableMethods(Context, *I, WantInstanceMethods, ReturnType,
|
2010-10-19 02:21:28 +08:00
|
|
|
KnownMethods, InOriginalClass);
|
2010-04-07 08:21:17 +08:00
|
|
|
|
2010-10-19 02:21:28 +08:00
|
|
|
// Add methods from any class extensions and categories.
|
|
|
|
for (const ObjCCategoryDecl *Cat = IFace->getCategoryList(); Cat;
|
|
|
|
Cat = Cat->getNextClassCategory())
|
2010-06-23 07:20:40 +08:00
|
|
|
FindImplementableMethods(Context, const_cast<ObjCCategoryDecl*>(Cat),
|
|
|
|
WantInstanceMethods, ReturnType,
|
2010-10-19 02:21:28 +08:00
|
|
|
KnownMethods, false);
|
|
|
|
|
|
|
|
// Visit the superclass.
|
|
|
|
if (IFace->getSuperClass())
|
|
|
|
FindImplementableMethods(Context, IFace->getSuperClass(),
|
|
|
|
WantInstanceMethods, ReturnType,
|
|
|
|
KnownMethods, false);
|
2010-04-07 08:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(Container)) {
|
|
|
|
// Recurse into protocols.
|
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols
|
|
|
|
= Category->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
|
2010-10-19 02:21:28 +08:00
|
|
|
E = Protocols.end();
|
2010-04-07 08:21:17 +08:00
|
|
|
I != E; ++I)
|
|
|
|
FindImplementableMethods(Context, *I, WantInstanceMethods, ReturnType,
|
2010-10-19 02:21:28 +08:00
|
|
|
KnownMethods, InOriginalClass);
|
|
|
|
|
|
|
|
// If this category is the original class, jump to the interface.
|
|
|
|
if (InOriginalClass && Category->getClassInterface())
|
|
|
|
FindImplementableMethods(Context, Category->getClassInterface(),
|
|
|
|
WantInstanceMethods, ReturnType, KnownMethods,
|
|
|
|
false);
|
2010-04-07 08:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
|
|
|
|
// Recurse into protocols.
|
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols
|
|
|
|
= Protocol->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
|
|
|
|
E = Protocols.end();
|
|
|
|
I != E; ++I)
|
|
|
|
FindImplementableMethods(Context, *I, WantInstanceMethods, ReturnType,
|
2010-10-19 02:21:28 +08:00
|
|
|
KnownMethods, false);
|
2010-04-07 08:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add methods in this container. This operation occurs last because
|
|
|
|
// we want the methods from this container to override any methods
|
|
|
|
// we've previously seen with the same selector.
|
|
|
|
for (ObjCContainerDecl::method_iterator M = Container->meth_begin(),
|
|
|
|
MEnd = Container->meth_end();
|
|
|
|
M != MEnd; ++M) {
|
|
|
|
if ((*M)->isInstanceMethod() == WantInstanceMethods) {
|
|
|
|
if (!ReturnType.isNull() &&
|
|
|
|
!Context.hasSameUnqualifiedType(ReturnType, (*M)->getResultType()))
|
|
|
|
continue;
|
|
|
|
|
2010-08-25 09:08:01 +08:00
|
|
|
KnownMethods[(*M)->getSelector()] = std::make_pair(*M, InOriginalClass);
|
2010-04-07 08:21:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCMethodDecl(Scope *S,
|
|
|
|
bool IsInstanceMethod,
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType ReturnTy,
|
2010-08-21 17:40:31 +08:00
|
|
|
Decl *IDecl) {
|
2010-04-07 08:21:17 +08:00
|
|
|
// Determine the return type of the method we're declaring, if
|
|
|
|
// provided.
|
|
|
|
QualType ReturnType = GetTypeFromParser(ReturnTy);
|
|
|
|
|
2010-10-19 02:21:28 +08:00
|
|
|
// Determine where we should start searching for methods.
|
|
|
|
ObjCContainerDecl *SearchDecl = 0;
|
2010-04-07 08:21:17 +08:00
|
|
|
bool IsInImplementation = false;
|
2010-08-21 17:40:31 +08:00
|
|
|
if (Decl *D = IDecl) {
|
2010-04-07 08:21:17 +08:00
|
|
|
if (ObjCImplementationDecl *Impl = dyn_cast<ObjCImplementationDecl>(D)) {
|
|
|
|
SearchDecl = Impl->getClassInterface();
|
|
|
|
IsInImplementation = true;
|
|
|
|
} else if (ObjCCategoryImplDecl *CatImpl
|
2010-10-19 02:21:28 +08:00
|
|
|
= dyn_cast<ObjCCategoryImplDecl>(D)) {
|
2010-04-07 08:21:17 +08:00
|
|
|
SearchDecl = CatImpl->getCategoryDecl();
|
|
|
|
IsInImplementation = true;
|
2010-10-19 02:21:28 +08:00
|
|
|
} else
|
2010-04-07 08:21:17 +08:00
|
|
|
SearchDecl = dyn_cast<ObjCContainerDecl>(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SearchDecl && S) {
|
2010-10-19 02:21:28 +08:00
|
|
|
if (DeclContext *DC = static_cast<DeclContext *>(S->getEntity()))
|
2010-04-07 08:21:17 +08:00
|
|
|
SearchDecl = dyn_cast<ObjCContainerDecl>(DC);
|
|
|
|
}
|
|
|
|
|
2010-10-19 02:21:28 +08:00
|
|
|
if (!SearchDecl) {
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
0, 0);
|
2010-04-07 08:21:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find all of the methods that we could declare/implement here.
|
|
|
|
KnownMethodsMap KnownMethods;
|
|
|
|
FindImplementableMethods(Context, SearchDecl, IsInstanceMethod,
|
2010-10-19 02:21:28 +08:00
|
|
|
ReturnType, KnownMethods);
|
2010-04-07 08:21:17 +08:00
|
|
|
|
|
|
|
// Add declarations or definitions for each of the known methods.
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2010-04-07 08:21:17 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
PrintingPolicy Policy(Context.PrintingPolicy);
|
|
|
|
Policy.AnonymousTagLocations = false;
|
|
|
|
for (KnownMethodsMap::iterator M = KnownMethods.begin(),
|
|
|
|
MEnd = KnownMethods.end();
|
|
|
|
M != MEnd; ++M) {
|
2010-08-25 09:08:01 +08:00
|
|
|
ObjCMethodDecl *Method = M->second.first;
|
2010-04-07 08:21:17 +08:00
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
|
|
|
|
// If the result type was not already provided, add it to the
|
|
|
|
// pattern as (type).
|
|
|
|
if (ReturnType.isNull()) {
|
|
|
|
std::string TypeStr;
|
|
|
|
Method->getResultType().getAsStringInternal(TypeStr, Policy);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddTextChunk(TypeStr);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
}
|
|
|
|
|
|
|
|
Selector Sel = Method->getSelector();
|
|
|
|
|
|
|
|
// Add the first part of the selector to the pattern.
|
|
|
|
Pattern->AddTypedTextChunk(Sel.getIdentifierInfoForSlot(0)->getName());
|
|
|
|
|
|
|
|
// Add parameters to the pattern.
|
|
|
|
unsigned I = 0;
|
|
|
|
for (ObjCMethodDecl::param_iterator P = Method->param_begin(),
|
|
|
|
PEnd = Method->param_end();
|
|
|
|
P != PEnd; (void)++P, ++I) {
|
|
|
|
// Add the part of the selector name.
|
|
|
|
if (I == 0)
|
2010-10-19 05:05:04 +08:00
|
|
|
Pattern->AddTypedTextChunk(":");
|
2010-04-07 08:21:17 +08:00
|
|
|
else if (I < Sel.getNumArgs()) {
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
2010-10-19 05:05:04 +08:00
|
|
|
Pattern->AddTypedTextChunk((Sel.getIdentifierInfoForSlot(I)->getName()
|
|
|
|
+ ":").str());
|
2010-04-07 08:21:17 +08:00
|
|
|
} else
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Add the parameter type.
|
|
|
|
std::string TypeStr;
|
|
|
|
(*P)->getOriginalType().getAsStringInternal(TypeStr, Policy);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddTextChunk(TypeStr);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
|
|
|
|
if (IdentifierInfo *Id = (*P)->getIdentifier())
|
2010-08-31 13:13:43 +08:00
|
|
|
Pattern->AddTextChunk(Id->getName());
|
2010-04-07 08:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Method->isVariadic()) {
|
|
|
|
if (Method->param_size() > 0)
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_Comma);
|
|
|
|
Pattern->AddTextChunk("...");
|
2010-08-31 13:13:43 +08:00
|
|
|
}
|
2010-04-07 08:21:17 +08:00
|
|
|
|
2010-05-28 08:57:46 +08:00
|
|
|
if (IsInImplementation && Results.includeCodePatterns()) {
|
2010-04-07 08:21:17 +08:00
|
|
|
// We will be defining the method here, so add a compound statement.
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftBrace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
|
|
|
if (!Method->getResultType()->isVoidType()) {
|
|
|
|
// If the result type is not void, add a return clause.
|
|
|
|
Pattern->AddTextChunk("return");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("expression");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_SemiColon);
|
|
|
|
} else
|
|
|
|
Pattern->AddPlaceholderChunk("statements");
|
|
|
|
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_VerticalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightBrace);
|
|
|
|
}
|
|
|
|
|
2010-08-25 09:08:01 +08:00
|
|
|
unsigned Priority = CCP_CodePattern;
|
|
|
|
if (!M->second.second)
|
|
|
|
Priority += CCD_InBaseClass;
|
|
|
|
|
|
|
|
Results.AddResult(Result(Pattern, Priority,
|
2010-08-18 00:06:07 +08:00
|
|
|
Method->isInstanceMethod()
|
|
|
|
? CXCursor_ObjCInstanceMethodDecl
|
|
|
|
: CXCursor_ObjCClassMethodDecl));
|
2010-04-07 08:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Results.ExitScope();
|
|
|
|
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2010-04-07 08:21:17 +08:00
|
|
|
}
|
2010-07-09 07:20:03 +08:00
|
|
|
|
|
|
|
void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S,
|
|
|
|
bool IsInstanceMethod,
|
2010-07-09 07:37:41 +08:00
|
|
|
bool AtParameterName,
|
2010-08-24 13:47:05 +08:00
|
|
|
ParsedType ReturnTy,
|
2010-07-09 07:20:03 +08:00
|
|
|
IdentifierInfo **SelIdents,
|
|
|
|
unsigned NumSelIdents) {
|
|
|
|
// If we have an external source, load the entire class method
|
2010-08-19 07:57:06 +08:00
|
|
|
// pool from the AST file.
|
2010-07-09 07:20:03 +08:00
|
|
|
if (ExternalSource) {
|
|
|
|
for (uint32_t I = 0, N = ExternalSource->GetNumExternalSelectors();
|
|
|
|
I != N; ++I) {
|
|
|
|
Selector Sel = ExternalSource->GetExternalSelector(I);
|
2010-08-03 07:18:59 +08:00
|
|
|
if (Sel.isNull() || MethodPool.count(Sel))
|
2010-07-09 07:20:03 +08:00
|
|
|
continue;
|
2010-08-03 07:18:59 +08:00
|
|
|
|
|
|
|
ReadMethodPool(Sel);
|
2010-07-09 07:20:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the set of methods we can see.
|
2010-08-25 14:19:51 +08:00
|
|
|
typedef CodeCompletionResult Result;
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
|
2010-07-09 07:20:03 +08:00
|
|
|
|
|
|
|
if (ReturnTy)
|
|
|
|
Results.setPreferredType(GetTypeFromParser(ReturnTy).getNonReferenceType());
|
2010-08-03 07:18:59 +08:00
|
|
|
|
2010-07-09 07:20:03 +08:00
|
|
|
Results.EnterNewScope();
|
2010-08-03 07:18:59 +08:00
|
|
|
for (GlobalMethodPool::iterator M = MethodPool.begin(),
|
|
|
|
MEnd = MethodPool.end();
|
|
|
|
M != MEnd; ++M) {
|
|
|
|
for (ObjCMethodList *MethList = IsInstanceMethod ? &M->second.first :
|
|
|
|
&M->second.second;
|
|
|
|
MethList && MethList->Method;
|
2010-07-09 07:20:03 +08:00
|
|
|
MethList = MethList->Next) {
|
|
|
|
if (!isAcceptableObjCMethod(MethList->Method, MK_Any, SelIdents,
|
|
|
|
NumSelIdents))
|
|
|
|
continue;
|
|
|
|
|
2010-07-09 07:37:41 +08:00
|
|
|
if (AtParameterName) {
|
|
|
|
// Suggest parameter names we've seen before.
|
|
|
|
if (NumSelIdents && NumSelIdents <= MethList->Method->param_size()) {
|
|
|
|
ParmVarDecl *Param = MethList->Method->param_begin()[NumSelIdents-1];
|
|
|
|
if (Param->getIdentifier()) {
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(Param->getIdentifier()->getName());
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-07-09 07:20:03 +08:00
|
|
|
Result R(MethList->Method, 0);
|
|
|
|
R.StartParameter = NumSelIdents;
|
|
|
|
R.AllParametersAreInformative = false;
|
|
|
|
R.DeclaringEntity = true;
|
|
|
|
Results.MaybeAddResult(R, CurContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Results.ExitScope();
|
2010-08-12 05:23:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
Results.data(),Results.size());
|
2010-07-09 07:20:03 +08:00
|
|
|
}
|
2010-08-14 06:48:40 +08:00
|
|
|
|
2010-08-25 06:20:20 +08:00
|
|
|
void Sema::CodeCompletePreprocessorDirective(bool InConditional) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this,
|
|
|
|
CodeCompletionContext::CCC_PreprocessorDirective);
|
2010-08-25 03:08:16 +08:00
|
|
|
Results.EnterNewScope();
|
|
|
|
|
|
|
|
// #if <condition>
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("if");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("condition");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #ifdef <macro>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("ifdef");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("macro");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #ifndef <macro>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("ifndef");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("macro");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
if (InConditional) {
|
|
|
|
// #elif <condition>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("elif");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("condition");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #else
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("else");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #endif
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("endif");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
// #include "header"
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("include");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddTextChunk("\"");
|
|
|
|
Pattern->AddPlaceholderChunk("header");
|
|
|
|
Pattern->AddTextChunk("\"");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #include <header>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("include");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddTextChunk("<");
|
|
|
|
Pattern->AddPlaceholderChunk("header");
|
|
|
|
Pattern->AddTextChunk(">");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #define <macro>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("define");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("macro");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #define <macro>(<args>)
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("define");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("macro");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("args");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #undef <macro>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("undef");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("macro");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #line <number>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("line");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("number");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #line <number> "filename"
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("line");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("number");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddTextChunk("\"");
|
|
|
|
Pattern->AddPlaceholderChunk("filename");
|
|
|
|
Pattern->AddTextChunk("\"");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #error <message>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("error");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("message");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #pragma <arguments>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("pragma");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("arguments");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
if (getLangOptions().ObjC1) {
|
|
|
|
// #import "header"
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("import");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddTextChunk("\"");
|
|
|
|
Pattern->AddPlaceholderChunk("header");
|
|
|
|
Pattern->AddTextChunk("\"");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #import <header>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("import");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddTextChunk("<");
|
|
|
|
Pattern->AddPlaceholderChunk("header");
|
|
|
|
Pattern->AddTextChunk(">");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
// #include_next "header"
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("include_next");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddTextChunk("\"");
|
|
|
|
Pattern->AddPlaceholderChunk("header");
|
|
|
|
Pattern->AddTextChunk("\"");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #include_next <header>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("include_next");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddTextChunk("<");
|
|
|
|
Pattern->AddPlaceholderChunk("header");
|
|
|
|
Pattern->AddTextChunk(">");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// #warning <message>
|
|
|
|
Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("warning");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddPlaceholderChunk("message");
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
|
|
|
|
// Note: #ident and #sccs are such crazy anachronisms that we don't provide
|
|
|
|
// completions for them. And __include_macros is a Clang-internal extension
|
|
|
|
// that we don't want to encourage anyone to use.
|
|
|
|
|
|
|
|
// FIXME: we don't support #assert or #unassert, so don't suggest them.
|
|
|
|
Results.ExitScope();
|
|
|
|
|
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
2010-08-26 02:41:16 +08:00
|
|
|
CodeCompletionContext::CCC_PreprocessorDirective,
|
2010-08-25 03:08:16 +08:00
|
|
|
Results.data(), Results.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompleteInPreprocessorConditionalExclusion(Scope *S) {
|
2010-08-25 06:20:20 +08:00
|
|
|
CodeCompleteOrdinaryName(S,
|
2010-08-27 07:41:50 +08:00
|
|
|
S->getFnParent()? Sema::PCC_RecoveryInFunction
|
|
|
|
: Sema::PCC_Namespace);
|
2010-08-25 03:08:16 +08:00
|
|
|
}
|
|
|
|
|
2010-08-25 06:20:20 +08:00
|
|
|
void Sema::CodeCompletePreprocessorMacroName(bool IsDefinition) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this,
|
|
|
|
IsDefinition? CodeCompletionContext::CCC_MacroName
|
|
|
|
: CodeCompletionContext::CCC_MacroNameUse);
|
2010-08-25 04:21:13 +08:00
|
|
|
if (!IsDefinition && (!CodeCompleter || CodeCompleter->includeMacros())) {
|
|
|
|
// Add just the names of macros, not their arguments.
|
|
|
|
Results.EnterNewScope();
|
|
|
|
for (Preprocessor::macro_iterator M = PP.macro_begin(),
|
|
|
|
MEnd = PP.macro_end();
|
|
|
|
M != MEnd; ++M) {
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk(M->first->getName());
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
}
|
|
|
|
Results.ExitScope();
|
|
|
|
} else if (IsDefinition) {
|
|
|
|
// FIXME: Can we detect when the user just wrote an include guard above?
|
|
|
|
}
|
|
|
|
|
2010-09-24 07:01:17 +08:00
|
|
|
HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
|
2010-08-25 04:21:13 +08:00
|
|
|
Results.data(), Results.size());
|
|
|
|
}
|
|
|
|
|
2010-08-25 06:20:20 +08:00
|
|
|
void Sema::CodeCompletePreprocessorExpression() {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Results(*this,
|
|
|
|
CodeCompletionContext::CCC_PreprocessorExpression);
|
2010-08-25 06:20:20 +08:00
|
|
|
|
|
|
|
if (!CodeCompleter || CodeCompleter->includeMacros())
|
|
|
|
AddMacroResults(PP, Results);
|
|
|
|
|
|
|
|
// defined (<macro>)
|
|
|
|
Results.EnterNewScope();
|
|
|
|
CodeCompletionString *Pattern = new CodeCompletionString;
|
|
|
|
Pattern->AddTypedTextChunk("defined");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_HorizontalSpace);
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_LeftParen);
|
|
|
|
Pattern->AddPlaceholderChunk("macro");
|
|
|
|
Pattern->AddChunk(CodeCompletionString::CK_RightParen);
|
|
|
|
Results.AddResult(Pattern);
|
|
|
|
Results.ExitScope();
|
|
|
|
|
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
|
|
|
CodeCompletionContext::CCC_PreprocessorExpression,
|
|
|
|
Results.data(), Results.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::CodeCompletePreprocessorMacroArgument(Scope *S,
|
|
|
|
IdentifierInfo *Macro,
|
|
|
|
MacroInfo *MacroInfo,
|
|
|
|
unsigned Argument) {
|
|
|
|
// FIXME: In the future, we could provide "overload" results, much like we
|
|
|
|
// do for function calls.
|
|
|
|
|
|
|
|
CodeCompleteOrdinaryName(S,
|
2010-08-27 07:41:50 +08:00
|
|
|
S->getFnParent()? Sema::PCC_RecoveryInFunction
|
|
|
|
: Sema::PCC_Namespace);
|
2010-08-25 06:20:20 +08:00
|
|
|
}
|
|
|
|
|
2010-08-26 01:04:25 +08:00
|
|
|
void Sema::CodeCompleteNaturalLanguage() {
|
|
|
|
HandleCodeCompleteResults(this, CodeCompleter,
|
2010-08-26 01:10:00 +08:00
|
|
|
CodeCompletionContext::CCC_NaturalLanguage,
|
2010-08-26 01:04:25 +08:00
|
|
|
0, 0);
|
|
|
|
}
|
|
|
|
|
2010-08-14 06:48:40 +08:00
|
|
|
void Sema::GatherGlobalCodeCompletions(
|
2010-08-25 14:19:51 +08:00
|
|
|
llvm::SmallVectorImpl<CodeCompletionResult> &Results) {
|
2010-09-24 07:01:17 +08:00
|
|
|
ResultBuilder Builder(*this, CodeCompletionContext::CCC_Recovery);
|
2010-08-15 14:18:01 +08:00
|
|
|
if (!CodeCompleter || CodeCompleter->includeGlobals()) {
|
|
|
|
CodeCompletionDeclConsumer Consumer(Builder,
|
|
|
|
Context.getTranslationUnitDecl());
|
|
|
|
LookupVisibleDecls(Context.getTranslationUnitDecl(), LookupAnyName,
|
|
|
|
Consumer);
|
|
|
|
}
|
2010-08-14 06:48:40 +08:00
|
|
|
|
|
|
|
if (!CodeCompleter || CodeCompleter->includeMacros())
|
|
|
|
AddMacroResults(PP, Builder);
|
|
|
|
|
|
|
|
Results.clear();
|
|
|
|
Results.insert(Results.end(),
|
|
|
|
Builder.data(), Builder.data() + Builder.size());
|
|
|
|
}
|