mirror of
https://github.com/github/codeql.git
synced 2026-05-04 13:15:21 +02:00
Kotlin: When expressions
This commit is contained in:
@@ -633,8 +633,22 @@ case @expr.kind of
|
||||
| 72 = @intersectiontypeaccess
|
||||
| 73 = @switchexpr
|
||||
| 74 = @errorexpr
|
||||
| 75 = @whenexpr
|
||||
;
|
||||
|
||||
/** Holds if this `when` expression was written as an `if` expression. */
|
||||
when_if(unique int id: @whenexpr ref);
|
||||
|
||||
#keyset[whenid,idx]
|
||||
when_branch(
|
||||
int id: @whenbranch,
|
||||
int whenid: @whenexpr ref,
|
||||
int idx: int ref
|
||||
);
|
||||
|
||||
/** Holds if this `when` branch was written as an `else` branch. */
|
||||
when_branch_else(unique int id: @whenbranch ref);
|
||||
|
||||
@classinstancexpr = @newexpr | @lambdaexpr | @memberref
|
||||
|
||||
@annotation = @declannotation | @typeannotation
|
||||
@@ -713,7 +727,7 @@ memberRefBinding(
|
||||
int callable: @callable ref
|
||||
);
|
||||
|
||||
@exprparent = @stmt | @expr | @callable | @field | @fielddecl | @class | @interface | @param | @localvar | @typevariable;
|
||||
@exprparent = @stmt | @expr | @whenbranch | @callable | @field | @fielddecl | @class | @interface | @param | @localvar | @typevariable;
|
||||
|
||||
variableBinding(
|
||||
unique int expr: @varaccess ref,
|
||||
@@ -881,7 +895,7 @@ javadocText(
|
||||
|
||||
@locatable = @file | @class | @interface | @fielddecl | @field | @constructor | @method | @param | @exception
|
||||
| @boundedtype | @typebound | @array | @primitive
|
||||
| @import | @stmt | @expr | @localvar | @javadoc | @javadocTag | @javadocText
|
||||
| @import | @stmt | @expr | @whenbranch | @localvar | @javadoc | @javadocTag | @javadocText
|
||||
| @xmllocatable;
|
||||
|
||||
@top = @element | @locatable | @folder;
|
||||
|
||||
@@ -2133,3 +2133,33 @@ class Argument extends Expr {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** A Kotlin `when` expression. */
|
||||
class WhenExpr extends Expr, @whenexpr {
|
||||
override string toString() { result = "when ..." }
|
||||
|
||||
override string getHalsteadID() { result = "WhenExpr" }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "WhenExpr" }
|
||||
|
||||
/** Gets the `i`th branch. */
|
||||
WhenBranch getBranch(int i) {
|
||||
when_branch(result, this, i)
|
||||
}
|
||||
}
|
||||
|
||||
/** A Kotlin `when` branch. */
|
||||
class WhenBranch extends Top, @whenbranch {
|
||||
/** Gets the condition of this branch. */
|
||||
Expr getCondition() { result.isNthChildOf(this, 0) }
|
||||
|
||||
/** Gets the result of this branch. */
|
||||
Top getResult() {
|
||||
result.(Expr).isNthChildOf(this, 1) or
|
||||
result.(Stmt).isNthChildOf(this, 1)
|
||||
}
|
||||
|
||||
override string toString() { result = "... -> ..." }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "WhenBranch" }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user