@@ -887,8 +887,10 @@ class PrintAST : public ASTVisitor<PrintAST> {
887
887
printTransformedTypeWithOptions (T, Options);
888
888
}
889
889
890
- void printTypeLocWithOptions (const TypeLoc &TL, const PrintOptions &options) {
890
+ void printTypeLocWithOptions (const TypeLoc &TL, const PrintOptions &options,
891
+ std::optional<llvm::function_ref<void ()>> printBeforeType = std::nullopt) {
891
892
if (CurrentType && TL.getType ()) {
893
+ if (printBeforeType) (*printBeforeType)();
892
894
printTransformedTypeWithOptions (TL.getType (), options);
893
895
return ;
894
896
}
@@ -901,11 +903,21 @@ class PrintAST : public ASTVisitor<PrintAST> {
901
903
return ;
902
904
}
903
905
906
+ if (printBeforeType) (*printBeforeType)();
904
907
TL.getType ().print (Printer, options);
905
908
}
906
909
907
910
void printTypeLoc (const TypeLoc &TL) { printTypeLocWithOptions (TL, Options); }
908
911
912
+ // / Print a TypeLoc. If we decide to print based on the type, rather than
913
+ // / based on the TypeRepr, call the given function before printing the type;
914
+ // / this is useful if there are attributes in the TypeRepr which don't end
915
+ // / up being part of the type, such as `@unchecked` in inheritance clauses.
916
+ void printTypeLoc (const TypeLoc &TL,
917
+ llvm::function_ref<void ()> printBeforeType) {
918
+ printTypeLocWithOptions (TL, Options, printBeforeType);
919
+ }
920
+
909
921
void printTypeLocForImplicitlyUnwrappedOptional (TypeLoc TL, bool IUO) {
910
922
PrintOptions options = Options;
911
923
options.PrintOptionalAsImplicitlyUnwrapped = IUO;
@@ -2710,15 +2722,15 @@ void PrintAST::printInherited(const Decl *decl) {
2710
2722
Printer << " : " ;
2711
2723
2712
2724
interleave (TypesToPrint, [&](InheritedEntry inherited) {
2713
- if (inherited. isUnchecked ())
2714
- Printer << " @unchecked " ;
2715
- if (inherited. isRetroactive () &&
2716
- ! llvm::is_contained (Options. ExcludeAttrList , TypeAttrKind::Retroactive))
2717
- Printer << " @retroactive " ;
2718
- if (inherited. isPreconcurrency ())
2719
- Printer << " @preconcurrency " ;
2720
-
2721
- printTypeLoc (inherited );
2725
+ printTypeLoc (inherited, [&] {
2726
+ if (inherited. isUnchecked ())
2727
+ Printer << " @unchecked " ;
2728
+ if (inherited. isRetroactive () &&
2729
+ ! llvm::is_contained (Options. ExcludeAttrList , TypeAttrKind::Retroactive))
2730
+ Printer << " @retroactive " ;
2731
+ if (inherited. isPreconcurrency ())
2732
+ Printer << " @preconcurrency " ;
2733
+ } );
2722
2734
}, [&]() {
2723
2735
Printer << " , " ;
2724
2736
});
0 commit comments