Skip to content

Commit 3609656

Browse files
committed
add a dumper for effect Classification for debugging
1 parent a5ad953 commit 3609656

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,17 @@ class PotentialThrowReason {
272272
CallRethrowsWithDefaultThrowingArgument,
273273
};
274274

275+
static StringRef kindToString(Kind k) {
276+
switch (k) {
277+
case Kind::Throw: return "Throw";
278+
case Kind::CallThrows: return "CallThrows";
279+
case Kind::CallRethrowsWithExplicitThrowingArgument:
280+
return "CallRethrowsWithExplicitThrowingArgument";
281+
case Kind::CallRethrowsWithDefaultThrowingArgument:
282+
return "CallRethrowsWithDefaultThrowingArgument";
283+
}
284+
}
285+
275286
private:
276287
Expr *TheExpression;
277288
Kind TheKind;
@@ -329,6 +340,26 @@ class Classification {
329340
ThrowingKind Result = ThrowingKind::None;
330341
Optional<PotentialThrowReason> Reason;
331342

343+
void print(raw_ostream &out) const {
344+
out << "{ IsInvalid = " << IsInvalid
345+
<< ", IsAsync = " << IsAsync
346+
<< ", Result = ThrowingKind::";
347+
348+
switch(Result) {
349+
case ThrowingKind::None: out << "None"; break;
350+
case ThrowingKind::RethrowingOnly: out << "RethrowingOnly"; break;
351+
case ThrowingKind::Throws: out << "Throws"; break;
352+
}
353+
354+
out << ", Reason = ";
355+
if (!Reason)
356+
out << "nil";
357+
else
358+
out << PotentialThrowReason::kindToString(Reason.getValue().getKind());
359+
360+
out << " }";
361+
}
362+
332363
public:
333364
Classification() : Result(ThrowingKind::None) {}
334365
explicit Classification(ThrowingKind result, PotentialThrowReason reason,
@@ -386,6 +417,10 @@ class Classification {
386417
}
387418

388419
bool isAsync() const { return IsAsync; }
420+
421+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
422+
LLVM_DUMP_METHOD void dump() const { print(llvm::errs()); }
423+
#endif
389424
};
390425

391426

0 commit comments

Comments
 (0)