@@ -482,21 +482,22 @@ namespace {
482
482
raw_ostream &OS;
483
483
unsigned Indent;
484
484
public:
485
+ bool ParseIfNeeded;
485
486
llvm::function_ref<Type(Expr *)> GetTypeOfExpr;
486
487
llvm::function_ref<Type(TypeRepr *)> GetTypeOfTypeRepr;
487
488
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
488
489
GetTypeOfKeyPathComponent;
489
490
char quote = ' "' ;
490
491
491
- explicit PrintBase (raw_ostream &os, unsigned indent = 0 ,
492
- llvm::function_ref<Type(Expr *)> getTypeOfExpr = defaultGetTypeOfExpr ,
493
- llvm::function_ref<Type(TypeRepr *)> getTypeOfTypeRepr = nullptr ,
494
- llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
495
- getTypeOfKeyPathComponent =
496
- defaultGetTypeOfKeyPathComponent)
497
- : OS(os), Indent(indent), GetTypeOfExpr(getTypeOfExpr ),
498
- GetTypeOfTypeRepr(getTypeOfTypeRepr),
499
- GetTypeOfKeyPathComponent(getTypeOfKeyPathComponent) { }
492
+ explicit PrintBase (
493
+ raw_ostream &os, unsigned indent = 0 , bool parseIfNeeded = false ,
494
+ llvm::function_ref<Type(Expr *)> getTypeOfExpr = defaultGetTypeOfExpr ,
495
+ llvm::function_ref<Type(TypeRepr *)> getTypeOfTypeRepr = nullptr,
496
+ llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
497
+ getTypeOfKeyPathComponent = defaultGetTypeOfKeyPathComponent)
498
+ : OS(os), Indent(indent), ParseIfNeeded(parseIfNeeded ),
499
+ GetTypeOfExpr(getTypeOfExpr), GetTypeOfTypeRepr(getTypeOfTypeRepr),
500
+ GetTypeOfKeyPathComponent(getTypeOfKeyPathComponent) {}
500
501
501
502
bool hasNonStandardOutput () {
502
503
return &OS != &llvm::errs () && &OS != &llvm::dbgs ();
@@ -1301,7 +1302,9 @@ namespace {
1301
1302
break ;
1302
1303
}
1303
1304
1304
- for (Decl *D : IDC->getMembers ()) {
1305
+ auto members = ParseIfNeeded ? IDC->getMembers ()
1306
+ : IDC->getCurrentMembersWithoutLoading ();
1307
+ for (Decl *D : members) {
1305
1308
printRec (D);
1306
1309
}
1307
1310
printFoot ();
@@ -1313,7 +1316,9 @@ namespace {
1313
1316
OS << SF.getFilename ();
1314
1317
});
1315
1318
1316
- if (auto items = SF.getCachedTopLevelItems ()) {
1319
+ auto items =
1320
+ ParseIfNeeded ? SF.getTopLevelItems () : SF.getCachedTopLevelItems ();
1321
+ if (items) {
1317
1322
for (auto item : *items) {
1318
1323
if (item.isImplicit ())
1319
1324
continue ;
@@ -1556,7 +1561,7 @@ namespace {
1556
1561
});
1557
1562
}
1558
1563
1559
- if (auto Body = D->getBody (/* canSynthesize=*/ false )) {
1564
+ if (auto Body = D->getBody (/* canSynthesize=*/ ParseIfNeeded )) {
1560
1565
printRec (Body, &D->getASTContext ());
1561
1566
}
1562
1567
}
@@ -1858,13 +1863,7 @@ void SourceFile::dump() const {
1858
1863
}
1859
1864
1860
1865
void SourceFile::dump (llvm::raw_ostream &OS, bool parseIfNeeded) const {
1861
- // If we're allowed to parse the SourceFile, do so now. We need to force the
1862
- // parsing request as by default the dumping logic tries not to kick any
1863
- // requests.
1864
- if (parseIfNeeded)
1865
- (void )getTopLevelItems ();
1866
-
1867
- PrintDecl (OS).visitSourceFile (*this );
1866
+ PrintDecl (OS, /* indent*/ 0 , parseIfNeeded).visitSourceFile (*this );
1868
1867
llvm::errs () << ' \n ' ;
1869
1868
}
1870
1869
@@ -1889,13 +1888,16 @@ class PrintStmt : public StmtVisitor<PrintStmt, void, StringRef>,
1889
1888
using PrintBase::PrintBase;
1890
1889
const ASTContext *Ctx;
1891
1890
1892
- PrintStmt (raw_ostream &os, const ASTContext *ctx, unsigned indent = 0 ,
1893
- llvm::function_ref<Type(Expr *)> getTypeOfExpr = defaultGetTypeOfExpr,
1894
- llvm::function_ref<Type(TypeRepr *)> getTypeOfTypeRepr = nullptr ,
1895
- llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
1896
- getTypeOfKeyPathComponent = defaultGetTypeOfKeyPathComponent)
1897
- : PrintBase(os, indent, getTypeOfExpr, getTypeOfTypeRepr,
1898
- getTypeOfKeyPathComponent), Ctx(ctx) { }
1891
+ PrintStmt (
1892
+ raw_ostream &os, const ASTContext *ctx, unsigned indent = 0 ,
1893
+ bool parseIfNeeded = false ,
1894
+ llvm::function_ref<Type(Expr *)> getTypeOfExpr = defaultGetTypeOfExpr,
1895
+ llvm::function_ref<Type(TypeRepr *)> getTypeOfTypeRepr = nullptr ,
1896
+ llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
1897
+ getTypeOfKeyPathComponent = defaultGetTypeOfKeyPathComponent)
1898
+ : PrintBase(os, indent, parseIfNeeded, getTypeOfExpr, getTypeOfTypeRepr,
1899
+ getTypeOfKeyPathComponent),
1900
+ Ctx (ctx) {}
1899
1901
1900
1902
using PrintBase::printRec;
1901
1903
@@ -3259,8 +3261,8 @@ void Expr::dump(raw_ostream &OS, llvm::function_ref<Type(Expr *)> getTypeOfExpr,
3259
3261
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
3260
3262
getTypeOfKeyPathComponent,
3261
3263
unsigned Indent) const {
3262
- PrintExpr (OS, Indent, getTypeOfExpr, getTypeOfTypeRepr ,
3263
- getTypeOfKeyPathComponent)
3264
+ PrintExpr (OS, Indent, /* parseIfNeeded */ false , getTypeOfExpr ,
3265
+ getTypeOfTypeRepr, getTypeOfKeyPathComponent)
3264
3266
.visit (const_cast <Expr *>(this ), " " );
3265
3267
}
3266
3268
@@ -3564,8 +3566,9 @@ void PrintBase::printRec(Decl *D, StringRef label) {
3564
3566
printHead (" <null decl>" , DeclColor, label);
3565
3567
printFoot ();
3566
3568
} else {
3567
- PrintDecl (OS, Indent, GetTypeOfExpr, GetTypeOfTypeRepr,
3568
- GetTypeOfKeyPathComponent).visit (D, label);
3569
+ PrintDecl (OS, Indent, ParseIfNeeded, GetTypeOfExpr, GetTypeOfTypeRepr,
3570
+ GetTypeOfKeyPathComponent)
3571
+ .visit (D, label);
3569
3572
}
3570
3573
}, label);
3571
3574
}
@@ -3575,8 +3578,9 @@ void PrintBase::printRec(Expr *E, StringRef label) {
3575
3578
printHead (" <null expr>" , ExprColor, label);
3576
3579
printFoot ();
3577
3580
} else {
3578
- PrintExpr (OS, Indent, GetTypeOfExpr, GetTypeOfTypeRepr,
3579
- GetTypeOfKeyPathComponent).visit (E, label);
3581
+ PrintExpr (OS, Indent, ParseIfNeeded, GetTypeOfExpr, GetTypeOfTypeRepr,
3582
+ GetTypeOfKeyPathComponent)
3583
+ .visit (E, label);
3580
3584
}
3581
3585
}, label);
3582
3586
}
@@ -3586,8 +3590,9 @@ void PrintBase::printRec(Stmt *S, const ASTContext *Ctx, StringRef label) {
3586
3590
printHead (" <null stmt>" , ExprColor, label);
3587
3591
printFoot ();
3588
3592
} else {
3589
- PrintStmt (OS, Ctx, Indent, GetTypeOfExpr, GetTypeOfTypeRepr,
3590
- GetTypeOfKeyPathComponent).visit (S, label);
3593
+ PrintStmt (OS, Ctx, Indent, ParseIfNeeded, GetTypeOfExpr,
3594
+ GetTypeOfTypeRepr, GetTypeOfKeyPathComponent)
3595
+ .visit (S, label);
3591
3596
}
3592
3597
}, label);
3593
3598
}
@@ -3597,8 +3602,9 @@ void PrintBase::printRec(TypeRepr *T, StringRef label) {
3597
3602
printHead (" <null typerepr>" , TypeReprColor, label);
3598
3603
printFoot ();
3599
3604
} else {
3600
- PrintTypeRepr (OS, Indent, GetTypeOfExpr, GetTypeOfTypeRepr,
3601
- GetTypeOfKeyPathComponent).visit (T, label);
3605
+ PrintTypeRepr (OS, Indent, ParseIfNeeded, GetTypeOfExpr, GetTypeOfTypeRepr,
3606
+ GetTypeOfKeyPathComponent)
3607
+ .visit (T, label);
3602
3608
}
3603
3609
}, label);
3604
3610
}
@@ -3608,9 +3614,9 @@ void PrintBase::printRec(const Pattern *P, StringRef label) {
3608
3614
printHead (" <null pattern>" , PatternColor, label);
3609
3615
printFoot ();
3610
3616
} else {
3611
- PrintPattern (OS, Indent, GetTypeOfExpr, GetTypeOfTypeRepr,
3612
- GetTypeOfKeyPathComponent). visit ( const_cast <Pattern *>(P),
3613
- label);
3617
+ PrintPattern (OS, Indent, ParseIfNeeded, GetTypeOfExpr, GetTypeOfTypeRepr,
3618
+ GetTypeOfKeyPathComponent)
3619
+ . visit ( const_cast <Pattern *>(P), label);
3614
3620
}
3615
3621
}, label);
3616
3622
}
@@ -4536,8 +4542,9 @@ namespace {
4536
4542
printHead (" <null type>" , DeclColor, label);
4537
4543
printFoot ();
4538
4544
} else {
4539
- PrintType (OS, Indent, GetTypeOfExpr, GetTypeOfTypeRepr,
4540
- GetTypeOfKeyPathComponent).visit (type, label);
4545
+ PrintType (OS, Indent, ParseIfNeeded, GetTypeOfExpr, GetTypeOfTypeRepr,
4546
+ GetTypeOfKeyPathComponent)
4547
+ .visit (type, label);
4541
4548
}
4542
4549
}, label);
4543
4550
}
0 commit comments