Skip to content

[kotlin2cpg] Emit JUMP_ARGUMENT edges for labeled break/continue statements#6005

Open
SuperUserDone wants to merge 3 commits into
masterfrom
louis/GH-8864-kotlin2cpg
Open

[kotlin2cpg] Emit JUMP_ARGUMENT edges for labeled break/continue statements#6005
SuperUserDone wants to merge 3 commits into
masterfrom
louis/GH-8864-kotlin2cpg

Conversation

@SuperUserDone
Copy link
Copy Markdown
Contributor

@SuperUserDone SuperUserDone requested a review from ml86 May 26, 2026 11:58
Copy link
Copy Markdown
Contributor

@ml86 ml86 left a comment

Choose a reason for hiding this comment

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

Can you please put the code to create the AST for a break and continue in reusable form into x2cpgs AstCreatorBase class. That way also other frontends can benefit from it.

@SuperUserDone SuperUserDone force-pushed the louis/GH-8864-kotlin2cpg branch from 407d164 to 4e7812a Compare May 27, 2026 15:13
Comment on lines +251 to +258
def breakAst(node: Node, codeStr: String, labelName: Option[String]): Ast =
labeledJumpAst(node, ControlStructureTypes.BREAK, codeStr, labelName)

/** Creates an AST for a continue statement. When `labelName` is present a `JumpLabel` child is created at order 1 and
* connected to the continue node via a `JUMP_ARGUMENT` edge.
*/
def continueAst(node: Node, codeStr: String, labelName: Option[String]): Ast =
labeledJumpAst(node, ControlStructureTypes.CONTINUE, codeStr, labelName)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did you go for optional labelName? We currently have two kinds of break/continue statements we support. One with a label and one with an integer indicating the number of levels to jump out. The None case would be a third option.
I suggest you create one breakAst which take String and which take Int to implement those two cases. Same for continue.

Copy link
Copy Markdown
Contributor Author

@SuperUserDone SuperUserDone Jun 2, 2026

Choose a reason for hiding this comment

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

Was under the impression that there are 3 cases:

  • Label, eg break x
  • Integer, eg break 1
  • No argument, eg break

No argument would be handled by emitting no edge and no label or integer, only the control structure node.

Made it so the break without an argument is equivalent to break 1.

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