@@ -57,14 +57,21 @@ Decl *ASTGen::generate(const DeclSyntax &D, const SourceLoc Loc) {
57
57
}
58
58
59
59
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 ());
67
72
}
73
+ if (hasDeclAttributes (attrsLoc))
74
+ return getDeclAttributes (attrsLoc);
68
75
return DeclAttributes ();
69
76
}
70
77
@@ -104,7 +111,8 @@ TypeDecl *ASTGen::generate(const AssociatedtypeDeclSyntax &D,
104
111
Identifier name;
105
112
SourceLoc nameLoc = generateIdentifierDeclName (idToken, Loc, name);
106
113
107
- DeclAttributes attrs = generateDeclAttributes (D, Loc, true );
114
+ DeclAttributes attrs =
115
+ generateDeclAttributes (D, D.getAttributes (), D.getModifiers (), Loc, true );
108
116
109
117
DebuggerContextChange DCC (P, name, DeclKind::AssociatedType);
110
118
@@ -139,7 +147,8 @@ TypeDecl *ASTGen::generate(const TypealiasDeclSyntax &D, const SourceLoc Loc) {
139
147
auto keywordLoc = advanceLocBegin (Loc, D.getTypealiasKeyword ());
140
148
Identifier name;
141
149
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 );
143
152
SourceLoc equalLoc;
144
153
145
154
DebuggerContextChange DCC (P, name, DeclKind::TypeAlias);
@@ -1130,7 +1139,14 @@ GenericParamList *ASTGen::generate(const GenericParameterClauseSyntax &clause,
1130
1139
1131
1140
for (auto elem : clause.getGenericParameterList ()) {
1132
1141
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
+ }
1134
1150
Identifier name = Context.getIdentifier (elem.getName ().getIdentifierText ());
1135
1151
SourceLoc nameLoc = advanceLocBegin (Loc, elem.getName ());
1136
1152
0 commit comments