Skip to content

Commit 754f21d

Browse files
authored
Merge pull request swiftlang#32205 from AnthonyLatsis/pretty-const-stacktrace
[NFC] AST: const-qualify ASTContext refs in PrettyStackTrace.h
2 parents 31cf1f2 + b68d827 commit 754f21d

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

include/swift/AST/PrettyStackTrace.h

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,24 @@ namespace swift {
3838
class TypeRepr;
3939

4040
void printSourceLocDescription(llvm::raw_ostream &out, SourceLoc loc,
41-
ASTContext &Context, bool addNewline = true);
41+
const ASTContext &Context,
42+
bool addNewline = true);
4243

4344
/// PrettyStackTraceLocation - Observe that we are doing some
4445
/// processing starting at a fixed location.
4546
class PrettyStackTraceLocation : public llvm::PrettyStackTraceEntry {
46-
ASTContext &Context;
47+
const ASTContext &Context;
4748
SourceLoc Loc;
4849
const char *Action;
4950
public:
50-
PrettyStackTraceLocation(ASTContext &C, const char *action, SourceLoc loc)
51+
PrettyStackTraceLocation(const ASTContext &C, const char *action,
52+
SourceLoc loc)
5153
: Context(C), Loc(loc), Action(action) {}
5254
virtual void print(llvm::raw_ostream &OS) const;
5355
};
5456

5557
void printDeclDescription(llvm::raw_ostream &out, const Decl *D,
56-
ASTContext &Context, bool addNewline = true);
58+
const ASTContext &Context, bool addNewline = true);
5759

5860
/// PrettyStackTraceDecl - Observe that we are processing a specific
5961
/// declaration.
@@ -78,60 +80,60 @@ class PrettyStackTraceAnyFunctionRef : public llvm::PrettyStackTraceEntry {
7880
};
7981

8082
void printExprDescription(llvm::raw_ostream &out, Expr *E,
81-
ASTContext &Context, bool addNewline = true);
83+
const ASTContext &Context, bool addNewline = true);
8284

8385
/// PrettyStackTraceExpr - Observe that we are processing a specific
8486
/// expression.
8587
class PrettyStackTraceExpr : public llvm::PrettyStackTraceEntry {
86-
ASTContext &Context;
88+
const ASTContext &Context;
8789
Expr *TheExpr;
8890
const char *Action;
8991
public:
90-
PrettyStackTraceExpr(ASTContext &C, const char *action, Expr *E)
92+
PrettyStackTraceExpr(const ASTContext &C, const char *action, Expr *E)
9193
: Context(C), TheExpr(E), Action(action) {}
9294
virtual void print(llvm::raw_ostream &OS) const;
9395
};
9496

9597
void printStmtDescription(llvm::raw_ostream &out, Stmt *S,
96-
ASTContext &Context, bool addNewline = true);
98+
const ASTContext &Context, bool addNewline = true);
9799

98100
/// PrettyStackTraceStmt - Observe that we are processing a specific
99101
/// statement.
100102
class PrettyStackTraceStmt : public llvm::PrettyStackTraceEntry {
101-
ASTContext &Context;
103+
const ASTContext &Context;
102104
Stmt *TheStmt;
103105
const char *Action;
104106
public:
105-
PrettyStackTraceStmt(ASTContext &C, const char *action, Stmt *S)
107+
PrettyStackTraceStmt(const ASTContext &C, const char *action, Stmt *S)
106108
: Context(C), TheStmt(S), Action(action) {}
107109
virtual void print(llvm::raw_ostream &OS) const;
108110
};
109111

110112
void printPatternDescription(llvm::raw_ostream &out, Pattern *P,
111-
ASTContext &Context, bool addNewline = true);
113+
const ASTContext &Context, bool addNewline = true);
112114

113115
/// PrettyStackTracePattern - Observe that we are processing a
114116
/// specific pattern.
115117
class PrettyStackTracePattern : public llvm::PrettyStackTraceEntry {
116-
ASTContext &Context;
118+
const ASTContext &Context;
117119
Pattern *ThePattern;
118120
const char *Action;
119121
public:
120-
PrettyStackTracePattern(ASTContext &C, const char *action, Pattern *P)
122+
PrettyStackTracePattern(const ASTContext &C, const char *action, Pattern *P)
121123
: Context(C), ThePattern(P), Action(action) {}
122124
virtual void print(llvm::raw_ostream &OS) const;
123125
};
124126

125127
void printTypeDescription(llvm::raw_ostream &out, Type T,
126-
ASTContext &Context, bool addNewline = true);
128+
const ASTContext &Context, bool addNewline = true);
127129

128130
/// PrettyStackTraceType - Observe that we are processing a specific type.
129131
class PrettyStackTraceType : public llvm::PrettyStackTraceEntry {
130-
ASTContext &Context;
132+
const ASTContext &Context;
131133
Type TheType;
132134
const char *Action;
133135
public:
134-
PrettyStackTraceType(ASTContext &C, const char *action, Type type)
136+
PrettyStackTraceType(const ASTContext &C, const char *action, Type type)
135137
: Context(C), TheType(type), Action(action) {}
136138
virtual void print(llvm::raw_ostream &OS) const;
137139
};
@@ -149,31 +151,33 @@ class PrettyStackTraceClangType : public llvm::PrettyStackTraceEntry {
149151

150152
/// Observe that we are processing a specific type representation.
151153
class PrettyStackTraceTypeRepr : public llvm::PrettyStackTraceEntry {
152-
ASTContext &Context;
154+
const ASTContext &Context;
153155
TypeRepr *TheType;
154156
const char *Action;
155157
public:
156-
PrettyStackTraceTypeRepr(ASTContext &C, const char *action, TypeRepr *type)
158+
PrettyStackTraceTypeRepr(const ASTContext &C, const char *action,
159+
TypeRepr *type)
157160
: Context(C), TheType(type), Action(action) {}
158161
virtual void print(llvm::raw_ostream &OS) const;
159162
};
160163

161164
/// PrettyStackTraceConformance - Observe that we are processing a
162165
/// specific protocol conformance.
163166
class PrettyStackTraceConformance : public llvm::PrettyStackTraceEntry {
164-
ASTContext &Context;
167+
const ASTContext &Context;
165168
const ProtocolConformance *Conformance;
166169
const char *Action;
167170
public:
168-
PrettyStackTraceConformance(ASTContext &C, const char *action,
171+
PrettyStackTraceConformance(const ASTContext &C, const char *action,
169172
const ProtocolConformance *conformance)
170173
: Context(C), Conformance(conformance), Action(action) {}
171174
virtual void print(llvm::raw_ostream &OS) const;
172175
};
173176

174177
void printConformanceDescription(llvm::raw_ostream &out,
175178
const ProtocolConformance *conformance,
176-
ASTContext &Context, bool addNewline = true);
179+
const ASTContext &Context,
180+
bool addNewline = true);
177181

178182
class PrettyStackTraceGenericSignature : public llvm::PrettyStackTraceEntry {
179183
const char *Action;

lib/AST/PrettyStackTrace.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void PrettyStackTraceDecl::print(llvm::raw_ostream &out) const {
4343
}
4444

4545
void swift::printDeclDescription(llvm::raw_ostream &out, const Decl *D,
46-
ASTContext &Context, bool addNewline) {
46+
const ASTContext &Context, bool addNewline) {
4747
SourceLoc loc = D->getStartLoc();
4848
bool hasPrintedName = false;
4949
if (auto *named = dyn_cast<ValueDecl>(D)) {
@@ -127,7 +127,7 @@ void PrettyStackTraceExpr::print(llvm::raw_ostream &out) const {
127127
}
128128

129129
void swift::printExprDescription(llvm::raw_ostream &out, Expr *E,
130-
ASTContext &Context, bool addNewline) {
130+
const ASTContext &Context, bool addNewline) {
131131
out << "expression at ";
132132
E->getSourceRange().print(out, Context.SourceMgr);
133133
if (addNewline) out << '\n';
@@ -143,7 +143,7 @@ void PrettyStackTraceStmt::print(llvm::raw_ostream &out) const {
143143
}
144144

145145
void swift::printStmtDescription(llvm::raw_ostream &out, Stmt *S,
146-
ASTContext &Context, bool addNewline) {
146+
const ASTContext &Context, bool addNewline) {
147147
out << "statement at ";
148148
S->getSourceRange().print(out, Context.SourceMgr);
149149
if (addNewline) out << '\n';
@@ -159,7 +159,8 @@ void PrettyStackTracePattern::print(llvm::raw_ostream &out) const {
159159
}
160160

161161
void swift::printPatternDescription(llvm::raw_ostream &out, Pattern *P,
162-
ASTContext &Context, bool addNewline) {
162+
const ASTContext &Context,
163+
bool addNewline) {
163164
out << "pattern at ";
164165
P->getSourceRange().print(out, Context.SourceMgr);
165166
if (addNewline) out << '\n';
@@ -198,7 +199,7 @@ void PrettyStackTraceType::print(llvm::raw_ostream &out) const {
198199
}
199200

200201
void swift::printTypeDescription(llvm::raw_ostream &out, Type type,
201-
ASTContext &Context, bool addNewline) {
202+
const ASTContext &Context, bool addNewline) {
202203
out << "type '" << type << '\'';
203204
if (Decl *decl = InterestingDeclForType().visit(type)) {
204205
if (decl->getSourceRange().isValid()) {
@@ -236,7 +237,8 @@ void PrettyStackTraceConformance::print(llvm::raw_ostream &out) const {
236237

237238
void swift::printConformanceDescription(llvm::raw_ostream &out,
238239
const ProtocolConformance *conformance,
239-
ASTContext &ctxt, bool addNewline) {
240+
const ASTContext &ctxt,
241+
bool addNewline) {
240242
if (!conformance) {
241243
out << "NULL protocol conformance!";
242244
if (addNewline) out << '\n';
@@ -250,7 +252,7 @@ void swift::printConformanceDescription(llvm::raw_ostream &out,
250252
}
251253

252254
void swift::printSourceLocDescription(llvm::raw_ostream &out,
253-
SourceLoc loc, ASTContext &ctx,
255+
SourceLoc loc, const ASTContext &ctx,
254256
bool addNewline) {
255257
loc.print(out, ctx.SourceMgr);
256258
if (addNewline) out << '\n';

0 commit comments

Comments
 (0)