@@ -326,8 +326,11 @@ class alignas(1 << DeclAlignInBits) Decl {
326
326
327
327
// / Whether we are overridden later.
328
328
unsigned Overridden : 1 ;
329
+
330
+ // / Whether the function body throws.
331
+ unsigned Throws : 1 ;
329
332
};
330
- enum { NumAbstractFunctionDeclBits = NumValueDeclBits + 10 };
333
+ enum { NumAbstractFunctionDeclBits = NumValueDeclBits + 11 };
331
334
static_assert (NumAbstractFunctionDeclBits <= 32 , " fits in an unsigned" );
332
335
333
336
class FuncDeclBitfields {
@@ -4573,18 +4576,25 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
4573
4576
4574
4577
CaptureInfo Captures;
4575
4578
4579
+ // / Location of the 'throws' token.
4580
+ SourceLoc ThrowsLoc;
4581
+
4576
4582
ImportAsMemberStatus IAMStatus;
4577
4583
4578
- AbstractFunctionDecl (DeclKind Kind, DeclContext *Parent, DeclName Name,
4579
- SourceLoc NameLoc, unsigned NumParameterLists,
4584
+ AbstractFunctionDecl (DeclKind Kind, DeclContext *Parent,
4585
+ DeclName Name, SourceLoc NameLoc,
4586
+ bool Throws, SourceLoc ThrowsLoc,
4587
+ unsigned NumParameterLists,
4580
4588
GenericParamList *GenericParams)
4581
4589
: ValueDecl(Kind, Parent, Name, NameLoc),
4582
4590
DeclContext (DeclContextKind::AbstractFunctionDecl, Parent),
4583
- Body(nullptr ), GenericParams(nullptr ), GenericSig(nullptr ) {
4591
+ Body(nullptr ), GenericParams(nullptr ), GenericSig(nullptr ),
4592
+ ThrowsLoc(ThrowsLoc) {
4584
4593
setBodyKind (BodyKind::None);
4585
4594
setGenericParams (GenericParams);
4586
4595
AbstractFunctionDeclBits.NumParameterLists = NumParameterLists;
4587
4596
AbstractFunctionDeclBits.Overridden = false ;
4597
+ AbstractFunctionDeclBits.Throws = Throws;
4588
4598
4589
4599
// Verify no bitfield truncation.
4590
4600
assert (AbstractFunctionDeclBits.NumParameterLists == NumParameterLists);
@@ -4617,6 +4627,12 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
4617
4627
void setSelfIndex (uint8_t idx) { return IAMStatus.setSelfIndex (idx); }
4618
4628
4619
4629
public:
4630
+ // / Retrieve the location of the 'throws' keyword, if present.
4631
+ SourceLoc getThrowsLoc () const { return ThrowsLoc; }
4632
+
4633
+ // / Returns true if the function body throws.
4634
+ bool hasThrows () const { return AbstractFunctionDeclBits.Throws ; }
4635
+
4620
4636
// FIXME: Hack that provides names with keyword arguments for accessors.
4621
4637
DeclName getEffectiveFullName () const ;
4622
4638
@@ -4831,9 +4847,6 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
4831
4847
// / Resolved during type checking
4832
4848
void setIsOverridden () { AbstractFunctionDeclBits.Overridden = true ; }
4833
4849
4834
- // / Whether the function body is 'throws'.
4835
- bool isBodyThrowing () const ;
4836
-
4837
4850
// / Set information about the foreign error convention used by this
4838
4851
// / declaration.
4839
4852
void setForeignErrorConvention (const ForeignErrorConvention &convention);
@@ -4876,7 +4889,6 @@ class FuncDecl final : public AbstractFunctionDecl,
4876
4889
4877
4890
SourceLoc StaticLoc; // Location of the 'static' token or invalid.
4878
4891
SourceLoc FuncLoc; // Location of the 'func' token.
4879
- SourceLoc ThrowsLoc; // Location of the 'throws' token.
4880
4892
SourceLoc AccessorKeywordLoc; // Location of the accessor keyword, e.g. 'set'.
4881
4893
4882
4894
TypeLoc FnRetType;
@@ -4901,14 +4913,17 @@ class FuncDecl final : public AbstractFunctionDecl,
4901
4913
AddressorKind> OperatorAndAddressorKind;
4902
4914
4903
4915
FuncDecl (SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
4904
- SourceLoc FuncLoc, DeclName Name,
4905
- SourceLoc NameLoc, SourceLoc ThrowsLoc,
4916
+ SourceLoc FuncLoc,
4917
+ DeclName Name, SourceLoc NameLoc,
4918
+ bool Throws, SourceLoc ThrowsLoc,
4906
4919
SourceLoc AccessorKeywordLoc,
4907
4920
unsigned NumParameterLists,
4908
4921
GenericParamList *GenericParams, Type Ty, DeclContext *Parent)
4909
- : AbstractFunctionDecl(DeclKind::Func, Parent, Name, NameLoc,
4922
+ : AbstractFunctionDecl(DeclKind::Func, Parent,
4923
+ Name, NameLoc,
4924
+ Throws, ThrowsLoc,
4910
4925
NumParameterLists, GenericParams),
4911
- StaticLoc (StaticLoc), FuncLoc(FuncLoc), ThrowsLoc(ThrowsLoc),
4926
+ StaticLoc (StaticLoc), FuncLoc(FuncLoc),
4912
4927
AccessorKeywordLoc(AccessorKeywordLoc),
4913
4928
OverriddenOrDerivedForOrBehaviorParamDecl(),
4914
4929
OperatorAndAddressorKind(nullptr , AddressorKind::NotAddressor) {
@@ -4926,31 +4941,35 @@ class FuncDecl final : public AbstractFunctionDecl,
4926
4941
4927
4942
static FuncDecl *createImpl (ASTContext &Context, SourceLoc StaticLoc,
4928
4943
StaticSpellingKind StaticSpelling,
4929
- SourceLoc FuncLoc, DeclName Name,
4930
- SourceLoc NameLoc, SourceLoc ThrowsLoc,
4944
+ SourceLoc FuncLoc,
4945
+ DeclName Name, SourceLoc NameLoc,
4946
+ bool Throws, SourceLoc ThrowsLoc,
4931
4947
SourceLoc AccessorKeywordLoc,
4932
- GenericParamList *GenericParams, Type Ty,
4933
- unsigned NumParameterLists,
4948
+ GenericParamList *GenericParams,
4949
+ unsigned NumParameterLists, Type Ty,
4934
4950
DeclContext *Parent,
4935
4951
ClangNode ClangN);
4936
4952
4937
4953
public:
4938
4954
// / Factory function only for use by deserialization.
4939
4955
static FuncDecl *createDeserialized (ASTContext &Context, SourceLoc StaticLoc,
4940
4956
StaticSpellingKind StaticSpelling,
4941
- SourceLoc FuncLoc, DeclName Name,
4942
- SourceLoc NameLoc, SourceLoc ThrowsLoc,
4957
+ SourceLoc FuncLoc,
4958
+ DeclName Name, SourceLoc NameLoc,
4959
+ bool Throws, SourceLoc ThrowsLoc,
4943
4960
SourceLoc AccessorKeywordLoc,
4944
- GenericParamList *GenericParams, Type Ty,
4945
- unsigned NumParameterLists,
4961
+ GenericParamList *GenericParams,
4962
+ unsigned NumParameterLists, Type Ty,
4946
4963
DeclContext *Parent);
4947
4964
4948
4965
static FuncDecl *create (ASTContext &Context, SourceLoc StaticLoc,
4949
4966
StaticSpellingKind StaticSpelling,
4950
- SourceLoc FuncLoc, DeclName Name, SourceLoc NameLoc,
4951
- SourceLoc ThrowsLoc, SourceLoc AccessorKeywordLoc,
4967
+ SourceLoc FuncLoc,
4968
+ DeclName Name, SourceLoc NameLoc,
4969
+ bool Throws, SourceLoc ThrowsLoc,
4970
+ SourceLoc AccessorKeywordLoc,
4952
4971
GenericParamList *GenericParams,
4953
- Type Ty, ArrayRef<ParameterList *> ParameterLists,
4972
+ ArrayRef<ParameterList *> ParameterLists, Type Ty ,
4954
4973
TypeLoc FnRetType, DeclContext *Parent,
4955
4974
ClangNode ClangN = ClangNode());
4956
4975
@@ -5013,7 +5032,6 @@ class FuncDecl final : public AbstractFunctionDecl,
5013
5032
5014
5033
SourceLoc getStaticLoc () const { return StaticLoc; }
5015
5034
SourceLoc getFuncLoc () const { return FuncLoc; }
5016
- SourceLoc getThrowsLoc () const { return ThrowsLoc; }
5017
5035
SourceLoc getAccessorKeywordLoc () const {return AccessorKeywordLoc; }
5018
5036
5019
5037
SourceLoc getStartLoc () const {
@@ -5427,9 +5445,6 @@ class ConstructorDecl : public AbstractFunctionDecl {
5427
5445
// / The location of the '!' or '?' for a failable initializer.
5428
5446
SourceLoc FailabilityLoc;
5429
5447
5430
- // Location of the 'throws' token.
5431
- SourceLoc ThrowsLoc;
5432
-
5433
5448
ParameterList *ParameterLists[2 ];
5434
5449
5435
5450
// / The type of the initializing constructor.
@@ -5449,9 +5464,10 @@ class ConstructorDecl : public AbstractFunctionDecl {
5449
5464
public:
5450
5465
ConstructorDecl (DeclName Name, SourceLoc ConstructorLoc,
5451
5466
OptionalTypeKind Failability, SourceLoc FailabilityLoc,
5452
- ParamDecl *selfParam, ParameterList *BodyParams,
5467
+ bool Throws, SourceLoc ThrowsLoc,
5468
+ ParamDecl *SelfParam, ParameterList *BodyParams,
5453
5469
GenericParamList *GenericParams,
5454
- SourceLoc throwsLoc, DeclContext *Parent);
5470
+ DeclContext *Parent);
5455
5471
5456
5472
void setParameterLists (ParamDecl *selfParam, ParameterList *bodyParams);
5457
5473
@@ -5590,9 +5606,6 @@ class ConstructorDecl : public AbstractFunctionDecl {
5590
5606
// / Retrieve the location of the '!' or '?' in a failable initializer.
5591
5607
SourceLoc getFailabilityLoc () const { return FailabilityLoc; }
5592
5608
5593
- // / Retrieve the location of the 'throws' keyword, if present.
5594
- SourceLoc getThrowsLoc () const { return ThrowsLoc; }
5595
-
5596
5609
// / Whether the implementation of this method is a stub that traps at runtime.
5597
5610
bool hasStubImplementation () const {
5598
5611
return ConstructorDeclBits.HasStubImplementation ;
0 commit comments