@@ -1141,6 +1141,8 @@ class PrintAST : public ASTVisitor<PrintAST> {
11411141
11421142 void printArgumentList (ArgumentList *args, bool forSubscript = false );
11431143
1144+ void printAvailabilitySpec (AvailabilitySpec *spec);
1145+
11441146 void printStmtCondition (StmtCondition stmt);
11451147
11461148#define DECL (Name,Parent ) void visit##Name##Decl(Name##Decl *decl);
@@ -5697,19 +5699,58 @@ void PrintAST::visitRepeatWhileStmt(RepeatWhileStmt *stmt) {
56975699 visit (stmt->getCond ());
56985700}
56995701
5702+ void PrintAST::printAvailabilitySpec (AvailabilitySpec *spec) {
5703+ auto domainOrIdentifier = spec->getDomainOrIdentifier ();
5704+ if (auto domain = domainOrIdentifier.getAsDomain ()) {
5705+ Printer << domain->getNameForAttributePrinting ();
5706+ } else {
5707+ Printer << domainOrIdentifier.getAsIdentifier ().value ();
5708+ }
5709+
5710+ if (!spec->getRawVersion ().empty ())
5711+ Printer << " " << spec->getRawVersion ().getAsString ();
5712+ }
5713+
57005714void PrintAST::printStmtCondition (StmtCondition condition) {
57015715 interleave (
57025716 condition,
57035717 [&](StmtConditionElement &elt) {
5704- if (auto pattern = elt.getPatternOrNull ()) {
5705- printPattern (pattern);
5706- auto initializer = elt.getInitializer ();
5707- if (initializer) {
5718+ switch (elt.getKind ()) {
5719+ case StmtConditionElement::ConditionKind::CK_Boolean:
5720+ visit (elt.getBoolean ());
5721+ break ;
5722+
5723+ case StmtConditionElement::ConditionKind::CK_PatternBinding:
5724+ printPattern (elt.getPattern ());
5725+ if (auto initializer = elt.getInitializer ()) {
57085726 Printer << " = " ;
57095727 visit (initializer);
57105728 }
5711- } else if (auto boolean = elt.getBooleanOrNull ()) {
5712- visit (boolean);
5729+ break ;
5730+
5731+ case StmtConditionElement::ConditionKind::CK_Availability:
5732+ if (auto availability = elt.getAvailability ()) {
5733+ Printer << (availability->isUnavailability ()
5734+ ? tok::pound_unavailable
5735+ : tok::pound_available)
5736+ << " (" ;
5737+
5738+ interleave (
5739+ availability->getQueries (),
5740+ [&](AvailabilitySpec *spec) { printAvailabilitySpec (spec); },
5741+ [&] { Printer << " , " ; });
5742+
5743+ Printer << " )" ;
5744+ }
5745+ break ;
5746+
5747+ case StmtConditionElement::ConditionKind::CK_HasSymbol:
5748+ if (auto hasSymbolInfo = elt.getHasSymbolInfo ()) {
5749+ Printer << tok::pound__hasSymbol << " (" ;
5750+ visit (hasSymbolInfo->getSymbolExpr ());
5751+ Printer << " )" ;
5752+ }
5753+ break ;
57135754 }
57145755 },
57155756 [&] { Printer << " , " ; });
0 commit comments