-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the way bytecode offsets are tracked.
* Split SimpleInstructionSequence and FullInstructionSequence * Remove usages of VBStyleCollection * Instructions now track their own bytecode offsets.
- Loading branch information
Showing
19 changed files
with
234 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 50 additions & 14 deletions
64
src/org/jetbrains/java/decompiler/code/FullInstructionSequence.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,61 @@ | ||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
package org.jetbrains.java.decompiler.code; | ||
|
||
import org.jetbrains.java.decompiler.util.collections.VBStyleCollection; | ||
import org.jetbrains.java.decompiler.main.DecompilerContext; | ||
import org.jetbrains.java.decompiler.util.TextUtil; | ||
|
||
import java.util.*; | ||
|
||
public class FullInstructionSequence extends InstructionSequence { | ||
|
||
// ***************************************************************************** | ||
// constructors | ||
// ***************************************************************************** | ||
public record FullInstructionSequence( | ||
List<Instruction> instructions, | ||
Map<Integer, Integer> offsetToIndex, | ||
ExceptionTable exceptionTable | ||
) implements Iterable<Instruction> { | ||
|
||
public FullInstructionSequence(VBStyleCollection<Instruction, Integer> collinstr, ExceptionTable extable) { | ||
super(collinstr); | ||
this.exceptionTable = extable; | ||
public Instruction getInstr(int index) { | ||
return this.instructions.get(index); | ||
} | ||
|
||
public int length() { | ||
return this.instructions.size(); | ||
} | ||
|
||
public boolean isEmpty() { | ||
return this.instructions.isEmpty(); | ||
} | ||
|
||
public int getIndexByRelOffset(Instruction instruction, int offset) { | ||
int absoluteOffset = instruction.startOffset + offset; | ||
return offsetToIndex.getOrDefault(absoluteOffset, -1); | ||
} | ||
|
||
@Override | ||
public Iterator<Instruction> iterator() { | ||
return this.instructions.iterator(); | ||
} | ||
|
||
public String toString() { | ||
return toString(0); | ||
} | ||
|
||
public String toString(int indent) { | ||
String new_line_separator = DecompilerContext.getNewLineSeparator(); | ||
|
||
// translate raw exception handlers to instr | ||
for (ExceptionHandler handler : extable.getHandlers()) { | ||
handler.from_instr = this.getPointerByAbsOffset(handler.from); | ||
int toIndex = this.getPointerByAbsOffset(handler.to); | ||
handler.to_instr = toIndex == -1 ? this.collinstr.size() : toIndex; | ||
handler.handler_instr = this.getPointerByAbsOffset(handler.handler); | ||
StringBuilder buf = new StringBuilder(); | ||
|
||
for (var instr : this.instructions) { | ||
buf.append(TextUtil.getIndentString(indent)); | ||
buf.append(instr.startOffset); | ||
buf.append(": "); | ||
buf.append(instr); | ||
buf.append(new_line_separator); | ||
} | ||
|
||
return buf.toString(); | ||
} | ||
|
||
public Instruction getLast() { | ||
return this.instructions.get(this.instructions.size() - 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.