mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
move the TypeLoc for a parameter out of Parameter and onto ParamDecl. NFC.
This commit is contained in:
@@ -4163,6 +4163,8 @@ class ParamDecl : public VarDecl {
|
||||
Identifier ArgumentName;
|
||||
SourceLoc ArgumentNameLoc;
|
||||
|
||||
/// This is the type specified, including location information.
|
||||
TypeLoc typeLoc;
|
||||
public:
|
||||
ParamDecl(bool isLet, SourceLoc argumentNameLoc,
|
||||
Identifier argumentName, SourceLoc parameterNameLoc,
|
||||
@@ -4183,6 +4185,9 @@ public:
|
||||
return const_cast<ParamDecl*>(this)->getParameter();
|
||||
}
|
||||
|
||||
TypeLoc &getTypeLoc() { return typeLoc; }
|
||||
TypeLoc getTypeLoc() const { return typeLoc; }
|
||||
|
||||
SourceRange getSourceRange() const;
|
||||
|
||||
/// Create an implicit 'self' decl for a method in the specified decl context.
|
||||
|
||||
@@ -46,9 +46,6 @@ struct Parameter {
|
||||
/// This is the location of the ":" token.
|
||||
SourceLoc colonLoc;
|
||||
|
||||
/// This is the type specified, including location information.
|
||||
TypeLoc type;
|
||||
|
||||
/// The default value, if any, along with whether this is varargs.
|
||||
llvm::PointerIntPair<ExprHandle *, 1, bool> defaultValueAndIsVariadic;
|
||||
|
||||
|
||||
@@ -1572,7 +1572,7 @@ void PrintAST::printOneParameter(const Parameter ¶m, bool Curried,
|
||||
Printer << ": ";
|
||||
};
|
||||
|
||||
auto TheTypeLoc = param.type;
|
||||
auto TheTypeLoc = param.decl->getTypeLoc();
|
||||
if (TheTypeLoc.getTypeRepr()) {
|
||||
// If the outer typeloc is an InOutTypeRepr, print the 'inout' before the
|
||||
// subpattern.
|
||||
|
||||
@@ -852,7 +852,7 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
|
||||
|
||||
// Don't walk into the type if the decl is implicit, or if the type is
|
||||
// implicit.
|
||||
if (!P.decl->isImplicit() && doIt(P.type))
|
||||
if (!P.decl->isImplicit() && doIt(P.decl->getTypeLoc()))
|
||||
return true;
|
||||
|
||||
if (auto *E = P.getDefaultValue()) {
|
||||
|
||||
@@ -1395,7 +1395,7 @@ bool ArchetypeBuilder::inferRequirements(ParameterList *params,
|
||||
|
||||
bool hadError = false;
|
||||
for (auto &P : *params)
|
||||
hadError |= inferRequirements(P.type, genericParams);
|
||||
hadError |= inferRequirements(P.decl->getTypeLoc(), genericParams);
|
||||
return hadError;
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -3152,15 +3152,14 @@ SourceRange VarDecl::getSourceRange() const {
|
||||
}
|
||||
|
||||
SourceRange VarDecl::getTypeSourceRangeForDiagnostics() const {
|
||||
Pattern *Pat = getParentPattern();
|
||||
|
||||
// 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 (P.type.getTypeRepr())
|
||||
return P.type.getTypeRepr()->getSourceRange();
|
||||
if (auto typeRepr = P.decl->getTypeLoc().getTypeRepr())
|
||||
return typeRepr->getSourceRange();
|
||||
}
|
||||
|
||||
Pattern *Pat = getParentPattern();
|
||||
if (!Pat || Pat->isImplicit())
|
||||
return getSourceRange();
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ SourceRange Parameter::getSourceRange() const {
|
||||
}
|
||||
|
||||
// If the typeloc has a valid location, use it to end the range.
|
||||
if (auto typeRepr = type.getTypeRepr()) {
|
||||
if (auto typeRepr = decl->getTypeLoc().getTypeRepr()) {
|
||||
auto endLoc = typeRepr->getEndLoc();
|
||||
if (endLoc.isValid())
|
||||
return SourceRange(range.Start, endLoc);
|
||||
@@ -142,6 +142,8 @@ ParameterList *ParameterList::clone(const ASTContext &C,
|
||||
if ((options & Implicit) || decl->isImplicit())
|
||||
param.decl->setImplicit();
|
||||
|
||||
param.decl->getTypeLoc() = decl->getTypeLoc();
|
||||
|
||||
// If we're inheriting a default argument, mark it as such.
|
||||
if (param.defaultArgumentKind != DefaultArgumentKind::None &&
|
||||
(options & Inherited)) {
|
||||
|
||||
@@ -2904,7 +2904,7 @@ createSetterAccessorArgument(SourceLoc nameLoc, Identifier name,
|
||||
if (isNameImplicit)
|
||||
result.decl->setImplicit();
|
||||
|
||||
result.type = elementTy.clone(P.Context);
|
||||
result.decl->getTypeLoc() = elementTy.clone(P.Context);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ mapParsedParameters(Parser &parser,
|
||||
if (specifierKind == Parser::ParsedParameter::InOut)
|
||||
type = new (ctx) InOutTypeRepr(type, letVarInOutLoc);
|
||||
|
||||
param.type = TypeLoc(type);
|
||||
param.decl->getTypeLoc() = TypeLoc(type);
|
||||
} else if (specifierKind == Parser::ParsedParameter::InOut) {
|
||||
parser.diagnose(letVarInOutLoc, diag::inout_must_have_type);
|
||||
letVarInOutLoc = SourceLoc();
|
||||
@@ -420,7 +420,7 @@ mapParsedParameters(Parser &parser,
|
||||
.fixItRemove(param.EllipsisLoc);
|
||||
|
||||
param.EllipsisLoc = SourceLoc();
|
||||
} else if (!result.type.getTypeRepr()) {
|
||||
} else if (!result.decl->getTypeLoc().getTypeRepr()) {
|
||||
parser.diagnose(param.EllipsisLoc, diag::untyped_pattern_ellipsis)
|
||||
.highlight(result.getSourceRange());
|
||||
|
||||
|
||||
+2
-2
@@ -1683,9 +1683,9 @@ namespace {
|
||||
ConstraintLocatorBuilder locator) {
|
||||
for (auto ¶m : *params) {
|
||||
// If a type was explicitly specified, use its opened type.
|
||||
if (param.type.getType()) {
|
||||
if (auto type = param.decl->getTypeLoc().getType()) {
|
||||
// FIXME: Need a better locator for a pattern as a base.
|
||||
Type openedType = CS.openType(param.type.getType(), locator);
|
||||
Type openedType = CS.openType(type, locator);
|
||||
param.decl->overwriteType(openedType);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -58,10 +58,8 @@ static Parameter buildArgument(SourceLoc loc, DeclContext *DC,
|
||||
loc, context.getIdentifier(name),
|
||||
Type(), DC);
|
||||
param->setImplicit();
|
||||
|
||||
Parameter P = Parameter::withoutLoc(param);
|
||||
P.type.setType(type);
|
||||
return P;
|
||||
param->getTypeLoc().setType(type);
|
||||
return Parameter::withoutLoc(param);
|
||||
}
|
||||
|
||||
static Parameter buildLetArgument(SourceLoc loc, DeclContext *DC,
|
||||
|
||||
@@ -887,7 +887,7 @@ void TypeChecker::revertGenericFuncSignature(AbstractFunctionDecl *func) {
|
||||
// Clear out the type of the decl.
|
||||
if (param.decl->hasType() && !param.decl->isInvalid())
|
||||
param.decl->overwriteType(Type());
|
||||
revertDependentTypeLoc(param.type);
|
||||
revertDependentTypeLoc(param.decl->getTypeLoc());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1338,7 +1338,7 @@ Type swift::configureImplicitSelf(TypeChecker &tc,
|
||||
|
||||
// Install the self type on the Parameter that contains it. This ensures that
|
||||
// we don't lose it when generic types get reverted.
|
||||
selfDecl->getParameter().type = TypeLoc::withoutLoc(selfTy);
|
||||
selfDecl->getTypeLoc() = TypeLoc::withoutLoc(selfTy);
|
||||
return selfTy;
|
||||
}
|
||||
|
||||
@@ -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.type, SD,
|
||||
checkTypeAccessibility(TC, P.decl->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.type, fn,
|
||||
checkTypeAccessibility(TC, P.decl->getTypeLoc(), fn,
|
||||
[&](Accessibility typeAccess,
|
||||
const TypeRepr *thisComplainRepr) {
|
||||
if (!minAccess || *minAccess > typeAccess) {
|
||||
@@ -3915,7 +3915,7 @@ public:
|
||||
if (FD->isObservingAccessor() || (FD->isSetter() && FD->isImplicit())) {
|
||||
unsigned firstParamIdx = FD->getParent()->isTypeContext();
|
||||
auto *firstParamPattern = FD->getParameterList(firstParamIdx);
|
||||
firstParamPattern->get(0).type.setType(valueTy, true);
|
||||
firstParamPattern->get(0).decl->getTypeLoc().setType(valueTy, true);
|
||||
} else if (FD->isGetter() && FD->isImplicit()) {
|
||||
FD->getBodyResultTypeLoc().setType(valueTy, true);
|
||||
}
|
||||
@@ -3938,7 +3938,7 @@ public:
|
||||
type = type->getReferenceStorageReferent();
|
||||
|
||||
auto &valueParam = FD->getParameterLists().back()->get(0);
|
||||
valueParam.type = TypeLoc::withoutLoc(type);
|
||||
valueParam.decl->getTypeLoc() = TypeLoc::withoutLoc(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4220,8 +4220,8 @@ public:
|
||||
if (!parentParamTy || parentParamTy->getAnyOptionalObjectType())
|
||||
return;
|
||||
|
||||
TypeLoc TL = param.type;
|
||||
if (!param.type.getTypeRepr())
|
||||
TypeLoc TL = param.decl->getTypeLoc();
|
||||
if (!TL.getTypeRepr())
|
||||
return;
|
||||
|
||||
// Allow silencing this warning using parens.
|
||||
|
||||
@@ -710,13 +710,14 @@ static bool validateParameterType(Parameter ¶m, DeclContext *DC,
|
||||
TypeResolutionOptions options,
|
||||
GenericTypeResolver *resolver,
|
||||
TypeChecker &TC) {
|
||||
if (auto ty = param.type.getType())
|
||||
auto decl = param.decl;
|
||||
if (auto ty = decl->getTypeLoc().getType())
|
||||
return ty->is<ErrorType>();
|
||||
|
||||
bool hadError = TC.validateType(param.type, DC, options|TR_FunctionInput,
|
||||
resolver);
|
||||
bool hadError = TC.validateType(decl->getTypeLoc(), DC,
|
||||
options|TR_FunctionInput, resolver);
|
||||
|
||||
Type Ty = param.type.getType();
|
||||
Type Ty = decl->getTypeLoc().getType();
|
||||
if (param.isVariadic() && !hadError) {
|
||||
// If isn't legal to declare something both inout and variadic.
|
||||
if (Ty->is<InOutType>()) {
|
||||
@@ -728,11 +729,11 @@ static bool validateParameterType(Parameter ¶m, DeclContext *DC,
|
||||
hadError = true;
|
||||
}
|
||||
}
|
||||
param.type.setType(Ty);
|
||||
decl->getTypeLoc().setType(Ty);
|
||||
}
|
||||
|
||||
if (hadError)
|
||||
param.type.setType(ErrorType::get(TC.Context), /*validated*/true);
|
||||
decl->getTypeLoc().setType(ErrorType::get(TC.Context), /*validated*/true);
|
||||
|
||||
return hadError;
|
||||
}
|
||||
@@ -744,13 +745,13 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL, DeclContext *DC,
|
||||
bool hadError = false;
|
||||
|
||||
for (auto ¶m : *PL) {
|
||||
if (param.type.getTypeRepr())
|
||||
if (param.decl->getTypeLoc().getTypeRepr())
|
||||
hadError |= validateParameterType(param, DC, options, resolver, *this);
|
||||
|
||||
auto type = param.type.getType();
|
||||
auto type = param.decl->getTypeLoc().getType();
|
||||
if (!type && param.decl->hasType()) {
|
||||
type = param.decl->getType();
|
||||
param.type.setType(type);
|
||||
param.decl->getTypeLoc().setType(type);
|
||||
}
|
||||
|
||||
// If there was no type specified, and if we're not looking at a
|
||||
@@ -1561,13 +1562,13 @@ bool TypeChecker::coerceParameterListToType(ParameterList *P, DeclContext *DC,
|
||||
bool hadError = false;
|
||||
|
||||
// Check that the type, if explicitly spelled, is ok.
|
||||
if (param.type.getTypeRepr()) {
|
||||
if (param.decl->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.type.getType()) &&
|
||||
if (!hadError && !ty->isEqual(param.decl->getTypeLoc().getType()) &&
|
||||
!ty->is<ErrorType>())
|
||||
param.decl->overwriteType(ty);
|
||||
}
|
||||
|
||||
@@ -573,7 +573,8 @@ SourceLoc OptionalAdjustment::getOptionalityLoc(ValueDecl *witness) const {
|
||||
return SourceLoc();
|
||||
}
|
||||
|
||||
return getOptionalityLoc(params->get(getParameterIndex()).type.getTypeRepr());
|
||||
return getOptionalityLoc(params->get(getParameterIndex()).decl->getTypeLoc()
|
||||
.getTypeRepr());
|
||||
}
|
||||
|
||||
SourceLoc OptionalAdjustment::getOptionalityLoc(TypeRepr *tyR) const {
|
||||
|
||||
@@ -2430,7 +2430,7 @@ static void diagnoseFunctionParamNotRepresentable(
|
||||
if (P.decl->hasType()) {
|
||||
Type ParamTy = P.decl->getType();
|
||||
SourceRange SR;
|
||||
if (auto typeRepr = P.type.getTypeRepr())
|
||||
if (auto typeRepr = P.decl->getTypeLoc().getTypeRepr())
|
||||
SR = typeRepr->getSourceRange();
|
||||
TC.diagnoseTypeNotRepresentableInObjC(AFD, ParamTy, SR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user