@@ -35,28 +35,25 @@ using namespace swift;
3535
3636void PrettyStackTraceDecl::print (llvm::raw_ostream &out) const {
3737 out << " While " << Action << ' ' ;
38- if (!TheDecl) {
39- out << " NULL declaration!\n " ;
40- return ;
41- }
42- printDeclDescription (out, TheDecl, TheDecl->getASTContext ());
38+ printDeclDescription (out, TheDecl);
4339}
4440
4541void PrettyStackTraceDeclAndSubst::print (llvm::raw_ostream &out) const {
4642 out << " While " << action << ' ' ;
47- if (!decl) {
48- out << " NULL declaration!\n " ;
49- return ;
50- }
51- printDeclDescription (out, decl, decl->getASTContext ());
43+ printDeclDescription (out, decl);
5244
5345 out << " with substitution map: " ;
5446 subst.dump (out);
5547}
5648
5749
5850void swift::printDeclDescription (llvm::raw_ostream &out, const Decl *D,
59- const ASTContext &Context, bool addNewline) {
51+ bool addNewline) {
52+ if (!D) {
53+ out << " NULL declaration!" ;
54+ if (addNewline) out << ' \n ' ;
55+ return ;
56+ }
6057 SourceLoc loc = D->getStartLoc ();
6158 bool hasPrintedName = false ;
6259 if (auto *named = dyn_cast<ValueDecl>(D)) {
@@ -114,7 +111,7 @@ void swift::printDeclDescription(llvm::raw_ostream &out, const Decl *D,
114111
115112 if (loc.isValid ()) {
116113 out << " (at " ;
117- loc.print (out, Context .SourceMgr );
114+ loc.print (out, D-> getASTContext () .SourceMgr );
118115 out << ' )' ;
119116 } else {
120117 out << " (in module '" << D->getModuleContext ()->getName () << " ')" ;
@@ -124,25 +121,25 @@ void swift::printDeclDescription(llvm::raw_ostream &out, const Decl *D,
124121
125122void PrettyStackTraceAnyFunctionRef::print (llvm::raw_ostream &out) const {
126123 out << " While " << Action << ' ' ;
127- auto &Context = TheRef.getAsDeclContext ()->getASTContext ();
128- if (auto *AFD = TheRef.getAbstractFunctionDecl ())
129- printDeclDescription (out, AFD, Context);
130- else {
124+ if (auto *AFD = TheRef.getAbstractFunctionDecl ()) {
125+ printDeclDescription (out, AFD);
126+ } else {
131127 auto *ACE = TheRef.getAbstractClosureExpr ();
132- printExprDescription (out, ACE, Context );
128+ printExprDescription (out, ACE, ACE-> getASTContext () );
133129 }
134130}
135131
136132void PrettyStackTraceFreestandingMacroExpansion::print (
137133 llvm::raw_ostream &out) const {
138134 out << " While " << Action << ' ' ;
139- auto &Context = Expansion->getDeclContext ()->getASTContext ();
140135 switch (Expansion->getFreestandingMacroKind ()) {
141- case FreestandingMacroKind::Expr:
136+ case FreestandingMacroKind::Expr: {
137+ auto &Context = Expansion->getDeclContext ()->getASTContext ();
142138 printExprDescription (out, cast<MacroExpansionExpr>(Expansion), Context);
143139 break ;
140+ }
144141 case FreestandingMacroKind::Decl:
145- printDeclDescription (out, cast<MacroExpansionDecl>(Expansion), Context );
142+ printDeclDescription (out, cast<MacroExpansionDecl>(Expansion));
146143 break ;
147144 }
148145}
@@ -277,7 +274,7 @@ void swift::printConformanceDescription(llvm::raw_ostream &out,
277274 }
278275
279276 out << " protocol conformance to " ;
280- printDeclDescription (out, conformance->getProtocol (), ctxt, /* newline*/ false );
277+ printDeclDescription (out, conformance->getProtocol (), /* newline*/ false );
281278 out << " for " ;
282279 printTypeDescription (out, conformance->getType (), ctxt, addNewline);
283280}
0 commit comments