mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
//===- CodeCompletion.cpp - Code completion implementation ----------------===//
|
||||
//===--- CodeCompletion.cpp - Code completion implementation --------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
||||
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See http://swift.org/LICENSE.txt for license information
|
||||
@@ -1326,6 +1326,7 @@ static bool isTopLevelContext(const DeclContext *DC) {
|
||||
case DeclContextKind::TopLevelCodeDecl:
|
||||
return true;
|
||||
case DeclContextKind::AbstractFunctionDecl:
|
||||
case DeclContextKind::SubscriptDecl:
|
||||
return false;
|
||||
default:
|
||||
continue;
|
||||
@@ -1584,7 +1585,7 @@ public:
|
||||
void addImportModuleNames() {
|
||||
// FIXME: Add user-defined swift modules
|
||||
SmallVector<clang::Module*, 20> Modules;
|
||||
Ctx.getVisibleTopLevelClangeModules(Modules);
|
||||
Ctx.getVisibleTopLevelClangModules(Modules);
|
||||
std::sort(Modules.begin(), Modules.end(),
|
||||
[](clang::Module* LHS , clang::Module* RHS) {
|
||||
return LHS->getTopLevelModuleName().compare_lower(
|
||||
@@ -1796,31 +1797,21 @@ public:
|
||||
addTypeAnnotation(Builder, VarType);
|
||||
}
|
||||
|
||||
void addPatternParameters(CodeCompletionResultBuilder &Builder,
|
||||
const Pattern *P) {
|
||||
if (auto *TP = dyn_cast<TuplePattern>(P)) {
|
||||
bool NeedComma = false;
|
||||
for (unsigned i = 0, end = TP->getNumElements(); i < end; ++i) {
|
||||
TuplePatternElt TupleElt = TP->getElement(i);
|
||||
if (NeedComma)
|
||||
Builder.addComma();
|
||||
NeedComma = true;
|
||||
void addParameters(CodeCompletionResultBuilder &Builder,
|
||||
const ParameterList *params) {
|
||||
bool NeedComma = false;
|
||||
for (auto ¶m : *params) {
|
||||
if (NeedComma)
|
||||
Builder.addComma();
|
||||
NeedComma = true;
|
||||
|
||||
bool HasEllipsis = TupleElt.hasEllipsis();
|
||||
Type EltT = TupleElt.getPattern()->getType();
|
||||
if (HasEllipsis)
|
||||
EltT = TupleTypeElt::getVarargBaseTy(EltT);
|
||||
Type type = param->getType();
|
||||
if (param->isVariadic())
|
||||
type = ParamDecl::getVarargBaseTy(type);
|
||||
|
||||
Builder.addCallParameter(TupleElt.getPattern()->getBoundName(),
|
||||
EltT, HasEllipsis);
|
||||
}
|
||||
return;
|
||||
Builder.addCallParameter(param->getArgumentName(), type,
|
||||
param->isVariadic());
|
||||
}
|
||||
|
||||
Type PType = P->getType();
|
||||
if (auto Parens = dyn_cast<ParenType>(PType.getPointer()))
|
||||
PType = Parens->getUnderlyingType();
|
||||
Builder.addCallParameter(P->getBoundName(), PType, /*IsVarArg*/false);
|
||||
}
|
||||
|
||||
void addPatternFromTypeImpl(CodeCompletionResultBuilder &Builder, Type T,
|
||||
@@ -1894,17 +1885,9 @@ public:
|
||||
const AbstractFunctionDecl *AFD,
|
||||
bool includeDefaultArgs = true) {
|
||||
|
||||
const TuplePattern *BodyTuple = nullptr;
|
||||
if (AFD) {
|
||||
auto BodyPatterns = AFD->getBodyParamPatterns();
|
||||
// Skip over the implicit 'self'.
|
||||
if (AFD->getImplicitSelfDecl()) {
|
||||
BodyPatterns = BodyPatterns.slice(1);
|
||||
}
|
||||
|
||||
if (!BodyPatterns.empty())
|
||||
BodyTuple = dyn_cast<TuplePattern>(BodyPatterns.front());
|
||||
}
|
||||
const ParameterList *BodyParams = nullptr;
|
||||
if (AFD)
|
||||
BodyParams = AFD->getParameterList(AFD->getImplicitSelfDecl() ? 1 : 0);
|
||||
|
||||
bool modifiedBuilder = false;
|
||||
|
||||
@@ -1941,11 +1924,10 @@ public:
|
||||
|
||||
if (NeedComma)
|
||||
Builder.addComma();
|
||||
if (BodyTuple) {
|
||||
if (BodyParams) {
|
||||
// If we have a local name for the parameter, pass in that as well.
|
||||
auto ParamPat = BodyTuple->getElement(i).getPattern();
|
||||
Builder.addCallParameter(Name, ParamPat->getBodyName(), ParamType,
|
||||
TupleElt.isVararg());
|
||||
auto name = BodyParams->get(i)->getName();
|
||||
Builder.addCallParameter(Name, name, ParamType, TupleElt.isVararg());
|
||||
} else {
|
||||
Builder.addCallParameter(Name, ParamType, TupleElt.isVararg());
|
||||
}
|
||||
@@ -1961,9 +1943,9 @@ public:
|
||||
}
|
||||
|
||||
modifiedBuilder = true;
|
||||
if (BodyTuple) {
|
||||
auto ParamPat = BodyTuple->getElement(0).getPattern();
|
||||
Builder.addCallParameter(Identifier(), ParamPat->getBodyName(), T,
|
||||
if (BodyParams) {
|
||||
auto name = BodyParams->get(0)->getName();
|
||||
Builder.addCallParameter(Identifier(), name, T,
|
||||
/*IsVarArg*/false);
|
||||
} else
|
||||
Builder.addCallParameter(Identifier(), T, /*IsVarArg*/false);
|
||||
@@ -2122,7 +2104,7 @@ public:
|
||||
// Build type annotation.
|
||||
{
|
||||
llvm::raw_svector_ostream OS(TypeStr);
|
||||
for (unsigned i = FirstIndex + 1, e = FD->getBodyParamPatterns().size();
|
||||
for (unsigned i = FirstIndex + 1, e = FD->getParameterLists().size();
|
||||
i != e; ++i) {
|
||||
ResultType->castTo<AnyFunctionType>()->getInput()->print(OS);
|
||||
ResultType = ResultType->castTo<AnyFunctionType>()->getResult();
|
||||
@@ -2254,7 +2236,7 @@ public:
|
||||
Builder.setAssociatedDecl(SD);
|
||||
setClangDeclKeywords(SD, Pairs, Builder);
|
||||
Builder.addLeftBracket();
|
||||
addPatternParameters(Builder, SD->getIndices());
|
||||
addParameters(Builder, SD->getIndices());
|
||||
Builder.addRightBracket();
|
||||
|
||||
// Add a type annotation.
|
||||
@@ -2436,7 +2418,7 @@ public:
|
||||
if (HaveDot)
|
||||
return;
|
||||
|
||||
// If instance type is type alias, showing users that the contructed
|
||||
// If instance type is type alias, showing users that the constructed
|
||||
// type is the typealias instead of the underlying type of the alias.
|
||||
Optional<Type> Result = None;
|
||||
if (auto AT = MT->getInstanceType()) {
|
||||
@@ -3265,10 +3247,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static void collectArgumentExpection(unsigned Position, bool HasName,
|
||||
ArrayRef<Type> Types, SourceLoc Loc,
|
||||
std::vector<Type> &ExpectedTypes,
|
||||
std::vector<StringRef> &ExpectedNames) {
|
||||
static void collectArgumentExpectation(unsigned Position, bool HasName,
|
||||
ArrayRef<Type> Types, SourceLoc Loc,
|
||||
std::vector<Type> &ExpectedTypes,
|
||||
std::vector<StringRef> &ExpectedNames) {
|
||||
SmallPtrSet<TypeBase *, 4> seenTypes;
|
||||
SmallPtrSet<const char *, 4> seenNames;
|
||||
|
||||
@@ -3298,8 +3280,8 @@ public:
|
||||
ArrayRef<Type> Types, SourceLoc Loc) {
|
||||
std::vector<Type> ExpectedTypes;
|
||||
std::vector<StringRef> ExpectedNames;
|
||||
collectArgumentExpection(Position, HasName, Types, Loc, ExpectedTypes,
|
||||
ExpectedNames);
|
||||
collectArgumentExpectation(Position, HasName, Types, Loc, ExpectedTypes,
|
||||
ExpectedNames);
|
||||
addArgNameCompletionResults(ExpectedNames);
|
||||
if (!ExpectedTypes.empty()) {
|
||||
setExpectedTypes(ExpectedTypes);
|
||||
@@ -3311,7 +3293,7 @@ public:
|
||||
static bool isPotentialSignatureMatch(ArrayRef<Type> TupleEles,
|
||||
ArrayRef<Type> ExprTypes,
|
||||
DeclContext *DC) {
|
||||
// Not likely to be a mactch if users provide more arguments than expected.
|
||||
// Not likely to be a match if users provide more arguments than expected.
|
||||
if (ExprTypes.size() >= TupleEles.size())
|
||||
return false;
|
||||
for (unsigned I = 0; I < ExprTypes.size(); ++ I) {
|
||||
@@ -3376,16 +3358,16 @@ public:
|
||||
}
|
||||
|
||||
static bool
|
||||
collectArgumentExpectatation(DeclContext &DC, CallExpr *CallE, Expr *CCExpr,
|
||||
std::vector<Type> &ExpectedTypes,
|
||||
std::vector<StringRef> &ExpectedNames) {
|
||||
collectArgumentExpectation(DeclContext &DC, CallExpr *CallE, Expr *CCExpr,
|
||||
std::vector<Type> &ExpectedTypes,
|
||||
std::vector<StringRef> &ExpectedNames) {
|
||||
SmallVector<Type, 2> PossibleTypes;
|
||||
unsigned Position;
|
||||
bool HasName;
|
||||
if (collectPossibleArgTypes(DC, CallE, CCExpr, PossibleTypes, Position,
|
||||
HasName, true)) {
|
||||
collectArgumentExpection(Position, HasName, PossibleTypes,
|
||||
CCExpr->getStartLoc(), ExpectedTypes, ExpectedNames);
|
||||
collectArgumentExpectation(Position, HasName, PossibleTypes,
|
||||
CCExpr->getStartLoc(), ExpectedTypes, ExpectedNames);
|
||||
return !ExpectedTypes.empty() || !ExpectedNames.empty();
|
||||
}
|
||||
return false;
|
||||
@@ -4209,7 +4191,7 @@ public:
|
||||
case ExprKind::Call: {
|
||||
std::vector<Type> PotentialTypes;
|
||||
std::vector<StringRef> ExpectedNames;
|
||||
CompletionLookup::collectArgumentExpectatation(
|
||||
CompletionLookup::collectArgumentExpectation(
|
||||
*DC, cast<CallExpr>(Parent), ParsedExpr, PotentialTypes,
|
||||
ExpectedNames);
|
||||
for (Type Ty : PotentialTypes)
|
||||
|
||||
Reference in New Issue
Block a user