|
1 | 1 | package org.usvm
|
2 | 2 |
|
3 |
| -import org.ksmt.utils.asExpr |
4 | 3 | import org.usvm.util.SetRegion
|
5 | 4 | import org.usvm.util.emptyRegionTree
|
6 | 5 | import java.util.*
|
@@ -172,7 +171,7 @@ data class UMemoryRegion<RegionId : URegionId<Key>, Key, Sort : USort>(
|
172 | 171 | keyConverter: UMemoryKeyConverter<SrcKey, Key>,
|
173 | 172 | guard: UBoolExpr
|
174 | 173 | ): UMemoryRegion<RegionId, Key, Sort> {
|
175 |
| - val updatesCopy = updates.copy(fromRegion, fromKey, toKey, keyConverter, guard) |
| 174 | + val updatesCopy = updates.copyRange(fromRegion, fromKey, toKey, keyConverter, guard) |
176 | 175 | return UMemoryRegion(regionId, sort, updatesCopy, defaultValue, instantiator)
|
177 | 176 | }
|
178 | 177 | }
|
@@ -244,219 +243,6 @@ fun refIndexRangeRegion(
|
244 | 243 | idx2: USymbolicArrayIndex
|
245 | 244 | ): UArrayIndexRegion = indexRangeRegion(idx1.second, idx2.second)
|
246 | 245 |
|
247 |
| -/** |
248 |
| - * An interface that represents any possible type of regions that can be used in the memory. |
249 |
| - */ |
250 |
| -interface URegionId<Key> { |
251 |
| - fun <Field, ArrayType, Sort : USort> read( |
252 |
| - key: Key, |
253 |
| - sort: Sort, |
254 |
| - heap: UReadOnlySymbolicHeap<Field, ArrayType> |
255 |
| - ): UExpr<Sort> |
256 |
| - |
257 |
| - fun <Field, ArrayType, Sort : USort> write( |
258 |
| - key: Key, |
259 |
| - sort: Sort, |
260 |
| - heap: USymbolicHeap<Field, ArrayType>, |
261 |
| - value: UExpr<Sort>, |
262 |
| - guard: UBoolExpr |
263 |
| - ) |
264 |
| - |
265 |
| - fun <Field, ArrayType, SrcKey, Sort : USort> copy( |
266 |
| - from: Key, |
267 |
| - to: Key, |
268 |
| - sort: Sort, |
269 |
| - heap: USymbolicHeap<Field, ArrayType>, |
270 |
| - converter: UMemoryKeyConverter<Key, SrcKey>, |
271 |
| - guard: UBoolExpr |
272 |
| - ) |
273 |
| - |
274 |
| - fun <Field, ArrayType> keyMapper(composer: UComposer<Field, ArrayType>): KeyMapper<Key> |
275 |
| -} |
276 |
| - |
277 |
| -/** |
278 |
| - * A region id for a region storing the specific [field]. |
279 |
| - */ |
280 |
| -data class UInputFieldRegionId<Field> internal constructor( |
281 |
| - val field: Field |
282 |
| -) : URegionId<UHeapRef> { |
283 |
| - @Suppress("UNCHECKED_CAST") |
284 |
| - override fun <Field, ArrayType, Sort : USort> read( |
285 |
| - key: UHeapRef, |
286 |
| - sort: Sort, |
287 |
| - heap: UReadOnlySymbolicHeap<Field, ArrayType> |
288 |
| - ) = heap.readField(key, field as Field, sort).asExpr(sort) |
289 |
| - |
290 |
| - @Suppress("UNCHECKED_CAST") |
291 |
| - override fun <Field, ArrayType, Sort : USort> write( |
292 |
| - key: UHeapRef, |
293 |
| - sort: Sort, |
294 |
| - heap: USymbolicHeap<Field, ArrayType>, |
295 |
| - value: UExpr<Sort>, |
296 |
| - guard: UBoolExpr |
297 |
| - ) = heap.writeField(key, field as Field, sort, value, guard) |
298 |
| - |
299 |
| - override fun <Field, ArrayType, SrcKey, Sort : USort> copy( |
300 |
| - from: UHeapRef, |
301 |
| - to: UHeapRef, |
302 |
| - sort: Sort, |
303 |
| - heap: USymbolicHeap<Field, ArrayType>, |
304 |
| - converter: UMemoryKeyConverter<UHeapRef, SrcKey>, |
305 |
| - guard: UBoolExpr |
306 |
| - ) = error("Fields region copying should never happen") |
307 |
| - |
308 |
| - override fun <Field, ArrayType> keyMapper( |
309 |
| - composer: UComposer<Field, ArrayType> |
310 |
| - ): KeyMapper<UHeapRef> = { composer.compose(it) } |
311 |
| -} |
312 |
| - |
313 |
| -interface UArrayId<ArrayType, Key> : URegionId<Key> { |
314 |
| - val arrayType: ArrayType |
315 |
| -} |
316 |
| - |
317 |
| -/** |
318 |
| - * A region id for a region storing arrays allocated during execution. |
319 |
| - * Each identifier contains information about its [arrayType] and [address]. |
320 |
| - */ |
321 |
| -data class UAllocatedArrayId<ArrayType> internal constructor( |
322 |
| - override val arrayType: ArrayType, |
323 |
| - val address: UConcreteHeapAddress, |
324 |
| -) : UArrayId<ArrayType, USizeExpr> { |
325 |
| - @Suppress("UNCHECKED_CAST") |
326 |
| - override fun <Field, ArrayType, Sort : USort> read( |
327 |
| - key: USizeExpr, |
328 |
| - sort: Sort, |
329 |
| - heap: UReadOnlySymbolicHeap<Field, ArrayType> |
330 |
| - ): UExpr<Sort> { |
331 |
| - val ref = key.uctx.mkConcreteHeapRef(address) |
332 |
| - return heap.readArrayIndex(ref, key, arrayType as ArrayType, sort).asExpr(sort) |
333 |
| - } |
334 |
| - |
335 |
| - @Suppress("UNCHECKED_CAST") |
336 |
| - override fun <Field, ArrayType, Sort : USort> write( |
337 |
| - key: USizeExpr, |
338 |
| - sort: Sort, |
339 |
| - heap: USymbolicHeap<Field, ArrayType>, |
340 |
| - value: UExpr<Sort>, |
341 |
| - guard: UBoolExpr |
342 |
| - ) { |
343 |
| - val ref = key.uctx.mkConcreteHeapRef(address) |
344 |
| - heap.writeArrayIndex(ref, key, arrayType as ArrayType, sort, value, guard) |
345 |
| - } |
346 |
| - |
347 |
| - override fun <Field, ArrayType, SrcKey, Sort : USort> copy( |
348 |
| - from: USizeExpr, |
349 |
| - to: USizeExpr, |
350 |
| - sort: Sort, |
351 |
| - heap: USymbolicHeap<Field, ArrayType>, |
352 |
| - converter: UMemoryKeyConverter<USizeExpr, SrcKey>, |
353 |
| - guard: UBoolExpr |
354 |
| - ) { |
355 |
| - TODO("Not yet implemented") |
356 |
| - } |
357 |
| - |
358 |
| - override fun <Field, ArrayType> keyMapper( |
359 |
| - composer: UComposer<Field, ArrayType> |
360 |
| - ): KeyMapper<USizeExpr> = { composer.compose(it) } |
361 |
| - |
362 |
| - // we don't include arrayType into hashcode and equals, because [address] already defines unambiguously |
363 |
| - override fun equals(other: Any?): Boolean { |
364 |
| - if (this === other) return true |
365 |
| - if (javaClass != other?.javaClass) return false |
366 |
| - |
367 |
| - other as UAllocatedArrayId<*> |
368 |
| - |
369 |
| - if (address != other.address) return false |
370 |
| - |
371 |
| - return true |
372 |
| - } |
373 |
| - |
374 |
| - override fun hashCode(): Int { |
375 |
| - return address |
376 |
| - } |
377 |
| -} |
378 |
| - |
379 |
| -/** |
380 |
| - * A region id for a region storing arrays retrieved as a symbolic value, contains only its [arrayType]. |
381 |
| - */ |
382 |
| -data class UInputArrayId<ArrayType> internal constructor( |
383 |
| - override val arrayType: ArrayType |
384 |
| -) : UArrayId<ArrayType, USymbolicArrayIndex> { |
385 |
| - @Suppress("UNCHECKED_CAST") |
386 |
| - override fun <Field, ArrayType, Sort : USort> read( |
387 |
| - key: USymbolicArrayIndex, |
388 |
| - sort: Sort, |
389 |
| - heap: UReadOnlySymbolicHeap<Field, ArrayType> |
390 |
| - ): UExpr<Sort> = heap.readArrayIndex(key.first, key.second, arrayType as ArrayType, sort).asExpr(sort) |
391 |
| - |
392 |
| - @Suppress("UNCHECKED_CAST") |
393 |
| - override fun <Field, ArrayType, Sort : USort> write( |
394 |
| - key: USymbolicArrayIndex, |
395 |
| - sort: Sort, |
396 |
| - heap: USymbolicHeap<Field, ArrayType>, |
397 |
| - value: UExpr<Sort>, |
398 |
| - guard: UBoolExpr |
399 |
| - ) = heap.writeArrayIndex(key.first, key.second, arrayType as ArrayType, sort, value, guard) |
400 |
| - |
401 |
| - override fun <Field, ArrayType, SrcKey, Sort : USort> copy( |
402 |
| - from: USymbolicArrayIndex, |
403 |
| - to: USymbolicArrayIndex, |
404 |
| - sort: Sort, |
405 |
| - heap: USymbolicHeap<Field, ArrayType>, |
406 |
| - converter: UMemoryKeyConverter<USymbolicArrayIndex, SrcKey>, |
407 |
| - guard: UBoolExpr |
408 |
| - ) { |
409 |
| - TODO("Not yet implemented") |
410 |
| - } |
411 |
| - |
412 |
| - override fun <Field, ArrayType> keyMapper( |
413 |
| - composer: UComposer<Field, ArrayType> |
414 |
| - ): KeyMapper<USymbolicArrayIndex> = { |
415 |
| - val ref = composer.compose(it.first) |
416 |
| - val idx = composer.compose(it.second) |
417 |
| - if (ref === it.first && idx === it.second) it else ref to idx |
418 |
| - } |
419 |
| -} |
420 |
| - |
421 |
| -/** |
422 |
| - * A region id for a region storing array lengths for arrays of a specific [arrayType]. |
423 |
| - */ |
424 |
| -data class UInputArrayLengthId<ArrayType> internal constructor( |
425 |
| - val arrayType: ArrayType |
426 |
| -) : URegionId<UHeapRef> { |
427 |
| - @Suppress("UNCHECKED_CAST") |
428 |
| - override fun <Field, ArrayType, Sort : USort> read( |
429 |
| - key: UHeapRef, |
430 |
| - sort: Sort, |
431 |
| - heap: UReadOnlySymbolicHeap<Field, ArrayType> |
432 |
| - ): UExpr<Sort> = heap.readArrayLength(key, arrayType as ArrayType).asExpr(sort) |
433 |
| - |
434 |
| - @Suppress("UNCHECKED_CAST") |
435 |
| - override fun <Field, ArrayType, Sort : USort> write( |
436 |
| - key: UHeapRef, |
437 |
| - sort: Sort, |
438 |
| - heap: USymbolicHeap<Field, ArrayType>, |
439 |
| - value: UExpr<Sort>, |
440 |
| - guard: UBoolExpr |
441 |
| - ) { |
442 |
| - assert(guard.isTrue) |
443 |
| - heap.writeArrayLength(key, value.asExpr(key.uctx.sizeSort), arrayType as ArrayType) |
444 |
| - } |
445 |
| - |
446 |
| - override fun <Field, ArrayType, SrcKey, Sort : USort> copy( |
447 |
| - from: UHeapRef, |
448 |
| - to: UHeapRef, |
449 |
| - sort: Sort, |
450 |
| - heap: USymbolicHeap<Field, ArrayType>, |
451 |
| - converter: UMemoryKeyConverter<UHeapRef, SrcKey>, |
452 |
| - guard: UBoolExpr |
453 |
| - ) = error("Lengths region copying should never happen") |
454 |
| - |
455 |
| - override fun <Field, ArrayType> keyMapper( |
456 |
| - composer: UComposer<Field, ArrayType> |
457 |
| - ): KeyMapper<UHeapRef> = { composer.compose(it) } |
458 |
| -} |
459 |
| - |
460 | 246 | typealias UInputFieldMemoryRegion<Field, Sort> = UMemoryRegion<UInputFieldRegionId<Field>, UHeapRef, Sort>
|
461 | 247 | typealias UAllocatedArrayMemoryRegion<ArrayType, Sort> = UMemoryRegion<UAllocatedArrayId<ArrayType>, USizeExpr, Sort>
|
462 | 248 | typealias UInputArrayMemoryRegion<ArrayType, Sort> = UMemoryRegion<UInputArrayId<ArrayType>, USymbolicArrayIndex, Sort>
|
|
0 commit comments