-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Refactoring] SR-5743 Try To Force Try Refactor implementation #12128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great in general! Some minor comments 😄
struct TryExprCounter: public SourceEntityWalker { | ||
unsigned int Count = 0; | ||
bool walkToExprPre(Expr *E) { | ||
if (auto *FE = dyn_cast<TryExpr>(E)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we don't need FE
; so isa<TryExpr>(E)
is sufficient.
SM, | ||
DCStmt->getStartLoc(), | ||
FirstNodeStartLoc); | ||
EditConsumer.accept(SM, BeforeBodyRange, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a method in EditorConsumer
called remove(SM, CharSourceRange)
is cleaner than this. Could you add that method?
FirstNodeStartLoc); | ||
EditConsumer.accept(SM, BeforeBodyRange, ""); | ||
auto LastNodePastEndLoc = BCStmt->getElements() | ||
.back().getEndLoc().getAdvancedLocOrInvalid(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not sure the last token is of length 1
. Using Lexer::getLocForEndOfToken
instead.
SM, | ||
LastNodePastEndLoc, | ||
CatchRBraceLoc); | ||
EditConsumer.accept(SM, AfterBodyRange, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the newly added remove
function here too.
@Kacper20 thinking more about this, I'm little concerned that this refactoring is a transition from a more recommended language usage to a less recommended one. Personally, I'm not sure this is what we want to implicitly encourage. What do you think? |
Yeah, I think the same. Wasn't convinced by this but wanted to make one to learn more about the refactorings. Closing this and moving JIRA ticket to Resolved, then. I will add |
Opposite refactor to this one.
Behavior is as follows:
do/catch
statement — statement is removed, code that is contained indo
block is untouched (except of added exclamation totry
)try
expr that isn't nested in anydo/catch
— exclamation is addeddo/catch
statement — exclamation is addedI was thinking a lot about doing some more work in the last case. The alternative could be to take all of the nodes that are contained in
BraceStmt
, find the node that contains (or is) the selectedTryExpr
and extract it along with all the preceding nodes out of thedo/catch
statement. This is easy to implement, but I'm not sure whether it'll not be confusing to the user. What do you think?Resolves SR-5743.
cc @nkcsgexi @harlanhaskins