@@ -2224,8 +2224,11 @@ void PrintAST::printMembers(ArrayRef<Decl *> members, bool needComma,
2224
2224
2225
2225
void PrintAST::printGenericDeclGenericParams (GenericContext *decl) {
2226
2226
if (decl->isGeneric ())
2227
- if (auto GenericSig = decl->getGenericSignature ())
2227
+ if (auto GenericSig = decl->getGenericSignature ()) {
2228
+ Printer.printStructurePre (PrintStructureKind::DeclGenericParameterClause);
2228
2229
printGenericSignature (GenericSig, PrintParams | InnermostOnly);
2230
+ Printer.printStructurePost (PrintStructureKind::DeclGenericParameterClause);
2231
+ }
2229
2232
}
2230
2233
2231
2234
void PrintAST::printDeclGenericRequirements (GenericContext *decl) {
@@ -2239,12 +2242,14 @@ void PrintAST::printDeclGenericRequirements(GenericContext *decl) {
2239
2242
if (parentSig && parentSig->isEqual (genericSig))
2240
2243
return ;
2241
2244
2245
+ Printer.printStructurePre (PrintStructureKind::DeclGenericParameterClause);
2242
2246
printGenericSignature (genericSig, PrintRequirements,
2243
2247
[parentSig](const Requirement &req) {
2244
2248
if (parentSig)
2245
2249
return !parentSig->isRequirementSatisfied (req);
2246
2250
return true ;
2247
2251
});
2252
+ Printer.printStructurePost (PrintStructureKind::DeclGenericParameterClause);
2248
2253
}
2249
2254
2250
2255
void PrintAST::printInherited (const Decl *decl) {
@@ -3236,25 +3241,32 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
3236
3241
Printer.printName (decl->getName (), getTypeMemberPrintNameContext (decl));
3237
3242
});
3238
3243
3239
- auto type = decl->getInterfaceType ();
3240
- Printer << " : " ;
3241
- TypeLoc tyLoc;
3242
- if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr ()) {
3243
- tyLoc = TypeLoc (repr, type);
3244
- } else {
3245
- tyLoc = TypeLoc::withoutLoc (type);
3246
- }
3247
- Printer.printDeclResultTypePre (decl, tyLoc);
3244
+ {
3245
+ Printer.printStructurePre (PrintStructureKind::DeclResultTypeClause);
3246
+ SWIFT_DEFER {
3247
+ Printer.printStructurePost (PrintStructureKind::DeclResultTypeClause);
3248
+ };
3248
3249
3249
- // HACK: When printing result types for vars with opaque result types,
3250
- // always print them using the `some` keyword instead of printing
3251
- // the full stable reference.
3252
- llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
3253
- x (Options.OpaqueReturnTypePrinting ,
3254
- PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
3250
+ auto type = decl->getInterfaceType ();
3251
+ Printer << " : " ;
3252
+ TypeLoc tyLoc;
3253
+ if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr ()) {
3254
+ tyLoc = TypeLoc (repr, type);
3255
+ } else {
3256
+ tyLoc = TypeLoc::withoutLoc (type);
3257
+ }
3258
+ Printer.printDeclResultTypePre (decl, tyLoc);
3255
3259
3256
- printTypeLocForImplicitlyUnwrappedOptional (
3257
- tyLoc, decl->isImplicitlyUnwrappedOptional ());
3260
+ // HACK: When printing result types for vars with opaque result types,
3261
+ // always print them using the `some` keyword instead of printing
3262
+ // the full stable reference.
3263
+ llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
3264
+ x (Options.OpaqueReturnTypePrinting ,
3265
+ PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
3266
+
3267
+ printTypeLocForImplicitlyUnwrappedOptional (
3268
+ tyLoc, decl->isImplicitlyUnwrappedOptional ());
3269
+ }
3258
3270
3259
3271
printAccessors (decl);
3260
3272
}
@@ -3332,20 +3344,31 @@ void PrintAST::printOneParameter(const ParamDecl *param,
3332
3344
TheTypeLoc.setType (BGT->getGenericArgs ()[0 ]);
3333
3345
}
3334
3346
3335
- if (!param->isVariadic () &&
3336
- !willUseTypeReprPrinting (TheTypeLoc, CurrentType, Options)) {
3337
- auto type = TheTypeLoc.getType ();
3338
- printParameterFlags (Printer, Options, paramFlags,
3339
- isEscaping (type));
3340
- }
3347
+ {
3348
+ Printer.printStructurePre (PrintStructureKind::FunctionParameterType);
3349
+ SWIFT_DEFER {
3350
+ Printer.printStructurePost (PrintStructureKind::FunctionParameterType);
3351
+ };
3352
+ if (!param->isVariadic () &&
3353
+ !willUseTypeReprPrinting (TheTypeLoc, CurrentType, Options)) {
3354
+ auto type = TheTypeLoc.getType ();
3355
+ printParameterFlags (Printer, Options, paramFlags,
3356
+ isEscaping (type));
3357
+ }
3341
3358
3342
- printTypeLocForImplicitlyUnwrappedOptional (
3343
- TheTypeLoc, param->isImplicitlyUnwrappedOptional ());
3359
+ printTypeLocForImplicitlyUnwrappedOptional (
3360
+ TheTypeLoc, param->isImplicitlyUnwrappedOptional ());
3344
3361
3345
- if (param->isVariadic ())
3346
- Printer << " ..." ;
3362
+ if (param->isVariadic ())
3363
+ Printer << " ..." ;
3364
+ }
3347
3365
3348
3366
if (param->isDefaultArgument () && Options.PrintDefaultArgumentValue ) {
3367
+ Printer.callPrintStructurePre (PrintStructureKind::DefaultArgumentClause);
3368
+ SWIFT_DEFER {
3369
+ Printer.printStructurePost (PrintStructureKind::DefaultArgumentClause);
3370
+ };
3371
+
3349
3372
SmallString<128 > scratch;
3350
3373
auto defaultArgStr = param->getDefaultValueStringRepresentation (scratch);
3351
3374
@@ -3368,6 +3391,10 @@ void PrintAST::printOneParameter(const ParamDecl *param,
3368
3391
void PrintAST::printParameterList (ParameterList *PL,
3369
3392
ArrayRef<AnyFunctionType::Param> params,
3370
3393
bool isAPINameByDefault) {
3394
+ Printer.printStructurePre (PrintStructureKind::FunctionParameterList);
3395
+ SWIFT_DEFER {
3396
+ Printer.printStructurePost (PrintStructureKind::FunctionParameterList);
3397
+ };
3371
3398
Printer << " (" ;
3372
3399
const unsigned paramSize = params.size ();
3373
3400
for (unsigned i = 0 , e = PL->size (); i != e; ++i) {
@@ -3398,19 +3425,25 @@ void PrintAST::printFunctionParameters(AbstractFunctionDecl *AFD) {
3398
3425
printParameterList (BodyParams, parameterListTypes,
3399
3426
AFD->argumentNameIsAPIByDefault ());
3400
3427
3401
- if (AFD->hasAsync ()) {
3402
- Printer << " " ;
3403
- if (AFD->getAttrs ().hasAttribute <ReasyncAttr>())
3404
- Printer.printKeyword (" reasync" , Options);
3405
- else
3406
- Printer.printKeyword (" async" , Options);
3407
- }
3428
+ if (AFD->hasAsync () || AFD->hasThrows ()) {
3429
+ Printer.printStructurePre (PrintStructureKind::EffectsSpecifiers);
3430
+ SWIFT_DEFER {
3431
+ Printer.printStructurePost (PrintStructureKind::EffectsSpecifiers);
3432
+ };
3433
+ if (AFD->hasAsync ()) {
3434
+ Printer << " " ;
3435
+ if (AFD->getAttrs ().hasAttribute <ReasyncAttr>())
3436
+ Printer.printKeyword (" reasync" , Options);
3437
+ else
3438
+ Printer.printKeyword (" async" , Options);
3439
+ }
3408
3440
3409
- if (AFD->hasThrows ()) {
3410
- if (AFD->getAttrs ().hasAttribute <RethrowsAttr>())
3411
- Printer << " " << tok::kw_rethrows;
3412
- else
3413
- Printer << " " << tok::kw_throws;
3441
+ if (AFD->hasThrows ()) {
3442
+ if (AFD->getAttrs ().hasAttribute <RethrowsAttr>())
3443
+ Printer << " " << tok::kw_rethrows;
3444
+ else
3445
+ Printer << " " << tok::kw_throws;
3446
+ }
3414
3447
}
3415
3448
}
3416
3449
@@ -3522,6 +3555,10 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
3522
3555
3523
3556
Type ResultTy = decl->getResultInterfaceType ();
3524
3557
if (ResultTy && !ResultTy->isVoid ()) {
3558
+ Printer.printStructurePre (PrintStructureKind::DeclResultTypeClause);
3559
+ SWIFT_DEFER {
3560
+ Printer.printStructurePost (PrintStructureKind::DeclResultTypeClause);
3561
+ };
3525
3562
TypeLoc ResultTyLoc (decl->getResultTypeRepr (), ResultTy);
3526
3563
3527
3564
// When printing a protocol requirement with types substituted for a
@@ -3699,23 +3736,32 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
3699
3736
printParameterList (decl->getIndices (), params,
3700
3737
/* isAPINameByDefault*/ false );
3701
3738
});
3702
- Printer << " -> " ;
3703
-
3704
- TypeLoc elementTy (decl->getElementTypeRepr (),
3705
- decl->getElementInterfaceType ());
3706
- Printer.printDeclResultTypePre (decl, elementTy);
3707
- Printer.callPrintStructurePre (PrintStructureKind::FunctionReturnType);
3708
-
3709
- // HACK: When printing result types for subscripts with opaque result types,
3710
- // always print them using the `some` keyword instead of printing
3711
- // the full stable reference.
3712
- llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
3713
- x (Options.OpaqueReturnTypePrinting ,
3714
- PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
3715
-
3716
- printTypeLocForImplicitlyUnwrappedOptional (
3717
- elementTy, decl->isImplicitlyUnwrappedOptional ());
3718
- Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
3739
+
3740
+ {
3741
+ Printer.printStructurePre (PrintStructureKind::DeclResultTypeClause);
3742
+ SWIFT_DEFER {
3743
+ Printer.printStructurePost (PrintStructureKind::DeclResultTypeClause);
3744
+ };
3745
+
3746
+ Printer << " -> " ;
3747
+
3748
+ TypeLoc elementTy (decl->getElementTypeRepr (),
3749
+ decl->getElementInterfaceType ());
3750
+ Printer.printDeclResultTypePre (decl, elementTy);
3751
+ Printer.callPrintStructurePre (PrintStructureKind::FunctionReturnType);
3752
+
3753
+ // HACK: When printing result types for subscripts with opaque result types,
3754
+ // always print them using the `some` keyword instead of printing
3755
+ // the full stable reference.
3756
+ llvm::SaveAndRestore<PrintOptions::OpaqueReturnTypePrintingMode>
3757
+ x (Options.OpaqueReturnTypePrinting ,
3758
+ PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword);
3759
+
3760
+ printTypeLocForImplicitlyUnwrappedOptional (
3761
+ elementTy, decl->isImplicitlyUnwrappedOptional ());
3762
+ Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
3763
+ }
3764
+
3719
3765
printDeclGenericRequirements (decl);
3720
3766
printAccessors (decl);
3721
3767
}
0 commit comments