Skip to content

Commit 550865c

Browse files
committed
Revert "Merge pull request #27528 from rintaro/syntaxparse-rdar55952739"
This reverts commit 2ddba9c, reversing changes made to 33770fa.
1 parent cd1a299 commit 550865c

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

include/swift/Parse/ASTGen.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ class ASTGen {
6767

6868
private:
6969
DeclAttributes
70-
generateDeclAttributes(const syntax::Syntax &D, SourceLoc Loc,
71-
bool includeComments);
70+
generateDeclAttributes(const syntax::DeclSyntax &D,
71+
const Optional<syntax::AttributeListSyntax> &attrs,
72+
const Optional<syntax::ModifierListSyntax> &modifiers,
73+
SourceLoc Loc, bool includeComments);
7274

7375
void generateFreeStandingGenericWhereClause(
7476
const syntax::GenericWhereClauseSyntax &syntax,

lib/Parse/ASTGen.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,21 @@ Decl *ASTGen::generate(const DeclSyntax &D, const SourceLoc Loc) {
5757
}
5858

5959
DeclAttributes
60-
ASTGen::generateDeclAttributes(const Syntax &D, SourceLoc Loc,
61-
bool includeComments) {
62-
// Find the AST attribute-list from the lookup table.
63-
if (auto firstTok = D.getFirstToken()) {
64-
auto declLoc = advanceLocBegin(Loc, *firstTok);
65-
if (hasDeclAttributes(declLoc))
66-
return getDeclAttributes(declLoc);
60+
ASTGen::generateDeclAttributes(const DeclSyntax &D,
61+
const Optional<AttributeListSyntax> &attrs,
62+
const Optional<ModifierListSyntax> &modifiers,
63+
SourceLoc Loc, bool includeComments) {
64+
SourceLoc attrsLoc;
65+
if (attrs) {
66+
attrsLoc = advanceLocBegin(Loc, *attrs->getFirstToken());
67+
} else if (modifiers) {
68+
attrsLoc = advanceLocBegin(Loc, *modifiers->getFirstToken());
69+
} else {
70+
// We might have comment attributes.
71+
attrsLoc = advanceLocBegin(Loc, *D.getFirstToken());
6772
}
73+
if (hasDeclAttributes(attrsLoc))
74+
return getDeclAttributes(attrsLoc);
6875
return DeclAttributes();
6976
}
7077

@@ -104,7 +111,8 @@ TypeDecl *ASTGen::generate(const AssociatedtypeDeclSyntax &D,
104111
Identifier name;
105112
SourceLoc nameLoc = generateIdentifierDeclName(idToken, Loc, name);
106113

107-
DeclAttributes attrs = generateDeclAttributes(D, Loc, true);
114+
DeclAttributes attrs =
115+
generateDeclAttributes(D, D.getAttributes(), D.getModifiers(), Loc, true);
108116

109117
DebuggerContextChange DCC(P, name, DeclKind::AssociatedType);
110118

@@ -139,7 +147,8 @@ TypeDecl *ASTGen::generate(const TypealiasDeclSyntax &D, const SourceLoc Loc) {
139147
auto keywordLoc = advanceLocBegin(Loc, D.getTypealiasKeyword());
140148
Identifier name;
141149
SourceLoc nameLoc = generateIdentifierDeclName(idToken, Loc, name);
142-
auto attrs = generateDeclAttributes(D, Loc, true);
150+
auto attrs =
151+
generateDeclAttributes(D, D.getAttributes(), D.getModifiers(), Loc, true);
143152
SourceLoc equalLoc;
144153

145154
DebuggerContextChange DCC(P, name, DeclKind::TypeAlias);
@@ -1130,7 +1139,14 @@ GenericParamList *ASTGen::generate(const GenericParameterClauseSyntax &clause,
11301139

11311140
for (auto elem : clause.getGenericParameterList()) {
11321141

1133-
DeclAttributes attrs = generateDeclAttributes(elem, Loc, false);
1142+
DeclAttributes attrs;
1143+
if (auto attrsSyntax = elem.getAttributes()) {
1144+
if (auto firstTok = attrsSyntax->getFirstToken()) {
1145+
auto attrsLoc = advanceLocBegin(Loc, *firstTok);
1146+
if (hasDeclAttributes(attrsLoc))
1147+
attrs = getDeclAttributes(attrsLoc);
1148+
}
1149+
}
11341150
Identifier name = Context.getIdentifier(elem.getName().getIdentifierText());
11351151
SourceLoc nameLoc = advanceLocBegin(Loc, elem.getName());
11361152

lib/Parse/ParseDecl.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,7 +2714,6 @@ Parser::parseDecl(ParseDeclOptions Flags,
27142714
StructureMarkerKind::Declaration);
27152715

27162716
// Parse attributes.
2717-
SourceLoc AttrsLoc = Tok.getLoc();
27182717
DeclAttributes Attributes;
27192718
if (Tok.hasComment())
27202719
Attributes.add(new (Context) RawDocCommentAttr(Tok.getCommentRange()));
@@ -2726,8 +2725,12 @@ Parser::parseDecl(ParseDeclOptions Flags,
27262725
StaticSpellingKind StaticSpelling = StaticSpellingKind::None;
27272726
parseDeclModifierList(Attributes, StaticLoc, StaticSpelling);
27282727

2729-
if (!Attributes.isEmpty())
2730-
Generator.addDeclAttributes(Attributes, AttrsLoc);
2728+
if (!Attributes.isEmpty()) {
2729+
auto startLoc = Attributes.getStartLoc();
2730+
if (startLoc.isInvalid())
2731+
startLoc = Tok.getLoc();
2732+
Generator.addDeclAttributes(Attributes, startLoc);
2733+
}
27312734

27322735
// We emit diagnostics for 'try let ...' in parseDeclVar().
27332736
SourceLoc tryLoc;

lib/Parse/ParseGeneric.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ Parser::parseGenericParameterClauseSyntax() {
7878
SyntaxParsingContext TmpCtxt(SyntaxContext);
7979
TmpCtxt.setTransparent();
8080

81-
auto AttrsLoc = Tok.getLoc();
8281
DeclAttributes attrsAST;
8382
parseDeclAttributeList(attrsAST);
8483
if (!attrsAST.isEmpty())
85-
Generator.addDeclAttributes(attrsAST, AttrsLoc);
84+
Generator.addDeclAttributes(attrsAST, attrsAST.getStartLoc());
8685
auto attrs = SyntaxContext->popIf<ParsedAttributeListSyntax>();
8786
if (attrs)
8887
paramBuilder.useAttributes(std::move(*attrs));

test/Parse/attr_available_ignored.swift

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)