This is an archive of the discontinued LLVM Phabricator instance.

[clang][JumpDiagnostics] use StmtClass rather than dyn_cast chain NFC
AbandonedPublic

Authored by nickdesaulniers on Jul 17 2023, 12:23 PM.

Details

Summary

Avoid the anti-pattern of:

if dyn_cast<X>:
  ...
elif dyn_cast<Y>:
  ...
elif dyn_cast<Z>:
  ...

And simply switch on the statement class, as is done elsewhere in this
class. These cases are for classes with no shared inheritance lineage
beyond all inheriting from clang::Stmt.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 12:23 PM
nickdesaulniers requested review of this revision.Jul 17 2023, 12:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 12:23 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I'm not sure it is actually an anti-pattern. dyn_cast will transparently handle subclasses, should any be added in the future, but a switch wouldn't.

I'm not sure it is actually an anti-pattern. dyn_cast will transparently handle subclasses, should any be added in the future, but a switch wouldn't.

Yeah, I don't think we have a strong style preference either way, here, given that this can't be an exhaustive switch anyway.

nickdesaulniers abandoned this revision.Jul 18 2023, 10:07 AM

no worries then