Skip to content

Commit d75dd44

Browse files
authored
Merge pull request #70495 from hamishknight/decl-the-halls
2 parents ef1f9eb + 0a35e00 commit d75dd44

26 files changed

+1133
-477
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 105 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ namespace swift {
265265
BridgedPattern Bridged##Id##Pattern_asPattern(Bridged##Id##Pattern pattern);
266266
#include "swift/AST/PatternNodes.def"
267267

268+
struct BridgedPatternBindingEntry {
269+
BridgedPattern pattern;
270+
BridgedSourceLoc equalLoc;
271+
BridgedNullableExpr init;
272+
BridgedNullablePatternBindingInitializer initContext;
273+
};
274+
268275
//===----------------------------------------------------------------------===//
269276
// MARK: Diagnostic Engine
270277
//===----------------------------------------------------------------------===//
@@ -371,25 +378,67 @@ void BridgedDiagnostic_fixItReplace(BridgedDiagnostic cDiag,
371378
SWIFT_NAME("BridgedDiagnostic.finish(self:)")
372379
void BridgedDiagnostic_finish(BridgedDiagnostic cDiag);
373380

381+
//===----------------------------------------------------------------------===//
382+
// MARK: DeclContexts
383+
//===----------------------------------------------------------------------===//
384+
385+
SWIFT_NAME("getter:BridgedDeclContext.isLocalContext(self:)")
386+
bool BridgedDeclContext_isLocalContext(BridgedDeclContext cDeclContext);
387+
388+
SWIFT_NAME("BridgedPatternBindingInitializer.create(declContext:)")
389+
BridgedPatternBindingInitializer
390+
BridgedPatternBindingInitializer_create(BridgedDeclContext cDeclContext);
391+
392+
SWIFT_NAME("getter:BridgedPatternBindingInitializer.asDeclContext(self:)")
393+
BridgedDeclContext BridgedPatternBindingInitializer_asDeclContext(
394+
BridgedPatternBindingInitializer cInit);
395+
374396
//===----------------------------------------------------------------------===//
375397
// MARK: Decls
376398
//===----------------------------------------------------------------------===//
377399

400+
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedStaticSpelling {
401+
BridgedStaticSpellingNone,
402+
BridgedStaticSpellingStatic,
403+
BridgedStaticSpellingClass
404+
};
405+
406+
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedAccessorKind {
407+
#define ACCESSOR(ID) BridgedAccessorKind##ID,
408+
#include "swift/AST/AccessorKinds.def"
409+
};
410+
411+
struct BridgedAccessorRecord {
412+
BridgedSourceLoc lBraceLoc;
413+
BridgedArrayRef accessors;
414+
BridgedSourceLoc rBraceLoc;
415+
};
416+
417+
SWIFT_NAME("BridgedAccessorDecl.createParsed(_:declContext:kind:storage:"
418+
"declLoc:accessorKeywordLoc:parameterList:asyncSpecifierLoc:"
419+
"throwsSpecifierLoc:thrownType:)")
420+
BridgedAccessorDecl BridgedAccessorDecl_createParsed(
421+
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
422+
BridgedAccessorKind cKind, BridgedAbstractStorageDecl cStorage,
423+
BridgedSourceLoc cDeclLoc, BridgedSourceLoc cAccessorKeywordLoc,
424+
BridgedNullableParameterList cParamList, BridgedSourceLoc cAsyncLoc,
425+
BridgedSourceLoc cThrowsLoc, BridgedNullableTypeRepr cThrownType);
426+
378427
SWIFT_NAME(
379428
"BridgedPatternBindingDecl.createParsed(_:declContext:bindingKeywordLoc:"
380-
"pattern:initializer:isStatic:isLet:)")
429+
"entries:isStatic:isLet:)")
381430
BridgedPatternBindingDecl BridgedPatternBindingDecl_createParsed(
382431
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
383-
BridgedSourceLoc cBindingKeywordLoc, BridgedPattern pattern,
384-
BridgedExpr opaqueInitExpr, bool isStatic, bool isLet);
432+
BridgedSourceLoc cBindingKeywordLoc, BridgedArrayRef cBindingEntries,
433+
bool isStatic, bool isLet);
385434

386-
SWIFT_NAME("BridgedParamDecl.createParsed(_:declContext:specifierLoc:firstName:"
387-
"firstNameLoc:secondName:secondNameLoc:type:defaultValue:)")
435+
SWIFT_NAME("BridgedParamDecl.createParsed(_:declContext:specifierLoc:argName:"
436+
"argNameLoc:paramName:paramNameLoc:type:defaultValue:)")
388437
BridgedParamDecl BridgedParamDecl_createParsed(
389438
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
390-
BridgedSourceLoc cSpecifierLoc, BridgedIdentifier cFirstName,
391-
BridgedSourceLoc cFirstNameLoc, BridgedIdentifier cSecondName,
392-
BridgedSourceLoc cSecondNameLoc, BridgedNullableTypeRepr type,
439+
BridgedSourceLoc cSpecifierLoc, BridgedIdentifier cArgName,
440+
BridgedSourceLoc cArgNameLoc, BridgedIdentifier cParamName,
441+
BridgedSourceLoc cParamNameLoc, BridgedNullableTypeRepr type,
393442
BridgedNullableExpr defaultValue);
394443

395444
SWIFT_NAME("BridgedConstructorDecl.setParsedBody(self:_:)")
@@ -588,6 +637,17 @@ BridgedImportDecl BridgedImportDecl_createParsed(
588637
BridgedSourceLoc cImportKeywordLoc, BridgedImportKind cImportKind,
589638
BridgedSourceLoc cImportKindLoc, BridgedArrayRef cImportPathElements);
590639

640+
SWIFT_NAME("BridgedSubscriptDecl.createParsed(_:declContext:staticLoc:"
641+
"staticSpelling:subscriptKeywordLoc:genericParamList:parameterList:"
642+
"arrowLoc:returnType:)")
643+
BridgedSubscriptDecl BridgedSubscriptDecl_createParsed(
644+
BridgedASTContext cContext, BridgedDeclContext cDeclContext,
645+
BridgedSourceLoc cStaticLoc, BridgedStaticSpelling cStaticSpelling,
646+
BridgedSourceLoc cSubscriptKeywordLoc,
647+
BridgedNullableGenericParamList cGenericParamList,
648+
BridgedParameterList cParamList, BridgedSourceLoc cArrowLoc,
649+
BridgedTypeRepr returnType);
650+
591651
SWIFT_NAME(
592652
"BridgedTopLevelCodeDecl.createParsed(_:declContext:startLoc:stmt:endLoc:)")
593653
BridgedTopLevelCodeDecl BridgedTopLevelCodeDecl_createStmt(
@@ -608,6 +668,22 @@ void BridgedTopLevelCodeDecl_dump(BridgedTopLevelCodeDecl decl);
608668
SWIFT_NAME("BridgedDecl.dump(self:)")
609669
void BridgedDecl_dump(BridgedDecl decl);
610670

671+
//===----------------------------------------------------------------------===//
672+
// MARK: AbstractStorageDecl
673+
//===----------------------------------------------------------------------===//
674+
675+
SWIFT_NAME("BridgedAbstractStorageDecl.setAccessors(self:_:)")
676+
void BridgedAbstractStorageDecl_setAccessors(
677+
BridgedAbstractStorageDecl cStorage, BridgedAccessorRecord accessors);
678+
679+
//===----------------------------------------------------------------------===//
680+
// MARK: AccessorDecl
681+
//===----------------------------------------------------------------------===//
682+
683+
SWIFT_NAME("BridgedAccessorDecl.setParsedBody(self:_:)")
684+
void BridgedAccessorDecl_setParsedBody(BridgedAccessorDecl decl,
685+
BridgedBraceStmt body);
686+
611687
//===----------------------------------------------------------------------===//
612688
// MARK: NominalTypeDecl
613689
//===----------------------------------------------------------------------===//
@@ -632,6 +708,15 @@ SWIFT_NAME("BridgedNominalTypeDecl.setParsedMembers(self:_:)")
632708
void BridgedNominalTypeDecl_setParsedMembers(BridgedNominalTypeDecl decl,
633709
BridgedArrayRef members);
634710

711+
//===----------------------------------------------------------------------===//
712+
// MARK: SubscriptDecl
713+
//===----------------------------------------------------------------------===//
714+
715+
SWIFT_NAME("getter:BridgedSubscriptDecl.asAbstractStorageDecl(self:)")
716+
BRIDGED_INLINE
717+
BridgedAbstractStorageDecl
718+
BridgedSubscriptDecl_asAbstractStorageDecl(BridgedSubscriptDecl decl);
719+
635720
//===----------------------------------------------------------------------===//
636721
// MARK: VarDecl
637722
//===----------------------------------------------------------------------===//
@@ -640,6 +725,11 @@ SWIFT_NAME("BridgedVarDecl.getUserFacingName(self:)")
640725
BRIDGED_INLINE
641726
BridgedStringRef BridgedVarDecl_getUserFacingName(BridgedVarDecl decl);
642727

728+
SWIFT_NAME("getter:BridgedVarDecl.asAbstractStorageDecl(self:)")
729+
BRIDGED_INLINE
730+
BridgedAbstractStorageDecl
731+
BridgedVarDecl_asAbstractStorageDecl(BridgedVarDecl decl);
732+
643733
//===----------------------------------------------------------------------===//
644734
// MARK: Exprs
645735
//===----------------------------------------------------------------------===//
@@ -1111,6 +1201,9 @@ void BridgedTypeRepr_dump(BridgedTypeRepr type);
11111201
// MARK: Patterns
11121202
//===----------------------------------------------------------------------===//
11131203

1204+
SWIFT_NAME("getter:BridgedPattern.singleVar(self:)")
1205+
BridgedNullableVarDecl BridgedPattern_getSingleVar(BridgedPattern cPattern);
1206+
11141207
SWIFT_NAME("BridgedAnyPattern.createParsed(_:loc:)")
11151208
BridgedAnyPattern BridgedAnyPattern_createParsed(BridgedASTContext cContext,
11161209
BridgedSourceLoc cLoc);
@@ -1159,6 +1252,10 @@ BridgedTypedPattern BridgedTypedPattern_createParsed(BridgedASTContext cContext,
11591252
BridgedPattern cPattern,
11601253
BridgedTypeRepr cType);
11611254

1255+
SWIFT_NAME("BridgedTypedPattern.createPropagated(_:pattern:type:)")
1256+
BridgedTypedPattern BridgedTypedPattern_createPropagated(
1257+
BridgedASTContext cContext, BridgedPattern cPattern, BridgedTypeRepr cType);
1258+
11621259
//===----------------------------------------------------------------------===//
11631260
// MARK: Misc
11641261
//===----------------------------------------------------------------------===//

include/swift/AST/ASTBridgingImpl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ bool BridgedNominalTypeDecl_hasValueDeinit(BridgedNominalTypeDecl decl) {
4545
return decl.unbridged()->getValueTypeDestructor() != nullptr;
4646
}
4747

48+
//===----------------------------------------------------------------------===//
49+
// MARK: BridgedSubscriptDecl
50+
//===----------------------------------------------------------------------===//
51+
52+
BridgedAbstractStorageDecl
53+
BridgedSubscriptDecl_asAbstractStorageDecl(BridgedSubscriptDecl decl) {
54+
return decl.unbridged();
55+
}
56+
4857
//===----------------------------------------------------------------------===//
4958
// MARK: BridgedVarDecl
5059
//===----------------------------------------------------------------------===//
@@ -53,6 +62,11 @@ BridgedStringRef BridgedVarDecl_getUserFacingName(BridgedVarDecl decl) {
5362
return decl.unbridged()->getBaseName().userFacingName();
5463
}
5564

65+
BridgedAbstractStorageDecl
66+
BridgedVarDecl_asAbstractStorageDecl(BridgedVarDecl decl) {
67+
return decl.unbridged();
68+
}
69+
5670
SWIFT_END_NULLABILITY_ANNOTATIONS
5771

5872
#endif // SWIFT_AST_ASTBRIDGINGIMPL_H

include/swift/AST/ASTBridgingWrappers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ AST_BRIDGING_WRAPPER_NULLABLE(TypeRepr)
7474
AST_BRIDGING_WRAPPER_NULLABLE(GenericParamList)
7575
AST_BRIDGING_WRAPPER_NULLABLE(TrailingWhereClause)
7676
AST_BRIDGING_WRAPPER_NULLABLE(ParameterList)
77+
AST_BRIDGING_WRAPPER_NULLABLE(PatternBindingInitializer)
7778
AST_BRIDGING_WRAPPER_NONNULL(TypeAttributes)
7879
AST_BRIDGING_WRAPPER_NONNULL(CustomAttribute)
7980

include/swift/AST/Decl.h

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6814,7 +6814,6 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
68146814

68156815
SourceLoc StaticLoc;
68166816
SourceLoc ArrowLoc;
6817-
SourceLoc EndLoc;
68186817
ParameterList *Indices;
68196818
TypeLoc ElementTy;
68206819

@@ -6843,13 +6842,12 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
68436842
Type ElementTy, DeclContext *Parent,
68446843
GenericParamList *GenericParams);
68456844

6846-
static SubscriptDecl *create(ASTContext &Context, DeclName Name,
6847-
SourceLoc StaticLoc,
6848-
StaticSpellingKind StaticSpelling,
6849-
SourceLoc SubscriptLoc, ParameterList *Indices,
6850-
SourceLoc ArrowLoc, TypeRepr *ElementTyR,
6851-
DeclContext *Parent,
6852-
GenericParamList *GenericParams);
6845+
static SubscriptDecl *createParsed(ASTContext &Context, SourceLoc StaticLoc,
6846+
StaticSpellingKind StaticSpelling,
6847+
SourceLoc SubscriptLoc,
6848+
ParameterList *Indices, SourceLoc ArrowLoc,
6849+
TypeRepr *ElementTyR, DeclContext *Parent,
6850+
GenericParamList *GenericParams);
68536851

68546852
static SubscriptDecl *create(ASTContext &Context, DeclName Name,
68556853
SourceLoc StaticLoc,
@@ -6874,13 +6872,7 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
68746872

68756873
SourceLoc getStaticLoc() const { return StaticLoc; }
68766874
SourceLoc getSubscriptLoc() const { return getNameLoc(); }
6877-
6878-
SourceLoc getStartLoc() const {
6879-
return getStaticLoc().isValid() ? getStaticLoc() : getSubscriptLoc();
6880-
}
6881-
SourceLoc getEndLoc() const { return EndLoc; }
68826875

6883-
void setEndLoc(SourceLoc sl) { EndLoc = sl; }
68846876
SourceRange getSourceRange() const;
68856877
SourceRange getSignatureSourceRange() const;
68866878

@@ -7886,6 +7878,23 @@ class AccessorDecl final : public FuncDecl {
78867878
TypeLoc thrownType, ParameterList *parameterList, Type fnRetType,
78877879
DeclContext *parent, ClangNode clangNode = ClangNode());
78887880

7881+
/// Create a parsed accessor.
7882+
///
7883+
/// \param paramList A parameter list for e.g \c set(newValue), or \c nullptr
7884+
/// if the accessor doesn't have any user-specified arguments.
7885+
static AccessorDecl *createParsed(ASTContext &ctx, AccessorKind accessorKind,
7886+
AbstractStorageDecl *storage,
7887+
SourceLoc declLoc,
7888+
SourceLoc accessorKeywordLoc,
7889+
ParameterList *paramList,
7890+
SourceLoc asyncLoc, SourceLoc throwsLoc,
7891+
TypeRepr *thrownType, DeclContext *dc);
7892+
7893+
/// Retrieve the implicit parameter name for the given accessor kind (e.g
7894+
/// \c oldValue for `didSet`, `newValue` for `set`), or an empty string if
7895+
/// the kind does not have an implicit parameter name.
7896+
static StringRef implicitParameterNameFor(AccessorKind kind);
7897+
78897898
SourceLoc getAccessorKeywordLoc() const { return AccessorKeywordLoc; }
78907899

78917900
AbstractStorageDecl *getStorage() const {

include/swift/AST/Pattern.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,13 @@ class TypedPattern : public Pattern {
447447
return tp;
448448
}
449449

450+
static TypedPattern *createPropagated(ASTContext &ctx, Pattern *pattern,
451+
TypeRepr *typeRepr) {
452+
auto *TP = new (ctx) TypedPattern(pattern, typeRepr);
453+
TP->setPropagatedType();
454+
return TP;
455+
}
456+
450457
/// True if the type in this \c TypedPattern was propagated from a different
451458
/// \c TypedPattern.
452459
///

include/swift/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ class Parser {
12701270

12711271
bool parseAccessorAfterIntroducer(
12721272
SourceLoc Loc, AccessorKind Kind, ParsedAccessors &accessors,
1273-
bool &hasEffectfulGet, ParameterList *Indices, bool &parsingLimitedSyntax,
1273+
bool &hasEffectfulGet, bool &parsingLimitedSyntax,
12741274
DeclAttributes &Attributes, ParseDeclOptions Flags,
12751275
AbstractStorageDecl *storage, ParserStatus &Status);
12761276

0 commit comments

Comments
 (0)