Skip to content

Commit d00f45a

Browse files
committed
[AST] Switch FuncDecl::get{Start,End}Loc to using early return
1 parent 839e20b commit d00f45a

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8412,6 +8412,7 @@ class FuncDecl : public AbstractFunctionDecl {
84128412
SourceLoc getFuncLoc() const { return FuncLoc; }
84138413

84148414
SourceLoc getStartLoc() const;
8415+
SourceLoc getEndLoc() const;
84158416
SourceRange getSourceRange() const;
84168417

84178418
TypeRepr *getResultTypeRepr() const { return FnRetType.getTypeRepr(); }

lib/AST/Decl.cpp

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11458,40 +11458,61 @@ DestructorDecl *DestructorDecl::getSuperDeinit() const {
1145811458
}
1145911459

1146011460
SourceLoc FuncDecl::getStartLoc() const {
11461-
auto startLoc = StaticLoc;
11462-
if (startLoc.isInvalid())
11463-
startLoc = FuncLoc;
11464-
if (startLoc.isInvalid())
11465-
startLoc = getNameLoc();
11466-
if (startLoc.isInvalid())
11467-
startLoc = getSignatureSourceRange().Start;
11468-
if (startLoc.isInvalid())
11469-
startLoc = getResultTypeSourceRange().Start;
11470-
if (startLoc.isInvalid())
11471-
startLoc = getGenericTrailingWhereClauseSourceRange().Start;
11472-
if (startLoc.isInvalid())
11473-
startLoc = getOriginalBodySourceRange().Start;
11461+
if (StaticLoc)
11462+
return StaticLoc;
1147411463

11475-
return startLoc;
11464+
if (FuncLoc)
11465+
return FuncLoc;
11466+
11467+
auto nameLoc = getNameLoc();
11468+
if (nameLoc)
11469+
return nameLoc;
11470+
11471+
auto sigStart = getSignatureSourceRange().Start;
11472+
if (sigStart)
11473+
return sigStart;
11474+
11475+
auto resultTyStart = getResultTypeSourceRange().Start;
11476+
if (resultTyStart)
11477+
return resultTyStart;
11478+
11479+
auto genericWhereStart = getGenericTrailingWhereClauseSourceRange().Start;
11480+
if (genericWhereStart)
11481+
return genericWhereStart;
11482+
11483+
auto bodyStart = getOriginalBodySourceRange().Start;
11484+
if (bodyStart)
11485+
return bodyStart;
11486+
11487+
return SourceLoc();
11488+
}
11489+
11490+
SourceLoc FuncDecl::getEndLoc() const {
11491+
auto bodyEnd = getOriginalBodySourceRange().End;
11492+
if (bodyEnd)
11493+
return bodyEnd;
11494+
11495+
auto genericWhereEnd = getGenericTrailingWhereClauseSourceRange().End;
11496+
if (genericWhereEnd)
11497+
return genericWhereEnd;
11498+
11499+
auto resultTyEnd = getResultTypeSourceRange().End;
11500+
if (resultTyEnd)
11501+
return resultTyEnd;
11502+
11503+
auto sigEnd = getSignatureSourceRange().End;
11504+
if (sigEnd)
11505+
return sigEnd;
11506+
11507+
return getStartLoc();
1147611508
}
1147711509

1147811510
SourceRange FuncDecl::getSourceRange() const {
1147911511
SourceLoc startLoc = getStartLoc();
11480-
1148111512
if (startLoc.isInvalid())
1148211513
return SourceRange();
1148311514

11484-
SourceLoc endLoc = getOriginalBodySourceRange().End;
11485-
if (endLoc.isInvalid())
11486-
endLoc = getGenericTrailingWhereClauseSourceRange().End;
11487-
if (endLoc.isInvalid())
11488-
endLoc = getResultTypeSourceRange().End;
11489-
if (endLoc.isInvalid())
11490-
endLoc = getSignatureSourceRange().End;
11491-
if (endLoc.isInvalid())
11492-
endLoc = startLoc;
11493-
11494-
return { startLoc, endLoc };
11515+
return { startLoc, getEndLoc() };
1149511516
}
1149611517

1149711518
EnumElementDecl::EnumElementDecl(SourceLoc IdentifierLoc, DeclName Name,

0 commit comments

Comments
 (0)