@@ -106,6 +106,9 @@ PrintOptions PrintOptions::printParseableInterfaceFile() {
106
106
result.CollapseSingleGetterProperty = false ;
107
107
result.VarInitializers = true ;
108
108
109
+ // We should print __consuming, __owned, etc for the module interface file.
110
+ result.SkipUnderscoredKeywords = false ;
111
+
109
112
result.FunctionBody = [](const ValueDecl *decl, ASTPrinter &printer) {
110
113
auto AFD = dyn_cast<AbstractFunctionDecl>(decl);
111
114
if (!AFD || !AFD->hasInlinableBodyText ()) return ;
@@ -366,7 +369,7 @@ ASTPrinter &operator<<(ASTPrinter &printer, tok keyword) {
366
369
SmallString<16 > Buffer;
367
370
llvm::raw_svector_ostream OS (Buffer);
368
371
OS << keyword;
369
- printer.printKeyword (Buffer.str ());
372
+ printer.printKeyword (Buffer.str (), PrintOptions () );
370
373
return printer;
371
374
}
372
375
@@ -591,7 +594,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
591
594
Printer << tok::kw_public;
592
595
break ;
593
596
case AccessLevel::Open:
594
- Printer.printKeyword (" open" );
597
+ Printer.printKeyword (" open" , Options );
595
598
break ;
596
599
}
597
600
Printer << suffix << " " ;
@@ -1630,11 +1633,9 @@ static StringRef getAccessorLabel(AccessorDecl *accessor) {
1630
1633
1631
1634
void PrintAST::printMutatingModifiersIfNeeded (const AccessorDecl *accessor) {
1632
1635
if (accessor->isAssumedNonMutating () && accessor->isMutating ()) {
1633
- Printer.printKeyword (" mutating" );
1634
- Printer << " " ;
1636
+ Printer.printKeyword (" mutating" , Options, " " );
1635
1637
} else if (accessor->isExplicitNonMutating ()) {
1636
- Printer.printKeyword (" nonmutating" );
1637
- Printer << " " ;
1638
+ Printer.printKeyword (" nonmutating" , Options, " " );
1638
1639
}
1639
1640
}
1640
1641
@@ -1691,17 +1692,17 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
1691
1692
Printer << " {" ;
1692
1693
if (mutatingGetter) {
1693
1694
Printer << " " ;
1694
- Printer.printKeyword (" mutating" );
1695
+ Printer.printKeyword (" mutating" , Options );
1695
1696
}
1696
1697
Printer << " " ;
1697
- Printer.printKeyword (" get" );
1698
+ Printer.printKeyword (" get" , Options );
1698
1699
if (settable) {
1699
1700
if (nonmutatingSetter) {
1700
1701
Printer << " " ;
1701
- Printer.printKeyword (" nonmutating" );
1702
+ Printer.printKeyword (" nonmutating" , Options );
1702
1703
}
1703
1704
Printer << " " ;
1704
- Printer.printKeyword (" set" );
1705
+ Printer.printKeyword (" set" , Options );
1705
1706
}
1706
1707
Printer << " }" ;
1707
1708
return ;
@@ -1744,7 +1745,7 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
1744
1745
if (!PrintAccessorBody) {
1745
1746
Printer << " " ;
1746
1747
printMutatingModifiersIfNeeded (Accessor);
1747
- Printer.printKeyword (getAccessorLabel (Accessor));
1748
+ Printer.printKeyword (getAccessorLabel (Accessor), Options );
1748
1749
} else {
1749
1750
{
1750
1751
IndentRAII IndentMore (*this );
@@ -2380,13 +2381,13 @@ static void printParameterFlags(ASTPrinter &printer, PrintOptions options,
2380
2381
/* nothing */
2381
2382
break ;
2382
2383
case ValueOwnership::InOut:
2383
- printer << " inout " ;
2384
+ printer. printKeyword ( " inout " , options, " " ) ;
2384
2385
break ;
2385
2386
case ValueOwnership::Shared:
2386
- printer << " __shared " ;
2387
+ printer. printKeyword ( " __shared " , options, " " ) ;
2387
2388
break ;
2388
2389
case ValueOwnership::Owned:
2389
- printer << " __owned " ;
2390
+ printer. printKeyword ( " __owned " , options, " " ) ;
2390
2391
break ;
2391
2392
}
2392
2393
}
@@ -2546,7 +2547,7 @@ void PrintAST::printOneParameter(const ParamDecl *param,
2546
2547
case DefaultArgumentKind::Function:
2547
2548
case DefaultArgumentKind::DSOHandle:
2548
2549
case DefaultArgumentKind::NilLiteral:
2549
- Printer.printKeyword (defaultArgStr);
2550
+ Printer.printKeyword (defaultArgStr, Options );
2550
2551
break ;
2551
2552
default :
2552
2553
Printer << defaultArgStr;
@@ -2681,11 +2682,9 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
2681
2682
if (decl->isStatic ())
2682
2683
printStaticKeyword (decl->getCorrectStaticSpelling ());
2683
2684
if (decl->isMutating () && !decl->getAttrs ().hasAttribute <MutatingAttr>()) {
2684
- Printer.printKeyword (" mutating" );
2685
- Printer << " " ;
2685
+ Printer.printKeyword (" mutating" , Options, " " );
2686
2686
} else if (decl->isConsuming () && !decl->getAttrs ().hasAttribute <ConsumingAttr>()) {
2687
- Printer.printKeyword (" __consuming" );
2688
- Printer << " " ;
2687
+ Printer.printKeyword (" __consuming" , Options, " " );
2689
2688
}
2690
2689
Printer << tok::kw_func << " " ;
2691
2690
}
@@ -2862,8 +2861,7 @@ void PrintAST::visitConstructorDecl(ConstructorDecl *decl) {
2862
2861
isClassContext = dc->getSelfClassDecl () != nullptr ;
2863
2862
}
2864
2863
if (isClassContext) {
2865
- Printer.printKeyword (" convenience" );
2866
- Printer << " " ;
2864
+ Printer.printKeyword (" convenience" , Options, " " );
2867
2865
} else {
2868
2866
assert (decl->getDeclContext ()->getExtendedProtocolDecl () &&
2869
2867
" unexpected convenience initializer" );
@@ -2912,8 +2910,8 @@ void PrintAST::visitDestructorDecl(DestructorDecl *decl) {
2912
2910
}
2913
2911
2914
2912
void PrintAST::visitInfixOperatorDecl (InfixOperatorDecl *decl) {
2915
- Printer.printKeyword (" infix" );
2916
- Printer << " " << tok::kw_operator << " " ;
2913
+ Printer.printKeyword (" infix" , Options, " " );
2914
+ Printer << tok::kw_operator << " " ;
2917
2915
recordDeclLoc (decl,
2918
2916
[&]{
2919
2917
Printer.printName (decl->getName ());
@@ -2944,33 +2942,30 @@ void PrintAST::visitPrecedenceGroupDecl(PrecedenceGroupDecl *decl) {
2944
2942
if (!decl->isAssociativityImplicit () ||
2945
2943
!decl->isNonAssociative ()) {
2946
2944
indent ();
2947
- Printer.printKeyword (" associativity" );
2948
- Printer << " : " ;
2945
+ Printer.printKeyword (" associativity" , Options, " : " );
2949
2946
switch (decl->getAssociativity ()) {
2950
2947
case Associativity::None:
2951
- Printer.printKeyword (" none" );
2948
+ Printer.printKeyword (" none" , Options );
2952
2949
break ;
2953
2950
case Associativity::Left:
2954
- Printer.printKeyword (" left" );
2951
+ Printer.printKeyword (" left" , Options );
2955
2952
break ;
2956
2953
case Associativity::Right:
2957
- Printer.printKeyword (" right" );
2954
+ Printer.printKeyword (" right" , Options );
2958
2955
break ;
2959
2956
}
2960
2957
Printer.printNewline ();
2961
2958
}
2962
2959
if (!decl->isAssignmentImplicit () ||
2963
2960
decl->isAssignment ()) {
2964
2961
indent ();
2965
- Printer.printKeyword (" assignment" );
2966
- Printer << " : " ;
2967
- Printer.printKeyword (decl->isAssignment () ? " true" : " false" );
2962
+ Printer.printKeyword (" assignment" , Options, " : " );
2963
+ Printer.printKeyword (decl->isAssignment () ? " true" : " false" , Options);
2968
2964
Printer.printNewline ();
2969
2965
}
2970
2966
if (!decl->getHigherThan ().empty ()) {
2971
2967
indent ();
2972
- Printer.printKeyword (" higherThan" );
2973
- Printer << " : " ;
2968
+ Printer.printKeyword (" higherThan" , Options, " : " );
2974
2969
if (!decl->getHigherThan ().empty ()) {
2975
2970
Printer << decl->getHigherThan ()[0 ].Name ;
2976
2971
for (auto &rel : decl->getHigherThan ().slice (1 ))
@@ -2980,8 +2975,7 @@ void PrintAST::visitPrecedenceGroupDecl(PrecedenceGroupDecl *decl) {
2980
2975
}
2981
2976
if (!decl->getLowerThan ().empty ()) {
2982
2977
indent ();
2983
- Printer.printKeyword (" lowerThan" );
2984
- Printer << " : " ;
2978
+ Printer.printKeyword (" lowerThan" , Options, " : " );
2985
2979
if (!decl->getLowerThan ().empty ()) {
2986
2980
Printer << decl->getLowerThan ()[0 ].Name ;
2987
2981
for (auto &rel : decl->getLowerThan ().slice (1 ))
@@ -2995,8 +2989,8 @@ void PrintAST::visitPrecedenceGroupDecl(PrecedenceGroupDecl *decl) {
2995
2989
}
2996
2990
2997
2991
void PrintAST::visitPrefixOperatorDecl (PrefixOperatorDecl *decl) {
2998
- Printer.printKeyword (" prefix" );
2999
- Printer << " " << tok::kw_operator << " " ;
2992
+ Printer.printKeyword (" prefix" , Options, " " );
2993
+ Printer << tok::kw_operator << " " ;
3000
2994
recordDeclLoc (decl,
3001
2995
[&]{
3002
2996
Printer.printName (decl->getName ());
@@ -3013,8 +3007,8 @@ void PrintAST::visitPrefixOperatorDecl(PrefixOperatorDecl *decl) {
3013
3007
}
3014
3008
3015
3009
void PrintAST::visitPostfixOperatorDecl (PostfixOperatorDecl *decl) {
3016
- Printer.printKeyword (" postfix" );
3017
- Printer << " " << tok::kw_operator << " " ;
3010
+ Printer.printKeyword (" postfix" , Options, " " );
3011
+ Printer << tok::kw_operator << " " ;
3018
3012
recordDeclLoc (decl,
3019
3013
[&]{
3020
3014
Printer.printName (decl->getName ());
@@ -3051,8 +3045,7 @@ void PrintAST::visitReturnStmt(ReturnStmt *stmt) {
3051
3045
}
3052
3046
3053
3047
void PrintAST::visitYieldStmt (YieldStmt *stmt) {
3054
- Printer.printKeyword (" yield" );
3055
- Printer << " " ;
3048
+ Printer.printKeyword (" yield" , Options, " " );
3056
3049
bool parens = (stmt->getYields ().size () != 1
3057
3050
|| stmt->getLParenLoc ().isValid ());
3058
3051
if (parens) Printer << " (" ;
0 commit comments