@@ -482,21 +482,22 @@ namespace {
482482 raw_ostream &OS;
483483 unsigned Indent;
484484 public:
485+ bool ParseIfNeeded;
485486 llvm::function_ref<Type(Expr *)> GetTypeOfExpr;
486487 llvm::function_ref<Type(TypeRepr *)> GetTypeOfTypeRepr;
487488 llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
488489 GetTypeOfKeyPathComponent;
489490 char quote = ' "' ;
490491
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) {}
500501
501502 bool hasNonStandardOutput () {
502503 return &OS != &llvm::errs () && &OS != &llvm::dbgs ();
@@ -1301,7 +1302,9 @@ namespace {
13011302 break ;
13021303 }
13031304
1304- for (Decl *D : IDC->getMembers ()) {
1305+ auto members = ParseIfNeeded ? IDC->getMembers ()
1306+ : IDC->getCurrentMembersWithoutLoading ();
1307+ for (Decl *D : members) {
13051308 printRec (D);
13061309 }
13071310 printFoot ();
@@ -1313,7 +1316,9 @@ namespace {
13131316 OS << SF.getFilename ();
13141317 });
13151318
1316- if (auto items = SF.getCachedTopLevelItems ()) {
1319+ auto items =
1320+ ParseIfNeeded ? SF.getTopLevelItems () : SF.getCachedTopLevelItems ();
1321+ if (items) {
13171322 for (auto item : *items) {
13181323 if (item.isImplicit ())
13191324 continue ;
@@ -1556,7 +1561,7 @@ namespace {
15561561 });
15571562 }
15581563
1559- if (auto Body = D->getBody (/* canSynthesize=*/ false )) {
1564+ if (auto Body = D->getBody (/* canSynthesize=*/ ParseIfNeeded )) {
15601565 printRec (Body, &D->getASTContext ());
15611566 }
15621567 }
@@ -1858,13 +1863,7 @@ void SourceFile::dump() const {
18581863}
18591864
18601865void 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 );
18681867 llvm::errs () << ' \n ' ;
18691868}
18701869
@@ -1889,13 +1888,16 @@ class PrintStmt : public StmtVisitor<PrintStmt, void, StringRef>,
18891888 using PrintBase::PrintBase;
18901889 const ASTContext *Ctx;
18911890
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) {}
18991901
19001902 using PrintBase::printRec;
19011903
@@ -3259,8 +3261,8 @@ void Expr::dump(raw_ostream &OS, llvm::function_ref<Type(Expr *)> getTypeOfExpr,
32593261 llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
32603262 getTypeOfKeyPathComponent,
32613263 unsigned Indent) const {
3262- PrintExpr (OS, Indent, getTypeOfExpr, getTypeOfTypeRepr ,
3263- getTypeOfKeyPathComponent)
3264+ PrintExpr (OS, Indent, /* parseIfNeeded */ false , getTypeOfExpr ,
3265+ getTypeOfTypeRepr, getTypeOfKeyPathComponent)
32643266 .visit (const_cast <Expr *>(this ), " " );
32653267}
32663268
@@ -3564,8 +3566,9 @@ void PrintBase::printRec(Decl *D, StringRef label) {
35643566 printHead (" <null decl>" , DeclColor, label);
35653567 printFoot ();
35663568 } 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);
35693572 }
35703573 }, label);
35713574}
@@ -3575,8 +3578,9 @@ void PrintBase::printRec(Expr *E, StringRef label) {
35753578 printHead (" <null expr>" , ExprColor, label);
35763579 printFoot ();
35773580 } 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);
35803584 }
35813585 }, label);
35823586}
@@ -3586,8 +3590,9 @@ void PrintBase::printRec(Stmt *S, const ASTContext *Ctx, StringRef label) {
35863590 printHead (" <null stmt>" , ExprColor, label);
35873591 printFoot ();
35883592 } 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);
35913596 }
35923597 }, label);
35933598}
@@ -3597,8 +3602,9 @@ void PrintBase::printRec(TypeRepr *T, StringRef label) {
35973602 printHead (" <null typerepr>" , TypeReprColor, label);
35983603 printFoot ();
35993604 } 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);
36023608 }
36033609 }, label);
36043610}
@@ -3608,9 +3614,9 @@ void PrintBase::printRec(const Pattern *P, StringRef label) {
36083614 printHead (" <null pattern>" , PatternColor, label);
36093615 printFoot ();
36103616 } 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);
36143620 }
36153621 }, label);
36163622}
@@ -4536,8 +4542,9 @@ namespace {
45364542 printHead (" <null type>" , DeclColor, label);
45374543 printFoot ();
45384544 } 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);
45414548 }
45424549 }, label);
45434550 }
0 commit comments