@@ -676,6 +676,7 @@ class alignas(1 << DeclAlignInBits) Decl {
676
676
677
677
Decl (const Decl&) = delete ;
678
678
void operator =(const Decl&) = delete ;
679
+ SourceLoc getLocFromSource () const ;
679
680
680
681
protected:
681
682
@@ -1582,7 +1583,7 @@ enum class ImportKind : uint8_t {
1582
1583
class ImportDecl final : public Decl,
1583
1584
private llvm::TrailingObjects<ImportDecl, std::pair<Identifier,SourceLoc>> {
1584
1585
friend TrailingObjects;
1585
-
1586
+ friend class Decl ;
1586
1587
public:
1587
1588
typedef std::pair<Identifier, SourceLoc> AccessPathElement;
1588
1589
@@ -1654,7 +1655,7 @@ class ImportDecl final : public Decl,
1654
1655
}
1655
1656
1656
1657
SourceLoc getStartLoc () const { return ImportLoc; }
1657
- SourceLoc getLoc () const { return getFullAccessPath ().front ().second ; }
1658
+ SourceLoc getLocFromSource () const { return getFullAccessPath ().front ().second ; }
1658
1659
SourceRange getSourceRange () const {
1659
1660
return SourceRange (ImportLoc, getFullAccessPath ().back ().second );
1660
1661
}
@@ -1716,6 +1717,7 @@ class ExtensionDecl final : public GenericContext, public Decl,
1716
1717
std::pair<LazyMemberLoader *, uint64_t > takeConformanceLoaderSlow ();
1717
1718
1718
1719
friend class ExtendedNominalRequest ;
1720
+ friend class Decl ;
1719
1721
public:
1720
1722
using Decl::getASTContext;
1721
1723
@@ -1728,7 +1730,7 @@ class ExtensionDecl final : public GenericContext, public Decl,
1728
1730
ClangNode clangNode = ClangNode());
1729
1731
1730
1732
SourceLoc getStartLoc () const { return ExtensionLoc; }
1731
- SourceLoc getLoc () const { return ExtensionLoc; }
1733
+ SourceLoc getLocFromSource () const { return ExtensionLoc; }
1732
1734
SourceRange getSourceRange () const {
1733
1735
return { ExtensionLoc, Braces.End };
1734
1736
}
@@ -2041,7 +2043,7 @@ class PatternBindingEntry {
2041
2043
class PatternBindingDecl final : public Decl,
2042
2044
private llvm::TrailingObjects<PatternBindingDecl, PatternBindingEntry> {
2043
2045
friend TrailingObjects;
2044
-
2046
+ friend class Decl ;
2045
2047
SourceLoc StaticLoc; // /< Location of the 'static/class' keyword, if present.
2046
2048
SourceLoc VarLoc; // /< Location of the 'var' keyword.
2047
2049
@@ -2050,7 +2052,7 @@ class PatternBindingDecl final : public Decl,
2050
2052
PatternBindingDecl (SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
2051
2053
SourceLoc VarLoc, unsigned NumPatternEntries,
2052
2054
DeclContext *Parent);
2053
-
2055
+ SourceLoc getLocFromSource () const { return VarLoc; }
2054
2056
public:
2055
2057
static PatternBindingDecl *create (ASTContext &Ctx, SourceLoc StaticLoc,
2056
2058
StaticSpellingKind StaticSpelling,
@@ -2080,7 +2082,6 @@ class PatternBindingDecl final : public Decl,
2080
2082
SourceLoc getStartLoc () const {
2081
2083
return StaticLoc.isValid () ? StaticLoc : VarLoc;
2082
2084
}
2083
- SourceLoc getLoc () const { return VarLoc; }
2084
2085
SourceRange getSourceRange () const ;
2085
2086
2086
2087
unsigned getNumPatternEntries () const {
@@ -2216,7 +2217,8 @@ class PatternBindingDecl final : public Decl,
2216
2217
// / global variables.
2217
2218
class TopLevelCodeDecl : public DeclContext , public Decl {
2218
2219
BraceStmt *Body;
2219
-
2220
+ SourceLoc getLocFromSource () const { return getStartLoc (); }
2221
+ friend class Decl ;
2220
2222
public:
2221
2223
TopLevelCodeDecl (DeclContext *Parent, BraceStmt *Body = nullptr )
2222
2224
: DeclContext(DeclContextKind::TopLevelCodeDecl, Parent),
@@ -2227,7 +2229,6 @@ class TopLevelCodeDecl : public DeclContext, public Decl {
2227
2229
void setBody (BraceStmt *b) { Body = b; }
2228
2230
2229
2231
SourceLoc getStartLoc () const ;
2230
- SourceLoc getLoc () const { return getStartLoc (); }
2231
2232
SourceRange getSourceRange () const ;
2232
2233
2233
2234
static bool classof (const Decl *D) {
@@ -2266,6 +2267,8 @@ class IfConfigDecl : public Decl {
2266
2267
// / The array is ASTContext allocated.
2267
2268
ArrayRef<IfConfigClause> Clauses;
2268
2269
SourceLoc EndLoc;
2270
+ SourceLoc getLocFromSource () const { return Clauses[0 ].Loc ; }
2271
+ friend class Decl ;
2269
2272
public:
2270
2273
2271
2274
IfConfigDecl (DeclContext *Parent, ArrayRef<IfConfigClause> Clauses,
@@ -2291,7 +2294,6 @@ class IfConfigDecl : public Decl {
2291
2294
}
2292
2295
2293
2296
SourceLoc getEndLoc () const { return EndLoc; }
2294
- SourceLoc getLoc () const { return Clauses[0 ].Loc ; }
2295
2297
2296
2298
bool hadMissingEnd () const { return Bits.IfConfigDecl .HadMissingEnd ; }
2297
2299
@@ -2308,7 +2310,8 @@ class PoundDiagnosticDecl : public Decl {
2308
2310
SourceLoc StartLoc;
2309
2311
SourceLoc EndLoc;
2310
2312
StringLiteralExpr *Message;
2311
-
2313
+ SourceLoc getLocFromSource () const { return StartLoc; }
2314
+ friend class Decl ;
2312
2315
public:
2313
2316
PoundDiagnosticDecl (DeclContext *Parent, bool IsError, SourceLoc StartLoc,
2314
2317
SourceLoc EndLoc, StringLiteralExpr *Message)
@@ -2337,7 +2340,6 @@ class PoundDiagnosticDecl : public Decl {
2337
2340
}
2338
2341
2339
2342
SourceLoc getEndLoc () const { return EndLoc; };
2340
- SourceLoc getLoc () const { return StartLoc; }
2341
2343
2342
2344
SourceRange getSourceRange () const {
2343
2345
return SourceRange (StartLoc, EndLoc);
@@ -2400,7 +2402,8 @@ class ValueDecl : public Decl {
2400
2402
friend class IsFinalRequest ;
2401
2403
friend class IsDynamicRequest ;
2402
2404
friend class IsImplicitlyUnwrappedOptionalRequest ;
2403
-
2405
+ friend class Decl ;
2406
+ SourceLoc getLocFromSource () const { return NameLoc; }
2404
2407
protected:
2405
2408
ValueDecl (DeclKind K,
2406
2409
llvm::PointerUnion<DeclContext *, ASTContext *> context,
@@ -2473,7 +2476,6 @@ class ValueDecl : public Decl {
2473
2476
bool canInferObjCFromRequirement (ValueDecl *requirement);
2474
2477
2475
2478
SourceLoc getNameLoc () const { return NameLoc; }
2476
- SourceLoc getLoc () const { return NameLoc; }
2477
2479
2478
2480
bool isUsableFromInline () const ;
2479
2481
@@ -5689,7 +5691,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5689
5691
// / Note that a true return value does not imply that the body was actually
5690
5692
// / parsed.
5691
5693
bool hasBody () const {
5692
- return getBodyKind () != BodyKind::None;
5694
+ return getBodyKind () != BodyKind::None &&
5695
+ getBodyKind () != BodyKind::Skipped;
5693
5696
}
5694
5697
5695
5698
// / Returns true if the text of this function's body can be retrieved either
@@ -5716,14 +5719,22 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5716
5719
// / Note that the body was skipped for this function. Function body
5717
5720
// / cannot be attached after this call.
5718
5721
void setBodySkipped (SourceRange bodyRange) {
5719
- assert (getBodyKind () == BodyKind::None);
5722
+ // FIXME: Remove 'Parsed' from this once we can delay parsing function
5723
+ // bodies. Right now -experimental-skip-non-inlinable-function-bodies
5724
+ // requires being able to change the state from Parsed to Skipped,
5725
+ // because we're still eagerly parsing function bodies.
5726
+ assert (getBodyKind () == BodyKind::None ||
5727
+ getBodyKind () == BodyKind::Unparsed ||
5728
+ getBodyKind () == BodyKind::Parsed);
5729
+ assert (bodyRange.isValid ());
5720
5730
BodyRange = bodyRange;
5721
5731
setBodyKind (BodyKind::Skipped);
5722
5732
}
5723
5733
5724
5734
// / Note that parsing for the body was delayed.
5725
5735
void setBodyDelayed (SourceRange bodyRange) {
5726
5736
assert (getBodyKind () == BodyKind::None);
5737
+ assert (bodyRange.isValid ());
5727
5738
BodyRange = bodyRange;
5728
5739
setBodyKind (BodyKind::Unparsed);
5729
5740
}
@@ -5769,6 +5780,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5769
5780
return getBodyKind () == BodyKind::TypeChecked;
5770
5781
}
5771
5782
5783
+ bool isBodySkipped () const {
5784
+ return getBodyKind () == BodyKind::Skipped;
5785
+ }
5786
+
5772
5787
bool isMemberwiseInitializer () const {
5773
5788
return getBodyKind () == BodyKind::MemberwiseInitializer;
5774
5789
}
@@ -6268,6 +6283,7 @@ AbstractStorageDecl::AccessorRecord::getAccessor(AccessorKind kind) const {
6268
6283
class EnumCaseDecl final : public Decl,
6269
6284
private llvm::TrailingObjects<EnumCaseDecl, EnumElementDecl *> {
6270
6285
friend TrailingObjects;
6286
+ friend class Decl ;
6271
6287
SourceLoc CaseLoc;
6272
6288
6273
6289
EnumCaseDecl (SourceLoc CaseLoc,
@@ -6280,6 +6296,7 @@ class EnumCaseDecl final : public Decl,
6280
6296
std::uninitialized_copy (Elements.begin (), Elements.end (),
6281
6297
getTrailingObjects<EnumElementDecl *>());
6282
6298
}
6299
+ SourceLoc getLocFromSource () const { return CaseLoc; }
6283
6300
6284
6301
public:
6285
6302
static EnumCaseDecl *create (SourceLoc CaseLoc,
@@ -6291,11 +6308,6 @@ class EnumCaseDecl final : public Decl,
6291
6308
return {getTrailingObjects<EnumElementDecl *>(),
6292
6309
Bits.EnumCaseDecl .NumElements };
6293
6310
}
6294
-
6295
- SourceLoc getLoc () const {
6296
- return CaseLoc;
6297
- }
6298
-
6299
6311
SourceRange getSourceRange () const ;
6300
6312
6301
6313
static bool classof (const Decl *D) {
@@ -6708,7 +6720,8 @@ class PrecedenceGroupDecl : public Decl {
6708
6720
SourceLoc higherThanLoc, ArrayRef<Relation> higherThan,
6709
6721
SourceLoc lowerThanLoc, ArrayRef<Relation> lowerThan,
6710
6722
SourceLoc rbraceLoc);
6711
-
6723
+ friend class Decl ;
6724
+ SourceLoc getLocFromSource () const { return NameLoc; }
6712
6725
public:
6713
6726
static PrecedenceGroupDecl *create (DeclContext *dc,
6714
6727
SourceLoc precedenceGroupLoc,
@@ -6728,7 +6741,6 @@ class PrecedenceGroupDecl : public Decl {
6728
6741
SourceLoc rbraceLoc);
6729
6742
6730
6743
6731
- SourceLoc getLoc () const { return NameLoc; }
6732
6744
SourceRange getSourceRange () const {
6733
6745
return { PrecedenceGroupLoc, RBraceLoc };
6734
6746
}
@@ -6847,7 +6859,8 @@ class OperatorDecl : public Decl {
6847
6859
ArrayRef<Identifier> Identifiers;
6848
6860
ArrayRef<SourceLoc> IdentifierLocs;
6849
6861
ArrayRef<NominalTypeDecl *> DesignatedNominalTypes;
6850
-
6862
+ SourceLoc getLocFromSource () const { return NameLoc; }
6863
+ friend class Decl ;
6851
6864
public:
6852
6865
OperatorDecl (DeclKind kind, DeclContext *DC, SourceLoc OperatorLoc,
6853
6866
Identifier Name, SourceLoc NameLoc,
@@ -6862,7 +6875,6 @@ class OperatorDecl : public Decl {
6862
6875
: Decl(kind, DC), OperatorLoc(OperatorLoc), NameLoc(NameLoc), name(Name),
6863
6876
DesignatedNominalTypes(DesignatedNominalTypes) {}
6864
6877
6865
- SourceLoc getLoc () const { return NameLoc; }
6866
6878
6867
6879
SourceLoc getOperatorLoc () const { return OperatorLoc; }
6868
6880
SourceLoc getNameLoc () const { return NameLoc; }
@@ -7025,6 +7037,10 @@ class MissingMemberDecl : public Decl {
7025
7037
&& " not enough bits" );
7026
7038
setImplicit ();
7027
7039
}
7040
+ friend class Decl ;
7041
+ SourceLoc getLocFromSource () const {
7042
+ return SourceLoc ();
7043
+ }
7028
7044
public:
7029
7045
static MissingMemberDecl *
7030
7046
create (ASTContext &ctx, DeclContext *DC, DeclName name,
@@ -7049,10 +7065,6 @@ class MissingMemberDecl : public Decl {
7049
7065
return Bits.MissingMemberDecl .NumberOfFieldOffsetVectorEntries ;
7050
7066
}
7051
7067
7052
- SourceLoc getLoc () const {
7053
- return SourceLoc ();
7054
- }
7055
-
7056
7068
SourceRange getSourceRange () const {
7057
7069
return SourceRange ();
7058
7070
}
0 commit comments