[kotlin2cpg] Emit JUMP_ARGUMENT edges for labeled break/continue statements#6005
[kotlin2cpg] Emit JUMP_ARGUMENT edges for labeled break/continue statements#6005SuperUserDone wants to merge 3 commits into
Conversation
ml86
left a comment
There was a problem hiding this comment.
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.
407d164 to
4e7812a
Compare
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Kotlin2cpg of: https://github.com/ShiftLeftSecurity/codescience/issues/8864