Skip to content

Commit 87285e0

Browse files
committed
[NFC] Add DeclNameLoc to specialize/dynamicReplacement
1 parent 1b42bf0 commit 87285e0

File tree

4 files changed

+45
-19
lines changed

4 files changed

+45
-19
lines changed

include/swift/AST/Attr.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,18 +948,20 @@ class DynamicReplacementAttr final
948948
friend class DynamicallyReplacedDeclRequest;
949949

950950
DeclNameRef ReplacedFunctionName;
951+
DeclNameLoc ReplacedFunctionNameLoc;
951952
LazyMemberLoader *Resolver = nullptr;
952953
uint64_t ResolverContextData;
953954

954955
/// Create an @_dynamicReplacement(for:) attribute written in the source.
955956
DynamicReplacementAttr(SourceLoc atLoc, SourceRange baseRange,
956957
DeclNameRef replacedFunctionName,
958+
DeclNameLoc replacedFunctionNameLoc,
957959
SourceRange parenRange);
958960

959961
DynamicReplacementAttr(DeclNameRef name, AbstractFunctionDecl *f)
960962
: DeclAttribute(DAK_DynamicReplacement, SourceLoc(), SourceRange(),
961963
/*Implicit=*/false),
962-
ReplacedFunctionName(name),
964+
ReplacedFunctionName(name), ReplacedFunctionNameLoc(),
963965
Resolver(nullptr), ResolverContextData(0) {
964966
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false;
965967
}
@@ -969,7 +971,7 @@ class DynamicReplacementAttr final
969971
uint64_t Data = 0)
970972
: DeclAttribute(DAK_DynamicReplacement, SourceLoc(), SourceRange(),
971973
/*Implicit=*/false),
972-
ReplacedFunctionName(name),
974+
ReplacedFunctionName(name), ReplacedFunctionNameLoc(),
973975
Resolver(Resolver), ResolverContextData(Data) {
974976
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false;
975977
}
@@ -991,7 +993,8 @@ class DynamicReplacementAttr final
991993
public:
992994
static DynamicReplacementAttr *
993995
create(ASTContext &Context, SourceLoc AtLoc, SourceLoc DynReplLoc,
994-
SourceLoc LParenLoc, DeclNameRef replacedFunction, SourceLoc RParenLoc);
996+
SourceLoc LParenLoc, DeclNameRef replacedFunction,
997+
DeclNameLoc replacedFunctionNameLoc, SourceLoc RParenLoc);
995998

996999
static DynamicReplacementAttr *create(ASTContext &ctx,
9971000
DeclNameRef replacedFunction,
@@ -1006,6 +1009,10 @@ class DynamicReplacementAttr final
10061009
return ReplacedFunctionName;
10071010
}
10081011

1012+
DeclNameLoc getReplacedFunctionNameLoc() const {
1013+
return ReplacedFunctionNameLoc;
1014+
}
1015+
10091016
/// Retrieve the location of the opening parentheses, if there is one.
10101017
SourceLoc getLParenLoc() const;
10111018

@@ -1327,6 +1334,7 @@ class SpecializeAttr final
13271334
GenericSignature specializedSignature;
13281335

13291336
DeclNameRef targetFunctionName;
1337+
DeclNameLoc targetFunctionNameLoc;
13301338
LazyMemberLoader *resolver = nullptr;
13311339
uint64_t resolverContextData;
13321340
size_t numSPIGroups;
@@ -1335,13 +1343,15 @@ class SpecializeAttr final
13351343
TrailingWhereClause *clause, bool exported,
13361344
SpecializationKind kind, GenericSignature specializedSignature,
13371345
DeclNameRef targetFunctionName,
1346+
DeclNameLoc targetFunctionNameLoc,
13381347
ArrayRef<Identifier> spiGroups);
13391348

13401349
public:
13411350
static SpecializeAttr *create(ASTContext &Ctx, SourceLoc atLoc,
13421351
SourceRange Range, TrailingWhereClause *clause,
13431352
bool exported, SpecializationKind kind,
13441353
DeclNameRef targetFunctionName,
1354+
DeclNameLoc targetFunctionNameLoc,
13451355
ArrayRef<Identifier> spiGroups,
13461356
GenericSignature specializedSignature
13471357
= nullptr);
@@ -1398,6 +1408,10 @@ class SpecializeAttr final
13981408
return targetFunctionName;
13991409
}
14001410

1411+
DeclNameLoc getTargetFunctionNameLoc() const {
1412+
return targetFunctionNameLoc;
1413+
}
1414+
14011415
/// \p forDecl is the value decl that the attribute belongs to.
14021416
ValueDecl *getTargetFunctionDecl(const ValueDecl *forDecl) const;
14031417

include/swift/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ class Parser {
10841084
swift::tok ClosingBrace, bool &DiscardAttribute, Optional<bool> &Exported,
10851085
Optional<SpecializeAttr::SpecializationKind> &Kind,
10861086
TrailingWhereClause *&TrailingWhereClause, DeclNameRef &targetFunction,
1087-
SmallVectorImpl<Identifier> &spiGroups,
1087+
DeclNameLoc &targetFunctionLoc, SmallVectorImpl<Identifier> &spiGroups,
10881088
llvm::function_ref<bool(Parser &)> parseSILTargetName,
10891089
llvm::function_ref<bool(Parser &)> parseSILSIPModule);
10901090

lib/AST/Attr.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,10 +1363,11 @@ PrivateImportAttr *PrivateImportAttr::create(ASTContext &Ctxt, SourceLoc AtLoc,
13631363
DynamicReplacementAttr::DynamicReplacementAttr(SourceLoc atLoc,
13641364
SourceRange baseRange,
13651365
DeclNameRef name,
1366+
DeclNameLoc nameLoc,
13661367
SourceRange parenRange)
13671368
: DeclAttribute(DAK_DynamicReplacement, atLoc, baseRange,
13681369
/*Implicit=*/false),
1369-
ReplacedFunctionName(name) {
1370+
ReplacedFunctionName(name), ReplacedFunctionNameLoc(nameLoc) {
13701371
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = true;
13711372
getTrailingLocations()[0] = parenRange.Start;
13721373
getTrailingLocations()[1] = parenRange.End;
@@ -1375,11 +1376,12 @@ DynamicReplacementAttr::DynamicReplacementAttr(SourceLoc atLoc,
13751376
DynamicReplacementAttr *
13761377
DynamicReplacementAttr::create(ASTContext &Ctx, SourceLoc AtLoc,
13771378
SourceLoc DynReplLoc, SourceLoc LParenLoc,
1378-
DeclNameRef ReplacedFunction, SourceLoc RParenLoc) {
1379+
DeclNameRef ReplacedFunction,
1380+
DeclNameLoc nameLoc, SourceLoc RParenLoc) {
13791381
void *mem = Ctx.Allocate(totalSizeToAlloc<SourceLoc>(2),
13801382
alignof(DynamicReplacementAttr));
13811383
return new (mem) DynamicReplacementAttr(
1382-
AtLoc, SourceRange(DynReplLoc, RParenLoc), ReplacedFunction,
1384+
AtLoc, SourceRange(DynReplLoc, RParenLoc), ReplacedFunction, nameLoc,
13831385
SourceRange(LParenLoc, RParenLoc));
13841386
}
13851387

@@ -1636,11 +1638,14 @@ SpecializeAttr::SpecializeAttr(SourceLoc atLoc, SourceRange range,
16361638
SpecializationKind kind,
16371639
GenericSignature specializedSignature,
16381640
DeclNameRef targetFunctionName,
1641+
DeclNameLoc targetFunctionNameLoc,
16391642
ArrayRef<Identifier> spiGroups)
16401643
: DeclAttribute(DAK_Specialize, atLoc, range,
16411644
/*Implicit=*/clause == nullptr),
16421645
trailingWhereClause(clause), specializedSignature(specializedSignature),
1643-
targetFunctionName(targetFunctionName), numSPIGroups(spiGroups.size()) {
1646+
targetFunctionName(targetFunctionName),
1647+
targetFunctionNameLoc(targetFunctionNameLoc),
1648+
numSPIGroups(spiGroups.size()) {
16441649
std::uninitialized_copy(spiGroups.begin(), spiGroups.end(),
16451650
getTrailingObjects<Identifier>());
16461651
Bits.SpecializeAttr.exported = exported;
@@ -1656,13 +1661,14 @@ SpecializeAttr *SpecializeAttr::create(ASTContext &Ctx, SourceLoc atLoc,
16561661
TrailingWhereClause *clause,
16571662
bool exported, SpecializationKind kind,
16581663
DeclNameRef targetFunctionName,
1664+
DeclNameLoc targetFunctionNameLoc,
16591665
ArrayRef<Identifier> spiGroups,
16601666
GenericSignature specializedSignature) {
16611667
unsigned size = totalSizeToAlloc<Identifier>(spiGroups.size());
16621668
void *mem = Ctx.Allocate(size, alignof(SpecializeAttr));
16631669
return new (mem)
16641670
SpecializeAttr(atLoc, range, clause, exported, kind, specializedSignature,
1665-
targetFunctionName, spiGroups);
1671+
targetFunctionName, targetFunctionNameLoc, spiGroups);
16661672
}
16671673

16681674
SpecializeAttr *SpecializeAttr::create(ASTContext &ctx, bool exported,
@@ -1674,7 +1680,8 @@ SpecializeAttr *SpecializeAttr::create(ASTContext &ctx, bool exported,
16741680
void *mem = ctx.Allocate(size, alignof(SpecializeAttr));
16751681
return new (mem)
16761682
SpecializeAttr(SourceLoc(), SourceRange(), nullptr, exported, kind,
1677-
specializedSignature, targetFunctionName, spiGroups);
1683+
specializedSignature, targetFunctionName, DeclNameLoc(),
1684+
spiGroups);
16781685
}
16791686

16801687
SpecializeAttr *SpecializeAttr::create(
@@ -1685,7 +1692,8 @@ SpecializeAttr *SpecializeAttr::create(
16851692
void *mem = ctx.Allocate(size, alignof(SpecializeAttr));
16861693
auto *attr = new (mem)
16871694
SpecializeAttr(SourceLoc(), SourceRange(), nullptr, exported, kind,
1688-
specializedSignature, targetFunctionName, spiGroups);
1695+
specializedSignature, targetFunctionName, DeclNameLoc(),
1696+
spiGroups);
16891697
attr->resolver = resolver;
16901698
attr->resolverContextData = data;
16911699
return attr;

lib/Parse/ParseDecl.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ bool Parser::parseSpecializeAttributeArguments(
582582
swift::tok ClosingBrace, bool &DiscardAttribute, Optional<bool> &Exported,
583583
Optional<SpecializeAttr::SpecializationKind> &Kind,
584584
swift::TrailingWhereClause *&TrailingWhereClause,
585-
DeclNameRef &targetFunction, SmallVectorImpl<Identifier> &spiGroups,
585+
DeclNameRef &targetFunction, DeclNameLoc &targetFunctionLoc,
586+
SmallVectorImpl<Identifier> &spiGroups,
586587
llvm::function_ref<bool(Parser &)> parseSILTargetName,
587588
llvm::function_ref<bool(Parser &)> parseSILSIPModule) {
588589
SyntaxParsingContext ContentContext(SyntaxContext,
@@ -665,9 +666,8 @@ bool Parser::parseSpecializeAttributeArguments(
665666
}
666667
if (ParamLabel == "target") {
667668
if (!parseSILTargetName(*this)) {
668-
DeclNameLoc loc;
669669
targetFunction = parseDeclNameRef(
670-
loc, diag::attr_specialize_expected_function,
670+
targetFunctionLoc, diag::attr_specialize_expected_function,
671671
DeclNameFlag::AllowZeroArgCompoundNames |
672672
DeclNameFlag::AllowKeywordsUsingSpecialNames |
673673
DeclNameFlag::AllowOperators);
@@ -742,10 +742,12 @@ bool Parser::parseSpecializeAttribute(
742742
TrailingWhereClause *trailingWhereClause = nullptr;
743743

744744
DeclNameRef targetFunction;
745+
DeclNameLoc targetFunctionLoc;
745746
SmallVector<Identifier, 4> spiGroups;
746747
if (!parseSpecializeAttributeArguments(
747748
ClosingBrace, DiscardAttribute, exported, kind, trailingWhereClause,
748-
targetFunction, spiGroups, parseSILTargetName, parseSILSIPModule)) {
749+
targetFunction, targetFunctionLoc, spiGroups, parseSILTargetName,
750+
parseSILSIPModule)) {
749751
return false;
750752
}
751753

@@ -774,7 +776,8 @@ bool Parser::parseSpecializeAttribute(
774776
// Store the attribute.
775777
Attr = SpecializeAttr::create(Context, AtLoc, SourceRange(Loc, rParenLoc),
776778
trailingWhereClause, exported.getValue(),
777-
kind.getValue(), targetFunction, spiGroups);
779+
kind.getValue(), targetFunction,
780+
targetFunctionLoc, spiGroups);
778781
return true;
779782
}
780783

@@ -2466,6 +2469,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
24662469

24672470
SourceLoc LParenLoc = consumeToken(tok::l_paren);
24682471
DeclNameRef replacedFunction;
2472+
DeclNameLoc replacedFunctionLoc;
24692473
{
24702474
SyntaxParsingContext ContentContext(
24712475
SyntaxContext, SyntaxKind::NamedAttributeStringArgument);
@@ -2484,8 +2488,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
24842488
}
24852489
consumeToken(tok::colon);
24862490

2487-
DeclNameLoc loc;
2488-
replacedFunction = parseDeclNameRef(loc,
2491+
replacedFunction = parseDeclNameRef(replacedFunctionLoc,
24892492
diag::attr_dynamic_replacement_expected_function,
24902493
DeclNameFlag::AllowZeroArgCompoundNames |
24912494
DeclNameFlag::AllowKeywordsUsingSpecialNames |
@@ -2504,7 +2507,8 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
25042507

25052508

25062509
DynamicReplacementAttr *attr = DynamicReplacementAttr::create(
2507-
Context, AtLoc, Loc, LParenLoc, replacedFunction, RParenLoc);
2510+
Context, AtLoc, Loc, LParenLoc, replacedFunction, replacedFunctionLoc,
2511+
RParenLoc);
25082512
Attributes.add(attr);
25092513
break;
25102514
}

0 commit comments

Comments
 (0)