Skip to content

[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

Closed

Conversation

Kacper20
Copy link
Contributor

@Kacper20 Kacper20 commented Sep 26, 2017

Opposite refactor to this one.
Behavior is as follows:

  • only one try in do/catch statement — statement is removed, code that is contained in do block is untouched (except of added exclamation to try)
  • try expr that isn't nested in any do/catch — exclamation is added
  • try that is among many other tries in do/catch statement — exclamation is added

I 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 selected TryExpr and extract it along with all the preceding nodes out of the do/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

Copy link
Contributor

@nkcsgexi nkcsgexi left a 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)) {
Copy link
Contributor

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, "");
Copy link
Contributor

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);
Copy link
Contributor

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, "");
Copy link
Contributor

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.

@nkcsgexi
Copy link
Contributor

@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?

@Kacper20
Copy link
Contributor Author

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 remove function in another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants