Replace assert with lazy assert, times with repeat.

This commit is contained in:
Ilya Gorbunov
2015-10-01 20:13:34 +03:00
parent c1ba30b4bc
commit 3106458cc4
50 changed files with 79 additions and 87 deletions
@@ -63,7 +63,7 @@ public abstract class CoveringTryCatchNodeProcessor(parameterSize: Int) {
if (result == 0) {
result = instructionIndex(t1.startLabel) - instructionIndex(t2.startLabel)
if (result == 0) {
assert(false, "Error: support multicatch finallies: ${t1.handler}, ${t2.handler}")
assert(false) { "Error: support multicatch finallies: ${t1.handler}, ${t2.handler}" }
result = instructionIndex(t1.endLabel) - instructionIndex(t2.endLabel)
}
}
@@ -131,12 +131,12 @@ class IntervalMetaInfo<T : SplittableInterval<T>> {
fun processCurrent(curIns: LabelNode, directOrder: Boolean) {
getInterval(curIns, directOrder).forEach {
val added = currentIntervals.add(it)
assert(added, "Wrong interval structure: $curIns, $it")
assert(added) { "Wrong interval structure: $curIns, $it" }
}
getInterval(curIns, !directOrder).forEach {
val removed = currentIntervals.remove(it)
assert(removed, "Wrong interval structure: $curIns, $it")
assert(removed) { "Wrong interval structure: $curIns, $it" }
}
}
@@ -237,7 +237,7 @@ public open class DefaultSourceMapper(val sourceInfo: SourceInfo, override val p
/*Source Mapping*/
class SMAP(val fileMappings: List<FileMapping>) {
init {
assert(fileMappings.isNotEmpty(), "File Mappings shouldn't be empty")
assert(fileMappings.isNotEmpty()) { "File Mappings shouldn't be empty" }
}
val default: FileMapping
@@ -275,7 +275,7 @@ class RawFileMapping(val name: String, val path: String) {
}
fun initRange(start: Int, end: Int) {
assert(lineMappings.isEmpty(), "initRange should only be called for empty mapping")
assert(lineMappings.isEmpty()) { "initRange should only be called for empty mapping" }
for (index in start..end) {
lineMappings.put(index, index)
}
@@ -77,8 +77,7 @@ private fun insertSaveRestoreStackMarkers(
doneTryStartLabels.add(tryStartLabel)
val nopNode = tryStartLabel.findNextOrNull { it.hasOpcode() }!!
assert(nopNode.getOpcode() == Opcodes.NOP,
"${methodNode.instructions.indexOf(nopNode)}: try block should start with NOP")
assert(nopNode.getOpcode() == Opcodes.NOP) { "${methodNode.instructions.indexOf(nopNode)}: try block should start with NOP" }
val newTryStartLabel = LabelNode(Label())
newTryStartLabels[tryStartLabel] = newTryStartLabel
@@ -93,8 +92,7 @@ private fun insertSaveRestoreStackMarkers(
doneHandlerLabels.add(handlerStartLabel)
val storeNode = handlerStartLabel.findNextOrNull { it.hasOpcode() }!!
assert(storeNode.getOpcode() == Opcodes.ASTORE,
"${methodNode.instructions.indexOf(storeNode)}: handler should start with ASTORE")
assert(storeNode.getOpcode() == Opcodes.ASTORE) { "${methodNode.instructions.indexOf(storeNode)}: handler should start with ASTORE" }
methodNode.instructions.insert(storeNode, PseudoInsn.RESTORE_STACK_IN_TRY_CATCH.createInsnNode())
}
@@ -110,8 +108,7 @@ private fun collectDecompiledTryDescriptors(
) {
for (tcb in methodNode.tryCatchBlocks) {
if (tcb.isDefaultHandlerNode()) {
assert(decompiledTryDescriptorForHandler.containsKey(tcb.start),
"${methodNode.debugString(tcb)}: default handler should occur after some regular handler")
assert(decompiledTryDescriptorForHandler.containsKey(tcb.start)) { "${methodNode.debugString(tcb)}: default handler should occur after some regular handler" }
}
val decompiledTryDescriptor = decompiledTryDescriptorForHandler.getOrPut(tcb.handler) {
@@ -65,7 +65,7 @@ internal class FixStackContext(val methodNode: MethodNode) {
inlineMarkersStack.push(insnNode)
}
InlineCodegenUtil.isAfterInlineMarker(insnNode) -> {
assert(inlineMarkersStack.isNotEmpty(), "Mismatching after inline method marker at ${indexOf(insnNode)}")
assert(inlineMarkersStack.isNotEmpty()) { "Mismatching after inline method marker at ${indexOf(insnNode)}" }
openingInlineMethodMarker[insnNode] = inlineMarkersStack.pop()
}
}
@@ -78,23 +78,23 @@ internal class FixStackContext(val methodNode: MethodNode) {
private fun visitFixStackBeforeJump(insnNode: AbstractInsnNode) {
val next = insnNode.getNext()
assert(next.getOpcode() == Opcodes.GOTO, "${indexOf(insnNode)}: should be followed by GOTO")
assert(next.getOpcode() == Opcodes.GOTO) { "${indexOf(insnNode)}: should be followed by GOTO" }
breakContinueGotoNodes.add(next as JumpInsnNode)
}
private fun visitFakeAlwaysTrueIfeq(insnNode: AbstractInsnNode) {
assert(insnNode.getNext().getOpcode() == Opcodes.IFEQ, "${indexOf(insnNode)}: should be followed by IFEQ")
assert(insnNode.getNext().getOpcode() == Opcodes.IFEQ) { "${indexOf(insnNode)}: should be followed by IFEQ" }
fakeAlwaysTrueIfeqMarkers.add(insnNode)
}
private fun visitFakeAlwaysFalseIfeq(insnNode: AbstractInsnNode) {
assert(insnNode.getNext().getOpcode() == Opcodes.IFEQ, "${indexOf(insnNode)}: should be followed by IFEQ")
assert(insnNode.getNext().getOpcode() == Opcodes.IFEQ) { "${indexOf(insnNode)}: should be followed by IFEQ" }
fakeAlwaysFalseIfeqMarkers.add(insnNode)
}
private fun visitSaveStackBeforeTry(insnNode: AbstractInsnNode) {
val tryStartLabel = insnNode.getNext()
assert(tryStartLabel is LabelNode, "${indexOf(insnNode)}: save should be followed by a label")
assert(tryStartLabel is LabelNode) { "${indexOf(insnNode)}: save should be followed by a label" }
saveStackNodesForTryStartLabel[tryStartLabel as LabelNode] = insnNode
}
@@ -77,8 +77,7 @@ public class FixStackMethodTransformer : MethodTransformer() {
val expectedStackSize = analyzer.frames[labelIndex]?.getStackSize() ?: DEAD_CODE
if (actualStackSize != DEAD_CODE && expectedStackSize != DEAD_CODE) {
assert(expectedStackSize <= actualStackSize,
"Label at $labelIndex, jump at $gotoIndex: stack underflow: $expectedStackSize > $actualStackSize")
assert(expectedStackSize <= actualStackSize) { "Label at $labelIndex, jump at $gotoIndex: stack underflow: $expectedStackSize > $actualStackSize" }
val frame = analyzer.frames[gotoIndex]!!
actions.add({ replaceMarkerWithPops(methodNode, gotoNode.getPrevious(), expectedStackSize, frame) })
}
@@ -154,7 +153,7 @@ public class FixStackMethodTransformer : MethodTransformer() {
val savedStackDescriptor = localVariablesManager.getBeforeInlineDescriptor(inlineMarker)
val afterInlineFrame = analyzer.getFrame(inlineMarker) as FixStackAnalyzer.FixStackFrame?
if (afterInlineFrame != null && savedStackDescriptor.isNotEmpty()) {
assert(afterInlineFrame.getStackSize() <= 1, "Inline method should not leave more than 1 value on stack")
assert(afterInlineFrame.getStackSize() <= 1) { "Inline method should not leave more than 1 value on stack" }
if (afterInlineFrame.getStackSize() == 1) {
val afterInlineStackValues = afterInlineFrame.getStackContent()
val returnValue = afterInlineStackValues.last()
@@ -26,7 +26,7 @@ internal class LocalVariablesManager(val context: FixStackContext, val methodNod
numRestoreMarkers == 0
fun markRestoreNodeEmitted() {
assert(numRestoreMarkers > 0, "Emitted more restore markers than expected for $savedStackDescriptor")
assert(numRestoreMarkers > 0) { "Emitted more restore markers than expected for $savedStackDescriptor" }
numRestoreMarkers--
}
}