aas-core-codegen 0.0.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aas_core_codegen/__init__.py +6 -0
- aas_core_codegen/__main__.py +8 -0
- aas_core_codegen/common.py +500 -0
- aas_core_codegen/cpp/__init__.py +1 -0
- aas_core_codegen/cpp/aas_common/__init__.py +6 -0
- aas_core_codegen/cpp/aas_common/_generate.py +713 -0
- aas_core_codegen/cpp/common.py +681 -0
- aas_core_codegen/cpp/constants/__init__.py +6 -0
- aas_core_codegen/cpp/constants/_generate.py +568 -0
- aas_core_codegen/cpp/description.py +654 -0
- aas_core_codegen/cpp/enhancing/__init__.py +4 -0
- aas_core_codegen/cpp/enhancing/_generate.py +993 -0
- aas_core_codegen/cpp/iteration/__init__.py +6 -0
- aas_core_codegen/cpp/iteration/_generate.py +2332 -0
- aas_core_codegen/cpp/jsonization/__init__.py +6 -0
- aas_core_codegen/cpp/jsonization/_generate.py +2619 -0
- aas_core_codegen/cpp/main.py +694 -0
- aas_core_codegen/cpp/naming.py +170 -0
- aas_core_codegen/cpp/optionaling.py +557 -0
- aas_core_codegen/cpp/pattern/__init__.py +6 -0
- aas_core_codegen/cpp/pattern/_generate.py +508 -0
- aas_core_codegen/cpp/revm/__init__.py +6 -0
- aas_core_codegen/cpp/revm/_generate.py +1149 -0
- aas_core_codegen/cpp/stringification/__init__.py +5 -0
- aas_core_codegen/cpp/stringification/_generate.py +955 -0
- aas_core_codegen/cpp/structure/__init__.py +7 -0
- aas_core_codegen/cpp/structure/_generate.py +1503 -0
- aas_core_codegen/cpp/transpilation.py +1383 -0
- aas_core_codegen/cpp/unrolling.py +159 -0
- aas_core_codegen/cpp/verification/__init__.py +6 -0
- aas_core_codegen/cpp/verification/_generate.py +3073 -0
- aas_core_codegen/cpp/visitation/__init__.py +6 -0
- aas_core_codegen/cpp/visitation/_generate.py +521 -0
- aas_core_codegen/cpp/wstringification/__init__.py +5 -0
- aas_core_codegen/cpp/wstringification/_generate.py +586 -0
- aas_core_codegen/cpp/xmlization/__init__.py +6 -0
- aas_core_codegen/cpp/xmlization/_generate.py +5373 -0
- aas_core_codegen/cpp/yielding.py +201 -0
- aas_core_codegen/csharp/__init__.py +1 -0
- aas_core_codegen/csharp/common.py +224 -0
- aas_core_codegen/csharp/constants/__init__.py +5 -0
- aas_core_codegen/csharp/constants/_generate.py +409 -0
- aas_core_codegen/csharp/copying/__init__.py +4 -0
- aas_core_codegen/csharp/copying/_generate.py +498 -0
- aas_core_codegen/csharp/description.py +1103 -0
- aas_core_codegen/csharp/enhancing/__init__.py +4 -0
- aas_core_codegen/csharp/enhancing/_generate.py +667 -0
- aas_core_codegen/csharp/jsonization/__init__.py +4 -0
- aas_core_codegen/csharp/jsonization/_generate.py +1630 -0
- aas_core_codegen/csharp/main.py +421 -0
- aas_core_codegen/csharp/naming.py +157 -0
- aas_core_codegen/csharp/reporting/__init__.py +4 -0
- aas_core_codegen/csharp/reporting/_generate.py +266 -0
- aas_core_codegen/csharp/stringification/__init__.py +4 -0
- aas_core_codegen/csharp/stringification/_generate.py +243 -0
- aas_core_codegen/csharp/structure/__init__.py +6 -0
- aas_core_codegen/csharp/structure/_generate.py +1341 -0
- aas_core_codegen/csharp/transpilation.py +990 -0
- aas_core_codegen/csharp/unrolling.py +211 -0
- aas_core_codegen/csharp/verification/__init__.py +6 -0
- aas_core_codegen/csharp/verification/_generate.py +1457 -0
- aas_core_codegen/csharp/visitation/__init__.py +5 -0
- aas_core_codegen/csharp/visitation/_generate.py +579 -0
- aas_core_codegen/csharp/xmlization/__init__.py +4 -0
- aas_core_codegen/csharp/xmlization/_generate.py +1980 -0
- aas_core_codegen/golang/__init__.py +1 -0
- aas_core_codegen/golang/aas_common/__init__.py +4 -0
- aas_core_codegen/golang/aas_common/_generate.py +152 -0
- aas_core_codegen/golang/common.py +303 -0
- aas_core_codegen/golang/constants/__init__.py +5 -0
- aas_core_codegen/golang/constants/_generate.py +339 -0
- aas_core_codegen/golang/description.py +501 -0
- aas_core_codegen/golang/enhancing/__init__.py +4 -0
- aas_core_codegen/golang/enhancing/_generate.py +527 -0
- aas_core_codegen/golang/jsonization/__init__.py +4 -0
- aas_core_codegen/golang/jsonization/_generate.py +1740 -0
- aas_core_codegen/golang/main.py +368 -0
- aas_core_codegen/golang/naming.py +412 -0
- aas_core_codegen/golang/pointering.py +631 -0
- aas_core_codegen/golang/reporting/__init__.py +4 -0
- aas_core_codegen/golang/reporting/_generate.py +218 -0
- aas_core_codegen/golang/stringification/__init__.py +4 -0
- aas_core_codegen/golang/stringification/_generate.py +394 -0
- aas_core_codegen/golang/structure/__init__.py +6 -0
- aas_core_codegen/golang/structure/_generate.py +1493 -0
- aas_core_codegen/golang/transpilation.py +1191 -0
- aas_core_codegen/golang/unrolling.py +159 -0
- aas_core_codegen/golang/verification/__init__.py +6 -0
- aas_core_codegen/golang/verification/_generate.py +1513 -0
- aas_core_codegen/golang/xmlization/__init__.py +4 -0
- aas_core_codegen/golang/xmlization/_generate.py +2507 -0
- aas_core_codegen/infer_for_schema/__init__.py +21 -0
- aas_core_codegen/infer_for_schema/_inline.py +693 -0
- aas_core_codegen/infer_for_schema/_len.py +527 -0
- aas_core_codegen/infer_for_schema/_pattern.py +311 -0
- aas_core_codegen/infer_for_schema/_set.py +394 -0
- aas_core_codegen/infer_for_schema/_stringify.py +201 -0
- aas_core_codegen/infer_for_schema/_types.py +135 -0
- aas_core_codegen/infer_for_schema/match.py +122 -0
- aas_core_codegen/intermediate/__init__.py +78 -0
- aas_core_codegen/intermediate/_hierarchy.py +397 -0
- aas_core_codegen/intermediate/_stringify.py +989 -0
- aas_core_codegen/intermediate/_translate.py +5128 -0
- aas_core_codegen/intermediate/_types.py +2901 -0
- aas_core_codegen/intermediate/construction.py +750 -0
- aas_core_codegen/intermediate/doc.py +344 -0
- aas_core_codegen/intermediate/pattern_verification.py +428 -0
- aas_core_codegen/intermediate/revm.py +985 -0
- aas_core_codegen/intermediate/type_inference.py +2266 -0
- aas_core_codegen/java/__init__.py +1 -0
- aas_core_codegen/java/common.py +197 -0
- aas_core_codegen/java/constants/__init__.py +5 -0
- aas_core_codegen/java/constants/_generate.py +334 -0
- aas_core_codegen/java/copying/__init__.py +4 -0
- aas_core_codegen/java/copying/_generate.py +502 -0
- aas_core_codegen/java/description.py +774 -0
- aas_core_codegen/java/enhancing/__init__.py +4 -0
- aas_core_codegen/java/enhancing/_generate.py +820 -0
- aas_core_codegen/java/generation/__init__.py +5 -0
- aas_core_codegen/java/generation/_generate.py +285 -0
- aas_core_codegen/java/jsonization/__init__.py +4 -0
- aas_core_codegen/java/jsonization/_generate.py +1472 -0
- aas_core_codegen/java/main.py +438 -0
- aas_core_codegen/java/naming.py +187 -0
- aas_core_codegen/java/optional.py +514 -0
- aas_core_codegen/java/reporting/__init__.py +4 -0
- aas_core_codegen/java/reporting/_generate.py +248 -0
- aas_core_codegen/java/stringification/__init__.py +4 -0
- aas_core_codegen/java/stringification/_generate.py +212 -0
- aas_core_codegen/java/structure/__init__.py +6 -0
- aas_core_codegen/java/structure/_generate.py +1767 -0
- aas_core_codegen/java/transpilation.py +1111 -0
- aas_core_codegen/java/verification/__init__.py +6 -0
- aas_core_codegen/java/verification/_generate.py +1536 -0
- aas_core_codegen/java/visitation/__init__.py +5 -0
- aas_core_codegen/java/visitation/_generate.py +689 -0
- aas_core_codegen/java/xmlization/__init__.py +4 -0
- aas_core_codegen/java/xmlization/_generate.py +2274 -0
- aas_core_codegen/jsonld/__init__.py +1 -0
- aas_core_codegen/jsonld/main.py +455 -0
- aas_core_codegen/jsonschema/__init__.py +1 -0
- aas_core_codegen/jsonschema/main.py +982 -0
- aas_core_codegen/main.py +245 -0
- aas_core_codegen/naming.py +133 -0
- aas_core_codegen/opcua/__init__.py +1 -0
- aas_core_codegen/opcua/main.py +1525 -0
- aas_core_codegen/opcua/naming.py +126 -0
- aas_core_codegen/parse/__init__.py +46 -0
- aas_core_codegen/parse/_rules.py +796 -0
- aas_core_codegen/parse/_stringify.py +532 -0
- aas_core_codegen/parse/_translate.py +3940 -0
- aas_core_codegen/parse/_types.py +973 -0
- aas_core_codegen/parse/retree/__init__.py +46 -0
- aas_core_codegen/parse/retree/_fix.py +434 -0
- aas_core_codegen/parse/retree/_parse.py +1143 -0
- aas_core_codegen/parse/retree/_render.py +298 -0
- aas_core_codegen/parse/retree/_stringify.py +199 -0
- aas_core_codegen/parse/retree/_types.py +362 -0
- aas_core_codegen/parse/retree/_visitor.py +70 -0
- aas_core_codegen/parse/tree.py +1303 -0
- aas_core_codegen/protobuf/__init__.py +1 -0
- aas_core_codegen/protobuf/common.py +225 -0
- aas_core_codegen/protobuf/description.py +1102 -0
- aas_core_codegen/protobuf/main.py +115 -0
- aas_core_codegen/protobuf/naming.py +143 -0
- aas_core_codegen/protobuf/structure/__init__.py +6 -0
- aas_core_codegen/protobuf/structure/_generate.py +502 -0
- aas_core_codegen/py.typed +1 -0
- aas_core_codegen/python/__init__.py +1 -0
- aas_core_codegen/python/aas_common/__init__.py +4 -0
- aas_core_codegen/python/aas_common/_generate.py +63 -0
- aas_core_codegen/python/common.py +406 -0
- aas_core_codegen/python/constants/__init__.py +5 -0
- aas_core_codegen/python/constants/_generate.py +377 -0
- aas_core_codegen/python/description.py +508 -0
- aas_core_codegen/python/jsonization/__init__.py +4 -0
- aas_core_codegen/python/jsonization/_generate.py +1391 -0
- aas_core_codegen/python/main.py +323 -0
- aas_core_codegen/python/naming.py +255 -0
- aas_core_codegen/python/stringification/__init__.py +4 -0
- aas_core_codegen/python/stringification/_generate.py +129 -0
- aas_core_codegen/python/structure/__init__.py +6 -0
- aas_core_codegen/python/structure/_generate.py +1801 -0
- aas_core_codegen/python/transpilation.py +958 -0
- aas_core_codegen/python/unrolling.py +156 -0
- aas_core_codegen/python/verification/__init__.py +6 -0
- aas_core_codegen/python/verification/_generate.py +1471 -0
- aas_core_codegen/python/xmlization/__init__.py +4 -0
- aas_core_codegen/python/xmlization/_generate.py +3003 -0
- aas_core_codegen/python_protobuf/__init__.py +1 -0
- aas_core_codegen/python_protobuf/main.py +1424 -0
- aas_core_codegen/python_protobuf/naming.py +85 -0
- aas_core_codegen/rdf_shacl/__init__.py +1 -0
- aas_core_codegen/rdf_shacl/_description.py +351 -0
- aas_core_codegen/rdf_shacl/common.py +206 -0
- aas_core_codegen/rdf_shacl/main.py +114 -0
- aas_core_codegen/rdf_shacl/naming.py +145 -0
- aas_core_codegen/rdf_shacl/rdf.py +435 -0
- aas_core_codegen/rdf_shacl/shacl.py +453 -0
- aas_core_codegen/run.py +124 -0
- aas_core_codegen/smoke/__init__.py +1 -0
- aas_core_codegen/smoke/main.py +219 -0
- aas_core_codegen/specific_implementations.py +72 -0
- aas_core_codegen/stringify.py +333 -0
- aas_core_codegen/typescript/__init__.py +1 -0
- aas_core_codegen/typescript/aas_common/__init__.py +4 -0
- aas_core_codegen/typescript/aas_common/_generate.py +472 -0
- aas_core_codegen/typescript/common.py +340 -0
- aas_core_codegen/typescript/constants/__init__.py +5 -0
- aas_core_codegen/typescript/constants/_generate.py +347 -0
- aas_core_codegen/typescript/description.py +530 -0
- aas_core_codegen/typescript/jsonization/__init__.py +4 -0
- aas_core_codegen/typescript/jsonization/_generate.py +1510 -0
- aas_core_codegen/typescript/main.py +258 -0
- aas_core_codegen/typescript/naming.py +189 -0
- aas_core_codegen/typescript/stringification/__init__.py +4 -0
- aas_core_codegen/typescript/stringification/_generate.py +367 -0
- aas_core_codegen/typescript/structure/__init__.py +6 -0
- aas_core_codegen/typescript/structure/_generate.py +2500 -0
- aas_core_codegen/typescript/transpilation.py +1051 -0
- aas_core_codegen/typescript/unrolling.py +159 -0
- aas_core_codegen/typescript/verification/__init__.py +6 -0
- aas_core_codegen/typescript/verification/_generate.py +1578 -0
- aas_core_codegen/xsd/__init__.py +1 -0
- aas_core_codegen/xsd/main.py +1187 -0
- aas_core_codegen/xsd/naming.py +83 -0
- aas_core_codegen/yielding/__init__.py +1 -0
- aas_core_codegen/yielding/flow.py +139 -0
- aas_core_codegen/yielding/linear.py +754 -0
- aas_core_codegen-0.0.16.dist-info/METADATA +211 -0
- aas_core_codegen-0.0.16.dist-info/RECORD +604 -0
- aas_core_codegen-0.0.16.dist-info/WHEEL +5 -0
- aas_core_codegen-0.0.16.dist-info/entry_points.txt +3 -0
- aas_core_codegen-0.0.16.dist-info/licenses/AUTHORS +9 -0
- aas_core_codegen-0.0.16.dist-info/licenses/LICENSE +23 -0
- aas_core_codegen-0.0.16.dist-info/top_level.txt +2 -0
- dev/continuous_integration/__init__.py +1 -0
- dev/continuous_integration/check_help_in_readme.py +208 -0
- dev/continuous_integration/check_init_and_pyproject_consistent.py +154 -0
- dev/continuous_integration/precommit.py +400 -0
- dev/dev_scripts/__init__.py +1 -0
- dev/dev_scripts/compare_rendered_regexes_against_source_py.py +42 -0
- dev/dev_scripts/copy_to_aas_core3_cpp.py +100 -0
- dev/dev_scripts/copy_to_aas_core3_java.py +90 -0
- dev/dev_scripts/download_latest_aas_core_meta_v3.py +114 -0
- dev/dev_scripts/draw_bipartite_graph_based_on_lines.py +37 -0
- dev/dev_scripts/run_tests_with_rerecord.py +69 -0
- dev/dev_scripts/update_to_aas_core_meta.py +174 -0
- dev/integration_tests/input/jsonschema/boilerplate/main.py +55 -0
- dev/integration_tests/input/meta_model.py +38 -0
- dev/integration_tests/input/python/boilerplate/main.py +153 -0
- dev/integration_tests/main.py +258 -0
- dev/test_data/csharp/test_structure/concrete_class_with_descendants/meta_model.py +15 -0
- dev/test_data/csharp/test_structure/constructor_without_arguments/all_properties_optional/meta_model.py +9 -0
- dev/test_data/csharp/test_structure/constructor_without_arguments/no_properties/meta_model.py +6 -0
- dev/test_data/csharp/test_verification/builtin_functions/len/on_list/meta_model.py +20 -0
- dev/test_data/csharp/test_verification/builtin_functions/len/on_str/meta_model.py +16 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/as_prefix/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/as_suffix/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_group_with_quantifier/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_the_middle/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_union/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/single_utf32_literal/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/with_quantifier_within_group/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/with_quantifier_without_group/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/at_the_beginning/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/at_the_end/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/in_the_middle/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/multiple/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/single/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/single_with_quantifier/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/mixed_with_non_utf32/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/more_than_two_high_surrogates/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/multiple_utf32_ranges/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/multiple_utf32_ranges_mixed_with_non_utf32/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/same_high_surrogate/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/same_high_surrogate_with_quantifier/meta_model.py +8 -0
- dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/two_high_surrogates/meta_model.py +8 -0
- dev/test_data/intermediate/expected/class/empty/meta_model.py +6 -0
- dev/test_data/intermediate/expected/class/implementation_specific_method/meta_model.py +8 -0
- dev/test_data/intermediate/expected/class/inheritance/meta_model.py +41 -0
- dev/test_data/intermediate/expected/class/methods_with_contracts/meta_model.py +15 -0
- dev/test_data/intermediate/expected/class/only_method_no_property/meta_model.py +7 -0
- dev/test_data/intermediate/expected/class/only_property_no_method/meta_model.py +9 -0
- dev/test_data/intermediate/expected/constant/constant_set/of_enum/meta_model.py +12 -0
- dev/test_data/intermediate/expected/constant/constant_set/of_str/meta_model.py +4 -0
- dev/test_data/intermediate/expected/constant/constant_set/with_description/meta_model.py +6 -0
- dev/test_data/intermediate/expected/constant/constant_set/with_superset_of/meta_model.py +14 -0
- dev/test_data/intermediate/expected/constant/constant_str/only_value/meta_model.py +7 -0
- dev/test_data/intermediate/expected/constant/constant_str/with_description/meta_model.py +5 -0
- dev/test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/meta_model.py +20 -0
- dev/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/meta_model.py +20 -0
- dev/test_data/intermediate/expected/empty/meta_model.py +2 -0
- dev/test_data/intermediate/expected/enumeration/meta_model.py +9 -0
- dev/test_data/intermediate/expected/interface/basic/meta_model.py +14 -0
- dev/test_data/intermediate/expected/interface/empty/meta_model.py +7 -0
- dev/test_data/intermediate/expected/interface/inheritance/meta_model.py +27 -0
- dev/test_data/intermediate/expected/interface/method_signature/meta_model.py +10 -0
- dev/test_data/intermediate/expected/interface/only_constructor/meta_model.py +11 -0
- dev/test_data/intermediate/expected/method/non_mutating/implementation_specific/meta_model.py +12 -0
- dev/test_data/intermediate/expected/method/non_mutating/understood/meta_model.py +11 -0
- dev/test_data/intermediate/expected/type_annotation/atomic/meta_model.py +9 -0
- dev/test_data/intermediate/expected/type_annotation/subscripted/class/meta_model.py +13 -0
- dev/test_data/intermediate/expected/type_annotation/subscripted/primitive/meta_model.py +9 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/enumeration_literals_in_subset_outside_of_superset/meta_model.py +20 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/invalid_literal/meta_model.py +11 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/mismatch_between_enumeration_and_literal/meta_model.py +30 -0
- dev/test_data/intermediate/unexpected/constant_set/of_enum/mismatch_in_enumerations_between_subset_and_superset/meta_model.py +21 -0
- dev/test_data/intermediate/unexpected/constant_set/of_str/literals_in_subset_outside_of_superset/meta_model.py +18 -0
- dev/test_data/intermediate/unexpected/constant_set/of_str/mismatch_between_type_annotation_and_literals/meta_model.py +10 -0
- dev/test_data/intermediate/unexpected/constant_set/of_str/superset_and_subset_mismatch_in_type/meta_model.py +12 -0
- dev/test_data/intermediate/unexpected/constraints/dangling_constraintref/meta_model.py +18 -0
- dev/test_data/intermediate/unexpected/constraints/duplicate_constraints/meta_model.py +20 -0
- dev/test_data/intermediate/unexpected/documentation/unexpected_documentation_elements/meta_model.py +34 -0
- dev/test_data/intermediate/unexpected/invariant/class_invariant_uses_re/meta_model.py +10 -0
- dev/test_data/intermediate/unexpected/invariant/invariant_of_constrained_primitive_uses_re/meta_model.py +7 -0
- dev/test_data/intermediate/unexpected/invariant/unexpected_argument_count_to_len/meta_model.py +20 -0
- dev/test_data/intermediate/unexpected/invariant/unhandled_built_in_function/meta_model.py +16 -0
- dev/test_data/intermediate/unexpected/method_definitions/non_constant_default/meta_model.py +7 -0
- dev/test_data/intermediate/unexpected/optional_constructor_arguments_wo_default/default_non_none/meta_model.py +16 -0
- dev/test_data/intermediate/unexpected/optional_constructor_arguments_wo_default/no_default/meta_model.py +16 -0
- dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/after_inheritance/meta_model.py +58 -0
- dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/type_missmatch/meta_model.py +9 -0
- dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/within_class/meta_model.py +22 -0
- dev/test_data/jsonschema/test_main/regression_when_len_constraints_on_inherited_property/meta_model.py +28 -0
- dev/test_data/opcua/test_main/abstract_and_concrete_classes/meta_model.py +37 -0
- dev/test_data/opcua/test_main/classes_with_invariants/meta_model.py +21 -0
- dev/test_data/opcua/test_main/concrete_class_with_descendant/meta_model.py +27 -0
- dev/test_data/opcua/test_main/concrete_class_with_enum/meta_model.py +21 -0
- dev/test_data/opcua/test_main/concrete_class_with_list_of_instances/meta_model.py +21 -0
- dev/test_data/opcua/test_main/concrete_class_with_primitive_attributes/meta_model.py +41 -0
- dev/test_data/opcua/test_main/concrete_class_with_string/meta_model.py +13 -0
- dev/test_data/opcua/test_main/constrained_primitive/meta_model.py +20 -0
- dev/test_data/opcua/test_main/multiple_inheritance/meta_model.py +25 -0
- dev/test_data/parse/expected/constant/constant_set/of_enum/meta_model.py +12 -0
- dev/test_data/parse/expected/constant/constant_set/of_str/meta_model.py +4 -0
- dev/test_data/parse/expected/constant/constant_set/with_description/meta_model.py +6 -0
- dev/test_data/parse/expected/constant/constant_set/with_superset_of/meta_model.py +14 -0
- dev/test_data/parse/expected/constant/constant_str/only_value/meta_model.py +7 -0
- dev/test_data/parse/expected/constant/constant_str/with_description/meta_model.py +5 -0
- dev/test_data/parse/expected/enum/ok/meta_model.py +15 -0
- dev/test_data/parse/expected/implementation_specific_class/properties_and_methods_in_implementation_specific_class/meta_model.py +17 -0
- dev/test_data/parse/expected/inheritance/basic/meta_model.py +11 -0
- dev/test_data/parse/expected/inheritance/diamond/meta_model.py +26 -0
- dev/test_data/parse/expected/inheritance/inheritance_from_concrete_class/meta_model.py +10 -0
- dev/test_data/parse/expected/invariants/in_relation/meta_model.py +16 -0
- dev/test_data/parse/expected/method/arguments/meta_model.py +7 -0
- dev/test_data/parse/expected/method/basic/meta_model.py +7 -0
- dev/test_data/parse/expected/method/contracts/condition_as_keyword_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/condition_as_positional_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/description_as_keyword_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/description_as_positional_argument/meta_model.py +8 -0
- dev/test_data/parse/expected/method/contracts/multiple_contracts_in_order/meta_model.py +17 -0
- dev/test_data/parse/expected/method/contracts/postcondition/basic/meta_model.py +10 -0
- dev/test_data/parse/expected/method/contracts/postcondition/snapshot/with_keyword_arguments/meta_model.py +9 -0
- dev/test_data/parse/expected/method/contracts/postcondition/snapshot/with_positional_arguments/meta_model.py +9 -0
- dev/test_data/parse/expected/method/default/meta_model.py +9 -0
- dev/test_data/parse/expected/method/description/meta_model.py +8 -0
- dev/test_data/parse/expected/method/is_implementation_specific/meta_model.py +8 -0
- dev/test_data/parse/expected/method/non_mutating/meta_model.py +11 -0
- dev/test_data/parse/expected/method/returns_none/meta_model.py +7 -0
- dev/test_data/parse/expected/method/returns_something/meta_model.py +7 -0
- dev/test_data/parse/expected/single_class/description/meta_model.py +12 -0
- dev/test_data/parse/expected/single_class/empty/meta_model.py +6 -0
- dev/test_data/parse/expected/single_class/property/description/meta_model.py +14 -0
- dev/test_data/parse/expected/single_class/property/mandatory/meta_model.py +6 -0
- dev/test_data/parse/expected/single_class/property/optional/meta_model.py +6 -0
- dev/test_data/parse/expected/single_class/property/recursion_to_entity/meta_model.py +6 -0
- dev/test_data/parse/unexpected/class_decorators/non_name_decorator/meta_model.py +7 -0
- dev/test_data/parse/unexpected/class_decorators/unknown_decorator/meta_model.py +7 -0
- dev/test_data/parse/unexpected/class_definitions/is_abstract_and_implementation_specific/meta_model.py +8 -0
- dev/test_data/parse/unexpected/class_definitions/unexpected_docstring_before_a_method/meta_model.py +11 -0
- dev/test_data/parse/unexpected/class_definitions/unexpected_docstring_for_a_pass/meta_model.py +9 -0
- dev/test_data/parse/unexpected/class_definitions/unexpected_double_description_for_a_property/meta_model.py +10 -0
- dev/test_data/parse/unexpected/class_inheritances/inheriting_from_implementation_specific_parent/meta_model.py +20 -0
- dev/test_data/parse/unexpected/class_inheritances/non_name_super_class/meta_model.py +6 -0
- dev/test_data/parse/unexpected/enum/expression_as_assignment_value/meta_model.py +6 -0
- dev/test_data/parse/unexpected/enum/non_assignment/meta_model.py +8 -0
- dev/test_data/parse/unexpected/enum/non_string_literal/meta_model.py +6 -0
- dev/test_data/parse/unexpected/enum/unexpected_inheritance/meta_model.py +6 -0
- dev/test_data/parse/unexpected/method_contracts/contract/non_lambda_condition/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/contract/non_string_literal_description/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/contract/without_any_arguments/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/contract/without_condition/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/postcondition/OLD_in_postcondition_without_snapshot/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/postcondition/argument_missing_in_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/precondition/argument_missing_in_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/argument_missing_in_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/capture_not_a_lambda/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/invalid_name/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/name_not_a_string_literal/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/without_a_capture/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_contracts/snapshot/without_a_name/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/non_mutating/non_mutating_constructor/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/non_mutating/non_mutating_verification_function/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/non_name_decorator/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/unknown_call_decorator/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_decorators/unknown_name_decorator/meta_model.py +8 -0
- dev/test_data/parse/unexpected/method_definitions/argument_with_final/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/argument_without_a_type_annotation/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/default_for_self/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/dunder/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/init_with_return_type/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_keyword_only_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_positional_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_type_annotation_for_self/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_variable_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/with_variable_keyword_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/without_arguments/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/without_self/meta_model.py +7 -0
- dev/test_data/parse/unexpected/method_definitions/without_type_annotation_for_result/meta_model.py +7 -0
- dev/test_data/parse/unexpected/property_definitions/final_without_subscript/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/nested_final/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/non_simple/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/unexpected_assignment/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/unexpected_non_name_property/meta_model.py +6 -0
- dev/test_data/parse/unexpected/property_definitions/without_type_annotation/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/constant_set_with_a_non_set_subset/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_inheritance/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_a_property/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_an_argument/meta_model.py +7 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_constant_set/meta_model.py +6 -0
- dev/test_data/parse/unexpected/symbol_table/dangling_subset_in_constant_set/meta_model.py +4 -0
- dev/test_data/parse/unexpected/symbol_table/inheritance_from_non_class/meta_model.py +10 -0
- dev/test_data/parse_retree/expected/character_set/common_escaping/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/complementing/double_caret/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/complementing/multiple_ranges/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/complementing/suffix_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/escape_first_caret/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/literals_which_need_no_escaping_in_characters_set_but_need_escaping_outside/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/multiple_ranges/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/single_literal/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/single_range/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/unescaped_dash/only_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/unescaped_dash/prefix_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/character_set/unescaped_dash/suffix_dash/source.py +1 -0
- dev/test_data/parse_retree/expected/dot/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/group/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/group_in_a_group/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/group_of_union_of_empty_concatenations/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/regex/source.py +1 -0
- dev/test_data/parse_retree/expected/empty/union_of_empty_concatenations/source.py +1 -0
- dev/test_data/parse_retree/expected/escaped_literals/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/at_the_beginning/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/at_the_end/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/in_the_middle/source.py +1 -0
- dev/test_data/parse_retree/expected/formatted_value/single_formatted_value/source.py +1 -0
- dev/test_data/parse_retree/expected/literal/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/at_least_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/at_least_one/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/at_most_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/exactly_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/maybe/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/greedy/zero_or_more/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/at_least_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/at_least_one/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/at_most_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/exactly_3/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/maybe/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/non_greedy/zero_or_more/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_character_set/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_formatted_value/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_group/source.py +1 -0
- dev/test_data/parse_retree/expected/quantifier/on_a_literal/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/double_end_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/double_start_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/end_symbol_in_the_middle/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/only_start_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/only_stop_symbol/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/start_symbol_at_the_beginning/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/start_symbol_in_the_middle/source.py +1 -0
- dev/test_data/parse_retree/expected/start_and_stop_symbols/stop_symbol_at_the_end/source.py +1 -0
- dev/test_data/parse_retree/expected/union/of_character_sets/source.py +1 -0
- dev/test_data/parse_retree/expected/union/of_groups/source.py +1 -0
- dev/test_data/parse_retree/expected/union/of_string_literals/source.py +1 -0
- dev/test_data/parse_retree/expected/union/within_group/source.py +1 -0
- dev/test_data/parse_retree/expected/whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/Uxxxxxxxx_out_of_range/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/only_backslash/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_Uxxxxxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_uxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unexpected_escaping/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/Uxxxxxxxx_out_of_range/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/only_backslash/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_Uxxxxxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_uxxxx/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unexpected_escaping/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_digit/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/whitespace/source.py +1 -0
- dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/word/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_character_range/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_quantifier/at_least_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_quantifier/between_3_and_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/invalid_quantifier/exactly_x/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unhandled_group_directives/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/character_set/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/group/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/group_of_union_of_empty_concatenations/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/quantifier/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/quantifier_with_comma/source.py +1 -0
- dev/test_data/parse_retree/unexpected/unterminated/quantifier_with_number_and_comma/source.py +1 -0
- dev/test_data/proto/test_main/expected/abstract_and_concrete_classes/meta_model.py +37 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_descendants/meta_model.py +30 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_enum/meta_model.py +21 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_list_of_instances/meta_model.py +21 -0
- dev/test_data/proto/test_main/expected/concrete_class_with_primitive_attributes/meta_model.py +41 -0
- dev/test_data/python_protobuf/test_main/abstract_and_concrete_classes/expected_output/pbization.py +532 -0
- dev/test_data/python_protobuf/test_main/abstract_and_concrete_classes/meta_model.py +37 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_descendant/expected_output/pbization.py +527 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_descendant/meta_model.py +27 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_enum/expected_output/pbization.py +290 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_enum/meta_model.py +21 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_list_of_instances/expected_output/pbization.py +328 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_list_of_instances/meta_model.py +23 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_primitive_attributes/expected_output/pbization.py +274 -0
- dev/test_data/python_protobuf/test_main/concrete_class_with_primitive_attributes/meta_model.py +41 -0
- dev/test_data/rdf_shacl/test_main/expected/regression_when_lang_string_class_is_missing/meta_model.py +29 -0
- dev/test_data/rdf_shacl/test_main/expected/regression_when_len_constraints_on_inherited_property/meta_model.py +27 -0
- dev/test_data/rdf_shacl/test_main/unexpected/regression_len_constraint_on_class_property/meta_model.py +61 -0
- dev/test_data/real_meta_models/aas_core_meta.v3.py +5721 -0
- dev/test_data/smoke/test_main/unexpected/infer_for_schema_error/meta_model.py +12 -0
- dev/test_data/smoke/test_main/unexpected/intermediate_error/meta_model.py +18 -0
- dev/test_data/smoke/test_main/unexpected/parse_error/meta_model.py +5 -0
- dev/test_data/smoke/test_main/unexpected/pattern_verification_unparsable_regex/direct_match/meta_model.py +8 -0
- dev/test_data/smoke/test_main/unexpected/type_error/meta_model.py +18 -0
- dev/tests/__init__.py +1 -0
- dev/tests/common.py +197 -0
- dev/tests/cpp/__init__.py +0 -0
- dev/tests/cpp/test_common.py +32 -0
- dev/tests/cpp/test_main.py +144 -0
- dev/tests/cpp/test_pattern.py +188 -0
- dev/tests/cpp/test_verification.py +189 -0
- dev/tests/cpp/test_yielding.py +225 -0
- dev/tests/csharp/__init__.py +0 -0
- dev/tests/csharp/live_test_main.py +109 -0
- dev/tests/csharp/test_common.py +28 -0
- dev/tests/csharp/test_description.py +684 -0
- dev/tests/csharp/test_main.py +129 -0
- dev/tests/csharp/test_structure.py +93 -0
- dev/tests/csharp/test_verification.py +82 -0
- dev/tests/description.py +29 -0
- dev/tests/golang/__init__.py +0 -0
- dev/tests/golang/test_common.py +78 -0
- dev/tests/golang/test_main.py +128 -0
- dev/tests/infer_for_schema/__init__.py +0 -0
- dev/tests/infer_for_schema/common.py +47 -0
- dev/tests/infer_for_schema/test_len_on_properties.py +955 -0
- dev/tests/infer_for_schema/test_len_on_self.py +580 -0
- dev/tests/infer_for_schema/test_patterns_on_properties.py +686 -0
- dev/tests/infer_for_schema/test_patterns_on_self.py +258 -0
- dev/tests/infer_for_schema/test_property_in_set_of_enumeration_literals.py +600 -0
- dev/tests/infer_for_schema/test_property_in_set_of_primitives.py +549 -0
- dev/tests/intermediate/__init__.py +0 -0
- dev/tests/intermediate/test_constructor.py +719 -0
- dev/tests/intermediate/test_hierarchy.py +221 -0
- dev/tests/intermediate/test_revm.py +134 -0
- dev/tests/intermediate/test_translate.py +337 -0
- dev/tests/intermediate/test_type_inference.py +333 -0
- dev/tests/intermediate/test_types.py +169 -0
- dev/tests/java/__init__.py +0 -0
- dev/tests/java/test_common.py +20 -0
- dev/tests/java/test_description.py +128 -0
- dev/tests/java/test_main.py +234 -0
- dev/tests/jsonld_context/test_main.py +79 -0
- dev/tests/opcua/__init__.py +3 -0
- dev/tests/opcua/test_main.py +110 -0
- dev/tests/our_jsonschema/__init__.py +3 -0
- dev/tests/our_jsonschema/test_main.py +232 -0
- dev/tests/parse/__init__.py +0 -0
- dev/tests/parse/test_parse.py +503 -0
- dev/tests/parse/test_retree.py +272 -0
- dev/tests/proto/__init__.py +0 -0
- dev/tests/proto/test_main.py +112 -0
- dev/tests/python/__init__.py +0 -0
- dev/tests/python/test_common.py +124 -0
- dev/tests/python/test_main.py +126 -0
- dev/tests/python/test_xml_playground.py +254 -0
- dev/tests/python_protobuf/__init__.py +0 -0
- dev/tests/python_protobuf/test_main.py +111 -0
- dev/tests/rdf_shacl/__init__.py +0 -0
- dev/tests/rdf_shacl/test_common.py +32 -0
- dev/tests/rdf_shacl/test_description.py +223 -0
- dev/tests/rdf_shacl/test_main.py +194 -0
- dev/tests/smoke/__init__.py +0 -0
- dev/tests/smoke/test_main.py +83 -0
- dev/tests/test_common.py +94 -0
- dev/tests/typescript/__init__.py +0 -0
- dev/tests/typescript/test_common.py +108 -0
- dev/tests/typescript/test_main.py +125 -0
- dev/tests/xsd/__init__.py +0 -0
- dev/tests/xsd/test_main.py +227 -0
- dev/tests/yielding/__init__.py +0 -0
- dev/tests/yielding/test_linear.py +558 -0
|
@@ -0,0 +1,1111 @@
|
|
|
1
|
+
"""Transpile Python to Java code."""
|
|
2
|
+
import abc
|
|
3
|
+
import io
|
|
4
|
+
from typing import (
|
|
5
|
+
Tuple,
|
|
6
|
+
List,
|
|
7
|
+
Mapping,
|
|
8
|
+
Optional,
|
|
9
|
+
Set,
|
|
10
|
+
Union,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from icontract import ensure
|
|
14
|
+
|
|
15
|
+
from aas_core_codegen import intermediate
|
|
16
|
+
from aas_core_codegen.common import (
|
|
17
|
+
assert_never,
|
|
18
|
+
Error,
|
|
19
|
+
Identifier,
|
|
20
|
+
indent_but_first_line,
|
|
21
|
+
Stripped,
|
|
22
|
+
)
|
|
23
|
+
from aas_core_codegen.java import (
|
|
24
|
+
common as java_common,
|
|
25
|
+
naming as java_naming,
|
|
26
|
+
)
|
|
27
|
+
from aas_core_codegen.csharp.common import (
|
|
28
|
+
INDENT as I,
|
|
29
|
+
INDENT2 as II,
|
|
30
|
+
)
|
|
31
|
+
from aas_core_codegen.intermediate import type_inference as intermediate_type_inference
|
|
32
|
+
from aas_core_codegen.parse import tree as parse_tree
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# NOTE (empwilli, 2024-01-19):
|
|
36
|
+
# We have to implement a very similar function for generating type annotations to
|
|
37
|
+
# aas_core_codegen.golang.common.generate_type since we can not simply pass
|
|
38
|
+
# intermediate_type_inference.TypeAnnotationUnion to
|
|
39
|
+
# aas_core_codegen.golang.common.generate_type.
|
|
40
|
+
|
|
41
|
+
PRIMITIVE_TYPE_MAP = {
|
|
42
|
+
intermediate_type_inference.PrimitiveType.BOOL: Stripped("Boolean"),
|
|
43
|
+
intermediate_type_inference.PrimitiveType.INT: Stripped("Long"),
|
|
44
|
+
intermediate_type_inference.PrimitiveType.FLOAT: Stripped("Float"),
|
|
45
|
+
intermediate_type_inference.PrimitiveType.STR: Stripped("String"),
|
|
46
|
+
intermediate_type_inference.PrimitiveType.BYTEARRAY: Stripped("byte[]"),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
51
|
+
def generate_type(
|
|
52
|
+
type_annotation: intermediate_type_inference.TypeAnnotationUnion,
|
|
53
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
54
|
+
"""
|
|
55
|
+
Generate the Java type for the given type annotation.
|
|
56
|
+
|
|
57
|
+
If ``types_package`` is specified, it is prepended to all our types.
|
|
58
|
+
|
|
59
|
+
(empwilli, 2024-01-19): We do not handle all the type annotations from
|
|
60
|
+
:py:mod:`aas_core_codegen.intermediate.type_inference` as that would be
|
|
61
|
+
YAGNI (*e.g.*, verification functions, built-in functions *etc.*).
|
|
62
|
+
If we do not know how to generate the type in Java, we return an error message.
|
|
63
|
+
"""
|
|
64
|
+
if isinstance(type_annotation, intermediate_type_inference.PrimitiveTypeAnnotation):
|
|
65
|
+
return PRIMITIVE_TYPE_MAP[type_annotation.a_type], None
|
|
66
|
+
|
|
67
|
+
elif isinstance(type_annotation, intermediate_type_inference.OurTypeAnnotation):
|
|
68
|
+
our_type = type_annotation.our_type
|
|
69
|
+
|
|
70
|
+
if isinstance(our_type, intermediate.Enumeration):
|
|
71
|
+
return Stripped(java_naming.enum_name(type_annotation.our_type.name)), None
|
|
72
|
+
|
|
73
|
+
elif isinstance(our_type, intermediate.ConstrainedPrimitive):
|
|
74
|
+
return java_common.PRIMITIVE_TYPE_MAP[our_type.constrainee], None
|
|
75
|
+
|
|
76
|
+
elif isinstance(
|
|
77
|
+
our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)
|
|
78
|
+
):
|
|
79
|
+
# NOTE (empwilli, 2024-01-19):
|
|
80
|
+
# We always refer to interfaces even in cases of concrete classes without
|
|
81
|
+
# concrete descendants since we want to allow enhancing.
|
|
82
|
+
|
|
83
|
+
return Stripped(java_naming.interface_name(our_type.name)), None
|
|
84
|
+
|
|
85
|
+
elif isinstance(type_annotation, intermediate_type_inference.ListTypeAnnotation):
|
|
86
|
+
item_type = generate_type(type_annotation=type_annotation.items)
|
|
87
|
+
|
|
88
|
+
return Stripped(f"List<{item_type}>"), None
|
|
89
|
+
|
|
90
|
+
elif isinstance(
|
|
91
|
+
type_annotation, intermediate_type_inference.OptionalTypeAnnotation
|
|
92
|
+
):
|
|
93
|
+
value_type = generate_type(type_annotation=type_annotation.value)
|
|
94
|
+
|
|
95
|
+
return Stripped(f"Optional<{value_type}>"), None
|
|
96
|
+
|
|
97
|
+
else:
|
|
98
|
+
return None, Error(
|
|
99
|
+
None,
|
|
100
|
+
f"(empwilli, 2024-01-19): We do not handle "
|
|
101
|
+
f"the type annotation {type_annotation} from "
|
|
102
|
+
"aas_core_codegen.intermediate.type_inference as that was, "
|
|
103
|
+
"at this time point, YAGNI (*e.g.*, verification functions, "
|
|
104
|
+
"built-in functions *etc.*). If you need this feature, please "
|
|
105
|
+
"contact the developers.",
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
raise AssertionError("Should not have gotten here")
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class Transpiler(
|
|
112
|
+
parse_tree.RestrictedTransformer[Tuple[Optional[Stripped], Optional[Error]]]
|
|
113
|
+
):
|
|
114
|
+
"""Transpile a node of our AST to Java code, or return an error."""
|
|
115
|
+
|
|
116
|
+
_JAVA_COMPARISON_MAP = {
|
|
117
|
+
parse_tree.Comparator.LT: "<",
|
|
118
|
+
parse_tree.Comparator.LE: "<=",
|
|
119
|
+
parse_tree.Comparator.GT: ">",
|
|
120
|
+
parse_tree.Comparator.GE: ">=",
|
|
121
|
+
parse_tree.Comparator.EQ: "==",
|
|
122
|
+
parse_tree.Comparator.NE: "!=",
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
def __init__(
|
|
126
|
+
self,
|
|
127
|
+
type_map: Mapping[
|
|
128
|
+
parse_tree.Node, intermediate_type_inference.TypeAnnotationUnion
|
|
129
|
+
],
|
|
130
|
+
optional_map: Mapping[parse_tree.Node, bool],
|
|
131
|
+
environment: intermediate_type_inference.Environment,
|
|
132
|
+
) -> None:
|
|
133
|
+
"""Initialize with the given values."""
|
|
134
|
+
self.type_map = type_map
|
|
135
|
+
self._optional_map = optional_map
|
|
136
|
+
self._environment = intermediate_type_inference.MutableEnvironment(
|
|
137
|
+
parent=environment
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
# Keep track of optionals in is none checks, here we don't want to call
|
|
141
|
+
# .get()
|
|
142
|
+
self._beneath_none_check = set() # type: Set[parse_tree.Node]
|
|
143
|
+
|
|
144
|
+
# Keep track of method calls. In Java we don't pass around optionals
|
|
145
|
+
# but Null. Optional should solely be used for return types. Thus, we
|
|
146
|
+
# have to unpack the value and fall back if it is not set.
|
|
147
|
+
self._beneath_call = set() # type: Set[parse_tree.Node]
|
|
148
|
+
|
|
149
|
+
# Keep track whenever we define a variable name, so that we can know how to
|
|
150
|
+
# generate the reference in the Java code.
|
|
151
|
+
self._variable_name_set = set() # type: Set[Identifier]
|
|
152
|
+
|
|
153
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
154
|
+
def transform_member(
|
|
155
|
+
self, node: parse_tree.Member
|
|
156
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
157
|
+
instance, error = self.transform(node.instance)
|
|
158
|
+
if error is not None:
|
|
159
|
+
return None, error
|
|
160
|
+
|
|
161
|
+
instance_type = intermediate_type_inference.beneath_optional(
|
|
162
|
+
self.type_map[node.instance]
|
|
163
|
+
)
|
|
164
|
+
member_type = intermediate_type_inference.beneath_optional(self.type_map[node])
|
|
165
|
+
|
|
166
|
+
# noinspection PyUnusedLocal
|
|
167
|
+
member_name: str
|
|
168
|
+
|
|
169
|
+
if isinstance(
|
|
170
|
+
instance_type, intermediate_type_inference.OurTypeAnnotation
|
|
171
|
+
) and isinstance(instance_type.our_type, intermediate.Enumeration):
|
|
172
|
+
# The member denotes a literal of an enumeration.
|
|
173
|
+
member_name = java_naming.enum_literal_name(node.name)
|
|
174
|
+
|
|
175
|
+
elif isinstance(member_type, intermediate_type_inference.MethodTypeAnnotation):
|
|
176
|
+
member_name = java_naming.method_name(node.name)
|
|
177
|
+
|
|
178
|
+
elif isinstance(
|
|
179
|
+
instance_type, intermediate_type_inference.OurTypeAnnotation
|
|
180
|
+
) and isinstance(instance_type.our_type, intermediate.Class):
|
|
181
|
+
if node.name in instance_type.our_type.properties_by_name:
|
|
182
|
+
getter_name = java_naming.getter_name(node.name)
|
|
183
|
+
|
|
184
|
+
if self._optional_map[node]:
|
|
185
|
+
if node in self._beneath_none_check:
|
|
186
|
+
member_name = f"{getter_name}()"
|
|
187
|
+
elif node in self._beneath_call:
|
|
188
|
+
member_name = f"{getter_name}().orElse(null)"
|
|
189
|
+
else:
|
|
190
|
+
member_name = f"{getter_name}().get()"
|
|
191
|
+
else:
|
|
192
|
+
member_name = f"{getter_name}()"
|
|
193
|
+
else:
|
|
194
|
+
return None, Error(
|
|
195
|
+
node.original_node,
|
|
196
|
+
f"The property {node.name!r} has not been defined "
|
|
197
|
+
f"in the class {instance_type.our_type.name!r}",
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
elif isinstance(
|
|
201
|
+
instance_type, intermediate_type_inference.EnumerationAsTypeTypeAnnotation
|
|
202
|
+
):
|
|
203
|
+
if node.name in instance_type.enumeration.literals_by_name:
|
|
204
|
+
member_name = java_naming.enum_literal_name(node.name)
|
|
205
|
+
else:
|
|
206
|
+
return None, Error(
|
|
207
|
+
node.original_node,
|
|
208
|
+
f"The literal {node.name!r} has not been defined "
|
|
209
|
+
f"in the enumeration {instance_type.enumeration.name!r}",
|
|
210
|
+
)
|
|
211
|
+
else:
|
|
212
|
+
return None, Error(
|
|
213
|
+
node.original_node,
|
|
214
|
+
f"We do not know how to generate the member access. The inferred type "
|
|
215
|
+
f"of the instance was {instance_type}, while the member type "
|
|
216
|
+
f"was {member_type}. However, we do not know how to resolve "
|
|
217
|
+
f"the member {node.name!r} in {instance_type}.",
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
return Stripped(f"{instance}.{member_name}"), None
|
|
221
|
+
|
|
222
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
223
|
+
def transform_index(
|
|
224
|
+
self, node: parse_tree.Index
|
|
225
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
226
|
+
collection, error = self.transform(node.collection)
|
|
227
|
+
if error is not None:
|
|
228
|
+
return None, error
|
|
229
|
+
|
|
230
|
+
index, error = self.transform(node.index)
|
|
231
|
+
if error is not None:
|
|
232
|
+
return None, error
|
|
233
|
+
assert index is not None
|
|
234
|
+
|
|
235
|
+
index_as_int = None # type: Optional[int]
|
|
236
|
+
try:
|
|
237
|
+
index_as_int = int(index)
|
|
238
|
+
except ValueError:
|
|
239
|
+
pass
|
|
240
|
+
|
|
241
|
+
if index_as_int is not None and index_as_int < 0:
|
|
242
|
+
# pylint: disable=invalid-unary-operand-type
|
|
243
|
+
index = Stripped(f"{collection}.size() - {abs(index_as_int)}")
|
|
244
|
+
|
|
245
|
+
no_parentheses_types = (
|
|
246
|
+
parse_tree.Member,
|
|
247
|
+
parse_tree.FunctionCall,
|
|
248
|
+
parse_tree.MethodCall,
|
|
249
|
+
parse_tree.Name,
|
|
250
|
+
parse_tree.Constant,
|
|
251
|
+
parse_tree.Index,
|
|
252
|
+
parse_tree.IsIn,
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
if not isinstance(node.collection, no_parentheses_types):
|
|
256
|
+
collection = Stripped(f"({collection})")
|
|
257
|
+
|
|
258
|
+
return Stripped(f"{collection}.get({index})"), None
|
|
259
|
+
|
|
260
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
261
|
+
def transform_comparison(
|
|
262
|
+
self, node: parse_tree.Comparison
|
|
263
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
264
|
+
comparator = Transpiler._JAVA_COMPARISON_MAP[node.op]
|
|
265
|
+
|
|
266
|
+
errors = []
|
|
267
|
+
|
|
268
|
+
left, error = self.transform(node.left)
|
|
269
|
+
if error is not None:
|
|
270
|
+
errors.append(error)
|
|
271
|
+
|
|
272
|
+
right, error = self.transform(node.right)
|
|
273
|
+
if error is not None:
|
|
274
|
+
errors.append(error)
|
|
275
|
+
|
|
276
|
+
if len(errors) > 0:
|
|
277
|
+
return None, Error(
|
|
278
|
+
node.original_node, "Failed to transpile the comparison", errors
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
no_parentheses_types = (
|
|
282
|
+
parse_tree.Member,
|
|
283
|
+
parse_tree.FunctionCall,
|
|
284
|
+
parse_tree.MethodCall,
|
|
285
|
+
parse_tree.Name,
|
|
286
|
+
parse_tree.Constant,
|
|
287
|
+
parse_tree.IsIn,
|
|
288
|
+
parse_tree.Index,
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
if isinstance(node.left, no_parentheses_types) and isinstance(
|
|
292
|
+
node.right, no_parentheses_types
|
|
293
|
+
):
|
|
294
|
+
return Stripped(f"{left} {comparator} {right}"), None
|
|
295
|
+
|
|
296
|
+
return Stripped(f"({left}) {comparator} ({right})"), None
|
|
297
|
+
|
|
298
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
299
|
+
def transform_is_in(
|
|
300
|
+
self, node: parse_tree.IsIn
|
|
301
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
302
|
+
errors = []
|
|
303
|
+
|
|
304
|
+
member, error = self.transform(node.member)
|
|
305
|
+
if error is not None:
|
|
306
|
+
errors.append(error)
|
|
307
|
+
|
|
308
|
+
container, error = self.transform(node.container)
|
|
309
|
+
if error is not None:
|
|
310
|
+
errors.append(error)
|
|
311
|
+
|
|
312
|
+
if len(errors) > 0:
|
|
313
|
+
return None, Error(
|
|
314
|
+
node.original_node,
|
|
315
|
+
"Failed to transpile the membership relation",
|
|
316
|
+
errors,
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
no_parentheses_types = (
|
|
320
|
+
parse_tree.Member,
|
|
321
|
+
parse_tree.FunctionCall,
|
|
322
|
+
parse_tree.MethodCall,
|
|
323
|
+
parse_tree.Name,
|
|
324
|
+
parse_tree.Constant,
|
|
325
|
+
parse_tree.IsIn,
|
|
326
|
+
parse_tree.Index,
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
if not isinstance(node.container, no_parentheses_types):
|
|
330
|
+
container = Stripped(f"({container})")
|
|
331
|
+
|
|
332
|
+
return Stripped(f"{container}.contains({member})"), None
|
|
333
|
+
|
|
334
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
335
|
+
def transform_implication(
|
|
336
|
+
self, node: parse_tree.Implication
|
|
337
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
338
|
+
errors = []
|
|
339
|
+
|
|
340
|
+
antecedent, error = self.transform(node.antecedent)
|
|
341
|
+
if error is not None:
|
|
342
|
+
errors.append(error)
|
|
343
|
+
|
|
344
|
+
consequent, error = self.transform(node.consequent)
|
|
345
|
+
if error is not None:
|
|
346
|
+
errors.append(error)
|
|
347
|
+
|
|
348
|
+
if len(errors) > 0:
|
|
349
|
+
return None, Error(
|
|
350
|
+
node.original_node, "Failed to transpile the implication", errors
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
assert antecedent is not None
|
|
354
|
+
assert consequent is not None
|
|
355
|
+
|
|
356
|
+
no_parentheses_types_in_this_context = (
|
|
357
|
+
parse_tree.Member,
|
|
358
|
+
parse_tree.FunctionCall,
|
|
359
|
+
parse_tree.MethodCall,
|
|
360
|
+
parse_tree.Name,
|
|
361
|
+
parse_tree.IsIn,
|
|
362
|
+
parse_tree.Index,
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
if isinstance(node.antecedent, no_parentheses_types_in_this_context):
|
|
366
|
+
not_antecedent = f"!{antecedent}"
|
|
367
|
+
else:
|
|
368
|
+
# NOTE (empwilli, 2023-12-14):
|
|
369
|
+
# This is a very rudimentary heuristic for breaking the lines, and can be
|
|
370
|
+
# greatly improved by rendering into Java code. However, at this point, we
|
|
371
|
+
# lack time for more sophisticated reformatting approaches.
|
|
372
|
+
if "\n" in antecedent:
|
|
373
|
+
not_antecedent = f"""\
|
|
374
|
+
!(
|
|
375
|
+
{I}{indent_but_first_line(antecedent, I)}
|
|
376
|
+
)"""
|
|
377
|
+
else:
|
|
378
|
+
not_antecedent = f"!({antecedent})"
|
|
379
|
+
|
|
380
|
+
if not isinstance(node.consequent, no_parentheses_types_in_this_context):
|
|
381
|
+
# NOTE (empwilli, 2023-12-14):
|
|
382
|
+
# This is a very rudimentary heuristic for breaking the lines, and can be
|
|
383
|
+
# greatly improved by rendering into Java code. However, at this point, we
|
|
384
|
+
# lack time for more sophisticated reformatting approaches.
|
|
385
|
+
if "\n" in consequent:
|
|
386
|
+
consequent = Stripped(
|
|
387
|
+
f"""\
|
|
388
|
+
(
|
|
389
|
+
{I}{indent_but_first_line(consequent, I)}
|
|
390
|
+
)"""
|
|
391
|
+
)
|
|
392
|
+
else:
|
|
393
|
+
consequent = Stripped(f"({consequent})")
|
|
394
|
+
|
|
395
|
+
return Stripped(f"{not_antecedent}\n|| {consequent}"), None
|
|
396
|
+
|
|
397
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
398
|
+
def transform_method_call(
|
|
399
|
+
self, node: parse_tree.MethodCall
|
|
400
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
401
|
+
errors = [] # type: List[Error]
|
|
402
|
+
|
|
403
|
+
instance, error = self.transform(node.member.instance)
|
|
404
|
+
if error is not None:
|
|
405
|
+
errors.append(error)
|
|
406
|
+
|
|
407
|
+
args = [] # type: List[Stripped]
|
|
408
|
+
for arg_node in node.args:
|
|
409
|
+
arg, error = self.transform(arg_node)
|
|
410
|
+
|
|
411
|
+
if error is not None:
|
|
412
|
+
errors.append(error)
|
|
413
|
+
continue
|
|
414
|
+
|
|
415
|
+
assert arg is not None
|
|
416
|
+
|
|
417
|
+
args.append(arg)
|
|
418
|
+
|
|
419
|
+
if len(errors) > 0:
|
|
420
|
+
return None, Error(
|
|
421
|
+
node.original_node, "Failed to transpile the method call", errors
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
assert instance is not None
|
|
425
|
+
|
|
426
|
+
if not isinstance(node.member.instance, (parse_tree.Name, parse_tree.Member)):
|
|
427
|
+
instance = Stripped(f"({instance})")
|
|
428
|
+
|
|
429
|
+
method_name = java_naming.method_name(node.member.name)
|
|
430
|
+
|
|
431
|
+
joined_args = ", ".join(args)
|
|
432
|
+
|
|
433
|
+
# Apply heuristic for breaking the lines
|
|
434
|
+
if len(joined_args) > 50:
|
|
435
|
+
writer = io.StringIO()
|
|
436
|
+
writer.write(f"{instance}.{method_name}(\n")
|
|
437
|
+
|
|
438
|
+
for i, arg in enumerate(args):
|
|
439
|
+
writer.write(f"{I}{arg}")
|
|
440
|
+
|
|
441
|
+
if i == len(args) - 1:
|
|
442
|
+
writer.write(")")
|
|
443
|
+
else:
|
|
444
|
+
writer.write(",\n")
|
|
445
|
+
|
|
446
|
+
return Stripped(writer.getvalue()), None
|
|
447
|
+
else:
|
|
448
|
+
return Stripped(f"{instance}.{method_name}({joined_args})"), None
|
|
449
|
+
|
|
450
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
451
|
+
def transform_function_call(
|
|
452
|
+
self, node: parse_tree.FunctionCall
|
|
453
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
454
|
+
errors = [] # type: List[Error]
|
|
455
|
+
|
|
456
|
+
# NOTE (empwilli, 2023-12-14):
|
|
457
|
+
# The validity of the arguments is checked in
|
|
458
|
+
# :py:func:`aas_core_codegen.intermediate._translate.translate`, so we do not
|
|
459
|
+
# have to test for argument arity here.
|
|
460
|
+
|
|
461
|
+
func_type = self.type_map[node.name]
|
|
462
|
+
|
|
463
|
+
if not isinstance(
|
|
464
|
+
func_type, intermediate_type_inference.FunctionTypeAnnotationUnionAsTuple
|
|
465
|
+
):
|
|
466
|
+
return None, Error(
|
|
467
|
+
node.name.original_node,
|
|
468
|
+
f"Expected the name to refer to a function, "
|
|
469
|
+
f"but its inferred type was {func_type}",
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
args = [] # type: List[Stripped]
|
|
473
|
+
for arg_node in node.args:
|
|
474
|
+
if isinstance(
|
|
475
|
+
func_type, intermediate_type_inference.VerificationTypeAnnotation
|
|
476
|
+
):
|
|
477
|
+
self._beneath_call.add(arg_node)
|
|
478
|
+
arg, error = self.transform(arg_node)
|
|
479
|
+
self._beneath_call.remove(arg_node)
|
|
480
|
+
else:
|
|
481
|
+
arg, error = self.transform(arg_node)
|
|
482
|
+
|
|
483
|
+
if error is not None:
|
|
484
|
+
errors.append(error)
|
|
485
|
+
continue
|
|
486
|
+
|
|
487
|
+
assert arg is not None
|
|
488
|
+
|
|
489
|
+
args.append(arg)
|
|
490
|
+
|
|
491
|
+
if len(errors) > 0:
|
|
492
|
+
return None, Error(
|
|
493
|
+
node.original_node, "Failed to transpile the function call", errors
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
if isinstance(
|
|
497
|
+
func_type, intermediate_type_inference.VerificationTypeAnnotation
|
|
498
|
+
):
|
|
499
|
+
method_name = java_naming.method_name(func_type.func.name)
|
|
500
|
+
|
|
501
|
+
joined_args = ", ".join(args)
|
|
502
|
+
|
|
503
|
+
# Apply heuristic for breaking the lines
|
|
504
|
+
if len(joined_args) > 50:
|
|
505
|
+
writer = io.StringIO()
|
|
506
|
+
writer.write(f"{method_name}(\n")
|
|
507
|
+
|
|
508
|
+
for i, arg in enumerate(args):
|
|
509
|
+
writer.write(f"{I}{arg}")
|
|
510
|
+
|
|
511
|
+
if i == len(args) - 1:
|
|
512
|
+
writer.write(")")
|
|
513
|
+
else:
|
|
514
|
+
writer.write(",\n")
|
|
515
|
+
|
|
516
|
+
return Stripped(writer.getvalue()), None
|
|
517
|
+
else:
|
|
518
|
+
return Stripped(f"{method_name}({joined_args})"), None
|
|
519
|
+
|
|
520
|
+
elif isinstance(
|
|
521
|
+
func_type, intermediate_type_inference.BuiltinFunctionTypeAnnotation
|
|
522
|
+
):
|
|
523
|
+
if func_type.func.name == "len":
|
|
524
|
+
assert len(args) == 1, (
|
|
525
|
+
f"Expected exactly one argument, but got: {args}; "
|
|
526
|
+
f"this should have been caught before."
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
collection_node = node.args[0]
|
|
530
|
+
if not isinstance(
|
|
531
|
+
collection_node,
|
|
532
|
+
(parse_tree.Name, parse_tree.Member, parse_tree.MethodCall),
|
|
533
|
+
):
|
|
534
|
+
collection = f"({args[0]})"
|
|
535
|
+
else:
|
|
536
|
+
collection = args[0]
|
|
537
|
+
|
|
538
|
+
arg_type = self.type_map[node.args[0]]
|
|
539
|
+
|
|
540
|
+
while isinstance(
|
|
541
|
+
arg_type, intermediate_type_inference.OptionalTypeAnnotation
|
|
542
|
+
):
|
|
543
|
+
arg_type = arg_type.value
|
|
544
|
+
|
|
545
|
+
if (
|
|
546
|
+
isinstance(
|
|
547
|
+
arg_type, intermediate_type_inference.PrimitiveTypeAnnotation
|
|
548
|
+
)
|
|
549
|
+
and arg_type.a_type == intermediate_type_inference.PrimitiveType.STR
|
|
550
|
+
):
|
|
551
|
+
return Stripped(f"{collection}.length()"), None
|
|
552
|
+
|
|
553
|
+
elif (
|
|
554
|
+
isinstance(arg_type, intermediate_type_inference.OurTypeAnnotation)
|
|
555
|
+
and isinstance(arg_type.our_type, intermediate.ConstrainedPrimitive)
|
|
556
|
+
and arg_type.our_type.constrainee == intermediate.PrimitiveType.STR
|
|
557
|
+
):
|
|
558
|
+
return Stripped(f"{collection}.length()"), None
|
|
559
|
+
|
|
560
|
+
elif isinstance(
|
|
561
|
+
arg_type, intermediate_type_inference.ListTypeAnnotation
|
|
562
|
+
):
|
|
563
|
+
return Stripped(f"{collection}.size()"), None
|
|
564
|
+
|
|
565
|
+
else:
|
|
566
|
+
return None, Error(
|
|
567
|
+
node.original_node,
|
|
568
|
+
f"We do not know how to compute the length on type {arg_type}",
|
|
569
|
+
errors,
|
|
570
|
+
)
|
|
571
|
+
else:
|
|
572
|
+
return None, Error(
|
|
573
|
+
node.original_node,
|
|
574
|
+
f"The handling of the built-in function {node.name!r} has not "
|
|
575
|
+
f"been implemented",
|
|
576
|
+
)
|
|
577
|
+
else:
|
|
578
|
+
assert_never(func_type)
|
|
579
|
+
|
|
580
|
+
raise AssertionError("Should not have gotten here")
|
|
581
|
+
|
|
582
|
+
def transform_constant(
|
|
583
|
+
self, node: parse_tree.Constant
|
|
584
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
585
|
+
if isinstance(node.value, bool):
|
|
586
|
+
return Stripped("true" if node.value else "false"), None
|
|
587
|
+
elif isinstance(node.value, (int, float)):
|
|
588
|
+
return Stripped(str(node.value)), None
|
|
589
|
+
elif isinstance(node.value, str):
|
|
590
|
+
return Stripped(java_common.string_literal(node.value)), None
|
|
591
|
+
else:
|
|
592
|
+
assert_never(node.value)
|
|
593
|
+
|
|
594
|
+
raise AssertionError("Should not have gotten here")
|
|
595
|
+
|
|
596
|
+
def transform_is_none(
|
|
597
|
+
self, node: parse_tree.IsNone
|
|
598
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
599
|
+
self._beneath_none_check.add(node.value)
|
|
600
|
+
|
|
601
|
+
value, error = self.transform(node.value)
|
|
602
|
+
|
|
603
|
+
self._beneath_none_check.remove(node.value)
|
|
604
|
+
|
|
605
|
+
if error is not None:
|
|
606
|
+
return None, error
|
|
607
|
+
|
|
608
|
+
no_parentheses_types = (
|
|
609
|
+
parse_tree.Name,
|
|
610
|
+
parse_tree.Member,
|
|
611
|
+
parse_tree.MethodCall,
|
|
612
|
+
parse_tree.FunctionCall,
|
|
613
|
+
parse_tree.IsIn,
|
|
614
|
+
parse_tree.Index,
|
|
615
|
+
)
|
|
616
|
+
|
|
617
|
+
if isinstance(node.value, no_parentheses_types):
|
|
618
|
+
if self._optional_map[node.value]:
|
|
619
|
+
return Stripped(f"!{value}.isPresent()"), None
|
|
620
|
+
else:
|
|
621
|
+
return Stripped(f"{value} == null"), None
|
|
622
|
+
else:
|
|
623
|
+
if self._optional_map[node.value]:
|
|
624
|
+
return Stripped(f"!({value}).isPresent()"), None
|
|
625
|
+
else:
|
|
626
|
+
return Stripped(f"({value}) == null"), None
|
|
627
|
+
|
|
628
|
+
def transform_is_not_none(
|
|
629
|
+
self, node: parse_tree.IsNotNone
|
|
630
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
631
|
+
self._beneath_none_check.add(node.value)
|
|
632
|
+
|
|
633
|
+
value, error = self.transform(node.value)
|
|
634
|
+
|
|
635
|
+
self._beneath_none_check.remove(node.value)
|
|
636
|
+
|
|
637
|
+
if error is not None:
|
|
638
|
+
return None, error
|
|
639
|
+
|
|
640
|
+
no_parentheses_types_in_this_context = (
|
|
641
|
+
parse_tree.Name,
|
|
642
|
+
parse_tree.Member,
|
|
643
|
+
parse_tree.MethodCall,
|
|
644
|
+
parse_tree.FunctionCall,
|
|
645
|
+
parse_tree.IsIn,
|
|
646
|
+
parse_tree.Index,
|
|
647
|
+
)
|
|
648
|
+
|
|
649
|
+
if isinstance(node.value, no_parentheses_types_in_this_context):
|
|
650
|
+
if self._optional_map[node.value]:
|
|
651
|
+
return Stripped(f"{value}.isPresent()"), None
|
|
652
|
+
else:
|
|
653
|
+
return Stripped(f"{value} != null"), None
|
|
654
|
+
else:
|
|
655
|
+
if self._optional_map[node.value]:
|
|
656
|
+
return Stripped(f"({value}).isPresent()"), None
|
|
657
|
+
else:
|
|
658
|
+
return Stripped(f"({value}) != null"), None
|
|
659
|
+
|
|
660
|
+
@abc.abstractmethod
|
|
661
|
+
def transform_name(
|
|
662
|
+
self, node: parse_tree.Name
|
|
663
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
664
|
+
raise NotImplementedError()
|
|
665
|
+
|
|
666
|
+
def transform_not(
|
|
667
|
+
self, node: parse_tree.Not
|
|
668
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
669
|
+
operand, error = self.transform(node.operand)
|
|
670
|
+
if error is not None:
|
|
671
|
+
return None, error
|
|
672
|
+
|
|
673
|
+
no_parentheses_types_in_this_context = (
|
|
674
|
+
parse_tree.Name,
|
|
675
|
+
parse_tree.Member,
|
|
676
|
+
parse_tree.MethodCall,
|
|
677
|
+
parse_tree.FunctionCall,
|
|
678
|
+
parse_tree.IsIn,
|
|
679
|
+
parse_tree.Index,
|
|
680
|
+
)
|
|
681
|
+
if not isinstance(node.operand, no_parentheses_types_in_this_context):
|
|
682
|
+
return Stripped(f"!({operand})"), None
|
|
683
|
+
else:
|
|
684
|
+
return Stripped(f"!{operand}"), None
|
|
685
|
+
|
|
686
|
+
def transform_and(
|
|
687
|
+
self, node: parse_tree.And
|
|
688
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
689
|
+
errors = [] # type: List[Error]
|
|
690
|
+
values = [] # type: List[Stripped]
|
|
691
|
+
|
|
692
|
+
for value_node in node.values:
|
|
693
|
+
value, error = self.transform(value_node)
|
|
694
|
+
if error is not None:
|
|
695
|
+
errors.append(error)
|
|
696
|
+
continue
|
|
697
|
+
|
|
698
|
+
assert value is not None
|
|
699
|
+
|
|
700
|
+
no_parentheses_types_in_this_context = (
|
|
701
|
+
parse_tree.Member,
|
|
702
|
+
parse_tree.MethodCall,
|
|
703
|
+
parse_tree.FunctionCall,
|
|
704
|
+
parse_tree.Comparison,
|
|
705
|
+
parse_tree.Name,
|
|
706
|
+
parse_tree.IsIn,
|
|
707
|
+
parse_tree.Index,
|
|
708
|
+
)
|
|
709
|
+
|
|
710
|
+
if not isinstance(value_node, no_parentheses_types_in_this_context):
|
|
711
|
+
# NOTE (empwilli, 2023-12-14):
|
|
712
|
+
# This is a very rudimentary heuristic for breaking the lines, and can
|
|
713
|
+
# be greatly improved by rendering into Java code. However, at this point,
|
|
714
|
+
# we lack time for more sophisticated reformatting approaches.
|
|
715
|
+
if "\n" in value:
|
|
716
|
+
value = Stripped(
|
|
717
|
+
f"""\
|
|
718
|
+
(
|
|
719
|
+
{I}{indent_but_first_line(value, I)}
|
|
720
|
+
)"""
|
|
721
|
+
)
|
|
722
|
+
else:
|
|
723
|
+
value = Stripped(f"({value})")
|
|
724
|
+
|
|
725
|
+
values.append(value)
|
|
726
|
+
|
|
727
|
+
if len(errors) > 0:
|
|
728
|
+
return None, Error(
|
|
729
|
+
node.original_node, "Failed to transpile the conjunction", errors
|
|
730
|
+
)
|
|
731
|
+
|
|
732
|
+
writer = io.StringIO()
|
|
733
|
+
for i, value in enumerate(values):
|
|
734
|
+
if i == 0:
|
|
735
|
+
writer.write(value)
|
|
736
|
+
else:
|
|
737
|
+
writer.write(f"\n&& {value}")
|
|
738
|
+
|
|
739
|
+
return Stripped(writer.getvalue()), None
|
|
740
|
+
|
|
741
|
+
def transform_or(
|
|
742
|
+
self, node: parse_tree.Or
|
|
743
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
744
|
+
errors = [] # type: List[Error]
|
|
745
|
+
values = [] # type: List[Stripped]
|
|
746
|
+
|
|
747
|
+
for value_node in node.values:
|
|
748
|
+
value, error = self.transform(value_node)
|
|
749
|
+
if error is not None:
|
|
750
|
+
errors.append(error)
|
|
751
|
+
continue
|
|
752
|
+
|
|
753
|
+
assert value is not None
|
|
754
|
+
|
|
755
|
+
no_parentheses_types_in_this_context = (
|
|
756
|
+
parse_tree.Member,
|
|
757
|
+
parse_tree.MethodCall,
|
|
758
|
+
parse_tree.FunctionCall,
|
|
759
|
+
parse_tree.Comparison,
|
|
760
|
+
parse_tree.Name,
|
|
761
|
+
parse_tree.IsIn,
|
|
762
|
+
parse_tree.Index,
|
|
763
|
+
)
|
|
764
|
+
|
|
765
|
+
if not isinstance(value_node, no_parentheses_types_in_this_context):
|
|
766
|
+
# NOTE (empwilli, 2023-12-14):
|
|
767
|
+
# This is a very rudimentary heuristic for breaking the lines, and can
|
|
768
|
+
# be greatly improved by rendering into Java code. However, at this point,
|
|
769
|
+
# we lack time for more sophisticated reformatting approaches.
|
|
770
|
+
if "\n" in value:
|
|
771
|
+
value = Stripped(
|
|
772
|
+
f"""\
|
|
773
|
+
(
|
|
774
|
+
{I}{indent_but_first_line(value, I)}
|
|
775
|
+
)"""
|
|
776
|
+
)
|
|
777
|
+
else:
|
|
778
|
+
value = Stripped(f"({value})")
|
|
779
|
+
|
|
780
|
+
values.append(value)
|
|
781
|
+
|
|
782
|
+
if len(errors) > 0:
|
|
783
|
+
return None, Error(
|
|
784
|
+
node.original_node, "Failed to transpile the conjunction", errors
|
|
785
|
+
)
|
|
786
|
+
|
|
787
|
+
writer = io.StringIO()
|
|
788
|
+
for i, value in enumerate(values):
|
|
789
|
+
if i == 0:
|
|
790
|
+
writer.write(value)
|
|
791
|
+
else:
|
|
792
|
+
writer.write(f"\n|| {value}")
|
|
793
|
+
|
|
794
|
+
return Stripped(writer.getvalue()), None
|
|
795
|
+
|
|
796
|
+
def _transform_add_or_sub(
|
|
797
|
+
self, node: Union[parse_tree.Add, parse_tree.Sub]
|
|
798
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
799
|
+
errors = [] # type: List[Error]
|
|
800
|
+
|
|
801
|
+
left, error = self.transform(node.left)
|
|
802
|
+
if error is not None:
|
|
803
|
+
errors.append(error)
|
|
804
|
+
|
|
805
|
+
right, error = self.transform(node.right)
|
|
806
|
+
if error is not None:
|
|
807
|
+
errors.append(error)
|
|
808
|
+
|
|
809
|
+
if len(errors) > 0:
|
|
810
|
+
operation_name = None # type: Optional[str]
|
|
811
|
+
if isinstance(node, parse_tree.Add):
|
|
812
|
+
operation_name = "the addition"
|
|
813
|
+
elif isinstance(node, parse_tree.Sub):
|
|
814
|
+
operation_name = "the subtraction"
|
|
815
|
+
else:
|
|
816
|
+
assert_never(node)
|
|
817
|
+
|
|
818
|
+
return None, Error(
|
|
819
|
+
node.original_node, f"Failed to transpile {operation_name}", errors
|
|
820
|
+
)
|
|
821
|
+
|
|
822
|
+
no_parentheses_types_in_this_context = (
|
|
823
|
+
parse_tree.Member,
|
|
824
|
+
parse_tree.MethodCall,
|
|
825
|
+
parse_tree.FunctionCall,
|
|
826
|
+
parse_tree.Constant,
|
|
827
|
+
parse_tree.Name,
|
|
828
|
+
parse_tree.IsIn,
|
|
829
|
+
parse_tree.Index,
|
|
830
|
+
)
|
|
831
|
+
|
|
832
|
+
if not isinstance(node.left, no_parentheses_types_in_this_context):
|
|
833
|
+
left = Stripped(f"({left})")
|
|
834
|
+
|
|
835
|
+
if not isinstance(node.right, no_parentheses_types_in_this_context):
|
|
836
|
+
right = Stripped(f"({right})")
|
|
837
|
+
|
|
838
|
+
if isinstance(node, parse_tree.Add):
|
|
839
|
+
return Stripped(f"{left} + {right}"), None
|
|
840
|
+
elif isinstance(node, parse_tree.Sub):
|
|
841
|
+
return Stripped(f"{left} - {right}"), None
|
|
842
|
+
else:
|
|
843
|
+
assert_never(node)
|
|
844
|
+
|
|
845
|
+
raise AssertionError("Unexpected execution path")
|
|
846
|
+
|
|
847
|
+
def transform_add(
|
|
848
|
+
self, node: parse_tree.Add
|
|
849
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
850
|
+
return self._transform_add_or_sub(node)
|
|
851
|
+
|
|
852
|
+
def transform_sub(
|
|
853
|
+
self, node: parse_tree.Sub
|
|
854
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
855
|
+
return self._transform_add_or_sub(node)
|
|
856
|
+
|
|
857
|
+
def transform_joined_str(
|
|
858
|
+
self, node: parse_tree.JoinedStr
|
|
859
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
860
|
+
parts = [] # type: List[str]
|
|
861
|
+
for value in node.values:
|
|
862
|
+
if isinstance(value, str):
|
|
863
|
+
string_literal = java_common.string_literal(
|
|
864
|
+
value.replace("{", "{{").replace("}", "}}")
|
|
865
|
+
)
|
|
866
|
+
|
|
867
|
+
assert string_literal.startswith('"') and string_literal.endswith('"')
|
|
868
|
+
|
|
869
|
+
parts.append(string_literal)
|
|
870
|
+
|
|
871
|
+
elif isinstance(value, parse_tree.FormattedValue):
|
|
872
|
+
code, error = self.transform(value.value)
|
|
873
|
+
if error is not None:
|
|
874
|
+
return None, error
|
|
875
|
+
|
|
876
|
+
assert code is not None
|
|
877
|
+
|
|
878
|
+
assert (
|
|
879
|
+
"\n" not in code
|
|
880
|
+
), f"New-lines are not expected in formatted values, but got: {code}"
|
|
881
|
+
|
|
882
|
+
no_parentheses = (
|
|
883
|
+
parse_tree.Member,
|
|
884
|
+
parse_tree.FunctionCall,
|
|
885
|
+
parse_tree.MethodCall,
|
|
886
|
+
parse_tree.Name,
|
|
887
|
+
parse_tree.Constant,
|
|
888
|
+
parse_tree.Index,
|
|
889
|
+
parse_tree.IsIn,
|
|
890
|
+
)
|
|
891
|
+
|
|
892
|
+
if isinstance(code, no_parentheses):
|
|
893
|
+
parts.append(f"{code}")
|
|
894
|
+
else:
|
|
895
|
+
parts.append(f"({code})")
|
|
896
|
+
else:
|
|
897
|
+
assert_never(value)
|
|
898
|
+
|
|
899
|
+
return Stripped(" + ".join(parts)), None
|
|
900
|
+
|
|
901
|
+
def _transform_any_or_all(
|
|
902
|
+
self, node: Union[parse_tree.Any, parse_tree.All]
|
|
903
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
904
|
+
errors = [] # type: List[Error]
|
|
905
|
+
|
|
906
|
+
iteration = None # type: Optional[Stripped]
|
|
907
|
+
start = None # type: Optional[Stripped]
|
|
908
|
+
end = None # type: Optional[Stripped]
|
|
909
|
+
|
|
910
|
+
if isinstance(node.generator, parse_tree.ForEach):
|
|
911
|
+
iteration, error = self.transform(node.generator.iteration)
|
|
912
|
+
if error is not None:
|
|
913
|
+
errors.append(error)
|
|
914
|
+
elif isinstance(node.generator, parse_tree.ForRange):
|
|
915
|
+
start, error = self.transform(node.generator.start)
|
|
916
|
+
if error is not None:
|
|
917
|
+
errors.append(error)
|
|
918
|
+
|
|
919
|
+
end, error = self.transform(node.generator.end)
|
|
920
|
+
if error is not None:
|
|
921
|
+
errors.append(error)
|
|
922
|
+
|
|
923
|
+
else:
|
|
924
|
+
assert_never(node.generator)
|
|
925
|
+
|
|
926
|
+
if len(errors) > 0:
|
|
927
|
+
return None, Error(
|
|
928
|
+
node.original_node,
|
|
929
|
+
"Failed to transpile the generator expression",
|
|
930
|
+
errors,
|
|
931
|
+
)
|
|
932
|
+
|
|
933
|
+
assert (iteration is not None) ^ (start is not None and end is not None)
|
|
934
|
+
|
|
935
|
+
variable_name = node.generator.variable.identifier
|
|
936
|
+
variable_type = self.type_map[node.generator.variable]
|
|
937
|
+
|
|
938
|
+
try:
|
|
939
|
+
self._environment.set(
|
|
940
|
+
identifier=variable_name, type_annotation=variable_type
|
|
941
|
+
)
|
|
942
|
+
self._variable_name_set.add(variable_name)
|
|
943
|
+
|
|
944
|
+
condition, error = self.transform(node.condition)
|
|
945
|
+
if error is not None:
|
|
946
|
+
errors.append(error)
|
|
947
|
+
|
|
948
|
+
variable, error = self.transform(node.generator.variable)
|
|
949
|
+
if error is not None:
|
|
950
|
+
errors.append(error)
|
|
951
|
+
|
|
952
|
+
finally:
|
|
953
|
+
self._variable_name_set.remove(variable_name)
|
|
954
|
+
self._environment.remove(variable_name)
|
|
955
|
+
|
|
956
|
+
if len(errors) > 0:
|
|
957
|
+
return None, Error(
|
|
958
|
+
node.original_node,
|
|
959
|
+
"Failed to transpile the generator expression",
|
|
960
|
+
errors,
|
|
961
|
+
)
|
|
962
|
+
|
|
963
|
+
assert variable is not None
|
|
964
|
+
assert condition is not None
|
|
965
|
+
|
|
966
|
+
qualifier_function = None # type: Optional[str]
|
|
967
|
+
if isinstance(node, parse_tree.Any):
|
|
968
|
+
qualifier_function = "anyMatch"
|
|
969
|
+
elif isinstance(node, parse_tree.All):
|
|
970
|
+
qualifier_function = "allMatch"
|
|
971
|
+
else:
|
|
972
|
+
assert_never(node)
|
|
973
|
+
|
|
974
|
+
source = None # type: Optional[Stripped]
|
|
975
|
+
if isinstance(node.generator, parse_tree.ForEach):
|
|
976
|
+
no_parentheses_types_in_this_context = (
|
|
977
|
+
parse_tree.Member,
|
|
978
|
+
parse_tree.MethodCall,
|
|
979
|
+
parse_tree.FunctionCall,
|
|
980
|
+
parse_tree.Name,
|
|
981
|
+
parse_tree.IsIn,
|
|
982
|
+
parse_tree.Index,
|
|
983
|
+
)
|
|
984
|
+
|
|
985
|
+
if not isinstance(
|
|
986
|
+
node.generator.iteration, no_parentheses_types_in_this_context
|
|
987
|
+
):
|
|
988
|
+
source = Stripped(f"({iteration}.stream())")
|
|
989
|
+
else:
|
|
990
|
+
source = Stripped(f"{iteration}.stream()")
|
|
991
|
+
elif isinstance(node.generator, parse_tree.ForRange):
|
|
992
|
+
assert start is not None
|
|
993
|
+
assert end is not None
|
|
994
|
+
|
|
995
|
+
source = Stripped(
|
|
996
|
+
f"""\
|
|
997
|
+
IntStream.range(
|
|
998
|
+
{I}{indent_but_first_line(start, I)},
|
|
999
|
+
{I}{indent_but_first_line(end, I)}
|
|
1000
|
+
)"""
|
|
1001
|
+
)
|
|
1002
|
+
|
|
1003
|
+
else:
|
|
1004
|
+
assert_never(node.generator)
|
|
1005
|
+
|
|
1006
|
+
return (
|
|
1007
|
+
Stripped(
|
|
1008
|
+
f"""\
|
|
1009
|
+
{source}.{qualifier_function}(
|
|
1010
|
+
{I}{variable} -> {indent_but_first_line(condition, II)})"""
|
|
1011
|
+
),
|
|
1012
|
+
None,
|
|
1013
|
+
)
|
|
1014
|
+
|
|
1015
|
+
def transform_any(
|
|
1016
|
+
self, node: parse_tree.Any
|
|
1017
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
1018
|
+
|
|
1019
|
+
return self._transform_any_or_all(node)
|
|
1020
|
+
|
|
1021
|
+
def transform_all(
|
|
1022
|
+
self, node: parse_tree.All
|
|
1023
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
1024
|
+
return self._transform_any_or_all(node)
|
|
1025
|
+
|
|
1026
|
+
def transform_assignment(
|
|
1027
|
+
self, node: parse_tree.Assignment
|
|
1028
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
1029
|
+
errors = [] # type: List[Error]
|
|
1030
|
+
|
|
1031
|
+
value, error = self.transform(node.value)
|
|
1032
|
+
if error is not None:
|
|
1033
|
+
errors.append(error)
|
|
1034
|
+
|
|
1035
|
+
target = None # type: Optional[Stripped]
|
|
1036
|
+
if isinstance(node.target, parse_tree.Name):
|
|
1037
|
+
type_anno = self._environment.find(identifier=node.target.identifier)
|
|
1038
|
+
if type_anno is None:
|
|
1039
|
+
# NOTE (empwilli, 2023-12-14):
|
|
1040
|
+
# This is a variable definition as we did not specify the identifier
|
|
1041
|
+
# in the environment.
|
|
1042
|
+
|
|
1043
|
+
type_anno = self.type_map[node.value]
|
|
1044
|
+
self._variable_name_set.add(node.target.identifier)
|
|
1045
|
+
self._environment.set(
|
|
1046
|
+
identifier=node.target.identifier, type_annotation=type_anno
|
|
1047
|
+
)
|
|
1048
|
+
|
|
1049
|
+
target, error = self.transform_name(node=node.target)
|
|
1050
|
+
if error is not None:
|
|
1051
|
+
errors.append(error)
|
|
1052
|
+
else:
|
|
1053
|
+
target = Stripped(f"{type_anno} {target}")
|
|
1054
|
+
else:
|
|
1055
|
+
target, error = self.transform(node=node.target)
|
|
1056
|
+
if error is not None:
|
|
1057
|
+
errors.append(error)
|
|
1058
|
+
|
|
1059
|
+
if len(errors) > 0:
|
|
1060
|
+
return None, Error(
|
|
1061
|
+
node.original_node, "Failed to transpile the assignment", errors
|
|
1062
|
+
)
|
|
1063
|
+
|
|
1064
|
+
assert target is not None
|
|
1065
|
+
assert value is not None
|
|
1066
|
+
|
|
1067
|
+
# NOTE (empwilli, 2023-12-14):
|
|
1068
|
+
# This is a rudimentary heuristic for basic line breaks, but works well in
|
|
1069
|
+
# practice.
|
|
1070
|
+
if "\n" not in value and len(value) > 50:
|
|
1071
|
+
return (
|
|
1072
|
+
Stripped(
|
|
1073
|
+
f"""\
|
|
1074
|
+
{target} = (
|
|
1075
|
+
{I}{indent_but_first_line(value, I)});"""
|
|
1076
|
+
),
|
|
1077
|
+
None,
|
|
1078
|
+
)
|
|
1079
|
+
|
|
1080
|
+
return Stripped(f"{target} = {value};"), None
|
|
1081
|
+
|
|
1082
|
+
def transform_return(
|
|
1083
|
+
self, node: parse_tree.Return
|
|
1084
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
1085
|
+
if node.value is None:
|
|
1086
|
+
return Stripped("return;"), None
|
|
1087
|
+
|
|
1088
|
+
value, error = self.transform(node.value)
|
|
1089
|
+
if error is not None:
|
|
1090
|
+
return None, error
|
|
1091
|
+
|
|
1092
|
+
assert value is not None
|
|
1093
|
+
|
|
1094
|
+
# NOTE (empwilli, 2023-12-14):
|
|
1095
|
+
# This is a rudimentary heuristic for basic line breaks, but works well in
|
|
1096
|
+
# practice.
|
|
1097
|
+
if "\n" not in value and len(value) > 50:
|
|
1098
|
+
return (
|
|
1099
|
+
Stripped(
|
|
1100
|
+
f"""\
|
|
1101
|
+
return (
|
|
1102
|
+
{I}{indent_but_first_line(value, I)});"""
|
|
1103
|
+
),
|
|
1104
|
+
None,
|
|
1105
|
+
)
|
|
1106
|
+
|
|
1107
|
+
return Stripped(f"return {value};"), None
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
# noinspection PyProtectedMember,PyProtectedMember
|
|
1111
|
+
assert all(op in Transpiler._JAVA_COMPARISON_MAP for op in parse_tree.Comparator)
|