@@ -1020,6 +1020,10 @@ namespace {
1020
1020
return Writer.hasNonStandardOutput ();
1021
1021
}
1022
1022
1023
+ bool isTypeChecked () const {
1024
+ return MemberLoading == ASTDumpMemberLoading::TypeChecked;
1025
+ }
1026
+
1023
1027
// / Call `Body` in a context where the printer is ready for a child to be
1024
1028
// / printed.
1025
1029
void printRecArbitrary (std::function<void (Label)> body, Label label) {
@@ -1614,11 +1618,17 @@ namespace {
1614
1618
}
1615
1619
}
1616
1620
1621
+ template <typename T>
1622
+ void printDeclContext (const T *D) {
1623
+ printField (static_cast <void *>(D->getDeclContext ()),
1624
+ Label::always (" decl_context" ));
1625
+ }
1626
+
1617
1627
// / Prints a field containing the name or the USR (based on parsability of
1618
1628
// / the output) of a decl that is being referenced elsewhere.
1619
1629
template <typename T>
1620
1630
void printReferencedDeclField (const T *D, Label label) {
1621
- if (Writer.isParsable ()) {
1631
+ if (Writer.isParsable () && isTypeChecked () ) {
1622
1632
printFieldQuoted (declUSR (D), label);
1623
1633
} else {
1624
1634
printFieldQuoted (D->getName (), label);
@@ -1630,7 +1640,7 @@ namespace {
1630
1640
template <typename T>
1631
1641
void printReferencedDeclWithContextField (const T *D, Label label,
1632
1642
TerminalColor Color = DeclColor) {
1633
- if (Writer.isParsable ()) {
1643
+ if (Writer.isParsable () && isTypeChecked () ) {
1634
1644
printFieldQuoted (declUSR (D), label, Color);
1635
1645
} else {
1636
1646
printFieldQuoted (D->printRef (), label, Color);
@@ -1640,7 +1650,7 @@ namespace {
1640
1650
// / Print a field containing a concrete reference to a declaration.
1641
1651
void printDeclRefField (ConcreteDeclRef declRef, Label label,
1642
1652
TerminalColor Color = DeclColor) {
1643
- if (Writer.isParsable ()) {
1653
+ if (Writer.isParsable () && isTypeChecked () ) {
1644
1654
// Just omit the key/value for parsable formats if there's no decl.
1645
1655
if (!declRef.getDecl ())
1646
1656
return ;
@@ -1809,6 +1819,7 @@ namespace {
1809
1819
}
1810
1820
void visitExprPattern (ExprPattern *P, Label label) {
1811
1821
printCommon (P, " pattern_expr" , label);
1822
+ printDeclContext (P);
1812
1823
switch (P->getCachedMatchOperandOwnership ()) {
1813
1824
case ValueOwnership::Default:
1814
1825
break ;
@@ -1839,6 +1850,7 @@ namespace {
1839
1850
}
1840
1851
void visitEnumElementPattern (EnumElementPattern *P, Label label) {
1841
1852
printCommon (P, " pattern_enum_element" , label);
1853
+ printDeclContext (P);
1842
1854
1843
1855
if (Writer.isParsable ()) {
1844
1856
printName (P->getName ().getFullName (), Label::always (" element" ));
@@ -1895,12 +1907,14 @@ namespace {
1895
1907
// Parsable outputs include the USR for each decl since they can be used
1896
1908
// to cross-reference them (within the AST dump itself and with other data
1897
1909
// sources like indexstore and SourceKit).
1898
- if (Writer.isParsable ()) {
1910
+ if (Writer.isParsable () && isTypeChecked () ) {
1899
1911
if (auto usr = declUSR (D); !usr.empty ()) {
1900
1912
printFieldQuoted (usr, Label::always (" usr" ));
1901
1913
}
1902
1914
}
1903
1915
1916
+ printDeclContext (D);
1917
+
1904
1918
printFlag (D->isImplicit (), " implicit" , DeclModifierColor);
1905
1919
printFlag (D->isHoisted (), " hoisted" , DeclModifierColor);
1906
1920
@@ -1919,7 +1933,7 @@ namespace {
1919
1933
printFlag (D->TrailingSemiLoc .isValid (), " trailing_semi" ,
1920
1934
DeclModifierColor);
1921
1935
1922
- if (Writer.isParsable ()) {
1936
+ if (Writer.isParsable () && isTypeChecked () ) {
1923
1937
// Print just the USRs of any auxiliary decls associated with this decl,
1924
1938
// which lets us relate macro expansions back to their originating decl
1925
1939
// if desired.
@@ -2098,13 +2112,15 @@ namespace {
2098
2112
2099
2113
printWhereRequirements (decl);
2100
2114
if (decl->overriddenDeclsComputed ()) {
2101
- printStringListField (decl->getOverriddenDecls (),
2102
- [&](AssociatedTypeDecl *overridden) {
2103
- if (Writer.isParsable ()) {
2104
- return declUSR (overridden->getProtocol ());
2105
- }
2106
- return std::string (overridden->getProtocol ()->getName ().str ());
2107
- }, Label::always (" overridden" ), /* delimiter=*/ " , " );
2115
+ printStringListField (
2116
+ decl->getOverriddenDecls (),
2117
+ [&](AssociatedTypeDecl *overridden) {
2118
+ if (Writer.isParsable () && isTypeChecked ()) {
2119
+ return declUSR (overridden->getProtocol ());
2120
+ }
2121
+ return std::string (overridden->getProtocol ()->getName ().str ());
2122
+ },
2123
+ Label::always (" overridden" ), /* delimiter=*/ " , " );
2108
2124
}
2109
2125
2110
2126
printAttributes (decl);
@@ -2214,15 +2230,18 @@ namespace {
2214
2230
2215
2231
if (VD->overriddenDeclsComputed ()) {
2216
2232
auto overridden = VD->getOverriddenDecls ();
2217
- printStringListField (overridden, [&](ValueDecl *overridden) {
2218
- if (Writer.isParsable ()) {
2219
- return declUSR (overridden);
2220
- }
2221
- std::string value;
2222
- llvm::raw_string_ostream SOS (value);
2223
- overridden->dumpRef (SOS);
2224
- return value;
2225
- }, Label::always (" override" ), /* delimiter=*/ " , " , OverrideColor);
2233
+ printStringListField (
2234
+ overridden,
2235
+ [&](ValueDecl *overridden) {
2236
+ if (Writer.isParsable () && isTypeChecked ()) {
2237
+ return declUSR (overridden);
2238
+ }
2239
+ std::string value;
2240
+ llvm::raw_string_ostream SOS (value);
2241
+ overridden->dumpRef (SOS);
2242
+ return value;
2243
+ },
2244
+ Label::always (" override" ), /* delimiter=*/ " , " , OverrideColor);
2226
2245
}
2227
2246
2228
2247
auto VarD = dyn_cast<VarDecl>(VD);
@@ -2424,6 +2443,8 @@ namespace {
2424
2443
printHead (" parameter" , ParameterColor, label);
2425
2444
2426
2445
printDeclName (PD, Label::optional (" name" ));
2446
+
2447
+ printDeclContext (PD);
2427
2448
if (!PD->getArgumentName ().empty ())
2428
2449
printFieldQuoted (PD->getArgumentName (), Label::always (" apiName" ),
2429
2450
IdentifierColor);
@@ -2522,23 +2543,32 @@ namespace {
2522
2543
printCommon (PBD, " pattern_binding_decl" , label);
2523
2544
printAttributes (PBD);
2524
2545
2525
- printList (range (PBD->getNumPatternEntries ()), [&](auto idx, Label label) {
2526
- // Ensure that we have an object structure printed in parsable modes
2527
- // so that the children aren't directly rendered as array elements.
2528
- if (Writer.isParsable ())
2529
- printHead (" pattern_entry" , FieldLabelColor, label);
2530
-
2531
- printRec (PBD->getPattern (idx), Label::optional (" pattern" ));
2532
- if (PBD->getOriginalInit (idx)) {
2533
- printRec (PBD->getOriginalInit (idx), Label::always (" original_init" ));
2534
- }
2535
- if (PBD->getInit (idx)) {
2536
- printRec (PBD->getInit (idx), Label::always (" processed_init" ));
2537
- }
2546
+ printList (
2547
+ range (PBD->getNumPatternEntries ()),
2548
+ [&](auto idx, Label label) {
2549
+ printRecArbitrary (
2550
+ [&](Label label) {
2551
+ printHead (" pattern_entry" , FieldLabelColor, label);
2552
+
2553
+ if (PBD->getInitContext (idx))
2554
+ printField (PBD->getInitContext (idx),
2555
+ Label::always (" init_context" ));
2556
+
2557
+ printRec (PBD->getPattern (idx), Label::optional (" pattern" ));
2558
+ if (PBD->getOriginalInit (idx)) {
2559
+ printRec (PBD->getOriginalInit (idx),
2560
+ Label::always (" original_init" ));
2561
+ }
2562
+ if (PBD->getInit (idx)) {
2563
+ printRec (PBD->getInit (idx),
2564
+ Label::always (" processed_init" ));
2565
+ }
2538
2566
2539
- if (Writer.isParsable ())
2540
- printFoot ();
2541
- }, Label::optional (" pattern_entries" ));
2567
+ printFoot ();
2568
+ },
2569
+ Label::optional (" pattern_entry" ));
2570
+ },
2571
+ Label::optional (" pattern_entries" ));
2542
2572
printFoot ();
2543
2573
}
2544
2574
@@ -3095,14 +3125,17 @@ class PrintStmt : public StmtVisitor<PrintStmt, void, Label>,
3095
3125
}
3096
3126
void visitBreakStmt (BreakStmt *S, Label label) {
3097
3127
printCommon (S, " break_stmt" , label);
3128
+ printDeclContext (S);
3098
3129
printFoot ();
3099
3130
}
3100
3131
void visitContinueStmt (ContinueStmt *S, Label label) {
3101
3132
printCommon (S, " continue_stmt" , label);
3133
+ printDeclContext (S);
3102
3134
printFoot ();
3103
3135
}
3104
3136
void visitFallthroughStmt (FallthroughStmt *S, Label label) {
3105
3137
printCommon (S, " fallthrough_stmt" , label);
3138
+ printDeclContext (S);
3106
3139
printFoot ();
3107
3140
}
3108
3141
void visitSwitchStmt (SwitchStmt *S, Label label) {
@@ -3186,6 +3219,7 @@ class PrintStmt : public StmtVisitor<PrintStmt, void, Label>,
3186
3219
3187
3220
void visitDoCatchStmt (DoCatchStmt *S, Label label) {
3188
3221
printCommon (S, " do_catch_stmt" , label);
3222
+ printDeclContext (S);
3189
3223
printThrowDest (S->rethrows (), /* wantNothrow=*/ true );
3190
3224
printRec (S->getBody (), Label::always (" body" ));
3191
3225
printRecRange (S->getCatches (), Ctx, Label::always (" catch_stmts" ));
@@ -4348,6 +4382,7 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, Label>,
4348
4382
4349
4383
void visitSingleValueStmtExpr (SingleValueStmtExpr *E, Label label) {
4350
4384
printCommon (E, " single_value_stmt_expr" , label);
4385
+ printDeclContext (E);
4351
4386
printRec (E->getStmt (), &E->getDeclContext ()->getASTContext (),
4352
4387
Label::optional (" stmt" ));
4353
4388
printFoot ();
@@ -4382,6 +4417,7 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, Label>,
4382
4417
4383
4418
void visitMacroExpansionExpr (MacroExpansionExpr *E, Label label) {
4384
4419
printCommon (E, " macro_expansion_expr" , label);
4420
+ printDeclContext (E);
4385
4421
4386
4422
printFieldQuoted (E->getMacroName (), Label::always (" name" ), IdentifierColor);
4387
4423
printField (E->getRawDiscriminator (), Label::always (" discriminator" ),
@@ -4483,6 +4519,7 @@ class PrintTypeRepr : public TypeReprVisitor<PrintTypeRepr, void, Label>,
4483
4519
printFieldQuoted (T->getNameRef (), Label::always (" id" ), IdentifierColor);
4484
4520
if (T->isBound ()) {
4485
4521
printReferencedDeclWithContextField (T->getBoundDecl (), Label::always (" bind" ));
4522
+ printDeclContext (T);
4486
4523
} else {
4487
4524
printFlag (" unbound" );
4488
4525
}
@@ -4975,6 +5012,11 @@ class PrintAttribute : public AttributeVisitor<PrintAttribute, void, Label>,
4975
5012
}
4976
5013
void visitCustomAttr (CustomAttr *Attr, Label label) {
4977
5014
printCommon (Attr, " custom_attr" , label);
5015
+
5016
+ printField (
5017
+ static_cast <void *>(static_cast <DeclContext *>(Attr->getInitContext ())),
5018
+ Label::always (" init_context" ));
5019
+
4978
5020
if (Attr->getType ()) {
4979
5021
printTypeField (Attr->getType (), Label::always (" type" ));
4980
5022
} else if (MemberLoading == ASTDumpMemberLoading::TypeChecked) {
@@ -5051,7 +5093,7 @@ class PrintAttribute : public AttributeVisitor<PrintAttribute, void, Label>,
5051
5093
}
5052
5094
void visitImplementsAttr (ImplementsAttr *Attr, Label label) {
5053
5095
printCommon (Attr, " implements_attr" , label);
5054
- if (Writer.isParsable ()) {
5096
+ if (Writer.isParsable () && isTypeChecked () ) {
5055
5097
// Print the resolved protocol's USR in parsable outputs, not the
5056
5098
// TypeRepr.
5057
5099
if (auto PD = Attr->getCachedProtocol (DC); PD && *PD != nullptr ) {
@@ -5213,7 +5255,7 @@ class PrintAttribute : public AttributeVisitor<PrintAttribute, void, Label>,
5213
5255
Label label) {
5214
5256
printCommon (Attr, " restated_objc_conformance_attr" , label);
5215
5257
if (Attr->Proto ) {
5216
- if (Writer.isParsable ()) {
5258
+ if (Writer.isParsable () && isTypeChecked () ) {
5217
5259
printFieldQuoted (declUSR (Attr->Proto ), Label::optional (" proto" ));
5218
5260
} else {
5219
5261
printFieldRaw ([&](auto &out) { Attr->Proto ->dumpRef (out); },
@@ -5294,7 +5336,7 @@ class PrintAttribute : public AttributeVisitor<PrintAttribute, void, Label>,
5294
5336
Label label) {
5295
5337
printCommon (Attr, " synthesized_protocol_attr" , label);
5296
5338
printFlag (Attr->isUnchecked (), " unchecked" );
5297
- if (Writer.isParsable ()) {
5339
+ if (Writer.isParsable () && isTypeChecked () ) {
5298
5340
printFieldQuoted (declUSR (Attr->getProtocol ()),
5299
5341
Label::optional (" protocol" ));
5300
5342
} else {
@@ -5491,7 +5533,7 @@ class PrintConformance : public PrintBase {
5491
5533
printFlag (" no_witness" );
5492
5534
else if (witness.getDecl () == req)
5493
5535
printFlag (" dynamic_witness" );
5494
- else if (Writer.isParsable ()) {
5536
+ else if (Writer.isParsable () && isTypeChecked () ) {
5495
5537
printFieldQuoted (declUSR (witness.getDecl ()),
5496
5538
Label::always (" witness" ));
5497
5539
} else {
0 commit comments