From cdb180465dd01631138e0aeb58d9365468daa873 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Sat, 2 Nov 2024 13:03:43 +0300 Subject: [PATCH] feat(#750): add StackMapFrames abstraction --- .../bytecode/BytecodeMethod.java | 8 ++- .../bytecode/StackMapFrames.java | 60 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/eolang/jeo/representation/bytecode/StackMapFrames.java diff --git a/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethod.java b/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethod.java index 3b009edb1..53d988c64 100644 --- a/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethod.java +++ b/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeMethod.java @@ -367,7 +367,13 @@ BytecodeMaxs currentMaxs() { * @return Frames. */ List computeFrames() { - return Collections.emptyList(); + return new StackMapFrames( + this.instructions, + this.tryblocks.stream() + .filter(BytecodeTryCatchBlock.class::isInstance) + .map(BytecodeTryCatchBlock.class::cast) + .collect(Collectors.toList()) + ).frames(); } /** diff --git a/src/main/java/org/eolang/jeo/representation/bytecode/StackMapFrames.java b/src/main/java/org/eolang/jeo/representation/bytecode/StackMapFrames.java new file mode 100644 index 000000000..53fd2f251 --- /dev/null +++ b/src/main/java/org/eolang/jeo/representation/bytecode/StackMapFrames.java @@ -0,0 +1,60 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2024 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.jeo.representation.bytecode; + +import java.util.Collections; +import java.util.List; + +/** + * This class knows how to compute the stack map frames from the bytecode entries. + * @since 0.6 + */ +final class StackMapFrames { + + /** + * The instructions. + */ + private final List instructions; + + /** + * The try-catch blocks. + */ + private final List blocks; + + StackMapFrames( + final List entries, + final List blocks + ) { + this.instructions = entries; + this.blocks = blocks; + } + + /** + * Compute the frames. + * @return The list of frames. + */ + List frames() { + return Collections.emptyList(); + } +}