Skip to content

Commit

Permalink
feat(objectionary#540): find the problem related to hiddent try-block…
Browse files Browse the repository at this point in the history
…s inside methods
  • Loading branch information
volodya-lombrozo committed Oct 10, 2024
1 parent dd76e0e commit f8077ed
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/jeo/BachedTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final class BachedTranslator implements Translator {
@Override
public Stream<Representation> apply(final Stream<? extends Representation> representations) {
return representations
// .parallel()
.parallel()
.map(this::translate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,15 +677,8 @@ private int computeLocalsWithCFG2() {
initial.put(index * type.getSize() + first, type.getSize());
}
Map<Integer, Variables> all = new TreeMap<>();
// all.put(0, initial);
Map<Integer, Variables> worklist = new HashMap<>();
worklist.put(0, initial);
// Variables tryVariables = new Variables(initial);
// this.tryblocks.stream()
// .map(BytecodeTryCatchBlock.class::cast)
// .map(BytecodeTryCatchBlock::handler)
// .map(this::index)
// .forEach(ind -> worklist.put(ind, tryVariables));
final int total = this.instructions.size();
Variables currentVars;
while (!worklist.isEmpty()) {
Expand All @@ -695,17 +688,9 @@ private int computeLocalsWithCFG2() {
.orElseThrow(() -> new IllegalStateException(""));
int current = curr.getKey();
worklist.remove(current);


if (all.get(current) != null) {
continue;
}

// catches(current).stream().forEach(ind -> {
// worklist.put(ind, new Variables(curr.getValue()));
// });


currentVars = new Variables(curr.getValue());
while (current < total) {
BytecodeEntry entry = this.instructions.get(current);
Expand Down Expand Up @@ -745,9 +730,83 @@ private int computeLocalsWithCFG2() {
current++;
}
}
// __________
// this.tryblocks.stream().map(BytecodeTryCatchBlock.class::cast)
// .forEach(block -> {
// final int start = this.index(block.start());
// final int end = this.index(block.end());
// final List<Variables> collect = all.entrySet().stream().filter(
// entry -> entry.getKey() >= start && entry.getKey() <= end
// ).map(Map.Entry::getValue).collect(Collectors.toList());
// if (!collect.isEmpty()) {
// Variables max = collect.get(0);
// for (final Variables variables : collect) {
// if (variables.size() > max.size()) {
// max = variables;
// }
// }
// worklist.put(
// this.index(block.handler()),
// new Variables(max)
// );
// }
// }
// );
// ----------
// while (!worklist.isEmpty()) {
// final Map.Entry<Integer, Variables> curr = worklist.entrySet()
// .stream()
// .findFirst()
// .orElseThrow(() -> new IllegalStateException(""));
// int current = curr.getKey();
// worklist.remove(current);
// if (all.get(current) != null) {
// continue;
// }
// currentVars = new Variables(curr.getValue());
// while (current < total) {
// BytecodeEntry entry = this.instructions.get(current);
// if (entry instanceof BytecodeInstruction) {
// final BytecodeInstruction var = BytecodeInstruction.class.cast(entry);
// if (var.isBranchInstruction()) {
// if (var.isSwitchInstruction()) {
// final List<Label> offsets = var.offsets();
// for (Label offset : offsets) {
// final int target = this.index(offset);
// worklist.put(target, new Variables(currentVars));
// }
// break;
// } else if (var.isConditionalBranchInstruction()) {
// final int jump = this.index(var.offset());
// worklist.put(jump, new Variables(currentVars));
// final int next = current + 1;
// worklist.put(next, new Variables(currentVars));
// break;
// } else if (var.isReturnInstruction()) {
// break;
// } else {
// final int jump = this.index(var.offset());
// worklist.put(jump, new Variables(currentVars));
// break;
// }
// }
// if (var.isVarInstruction()) {
// currentVars.put(var);
// }
// }
// final Variables value = new Variables(currentVars);
// this.catches(current).stream().forEach(ind -> {
// worklist.put(ind, new Variables(value));
// });
// all.put(current, value);
// current++;
// }
// }

return all.values().stream().mapToInt(Variables::size).max().orElse(0);
}


private List<Integer> catches(final int instruction) {
return this.tryblocks.stream().map(BytecodeTryCatchBlock.class::cast)
.filter(
Expand Down

0 comments on commit f8077ed

Please sign in to comment.