Skip to content

Commit

Permalink
feat(objectionary#344): fix the bug with local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Aug 2, 2024
1 parent 0ec0500 commit 117a0b3
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/opeo/ast/LocalVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class LocalVariable implements AstNode, Typed {
/**
* The prefix of the variable.
*/
private static final String PREFIX = "local";
private static final String PREFIX = "local-";

/**
* The identifier of the variable.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/opeo/compilation/XmirParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public AstNode parse(final XmlNode node) {
result = new FieldRetrieval(node, this);
} else if (".write-field".equals(base)) {
result = new FieldAssignment(node, this);
} else if (base.contains("local")) {
} else if (base.startsWith("local-")) {
result = new LocalVariable(node);
} else if (".new".equals(base)) {
result = new Constructor(node, this);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/it/JeoAndOpeoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ void compilesDecompiled(final String path) {
"xmir/disassembled/UndertowWebServerFactoryCustomizer$ServerOptions.xmir",
"xmir/disassembled/MutableCoercionConfig.xmir",
"xmir/disassembled/WebProperties$Resources$Chain$Strategy$Content.xmir",
"xmir/disassembled/OAuth2ClientRegistrationRepositoryConfiguration.xmir"
"xmir/disassembled/OAuth2ClientRegistrationRepositoryConfiguration.xmir",
"xmir/disassembled/DefaultRouterFunctionSpec.xmir"
})
void decompilesCompilesAndKeepsTheSameInstructions(final String path) throws Exception {
final XMLDocument original = new XMLDocument(new BytesOf(new ResourceOf(path)).asBytes());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/eolang/opeo/ast/LocalVariableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void convertsToXmir() throws ImpossibleModificationException {
MatcherAssert.assertThat(
"We expect the xmir variable to be equal to <o base='local1'/>, but it wasn't",
new Xembler(new LocalVariable(1, Type.INT_TYPE).toXmir()).xml(),
XhtmlMatchers.hasXPath("./o[@base='local1']")
XhtmlMatchers.hasXPath("./o[@base='local-1']")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class VariableAssignmentTest {
private static final String XMIR = String.join(
"\n",
"<o base='.write-local-var'>",
" <o base='local1'>",
" <o base='local-1'>",
" <o base='string' data='bytes'>64 65 73 63 72 69 70 74 6F 72 3D 44 7C 74 79 70 65 3D 6C 6F 63 61 6C</o>",
" </o>",
" <o base='int' data='bytes'>00 00 00 00 00 00 00 02</o>",
Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/xmir/decompiled/Enhancer$3.xmir
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 6F 72 67 2E 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2E 63 67 6C 69 62 2E 70 72 6F 78 79 2E 45 6E 68 61 6E 63 65 72 24 33</o>
</o>
</o>
<o base="local1" line="999">
<o base="local-1" line="999">
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 4C 6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 63 67 6C 69 62 2F 70 72 6F 78 79 2F 45 6E 68 61 6E 63 65 72 3B 7C 74 79 70 65 3D 6C 6F 63 61 6C</o>
</o>
</o>
Expand All @@ -91,7 +91,7 @@
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 6F 72 67 2E 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2E 63 67 6C 69 62 2E 70 72 6F 78 79 2E 45 6E 68 61 6E 63 65 72 24 33</o>
</o>
</o>
<o base="local2" line="999">
<o base="local-2" line="999">
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 4C 6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 63 67 6C 69 62 2F 63 6F 72 65 2F 43 6F 64 65 45 6D 69 74 74 65 72 3B 7C 74 79 70 65 3D 6C 6F 63 61 6C</o>
</o>
</o>
Expand Down Expand Up @@ -140,7 +140,7 @@
<o base=".access$100" line="999">
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 28 49 29 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B 7C 69 6E 74 65 72 66 61 63 65 64 3D 66 61 6C 73 65 7C 6E 61 6D 65 3D 61 63 63 65 73 73 24 31 30 30 7C 6F 77 6E 65 72 3D 6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 63 67 6C 69 62 2F 70 72 6F 78 79 2F 45 6E 68 61 6E 63 65 72 7C 74 79 70 65 3D 73 74 61 74 69 63</o>
<o base="org.springframework.cglib.proxy.Enhancer" line="999"/>
<o base="local1" line="999">
<o base="local-1" line="999">
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 49 7C 74 79 70 65 3D 6C 6F 63 61 6C</o>
</o>
</o>
Expand All @@ -158,7 +158,7 @@
</o>
</o>
</o>
<o base="local2" line="999">
<o base="local-2" line="999">
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 4C 6F 72 67 2F 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2F 61 73 6D 2F 4C 61 62 65 6C 3B 7C 74 79 70 65 3D 6C 6F 63 61 6C</o>
</o>
</o>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<o base="$" line="999">
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 6F 72 67 2E 73 70 72 69 6E 67 66 72 61 6D 65 77 6F 72 6B 2E 75 74 69 6C 2E 53 74 72 65 61 6D 55 74 69 6C 73 24 4E 6F 6E 43 6C 6F 73 69 6E 67 4F 75 74 70 75 74 53 74 72 65 61 6D</o>
</o>
<o base="local1" line="999">
<o base="local-1" line="999">
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 4C 6A 61 76 61 2F 69 6F 2F 4F 75 74 70 75 74 53 74 72 65 61 6D 3B 7C 74 79 70 65 3D 6C 6F 63 61 6C</o>
</o>
</o>
Expand Down Expand Up @@ -98,13 +98,13 @@
</o>
</o>
</o>
<o base="local1" line="999">
<o base="local-1" line="999">
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 5B 42 7C 74 79 70 65 3D 6C 6F 63 61 6C</o>
</o>
<o base="local2" line="999">
<o base="local-2" line="999">
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 49 7C 74 79 70 65 3D 6C 6F 63 61 6C</o>
</o>
<o base="local3" line="999">
<o base="local-3" line="999">
<o base="string" data="bytes" line="999">64 65 73 63 72 69 70 74 6F 72 3D 49 7C 74 79 70 65 3D 6C 6F 63 61 6C</o>
</o>
</o>
Expand Down
Loading

0 comments on commit 117a0b3

Please sign in to comment.