@@ -562,6 +562,7 @@ static bool escapeKeywordInContext(StringRef keyword, PrintNameContext context){
562
562
563
563
case PrintNameContext::FunctionParameterExternal:
564
564
case PrintNameContext::FunctionParameterLocal:
565
+ case PrintNameContext::TupleElement:
565
566
return !canBeArgumentLabel (keyword);
566
567
}
567
568
}
@@ -760,17 +761,12 @@ class PrintAST : public ASTVisitor<PrintAST> {
760
761
void printTypeLoc (const TypeLoc &TL) {
761
762
if (Options.TransformContext && TL.getType ()) {
762
763
if (auto RT = Options.TransformContext ->transform (TL.getType ())) {
763
- Printer.printTypePre (TypeLoc::withoutLoc (RT));
764
764
PrintOptions FreshOptions;
765
765
RT.print (Printer, FreshOptions);
766
- Printer.printTypePost (TypeLoc::withoutLoc (RT));
767
766
return ;
768
767
}
769
768
}
770
769
771
- Printer.printTypePre (TL);
772
- defer { Printer.printTypePost (TL); };
773
-
774
770
// Print a TypeRepr if instructed to do so by options, or if the type
775
771
// is null.
776
772
if ((Options.PreferTypeRepr && TL.hasLocation ()) ||
@@ -779,6 +775,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
779
775
repr->print (Printer, Options);
780
776
return ;
781
777
}
778
+
782
779
TL.getType ().print (Printer, Options);
783
780
}
784
781
@@ -2321,7 +2318,9 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
2321
2318
if (ResultTy && !ResultTy->isEqual (TupleType::getEmpty (Context))) {
2322
2319
Printer << " -> " ;
2323
2320
// Use the non-repr external type, but reuse the TypeLoc printing code.
2321
+ Printer.printStructurePre (PrintStructureKind::FunctionReturnType);
2324
2322
printTypeLoc (TypeLoc::withoutLoc (ResultTy));
2323
+ Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
2325
2324
}
2326
2325
}
2327
2326
@@ -2383,7 +2382,10 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
2383
2382
/* isAPINameByDefault*/ [](unsigned )->bool {return false ;});
2384
2383
});
2385
2384
Printer << " -> " ;
2385
+
2386
+ Printer.printStructurePre (PrintStructureKind::FunctionReturnType);
2386
2387
printTypeLoc (decl->getElementTypeLoc ());
2388
+ Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
2387
2389
2388
2390
printAccessors (decl);
2389
2391
}
@@ -2944,6 +2946,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
2944
2946
: Printer(Printer), Options(PO) {}
2945
2947
2946
2948
void visit (Type T) {
2949
+ Printer.printTypePre (TypeLoc::withoutLoc (T));
2950
+ defer { Printer.printTypePost (TypeLoc::withoutLoc (T)); };
2951
+
2947
2952
// If we have an alternate name for this type, use it.
2948
2953
if (Options.AlternativeTypeNames ) {
2949
2954
auto found = Options.AlternativeTypeNames ->find (T.getCanonicalTypeOrNull ());
@@ -3057,10 +3062,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3057
3062
const TupleTypeElt &TD = Fields[i];
3058
3063
Type EltType = TD.getType ();
3059
3064
3065
+ Printer.callPrintStructurePre (PrintStructureKind::TupleElement);
3066
+ defer { Printer.printStructurePost (PrintStructureKind::TupleElement); };
3060
3067
3061
3068
if (TD.hasName ()) {
3062
- Printer.printName (TD.getName (),
3063
- PrintNameContext::FunctionParameterExternal);
3069
+ Printer.printName (TD.getName (), PrintNameContext::TupleElement);
3064
3070
Printer << " : " ;
3065
3071
}
3066
3072
if (TD.isVararg ()) {
@@ -3267,17 +3273,26 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3267
3273
}
3268
3274
3269
3275
void visitFunctionType (FunctionType *T) {
3276
+ Printer.callPrintStructurePre (PrintStructureKind::FunctionType);
3277
+ defer { Printer.printStructurePost (PrintStructureKind::FunctionType); };
3278
+
3270
3279
printFunctionExtInfo (T->getExtInfo ());
3271
3280
printWithParensIfNotSimple (T->getInput ());
3272
3281
3273
3282
if (T->throws ())
3274
3283
Printer << " " << tok::kw_throws;
3275
3284
3276
3285
Printer << " -> " ;
3286
+
3287
+ Printer.printStructurePre (PrintStructureKind::FunctionReturnType);
3277
3288
T->getResult ().print (Printer, Options);
3289
+ Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
3278
3290
}
3279
3291
3280
3292
void visitPolymorphicFunctionType (PolymorphicFunctionType *T) {
3293
+ Printer.callPrintStructurePre (PrintStructureKind::FunctionType);
3294
+ defer { Printer.printStructurePost (PrintStructureKind::FunctionType); };
3295
+
3281
3296
printFunctionExtInfo (T->getExtInfo ());
3282
3297
printGenericParams (&T->getGenericParams ());
3283
3298
Printer << " " ;
@@ -3287,7 +3302,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3287
3302
Printer << " " << tok::kw_throws;
3288
3303
3289
3304
Printer << " -> " ;
3305
+ Printer.printStructurePre (PrintStructureKind::FunctionReturnType);
3290
3306
T->getResult ().print (Printer, Options);
3307
+ Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
3291
3308
}
3292
3309
3293
3310
// / If we can't find the depth of a type, return ErrorDepth.
@@ -3427,6 +3444,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3427
3444
}
3428
3445
3429
3446
void visitGenericFunctionType (GenericFunctionType *T) {
3447
+ Printer.callPrintStructurePre (PrintStructureKind::FunctionType);
3448
+ defer { Printer.printStructurePost (PrintStructureKind::FunctionType); };
3449
+
3430
3450
printFunctionExtInfo (T->getExtInfo ());
3431
3451
printGenericSignature (T->getGenericParams (), T->getRequirements ());
3432
3452
Printer << " " ;
@@ -3436,7 +3456,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
3436
3456
Printer << " " << tok::kw_throws;
3437
3457
3438
3458
Printer << " -> " ;
3459
+ Printer.printStructurePre (PrintStructureKind::FunctionReturnType);
3439
3460
T->getResult ().print (Printer, Options);
3461
+ Printer.printStructurePost (PrintStructureKind::FunctionReturnType);
3440
3462
}
3441
3463
3442
3464
void printCalleeConvention (ParameterConvention conv) {
0 commit comments