@@ -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 ;
@@ -350,7 +353,7 @@ ASTPrinter &operator<<(ASTPrinter &printer, tok keyword) {
350
353
SmallString<16 > Buffer;
351
354
llvm::raw_svector_ostream OS (Buffer);
352
355
OS << keyword;
353
- printer.printKeyword (Buffer.str ());
356
+ printer.printKeyword (Buffer.str (), PrintOptions () );
354
357
return printer;
355
358
}
356
359
@@ -575,7 +578,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
575
578
Printer << tok::kw_public;
576
579
break ;
577
580
case AccessLevel::Open:
578
- Printer.printKeyword (" open" );
581
+ Printer.printKeyword (" open" , Options );
579
582
break ;
580
583
}
581
584
Printer << suffix << " " ;
@@ -1614,11 +1617,9 @@ static StringRef getAccessorLabel(AccessorDecl *accessor) {
1614
1617
1615
1618
void PrintAST::printMutatingModifiersIfNeeded (const AccessorDecl *accessor) {
1616
1619
if (accessor->isAssumedNonMutating () && accessor->isMutating ()) {
1617
- Printer.printKeyword (" mutating" );
1618
- Printer << " " ;
1620
+ Printer.printKeyword (" mutating" , Options, " " );
1619
1621
} else if (accessor->isExplicitNonMutating ()) {
1620
- Printer.printKeyword (" nonmutating" );
1621
- Printer << " " ;
1622
+ Printer.printKeyword (" nonmutating" , Options, " " );
1622
1623
}
1623
1624
}
1624
1625
@@ -1675,17 +1676,17 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
1675
1676
Printer << " {" ;
1676
1677
if (mutatingGetter) {
1677
1678
Printer << " " ;
1678
- Printer.printKeyword (" mutating" );
1679
+ Printer.printKeyword (" mutating" , Options );
1679
1680
}
1680
1681
Printer << " " ;
1681
- Printer.printKeyword (" get" );
1682
+ Printer.printKeyword (" get" , Options );
1682
1683
if (settable) {
1683
1684
if (nonmutatingSetter) {
1684
1685
Printer << " " ;
1685
- Printer.printKeyword (" nonmutating" );
1686
+ Printer.printKeyword (" nonmutating" , Options );
1686
1687
}
1687
1688
Printer << " " ;
1688
- Printer.printKeyword (" set" );
1689
+ Printer.printKeyword (" set" , Options );
1689
1690
}
1690
1691
Printer << " }" ;
1691
1692
return ;
@@ -1728,7 +1729,7 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
1728
1729
if (!PrintAccessorBody) {
1729
1730
Printer << " " ;
1730
1731
printMutatingModifiersIfNeeded (Accessor);
1731
- Printer.printKeyword (getAccessorLabel (Accessor));
1732
+ Printer.printKeyword (getAccessorLabel (Accessor), Options );
1732
1733
} else {
1733
1734
{
1734
1735
IndentRAII IndentMore (*this );
@@ -2364,13 +2365,13 @@ static void printParameterFlags(ASTPrinter &printer, PrintOptions options,
2364
2365
/* nothing */
2365
2366
break ;
2366
2367
case ValueOwnership::InOut:
2367
- printer << " inout " ;
2368
+ printer. printKeyword ( " inout " , options, " " ) ;
2368
2369
break ;
2369
2370
case ValueOwnership::Shared:
2370
- printer << " __shared " ;
2371
+ printer. printKeyword ( " __shared " , options, " " ) ;
2371
2372
break ;
2372
2373
case ValueOwnership::Owned:
2373
- printer << " __owned " ;
2374
+ printer. printKeyword ( " __owned " , options, " " ) ;
2374
2375
break ;
2375
2376
}
2376
2377
}
@@ -2530,7 +2531,7 @@ void PrintAST::printOneParameter(const ParamDecl *param,
2530
2531
case DefaultArgumentKind::Function:
2531
2532
case DefaultArgumentKind::DSOHandle:
2532
2533
case DefaultArgumentKind::NilLiteral:
2533
- Printer.printKeyword (defaultArgStr);
2534
+ Printer.printKeyword (defaultArgStr, Options );
2534
2535
break ;
2535
2536
default :
2536
2537
Printer << defaultArgStr;
@@ -2665,11 +2666,9 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
2665
2666
if (decl->isStatic ())
2666
2667
printStaticKeyword (decl->getCorrectStaticSpelling ());
2667
2668
if (decl->isMutating () && !decl->getAttrs ().hasAttribute <MutatingAttr>()) {
2668
- Printer.printKeyword (" mutating" );
2669
- Printer << " " ;
2669
+ Printer.printKeyword (" mutating" , Options, " " );
2670
2670
} else if (decl->isConsuming () && !decl->getAttrs ().hasAttribute <ConsumingAttr>()) {
2671
- Printer.printKeyword (" __consuming" );
2672
- Printer << " " ;
2671
+ Printer.printKeyword (" __consuming" , Options, " " );
2673
2672
}
2674
2673
Printer << tok::kw_func << " " ;
2675
2674
}
@@ -2846,8 +2845,7 @@ void PrintAST::visitConstructorDecl(ConstructorDecl *decl) {
2846
2845
isClassContext = dc->getSelfClassDecl () != nullptr ;
2847
2846
}
2848
2847
if (isClassContext) {
2849
- Printer.printKeyword (" convenience" );
2850
- Printer << " " ;
2848
+ Printer.printKeyword (" convenience" , Options, " " );
2851
2849
} else {
2852
2850
assert (decl->getDeclContext ()->getExtendedProtocolDecl () &&
2853
2851
" unexpected convenience initializer" );
@@ -2896,8 +2894,8 @@ void PrintAST::visitDestructorDecl(DestructorDecl *decl) {
2896
2894
}
2897
2895
2898
2896
void PrintAST::visitInfixOperatorDecl (InfixOperatorDecl *decl) {
2899
- Printer.printKeyword (" infix" );
2900
- Printer << " " << tok::kw_operator << " " ;
2897
+ Printer.printKeyword (" infix" , Options, " " );
2898
+ Printer << tok::kw_operator << " " ;
2901
2899
recordDeclLoc (decl,
2902
2900
[&]{
2903
2901
Printer.printName (decl->getName ());
@@ -2928,33 +2926,30 @@ void PrintAST::visitPrecedenceGroupDecl(PrecedenceGroupDecl *decl) {
2928
2926
if (!decl->isAssociativityImplicit () ||
2929
2927
!decl->isNonAssociative ()) {
2930
2928
indent ();
2931
- Printer.printKeyword (" associativity" );
2932
- Printer << " : " ;
2929
+ Printer.printKeyword (" associativity" , Options, " : " );
2933
2930
switch (decl->getAssociativity ()) {
2934
2931
case Associativity::None:
2935
- Printer.printKeyword (" none" );
2932
+ Printer.printKeyword (" none" , Options );
2936
2933
break ;
2937
2934
case Associativity::Left:
2938
- Printer.printKeyword (" left" );
2935
+ Printer.printKeyword (" left" , Options );
2939
2936
break ;
2940
2937
case Associativity::Right:
2941
- Printer.printKeyword (" right" );
2938
+ Printer.printKeyword (" right" , Options );
2942
2939
break ;
2943
2940
}
2944
2941
Printer.printNewline ();
2945
2942
}
2946
2943
if (!decl->isAssignmentImplicit () ||
2947
2944
decl->isAssignment ()) {
2948
2945
indent ();
2949
- Printer.printKeyword (" assignment" );
2950
- Printer << " : " ;
2951
- Printer.printKeyword (decl->isAssignment () ? " true" : " false" );
2946
+ Printer.printKeyword (" assignment" , Options, " : " );
2947
+ Printer.printKeyword (decl->isAssignment () ? " true" : " false" , Options);
2952
2948
Printer.printNewline ();
2953
2949
}
2954
2950
if (!decl->getHigherThan ().empty ()) {
2955
2951
indent ();
2956
- Printer.printKeyword (" higherThan" );
2957
- Printer << " : " ;
2952
+ Printer.printKeyword (" higherThan" , Options, " : " );
2958
2953
if (!decl->getHigherThan ().empty ()) {
2959
2954
Printer << decl->getHigherThan ()[0 ].Name ;
2960
2955
for (auto &rel : decl->getHigherThan ().slice (1 ))
@@ -2964,8 +2959,7 @@ void PrintAST::visitPrecedenceGroupDecl(PrecedenceGroupDecl *decl) {
2964
2959
}
2965
2960
if (!decl->getLowerThan ().empty ()) {
2966
2961
indent ();
2967
- Printer.printKeyword (" lowerThan" );
2968
- Printer << " : " ;
2962
+ Printer.printKeyword (" lowerThan" , Options, " : " );
2969
2963
if (!decl->getLowerThan ().empty ()) {
2970
2964
Printer << decl->getLowerThan ()[0 ].Name ;
2971
2965
for (auto &rel : decl->getLowerThan ().slice (1 ))
@@ -2979,8 +2973,8 @@ void PrintAST::visitPrecedenceGroupDecl(PrecedenceGroupDecl *decl) {
2979
2973
}
2980
2974
2981
2975
void PrintAST::visitPrefixOperatorDecl (PrefixOperatorDecl *decl) {
2982
- Printer.printKeyword (" prefix" );
2983
- Printer << " " << tok::kw_operator << " " ;
2976
+ Printer.printKeyword (" prefix" , Options, " " );
2977
+ Printer << tok::kw_operator << " " ;
2984
2978
recordDeclLoc (decl,
2985
2979
[&]{
2986
2980
Printer.printName (decl->getName ());
@@ -2997,8 +2991,8 @@ void PrintAST::visitPrefixOperatorDecl(PrefixOperatorDecl *decl) {
2997
2991
}
2998
2992
2999
2993
void PrintAST::visitPostfixOperatorDecl (PostfixOperatorDecl *decl) {
3000
- Printer.printKeyword (" postfix" );
3001
- Printer << " " << tok::kw_operator << " " ;
2994
+ Printer.printKeyword (" postfix" , Options, " " );
2995
+ Printer << tok::kw_operator << " " ;
3002
2996
recordDeclLoc (decl,
3003
2997
[&]{
3004
2998
Printer.printName (decl->getName ());
@@ -3035,8 +3029,7 @@ void PrintAST::visitReturnStmt(ReturnStmt *stmt) {
3035
3029
}
3036
3030
3037
3031
void PrintAST::visitYieldStmt (YieldStmt *stmt) {
3038
- Printer.printKeyword (" yield" );
3039
- Printer << " " ;
3032
+ Printer.printKeyword (" yield" , Options, " " );
3040
3033
bool parens = (stmt->getYields ().size () != 1
3041
3034
|| stmt->getLParenLoc ().isValid ());
3042
3035
if (parens) Printer << " (" ;
0 commit comments