|
1 | 1 | package org.usvm.machine.expr |
2 | 2 |
|
| 3 | +import io.ksmt.expr.KFpRoundingMode |
3 | 4 | import io.ksmt.utils.asExpr |
4 | 5 | import mu.KotlinLogging |
5 | 6 | import org.jacodb.ets.model.EtsArrayType |
@@ -76,6 +77,13 @@ internal fun TsExprResolver.tryApproximateInstanceCall( |
76 | 77 | } |
77 | 78 | } |
78 | 79 |
|
| 80 | + // Handle `Math` method calls |
| 81 | + if (expr.instance.name == "Math") { |
| 82 | + if (expr.callee.name == "floor") { |
| 83 | + return from(handleMathFloor(expr)) |
| 84 | + } |
| 85 | + } |
| 86 | + |
79 | 87 | val instance = scope.calcOnState { resolve(expr.instance)?.asExpr(addressSort) } |
80 | 88 | ?: return TsExprApproximationResult.ResolveFailure |
81 | 89 |
|
@@ -255,6 +263,27 @@ private fun TsExprResolver.handlePromiseResolveReject(expr: EtsInstanceCallExpr) |
255 | 263 | promise |
256 | 264 | } |
257 | 265 |
|
| 266 | +private fun TsExprResolver.handleMathFloor(expr: EtsInstanceCallExpr): UExpr<*>? = with(ctx) { |
| 267 | + check(expr.args.size == 1) { |
| 268 | + "Math.floor() should have exactly one argument, but got ${expr.args.size}" |
| 269 | + } |
| 270 | + val arg = resolve(expr.args.single()) ?: return null |
| 271 | + |
| 272 | + when (arg.sort) { |
| 273 | + fp64Sort -> mkFpRoundToIntegralExpr( |
| 274 | + roundingMode = mkFpRoundingModeExpr(KFpRoundingMode.RoundTowardNegative), |
| 275 | + value = arg.asExpr(fp64Sort), |
| 276 | + ) |
| 277 | + |
| 278 | + sizeSort -> arg.asExpr(sizeSort) |
| 279 | + |
| 280 | + else -> { |
| 281 | + logger.warn { "Unsupported argument sort for Math.floor(): ${arg.sort}" } |
| 282 | + null |
| 283 | + } |
| 284 | + } |
| 285 | +} |
| 286 | + |
258 | 287 | /** |
259 | 288 | * Handles the `Array.push(...items)` method call. |
260 | 289 | * Appends the specified `items` to the end of the array. |
|
0 commit comments