Eliminate the Parameter type completely - now ParameterList is just

an overblown array of ParamDecl*'s that also keeps track of parenlocs
and has helper methods.
This commit is contained in:
Chris Lattner
2016-01-03 14:44:48 -08:00
parent a503269e2d
commit 6afe77d597
43 changed files with 362 additions and 513 deletions
-5
View File
@@ -28,7 +28,6 @@
namespace swift {
class ParameterList;
struct Parameter;
/// ASTVisitor - This is a simple visitor class for Swift expressions.
template<typename ImplClass,
@@ -164,12 +163,8 @@ public:
bool visit(ParameterList *PL) {
return static_cast<ImplClass*>(this)->visitParameterList(PL);
}
bool visit(Parameter &P) {
return static_cast<ImplClass*>(this)->visitParameter(P);
}
bool visitParameterList(ParameterList *PL) { return false; }
bool visitParameter(Parameter &P) { return false; }
};
+4 -8
View File
@@ -61,7 +61,6 @@ namespace swift {
class NameAliasType;
class EnumCaseDecl;
class EnumElementDecl;
struct Parameter;
class ParameterList;
class Pattern;
struct PrintOptions;
@@ -4198,12 +4197,6 @@ public:
/// The resulting source location will be valid if the argument name
/// was specified separately from the parameter name.
SourceLoc getArgumentNameLoc() const { return ArgumentNameLoc; }
/// Return the Parameter value corresponding to this ParamDecl.
Parameter &getParameter();
const Parameter &getParameter() const {
return const_cast<ParamDecl*>(this)->getParameter();
}
TypeLoc &getTypeLoc() { return typeLoc; }
TypeLoc getTypeLoc() const { return typeLoc; }
@@ -4631,7 +4624,10 @@ public:
///
/// Note that some functions don't have an implicit 'self' decl, for example,
/// free functions. In this case nullptr is returned.
ParamDecl *getImplicitSelfDecl() const;
const ParamDecl *getImplicitSelfDecl() const {
return const_cast<AbstractFunctionDecl*>(this)->getImplicitSelfDecl();
}
ParamDecl *getImplicitSelfDecl();
/// \brief Retrieve the set of parameters to a generic function, or null if
/// this function is not generic.
+14 -78
View File
@@ -18,78 +18,14 @@
#ifndef SWIFT_AST_PARAMETER_H
#define SWIFT_AST_PARAMETER_H
#include "swift/AST/TypeLoc.h"
#include "swift/AST/Decl.h"
#include "swift/Basic/OptionSet.h"
namespace swift {
class ParamDecl;
class ExprHandle;
/// This describes a single parameter, including such feats as:
///
/// a b : Int //< Differing internal vs external name.
/// inout a : Int //< inout parameter.
/// @autoclosure a : T //< Parameter attribute.
/// a : Int = 42 //< Default value.
/// a : Int... //< Varargs parameter.
///
/// A parameter is stored as ParamDecls with additional information in the
/// Parameter struct to represent source information as well as extra semantics.
///
struct Parameter {
/// The decl keeps track of the internal and external parameter name, as well
/// as the parameter attributes.
ParamDecl *decl;
bool hasDefaultValue() const {
return decl->getDefaultValue() != nullptr;
}
void setDefaultValue(ExprHandle *H) {
decl->setDefaultValue(H);
}
ExprHandle *getDefaultValue() const {
return decl->getDefaultValue();
}
/// Whether or not this parameter is varargs.
bool isVariadic() const { return decl->isVariadic(); }
void setVariadic(bool value = true) { decl->setVariadic(value); }
/// Remove the type of this varargs element designator, without the array
/// type wrapping it. A parameter like "Int..." will have formal parameter
/// type of "[Int]" and this returns "Int".
static Type getVarargBaseTy(Type VarArgT);
/// Remove the type of this varargs element designator, without the array
/// type wrapping it.
Type getVarargBaseTy() const {
assert(isVariadic());
return getVarargBaseTy(decl->getType());
}
/// Create a simple parameter without location information.
static Parameter withoutLoc(ParamDecl *decl) {
Parameter result;
result.decl = decl;
return result;
}
/// Return the full source range of this parameter.
SourceRange getSourceRange() const;
SourceLoc getStartLoc() const { return getSourceRange().Start; }
SourceLoc getEndLoc() const { return getSourceRange().End; }
void dump() const;
void dump(raw_ostream &OS, unsigned Indent = 0) const;
// void print(raw_ostream &OS) const;
};
/// This describes a list of parameters. Each parameter descriptor is tail
/// allocated onto this list.
class alignas(alignof(Parameter)) ParameterList {
class alignas(alignof(ParamDecl*)) ParameterList {
void *operator new(size_t Bytes) throw() = delete;
void operator delete(void *Data) throw() = delete;
void *operator new(size_t Bytes, void *Mem) throw() = delete;
@@ -105,13 +41,13 @@ class alignas(alignof(Parameter)) ParameterList {
public:
/// Create a parameter list with the specified parameters.
static ParameterList *create(const ASTContext &C, SourceLoc LParenLoc,
ArrayRef<Parameter> params,
ArrayRef<ParamDecl*> params,
SourceLoc RParenLoc);
/// Create a parameter list with the specified parameters, with no location
/// info for the parens.
static ParameterList *create(const ASTContext &C,
ArrayRef<Parameter> params) {
ArrayRef<ParamDecl*> params) {
return create(C, SourceLoc(), params, SourceLoc());
}
@@ -124,7 +60,7 @@ public:
/// Create a parameter list for a single parameter lacking location info.
static ParameterList *createWithoutLoc(ParamDecl *decl) {
return create(decl->getASTContext(), Parameter::withoutLoc(decl));
return create(decl->getASTContext(), decl);
}
/// Create an implicit 'self' decl for a method in the specified decl context.
@@ -141,19 +77,19 @@ public:
SourceLoc getLParenLoc() const { return LParenLoc; }
SourceLoc getRParenLoc() const { return RParenLoc; }
typedef MutableArrayRef<Parameter>::iterator iterator;
typedef ArrayRef<Parameter>::iterator const_iterator;
typedef MutableArrayRef<ParamDecl*>::iterator iterator;
typedef ArrayRef<ParamDecl*>::iterator const_iterator;
iterator begin() { return getArray().begin(); }
iterator end() { return getArray().end(); }
const_iterator begin() const { return getArray().begin(); }
const_iterator end() const { return getArray().end(); }
MutableArrayRef<Parameter> getArray() {
auto Ptr = reinterpret_cast<Parameter*>(this + 1);
MutableArrayRef<ParamDecl*> getArray() {
auto Ptr = reinterpret_cast<ParamDecl**>(this + 1);
return { Ptr, numParameters };
}
ArrayRef<Parameter> getArray() const {
auto Ptr = reinterpret_cast<const Parameter*>(this + 1);
ArrayRef<ParamDecl*> getArray() const {
auto Ptr = reinterpret_cast<ParamDecl*const*>(this + 1);
return { Ptr, numParameters };
}
@@ -161,16 +97,16 @@ public:
return numParameters;
}
const Parameter &get(unsigned i) const {
const ParamDecl *get(unsigned i) const {
return getArray()[i];
}
Parameter &get(unsigned i) {
ParamDecl *&get(unsigned i) {
return getArray()[i];
}
const Parameter &operator[](unsigned i) const { return get(i); }
Parameter &operator[](unsigned i) { return get(i); }
const ParamDecl *operator[](unsigned i) const { return get(i); }
ParamDecl *&operator[](unsigned i) { return get(i); }
/// Change the DeclContext of any contained parameters to the specified
/// DeclContext.
+2 -2
View File
@@ -3443,8 +3443,8 @@ DeclName::DeclName(ASTContext &C, Identifier baseName,
ParameterList *paramList) {
SmallVector<Identifier, 4> names;
for (auto &P : *paramList)
names.push_back(P.decl->getArgumentName());
for (auto P : *paramList)
names.push_back(P->getArgumentName());
initialize(C, baseName, names);
}
+15 -40
View File
@@ -473,7 +473,7 @@ namespace {
OS << ")";
}
void printDeclName(ValueDecl *D) {
void printDeclName(const ValueDecl *D) {
if (D->getFullName())
OS << '\"' << D->getFullName() << '\"';
else
@@ -653,15 +653,8 @@ namespace {
}
}
void visitParamDecl(ParamDecl *VD) {
printCommon(VD, "param_decl");
if (!VD->isLet())
OS << " var";
if (VD->getName() != VD->getArgumentName()) {
OS << " argument_name=";
printName(OS, VD->getArgumentName());
}
OS << ')';
void visitParamDecl(ParamDecl *PD) {
printParameter(PD);
}
void visitEnumCaseDecl(EnumCaseDecl *ECD) {
@@ -773,27 +766,27 @@ namespace {
}
}
void printParameter(const Parameter &P) {
void printParameter(const ParamDecl *P) {
OS.indent(Indent) << "(parameter ";
printDeclName(P.decl);
if (!P.decl->getArgumentName().empty())
OS << " apiName=" << P.decl->getArgumentName();
printDeclName(P);
if (!P->getArgumentName().empty())
OS << " apiName=" << P->getArgumentName();
OS << " type=";
if (P.decl->hasType()) {
if (P->hasType()) {
OS << '\'';
P.decl->getType().print(OS);
P->getType().print(OS);
OS << '\'';
} else
OS << "<null type>";
if (!P.decl->isLet())
if (!P->isLet())
OS << " mutable";
if (P.isVariadic())
if (P->isVariadic())
OS << " variadic";
switch (P.decl->getDefaultArgumentKind()) {
switch (P->getDefaultArgumentKind()) {
case DefaultArgumentKind::None: break;
case DefaultArgumentKind::Column:
printField("default_arg", "__COLUMN__");
@@ -818,7 +811,7 @@ namespace {
break;
}
if (auto init = P.getDefaultValue()) {
if (auto init = P->getDefaultValue()) {
OS << " expression=\n";
printRec(init->getExpr());
}
@@ -996,24 +989,6 @@ namespace {
};
} // end anonymous namespace.
void Parameter::dump() const {
dump(llvm::errs(), 0);
}
void Parameter::dump(raw_ostream &OS, unsigned Indent) const {
llvm::Optional<llvm::SaveAndRestore<bool>> X;
// Make sure to print type variables if we can get to ASTContext.
if (decl) {
X.emplace(llvm::SaveAndRestore<bool>(decl->getASTContext().LangOpts.DebugConstraintSolver,
true));
}
PrintDecl(OS, Indent).printParameter(*this);
llvm::errs() << '\n';
}
void ParameterList::dump() const {
dump(llvm::errs(), 0);
}
@@ -1022,8 +997,8 @@ void ParameterList::dump(raw_ostream &OS, unsigned Indent) const {
llvm::Optional<llvm::SaveAndRestore<bool>> X;
// Make sure to print type variables if we can get to ASTContext.
if (size() != 0 && get(0).decl) {
auto &ctx = get(0).decl->getASTContext();
if (size() != 0 && get(0)) {
auto &ctx = get(0)->getASTContext();
X.emplace(llvm::SaveAndRestore<bool>(ctx.LangOpts.DebugConstraintSolver,
true));
}
+17 -17
View File
@@ -471,7 +471,7 @@ private:
/// \returns true if anything was printed.
bool printASTNodes(const ArrayRef<ASTNode> &Elements, bool NeedIndent = true);
void printOneParameter(const Parameter &param, bool Curried,
void printOneParameter(const ParamDecl *param, bool Curried,
bool ArgNameIsAPIByDefault);
void printParameterList(ParameterList *PL, bool isCurried,
@@ -1540,12 +1540,12 @@ void PrintAST::visitParamDecl(ParamDecl *decl) {
return visitVarDecl(decl);
}
void PrintAST::printOneParameter(const Parameter &param, bool Curried,
void PrintAST::printOneParameter(const ParamDecl *param, bool Curried,
bool ArgNameIsAPIByDefault) {
auto printArgName = [&]() {
// Print argument name.
auto ArgName = param.decl->getArgumentName();
auto BodyName = param.decl->getName();
auto ArgName = param->getArgumentName();
auto BodyName = param->getName();
switch (Options.ArgAndParamPrinting) {
case PrintOptions::ArgAndParamPrintingMode::ArgumentOnly:
Printer.printName(ArgName, PrintNameContext::FunctionParameter);
@@ -1572,7 +1572,7 @@ void PrintAST::printOneParameter(const Parameter &param, bool Curried,
Printer << ": ";
};
auto TheTypeLoc = param.decl->getTypeLoc();
auto TheTypeLoc = param->getTypeLoc();
if (TheTypeLoc.getTypeRepr()) {
// If the outer typeloc is an InOutTypeRepr, print the 'inout' before the
// subpattern.
@@ -1587,8 +1587,8 @@ void PrintAST::printOneParameter(const Parameter &param, bool Curried,
Printer << "inout ";
}
} else {
if (param.decl->hasType())
TheTypeLoc = TypeLoc::withoutLoc(param.decl->getType());
if (param->hasType())
TheTypeLoc = TypeLoc::withoutLoc(param->getType());
if (Type T = TheTypeLoc.getType()) {
if (auto *IOT = T->getAs<InOutType>()) {
@@ -1600,8 +1600,8 @@ void PrintAST::printOneParameter(const Parameter &param, bool Curried,
// If the parameter is autoclosure, or noescape, print it. This is stored
// on the type of the decl, not on the typerepr.
if (param.decl->hasType()) {
auto bodyCanType = param.decl->getType()->getCanonicalType();
if (param->hasType()) {
auto bodyCanType = param->getType()->getCanonicalType();
if (auto patternType = dyn_cast<AnyFunctionType>(bodyCanType)) {
switch (patternType->isAutoClosure()*2 + patternType->isNoEscape()) {
case 0: break; // neither.
@@ -1636,14 +1636,14 @@ void PrintAST::printOneParameter(const Parameter &param, bool Curried,
// If the parameter is variadic, we will print the "..." after it, but we have
// to strip off the added array type.
if (param.isVariadic() && TheTypeLoc.getType()) {
if (param->isVariadic() && TheTypeLoc.getType()) {
if (auto *BGT = TheTypeLoc.getType()->getAs<BoundGenericType>())
TheTypeLoc.setType(BGT->getGenericArgs()[0]);
}
printTypeLoc(TheTypeLoc);
if (param.isVariadic())
if (param->isVariadic())
Printer << "...";
// After printing the type, we need to restore what the option used to be.
@@ -1654,11 +1654,11 @@ void PrintAST::printOneParameter(const Parameter &param, bool Curried,
if (Options.PrintDefaultParameterPlaceholder &&
param.decl->isDefaultArgument()) {
param->isDefaultArgument()) {
// For Clang declarations, figure out the default we're using.
auto AFD = dyn_cast<AbstractFunctionDecl>(param.decl->getDeclContext());
if (AFD && AFD->getClangDecl() && param.decl->hasType()) {
auto CurrType = param.decl->getType();
auto AFD = dyn_cast<AbstractFunctionDecl>(param->getDeclContext());
if (AFD && AFD->getClangDecl() && param->hasType()) {
auto CurrType = param->getType();
Printer << " = " << CurrType->getInferredDefaultArgString();
} else {
// Use placeholder anywhere else.
@@ -1765,8 +1765,8 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
Printer << (decl->isSetter() ? "set" : "willSet");
auto params = decl->getParameterLists().back();
if (params->size() != 0 && !params->get(0).decl->isImplicit()) {
auto Name = params->get(0).decl->getName();
if (params->size() != 0 && !params->get(0)->isImplicit()) {
auto Name = params->get(0)->getName();
if (!Name.empty()) {
Printer << "(";
Printer.printName(Name);
+5 -9
View File
@@ -123,10 +123,6 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
return inherited::visit(PL);
}
bool visit(Parameter &P) {
return inherited::visit(P);
}
//===--------------------------------------------------------------------===//
// Decls
//===--------------------------------------------------------------------===//
@@ -845,18 +841,18 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
if (!Walker.walkToParameterListPre(PL))
return false;
for (auto &P : *PL) {
for (auto P : *PL) {
// Walk each parameter's decl and typeloc and default value.
if (doIt(P.decl))
if (doIt(P))
return true;
// Don't walk into the type if the decl is implicit, or if the type is
// implicit.
if (!P.decl->isImplicit() && !P.decl->isTypeLocImplicit() &&
doIt(P.decl->getTypeLoc()))
if (!P->isImplicit() && !P->isTypeLocImplicit() &&
doIt(P->getTypeLoc()))
return true;
if (auto *E = P.getDefaultValue()) {
if (auto *E = P->getDefaultValue()) {
auto res = doIt(E->getExpr());
if (!res) return true;
E->setExpr(res, E->alreadyChecked());
+2 -2
View File
@@ -1394,8 +1394,8 @@ bool ArchetypeBuilder::inferRequirements(ParameterList *params,
return false;
bool hadError = false;
for (auto &P : *params)
hadError |= inferRequirements(P.decl->getTypeLoc(), genericParams);
for (auto P : *params)
hadError |= inferRequirements(P->getTypeLoc(), genericParams);
return hadError;
}
+4 -4
View File
@@ -146,14 +146,14 @@ getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType,
Module *M = Context.TheBuiltinModule;
DeclContext *DC = &M->getMainFile(FileUnitKind::Builtin);
SmallVector<Parameter, 4> params;
SmallVector<ParamDecl*, 4> params;
for (Type argType : argTypes) {
auto PD = new (Context) ParamDecl(/*IsLet*/true, SourceLoc(),
Identifier(), SourceLoc(),
Identifier(), argType,
DC);
PD->setImplicit();
params.push_back(Parameter::withoutLoc(PD));
params.push_back(PD);
}
auto *paramList = ParameterList::create(Context, params);
@@ -204,13 +204,13 @@ getBuiltinGenericFunction(Identifier Id,
Module *M = Context.TheBuiltinModule;
DeclContext *DC = &M->getMainFile(FileUnitKind::Builtin);
SmallVector<Parameter, 4> params;
SmallVector<ParamDecl*, 4> params;
for (auto paramType : ArgBodyTypes) {
auto PD = new (Context) ParamDecl(/*IsLet*/true, SourceLoc(),
Identifier(), SourceLoc(),
Identifier(), paramType, DC);
PD->setImplicit();
params.push_back(Parameter::withoutLoc(PD));
params.push_back(PD);
}
+52 -32
View File
@@ -401,7 +401,7 @@ bool Decl::isPrivateStdlibDecl(bool whitelistProtocols) const {
auto hasInternalParameter = [](const ParameterList *params) -> bool {
for (auto param : *params) {
if (param.decl->hasName() && param.decl->getNameStr().startswith("_"))
if (param->hasName() && param->getNameStr().startswith("_"))
return true;
}
return false;
@@ -3154,8 +3154,7 @@ SourceRange VarDecl::getSourceRange() const {
SourceRange VarDecl::getTypeSourceRangeForDiagnostics() const {
// For a parameter, map back to it's parameter to get the TypeLoc.
if (auto *PD = dyn_cast<ParamDecl>(this)) {
auto &P = PD->getParameter();
if (auto typeRepr = P.decl->getTypeLoc().getTypeRepr())
if (auto typeRepr = PD->getTypeLoc().getTypeRepr())
return typeRepr->getSourceRange();
}
@@ -3359,24 +3358,6 @@ ParamDecl::ParamDecl(ParamDecl *PD)
defaultArgumentKind(PD->defaultArgumentKind) {
}
Parameter &ParamDecl::getParameter() {
ArrayRef<ParameterList*> paramLists;
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(getDeclContext()))
paramLists = AFD->getParameterLists();
else if (auto *CE = dyn_cast<ClosureExpr>(getDeclContext()))
paramLists = CE->getParameters();
else
paramLists = cast<SubscriptDecl>(getDeclContext())->getIndices();
for (auto paramList : paramLists)
for (auto &param : *paramList)
if (param.decl == this)
return param;
llvm_unreachable("ParamDecl has no associated Parameter value?");
}
/// \brief Retrieve the type of 'self' for the given context.
static Type getSelfTypeForContext(DeclContext *dc) {
@@ -3422,12 +3403,52 @@ ParamDecl *ParamDecl::createSelf(SourceLoc loc, DeclContext *DC,
return selfDecl;
}
/// Return the full source range of this parameter.
SourceRange ParamDecl::getSourceRange() const {
return getParameter().getSourceRange();
SourceRange range;
SourceLoc APINameLoc = getArgumentNameLoc();
SourceLoc nameLoc = getNameLoc();
if (APINameLoc.isValid() && nameLoc.isInvalid())
range = APINameLoc;
else if (APINameLoc.isInvalid() && nameLoc.isValid())
range = nameLoc;
else
range = SourceRange(APINameLoc, nameLoc);
if (range.isInvalid()) return range;
// It would be nice to extend the front of the range to show where inout is,
// but we don't have that location info. Extend the back of the range to the
// location of the default argument, or the typeloc if they are valid.
if (auto expr = getDefaultValue()) {
auto endLoc = expr->getExpr()->getEndLoc();
if (endLoc.isValid())
return SourceRange(range.Start, endLoc);
}
// If the typeloc has a valid location, use it to end the range.
if (auto typeRepr = getTypeLoc().getTypeRepr()) {
auto endLoc = typeRepr->getEndLoc();
if (endLoc.isValid())
return SourceRange(range.Start, endLoc);
}
// Otherwise, just return the info we have about the parameter.
return range;
}
Type ParamDecl::getVarargBaseTy(Type VarArgT) {
return Parameter::getVarargBaseTy(VarArgT);
TypeBase *T = VarArgT.getPointer();
if (ArraySliceType *AT = dyn_cast<ArraySliceType>(T))
return AT->getBaseType();
if (BoundGenericType *BGT = dyn_cast<BoundGenericType>(T)) {
// It's the stdlib Array<T>.
return BGT->getGenericArgs()[0];
}
assert(isa<ErrorType>(T));
return T;
}
/// Determine whether the given Swift type is an integral type, i.e.,
@@ -3654,15 +3675,14 @@ Type AbstractFunctionDecl::computeInterfaceSelfType(bool isInitializingCtor) {
///
/// Note that some functions don't have an implicit 'self' decl, for example,
/// free functions. In this case nullptr is returned.
ParamDecl *AbstractFunctionDecl::getImplicitSelfDecl() const {
ParamDecl *AbstractFunctionDecl::getImplicitSelfDecl() {
auto paramLists = getParameterLists();
if (paramLists.empty())
return nullptr;
// "self" is always the first parameter list.
if (paramLists[0]->size() == 1 &&
paramLists[0]->get(0).decl->isSelfParameter())
return paramLists[0]->get(0).decl;
if (paramLists[0]->size() == 1 && paramLists[0]->get(0)->isSelfParameter())
return paramLists[0]->get(0);
return nullptr;
}
@@ -3679,8 +3699,8 @@ AbstractFunctionDecl::getDefaultArg(unsigned Index) const {
for (auto paramList : paramLists) {
if (Index < paramList->size()) {
auto &param = paramList->get(Index);
return { param.decl->getDefaultArgumentKind(), param.decl->getType() };
auto param = paramList->get(Index);
return { param->getDefaultArgumentKind(), param->getType() };
}
Index -= paramList->size();
@@ -4016,7 +4036,7 @@ bool FuncDecl::isUnaryOperator() const {
= getDeclContext()->isProtocolOrProtocolExtensionContext() ? 1 : 0;
auto *params = getParameterList(opArgIndex);
return params->size() == 1 && !params->get(0).isVariadic();
return params->size() == 1 && !params->get(0)->isVariadic();
}
bool FuncDecl::isBinaryOperator() const {
@@ -4027,7 +4047,7 @@ bool FuncDecl::isBinaryOperator() const {
= getDeclContext()->isProtocolOrProtocolExtensionContext() ? 1 : 0;
auto *params = getParameterList(opArgIndex);
return params->size() == 2 && !params->get(1).isVariadic();
return params->size() == 2 && !params->get(1)->isVariadic();
}
ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
@@ -4079,7 +4099,7 @@ bool ConstructorDecl::isObjCZeroParameterWithLongSelector() const {
if (params->size() != 1)
return false;
return params->get(0).decl->getType()->isVoid();
return params->get(0)->getType()->isVoid();
}
DestructorDecl::DestructorDecl(Identifier NameHack, SourceLoc DestructorLoc,
+1 -1
View File
@@ -719,7 +719,7 @@ void swift::lookupVisibleDecls(VisibleDeclConsumer &Consumer,
// Constructors and destructors don't have 'self' in parameter patterns.
if (isa<ConstructorDecl>(AFD) || isa<DestructorDecl>(AFD))
Consumer.foundDecl(AFD->getImplicitSelfDecl(),
Consumer.foundDecl(const_cast<ParamDecl*>(AFD->getImplicitSelfDecl()),
DeclVisibilityKind::FunctionParameter);
if (AFD->getExtensionType()) {
+2 -3
View File
@@ -92,9 +92,8 @@ public:
}
void checkParameterList(const ParameterList *params) {
for (auto &param : *params) {
checkValueDecl(param.decl,
DeclVisibilityKind::FunctionParameter);
for (auto param : *params) {
checkValueDecl(param, DeclVisibilityKind::FunctionParameter);
}
}
+20 -71
View File
@@ -21,72 +21,23 @@
#include "swift/AST/ExprHandle.h"
using namespace swift;
/// Return the full source range of this parameter.
SourceRange Parameter::getSourceRange() const {
SourceRange range;
SourceLoc APINameLoc = decl->getArgumentNameLoc();
SourceLoc nameLoc = decl->getNameLoc();
if (APINameLoc.isValid() && nameLoc.isInvalid())
range = APINameLoc;
else if (APINameLoc.isInvalid() && nameLoc.isValid())
range = nameLoc;
else
range = SourceRange(APINameLoc, nameLoc);
if (range.isInvalid()) return range;
// It would be nice to extend the front of the range to show where inout is,
// but we don't have that location info. Extend the back of the range to the
// location of the default argument, or the typeloc if they are valid.
if (auto expr = getDefaultValue()) {
auto endLoc = expr->getExpr()->getEndLoc();
if (endLoc.isValid())
return SourceRange(range.Start, endLoc);
}
// If the typeloc has a valid location, use it to end the range.
if (auto typeRepr = decl->getTypeLoc().getTypeRepr()) {
auto endLoc = typeRepr->getEndLoc();
if (endLoc.isValid())
return SourceRange(range.Start, endLoc);
}
// Otherwise, just return the info we have about the parameter.
return range;
}
Type Parameter::getVarargBaseTy(Type VarArgT) {
TypeBase *T = VarArgT.getPointer();
if (ArraySliceType *AT = dyn_cast<ArraySliceType>(T))
return AT->getBaseType();
if (BoundGenericType *BGT = dyn_cast<BoundGenericType>(T)) {
// It's the stdlib Array<T>.
return BGT->getGenericArgs()[0];
}
assert(isa<ErrorType>(T));
return T;
}
/// TODO: unique and reuse the () parameter list in ASTContext, it is common to
/// many methods. Other parameter lists cannot be uniqued because the decls
/// within them are always different anyway (they have different DeclContext's).
ParameterList *
ParameterList::create(const ASTContext &C, SourceLoc LParenLoc,
ArrayRef<Parameter> params, SourceLoc RParenLoc) {
ArrayRef<ParamDecl*> params, SourceLoc RParenLoc) {
assert(LParenLoc.isValid() == RParenLoc.isValid() &&
"Either both paren locs are valid or neither are");
auto byteSize = sizeof(ParameterList)+params.size()*sizeof(Parameter);
auto byteSize = sizeof(ParameterList)+params.size()*sizeof(ParamDecl*);
auto rawMem = C.Allocate(byteSize, alignof(ParameterList));
// Placement initialize the ParameterList and the Parameter's.
auto PL = ::new (rawMem) ParameterList(LParenLoc, params.size(), RParenLoc);
for (size_t i = 0, e = params.size(); i != e; ++i)
::new (&PL->get(i)) Parameter(params[i]);
::new (&PL->get(i)) ParamDecl*(params[i]);
return PL;
}
@@ -101,14 +52,14 @@ ParameterList::create(const ASTContext &C, SourceLoc LParenLoc,
ParameterList *ParameterList::createSelf(SourceLoc loc, DeclContext *DC,
bool isStaticMethod, bool isInOut) {
auto *PD = ParamDecl::createSelf(loc, DC, isStaticMethod, isInOut);
return create(DC->getASTContext(), Parameter::withoutLoc(PD));
return create(DC->getASTContext(), PD);
}
/// Change the DeclContext of any contained parameters to the specified
/// DeclContext.
void ParameterList::setDeclContextOfParamDecls(DeclContext *DC) {
for (auto &P : *this)
P.decl->setDeclContext(DC);
for (auto P : *this)
P->setDeclContext(DC);
}
@@ -121,26 +72,24 @@ ParameterList *ParameterList::clone(const ASTContext &C,
if (size() == 0)
return const_cast<ParameterList*>(this);
SmallVector<Parameter, 8> params(begin(), end());
SmallVector<ParamDecl*, 8> params(begin(), end());
// Remap the ParamDecls inside of the ParameterList.
for (auto &param : params) {
auto decl = param.decl;
param.decl = new (C) ParamDecl(decl);
for (auto &decl : params) {
decl = new (C) ParamDecl(decl);
if (options & Implicit)
param.decl->setImplicit();
decl->setImplicit();
// If the argument isn't named, and we're cloning for an inherited
// constructor, give the parameter a name so that silgen will produce a
// value for it.
if (decl->getName().empty() && (options & Inherited))
param.decl->setName(C.getIdentifier("argument"));
decl->setName(C.getIdentifier("argument"));
// If we're inheriting a default argument, mark it as such.
if (param.decl->isDefaultArgument() && (options & Inherited)) {
param.decl->setDefaultArgumentKind(DefaultArgumentKind::Inherited);
param.decl->setDefaultValue(nullptr);
if (decl->isDefaultArgument() && (options & Inherited)) {
decl->setDefaultArgumentKind(DefaultArgumentKind::Inherited);
decl->setDefaultValue(nullptr);
}
}
@@ -155,12 +104,12 @@ Type ParameterList::getType(const ASTContext &C) const {
SmallVector<TupleTypeElt, 8> argumentInfo;
for (auto &P : *this) {
if (!P.decl->hasType()) return Type();
for (auto P : *this) {
if (!P->hasType()) return Type();
argumentInfo.push_back({
P.decl->getType(), P.decl->getArgumentName(),
P.decl->getDefaultArgumentKind(), P.decl->isVariadic()
P->getType(), P->getArgumentName(),
P->getDefaultArgumentKind(), P->isVariadic()
});
}
@@ -192,8 +141,8 @@ SourceRange ParameterList::getSourceRange() const {
// Otherwise, try the first and last parameter.
if (size() != 0) {
auto Start = get(0).getStartLoc();
auto End = getArray().back().getEndLoc();
auto Start = get(0)->getStartLoc();
auto End = getArray().back()->getEndLoc();
if (Start.isValid() && End.isValid())
return { Start, End };
}
+1 -1
View File
@@ -2139,7 +2139,7 @@ struct ASTNodeBase {};
auto &param = firstParams->get(i);
if (checkParamNames &&
param.decl->getArgumentName() != paramNames[i]) {
param->getArgumentName() != paramNames[i]) {
Out << "Function full name doesn't match variable name\n";
AFD->dump(Out);
abort();
+15 -15
View File
@@ -643,7 +643,7 @@ makeUnionFieldAccessors(ClangImporter::Implementation &Impl,
auto inoutSelf = new (C) InOutExpr(SourceLoc(), inoutSelfRef,
InOutType::get(importedUnionDecl->getType()), /*implicit*/ true);
auto newValueDecl = setterDecl->getParameterList(1)->get(0).decl;
auto newValueDecl = setterDecl->getParameterList(1)->get(0);
auto newValueRef = new (C) DeclRefExpr(newValueDecl, SourceLoc(),
/*implicit*/ true);
@@ -1593,7 +1593,7 @@ namespace {
/*static*/false, /*inout*/true);
// Construct the set of parameters from the list of members.
SmallVector<Parameter, 8> valueParameters;
SmallVector<ParamDecl*, 8> valueParameters;
for (auto var : members) {
Identifier argName = wantCtorParamNames ? var->getName()
: Identifier();
@@ -1601,7 +1601,7 @@ namespace {
SourceLoc(), argName,
SourceLoc(), var->getName(),
var->getType(), structDecl);
valueParameters.push_back(Parameter::withoutLoc(param));
valueParameters.push_back(param);
}
// self & param.
@@ -1652,7 +1652,7 @@ namespace {
/*Implicit=*/true);
// Construct right-hand side.
auto rhs = new (context) DeclRefExpr(valueParameters[i].decl,
auto rhs = new (context) DeclRefExpr(valueParameters[i],
SourceLoc(),
/*Implicit=*/true);
@@ -3518,7 +3518,7 @@ namespace {
/// Build a declaration for an Objective-C subscript getter.
FuncDecl *buildSubscriptGetterDecl(const FuncDecl *getter, Type elementTy,
DeclContext *dc, Parameter index) {
DeclContext *dc, ParamDecl *index) {
auto &context = Impl.SwiftContext;
auto loc = getter->getLoc();
@@ -3558,7 +3558,7 @@ namespace {
/// Build a declaration for an Objective-C subscript setter.
FuncDecl *buildSubscriptSetterDecl(const FuncDecl *setter, Type elementTy,
DeclContext *dc, Parameter index) {
DeclContext *dc, ParamDecl *index) {
auto &context = Impl.SwiftContext;
auto loc = setter->getLoc();
@@ -3576,12 +3576,12 @@ namespace {
auto paramVarDecl = new (context) ParamDecl(/*isLet=*/false, SourceLoc(),
Identifier(), loc,
valueIndex->get(0).decl->getName(),
valueIndex->get(0)->getName(),
elementTy, dc);
auto valueIndicesPL = ParameterList::create(context, {
Parameter::withoutLoc(paramVarDecl),
paramVarDecl,
index
});
@@ -3622,13 +3622,13 @@ namespace {
}
/// Retrieve the element type and of a subscript setter.
std::pair<Type, Parameter>
std::pair<Type, ParamDecl *>
decomposeSubscriptSetter(FuncDecl *setter) {
auto *PL = setter->getParameterList(1);
if (PL->size() != 2)
return { nullptr, Parameter() };
return { nullptr, nullptr };
return { PL->get(0).decl->getType(), PL->get(1) };
return { PL->get(0)->getType(), PL->get(1) };
}
/// Rectify the (possibly different) types determined by the
@@ -3822,7 +3822,7 @@ namespace {
}
// Find the getter indices and make sure they match.
Parameter getterIndex;
ParamDecl *getterIndex;
{
auto params = getter->getParameterList(1);
if (params->size() != 1)
@@ -3844,7 +3844,7 @@ namespace {
};
// If we have a setter, rectify it with the getter.
Parameter setterIndex;
ParamDecl *setterIndex;
bool getterAndSetterInSameType = false;
if (setter) {
// Whether there is an existing read-only subscript for which
@@ -3879,7 +3879,7 @@ namespace {
// Make sure that the index types are equivalent.
// FIXME: Rectify these the same way we do for element types.
if (!setterIndex.decl->getType()->isEqual(getterIndex.decl->getType())){
if (!setterIndex->getType()->isEqual(getterIndex->getType())) {
// If there is an existing subscript operation, we're done.
if (existingSubscript)
return decl == getter ? existingSubscript : nullptr;
@@ -3887,7 +3887,7 @@ namespace {
// Otherwise, just forget we had a setter.
// FIXME: This feels very, very wrong.
setter = nullptr;
setterIndex = Parameter();
setterIndex = nullptr;
}
// If there is an existing subscript within this context, we
+8 -9
View File
@@ -1377,7 +1377,7 @@ importFunctionType(const clang::FunctionDecl *clangDecl,
return Type();
// Import the parameters.
SmallVector<Parameter, 4> parameters;
SmallVector<ParamDecl*, 4> parameters;
unsigned index = 0;
llvm::SmallBitVector nonNullArgs = getNonNullArgs(clangDecl, params);
ArrayRef<Identifier> argNames = name.getArgumentNames();
@@ -1442,7 +1442,7 @@ importFunctionType(const clang::FunctionDecl *clangDecl,
bodyVar->getAttrs().add(
new (SwiftContext) NoEscapeAttr(/*IsImplicit=*/false));
parameters.push_back(Parameter::withoutLoc(bodyVar));
parameters.push_back(bodyVar);
++index;
}
@@ -1451,13 +1451,12 @@ importFunctionType(const clang::FunctionDecl *clangDecl,
auto paramTy = BoundGenericType::get(SwiftContext.getArrayDecl(), Type(),
{SwiftContext.getAnyDecl()->getDeclaredType()});
auto name = SwiftContext.getIdentifier("varargs");
auto bodyVar = new (SwiftContext) ParamDecl(true, SourceLoc(),
auto param = new (SwiftContext) ParamDecl(true, SourceLoc(),
Identifier(),
SourceLoc(), name, paramTy,
ImportedHeaderUnit);
auto param = Parameter::withoutLoc(bodyVar);
param.setVariadic();
param->setVariadic();
parameters.push_back(param);
}
@@ -2068,7 +2067,7 @@ Type ClangImporter::Implementation::importMethodType(
llvm::SmallBitVector nonNullArgs = getNonNullArgs(clangDecl, params);
// Import the parameters.
SmallVector<Parameter, 4> swiftParams;
SmallVector<ParamDecl*, 4> swiftParams;
auto addEmptyTupleParameter = [&](Identifier argName) {
// It doesn't actually matter which DeclContext we use, so just
@@ -2078,7 +2077,7 @@ Type ClangImporter::Implementation::importMethodType(
SourceLoc(), argName,
SourceLoc(), argName, type,
ImportedHeaderUnit);
swiftParams.push_back(Parameter::withoutLoc(var));
swiftParams.push_back(var);
};
// Determine the number of parameters.
@@ -2198,7 +2197,7 @@ Type ClangImporter::Implementation::importMethodType(
}
// Set up the parameter info.
auto paramInfo = Parameter::withoutLoc(bodyVar);
auto paramInfo = bodyVar;
// Determine whether we have a default argument.
if (InferDefaultArguments &&
@@ -2212,7 +2211,7 @@ Type ClangImporter::Implementation::importMethodType(
param->getType(), optionalityOfParam,
methodName.getBaseName(), numEffectiveParams,
isLastParameter))
paramInfo.decl->setDefaultArgumentKind(DefaultArgumentKind::Normal);
paramInfo->setDefaultArgumentKind(DefaultArgumentKind::Normal);
}
swiftParams.push_back(paramInfo);
}
+7 -7
View File
@@ -1805,12 +1805,12 @@ public:
Builder.addComma();
NeedComma = true;
Type type = param.decl->getType();
if (param.isVariadic())
type = Parameter::getVarargBaseTy(type);
Type type = param->getType();
if (param->isVariadic())
type = ParamDecl::getVarargBaseTy(type);
Builder.addCallParameter(param.decl->getArgumentName(), type,
param.isVariadic());
Builder.addCallParameter(param->getArgumentName(), type,
param->isVariadic());
}
}
@@ -1926,7 +1926,7 @@ public:
Builder.addComma();
if (BodyParams) {
// If we have a local name for the parameter, pass in that as well.
auto name = BodyParams->get(i).decl->getName();
auto name = BodyParams->get(i)->getName();
Builder.addCallParameter(Name, name, ParamType, TupleElt.isVararg());
} else {
Builder.addCallParameter(Name, ParamType, TupleElt.isVararg());
@@ -1944,7 +1944,7 @@ public:
modifiedBuilder = true;
if (BodyParams) {
auto name = BodyParams->get(0).decl->getName();
auto name = BodyParams->get(0)->getName();
Builder.addCallParameter(Identifier(), name, T,
/*IsVarArg*/false);
} else
+6 -7
View File
@@ -2740,7 +2740,7 @@ static FuncDecl *createAccessorFunc(SourceLoc DeclLoc, ParameterList *param,
// micro-optimization for Objective-C thunk generation.
ParameterList *ValueArg;
{
SmallVector<Parameter, 2> ValueArgElements;
SmallVector<ParamDecl*, 2> ValueArgElements;
SourceLoc StartLoc, EndLoc;
if (param) {
assert(param->size() == 1 &&
@@ -2884,7 +2884,7 @@ static FuncDecl *createAccessorFunc(SourceLoc DeclLoc, ParameterList *param,
return D;
}
static Parameter
static ParamDecl *
createSetterAccessorArgument(SourceLoc nameLoc, Identifier name,
TypeLoc elementTy, AccessorKind accessorKind,
Parser &P) {
@@ -2897,17 +2897,16 @@ createSetterAccessorArgument(SourceLoc nameLoc, Identifier name,
name = P.Context.getIdentifier(implName);
}
Parameter result;
result.decl = new (P.Context) ParamDecl(/*IsLet*/true, SourceLoc(),
auto result = new (P.Context) ParamDecl(/*IsLet*/true, SourceLoc(),
Identifier(), nameLoc, name,
Type(), P.CurDeclContext);
if (isNameImplicit)
result.decl->setImplicit();
result->setImplicit();
result.decl->getTypeLoc() = elementTy.clone(P.Context);
result->getTypeLoc() = elementTy.clone(P.Context);
// AST Walker shouldn't go into the type recursively.
result.decl->setIsTypeLocImplicit(true);
result->setIsTypeLocImplicit(true);
return result;
}
+7 -7
View File
@@ -1708,7 +1708,7 @@ parseClosureSignatureIfPresent(SmallVectorImpl<CaptureListEntry> &captureList,
invalid = true;
} else {
// Parse identifier (',' identifier)*
SmallVector<Parameter, 4> elements;
SmallVector<ParamDecl*, 4> elements;
do {
if (Tok.isNot(tok::identifier, tok::kw__)) {
diagnose(Tok, diag::expected_closure_parameter_name);
@@ -1721,7 +1721,7 @@ parseClosureSignatureIfPresent(SmallVectorImpl<CaptureListEntry> &captureList,
auto var = new (Context) ParamDecl(/*IsLet*/ true, SourceLoc(),
Identifier(), Tok.getLoc(), name,
Type(), nullptr);
elements.push_back(Parameter::withoutLoc(var));
elements.push_back(var);
consumeToken();
// Consume a comma to continue.
@@ -1860,9 +1860,9 @@ ParserResult<Expr> Parser::parseExprClosure() {
if (!params) {
// Create a parameter pattern containing the anonymous variables.
auto &anonVars = AnonClosureVars.back().second;
SmallVector<Parameter, 4> elements;
SmallVector<ParamDecl*, 4> elements;
for (auto anonVar : anonVars)
elements.push_back(Parameter::withoutLoc(anonVar));
elements.push_back(anonVar);
params = ParameterList::create(Context, leftBrace, elements, leftBrace);
@@ -2344,9 +2344,9 @@ void Parser::addPatternVariablesToScope(ArrayRef<Pattern *> Patterns) {
}
void Parser::addParametersToScope(ParameterList *PL) {
for (auto &param : *PL)
if (param.decl->hasName())
addToScope(param.decl);
for (auto param : *PL)
if (param->hasName())
addToScope(param);
}
+21 -22
View File
@@ -307,21 +307,20 @@ mapParsedParameters(Parser &parser,
auto &ctx = parser.Context;
// Local function to create a pattern for a single parameter.
auto createParamPattern = [&](SourceLoc &letVarInOutLoc,
auto createParam = [&](SourceLoc &letVarInOutLoc,
Parser::ParsedParameter::SpecifierKindTy &specifierKind,
Identifier argName, SourceLoc argNameLoc,
Identifier paramName, SourceLoc paramNameLoc,
TypeRepr *type,
const DeclAttributes &Attrs) -> Parameter {
Parameter param;
const DeclAttributes &Attrs) -> ParamDecl * {
bool isLet = specifierKind == Parser::ParsedParameter::Let;
param.decl = new (ctx) ParamDecl(isLet, argNameLoc, argName,
auto param = new (ctx) ParamDecl(isLet, argNameLoc, argName,
paramNameLoc, paramName, Type(),
parser.CurDeclContext);
param.decl->getAttrs() = Attrs;
param->getAttrs() = Attrs;
if (argNameLoc.isInvalid() && paramNameLoc.isInvalid())
param.decl->setImplicit();
param->setImplicit();
// If a type was provided, create the typed pattern.
if (type) {
@@ -329,7 +328,7 @@ mapParsedParameters(Parser &parser,
if (specifierKind == Parser::ParsedParameter::InOut)
type = new (ctx) InOutTypeRepr(type, letVarInOutLoc);
param.decl->getTypeLoc() = TypeLoc(type);
param->getTypeLoc() = TypeLoc(type);
} else if (specifierKind == Parser::ParsedParameter::InOut) {
parser.diagnose(letVarInOutLoc, diag::inout_must_have_type);
letVarInOutLoc = SourceLoc();
@@ -340,7 +339,7 @@ mapParsedParameters(Parser &parser,
// Collect the elements of the tuple patterns for argument and body
// parameters.
SmallVector<Parameter, 4> elements;
SmallVector<ParamDecl*, 4> elements;
SourceLoc ellipsisLoc;
bool isFirstParameter = true;
for (auto &param : params) {
@@ -368,7 +367,7 @@ mapParsedParameters(Parser &parser,
}
// Create the pattern.
Parameter result;
ParamDecl *result = nullptr;
Identifier argName;
Identifier paramName;
if (param.SecondNameLoc.isValid()) {
@@ -376,10 +375,10 @@ mapParsedParameters(Parser &parser,
paramName = param.SecondName;
// Both names were provided, so pass them in directly.
result = createParamPattern(param.LetVarInOutLoc, param.SpecifierKind,
argName, param.FirstNameLoc,
paramName, param.SecondNameLoc,
param.Type, param.Attrs);
result = createParam(param.LetVarInOutLoc, param.SpecifierKind,
argName, param.FirstNameLoc,
paramName, param.SecondNameLoc,
param.Type, param.Attrs);
// If the first name is empty and this parameter would not have been
// an API name by default, complain.
@@ -406,10 +405,10 @@ mapParsedParameters(Parser &parser,
argName = param.FirstName;
paramName = param.FirstName;
result = createParamPattern(param.LetVarInOutLoc, param.SpecifierKind,
argName, SourceLoc(),
param.FirstName, param.FirstNameLoc,
param.Type, param.Attrs);
result = createParam(param.LetVarInOutLoc, param.SpecifierKind,
argName, SourceLoc(),
param.FirstName, param.FirstNameLoc,
param.Type, param.Attrs);
}
// If this parameter had an ellipsis, check whether it's the last parameter.
@@ -420,14 +419,14 @@ mapParsedParameters(Parser &parser,
.fixItRemove(param.EllipsisLoc);
param.EllipsisLoc = SourceLoc();
} else if (!result.decl->getTypeLoc().getTypeRepr()) {
} else if (!result->getTypeLoc().getTypeRepr()) {
parser.diagnose(param.EllipsisLoc, diag::untyped_pattern_ellipsis)
.highlight(result.getSourceRange());
.highlight(result->getSourceRange());
param.EllipsisLoc = SourceLoc();
} else {
ellipsisLoc = param.EllipsisLoc;
result.setVariadic();
result->setVariadic();
}
}
@@ -438,8 +437,8 @@ mapParsedParameters(Parser &parser,
.fixItRemove(SourceRange(param.EqualLoc,
param.DefaultArg->getExpr()->getEndLoc()));
} else {
result.decl->setDefaultArgumentKind(getDefaultArgKind(param.DefaultArg));
result.setDefaultValue(param.DefaultArg);
result->setDefaultArgumentKind(getDefaultArgKind(param.DefaultArg));
result->setDefaultValue(param.DefaultArg);
}
}
+4 -4
View File
@@ -274,7 +274,7 @@ private:
}
void printSingleMethodParam(StringRef selectorPiece,
const Parameter &param,
const ParamDecl *param,
const clang::ParmVarDecl *clangParam,
bool isNSUIntegerSubscript,
bool isLastPiece) {
@@ -283,14 +283,14 @@ private:
(clangParam && isNSUInteger(clangParam->getType()))) {
os << "NSUInteger";
} else {
print(param.decl->getType(), OTK_None);
print(param->getType(), OTK_None);
}
os << ")";
if (!param.decl->hasName()) {
if (!param->hasName()) {
os << "_";
} else {
Identifier name = param.decl->getName();
Identifier name = param->getName();
os << name;
if (isClangKeyword(name))
os << "_";
+2 -2
View File
@@ -772,8 +772,8 @@ void SILGenModule::emitDefaultArgGenerators(SILDeclRef::Loc decl,
ArrayRef<ParameterList*> paramLists) {
unsigned index = 0;
for (auto paramList : paramLists) {
for (auto &param : *paramList) {
if (auto handle = param.getDefaultValue())
for (auto param : *paramList) {
if (auto handle = param->getDefaultValue())
emitDefaultArgGenerator(SILDeclRef::getDefaultArgGenerator(decl, index),
handle->getExpr());
++index;
+1 -1
View File
@@ -91,7 +91,7 @@ static void emitImplicitValueConstructor(SILGenFunction &gen,
elements.push_back(
emitImplicitValueConstructorArg(gen, Loc,
param.decl->getType()->getCanonicalType(),
param->getType()->getCanonicalType(),
ctor));
}
+3 -4
View File
@@ -306,9 +306,8 @@ struct ArgumentInitHelper {
}
}
void emitParam(Parameter &param) {
void emitParam(ParamDecl *PD) {
++ArgNo;
auto PD = param.decl;
if (PD->hasName()) {
makeArgumentIntoBinding(PD->getType(), &*f.begin(), PD);
return;
@@ -349,8 +348,8 @@ static void makeArgument(Type ty, ParamDecl *decl,
void SILGenFunction::bindParametersForForwarding(const ParameterList *params,
SmallVectorImpl<SILValue> &parameters) {
for (auto &param : *params) {
makeArgument(param.decl->getType(), param.decl, parameters, *this);
for (auto param : *params) {
makeArgument(param->getType(), param, parameters, *this);
}
}
+2 -2
View File
@@ -6206,8 +6206,8 @@ static bool isVariadicWitness(AbstractFunctionDecl *afd) {
if (afd->getExtensionType())
++index;
for (auto &param : *afd->getParameterList(index))
if (param.isVariadic())
for (auto param : *afd->getParameterList(index))
if (param->isVariadic())
return true;
return false;
+10 -11
View File
@@ -463,7 +463,7 @@ ResolvedLocator constraints::resolveLocatorToDecl(
unsigned index = path[0].getValue2();
if (index < parameterList->size()) {
auto param = parameterList->get(index);
return ResolvedLocator(ResolvedLocator::ForVar, param.decl);
return ResolvedLocator(ResolvedLocator::ForVar, param);
}
break;
}
@@ -2591,9 +2591,9 @@ namespace {
// Save the types on ClosureExpr parameters.
if (auto *CE = dyn_cast<ClosureExpr>(expr))
for (auto &P : *CE->getParameters())
if (P.decl->hasType())
TS->ParamDeclTypes[P.decl] = P.decl->getType();
for (auto P : *CE->getParameters())
if (P->hasType())
TS->ParamDeclTypes[P] = P->getType();
return { true, expr };
}
@@ -2706,9 +2706,9 @@ static void eraseTypeData(Expr *expr) {
// so that they'll get regenerated from the associated TypeLocs or
// resynthesized.
if (auto *CE = dyn_cast<ClosureExpr>(expr))
for (auto &P : *CE->getParameters())
if (P.decl->hasType())
P.decl->overwriteType(Type());
for (auto P : *CE->getParameters())
if (P->hasType())
P->overwriteType(Type());
expr->setType(nullptr);
expr->clearLValueAccessKind();
@@ -2957,8 +2957,8 @@ typeCheckArbitrarySubExprIndependently(Expr *subExpr, TCCOptions options) {
// none of its arguments are type variables. If so, these type variables
// would be accessible to name lookup of the subexpression and may thus leak
// in. Reset them to UnresolvedTypes for safe measures.
for (auto &param : *CE->getParameters()) {
auto VD = param.decl;
for (auto param : *CE->getParameters()) {
auto VD = param;
if (VD->getType()->hasTypeVariable() || VD->getType()->is<ErrorType>())
VD->overwriteType(CS->getASTContext().TheUnresolvedType);
}
@@ -4262,8 +4262,7 @@ bool FailureDiagnosis::visitClosureExpr(ClosureExpr *CE) {
// lookups against the parameter decls.
//
// Handle this by rewriting the arguments to UnresolvedType().
for (auto &param : *CE->getParameters()) {
auto VD = param.decl;
for (auto VD : *CE->getParameters()) {
if (VD->getType()->hasTypeVariable() || VD->getType()->is<ErrorType>())
VD->overwriteType(CS->getASTContext().TheUnresolvedType);
}
+6 -6
View File
@@ -560,8 +560,8 @@ namespace {
if (auto AFD = dyn_cast<AbstractFunctionDecl>(VD)) {
for (auto params : AFD->getParameterLists()) {
for (auto &param : *params) {
if (!param.decl->isDefaultArgument())
for (auto param : *params) {
if (!param->isDefaultArgument())
nNoDefault++;
}
}
@@ -1681,12 +1681,12 @@ namespace {
/// types were not specified, and return the eventual function type.
Type getTypeForParameterList(ParameterList *params,
ConstraintLocatorBuilder locator) {
for (auto &param : *params) {
for (auto param : *params) {
// If a type was explicitly specified, use its opened type.
if (auto type = param.decl->getTypeLoc().getType()) {
if (auto type = param->getTypeLoc().getType()) {
// FIXME: Need a better locator for a pattern as a base.
Type openedType = CS.openType(type, locator);
param.decl->overwriteType(openedType);
param->overwriteType(openedType);
continue;
}
@@ -1694,7 +1694,7 @@ namespace {
Type ty = CS.createTypeVariable(CS.getConstraintLocator(locator),
/*options=*/0);
param.decl->overwriteType(ty);
param->overwriteType(ty);
}
return params->getType(CS.getASTContext());
+8 -8
View File
@@ -374,18 +374,18 @@ static Type getTypeAtIndex(const ParameterList *params, size_t index) {
return nullptr;
if (index < params->size()) {
auto &param = params->get(index);
if (param.isVariadic())
return param.getVarargBaseTy();
auto param = params->get(index);
if (param->isVariadic())
return param->getVarargBaseTy();
return param.decl->getType();
return param->getType();
}
/// FIXME: This looks completely wrong for varargs within a parameter list.
if (params->size() != 0) {
auto lastParam = params->getArray().back();
if (lastParam.isVariadic())
return lastParam.getVarargBaseTy();
if (lastParam->isVariadic())
return lastParam->getVarargBaseTy();
}
return nullptr;
@@ -474,8 +474,8 @@ static unsigned countDefaultArguments(AbstractFunctionDecl *func) {
auto paramList = func->getParameterList(func->getImplicitSelfDecl() != 0);
unsigned count = 0;
for (const auto &elt : *paramList) {
if (elt.decl->isDefaultArgument())
for (auto elt : *paramList) {
if (elt->isDefaultArgument())
++count;
}
+19 -23
View File
@@ -43,7 +43,7 @@ static void addMemberToContextIfNeeded(Decl *D, DeclContext *DC,
}
static ParamDecl *getParamDeclAtIndex(FuncDecl *fn, unsigned index) {
return fn->getParameterLists().back()->get(index).decl;
return fn->getParameterLists().back()->get(index);
}
static VarDecl *getFirstParamDecl(FuncDecl *fn) {
@@ -51,7 +51,7 @@ static VarDecl *getFirstParamDecl(FuncDecl *fn) {
};
static Parameter buildArgument(SourceLoc loc, DeclContext *DC,
static ParamDecl *buildArgument(SourceLoc loc, DeclContext *DC,
StringRef name, Type type, bool isLet) {
auto &context = DC->getASTContext();
auto *param = new (context) ParamDecl(isLet, SourceLoc(), Identifier(),
@@ -59,15 +59,15 @@ static Parameter buildArgument(SourceLoc loc, DeclContext *DC,
Type(), DC);
param->setImplicit();
param->getTypeLoc().setType(type);
return Parameter::withoutLoc(param);
return param;
}
static Parameter buildLetArgument(SourceLoc loc, DeclContext *DC,
static ParamDecl *buildLetArgument(SourceLoc loc, DeclContext *DC,
StringRef name, Type type) {
return buildArgument(loc, DC, name, type, /*isLet*/ true);
}
static Parameter buildInOutArgument(SourceLoc loc, DeclContext *DC,
static ParamDecl *buildInOutArgument(SourceLoc loc, DeclContext *DC,
StringRef name, Type type) {
return buildArgument(loc, DC, name, InOutType::get(type), /*isLet*/ false);
}
@@ -91,7 +91,7 @@ static Type getTypeOfStorage(AbstractStorageDecl *storage,
/// forwarding pattern.
static ParameterList *
buildIndexForwardingParamList(AbstractStorageDecl *storage,
ArrayRef<Parameter> prefix) {
ArrayRef<ParamDecl*> prefix) {
auto &context = storage->getASTContext();
auto subscript = dyn_cast<SubscriptDecl>(storage);
@@ -107,7 +107,7 @@ buildIndexForwardingParamList(AbstractStorageDecl *storage,
// Otherwise, we need to build up a new parameter list.
SmallVector<Parameter, 4> elements;
SmallVector<ParamDecl*, 4> elements;
// Start with the fields we were given, if there are any.
elements.append(prefix.begin(), prefix.end());
@@ -175,11 +175,10 @@ static FuncDecl *createSetterPrototype(AbstractStorageDecl *storage,
// Add a "(value : T, indices...)" argument list.
auto storageType = getTypeOfStorage(storage, TC);
auto valueParam = buildLetArgument(storage->getLoc(),
valueDecl = buildLetArgument(storage->getLoc(),
storage->getDeclContext(), "value",
storageType);
valueDecl = valueParam.decl;
params.push_back(buildIndexForwardingParamList(storage, valueParam));
params.push_back(buildIndexForwardingParamList(storage, valueDecl));
Type setterRetTy = TupleType::getEmpty(TC.Context);
FuncDecl *setter = FuncDecl::create(
@@ -305,8 +304,7 @@ static FuncDecl *createMaterializeForSetPrototype(AbstractStorageDecl *storage,
// - The buffer parameter, (buffer: Builtin.RawPointer,
// inout storage: Builtin.UnsafeValueBuffer,
// indices...).
Parameter bufferElements[] = {
ParamDecl *bufferElements[] = {
buildLetArgument(loc, DC, "buffer", ctx.TheRawPointerType),
buildInOutArgument(loc, DC, "callbackStorage", ctx.TheUnsafeValueBufferType)
};
@@ -394,7 +392,7 @@ static Expr *buildTupleExpr(ASTContext &ctx, ArrayRef<Expr*> args) {
/// NOTE: This returns null if a varargs parameter exists in the list, as it
/// cannot be forwarded correctly yet.
///
static Expr *buildArgumentForwardingExpr(ArrayRef<Parameter> params,
static Expr *buildArgumentForwardingExpr(ArrayRef<ParamDecl*> params,
ASTContext &ctx) {
SmallVector<Identifier, 4> labels;
SmallVector<SourceLoc, 4> labelLocs;
@@ -402,16 +400,15 @@ static Expr *buildArgumentForwardingExpr(ArrayRef<Parameter> params,
for (auto param : params) {
// We cannot express how to forward variadic parameters yet.
if (param.isVariadic())
if (param->isVariadic())
return nullptr;
Expr *ref = new (ctx) DeclRefExpr(param.decl, SourceLoc(),
/*implicit*/ true);
if (param.decl->getType()->is<InOutType>())
Expr *ref = new (ctx) DeclRefExpr(param, SourceLoc(), /*implicit*/ true);
if (param->getType()->is<InOutType>())
ref = new (ctx) InOutExpr(SourceLoc(), ref, Type(), /*implicit=*/true);
args.push_back(ref);
labels.push_back(param.decl->getArgumentName());
labels.push_back(param->getArgumentName());
labelLocs.push_back(SourceLoc());
}
@@ -998,8 +995,7 @@ static Expr *buildMaterializeForSetCallback(ASTContext &ctx,
// Generate the body of the closure.
SmallVector<ASTNode, 4> body;
generator(body, selfValueParam.decl, bufferParam.decl,
callbackStorageParam.decl);
generator(body, selfValueParam, bufferParam, callbackStorageParam);
closure->setBody(BraceStmt::create(ctx, SourceLoc(), body, SourceLoc(),
IsImplicit),
/*isSingleExpression*/ false);
@@ -1416,7 +1412,7 @@ void swift::synthesizeObservingAccessors(VarDecl *VD, TypeChecker &TC) {
// decls for 'self' and 'value'.
auto *Set = VD->getSetter();
auto *SelfDecl = Set->getImplicitSelfDecl();
VarDecl *ValueDecl = Set->getParameterLists().back()->get(0).decl;
VarDecl *ValueDecl = Set->getParameterLists().back()->get(0);
// The setter loads the oldValue, invokes willSet with the incoming value,
// does a direct store, then invokes didSet with the oldValue.
@@ -1854,7 +1850,7 @@ ConstructorDecl *swift::createImplicitConstructor(TypeChecker &tc,
accessLevel = std::min(accessLevel, Accessibility::Internal);
// Determine the parameter type of the implicit constructor.
SmallVector<Parameter, 8> params;
SmallVector<ParamDecl*, 8> params;
if (ICK == ImplicitConstructorKind::Memberwise) {
assert(isa<StructDecl>(decl) && "Only struct have memberwise constructor");
@@ -1886,7 +1882,7 @@ ConstructorDecl *swift::createImplicitConstructor(TypeChecker &tc,
auto *arg = new (context) ParamDecl(/*IsLet*/true, Loc, var->getName(),
Loc, var->getName(), varType, decl);
arg->setImplicit();
params.push_back(Parameter::withoutLoc(arg));
params.push_back(arg);
}
}
@@ -129,8 +129,8 @@ static void deriveBodyEquatable_enum_eq(AbstractFunctionDecl *eqDecl) {
ASTContext &C = parentDC->getASTContext();
auto args = eqDecl->getParameterLists().back();
auto aParam = args->get(0).decl;
auto bParam = args->get(1).decl;
auto aParam = args->get(0);
auto bParam = args->get(1);
CanType boolTy = C.getBoolDecl()->getDeclaredType().getCanonicalTypeOrNull();
@@ -201,8 +201,8 @@ deriveEquatable_enum_eq(TypeChecker &tc, Decl *parentDecl, EnumDecl *enumDecl) {
};
auto params = ParameterList::create(C, {
Parameter::withoutLoc(getParamDecl("a")),
Parameter::withoutLoc(getParamDecl("b"))
getParamDecl("a"),
getParamDecl("b")
});
auto genericParams = parentDC->getGenericParamsOfContext();
@@ -231,7 +231,7 @@ deriveBodyRawRepresentable_init(AbstractFunctionDecl *initDecl) {
/*HasBoundDecls=*/false, SourceLoc(),
dfltBody));
auto rawDecl = initDecl->getParameterList(1)->get(0).decl;
auto rawDecl = initDecl->getParameterList(1)->get(0);
auto rawRef = new (C) DeclRefExpr(rawDecl, SourceLoc(), /*implicit*/true);
auto switchStmt = SwitchStmt::create(LabeledStmtInfo(), SourceLoc(), rawRef,
SourceLoc(), cases, SourceLoc(), C);
+10 -10
View File
@@ -1194,9 +1194,9 @@ public:
VarDeclUsageChecker(TypeChecker &TC, AbstractFunctionDecl *AFD) : TC(TC) {
// Track the parameters of the function.
for (auto PL : AFD->getParameterLists())
for (auto &param : *PL)
if (shouldTrackVarDecl(param.decl))
VarDecls[param.decl] = 0;
for (auto param : *PL)
if (shouldTrackVarDecl(param))
VarDecls[param] = 0;
}
@@ -2047,9 +2047,9 @@ static Optional<DeclName> omitNeedlessWords(AbstractFunctionDecl *afd) {
SmallVector<OmissionTypeName, 4> paramTypes;
// Always look at the parameters in the last parameter list.
for (auto &param : *afd->getParameterLists().back()) {
paramTypes.push_back(getTypeNameForOmission(param.decl->getType())
.withDefaultArgument(param.decl->isDefaultArgument()));
for (auto param : *afd->getParameterLists().back()) {
paramTypes.push_back(getTypeNameForOmission(param->getType())
.withDefaultArgument(param->isDefaultArgument()));
}
// Handle contextual type, result type, and returnsSelf.
@@ -2069,7 +2069,7 @@ static Optional<DeclName> omitNeedlessWords(AbstractFunctionDecl *afd) {
StringRef firstParamName;
auto params = afd->getParameterList(afd->getImplicitSelfDecl() ? 1 : 0);
if (params->size() != 0)
firstParamName = params->get(0).decl->getName().str();
firstParamName = params->get(0)->getName().str();
// Find the set of property names.
const InheritedNameSet *allPropertyNames = nullptr;
@@ -2260,11 +2260,11 @@ static bool hasExtraneousDefaultArguments(AbstractFunctionDecl *afd,
}
for (unsigned i = 0; i != numElementsInParens; ++i) {
auto &param = bodyParams->get(i);
if (!param.decl->isDefaultArgument())
auto param = bodyParams->get(i);
if (!param->isDefaultArgument())
continue;
auto defaultArg = param.decl->getType()->getInferredDefaultArgString();
auto defaultArg = param->getType()->getInferredDefaultArgString();
// Never consider removing the first argument for a "set" method
// with an unnamed first argument.
+8 -9
View File
@@ -685,8 +685,8 @@ public:
static bool checkObjectOrOptionalObjectType(TypeChecker &TC, Decl *D,
Parameter &param) {
Type ty = param.decl->getType();
ParamDecl *param) {
Type ty = param->getType();
if (auto unwrapped = ty->getAnyOptionalObjectType())
ty = unwrapped;
@@ -694,8 +694,8 @@ static bool checkObjectOrOptionalObjectType(TypeChecker &TC, Decl *D,
// @objc class types are okay.
if (!classDecl->isObjC()) {
TC.diagnose(D, diag::ibaction_nonobjc_class_argument,
param.decl->getType())
.highlight(param.getSourceRange());
param->getType())
.highlight(param->getSourceRange());
return true;
}
} else if (ty->isObjCExistentialType()) {
@@ -704,8 +704,8 @@ static bool checkObjectOrOptionalObjectType(TypeChecker &TC, Decl *D,
} else {
// No other types are permitted.
TC.diagnose(D, diag::ibaction_nonobject_argument,
param.decl->getType())
.highlight(param.getSourceRange());
param->getType())
.highlight(param->getSourceRange());
return true;
}
@@ -751,7 +751,7 @@ void AttributeChecker::visitIBActionAttr(IBActionAttr *attr) {
if (isRelaxedIBAction(TC)) {
// Do a rough check to allow any ObjC-representable struct or enum type
// on iOS.
Type ty = paramList->get(0).decl->getType();
Type ty = paramList->get(0)->getType();
if (auto nominal = ty->getAnyNominal())
if (isa<StructDecl>(nominal) || isa<EnumDecl>(nominal))
if (nominal->classifyAsOptionalType() == OTK_None)
@@ -1219,8 +1219,7 @@ void AttributeChecker::visitRethrowsAttr(RethrowsAttr *attr) {
auto fn = cast<AbstractFunctionDecl>(D);
for (auto paramList : fn->getParameterLists()) {
for (auto param : *paramList)
if (hasThrowingFunctionParameter(param.decl->getType()
->getCanonicalType()))
if (hasThrowingFunctionParameter(param->getType()->getCanonicalType()))
return;
}
+18 -19
View File
@@ -885,9 +885,9 @@ void TypeChecker::revertGenericFuncSignature(AbstractFunctionDecl *func) {
for (auto paramList : func->getParameterLists()) {
for (auto &param : *paramList) {
// Clear out the type of the decl.
if (param.decl->hasType() && !param.decl->isInvalid())
param.decl->overwriteType(Type());
revertDependentTypeLoc(param.decl->getTypeLoc());
if (param->hasType() && !param->isInvalid())
param->overwriteType(Type());
revertDependentTypeLoc(param->getTypeLoc());
}
}
@@ -1988,7 +1988,7 @@ static void checkAccessibility(TypeChecker &TC, const Decl *D) {
const TypeRepr *complainRepr = nullptr;
bool problemIsElement = false;
for (auto &P : *SD->getIndices()) {
checkTypeAccessibility(TC, P.decl->getTypeLoc(), SD,
checkTypeAccessibility(TC, P->getTypeLoc(), SD,
[&](Accessibility typeAccess,
const TypeRepr *thisComplainRepr) {
if (!minAccess || *minAccess > typeAccess) {
@@ -2043,7 +2043,7 @@ static void checkAccessibility(TypeChecker &TC, const Decl *D) {
const TypeRepr *complainRepr = nullptr;
for (auto *PL : fn->getParameterLists().slice(isTypeContext)) {
for (auto &P : *PL) {
checkTypeAccessibility(TC, P.decl->getTypeLoc(), fn,
checkTypeAccessibility(TC, P->getTypeLoc(), fn,
[&](Accessibility typeAccess,
const TypeRepr *thisComplainRepr) {
if (!minAccess || *minAccess > typeAccess) {
@@ -3912,7 +3912,7 @@ public:
if (FD->isObservingAccessor() || (FD->isSetter() && FD->isImplicit())) {
unsigned firstParamIdx = FD->getParent()->isTypeContext();
auto *firstParamPattern = FD->getParameterList(firstParamIdx);
firstParamPattern->get(0).decl->getTypeLoc().setType(valueTy, true);
firstParamPattern->get(0)->getTypeLoc().setType(valueTy, true);
} else if (FD->isGetter() && FD->isImplicit()) {
FD->getBodyResultTypeLoc().setType(valueTy, true);
}
@@ -4073,23 +4073,22 @@ public:
// closure. We look at the type sugar directly, so that one can
// suppress this warning by adding parentheses.
auto &param = paramList->get(i-1);
auto paramType = param.decl->getType();
auto paramType = param->getType();
if (auto *funcTy = isUnparenthesizedTrailingClosure(paramType)) {
// If we saw any default arguments before this, complain.
// This doesn't apply to autoclosures.
if (anyDefaultArguments && !funcTy->getExtInfo().isAutoClosure()) {
TC.diagnose(param.getStartLoc(),
TC.diagnose(param->getStartLoc(),
diag::non_trailing_closure_before_default_args)
.highlight(SourceRange(param.getStartLoc(),
param.getEndLoc()));
.highlight(param->getSourceRange());
}
break;
}
// If we have a default argument, keep going.
if (param.decl->isDefaultArgument()) {
if (param->isDefaultArgument()) {
anyDefaultArguments = true;
continue;
}
@@ -4190,14 +4189,14 @@ public:
parentTy = parentTy->getResult()->castTo<AnyFunctionType>();
// Check the parameter types.
auto checkParam = [&](const Parameter &param, Type parentParamTy) {
Type paramTy = param.decl->getType();
auto checkParam = [&](const ParamDecl *decl, Type parentParamTy) {
Type paramTy = decl->getType();
if (!paramTy || !paramTy->getImplicitlyUnwrappedOptionalObjectType())
return;
if (!parentParamTy || parentParamTy->getAnyOptionalObjectType())
return;
TypeLoc TL = param.decl->getTypeLoc();
TypeLoc TL = decl->getTypeLoc();
if (!TL.getTypeRepr())
return;
@@ -4205,7 +4204,7 @@ public:
if (isa<ParenType>(TL.getType().getPointer()))
return;
TC.diagnose(param.getStartLoc(), diag::override_unnecessary_IUO,
TC.diagnose(decl->getStartLoc(), diag::override_unnecessary_IUO,
method->getDescriptiveKind(), parentParamTy, paramTy)
.highlight(TL.getSourceRange());
@@ -4228,7 +4227,7 @@ public:
if (auto parentTupleInput = parentInput->getAs<TupleType>()) {
// FIXME: If we ever allow argument reordering, this is incorrect.
ArrayRef<Parameter> sharedParams = paramList->getArray();
ArrayRef<ParamDecl*> sharedParams = paramList->getArray();
sharedParams = sharedParams.slice(0, parentTupleInput->getNumElements());
for_each(sharedParams, parentTupleInput->getElementTypes(), checkParam);
} else {
@@ -6799,8 +6798,8 @@ void TypeChecker::defineDefaultConstructor(NominalTypeDecl *decl) {
auto params = ctor->getParameters();
bool missingInit = false;
for (auto &param : *params) {
if (!param.hasDefaultValue()) {
for (auto param : *params) {
if (!param->isDefaultArgument()) {
missingInit = true;
break;
}
@@ -7047,7 +7046,7 @@ void TypeChecker::fixAbstractFunctionNames(InFlightDiagnostic &diag,
if (origArg == targetArg)
continue;
auto *param = params->get(i).decl;
auto *param = params->get(i);
// The parameter has an explicitly-specified API name, and it's wrong.
if (param->getArgumentNameLoc() != param->getLoc() &&
+2 -2
View File
@@ -990,8 +990,8 @@ namespace {
// Can default parameter initializers capture state? That seems like
// a really bad idea.
for (auto *paramList : AFD->getParameterLists())
for (auto &param : *paramList) {
if (auto E = param.getDefaultValue())
for (auto param : *paramList) {
if (auto E = param->getDefaultValue())
E->getExpr()->walk(*this);
}
return false;
+29 -32
View File
@@ -706,11 +706,10 @@ static bool validateTypedPattern(TypeChecker &TC, DeclContext *DC,
}
static bool validateParameterType(Parameter &param, DeclContext *DC,
static bool validateParameterType(ParamDecl *decl, DeclContext *DC,
TypeResolutionOptions options,
GenericTypeResolver *resolver,
TypeChecker &TC) {
auto decl = param.decl;
if (auto ty = decl->getTypeLoc().getType())
return ty->is<ErrorType>();
@@ -718,13 +717,13 @@ static bool validateParameterType(Parameter &param, DeclContext *DC,
options|TR_FunctionInput, resolver);
Type Ty = decl->getTypeLoc().getType();
if (param.isVariadic() && !hadError) {
if (decl->isVariadic() && !hadError) {
// If isn't legal to declare something both inout and variadic.
if (Ty->is<InOutType>()) {
TC.diagnose(param.getStartLoc(), diag::inout_cant_be_variadic);
TC.diagnose(decl->getStartLoc(), diag::inout_cant_be_variadic);
hadError = true;
} else {
Ty = TC.getArraySliceType(param.getStartLoc(), Ty);
Ty = TC.getArraySliceType(decl->getStartLoc(), Ty);
if (Ty.isNull()) {
hadError = true;
}
@@ -744,14 +743,14 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL, DeclContext *DC,
GenericTypeResolver *resolver) {
bool hadError = false;
for (auto &param : *PL) {
if (param.decl->getTypeLoc().getTypeRepr())
for (auto param : *PL) {
if (param->getTypeLoc().getTypeRepr())
hadError |= validateParameterType(param, DC, options, resolver, *this);
auto type = param.decl->getTypeLoc().getType();
if (!type && param.decl->hasType()) {
type = param.decl->getType();
param.decl->getTypeLoc().setType(type);
auto type = param->getTypeLoc().getType();
if (!type && param->hasType()) {
type = param->getType();
param->getTypeLoc().setType(type);
}
// If there was no type specified, and if we're not looking at a
@@ -762,19 +761,18 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL, DeclContext *DC,
// Closure argument lists are allowed to be missing types.
if (options & TR_InExpression)
continue;
param.decl->setInvalid();
param->setInvalid();
}
VarDecl *var = param.decl;
if (var->isInvalid()) {
var->overwriteType(ErrorType::get(Context));
if (param->isInvalid()) {
param->overwriteType(ErrorType::get(Context));
hadError = true;
} else
var->overwriteType(type);
param->overwriteType(type);
checkTypeModifyingDeclAttributes(var);
if (var->getType()->is<InOutType>())
var->setLet(false);
checkTypeModifyingDeclAttributes(param);
if (param->getType()->is<InOutType>())
param->setLet(false);
}
return hadError;
@@ -1558,30 +1556,29 @@ bool TypeChecker::coerceParameterListToType(ParameterList *P, DeclContext *DC,
bool hadError = paramListType->is<ErrorType>();
// Sometimes a scalar type gets applied to a single-argument parameter list.
auto handleParameter = [&](Parameter &param, Type ty) -> bool {
auto handleParameter = [&](ParamDecl *param, Type ty) -> bool {
bool hadError = false;
// Check that the type, if explicitly spelled, is ok.
if (param.decl->getTypeLoc().getTypeRepr()) {
if (param->getTypeLoc().getTypeRepr()) {
hadError |= validateParameterType(param, DC, TypeResolutionOptions(),
nullptr, *this);
// Now that we've type checked the explicit argument type, see if it
// agrees with the contextual type.
if (!hadError && !ty->isEqual(param.decl->getTypeLoc().getType()) &&
if (!hadError && !ty->isEqual(param->getTypeLoc().getType()) &&
!ty->is<ErrorType>())
param.decl->overwriteType(ty);
param->overwriteType(ty);
}
auto *var = param.decl;
if (var->isInvalid())
var->overwriteType(ErrorType::get(Context));
if (param->isInvalid())
param->overwriteType(ErrorType::get(Context));
else
var->overwriteType(ty);
param->overwriteType(ty);
checkTypeModifyingDeclAttributes(var);
checkTypeModifyingDeclAttributes(param);
if (ty->is<InOutType>())
var->setLet(false);
param->setLet(false);
return hadError;
};
@@ -1619,17 +1616,17 @@ bool TypeChecker::coerceParameterListToType(ParameterList *P, DeclContext *DC,
// If the tuple pattern had a label for the tuple element, it must match
// the label for the tuple type being matched.
auto argName = param.decl->getArgumentName();
auto argName = param->getArgumentName();
if (!hadError && !argName.empty() &&
argName != tupleTy->getElement(i).getName()) {
diagnose(param.decl->getArgumentNameLoc(),
diagnose(param->getArgumentNameLoc(),
diag::tuple_pattern_label_mismatch,
argName, tupleTy->getElement(i).getName());
hadError = true;
}
hadError |= handleParameter(param, CoercionType);
assert(!param.getDefaultValue() && "Closures cannot have default args");
assert(!param->isDefaultArgument() && "Closures cannot have default args");
}
return hadError;
+1 -1
View File
@@ -573,7 +573,7 @@ SourceLoc OptionalAdjustment::getOptionalityLoc(ValueDecl *witness) const {
return SourceLoc();
}
return getOptionalityLoc(params->get(getParameterIndex()).decl->getTypeLoc()
return getOptionalityLoc(params->get(getParameterIndex())->getTypeLoc()
.getTypeRepr());
}
+4 -4
View File
@@ -1115,11 +1115,11 @@ static void checkDefaultArguments(TypeChecker &tc, ParameterList *params,
for (auto &param : *params) {
unsigned curArgIndex = nextArgIndex++;
if (!param.getDefaultValue() || !param.decl->hasType() ||
param.decl->getType()->is<ErrorType>())
if (!param->getDefaultValue() || !param->hasType() ||
param->getType()->is<ErrorType>())
continue;
auto defaultValueHandle = param.getDefaultValue();
auto defaultValueHandle = param->getDefaultValue();
Expr *e = defaultValueHandle->getExpr();
// Re-use an existing initializer context if possible.
@@ -1137,7 +1137,7 @@ static void checkDefaultArguments(TypeChecker &tc, ParameterList *params,
}
// Type-check the initializer, then flag that we did so.
if (tc.typeCheckExpression(e, initContext, param.decl->getType(),
if (tc.typeCheckExpression(e, initContext, param->getType(),
CTP_DefaultParameter))
defaultValueHandle->setExpr(defaultValueHandle->getExpr(), true);
else
+11 -13
View File
@@ -2417,7 +2417,7 @@ static void describeObjCReason(TypeChecker &TC, const ValueDecl *VD,
static void diagnoseFunctionParamNotRepresentable(
TypeChecker &TC, const AbstractFunctionDecl *AFD, unsigned NumParams,
unsigned ParamIndex, const Parameter &P, ObjCReason Reason) {
unsigned ParamIndex, const ParamDecl *P, ObjCReason Reason) {
if (Reason == ObjCReason::DoNotDiagnose)
return;
@@ -2428,10 +2428,10 @@ static void diagnoseFunctionParamNotRepresentable(
TC.diagnose(AFD->getLoc(), diag::objc_invalid_on_func_param_type,
ParamIndex + 1, getObjCDiagnosticAttrKind(Reason));
}
if (P.decl->hasType()) {
Type ParamTy = P.decl->getType();
if (P->hasType()) {
Type ParamTy = P->getType();
SourceRange SR;
if (auto typeRepr = P.decl->getTypeLoc().getTypeRepr())
if (auto typeRepr = P->getTypeLoc().getTypeRepr())
SR = typeRepr->getSourceRange();
TC.diagnoseTypeNotRepresentableInObjC(AFD, ParamTy, SR);
}
@@ -2449,29 +2449,28 @@ static bool isParamListRepresentableInObjC(TypeChecker &TC,
bool IsObjC = true;
unsigned NumParams = PL->size();
for (unsigned ParamIndex = 0; ParamIndex != NumParams; ParamIndex++) {
auto &param = PL->get(ParamIndex);
auto param = PL->get(ParamIndex);
// Swift Varargs are not representable in Objective-C.
if (param.isVariadic()) {
if (param->isVariadic()) {
if (Diagnose && Reason != ObjCReason::DoNotDiagnose) {
TC.diagnose(param.getStartLoc(),
diag::objc_invalid_on_func_variadic,
TC.diagnose(param->getStartLoc(), diag::objc_invalid_on_func_variadic,
getObjCDiagnosticAttrKind(Reason))
.highlight(param.getSourceRange());
.highlight(param->getSourceRange());
describeObjCReason(TC, AFD, Reason);
}
return false;
}
if (TC.isRepresentableInObjC(AFD, param.decl->getType()))
if (TC.isRepresentableInObjC(AFD, param->getType()))
continue;
// Permit '()' when this method overrides a method with a
// foreign error convention that replaces NSErrorPointer with ()
// and this is the replaced parameter.
AbstractFunctionDecl *overridden;
if (param.decl->getType()->isVoid() && AFD->isBodyThrowing() &&
if (param->getType()->isVoid() && AFD->isBodyThrowing() &&
(overridden = AFD->getOverriddenDecl())) {
auto foreignError = overridden->getForeignErrorConvention();
if (foreignError &&
@@ -2831,8 +2830,7 @@ bool TypeChecker::isRepresentableInObjC(
errorParameterIndex = paramList->size();
while (errorParameterIndex > 0) {
// Skip over trailing closures.
auto type =
paramList->get(errorParameterIndex - 1).decl->getType();
auto type = paramList->get(errorParameterIndex - 1)->getType();
// It can't be a trailing closure unless it has a specific form.
// Only consider the rvalue type.
+7 -8
View File
@@ -285,7 +285,7 @@ ParameterList *ModuleFile::readParameterList() {
unsigned numParams;
decls_block::ParameterListLayout::readRecord(scratch, numParams);
SmallVector<Parameter, 8> params;
SmallVector<ParamDecl*, 8> params;
for (unsigned i = 0; i != numParams; ++i) {
scratch.clear();
auto entry = DeclTypeCursor.advance(AF_DontPopBlockAtEnd);
@@ -300,15 +300,14 @@ ParameterList *ModuleFile::readParameterList() {
isVariadic, rawDefaultArg);
Parameter result;
result.decl = cast<ParamDecl>(getDecl(paramID));
result.setVariadic(isVariadic);
auto decl = cast<ParamDecl>(getDecl(paramID));
decl->setVariadic(isVariadic);
// Decode the default argument kind.
// FIXME: Default argument expression, if available.
if (auto defaultArg = getActualDefaultArgKind(rawDefaultArg))
result.decl->setDefaultArgumentKind(*defaultArg);
params.push_back(result);
decl->setDefaultArgumentKind(*defaultArg);
params.push_back(decl);
}
return ParameterList::create(getContext(), params);
@@ -2281,7 +2280,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
auto *bodyParams0 = readParameterList();
auto *bodyParams1 = readParameterList();
assert(bodyParams0 && bodyParams1 && "missing parameters for constructor");
ctor->setParameterLists(bodyParams0->get(0).decl, bodyParams1);
ctor->setParameterLists(bodyParams0->get(0), bodyParams1);
// This must be set after recording the constructor in the map.
// A polymorphic constructor type needs to refer to the constructor to get
@@ -3097,7 +3096,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
dtor->setAccessibility(cast<ClassDecl>(DC)->getFormalAccess());
auto *selfParams = readParameterList();
assert(selfParams && "Didn't get self pattern?");
dtor->setSelfDecl(selfParams->get(0).decl);
dtor->setSelfDecl(selfParams->get(0));
dtor->setType(getType(signatureID));
dtor->setInterfaceType(getType(interfaceID));
+3 -3
View File
@@ -800,10 +800,10 @@ void Serializer::writeParameterList(const ParameterList *PL) {
// FIXME: Default argument expressions?
auto defaultArg =
getRawStableDefaultArgumentKind(param.decl->getDefaultArgumentKind());
getRawStableDefaultArgumentKind(param->getDefaultArgumentKind());
ParameterListEltLayout::emitRecord(Out, ScratchRecord, abbrCode,
addDeclRef(param.decl),
param.isVariadic(),
addDeclRef(param),
param->isVariadic(),
defaultArg);
}
}
@@ -523,8 +523,8 @@ static void addParameters(ArrayRef<Identifier> &ArgNames,
ArgNames = ArgNames.slice(1);
}
if (auto typeRepr = param.decl->getTypeLoc().getTypeRepr()) {
SourceRange TypeRange = param.decl->getTypeLoc().getSourceRange();
if (auto typeRepr = param->getTypeLoc().getTypeRepr()) {
SourceRange TypeRange = param->getTypeLoc().getSourceRange();
if (auto InOutTyR = dyn_cast_or_null<InOutTypeRepr>(typeRepr))
TypeRange = InOutTyR->getBase()->getSourceRange();
if (TypeRange.isInvalid())
@@ -535,7 +535,7 @@ static void addParameters(ArrayRef<Identifier> &ArgNames,
SM.getLocOffsetInBuffer(Lexer::getLocForEndOfToken(SM, TypeRange.End),
BufferID);
TextRange TR{ StartOffs, EndOffs-StartOffs };
TextEntity Param(param.decl, Arg, TR, StartOffs);
TextEntity Param(param, Arg, TR, StartOffs);
Ent.SubEntities.push_back(std::move(Param));
}
}
@@ -1912,9 +1912,9 @@ class FormatWalker: public ide::SourceEntityWalker {
// Function parameters are siblings.
for (auto P : AFD->getParameterLists()) {
for (auto &param : *P) {
addPair(param.getEndLoc(),
FindAlignLoc(param.getStartLoc()), tok::comma);
for (auto param : *P) {
addPair(param->getEndLoc(),
FindAlignLoc(param->getStartLoc()), tok::comma);
}
}
}