mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
Kotlin: Add support for string templates
This commit is contained in:
@@ -1419,6 +1419,17 @@ class X {
|
|||||||
val exprParent = parent.expr(e, callable)
|
val exprParent = parent.expr(e, callable)
|
||||||
extractCall(e, callable, exprParent.parent, exprParent.idx)
|
extractCall(e, callable, exprParent.parent, exprParent.idx)
|
||||||
}
|
}
|
||||||
|
is IrStringConcatenation -> {
|
||||||
|
val exprParent = parent.expr(e, callable)
|
||||||
|
val id = tw.getFreshIdLabel<DbStringtemplateexpr>()
|
||||||
|
val type = useType(e.type)
|
||||||
|
val locId = tw.getLocation(e)
|
||||||
|
tw.writeExprs_stringtemplateexpr(id, type.javaResult.id, type.kotlinResult.id, exprParent.parent, exprParent.idx)
|
||||||
|
tw.writeHasLocation(id, locId)
|
||||||
|
e.arguments.forEachIndexed { i, a ->
|
||||||
|
extractExpressionExpr(a, callable, id, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
is IrConst<*> -> {
|
is IrConst<*> -> {
|
||||||
val exprParent = parent.expr(e, callable)
|
val exprParent = parent.expr(e, callable)
|
||||||
val v = e.value
|
val v = e.value
|
||||||
|
|||||||
@@ -670,6 +670,7 @@ case @expr.kind of
|
|||||||
| 77 = @safecastexpr
|
| 77 = @safecastexpr
|
||||||
| 78 = @notinstanceofexpr
|
| 78 = @notinstanceofexpr
|
||||||
| 79 = @stmtexpr
|
| 79 = @stmtexpr
|
||||||
|
| 80 = @stringtemplateexpr
|
||||||
;
|
;
|
||||||
|
|
||||||
/** Holds if this `when` expression was written as an `if` expression. */
|
/** Holds if this `when` expression was written as an `if` expression. */
|
||||||
|
|||||||
@@ -2246,3 +2246,24 @@ class StmtExpr extends Expr, @stmtexpr {
|
|||||||
|
|
||||||
override string getAPrimaryQlClass() { result = "StmtExpr" }
|
override string getAPrimaryQlClass() { result = "StmtExpr" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Kotlin string template expression. For example, `"foo${bar}baz"`.
|
||||||
|
*/
|
||||||
|
class StringTemplateExpr extends Expr, @stringtemplateexpr {
|
||||||
|
/**
|
||||||
|
* Gets the `i`th component of this string template.
|
||||||
|
*
|
||||||
|
* For example, in the string template `"foo${bar}baz"`, the 0th
|
||||||
|
* component is the string literal `"foo"`, the 1st component is
|
||||||
|
* the variable access `bar`, and the 2nd component is the string
|
||||||
|
* literal `"bar"`.
|
||||||
|
*/
|
||||||
|
Expr getComponent(int i) { result.isNthChildOf(this, i) }
|
||||||
|
|
||||||
|
override string toString() { result = "\"...\"" }
|
||||||
|
|
||||||
|
override string getHalsteadID() { result = "StringTemplateExpr" }
|
||||||
|
|
||||||
|
override string getAPrimaryQlClass() { result = "StringTemplateExpr" }
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user