From 531d0666fd905d2648b64d77adc6bcee12ce0b04 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 28 Jun 2023 13:18:24 +0300 Subject: [PATCH 1/2] chore: update README file --- README.md | 692 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 471 insertions(+), 221 deletions(-) diff --git a/README.md b/README.md index 48655f91..e0090f88 100644 --- a/README.md +++ b/README.md @@ -8,62 +8,85 @@ [![Hits-of-Code](https://hitsofcode.com/github/polystat/j2eo)](https://hitsofcode.com/view/github/polystat/j2eo) ![Lines of code](https://img.shields.io/tokei/lines/github/polystat/j2eo) -This is a translator of **Java** programming language to [EOLANG](https://www.eolang.org) programming language. +This is a translator of **Java** programming language +to [EOLANG](https://www.eolang.org) programming language. ## Usage -1. Make sure you have installed: - - **Java 11+** (make sure command `java -version` shows 11+ version of Java in terminal if you have multiple Java - version installed). - - **Gradle 7.4+** to build the project. - - **Maven 3.8+** to run tests (be aware of [possible conflicts](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=980467) of the - latest versions of Maven and Java on some OSs). - - **ANTLR4 4.9.2** to build parser. - - You can refer to ACCEPTANCE.md file for instructions on installing these components. - -2. Clone the repo into your folder: - - HTTPS: - ```shell - git clone https://github.com/polystat/j2eo.git - cd ./j2eo - ``` - or SSH: +### Prerequisites + +- **Java 11+** (make sure command `java -version` shows 11+ version of Java + in terminal if you have multiple Java + version installed). +- **Gradle 7.4+** to build the project. +- **Maven 3.8+** to run tests (be aware + of [possible conflicts](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=980467) + of the + latest versions of Maven and Java on some OSs). +- **ANTLR4 4.9.2** to build parser. + +You can refer to [ACCEPTANCE.md](ACCEPTANCE.md) file for instructions on +installing these components. + +### Build sources + +In order to build `j2eo` transpiler from sources, you need to: + +1. Clone the repo. You have two options clone it by using `HTTPS` or `SSH`, just + choose one of them which is suitable for you: + 1) HTTPS: + ```shell + git clone https://github.com/polystat/j2eo.git + ``` + 2) SSH: + ```shell + git clone git@github.com:polystat/j2eo.git + ``` +2. Open the project root folder: ```shell - git clone git@github.com:polystat/j2eo.git - cd ./j2eo + cd j2eo ``` 3. Build the project: ```shell ./build.sh ``` - - See the [troubleshooting section](./README.md#troubleshooting) in case of problems -4. After build process, **j2eo.jar** file will appear in the project root folder (`./j2eo`). With this file, is it - possible to translate **.java** files or packages to **.eo** packages. Run: + See the [troubleshooting section](./README.md#troubleshooting) in case of + problems - ```shell - java -jar j2eo.jar -o - ``` +### Run transpiler - to get the translation. +After build process, **j2eo.jar** file will appear in the project root +folder (`./j2eo`). With this file, is it possible to translate **.java** files +or packages into **.eo** packages. In order to translate `java` sources +into `eo` sources just run the next command: - For example, - ```shell - java -jar j2eo.jar src/test/resources/SimpleTest.java -o output_eo - ``` - or - ```shell - java -jar j2eo.jar src/test/resources/polystat_tests/test1 -o output_eo - ``` +```shell +java -jar j2eo.jar -o +``` + +For example the following command will translate `SimpleTest.java` file +into `output_eo` directory: + +```shell +java -jar j2eo.jar src/test/resources/SimpleTest.java -o output_eo +``` + +You also can translate an entire folder. For example, the following command +wil translate `test1` directory into `output_eo` directory: + +```shell +java -jar j2eo.jar src/test/resources/polystat_tests/test1 -o output_eo +``` -You can also use [yegor256/j2eo](https://hub.docker.com/r/yegor256/j2eo) image for [Docker](https://docs.docker.com/get-docker/): +You can also use [yegor256/j2eo](https://hub.docker.com/r/yegor256/j2eo) image +for [Docker](https://docs.docker.com/get-docker/): ``` $ docker run -v $(pwd):/eo yegor256/j2eo hello.java --target output ``` -This command will translate `hello.java` in the current directory, saving the output to `output/` subdirectory. +This command will translate `hello.java` in the current directory, saving the +output to `output/` subdirectory. ### Unit tests @@ -78,29 +101,39 @@ gradle test J2EO comes with 1000+ bundled tests. There are two testing scenarios: #### Static check execution: + - Java source code is translated to EO using J2EO project -- Obtained EO code are compared with saved one. If they match — test is passed. If not — test is failed. +- Obtained EO code are compared with saved one. If they match — test is passed. + If not — test is failed. -All saved EO programs are located in [translated_test](src/test/resources/translated_tests) directory. +All saved EO programs are located +in [translated_test](src/test/resources/translated_tests) directory. This scenario can be executed by the following command: `./gradlew test --tests "common.TestJ2EOStaticCheck"` #### Parallel execution: -- original Java source code of the text is compiled with Java compiler and executed. Stdout output is saved. -- Java source code is translated to EO using J2EO project, then compiled with EO compiler and executed. Stdout output is stored. -- Stdout outputs are compared. If they match — test is passed. If not — test is failed. + +- original Java source code of the text is compiled with Java compiler and + executed. Stdout output is saved. +- Java source code is translated to EO using J2EO project, then compiled with EO + compiler and executed. Stdout output is stored. +- Stdout outputs are compared. If they match — test is passed. If not — test is + failed. This scenario may be executed using `./test_candidates.sh` script. -Test suite follows the **Java Language Specification** structure, covering applicable chapters and sections of the Java specifications. +Test suite follows the **Java Language Specification** structure, covering +applicable chapters and sections of the Java specifications. ### Running translator on Hadoop -Hadoop is a large Java project (contains ~1.8M lines of code as of time of writing this). We included it as a benchmark of the translator. +Hadoop is a large Java project (contains ~1.8M lines of code as of time of +writing this). We included it as a benchmark of the translator. -Repository contains a script to build J2EO, download Hadoop repo and run J2EO on it. +Repository contains a script to build J2EO, download Hadoop repo and run J2EO on +it. Usage: @@ -108,7 +141,10 @@ Usage: ./test-hadoop.sh ``` -It will download zipped `hadoop` and unpack it (in a separate folder) into `../j2eo-data` relative to the project's root. Next, it will put the If you no more need that folder, run +It will download zipped `hadoop` and unpack it (in a separate folder) +into `../j2eo-data` relative to the project's root. Next, it will put the If you +no more need that folder, run + ```sh rm -rf ../j2eo-data ``` @@ -117,8 +153,10 @@ rm -rf ../j2eo-data ## Motivation -This project is a part of Polystat project, the goal of which is to statically analyze different languages using EOLANG, -the implementation of phi-calculus. In order to do that, the first step is to convert source language into EO. This +This project is a part of Polystat project, the goal of which is to statically +analyze different languages using EOLANG, +the implementation of phi-calculus. In order to do that, the first step is to +convert source language into EO. This particular repository contains translator from Java to EO. --- @@ -127,17 +165,22 @@ particular repository contains translator from Java to EO. **Q**: Why do we implement yet another Java parser? -**A**: Publicly available parsers only support older versions of Java, while we aim to support the latest version ( +**A**: Publicly available parsers only support older versions of Java, while we +aim to support the latest version ( currently 16). Thus, we had to create our own parser. -Also in recent versions, external Java grammar implemented in ANTLR was added as an alternative. It claims to support Java 17, and it does, as for our testing on big projects. +Also in recent versions, external Java grammar implemented in ANTLR was added as +an alternative. It claims to support Java 17, and it does, as for our testing on +big projects.
**Q**: Why do we implement EO AST? -**A**: Working with AST instead of raw strings allows utilization of Java compiler's type checking to minimize amount of -bugs in our code. It is also much easier to work with abstraction layer than with strings. +**A**: Working with AST instead of raw strings allows utilization of Java +compiler's type checking to minimize amount of +bugs in our code. It is also much easier to work with abstraction layer than +with strings.
@@ -147,33 +190,42 @@ bugs in our code. It is also much easier to work with abstraction layer than wit - First, the Java source code files are parsed recursively. - Then, for each file, translator converts Java AST to EO AST. -- Then, EO AST is printed out as a source code to output directory in the same directory structure. +- Then, EO AST is printed out as a source code to output directory in the same + directory structure. --- ## Troubleshooting ### Java -Make sure you have these in sync (*mentioning* (not pointing to) the same `jdk` directory) + +Make sure you have these in sync (*mentioning* (not pointing to) the same `jdk` +directory) + - `which java` - `which javac` - - configure alternatives in case of mismatch ([link](https://stackoverflow.com/a/47432365)) + - configure alternatives in case of + mismatch ([link](https://stackoverflow.com/a/47432365)) - `echo $JAVA_HOME` - - See how to set `$JAVA_HOME` ([link](https://stackoverflow.com/a/18972665)) - - If it still points to a wrong directory, see where you might have set it ([link](https://unix.stackexchange.com/a/154957)) and edit that place + - See how to set `$JAVA_HOME` ([link](https://stackoverflow.com/a/18972665)) + - If it still points to a wrong directory, see where you might have set + it ([link](https://unix.stackexchange.com/a/154957)) and edit that place --- ## Awesome Bugs translation + [Awesome bugs repo](https://github.com/polystat/awesome-bugs) .java files: + - [directStateAccess](src/test/resources/awesome_bugs/java/directStateAccess) - [divByZero](src/test/resources/awesome_bugs/java/divByZero) - [inheritance](src/test/resources/awesome_bugs/java/inheritance) - [unjustifiedAssumption](src/test/resources/awesome_bugs/java/unjustifiedAssumption) Translations: + - [directStateAccess](src/test/resources/awesome_bugs/eo/directStateAccess) - [divByZero](src/test/resources/awesome_bugs/eo/divByZero) - [inheritance](src/test/resources/awesome_bugs/eo/inheritance) @@ -183,108 +235,125 @@ Translations: ## Test Translations -You can find all the `.java` tests translated to `.eo` files [here.](src/test/resources/translated_tests) -To translate `.java` tests into `.eo` files manually, you have to perform the following steps: +You can find all the `.java` tests translated to `.eo` +files [here.](src/test/resources/translated_tests) +To translate `.java` tests into `.eo` files manually, you have to perform the +following steps: + 1. Build the project 2. Locate `J2EO-xxx.jar` file in the `./build/libs/` folder -3. Copy this `J2EO-xxx.jar` file into the [`./src/test/resources/test_candidates/`](src/test/resources/test_candidates) folder -4. Run [`generate_eo_from_tests.py`](src/test/resources/test_candidates/generate_eo_from_tests.py) script in that folder +3. Copy this `J2EO-xxx.jar` file into + the [`./src/test/resources/test_candidates/`](src/test/resources/test_candidates) + folder -The script takes some time while performing translation. In the end, you will get updated translated files in the [`./src/test/resources/translated_tests/`](src/test/resources/translated_tests) folder. +Run [`generate_eo_from_tests.py`](src/test/resources/test_candidates/generate_eo_from_tests.py) +script in that folder + +The script takes some time while performing translation. In the end, you will +get updated translated files in +the [`./src/test/resources/translated_tests/`](src/test/resources/translated_tests) +folder. ## Examples of Java to EOLang translation -We use Java language specification document as a foundation for Java feature hierarchy. -Java 16 language specification: [see .pdf file](https://docs.oracle.com/javase/specs/jls/se16/jls16.pdf) +We use Java language specification document as a foundation for Java feature +hierarchy. +Java 16 language +specification: [see .pdf file](https://docs.oracle.com/javase/specs/jls/se16/jls16.pdf) + +[Ch. 4 - Types, Values, and Variables](src/test/resources/test_ready/ch_4_types_values_variables) -[Ch. 4 - Types, Values, and Variables](src/test/resources/test_ready/ch_4_types_values_variables) - Increment operator: - [Java](src/test/resources/test_ready/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_2_integer_operations/IncrementOperator.java) - to - [EO](src/test/resources/translated_tests/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_2_integer_operations/IncrementOperator.eo) + [Java](src/test/resources/test_ready/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_2_integer_operations/IncrementOperator.java) + to + [EO](src/test/resources/translated_tests/ch_4_types_values_variables/sec_4_2_primitive_types_and_values/sec_4_2_2_integer_operations/IncrementOperator.eo) [Ch. 5 - Conversions and Contexts](src/test/resources/test_ready/ch_5_conversions_and_contexts) [Ch. 6 - Names](src/test/resources/test_ready/ch_6_names) + - A simple declaration: - [Java](src/test/resources/test_ready/ch_6_names/sec_6_1_declarations/SimpleDeclaration.java) - to - [EO](src/test/resources/translated_tests/ch_6_names/sec_6_1_declarations/SimpleDeclaration.eo) + [Java](src/test/resources/test_ready/ch_6_names/sec_6_1_declarations/SimpleDeclaration.java) + to + [EO](src/test/resources/translated_tests/ch_6_names/sec_6_1_declarations/SimpleDeclaration.eo) [Ch. 7 - Packages and Modules WIP](src/test/resources/test_ready/ch_7_packages_and_modules) [Ch. 8 - Classes](src/test/resources/test_ready/ch_8_classes) + - Method class member: - [Java](src/test/resources/test_ready/ch_8_classes/sec_8_2_class_members/MethodClassMember.java) - to - [EO](src/test/resources/translated_tests/ch_8_classes/sec_8_2_class_members/MethodClassMember.eo) + [Java](src/test/resources/test_ready/ch_8_classes/sec_8_2_class_members/MethodClassMember.java) + to + [EO](src/test/resources/translated_tests/ch_8_classes/sec_8_2_class_members/MethodClassMember.eo) - Field initialization: - [Java](src/test/resources/test_ready/ch_8_classes/sec_8_3_field_declarations/sec_8_3_2_field_initialization/SimpleFieldInit.java) - to - [EO](src/test/resources/translated_tests/ch_8_classes/sec_8_3_field_declarations/sec_8_3_2_field_initialization/SimpleFieldInit.eo) + [Java](src/test/resources/test_ready/ch_8_classes/sec_8_3_field_declarations/sec_8_3_2_field_initialization/SimpleFieldInit.java) + to + [EO](src/test/resources/translated_tests/ch_8_classes/sec_8_3_field_declarations/sec_8_3_2_field_initialization/SimpleFieldInit.eo) - Method declaration: - [Java](src/test/resources/test_ready/ch_8_classes/sec_8_4_method_declarations/sec_8_4_1_formal_parametes/SimpleMethod.java) - to - [EO](src/test/resources/translated_tests/ch_8_classes/sec_8_4_method_declarations/sec_8_4_1_formal_parametes/SimpleMethod.eo) + [Java](src/test/resources/test_ready/ch_8_classes/sec_8_4_method_declarations/sec_8_4_1_formal_parametes/SimpleMethod.java) + to + [EO](src/test/resources/translated_tests/ch_8_classes/sec_8_4_method_declarations/sec_8_4_1_formal_parametes/SimpleMethod.eo) - Inner class: - [Java](src/test/resources/test_ready/ch_8_classes/sec_8_5_member_class_and_interface_declarations/SimpleInnerClass.java) - to - [EO](src/test/resources/translated_tests/ch_8_classes/sec_8_5_member_class_and_interface_declarations/SimpleInnerClass.eo) + [Java](src/test/resources/test_ready/ch_8_classes/sec_8_5_member_class_and_interface_declarations/SimpleInnerClass.java) + to + [EO](src/test/resources/translated_tests/ch_8_classes/sec_8_5_member_class_and_interface_declarations/SimpleInnerClass.eo) [Ch. 9 - Interfaces](src/test/resources/test_ready/ch_9_interfaces) [Ch. 10 - Arrays](src/test/resources/test_ready/ch_10_arrays) + - Primitive array declaration: - [Java](src/test/resources/test_ready/ch_10_arrays/sec_10_2_array_variables/PrimitiveArrayDecl.java) - to - [EO](src/test/resources/translated_tests/ch_10_arrays/sec_10_2_array_variables/PrimitiveArrayDecl.eo) + [Java](src/test/resources/test_ready/ch_10_arrays/sec_10_2_array_variables/PrimitiveArrayDecl.java) + to + [EO](src/test/resources/translated_tests/ch_10_arrays/sec_10_2_array_variables/PrimitiveArrayDecl.eo) [Ch. 11 - Exceptions WIP](src/test/resources/test_ready/ch_11_exceptions) [Ch. 14 - Block Statements, and Patterns](src/test/resources/test_ready/ch_14_blocks_statements_and_patterns) [Ch. 15 - Expressions](src/test/resources/test_ready/ch_15_expressions) -- Left-hand operands are evaluated first: - [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/SimpleLeftHandOperandIsEvaluatedFirst.java) - to - [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/SimpleLeftHandOperandIsEvaluatedFirst.eo) + +- Left-hand operands are evaluated first: + [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/SimpleLeftHandOperandIsEvaluatedFirst.java) + to + [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_7_evaluation_order/sec_15_7_1_evaluate_left_hand_operand_first/SimpleLeftHandOperandIsEvaluatedFirst.eo) - Integer literal: - [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_1_lexical_literals/IntegerLiteral.java) - to - [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_1_lexical_literals/IntegerLiteral.eo) + [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_1_lexical_literals/IntegerLiteral.java) + to + [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_1_lexical_literals/IntegerLiteral.eo) - Complex parenthesized expression: - [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_5_parenthesized_expressions/ComplexParenthExpression.java) - to - [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_5_parenthesized_expressions/ComplexParenthExpression.eo) + [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_5_parenthesized_expressions/ComplexParenthExpression.java) + to + [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_8_primary_expressions/sec_15_8_5_parenthesized_expressions/ComplexParenthExpression.eo) - Creation of a simple integer array: - [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_10_array_creation_and_access_expressions/sec_15_10_1_array_creation_expressions/SimpleIntegerArray.java) - to - [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_10_array_creation_and_access_expressions/sec_15_10_1_array_creation_expressions/SimpleIntegerArray.eo) + [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_10_array_creation_and_access_expressions/sec_15_10_1_array_creation_expressions/SimpleIntegerArray.java) + to + [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_10_array_creation_and_access_expressions/sec_15_10_1_array_creation_expressions/SimpleIntegerArray.eo) - Postfix increment: - [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_14_postfix_expressions/sec_15_14_2_postfix_increment_operator/SimplePostfixIncrement.java) - to - [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_14_postfix_expressions/sec_15_14_2_postfix_increment_operator/SimplePostfixIncrement.eo) + [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_14_postfix_expressions/sec_15_14_2_postfix_increment_operator/SimplePostfixIncrement.java) + to + [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_14_postfix_expressions/sec_15_14_2_postfix_increment_operator/SimplePostfixIncrement.eo) - Unary plus operator: - [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_15_unary_operators/sec_15_15_3_unary_plus_operator/SimpleUnaryPlus.java) - to - [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_15_unary_operators/sec_15_15_3_unary_plus_operator/SimpleUnaryPlus.eo) + [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_15_unary_operators/sec_15_15_3_unary_plus_operator/SimpleUnaryPlus.java) + to + [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_15_unary_operators/sec_15_15_3_unary_plus_operator/SimpleUnaryPlus.eo) - Multiplication operator: - [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_17_multiplicative_operators/sec_15_17_1_multiplication_operator/SimpleMultiplication.java) - to - [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_17_multiplicative_operators/sec_15_17_1_multiplication_operator/SimpleMultiplication.eo) + [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_17_multiplicative_operators/sec_15_17_1_multiplication_operator/SimpleMultiplication.java) + to + [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_17_multiplicative_operators/sec_15_17_1_multiplication_operator/SimpleMultiplication.eo) - Variable right shift: - [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_19_shift_operators/VariableRightShift.java) - to - [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_19_shift_operators/VariableRightShift.eo) + [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_19_shift_operators/VariableRightShift.java) + to + [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_19_shift_operators/VariableRightShift.eo) - Greater operator: - [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_20_relational_operators/sec_15_20_1_numerical_comparison_operators/SimpleGreaterComparison.java) - to - [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_20_relational_operators/sec_15_20_1_numerical_comparison_operators/SimpleGreaterComparison.eo) + [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_20_relational_operators/sec_15_20_1_numerical_comparison_operators/SimpleGreaterComparison.java) + to + [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_20_relational_operators/sec_15_20_1_numerical_comparison_operators/SimpleGreaterComparison.eo) - Assignment operator: - [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_26_assignment_operators/sec_15_26_1_simple_assignment_operator/SimpleAssignmentOperator.java) - to - [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_26_assignment_operators/sec_15_26_1_simple_assignment_operator/SimpleAssignmentOperator.eo) + [Java](src/test/resources/test_ready/ch_15_expressions/sec_15_26_assignment_operators/sec_15_26_1_simple_assignment_operator/SimpleAssignmentOperator.java) + to + [EO](src/test/resources/translated_tests/ch_15_expressions/sec_15_26_assignment_operators/sec_15_26_1_simple_assignment_operator/SimpleAssignmentOperator.eo) [Ch. 16 - Definite Assignments WIP](src/test/resources/test_ready/ch_16_definite_assignment) @@ -294,9 +363,13 @@ Java 16 language specification: [see .pdf file](https://docs.oracle.com/javase/s ## Examples of translation projections -Bellow there are all designed mappings at the current moment. If you didn't find a construction in the list bellow it is probably unsupported. +Bellow there are all designed mappings at the current moment. If you didn't find +a construction in the list bellow it is probably unsupported. -This list is created accordingly [Java SE 16](https://docs.oracle.com/javase/specs/jls/se16/jls16.pdf). Some chapters are omitted because they related only to internal structure of Java. +This list is created +accordingly [Java SE 16](https://docs.oracle.com/javase/specs/jls/se16/jls16.pdf). +Some chapters are omitted because they related only to internal structure of +Java. Others are omitted due to lack of implementation of translation. ### 4 Types, Values, and Variables @@ -305,38 +378,52 @@ Others are omitted due to lack of implementation of translation. #### 4.2 Primitive Types and Values -Any primitives types are supported. For handling them we use a [primitives](src/main/resources/stdlib/primitives) package. It provides `memory` wrappers for any primitive types. +Any primitives types are supported. For handling them we use +a [primitives](src/main/resources/stdlib/primitives) package. It +provides `memory` wrappers for any primitive types. + +Wrappers are more convenient way to simulate primitives types. For, +example `memory.write` returns `bool` object instead itself, so for handling `=` +operator we should do something like this: -Wrappers are more convenient way to simulate primitives types. For, example `memory.write` returns `bool` object instead itself, so for handling `=` operator we should do something like this: ``` [a b] > write seq > @ a.write b a ``` -It is more complex than just `a.write b`, where `a` and `b` are wrappers. Moreover, pure `memory` does not support in-place operations and conversions. -Therefore, we decided to generate more beautiful EO code and use wrappers instead generation of unreadable code with pure 'memory'. + +It is more complex than just `a.write b`, where `a` and `b` are wrappers. +Moreover, pure `memory` does not support in-place operations and conversions. +Therefore, we decided to generate more beautiful EO code and use wrappers +instead generation of unreadable code with pure 'memory'. #### 4.2.2 Integer Operations -The Java programming language provides a number of operators that act on integral + +The Java programming language provides a number of operators that act on +integral values. Supported ones: + * The comparison operators, which result in a value of type boolean: - - The numerical comparison operators <, <=, >, and >= - - The numerical equality operators == and != -* The unary plus and minus operators + and - + - The numerical comparison operators <, <=, >, and >= + - The numerical equality operators == and != +* The unary plus and minus operators + and - * The multiplicative operators *, /, and % -* The additive operators + and - +* The additive operators + and - * The increment operator ++, both prefix and postfix * The decrement operator --, both prefix and postfix * The signed and unsigned shift operators <<, >>, and >>> * The cast operator, which can convert from an integral value to a value -of any specified numeric type + of any specified numeric type Common translation scheme: + ```Java expr_1 op expr_2 ``` + --> + ``` [] > binary expr_1.translated_op > @ @@ -344,22 +431,28 @@ expr_1 op expr_2 ``` Unary case: + ```Java expr op // OR -op expr + op expr ``` + --> + ``` [] > unary expr.translated_op > @ ``` Cast case: + ```Java -(primitive_type) expr +(primitive_type)expr ``` + --> + ``` [] > cast translated_primitive_type.from expr @@ -367,11 +460,15 @@ Cast case: #### 4.2.3 Floating-Point Types, Formats, and Values -Currently, there is only runtime support for `double`. Nevertheless, translator can handle `float` well, but output EO code would not be equivalent to initial one during runtime. +Currently, there is only runtime support for `double`. Nevertheless, translator +can handle `float` well, but output EO code would not be equivalent to initial +one during runtime. #### 4.2.4 Floating-Point Operations + The Java programming language provides a number of operators that act on floating-point values. Supported operators: + * The comparison operators, which result in a value of type boolean: - The numerical comparison operators <, <=, >, and >= - The numerical equality operators == and != @@ -388,7 +485,8 @@ Scheme of translation is the same as in [4.2.2](#4.2.2-integer-operations) #### 4.3 Reference Types and Values -Currently, only classes as reference types are supported. Identifier of class is prepended with `class__` during translation. +Currently, only classes as reference types are supported. Identifier of class is +prepended with `class__` during translation. #### 4.4 Type Variables @@ -396,9 +494,9 @@ Type variables are omitted due to lack of types in EO. #### 4.5 Parameterized Types -The same situation as [4.4](#4.4-type-variables) +The same situation as [4.4](#4.4-type-variables) -#### 4.6 Type Erasure +#### 4.6 Type Erasure The same situation as [4.4](#4.4-type-variables) @@ -408,13 +506,18 @@ The same situation as [4.4](#4.4-type-variables) #### 4.12.1 Variables of Primitive Type -Any primitive type variable is being stored on special handwritten objects (`primitives`). For example, `int` value will be stored in `prim__int` object, `long` in `prim__long` and so on. +Any primitive type variable is being stored on special handwritten +objects (`primitives`). For example, `int` value will be stored in `prim__int` +object, `long` in `prim__long` and so on. Example: + ```Java float a; ``` + --> + ``` prim__float.constructor_1 > a prim__float.new @@ -422,13 +525,16 @@ prim__float.constructor_1 > a #### 4.12.2 Variables of Reference Type -Any reference type variable is being stored on `cage`. +Any reference type variable is being stored on `cage`. Example: + ```Java Ref a; ``` + --> + ``` cage > a ``` @@ -439,12 +545,14 @@ cage > a #### 5.1.1 Identity Conversion -This conversion is omitted by the translator. E.g., `(ClassA) class_a_instance` is `class_a_instance` in the translator perspective. +This conversion is omitted by the translator. E.g., `(ClassA) class_a_instance` +is `class_a_instance` in the translator perspective. #### 5.1.2 Widening Primitive Conversion 19 specific conversions on primitive types are called the widening primitive conversions: + * `byte` to `short`, `int`, `long`, `float` or `double` * `short` to `int`, `long`, `float` or `double` * `char` to `int`, `long`, `float` or `double` @@ -455,27 +563,34 @@ conversions: All of them has runtime support. Example: + ```Java -(primitive_type) expr +(primitive_type)expr ``` + --> + ``` [] > cast translated_type.from > @ expr ``` -`translated_type` is obtained according to [4.12.1](#4.12.1-Variables of Primitive Type) +`translated_type` is obtained according +to [4.12.1](#4.12.1-Variables of Primitive Type) #### 5.1.3 Narrowing Primitive Conversion + 22 specific conversions on primitive types are called the narrowing primitive conversions: + * `short` to `byte` or `char` * `char` to `byte` or `short` * `int` to `byte`, `short` or `char` * `long` to `byte`, `short`, `char` or `int` * `float` to `byte`, `short`, `char`, `int` or `long` -* `double` to `byte`, `short`, `char`, `int`, `long` or `float` (runtime support is not precise) +* `double` to `byte`, `short`, `char`, `int`, `long` or `float` (runtime support + is not precise) All of them has runtime support. @@ -487,15 +602,21 @@ The same situation as [4.4](#4.4-type-variables) #### 5.1.11 String Conversion -Currently, there is no support for this type of conversion. User should manually resolve them. For example: +Currently, there is no support for this type of conversion. User should manually +resolve them. For example: + ```Java -"1" + 1 +"1"+1 ``` + it should be manually rewritten to: + ```Java -"1" + String.valueOf(1) +"1"+String.valueOf(1) ``` + In this case the translator would convert it to: + ``` [] > binary_1 literal_1.add > @ @@ -516,61 +637,82 @@ In this case the translator would convert it to: ### 6 Names --- + #### 6.1 Declarations -A declaration introduces an entity into a program and includes an identifier. Supported declared entity is one of the following: -* An imported class or interface, declared in a single-type-import declaration or a -type-import-on-demand declaration +A declaration introduces an entity into a program and includes an identifier. +Supported declared entity is one of the following: + +* An imported class or interface, declared in a single-type-import declaration + or a + type-import-on-demand declaration * An imported static member, declared in a single-static-import declaration or a -static-import-on-demand declaration + static-import-on-demand declaration * A class, declared by a normal class declaration * A member of a reference type, one of the following: - - A member class - - A field, one of the following: - - A field declared in a class - - The field length, which is implicitly a member of every array type - - A method, one of the following: - - A method (abstract or otherwise) declared in a class + - A member class + - A field, one of the following: + - A field declared in a class + - The field length, which is implicitly a member of every array type + - A method, one of the following: + - A method (abstract or otherwise) declared in a class * A formal parameter, one of the following: - - A formal parameter of a method of a class - - A formal parameter of a constructor of a class + - A formal parameter of a method of a class + - A formal parameter of a constructor of a class * A local variable, one of the following: - - A local variable declared by a local variable declaration statement in a block + - A local variable declared by a local variable declaration statement in a + block * A local class, one of the following: - - A local class declared by a normal class declaration + - A local class declared by a normal class declaration -Any declaration is translated into EO object or EO copy of specific object. Example: +Any declaration is translated into EO object or EO copy of specific object. +Example: ```Java -class A { body } +class A { + body +} ``` + -> + ``` [] > class__A ... body ... ``` + Or, + ```Java int a; ``` + --> + ``` prim__int.constructor_1 > a prim__int.new ``` #### 6.2 Names and Identifiers + A name is used to refer to an entity declared in a program. -A *simple name* is a single identifier. Each simple identifier preserves name except classes. Their names are prepended with `class__`. There is no name mangling for variables. +A *simple name* is a single identifier. Each simple identifier preserves name +except classes. Their names are prepended with `class__`. There is no name +mangling for variables. + +A *qualified name* consists of a name, a "." token, and an identifier. Qualified +names are separated to several objects during translation. Example: -A *qualified name* consists of a name, a "." token, and an identifier. Qualified names are separated to several objects during translation. Example: ```Java a.b.c; ``` + --> + ``` [] > fieldAcces_1 fieldAcess_2.c > @ @@ -580,7 +722,9 @@ a.b.c; a ``` -Of course, it can be optimized to just one EO object, but at this moment translator does not perform such optimization for keeping translation of dot-separated entities more general. +Of course, it can be optimized to just one EO object, but at this moment +translator does not perform such optimization for keeping translation of +dot-separated entities more general. #### 6.4 Shadowing and Obscuring @@ -588,7 +732,8 @@ For now there is now handling of shadowing and obscuring. #### 6.6 Access Control -EO does not support access modifiers. All objects in an EO is public by default. Therefore, during translation such information is being lost. +EO does not support access modifiers. All objects in an EO is public by default. +Therefore, during translation such information is being lost. ### 7 Packages and Modules @@ -596,27 +741,35 @@ EO does not support access modifiers. All objects in an EO is public by default. #### 7.5 Import Declarations -Currently, translator supports only single type import declaration and single static support declarations. +Currently, translator supports only single type import declaration and single +static support declarations. Example: + ```Java import a.b.c; import static d.e.f; ``` + --> + ``` +alias a.b.class__c +alias d.class_e.f ``` -Any identifier in import declaration would be prepended with class__ if it's known that it is a class. +Any identifier in import declaration would be prepended with class__ if it's +known that it is a class. Identifier `java` will be replaced with `stdlib`. Example: + ```Java import java.lang.Random; ``` + --> + ``` +alias stdlib.lang.class__Random ``` @@ -627,23 +780,27 @@ import java.lang.Random; #### 8.1.1 Class Modifiers -Any modifiers except `static` are being omitted during translation. `static` is needed to distinguish a inner class from nested one. +Any modifiers except `static` are being omitted during translation. `static` is +needed to distinguish a inner class from nested one. #### 8.3 Field Declarations -Currently, only non-`static` fields are supported. +Currently, only non-`static` fields are supported. #### 8.4 Method Declarations Any method would be translated into EO object. Name in this case would be saved. Example: + ```Java -static String m(int p_int, String p_str) { - return p_int + p_str; -} +static String m(int p_int,String p_str){ + return p_int+p_str; + } ``` + --> + ``` [p_int p_str] > m seq > @ @@ -659,18 +816,23 @@ static String m(int p_int, String p_str) { p_str > @ ``` -Any non-`static` method will have additional parameter `this` that refers callee itself. It is necessary to implement overriding methods in EO correctly. +Any non-`static` method will have additional parameter `this` that refers callee +itself. It is necessary to implement overriding methods in EO correctly. #### 8.5 Member Class and Interface Declarations -Now only `static` nested classes are supported. Nested interfaces are unsupported. Example: +Now only `static` nested classes are supported. Nested interfaces are +unsupported. Example: ```Java class Outer { - class Inner {} + class Inner { + } } ``` + --> + ``` [] > class__Outer ... @@ -680,17 +842,20 @@ class Outer { #### 8.8 Constructor Declarations -Only non-multiple construction declarations with explicit `super` call are supported. +Only non-multiple construction declarations with explicit `super` call are +supported. Example: ```java -public A() { +public A(){ super(); ... -} + } ``` + --> + ``` [this] > constructor seq > @ @@ -744,29 +909,36 @@ ___ #### 10.2 Array Variables -Translator supports both types of arrays: primitive and reference. Examples: `int[]` and `String[]` +Translator supports both types of arrays: primitive and reference. +Examples: `int[]` and `String[]` #### 10.3 Array Creation -Look at [15.10.1](#15.10.1-array-creation-expressions) section. +Look at [15.10.1](#15.10.1-array-creation-expressions) section. #### 10.4 Array Access -For access to array elements translator uses `get` provided by EO `array` object. However, as indexes it uses primitive wrappers. +For access to array elements translator uses `get` provided by EO `array` +object. However, as indexes it uses primitive wrappers. Example is provided in [15.10.3](#15.10.3-array-access-expressions) section. #### 10.6 Array Initializers -An array initializer is written as a comma-separated list of expressions, enclosed +An array initializer is written as a comma-separated list of expressions, +enclosed by braces { and }. Example, `{ 1 + 1, 2 }` -Currently, it is the only way to store something in array. Other types of initializers (e.g. `new Type[num]`) are unsupported. +Currently, it is the only way to store something in array. Other types of +initializers (e.g. `new Type[num]`) are unsupported. Example: + ```java -{ 1 + 1, 2 } +{1+1,2} ``` + --> + ``` [] > initializerArray_1 * > @ @@ -795,7 +967,8 @@ Example: #### 10.7 Array Members -For now only `length` attribute is supported. During translation, it remains unchanged. +For now only `length` attribute is supported. During translation, it remains +unchanged. ### 14 Blocks, Statements, and Patterns @@ -803,31 +976,40 @@ For now only `length` attribute is supported. During translation, it remains unc #### 14.2 Blocks -By Java grammar, blocks are sequence of declarations and statements separated by curly braces. Translator creates new EO object for each block. Example: +By Java grammar, blocks are sequence of declarations and statements separated by +curly braces. Translator creates new EO object for each block. Example: ```Java { declaration; statement; -} + } ``` + --> + ``` [] > block_1 seq > @ declaration_1 statement_1 ``` -Number after object name is needed just for avoiding name collisions. `declaration_1` and `statement_1` are EO objects. They describe internal structure of itself. Inside a `seq` object they are just dataizing. + +Number after object name is needed just for avoiding name +collisions. `declaration_1` and `statement_1` are EO objects. They describe +internal structure of itself. Inside a `seq` object they are just dataizing. Now let's look to real Java code: + ```Java -void foo() { - int a = 1; +void foo(){ + int a=1; println(a); -} + } ``` + -> + ``` 1 [this] > foo 2 seq > @ @@ -852,15 +1034,30 @@ void foo() { 21 a > @ ``` -Any variables in blocks are declared separately from the `seq` object. In this case `int a` was declared at lines 5-6. Also it has an initializer `1`. So translator assign `a` to initializer value at lines 7-9. This initializer is simple one. It is a just literal. Translator mentioned it on lines 10-11. Literals are translated to EO objects itself (lines 12-15). +Any variables in blocks are declared separately from the `seq` object. In this +case `int a` was declared at lines 5-6. Also it has an initializer `1`. So +translator assign `a` to initializer value at lines 7-9. This initializer is +simple one. It is a just literal. Translator mentioned it on lines 10-11. +Literals are translated to EO objects itself (lines 12-15). -Any statement in blocks are statement expression by default. Their behaviour as a declarations are described separately. In this case statement `println(a)` is declared on lines 16-19. By default, any method is considered as class method. So access to it is performed via `this` (line 17). Moreover, it is necessary to pass `this` as argument during method invocation (line 18). `println(a)` is call with single argument `a`. It is a simple reference that was mentioned at line 19. Simple reference is itself a distinct object which translator declared on lines 20-21. +Any statement in blocks are statement expression by default. Their behaviour as +a declarations are described separately. In this case statement `println(a)` is +declared on lines 16-19. By default, any method is considered as class method. +So access to it is performed via `this` (line 17). Moreover, it is necessary to +pass `this` as argument during method invocation (line 18). `println(a)` is call +with single argument `a`. It is a simple reference that was mentioned at line + +19. Simple reference is itself a distinct object which translator declared on + lines 20-21. #### 14.4 Local Variable Declarations -A local variable declaration declares and optionally initializes one or more local -variables. Translator keeps location of declaration unchanged. -E.g. class member declarations stay inside class body, local method variables stays inside a method body and e.t.c. Depending on the type declared entity can be stored in `cage`, primitive wrapper or in separate EO object. +A local variable declaration declares and optionally initializes one or more +local +variables. Translator keeps location of declaration unchanged. +E.g. class member declarations stay inside class body, local method variables +stays inside a method body and e.t.c. Depending on the type declared entity can +be stored in `cage`, primitive wrapper or in separate EO object. Example of class member declaration: @@ -869,7 +1066,9 @@ class A { int member; } ``` + --> + ``` [] > class__A ... @@ -881,12 +1080,15 @@ class A { ``` Example of class member with initializer: + ```java class A { int member = 0; } ``` + --> + ``` [] > class__A ... @@ -909,15 +1111,19 @@ class A { ... ``` -In this case when instance of class `A` would be created, `init` object would be called for initializing variables. +In this case when instance of class `A` would be created, `init` object would be +called for initializing variables. Example of local method variable with initializer: + ```java -void m() { - int a = 0; -} +void m(){ + int a=0; + } ``` + --> + ``` [this] > m seq > @ @@ -935,22 +1141,29 @@ void m() { 0 ``` -Here the same logic is applicable as in previous example. Variable itself is being stored out of `seq` object, but it dataizes its initialization. +Here the same logic is applicable as in previous example. Variable itself is +being stored out of `seq` object, but it dataizes its initialization. -Example with nested class is located in [8.5](#8.5 Member Class and Interface Declarations). +Example with nested class is located +in [8.5](#8.5 Member Class and Interface Declarations). #### 14.5 Statements -All statements of block are being stored inside `seq` object after translation. Each of them is represented by unique name which during dataization simulates behaviour of initial statement. +All statements of block are being stored inside `seq` object after translation. +Each of them is represented by unique name which during dataization simulates +behaviour of initial statement. Example: + ```java { - int a = 1; + int a=1; method(); -} + } ``` + --> + ``` [] > block_1 seq > @ @@ -981,12 +1194,14 @@ Translator ignores it. Example: ```java -if (cond) +if(cond) then_block; -else + else else_block; ``` + --> + ``` [] > ifThenElse_1 translated_cond.if > @ @@ -1000,6 +1215,7 @@ else ``` If no else part is provided then translator generate empty block (`empty`): + ``` [] > empty_1 TRUE > @ @@ -1008,10 +1224,13 @@ If no else part is provided then translator generate empty block (`empty`): #### 14.10 The assert Statement Example: + ```java -assert cond : expr; +assert cond:expr; ``` + --> + ``` [] > assert_1 translated_cond.if > @ @@ -1025,11 +1244,14 @@ assert cond : expr; #### 14.12 The while Statement Example: + ```java -while (cond) +while(cond) block; ``` + --> + ``` [] > while_1 translated_cond.while > @ @@ -1043,12 +1265,15 @@ while (cond) #### 14.13 The do Statement Example: + ```java do block; -while (cond); + while(cond); ``` + --> + ``` [] > do_1 translated_cond.do > @ @@ -1067,13 +1292,16 @@ Note: currently there is no runtime support of `do` object. #### 15.8.1 Lexical Literals -Now supported only integer, floating point and string literals. Translator use wrappers to simulate behaviour of Java primitives. -Let's consider an assign operator in Java write value into variable and return its value. `memory` in EO does not provide a such behaviour. +Now supported only integer, floating point and string literals. Translator use +wrappers to simulate behaviour of Java primitives. +Let's consider an assign operator in Java write value into variable and return +its value. `memory` in EO does not provide a such behaviour. Therefore, we need to use a wrapper. Examples: -`1` -> +`1` -> + ``` [] > literal_1 prim__int.constructor_2 > @ @@ -1082,6 +1310,7 @@ Examples: ``` `1.0` -> + ``` [] > literal_1 prim__float.constructor_2 > @ @@ -1090,6 +1319,7 @@ Examples: ``` `"string"` -> + ``` [] > literal_1 class__String.constructor_2 > @ @@ -1103,17 +1333,20 @@ It's remaining unchanged. #### 15.8.5 Parenthesized Expressions -`(expresion)` -> +`(expresion)` -> + ``` [] > parenthesized_1 expresion > @ ``` -It can be simplified, but we keep such translation to maintain more complex cases. +It can be simplified, but we keep such translation to maintain more complex +cases. #### 15.9 Class Instance Creation Expression `new A(arg)` -> + ``` [] > statementExpression_1 class__A.constructor > @ @@ -1123,15 +1356,19 @@ It can be simplified, but we keep such translation to maintain more complex case arg > @ ``` -For referencing variables `simpleReference_1` is used. It can be simplified, but it's used for maintaining complex cases. +For referencing variables `simpleReference_1` is used. It can be simplified, but +it's used for maintaining complex cases. #### 15.10.1 Array Creation Expressions -Currently, only creation with array initializers is supported. Example of array initializers: `{1, 2, 3}`. +Currently, only creation with array initializers is supported. Example of array +initializers: `{1, 2, 3}`. -For storing array translator uses `cage` object. For simulation of array initializers translator uses `array` aka `*` object from EO. +For storing array translator uses `cage` object. For simulation of array +initializers translator uses `array` aka `*` object from EO. `int[] array = {1}` -> + ``` [] > variableDeclaration_1 array.write > @ @@ -1150,6 +1387,7 @@ For storing array translator uses `cage` object. For simulation of array initial #### 15.10.3 Array Access Expressions `array[idx]` -> + ``` [] > statementExpression_1 simpleReference_1.get > @ @@ -1165,6 +1403,7 @@ For storing array translator uses `cage` object. For simulation of array initial #### 15.11 Field Access Expressions `a.b` -> + ``` [] > statementExpression_1 simpleReference_1.b > @ @@ -1177,6 +1416,7 @@ It can be simplified, but we keep such translation for generalization. #### 15.11.2 Accessing Superclass Members using `super` `a.super.b` -> + ``` [] > statementExpression_1 simpleReference_1.super.b > @ @@ -1187,6 +1427,7 @@ It can be simplified, but we keep such translation for generalization. #### 15.12 Method Invocation Expressions `a.b(arg)` -> + ``` [] > statementExpression_1 a.b > @ # call of b @@ -1199,6 +1440,7 @@ It can be simplified, but we keep such translation for generalization. #### 15.14.2 Postfix Increment Operator `++` `expr++` -> + ``` [] > statementExpression_1 simpleReference_1.inc_post > @ # increment itself @@ -1209,6 +1451,7 @@ It can be simplified, but we keep such translation for generalization. #### 15.14.3 Postfix Decrement Operator `--` `expr--` -> + ``` [] > statementExpression_1 simpleReference_1.dec_post > @ # decrement itself @@ -1219,6 +1462,7 @@ It can be simplified, but we keep such translation for generalization. #### 15.15.1 Prefix Increment Operator `++` `++expr` -> + ``` [] > statementExpression_1 simpleReference_1.inc_pre > @ # increment itself @@ -1229,6 +1473,7 @@ It can be simplified, but we keep such translation for generalization. #### 15.15.2 Prefix Decrement Operator `--` `--expr` -> + ``` [] > statementExpression_1 simpleReference_1.dec_pre > @ # decrement itself @@ -1238,7 +1483,8 @@ It can be simplified, but we keep such translation for generalization. #### 15.15.3 Unary Plus Operator `+` -`+expr` -> +`+expr` -> + ``` [] > statementExpression_1 simpleReference_1 > @ @@ -1251,6 +1497,7 @@ It can be simplified, but we keep such translation for generalization. #### 15.15.4 Unary Minus Operator `-` `-expr` -> + ``` [] > statementExpression_1 simpleReference_1.neg > @ # negation itself @@ -1261,6 +1508,7 @@ It can be simplified, but we keep such translation for generalization. #### 15.16 Cast Expressions `(int) 1.0` -> + ``` [] > statementExpression_1 prim__int.from > @ # cast itself @@ -1274,6 +1522,7 @@ It can be simplified, but we keep such translation for generalization. #### 15.17-26 Binary Operators `left operand right` -> + ``` [] > statementExpression_1 simpleReference_1.t_operand > @ @@ -1286,5 +1535,6 @@ It can be simplified, but we keep such translation for generalization. `t_opernad` is translated `operand` -There are only runtime support only for following operands: -`+`, `-`, `*`, `%`, `/`, `&&`, `||`, `>`, `<`, `>=`, `<=`, `==`, `!=`, `<<`, `>>` and `>>>` +There are only runtime support only for following operands: +`+`, `-`, `*`, `%`, `/`, `&&`, `||`, `>`, `<`, `>=`, `<=`, `==`, `!=`, `<<`, `>>` +and `>>>` From 6d9fcecf9ee175a3c377f93f0b61a74d8aa88125 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 28 Jun 2023 13:34:02 +0300 Subject: [PATCH 2/2] chore: Add languages identifiers for code snippets --- README.md | 126 +++++++++++++++++++++++++++--------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index e0090f88..3a5af7f5 100644 --- a/README.md +++ b/README.md @@ -386,7 +386,7 @@ Wrappers are more convenient way to simulate primitives types. For, example `memory.write` returns `bool` object instead itself, so for handling `=` operator we should do something like this: -``` +```eo [a b] > write seq > @ a.write b @@ -418,13 +418,13 @@ values. Supported ones: Common translation scheme: -```Java +```java expr_1 op expr_2 ``` --> -``` +```eo [] > binary expr_1.translated_op > @ expr_2 @@ -432,7 +432,7 @@ expr_1 op expr_2 Unary case: -```Java +```java expr op // OR op expr @@ -447,13 +447,13 @@ expr op Cast case: -```Java +```java (primitive_type)expr ``` --> -``` +```eo [] > cast translated_primitive_type.from expr ``` @@ -512,13 +512,13 @@ object, `long` in `prim__long` and so on. Example: -```Java +```java float a; ``` --> -``` +```eo prim__float.constructor_1 > a prim__float.new ``` @@ -529,7 +529,7 @@ Any reference type variable is being stored on `cage`. Example: -```Java +```java Ref a; ``` @@ -564,13 +564,13 @@ All of them has runtime support. Example: -```Java +```java (primitive_type)expr ``` --> -``` +```eo [] > cast translated_type.from > @ expr @@ -605,19 +605,19 @@ The same situation as [4.4](#4.4-type-variables) Currently, there is no support for this type of conversion. User should manually resolve them. For example: -```Java +```java "1"+1 ``` it should be manually rewritten to: -```Java +```java "1"+String.valueOf(1) ``` In this case the translator would convert it to: -``` +```eo [] > binary_1 literal_1.add > @ methodInvocation_1 @@ -668,15 +668,15 @@ Supported declared entity is one of the following: Any declaration is translated into EO object or EO copy of specific object. Example: -```Java +```java class A { - body + // body } ``` -> -``` +```eo [] > class__A ... body @@ -685,7 +685,7 @@ class A { Or, -```Java +```java int a; ``` @@ -707,13 +707,13 @@ mangling for variables. A *qualified name* consists of a name, a "." token, and an identifier. Qualified names are separated to several objects during translation. Example: -```Java +```java a.b.c; ``` --> -``` +```eo [] > fieldAcces_1 fieldAcess_2.c > @ [] > fieldAcces_2 @@ -746,14 +746,14 @@ static support declarations. Example: -```Java +```java import a.b.c; import static d.e.f; ``` --> -``` +```eo +alias a.b.class__c +alias d.class_e.f ``` @@ -764,7 +764,7 @@ Identifier `java` will be replaced with `stdlib`. Example: -```Java +```java import java.lang.Random; ``` @@ -793,7 +793,7 @@ Any method would be translated into EO object. Name in this case would be saved. Example: -```Java +```java static String m(int p_int,String p_str){ return p_int+p_str; } @@ -801,7 +801,7 @@ static String m(int p_int,String p_str){ --> -``` +```eo [p_int p_str] > m seq > @ return_1 @@ -824,7 +824,7 @@ itself. It is necessary to implement overriding methods in EO correctly. Now only `static` nested classes are supported. Nested interfaces are unsupported. Example: -```Java +```java class Outer { class Inner { } @@ -833,7 +833,7 @@ class Outer { --> -``` +```eo [] > class__Outer ... [] > class Inner @@ -850,13 +850,13 @@ Example: ```java public A(){ super(); - ... - } + //... +} ``` --> -``` +```eo [this] > constructor seq > @ initialization @@ -881,7 +881,7 @@ If no constructor is provided then translator generate default constructor. #### Class translation structure: -``` +```eo [] > class__ class__ > super # Inheritance simulation super > @ @@ -939,7 +939,7 @@ Example: --> -``` +```eo [] > initializerArray_1 * > @ initializerSimple_1 @@ -979,16 +979,16 @@ unchanged. By Java grammar, blocks are sequence of declarations and statements separated by curly braces. Translator creates new EO object for each block. Example: -```Java +```java { declaration; statement; - } +} ``` --> -``` +```eo [] > block_1 seq > @ declaration_1 @@ -1001,16 +1001,16 @@ internal structure of itself. Inside a `seq` object they are just dataizing. Now let's look to real Java code: -```Java +```java void foo(){ int a=1; println(a); - } +} ``` -> -``` +```eo 1 [this] > foo 2 seq > @ 3 variableDeclaration_1 @@ -1069,7 +1069,7 @@ class A { --> -``` +```eo [] > class__A ... [] > new @@ -1089,7 +1089,7 @@ class A { --> -``` +```eo [] > class__A ... [] > new @@ -1124,7 +1124,7 @@ void m(){ --> -``` +```eo [this] > m seq > @ variableDeclaration_1 @@ -1159,12 +1159,12 @@ Example: { int a=1; method(); - } +} ``` --> -``` +```eo [] > block_1 seq > @ variableDeclaration_1 # int a = 1; @@ -1202,7 +1202,7 @@ if(cond) --> -``` +```eo [] > ifThenElse_1 translated_cond.if > @ block_1 @@ -1216,7 +1216,7 @@ if(cond) If no else part is provided then translator generate empty block (`empty`): -``` +```eo [] > empty_1 TRUE > @ ``` @@ -1231,7 +1231,7 @@ assert cond:expr; --> -``` +```eo [] > assert_1 translated_cond.if > @ TRUE @@ -1252,7 +1252,7 @@ while(cond) --> -``` +```eo [] > while_1 translated_cond.while > @ [while_i] @@ -1274,7 +1274,7 @@ do --> -``` +```eo [] > do_1 translated_cond.do > @ [do_i] @@ -1302,7 +1302,7 @@ Examples: `1` -> -``` +```eo [] > literal_1 prim__int.constructor_2 > @ prim__int.new @@ -1311,7 +1311,7 @@ Examples: `1.0` -> -``` +```eo [] > literal_1 prim__float.constructor_2 > @ prim__float.new @@ -1320,7 +1320,7 @@ Examples: `"string"` -> -``` +```eo [] > literal_1 class__String.constructor_2 > @ class__String.new @@ -1335,7 +1335,7 @@ It's remaining unchanged. `(expresion)` -> -``` +```eo [] > parenthesized_1 expresion > @ ``` @@ -1347,7 +1347,7 @@ cases. `new A(arg)` -> -``` +```eo [] > statementExpression_1 class__A.constructor > @ class__A.new @@ -1369,7 +1369,7 @@ initializers translator uses `array` aka `*` object from EO. `int[] array = {1}` -> -``` +```eo [] > variableDeclaration_1 array.write > @ initializerArray_1 @@ -1388,7 +1388,7 @@ initializers translator uses `array` aka `*` object from EO. `array[idx]` -> -``` +```eo [] > statementExpression_1 simpleReference_1.get > @ simpleReference_2.v @@ -1404,7 +1404,7 @@ initializers translator uses `array` aka `*` object from EO. `a.b` -> -``` +```eo [] > statementExpression_1 simpleReference_1.b > @ [] > simpleReference_1 @@ -1417,7 +1417,7 @@ It can be simplified, but we keep such translation for generalization. `a.super.b` -> -``` +```eo [] > statementExpression_1 simpleReference_1.super.b > @ [] > simpleReference_1 @@ -1428,7 +1428,7 @@ It can be simplified, but we keep such translation for generalization. `a.b(arg)` -> -``` +```eo [] > statementExpression_1 a.b > @ # call of b a # a should be passed @@ -1441,7 +1441,7 @@ It can be simplified, but we keep such translation for generalization. `expr++` -> -``` +```eo [] > statementExpression_1 simpleReference_1.inc_post > @ # increment itself [] > simpleReference_1 @@ -1452,7 +1452,7 @@ It can be simplified, but we keep such translation for generalization. `expr--` -> -``` +```eo [] > statementExpression_1 simpleReference_1.dec_post > @ # decrement itself [] > simpleReference_1 @@ -1498,7 +1498,7 @@ It can be simplified, but we keep such translation for generalization. `-expr` -> -``` +```eo [] > statementExpression_1 simpleReference_1.neg > @ # negation itself [] > simpleReference_1 @@ -1509,7 +1509,7 @@ It can be simplified, but we keep such translation for generalization. `(int) 1.0` -> -``` +```eo [] > statementExpression_1 prim__int.from > @ # cast itself literal_1 @@ -1523,7 +1523,7 @@ It can be simplified, but we keep such translation for generalization. `left operand right` -> -``` +```eo [] > statementExpression_1 simpleReference_1.t_operand > @ simpleReference_2