Skip to content
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

KE2: Extract some expr/stmt kinds #17664

Merged
merged 2 commits into from
Oct 8, 2024

Conversation

tamasvajk
Copy link
Contributor

No description provided.

@github-actions github-actions bot added the Java label Oct 4, 2024
@tamasvajk tamasvajk marked this pull request as ready for review October 4, 2024 11:49
@tamasvajk tamasvajk requested a review from a team as a code owner October 4, 2024 11:49
Copy link
Contributor

@igfoo igfoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for any comments to be addressed in a follow-up PR if that's easier.

is KtLabeledExpression -> {
// TODO: we could handle this here, or in each child that might have a label
// We're handling it in the children with the below
extractExpression(e.baseExpression!!, callable, parent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we'll want to have a helper that logs an error, and returns an @errorexpr, if this is null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can check at the end for all instances of !! and add the logging.

val locId = tw.getLocation(e)
tw.writeStmts_throwstmt(id, stmtParent.parent, stmtParent.idx, callable)
tw.writeHasLocation(id, locId)
val thrown = e.thrownExpression!!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Called from here too

}
for ((catchIdx, catchClause) in e.catchClauses.withIndex()) {
val catchId = tw.getFreshIdLabel<DbCatchclause>()
tw.writeStmts_catchclause(catchId, id, catchIdx, callable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a little odd that the dbscheme has a catchclause but not a finallyclause. I wonder if we should change that.

val parent: Label<out DbStmtparent>

val label = (loop.parent as? KtLabeledExpression)?.getLabelName()
if (label != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the logic of the old code, but with the PSI representation it would be more natural to me to write this as

val loopParent = loop.parent
if (loopParent is KtLabeledExpression) {
    val label = loopParent.getLabelName()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll remove this altogether later, and handle KtLabeledExpression explicitly in extractExpression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a TODO comment, so we don't forget about it, then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extractExpressionExpr(loop.condition, callable, id, 0, id)
}
}
val condition = loop.condition!!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know OTTOMH if this should be an errorexpr if it's null, or if that might be valid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

condition is marked with IfNotParsed, which has the following description:

Comes along with @nullable to indicate null is only possible if parsing error present

So I think this should be an error expression.


return id
val body = loop.body
if (body != null && bodyIdx != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there some theoretically impossible situations we should log about here? e.g. non-null-body with nulll-index?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the null case was introduced to handle enhanced for loops.

@tamasvajk tamasvajk merged commit 7c3fb32 into github:ke2 Oct 8, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants