@@ -92,7 +92,8 @@ static Type containsParameterizedProtocolType(Type inheritedTy) {
92
92
// / file.
93
93
static void checkInheritanceClause (
94
94
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> declUnion) {
95
- auto inheritedClause = InheritedTypes (declUnion).getEntries ();
95
+ auto inheritedTypes = InheritedTypes (declUnion);
96
+ auto inheritedClause = inheritedTypes.getEntries ();
96
97
const ExtensionDecl *ext = nullptr ;
97
98
const TypeDecl *typeDecl = nullptr ;
98
99
const Decl *decl;
@@ -123,45 +124,6 @@ static void checkInheritanceClause(
123
124
ASTContext &ctx = decl->getASTContext ();
124
125
auto &diags = ctx.Diags ;
125
126
126
- // Retrieve the location of the start of the inheritance clause.
127
- auto getStartLocOfInheritanceClause = [&] {
128
- if (ext)
129
- return ext->getSourceRange ().End ;
130
-
131
- return typeDecl->getNameLoc ();
132
- };
133
-
134
- // Compute the source range to be used when removing something from an
135
- // inheritance clause.
136
- auto getRemovalRange = [&](unsigned i) {
137
- // If there is just one entry, remove the entire inheritance clause.
138
- if (inheritedClause.size () == 1 ) {
139
- SourceLoc start = getStartLocOfInheritanceClause ();
140
- SourceLoc end = inheritedClause[i].getSourceRange ().End ;
141
- return SourceRange (Lexer::getLocForEndOfToken (ctx.SourceMgr , start),
142
- Lexer::getLocForEndOfToken (ctx.SourceMgr , end));
143
- }
144
-
145
- // If we're at the first entry, remove from the start of this entry to the
146
- // start of the next entry.
147
- if (i == 0 ) {
148
- return SourceRange (inheritedClause[i].getSourceRange ().Start ,
149
- inheritedClause[i+1 ].getSourceRange ().Start );
150
- }
151
-
152
- // Otherwise, remove from the end of the previous entry to the end of this
153
- // entry.
154
- SourceLoc afterPriorLoc =
155
- Lexer::getLocForEndOfToken (ctx.SourceMgr ,
156
- inheritedClause[i-1 ].getSourceRange ().End );
157
-
158
- SourceLoc afterMyEndLoc =
159
- Lexer::getLocForEndOfToken (ctx.SourceMgr ,
160
- inheritedClause[i].getSourceRange ().End );
161
-
162
- return SourceRange (afterPriorLoc, afterMyEndLoc);
163
- };
164
-
165
127
// Check all of the types listed in the inheritance clause.
166
128
Type superclassTy;
167
129
SourceRange superclassRange;
@@ -210,7 +172,7 @@ static void checkInheritanceClause(
210
172
// Swift <= 4.
211
173
auto knownIndex = inheritedAnyObject->first ;
212
174
auto knownRange = inheritedAnyObject->second ;
213
- SourceRange removeRange = getRemovalRange (knownIndex);
175
+ SourceRange removeRange = inheritedTypes. getRemovalRange (knownIndex);
214
176
if (!ctx.LangOpts .isSwiftVersionAtLeast (5 ) &&
215
177
isa<ProtocolDecl>(decl) &&
216
178
Lexer::getTokenAtLocation (ctx.SourceMgr , knownRange.Start )
@@ -278,7 +240,7 @@ static void checkInheritanceClause(
278
240
// Check if we already had a raw type.
279
241
if (superclassTy) {
280
242
if (superclassTy->isEqual (inheritedTy)) {
281
- auto removeRange = getRemovalRange (i);
243
+ auto removeRange = inheritedTypes. getRemovalRange (i);
282
244
diags.diagnose (inherited.getSourceRange ().Start ,
283
245
diag::duplicate_inheritance, inheritedTy)
284
246
.fixItRemoveChars (removeRange.Start , removeRange.End );
@@ -305,7 +267,7 @@ static void checkInheritanceClause(
305
267
306
268
// If this is not the first entry in the inheritance clause, complain.
307
269
if (i > 0 ) {
308
- auto removeRange = getRemovalRange (i);
270
+ auto removeRange = inheritedTypes. getRemovalRange (i);
309
271
310
272
diags.diagnose (inherited.getSourceRange ().Start ,
311
273
diag::raw_type_not_first, inheritedTy)
@@ -330,7 +292,7 @@ static void checkInheritanceClause(
330
292
331
293
if (superclassTy->isEqual (inheritedTy)) {
332
294
// Duplicate superclass.
333
- auto removeRange = getRemovalRange (i);
295
+ auto removeRange = inheritedTypes. getRemovalRange (i);
334
296
diags.diagnose (inherited.getSourceRange ().Start ,
335
297
diag::duplicate_inheritance, inheritedTy)
336
298
.fixItRemoveChars (removeRange.Start , removeRange.End );
@@ -346,7 +308,7 @@ static void checkInheritanceClause(
346
308
347
309
// If this is not the first entry in the inheritance clause, complain.
348
310
if (isa<ClassDecl>(decl) && i > 0 ) {
349
- auto removeRange = getRemovalRange (i);
311
+ auto removeRange = inheritedTypes. getRemovalRange (i);
350
312
diags.diagnose (inherited.getSourceRange ().Start ,
351
313
diag::superclass_not_first, inheritedTy)
352
314
.fixItRemoveChars (removeRange.Start , removeRange.End )
0 commit comments