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,1536 @@
|
|
|
1
|
+
"""Generate the invariant verifiers from the intermediate representation."""
|
|
2
|
+
import io
|
|
3
|
+
import textwrap
|
|
4
|
+
from typing import (
|
|
5
|
+
List,
|
|
6
|
+
Mapping,
|
|
7
|
+
Optional,
|
|
8
|
+
Sequence,
|
|
9
|
+
Set,
|
|
10
|
+
Tuple,
|
|
11
|
+
Union,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from icontract import ensure, require
|
|
15
|
+
|
|
16
|
+
from aas_core_codegen import (
|
|
17
|
+
intermediate,
|
|
18
|
+
naming,
|
|
19
|
+
specific_implementations,
|
|
20
|
+
)
|
|
21
|
+
from aas_core_codegen.common import (
|
|
22
|
+
assert_never,
|
|
23
|
+
Error,
|
|
24
|
+
indent_but_first_line,
|
|
25
|
+
Identifier,
|
|
26
|
+
Stripped,
|
|
27
|
+
wrap_text_into_lines,
|
|
28
|
+
)
|
|
29
|
+
from aas_core_codegen.intermediate import (
|
|
30
|
+
type_inference as intermediate_type_inference,
|
|
31
|
+
)
|
|
32
|
+
from aas_core_codegen.java import (
|
|
33
|
+
common as java_common,
|
|
34
|
+
description as java_description,
|
|
35
|
+
optional as java_optional,
|
|
36
|
+
naming as java_naming,
|
|
37
|
+
transpilation as java_transpilation,
|
|
38
|
+
)
|
|
39
|
+
from aas_core_codegen.java.common import (
|
|
40
|
+
INDENT as I,
|
|
41
|
+
INDENT2 as II,
|
|
42
|
+
INDENT3 as III,
|
|
43
|
+
INDENT4 as IIII,
|
|
44
|
+
INDENT5 as IIIII,
|
|
45
|
+
INDENT6 as IIIIII,
|
|
46
|
+
)
|
|
47
|
+
from aas_core_codegen.parse import tree as parse_tree, retree as parse_retree
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# region Verify
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def verify(
|
|
54
|
+
spec_impls: specific_implementations.SpecificImplementations,
|
|
55
|
+
verification_functions: Sequence[intermediate.Verification],
|
|
56
|
+
) -> Optional[List[str]]:
|
|
57
|
+
"""Verify all the implementation snippets related to verification."""
|
|
58
|
+
errors = [] # type: List[str]
|
|
59
|
+
|
|
60
|
+
expected_keys = [] # type: List[specific_implementations.ImplementationKey]
|
|
61
|
+
|
|
62
|
+
for func in verification_functions:
|
|
63
|
+
if isinstance(func, intermediate.ImplementationSpecificVerification):
|
|
64
|
+
expected_keys.append(
|
|
65
|
+
specific_implementations.ImplementationKey(
|
|
66
|
+
f"Verification/{func.name}.java"
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
for key in expected_keys:
|
|
71
|
+
if key not in spec_impls:
|
|
72
|
+
errors.append(f"The implementation snippet is missing for: {key}")
|
|
73
|
+
|
|
74
|
+
if len(errors) == 0:
|
|
75
|
+
return None
|
|
76
|
+
|
|
77
|
+
return errors
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# endregion
|
|
81
|
+
|
|
82
|
+
# region Generate
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class RegexRenderer(parse_retree.Renderer):
|
|
86
|
+
"""
|
|
87
|
+
Render the regular expressions for Java.
|
|
88
|
+
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
def char_to_str_and_escape_or_encode_if_necessary(
|
|
92
|
+
self, node: parse_retree.Char, escaping: Mapping[str, str]
|
|
93
|
+
) -> List[Union[str, parse_tree.FormattedValue]]:
|
|
94
|
+
if not node.explicitly_encoded:
|
|
95
|
+
escaped = escaping.get(node.character, None)
|
|
96
|
+
if escaped is not None:
|
|
97
|
+
result: List[Union[str, parse_tree.FormattedValue]] = [escaped]
|
|
98
|
+
else:
|
|
99
|
+
result = [node.character]
|
|
100
|
+
|
|
101
|
+
return result
|
|
102
|
+
|
|
103
|
+
else:
|
|
104
|
+
code = ord(node.character)
|
|
105
|
+
return [f"\\x{{{code:02x}}}"]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
_REGEX_RENDERER = RegexRenderer()
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class _PatternVerificationTranspiler(
|
|
112
|
+
parse_tree.RestrictedTransformer[Tuple[Optional[Stripped], Optional[Error]]]
|
|
113
|
+
):
|
|
114
|
+
"""Transpile a statement of a pattern verification into Java."""
|
|
115
|
+
|
|
116
|
+
def __init__(self, defined_variables: Set[Identifier]) -> None:
|
|
117
|
+
"""
|
|
118
|
+
Initialize with the given values.
|
|
119
|
+
|
|
120
|
+
The ``defined_variables`` are shared between different statement
|
|
121
|
+
transpilations. It is also mutated when assignments are transpiled. We need to
|
|
122
|
+
keep track of variables so that we know when we have to define them, and when
|
|
123
|
+
we can simply assign them a value, if they have been already defined.
|
|
124
|
+
"""
|
|
125
|
+
self.defined_variables = defined_variables
|
|
126
|
+
|
|
127
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
128
|
+
def _transform_joined_str_values(
|
|
129
|
+
self, values: Sequence[Union[str, parse_tree.FormattedValue]]
|
|
130
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
131
|
+
"""Transform the values of a joined string to a Java string literal."""
|
|
132
|
+
if all(isinstance(value, str) for value in values):
|
|
133
|
+
return (
|
|
134
|
+
Stripped(java_common.string_literal("".join(values))), # type: ignore
|
|
135
|
+
None,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
parts = [] # type: List[str]
|
|
139
|
+
for value in values:
|
|
140
|
+
if isinstance(value, str):
|
|
141
|
+
string_literal = java_common.string_literal(value)
|
|
142
|
+
|
|
143
|
+
assert string_literal.startswith('"') and string_literal.endswith('"')
|
|
144
|
+
|
|
145
|
+
parts.append(string_literal)
|
|
146
|
+
|
|
147
|
+
elif isinstance(value, parse_tree.FormattedValue):
|
|
148
|
+
code, error = self.transform(value.value)
|
|
149
|
+
if error is not None:
|
|
150
|
+
return None, error
|
|
151
|
+
assert code is not None
|
|
152
|
+
|
|
153
|
+
assert (
|
|
154
|
+
"\n" not in code
|
|
155
|
+
), f"New-lines are not expected in formatted values, but got: {code}"
|
|
156
|
+
|
|
157
|
+
parts.append(f"{code}")
|
|
158
|
+
else:
|
|
159
|
+
assert_never(value)
|
|
160
|
+
|
|
161
|
+
return Stripped(" + ".join(parts)), None
|
|
162
|
+
|
|
163
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
164
|
+
def transform_constant(
|
|
165
|
+
self, node: parse_tree.Constant
|
|
166
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
167
|
+
if isinstance(node.value, str):
|
|
168
|
+
regex, parse_error = parse_retree.parse(values=[node.value])
|
|
169
|
+
if parse_error is not None:
|
|
170
|
+
regex_line, pointer_line = parse_retree.render_pointer(
|
|
171
|
+
parse_error.cursor
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
None,
|
|
176
|
+
Error(
|
|
177
|
+
node.original_node,
|
|
178
|
+
f"The string constant could not be parsed "
|
|
179
|
+
f"as a regular expression: \n"
|
|
180
|
+
f"{parse_error.message}\n"
|
|
181
|
+
f"{regex_line}\n"
|
|
182
|
+
f"{pointer_line}",
|
|
183
|
+
),
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
assert regex is not None
|
|
187
|
+
|
|
188
|
+
return self._transform_joined_str_values(
|
|
189
|
+
values=parse_retree.render(regex=regex, renderer=_REGEX_RENDERER)
|
|
190
|
+
)
|
|
191
|
+
else:
|
|
192
|
+
raise AssertionError(f"Unexpected {node=}")
|
|
193
|
+
|
|
194
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
195
|
+
def transform_name(
|
|
196
|
+
self, node: parse_tree.Name
|
|
197
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
198
|
+
return Stripped(java_naming.variable_name(node.identifier)), None
|
|
199
|
+
|
|
200
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
201
|
+
def transform_joined_str(
|
|
202
|
+
self, node: parse_tree.JoinedStr
|
|
203
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
204
|
+
regex, parse_error = parse_retree.parse(values=node.values)
|
|
205
|
+
if parse_error is not None:
|
|
206
|
+
regex_line, pointer_line = parse_retree.render_pointer(parse_error.cursor)
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
None,
|
|
210
|
+
Error(
|
|
211
|
+
node.original_node,
|
|
212
|
+
f"The joined string could not be parsed "
|
|
213
|
+
f"as a regular expression: \n"
|
|
214
|
+
f"{parse_error.message}\n"
|
|
215
|
+
f"{regex_line}\n"
|
|
216
|
+
f"{pointer_line}",
|
|
217
|
+
),
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
assert regex is not None
|
|
221
|
+
|
|
222
|
+
return self._transform_joined_str_values(
|
|
223
|
+
values=parse_retree.render(regex=regex, renderer=_REGEX_RENDERER)
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
def transform_assignment(
|
|
227
|
+
self, node: parse_tree.Assignment
|
|
228
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
229
|
+
assert isinstance(node.target, parse_tree.Name)
|
|
230
|
+
variable = java_naming.variable_name(node.target.identifier)
|
|
231
|
+
code, error = self.transform(node.value)
|
|
232
|
+
if error is not None:
|
|
233
|
+
return None, error
|
|
234
|
+
assert code is not None
|
|
235
|
+
|
|
236
|
+
if node.target.identifier in self.defined_variables:
|
|
237
|
+
return Stripped(f"{variable} = {code};"), None
|
|
238
|
+
|
|
239
|
+
else:
|
|
240
|
+
self.defined_variables.add(node.target.identifier)
|
|
241
|
+
|
|
242
|
+
# NOTE (mristin):
|
|
243
|
+
# We assume here that we checked in the parse stage that all the variables
|
|
244
|
+
# used in a pattern verification function are actually typed as strings.
|
|
245
|
+
|
|
246
|
+
return Stripped(f"String {variable} = {code};"), None
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
250
|
+
def _transpile_pattern_verification(
|
|
251
|
+
verification: intermediate.PatternVerification,
|
|
252
|
+
package: java_common.PackageIdentifier,
|
|
253
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
254
|
+
"""Generate the verification function that checks the regular expressions."""
|
|
255
|
+
# We assume that we performed all the checks at the intermediate stage.
|
|
256
|
+
|
|
257
|
+
construct_name = java_naming.private_method_name(
|
|
258
|
+
Identifier(f"construct_{verification.name}")
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
blocks = [] # type: List[Stripped]
|
|
262
|
+
|
|
263
|
+
# region Construct block
|
|
264
|
+
|
|
265
|
+
writer = io.StringIO()
|
|
266
|
+
writer.write(
|
|
267
|
+
f"""\
|
|
268
|
+
private static Pattern {construct_name}() {{
|
|
269
|
+
"""
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
defined_variables = set() # type: Set[Identifier]
|
|
273
|
+
transpiler = _PatternVerificationTranspiler(defined_variables=defined_variables)
|
|
274
|
+
|
|
275
|
+
for i, stmt in enumerate(verification.parsed.body):
|
|
276
|
+
if i == len(verification.parsed.body) - 1:
|
|
277
|
+
break
|
|
278
|
+
|
|
279
|
+
code, error = transpiler.transform(stmt)
|
|
280
|
+
if error is not None:
|
|
281
|
+
return None, error
|
|
282
|
+
assert code is not None
|
|
283
|
+
|
|
284
|
+
writer.write(textwrap.indent(code, I))
|
|
285
|
+
writer.write("\n")
|
|
286
|
+
|
|
287
|
+
if len(verification.parsed.body) >= 2:
|
|
288
|
+
writer.write("\n")
|
|
289
|
+
|
|
290
|
+
pattern_expr, error = transpiler.transform(verification.pattern_expr)
|
|
291
|
+
if error is not None:
|
|
292
|
+
return None, error
|
|
293
|
+
assert pattern_expr is not None
|
|
294
|
+
|
|
295
|
+
# A pragmatic heuristics for breaking lines
|
|
296
|
+
if len(pattern_expr) < 50:
|
|
297
|
+
writer.write(textwrap.indent(f"return Pattern.compile({pattern_expr});\n", I))
|
|
298
|
+
else:
|
|
299
|
+
writer.write(
|
|
300
|
+
textwrap.indent(f"return Pattern.compile(\n{I}{pattern_expr});\n", I)
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
writer.write("}")
|
|
304
|
+
|
|
305
|
+
blocks.append(Stripped(writer.getvalue()))
|
|
306
|
+
|
|
307
|
+
# endregion
|
|
308
|
+
|
|
309
|
+
# region Initialize the regex
|
|
310
|
+
|
|
311
|
+
regex_name = java_naming.property_name(Identifier(f"regex_{verification.name}"))
|
|
312
|
+
|
|
313
|
+
blocks.append(
|
|
314
|
+
Stripped(f"private static final Pattern {regex_name} = {construct_name}();")
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
assert len(verification.arguments) == 1
|
|
318
|
+
assert isinstance(
|
|
319
|
+
verification.arguments[0].type_annotation, intermediate.PrimitiveTypeAnnotation
|
|
320
|
+
)
|
|
321
|
+
# noinspection PyUnresolvedReferences
|
|
322
|
+
assert (
|
|
323
|
+
verification.arguments[0].type_annotation.a_type
|
|
324
|
+
== intermediate.PrimitiveType.STR
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
arg_name = java_naming.argument_name(verification.arguments[0].name)
|
|
328
|
+
|
|
329
|
+
writer = io.StringIO()
|
|
330
|
+
if verification.description is not None:
|
|
331
|
+
comment, comment_errors = java_description.generate_comment_for_signature(
|
|
332
|
+
verification.description,
|
|
333
|
+
context=java_description.Context(package=package, cls_or_enum=None),
|
|
334
|
+
)
|
|
335
|
+
if comment_errors is not None:
|
|
336
|
+
return None, Error(
|
|
337
|
+
verification.description.parsed.node,
|
|
338
|
+
"Failed to generate the documentation comment",
|
|
339
|
+
comment_errors,
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
assert comment is not None
|
|
343
|
+
|
|
344
|
+
writer.write(comment)
|
|
345
|
+
writer.write("\n")
|
|
346
|
+
|
|
347
|
+
method_name = java_naming.method_name(verification.name)
|
|
348
|
+
|
|
349
|
+
writer.write(
|
|
350
|
+
f"""\
|
|
351
|
+
public static Boolean {method_name}(String {arg_name}) {{
|
|
352
|
+
{I}return {regex_name}.matcher({arg_name}).matches();
|
|
353
|
+
}}"""
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
blocks.append(Stripped(writer.getvalue()))
|
|
357
|
+
|
|
358
|
+
# endregion
|
|
359
|
+
|
|
360
|
+
writer = io.StringIO()
|
|
361
|
+
for i, block in enumerate(blocks):
|
|
362
|
+
if i > 0:
|
|
363
|
+
writer.write("\n\n")
|
|
364
|
+
|
|
365
|
+
writer.write(block)
|
|
366
|
+
|
|
367
|
+
return Stripped(writer.getvalue()), None
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
class _TranspilableVerificationTranspiler(java_transpilation.Transpiler):
|
|
371
|
+
"""Transpile the body of a :class:`.TranspilableVerification`."""
|
|
372
|
+
|
|
373
|
+
# fmt: off
|
|
374
|
+
@require(
|
|
375
|
+
lambda environment, verification:
|
|
376
|
+
all(
|
|
377
|
+
environment.find(arg.name) is not None
|
|
378
|
+
for arg in verification.arguments
|
|
379
|
+
),
|
|
380
|
+
"All arguments defined in the environment"
|
|
381
|
+
)
|
|
382
|
+
# fmt: on
|
|
383
|
+
def __init__(
|
|
384
|
+
self,
|
|
385
|
+
type_map: Mapping[
|
|
386
|
+
parse_tree.Node, intermediate_type_inference.TypeAnnotationUnion
|
|
387
|
+
],
|
|
388
|
+
is_optional_map: Mapping[
|
|
389
|
+
parse_tree.Node,
|
|
390
|
+
bool,
|
|
391
|
+
],
|
|
392
|
+
environment: intermediate_type_inference.Environment,
|
|
393
|
+
symbol_table: intermediate.SymbolTable,
|
|
394
|
+
verification: intermediate.TranspilableVerification,
|
|
395
|
+
) -> None:
|
|
396
|
+
"""Initialize with the given values."""
|
|
397
|
+
java_transpilation.Transpiler.__init__(
|
|
398
|
+
self,
|
|
399
|
+
type_map=type_map,
|
|
400
|
+
optional_map=is_optional_map,
|
|
401
|
+
environment=environment,
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
self._symbol_table = symbol_table
|
|
405
|
+
|
|
406
|
+
self._argument_name_set = frozenset(arg.name for arg in verification.arguments)
|
|
407
|
+
|
|
408
|
+
def transform_name(
|
|
409
|
+
self, node: parse_tree.Name
|
|
410
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
411
|
+
if node.identifier in self._variable_name_set:
|
|
412
|
+
return Stripped(java_naming.variable_name(node.identifier)), None
|
|
413
|
+
|
|
414
|
+
if node.identifier in self._argument_name_set:
|
|
415
|
+
return Stripped(java_naming.variable_name(node.identifier)), None
|
|
416
|
+
|
|
417
|
+
if node.identifier in self._symbol_table.constants_by_name:
|
|
418
|
+
constant_as_prop = java_naming.property_name(node.identifier)
|
|
419
|
+
return Stripped(f"Constants.{constant_as_prop}"), None
|
|
420
|
+
|
|
421
|
+
if node.identifier in self._symbol_table.verification_functions_by_name:
|
|
422
|
+
return Stripped(java_naming.method_name(node.identifier)), None
|
|
423
|
+
|
|
424
|
+
our_type = self._symbol_table.find_our_type(name=node.identifier)
|
|
425
|
+
if isinstance(our_type, intermediate.Enumeration):
|
|
426
|
+
return Stripped(java_naming.enum_name(node.identifier)), None
|
|
427
|
+
|
|
428
|
+
return None, Error(
|
|
429
|
+
node.original_node,
|
|
430
|
+
f"We can not determine how to transpile the name {node.identifier!r} "
|
|
431
|
+
f"to Java. We could not find it neither in the constants, nor in "
|
|
432
|
+
f"verification functions, nor as an enumeration. "
|
|
433
|
+
f"If you expect this name to be transpilable, please contact "
|
|
434
|
+
f"the developers.",
|
|
435
|
+
)
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
def _transpile_transpilable_verification(
|
|
439
|
+
verification: intermediate.TranspilableVerification,
|
|
440
|
+
symbol_table: intermediate.SymbolTable,
|
|
441
|
+
environment: intermediate_type_inference.Environment,
|
|
442
|
+
package: java_common.PackageIdentifier,
|
|
443
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
444
|
+
"""
|
|
445
|
+
Transpile a verification function.
|
|
446
|
+
|
|
447
|
+
The ``package`` defines the root Java package.
|
|
448
|
+
"""
|
|
449
|
+
# fmt: off
|
|
450
|
+
type_inference, error = (
|
|
451
|
+
intermediate_type_inference.infer_for_verification(
|
|
452
|
+
verification=verification,
|
|
453
|
+
base_environment=environment
|
|
454
|
+
)
|
|
455
|
+
)
|
|
456
|
+
# fmt: on
|
|
457
|
+
|
|
458
|
+
if error is not None:
|
|
459
|
+
return None, error
|
|
460
|
+
|
|
461
|
+
assert type_inference is not None
|
|
462
|
+
|
|
463
|
+
optional_inferrer = java_optional.OptionalInferrer(
|
|
464
|
+
environment=type_inference.environment_with_args,
|
|
465
|
+
type_map=type_inference.type_map,
|
|
466
|
+
)
|
|
467
|
+
|
|
468
|
+
for node in verification.parsed.body:
|
|
469
|
+
_ = optional_inferrer.transform(node)
|
|
470
|
+
|
|
471
|
+
if len(optional_inferrer.errors):
|
|
472
|
+
return None, Error(
|
|
473
|
+
verification.parsed.node,
|
|
474
|
+
f"Failed to infer whether types are "
|
|
475
|
+
f"optional in verification function {verification.name!r}",
|
|
476
|
+
optional_inferrer.errors,
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
transpiler = _TranspilableVerificationTranspiler(
|
|
480
|
+
type_map=type_inference.type_map,
|
|
481
|
+
is_optional_map=optional_inferrer.is_optional_map,
|
|
482
|
+
environment=type_inference.environment_with_args,
|
|
483
|
+
symbol_table=symbol_table,
|
|
484
|
+
verification=verification,
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
body = [] # type: List[Stripped]
|
|
488
|
+
for node in verification.parsed.body:
|
|
489
|
+
stmt, error = transpiler.transform(node)
|
|
490
|
+
if error is not None:
|
|
491
|
+
return None, Error(
|
|
492
|
+
verification.parsed.node,
|
|
493
|
+
f"Failed to transpile the verification function {verification.name!r}",
|
|
494
|
+
[error],
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
assert stmt is not None
|
|
498
|
+
body.append(stmt)
|
|
499
|
+
|
|
500
|
+
writer = io.StringIO()
|
|
501
|
+
if verification.description is not None:
|
|
502
|
+
comment, comment_errors = java_description.generate_comment_for_signature(
|
|
503
|
+
description=verification.description,
|
|
504
|
+
context=java_description.Context(package=package, cls_or_enum=None),
|
|
505
|
+
)
|
|
506
|
+
if comment_errors is not None:
|
|
507
|
+
return None, Error(
|
|
508
|
+
verification.description.parsed.node,
|
|
509
|
+
"Failed to generate the documentation comment",
|
|
510
|
+
comment_errors,
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
assert comment is not None
|
|
514
|
+
|
|
515
|
+
writer.write(comment)
|
|
516
|
+
writer.write("\n")
|
|
517
|
+
|
|
518
|
+
method_name = java_naming.method_name(verification.name)
|
|
519
|
+
|
|
520
|
+
if verification.returns is None:
|
|
521
|
+
return_type = "void"
|
|
522
|
+
else:
|
|
523
|
+
return_type = java_common.generate_type(type_annotation=verification.returns)
|
|
524
|
+
|
|
525
|
+
arg_defs = [] # type: List[Stripped]
|
|
526
|
+
for arg in verification.arguments:
|
|
527
|
+
arg_type = java_common.generate_type(arg.type_annotation)
|
|
528
|
+
arg_name = java_naming.argument_name(arg.name)
|
|
529
|
+
arg_defs.append(Stripped(f"{arg_type} {arg_name}"))
|
|
530
|
+
|
|
531
|
+
if len(arg_defs) == 0:
|
|
532
|
+
writer.write(
|
|
533
|
+
f"""\
|
|
534
|
+
public static {return_type} {method_name}() {{"""
|
|
535
|
+
)
|
|
536
|
+
else:
|
|
537
|
+
writer.write(
|
|
538
|
+
f"""\
|
|
539
|
+
public static {return_type} {method_name}(
|
|
540
|
+
"""
|
|
541
|
+
)
|
|
542
|
+
|
|
543
|
+
for i, arg_def in enumerate(arg_defs):
|
|
544
|
+
if i > 0:
|
|
545
|
+
writer.write(",\n")
|
|
546
|
+
writer.write(textwrap.indent(arg_def, I))
|
|
547
|
+
|
|
548
|
+
writer.write(") {")
|
|
549
|
+
|
|
550
|
+
for stmt in body:
|
|
551
|
+
writer.write("\n")
|
|
552
|
+
writer.write(textwrap.indent(stmt, I))
|
|
553
|
+
|
|
554
|
+
if len(body) > 0:
|
|
555
|
+
writer.write("\n")
|
|
556
|
+
|
|
557
|
+
writer.write("}")
|
|
558
|
+
|
|
559
|
+
return Stripped(writer.getvalue()), None
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
def _generate_enum_value_sets(symbol_table: intermediate.SymbolTable) -> Stripped:
|
|
563
|
+
"""Generate a class that pre-computes the sets of allowed enumeration literals."""
|
|
564
|
+
blocks = [] # type: List[Stripped]
|
|
565
|
+
|
|
566
|
+
for enum in symbol_table.enumerations:
|
|
567
|
+
enum_name = java_naming.enum_name(enum.name)
|
|
568
|
+
|
|
569
|
+
if len(enum.literals) == 0:
|
|
570
|
+
blocks.append(
|
|
571
|
+
Stripped(
|
|
572
|
+
f"""\
|
|
573
|
+
private static final Set<{enum_name}> for{enum_name} = new HashSet<>();"""
|
|
574
|
+
)
|
|
575
|
+
)
|
|
576
|
+
else:
|
|
577
|
+
hash_init_writer = io.StringIO()
|
|
578
|
+
|
|
579
|
+
for i, literal in enumerate(enum.literals):
|
|
580
|
+
literal_name = java_naming.enum_literal_name(literal.name)
|
|
581
|
+
hash_init_writer.write(f"temp.add({enum_name}.{literal_name});\n")
|
|
582
|
+
|
|
583
|
+
hash_init_body = hash_init_writer.getvalue()
|
|
584
|
+
|
|
585
|
+
blocks.append(
|
|
586
|
+
Stripped(
|
|
587
|
+
f"""\
|
|
588
|
+
private static final Set<{enum_name}> for{enum_name};
|
|
589
|
+
static {{
|
|
590
|
+
{I}final Set<{enum_name}> temp = new HashSet<>();
|
|
591
|
+
|
|
592
|
+
{I}{indent_but_first_line(hash_init_body, I)}
|
|
593
|
+
|
|
594
|
+
{I}if (!temp.containsAll(Arrays.asList({enum_name}.values()))) {{
|
|
595
|
+
{II}throw new IllegalStateException("Uncovered {enum_name}");
|
|
596
|
+
{I}}}
|
|
597
|
+
|
|
598
|
+
{I}for{enum_name} = Collections.unmodifiableSet(temp);
|
|
599
|
+
}}"""
|
|
600
|
+
)
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
writer = io.StringIO()
|
|
604
|
+
writer.write(
|
|
605
|
+
"""\
|
|
606
|
+
/**
|
|
607
|
+
* Hash allowed enum values for efficient validation of enums.
|
|
608
|
+
*/
|
|
609
|
+
private static class EnumValueSet {
|
|
610
|
+
"""
|
|
611
|
+
)
|
|
612
|
+
for i, block in enumerate(blocks):
|
|
613
|
+
if i > 0:
|
|
614
|
+
writer.write("\n\n")
|
|
615
|
+
|
|
616
|
+
writer.write(textwrap.indent(block, I))
|
|
617
|
+
|
|
618
|
+
writer.write("\n}")
|
|
619
|
+
|
|
620
|
+
return Stripped(writer.getvalue())
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
class _InvariantTranspiler(java_transpilation.Transpiler):
|
|
624
|
+
def __init__(
|
|
625
|
+
self,
|
|
626
|
+
type_map: Mapping[
|
|
627
|
+
parse_tree.Node, intermediate_type_inference.TypeAnnotationUnion
|
|
628
|
+
],
|
|
629
|
+
is_optional_map: Mapping[
|
|
630
|
+
parse_tree.Node,
|
|
631
|
+
bool,
|
|
632
|
+
],
|
|
633
|
+
environment: intermediate_type_inference.Environment,
|
|
634
|
+
symbol_table: intermediate.SymbolTable,
|
|
635
|
+
) -> None:
|
|
636
|
+
"""Initialize with the given values."""
|
|
637
|
+
java_transpilation.Transpiler.__init__(
|
|
638
|
+
self,
|
|
639
|
+
type_map=type_map,
|
|
640
|
+
optional_map=is_optional_map,
|
|
641
|
+
environment=environment,
|
|
642
|
+
)
|
|
643
|
+
|
|
644
|
+
self._symbol_table = symbol_table
|
|
645
|
+
|
|
646
|
+
def transform_name(
|
|
647
|
+
self, node: parse_tree.Name
|
|
648
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
649
|
+
if node.identifier in self._variable_name_set:
|
|
650
|
+
return Stripped(java_naming.variable_name(node.identifier)), None
|
|
651
|
+
|
|
652
|
+
if node.identifier == "self":
|
|
653
|
+
# The ``that`` refers to the argument of the verification function.
|
|
654
|
+
return Stripped("that"), None
|
|
655
|
+
|
|
656
|
+
if node.identifier in self._symbol_table.constants_by_name:
|
|
657
|
+
constant_as_prop = java_naming.property_name(node.identifier)
|
|
658
|
+
return Stripped(f"Constants.{constant_as_prop}"), None
|
|
659
|
+
|
|
660
|
+
if node.identifier in self._symbol_table.verification_functions_by_name:
|
|
661
|
+
return Stripped(java_naming.method_name(node.identifier)), None
|
|
662
|
+
|
|
663
|
+
our_type = self._symbol_table.find_our_type(name=node.identifier)
|
|
664
|
+
if isinstance(our_type, intermediate.Enumeration):
|
|
665
|
+
return Stripped(java_naming.enum_name(node.identifier)), None
|
|
666
|
+
|
|
667
|
+
return None, Error(
|
|
668
|
+
node.original_node,
|
|
669
|
+
f"We can not determine how to transpile the name {node.identifier!r} "
|
|
670
|
+
f"to Java. We could not find it "
|
|
671
|
+
f"neither in the local variables, "
|
|
672
|
+
f"nor in the global constants, "
|
|
673
|
+
f"nor in verification functions, "
|
|
674
|
+
f"nor as an enumeration. "
|
|
675
|
+
f"If you expect this name to be transpilable, please contact "
|
|
676
|
+
f"the developers.",
|
|
677
|
+
)
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
681
|
+
def _transpile_invariant(
|
|
682
|
+
invariant: intermediate.Invariant,
|
|
683
|
+
symbol_table: intermediate.SymbolTable,
|
|
684
|
+
environment: intermediate_type_inference.Environment,
|
|
685
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
686
|
+
"""Translate the invariant from the meta-model into C# code."""
|
|
687
|
+
# fmt: off
|
|
688
|
+
type_map, inference_error = (
|
|
689
|
+
intermediate_type_inference.infer_for_invariant(
|
|
690
|
+
invariant=invariant,
|
|
691
|
+
environment=environment
|
|
692
|
+
)
|
|
693
|
+
)
|
|
694
|
+
# fmt: on
|
|
695
|
+
|
|
696
|
+
if inference_error is not None:
|
|
697
|
+
return None, inference_error
|
|
698
|
+
|
|
699
|
+
assert type_map is not None
|
|
700
|
+
|
|
701
|
+
optional_inferrer = java_optional.OptionalInferrer(
|
|
702
|
+
environment=environment,
|
|
703
|
+
type_map=type_map,
|
|
704
|
+
)
|
|
705
|
+
|
|
706
|
+
_ = optional_inferrer.transform(invariant.body)
|
|
707
|
+
|
|
708
|
+
if len(optional_inferrer.errors):
|
|
709
|
+
return None, Error(
|
|
710
|
+
invariant.parsed.node,
|
|
711
|
+
"Failed to infer whether types are optional in the invariant",
|
|
712
|
+
optional_inferrer.errors,
|
|
713
|
+
)
|
|
714
|
+
|
|
715
|
+
transpiler = _InvariantTranspiler(
|
|
716
|
+
type_map=type_map,
|
|
717
|
+
is_optional_map=optional_inferrer.is_optional_map,
|
|
718
|
+
environment=environment,
|
|
719
|
+
symbol_table=symbol_table,
|
|
720
|
+
)
|
|
721
|
+
|
|
722
|
+
expr, error = transpiler.transform(invariant.parsed.body)
|
|
723
|
+
if error is not None:
|
|
724
|
+
return None, error
|
|
725
|
+
|
|
726
|
+
assert expr is not None
|
|
727
|
+
|
|
728
|
+
writer = io.StringIO()
|
|
729
|
+
if len(expr) > 50 or "\n" in expr:
|
|
730
|
+
writer.write("if (!(\n")
|
|
731
|
+
writer.write(textwrap.indent(expr, I))
|
|
732
|
+
writer.write(")) {\n")
|
|
733
|
+
else:
|
|
734
|
+
no_parenthesis_type_in_this_context = (
|
|
735
|
+
parse_tree.Name,
|
|
736
|
+
parse_tree.Member,
|
|
737
|
+
parse_tree.MethodCall,
|
|
738
|
+
parse_tree.FunctionCall,
|
|
739
|
+
)
|
|
740
|
+
|
|
741
|
+
if isinstance(invariant.parsed.body, no_parenthesis_type_in_this_context):
|
|
742
|
+
not_expr = f"!{expr}"
|
|
743
|
+
else:
|
|
744
|
+
not_expr = f"!({expr})"
|
|
745
|
+
|
|
746
|
+
writer.write(f"if ({not_expr}) {{\n")
|
|
747
|
+
|
|
748
|
+
writer.write(
|
|
749
|
+
textwrap.indent(
|
|
750
|
+
f"""\
|
|
751
|
+
errorStream = Stream.<Reporting.Error>concat(errorStream,
|
|
752
|
+
{I}Stream.of(new Reporting.Error(
|
|
753
|
+
{II}"Invariant violated:\\n" +
|
|
754
|
+
""",
|
|
755
|
+
I,
|
|
756
|
+
)
|
|
757
|
+
)
|
|
758
|
+
|
|
759
|
+
# NOTE (empwilli, 2024-01-22):
|
|
760
|
+
# We need to wrap the description in multiple literals as a single long
|
|
761
|
+
# string literal is often too much for the readability.
|
|
762
|
+
invariant_description_lines = wrap_text_into_lines(invariant.description)
|
|
763
|
+
|
|
764
|
+
for i, literal in enumerate(invariant_description_lines):
|
|
765
|
+
if i < len(invariant_description_lines) - 1:
|
|
766
|
+
writer.write(f"{III}{java_common.string_literal(literal)} +\n")
|
|
767
|
+
else:
|
|
768
|
+
writer.write(f"{III}{java_common.string_literal(literal)})));")
|
|
769
|
+
|
|
770
|
+
writer.write("\n}")
|
|
771
|
+
|
|
772
|
+
return Stripped(writer.getvalue()), None
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
def _generate_verify_method(our_type: intermediate.OurType) -> Stripped:
|
|
776
|
+
"""Generate the name of the ``verify*`` method."""
|
|
777
|
+
if isinstance(our_type, intermediate.Enumeration):
|
|
778
|
+
name = java_naming.enum_name(our_type.name)
|
|
779
|
+
return Stripped(f"verify{name}")
|
|
780
|
+
|
|
781
|
+
elif isinstance(our_type, intermediate.ConstrainedPrimitive):
|
|
782
|
+
name = java_naming.class_name(our_type.name)
|
|
783
|
+
return Stripped(f"verify{name}")
|
|
784
|
+
|
|
785
|
+
elif isinstance(our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)):
|
|
786
|
+
return Stripped("verifyToErrorStream")
|
|
787
|
+
else:
|
|
788
|
+
assert_never(our_type)
|
|
789
|
+
|
|
790
|
+
raise AssertionError("Unexpected execution path")
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
794
|
+
def _generate_transform_property(
|
|
795
|
+
prop: intermediate.Property,
|
|
796
|
+
) -> Tuple[Optional[Stripped], Optional[Error]]:
|
|
797
|
+
"""Generate the snippet to transform a property to errors."""
|
|
798
|
+
# NOTE (empwilli, 2024-01-19):
|
|
799
|
+
# Instead of writing here a complex but general solution with unrolling we choose
|
|
800
|
+
# to provide a simple, but limited, solution. First, the meta-model is quite
|
|
801
|
+
# limited itself at the moment, so the complexity of the general solution is not
|
|
802
|
+
# warranted. Second, we hope that there will be fewer bugs in the simple solution
|
|
803
|
+
# which is particularly important at this early adoption stage.
|
|
804
|
+
#
|
|
805
|
+
# We anticipate that in the future we will indeed need a general and complex
|
|
806
|
+
# solution. Here are just some thoughts on how to approach it:
|
|
807
|
+
# * Leave the pattern matching to produce more readable code for simple cases,
|
|
808
|
+
# * Unroll only in case of composite types and optional composite types.
|
|
809
|
+
|
|
810
|
+
type_anno = (
|
|
811
|
+
prop.type_annotation
|
|
812
|
+
if not isinstance(prop.type_annotation, intermediate.OptionalTypeAnnotation)
|
|
813
|
+
else prop.type_annotation.value
|
|
814
|
+
)
|
|
815
|
+
|
|
816
|
+
if isinstance(type_anno, intermediate.OptionalTypeAnnotation):
|
|
817
|
+
return None, Error(
|
|
818
|
+
prop.parsed.node,
|
|
819
|
+
"We currently implemented verification based on a very limited "
|
|
820
|
+
"pattern matching due to code simplicity. We did not handle "
|
|
821
|
+
"the case of nested optional values. Please contact "
|
|
822
|
+
"the developers if you need this functionality.",
|
|
823
|
+
)
|
|
824
|
+
elif isinstance(type_anno, intermediate.ListTypeAnnotation):
|
|
825
|
+
if isinstance(type_anno.items, intermediate.OptionalTypeAnnotation):
|
|
826
|
+
return None, Error(
|
|
827
|
+
prop.parsed.node,
|
|
828
|
+
"We currently implemented verification based on a very limited "
|
|
829
|
+
"pattern matching due to code simplicity. We did not handle "
|
|
830
|
+
"the case of lists of optional values. Please contact "
|
|
831
|
+
"the developers if you need this functionality.",
|
|
832
|
+
)
|
|
833
|
+
elif isinstance(type_anno.items, intermediate.ListTypeAnnotation):
|
|
834
|
+
return None, Error(
|
|
835
|
+
prop.parsed.node,
|
|
836
|
+
"We currently implemented verification based on a very limited "
|
|
837
|
+
"pattern matching due to code simplicity. We did not handle "
|
|
838
|
+
"the case of lists of lists. Please contact "
|
|
839
|
+
"the developers if you need this functionality.",
|
|
840
|
+
)
|
|
841
|
+
else:
|
|
842
|
+
pass
|
|
843
|
+
else:
|
|
844
|
+
pass
|
|
845
|
+
|
|
846
|
+
stmts = [] # type: List[Stripped]
|
|
847
|
+
|
|
848
|
+
getter_name = java_naming.getter_name(prop.name)
|
|
849
|
+
prop_literal = java_common.string_literal(naming.json_property(prop.name))
|
|
850
|
+
|
|
851
|
+
if isinstance(prop.type_annotation, intermediate.OptionalTypeAnnotation):
|
|
852
|
+
source_expr = Stripped(f"that.{getter_name}().get()")
|
|
853
|
+
else:
|
|
854
|
+
source_expr = Stripped(f"that.{getter_name}()")
|
|
855
|
+
|
|
856
|
+
if isinstance(type_anno, intermediate.PrimitiveTypeAnnotation):
|
|
857
|
+
# There is nothing that we check for primitive types.
|
|
858
|
+
return Stripped(""), None
|
|
859
|
+
elif isinstance(type_anno, intermediate.OurTypeAnnotation):
|
|
860
|
+
verify_method = _generate_verify_method(our_type=type_anno.our_type)
|
|
861
|
+
|
|
862
|
+
stmts.append(
|
|
863
|
+
Stripped(
|
|
864
|
+
f"""\
|
|
865
|
+
errorStream = Stream.<Reporting.Error>concat(errorStream,
|
|
866
|
+
{I}Stream.of({source_expr})
|
|
867
|
+
{II}.flatMap(Verification::{verify_method})
|
|
868
|
+
{III}.map(error -> {{
|
|
869
|
+
{IIII}error.prependSegment(
|
|
870
|
+
{IIIII}new Reporting.NameSegment({prop_literal}));
|
|
871
|
+
{IIII}return error;
|
|
872
|
+
{III}}}));"""
|
|
873
|
+
)
|
|
874
|
+
)
|
|
875
|
+
|
|
876
|
+
elif isinstance(type_anno, intermediate.ListTypeAnnotation):
|
|
877
|
+
assert not isinstance(
|
|
878
|
+
type_anno.items,
|
|
879
|
+
(intermediate.OptionalTypeAnnotation, intermediate.ListTypeAnnotation),
|
|
880
|
+
), (
|
|
881
|
+
"We chose to implement only a very limited pattern matching; "
|
|
882
|
+
"see the note above in the code."
|
|
883
|
+
)
|
|
884
|
+
|
|
885
|
+
# NOTE (empwilli, 2024-01-19):
|
|
886
|
+
# We only descend into our classes here.
|
|
887
|
+
if not isinstance(type_anno.items, intermediate.OurTypeAnnotation):
|
|
888
|
+
return Stripped(""), None
|
|
889
|
+
|
|
890
|
+
verify_method = _generate_verify_method(type_anno.items.our_type)
|
|
891
|
+
|
|
892
|
+
stmts.append(
|
|
893
|
+
Stripped(
|
|
894
|
+
f"""\
|
|
895
|
+
errorStream = Stream.<Reporting.Error>concat(errorStream,
|
|
896
|
+
{I}Verification.zip(
|
|
897
|
+
{II}IntStream.iterate(0, i -> i + 1).boxed(),
|
|
898
|
+
{II}{source_expr}.stream())
|
|
899
|
+
{III}.flatMap(elemTuple -> {{
|
|
900
|
+
{IIII}final int index = elemTuple.getFirst();
|
|
901
|
+
{IIII}final IClass elem = elemTuple.getSecond();
|
|
902
|
+
{IIII}return Verification.verifyToErrorStream(elem)
|
|
903
|
+
{IIIII}.map(error -> {{
|
|
904
|
+
{IIIIII}error.prependSegment(new Reporting.IndexSegment(index));
|
|
905
|
+
{IIIIII}return error;
|
|
906
|
+
{IIIII}}});
|
|
907
|
+
{III}}})
|
|
908
|
+
{II}.map(error -> {{
|
|
909
|
+
{III}error.prependSegment(
|
|
910
|
+
{IIII}new Reporting.NameSegment({prop_literal}));
|
|
911
|
+
{III}return error;
|
|
912
|
+
{II}}}));"""
|
|
913
|
+
)
|
|
914
|
+
)
|
|
915
|
+
|
|
916
|
+
else:
|
|
917
|
+
assert_never(type_anno)
|
|
918
|
+
|
|
919
|
+
verify_block = Stripped("\n".join(stmts))
|
|
920
|
+
if isinstance(prop.type_annotation, intermediate.OptionalTypeAnnotation):
|
|
921
|
+
return (
|
|
922
|
+
Stripped(
|
|
923
|
+
f"""\
|
|
924
|
+
if (that.{getter_name}().isPresent()) {{
|
|
925
|
+
{I}{indent_but_first_line(verify_block, I)}
|
|
926
|
+
}}"""
|
|
927
|
+
),
|
|
928
|
+
None,
|
|
929
|
+
)
|
|
930
|
+
else:
|
|
931
|
+
return verify_block, None
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
935
|
+
def _generate_transform_for_class(
|
|
936
|
+
cls: intermediate.ConcreteClass,
|
|
937
|
+
symbol_table: intermediate.SymbolTable,
|
|
938
|
+
base_environment: intermediate_type_inference.Environment,
|
|
939
|
+
) -> Tuple[Optional[Stripped], Optional[List[Error]]]:
|
|
940
|
+
"""Generate the transform method to errors for the given concrete class."""
|
|
941
|
+
errors = [] # type: List[Error]
|
|
942
|
+
blocks = [] # type: List[Stripped]
|
|
943
|
+
|
|
944
|
+
name = java_naming.class_name(cls.name)
|
|
945
|
+
|
|
946
|
+
environment = intermediate_type_inference.MutableEnvironment(
|
|
947
|
+
parent=base_environment
|
|
948
|
+
)
|
|
949
|
+
|
|
950
|
+
assert environment.find(Identifier("self")) is None
|
|
951
|
+
environment.set(
|
|
952
|
+
identifier=Identifier("self"),
|
|
953
|
+
type_annotation=intermediate_type_inference.OurTypeAnnotation(our_type=cls),
|
|
954
|
+
)
|
|
955
|
+
|
|
956
|
+
for invariant in cls.invariants:
|
|
957
|
+
invariant_code, error = _transpile_invariant(
|
|
958
|
+
invariant=invariant, symbol_table=symbol_table, environment=environment
|
|
959
|
+
)
|
|
960
|
+
if error is not None:
|
|
961
|
+
errors.append(
|
|
962
|
+
Error(
|
|
963
|
+
cls.parsed.node,
|
|
964
|
+
f"Failed to transpile the invariant of the class {cls.name!r}",
|
|
965
|
+
[error],
|
|
966
|
+
)
|
|
967
|
+
)
|
|
968
|
+
continue
|
|
969
|
+
|
|
970
|
+
assert invariant_code is not None
|
|
971
|
+
|
|
972
|
+
blocks.append(invariant_code)
|
|
973
|
+
|
|
974
|
+
if len(errors) > 0:
|
|
975
|
+
return None, errors
|
|
976
|
+
|
|
977
|
+
for prop in cls.properties:
|
|
978
|
+
block, error = _generate_transform_property(prop=prop)
|
|
979
|
+
if error is not None:
|
|
980
|
+
errors.append(error)
|
|
981
|
+
else:
|
|
982
|
+
assert block is not None
|
|
983
|
+
if block != "":
|
|
984
|
+
blocks.append(block)
|
|
985
|
+
|
|
986
|
+
if len(errors) > 0:
|
|
987
|
+
return None, errors
|
|
988
|
+
|
|
989
|
+
if len(blocks) == 0:
|
|
990
|
+
blocks.append(
|
|
991
|
+
Stripped(
|
|
992
|
+
f"""\
|
|
993
|
+
// No verification has been defined for {name}."""
|
|
994
|
+
)
|
|
995
|
+
)
|
|
996
|
+
|
|
997
|
+
writer = io.StringIO()
|
|
998
|
+
|
|
999
|
+
interface_name = java_naming.interface_name(cls.name)
|
|
1000
|
+
transform_name = java_naming.method_name(Identifier(f"transform_{cls.name}"))
|
|
1001
|
+
|
|
1002
|
+
writer.write(
|
|
1003
|
+
f"""\
|
|
1004
|
+
@Override
|
|
1005
|
+
public Stream<Reporting.Error> {transform_name}(
|
|
1006
|
+
{I}{interface_name} that) {{
|
|
1007
|
+
{I}Stream<Reporting.Error> errorStream = Stream.empty();
|
|
1008
|
+
|
|
1009
|
+
"""
|
|
1010
|
+
)
|
|
1011
|
+
|
|
1012
|
+
for i, stmt in enumerate(blocks):
|
|
1013
|
+
if i > 0:
|
|
1014
|
+
writer.write("\n\n")
|
|
1015
|
+
writer.write(textwrap.indent(stmt, I))
|
|
1016
|
+
|
|
1017
|
+
writer.write("\n\n")
|
|
1018
|
+
writer.write(f"{I}return errorStream;")
|
|
1019
|
+
writer.write("\n}")
|
|
1020
|
+
|
|
1021
|
+
return Stripped(writer.getvalue()), None
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
def _generate_transformer(
|
|
1025
|
+
symbol_table: intermediate.SymbolTable,
|
|
1026
|
+
base_environment: intermediate_type_inference.Environment,
|
|
1027
|
+
spec_impls: specific_implementations.SpecificImplementations,
|
|
1028
|
+
) -> Tuple[Optional[Stripped], Optional[List[Error]]]:
|
|
1029
|
+
"""Generate a transformer to double-dispatch an instance to errors."""
|
|
1030
|
+
errors = [] # type: List[Error]
|
|
1031
|
+
|
|
1032
|
+
blocks = [] # type: List[Stripped]
|
|
1033
|
+
|
|
1034
|
+
for our_type in symbol_table.our_types:
|
|
1035
|
+
if isinstance(our_type, intermediate.Enumeration):
|
|
1036
|
+
continue
|
|
1037
|
+
|
|
1038
|
+
elif isinstance(our_type, intermediate.ConstrainedPrimitive):
|
|
1039
|
+
continue
|
|
1040
|
+
|
|
1041
|
+
elif isinstance(our_type, intermediate.AbstractClass):
|
|
1042
|
+
# The abstract classes are directly dispatched by the transformer,
|
|
1043
|
+
# so we do not need to handle them separately.
|
|
1044
|
+
pass
|
|
1045
|
+
|
|
1046
|
+
elif isinstance(our_type, intermediate.ConcreteClass):
|
|
1047
|
+
if our_type.is_implementation_specific:
|
|
1048
|
+
transform_key = specific_implementations.ImplementationKey(
|
|
1049
|
+
f"Verification/transform_{our_type.name}.java"
|
|
1050
|
+
)
|
|
1051
|
+
|
|
1052
|
+
implementation = spec_impls.get(transform_key, None)
|
|
1053
|
+
if implementation is None:
|
|
1054
|
+
errors.append(
|
|
1055
|
+
Error(
|
|
1056
|
+
our_type.parsed.node,
|
|
1057
|
+
f"The transformation snippet is missing "
|
|
1058
|
+
f"for the implementation-specific "
|
|
1059
|
+
f"class {our_type.name}: {transform_key}",
|
|
1060
|
+
)
|
|
1061
|
+
)
|
|
1062
|
+
continue
|
|
1063
|
+
|
|
1064
|
+
blocks.append(spec_impls[transform_key])
|
|
1065
|
+
else:
|
|
1066
|
+
block, cls_errors = _generate_transform_for_class(
|
|
1067
|
+
cls=our_type,
|
|
1068
|
+
symbol_table=symbol_table,
|
|
1069
|
+
base_environment=base_environment,
|
|
1070
|
+
)
|
|
1071
|
+
if cls_errors is not None:
|
|
1072
|
+
errors.extend(cls_errors)
|
|
1073
|
+
else:
|
|
1074
|
+
assert block is not None
|
|
1075
|
+
blocks.append(block)
|
|
1076
|
+
else:
|
|
1077
|
+
assert_never(our_type)
|
|
1078
|
+
|
|
1079
|
+
if len(errors) > 0:
|
|
1080
|
+
return None, errors
|
|
1081
|
+
|
|
1082
|
+
writer = io.StringIO()
|
|
1083
|
+
writer.write(
|
|
1084
|
+
"""\
|
|
1085
|
+
private static class Transformer extends AbstractTransformer<Stream<Reporting.Error>> {
|
|
1086
|
+
"""
|
|
1087
|
+
)
|
|
1088
|
+
|
|
1089
|
+
for i, block in enumerate(blocks):
|
|
1090
|
+
if i > 0:
|
|
1091
|
+
writer.write("\n\n")
|
|
1092
|
+
writer.write(textwrap.indent(block, I))
|
|
1093
|
+
|
|
1094
|
+
writer.write("\n}")
|
|
1095
|
+
|
|
1096
|
+
return Stripped(writer.getvalue()), None
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
def _generate_verify_enumeration(enumeration: intermediate.Enumeration) -> Stripped:
|
|
1100
|
+
"""Generate the verify method to check that an enum is valid."""
|
|
1101
|
+
name = java_naming.enum_name(enumeration.name)
|
|
1102
|
+
|
|
1103
|
+
return Stripped(
|
|
1104
|
+
f"""\
|
|
1105
|
+
/**
|
|
1106
|
+
* Verify that {{@code that}} is a valid enumeration value.
|
|
1107
|
+
*/
|
|
1108
|
+
public static Stream<Reporting.Error> verify{name}(
|
|
1109
|
+
{I}{name} that) {{
|
|
1110
|
+
{I}if (!EnumValueSet.for{name}.contains(that)) {{
|
|
1111
|
+
{II}return Stream.of(new Reporting.Error(
|
|
1112
|
+
{III}"Invalid {name}: " + that));
|
|
1113
|
+
{I}}} else {{
|
|
1114
|
+
{II}return Stream.empty();
|
|
1115
|
+
{I}}}
|
|
1116
|
+
}}"""
|
|
1117
|
+
)
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
def _generate_verify_constrained_primitive(
|
|
1121
|
+
constrained_primitive: intermediate.ConstrainedPrimitive,
|
|
1122
|
+
symbol_table: intermediate.SymbolTable,
|
|
1123
|
+
base_environment: intermediate_type_inference.Environment,
|
|
1124
|
+
) -> Tuple[Optional[Stripped], Optional[List[Error]]]:
|
|
1125
|
+
"""Generate the verify function for the constrained primitives."""
|
|
1126
|
+
errors = [] # type: List[Error]
|
|
1127
|
+
blocks = [] # type: List[Stripped]
|
|
1128
|
+
|
|
1129
|
+
environment = intermediate_type_inference.MutableEnvironment(
|
|
1130
|
+
parent=base_environment
|
|
1131
|
+
)
|
|
1132
|
+
|
|
1133
|
+
assert environment.find(Identifier("self")) is None
|
|
1134
|
+
environment.set(
|
|
1135
|
+
identifier=Identifier("self"),
|
|
1136
|
+
type_annotation=intermediate_type_inference.OurTypeAnnotation(
|
|
1137
|
+
our_type=constrained_primitive
|
|
1138
|
+
),
|
|
1139
|
+
)
|
|
1140
|
+
|
|
1141
|
+
for invariant in constrained_primitive.invariants:
|
|
1142
|
+
invariant_code, error = _transpile_invariant(
|
|
1143
|
+
invariant=invariant, symbol_table=symbol_table, environment=environment
|
|
1144
|
+
)
|
|
1145
|
+
if error is not None:
|
|
1146
|
+
errors.append(
|
|
1147
|
+
Error(
|
|
1148
|
+
constrained_primitive.parsed.node,
|
|
1149
|
+
f"Failed to transpile the invariant of "
|
|
1150
|
+
f"the constrained primitive {constrained_primitive.name!r}",
|
|
1151
|
+
[error],
|
|
1152
|
+
)
|
|
1153
|
+
)
|
|
1154
|
+
continue
|
|
1155
|
+
|
|
1156
|
+
assert invariant_code is not None
|
|
1157
|
+
|
|
1158
|
+
blocks.append(invariant_code)
|
|
1159
|
+
|
|
1160
|
+
if len(errors) > 0:
|
|
1161
|
+
return None, errors
|
|
1162
|
+
|
|
1163
|
+
if len(blocks) == 0:
|
|
1164
|
+
blocks.append(
|
|
1165
|
+
Stripped(
|
|
1166
|
+
"""\
|
|
1167
|
+
// There is no verification specified."""
|
|
1168
|
+
)
|
|
1169
|
+
)
|
|
1170
|
+
|
|
1171
|
+
# NOTE (empwilli, 2024-01-22):
|
|
1172
|
+
# Constrained primitives are not really classes, but we simply use the naming
|
|
1173
|
+
# for classes here since we need to pick *something*.
|
|
1174
|
+
name = java_naming.class_name(constrained_primitive.name)
|
|
1175
|
+
|
|
1176
|
+
that_type = java_common.PRIMITIVE_TYPE_MAP[constrained_primitive.constrainee]
|
|
1177
|
+
|
|
1178
|
+
writer = io.StringIO()
|
|
1179
|
+
writer.write(
|
|
1180
|
+
f"""\
|
|
1181
|
+
/**
|
|
1182
|
+
* Verify the constraints of {{@code that}}.
|
|
1183
|
+
*/
|
|
1184
|
+
public static Stream<Reporting.Error> verify{name} (
|
|
1185
|
+
{I}{that_type} that) {{
|
|
1186
|
+
{I}Stream<Reporting.Error> errorStream = Stream.empty();
|
|
1187
|
+
|
|
1188
|
+
"""
|
|
1189
|
+
)
|
|
1190
|
+
|
|
1191
|
+
for i, block in enumerate(blocks):
|
|
1192
|
+
if i > 0:
|
|
1193
|
+
writer.write("\n\n")
|
|
1194
|
+
writer.write(textwrap.indent(block, I))
|
|
1195
|
+
|
|
1196
|
+
writer.write("\n\n")
|
|
1197
|
+
writer.write(f"{I}return errorStream;")
|
|
1198
|
+
writer.write("\n}")
|
|
1199
|
+
|
|
1200
|
+
assert len(errors) == 0
|
|
1201
|
+
return Stripped(writer.getvalue()), None
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
# fmt: off
|
|
1205
|
+
@ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
|
|
1206
|
+
@ensure(
|
|
1207
|
+
lambda result:
|
|
1208
|
+
not (result[0] is not None) or result[0].endswith('\n'),
|
|
1209
|
+
"Trailing newline mandatory for valid end-of-files"
|
|
1210
|
+
)
|
|
1211
|
+
# fmt: on
|
|
1212
|
+
def generate(
|
|
1213
|
+
symbol_table: intermediate.SymbolTable,
|
|
1214
|
+
package: java_common.PackageIdentifier,
|
|
1215
|
+
spec_impls: specific_implementations.SpecificImplementations,
|
|
1216
|
+
) -> Tuple[Optional[str], Optional[List[Error]]]:
|
|
1217
|
+
"""
|
|
1218
|
+
Generate the Java code of the structures based on the symbol table.
|
|
1219
|
+
|
|
1220
|
+
The ``package`` defines the root Java package.
|
|
1221
|
+
"""
|
|
1222
|
+
|
|
1223
|
+
imports = [
|
|
1224
|
+
Stripped("import java.lang.Iterable;"),
|
|
1225
|
+
Stripped("import java.math.BigInteger;"),
|
|
1226
|
+
Stripped("import java.util.Arrays;"),
|
|
1227
|
+
Stripped("import java.util.Collections;"),
|
|
1228
|
+
Stripped("import java.util.function.Consumer;"),
|
|
1229
|
+
Stripped("import java.util.HashSet;"),
|
|
1230
|
+
Stripped("import java.util.Iterator;"),
|
|
1231
|
+
Stripped("import java.util.Objects;"),
|
|
1232
|
+
Stripped("import java.util.regex.Matcher;"),
|
|
1233
|
+
Stripped("import java.util.regex.Pattern;"),
|
|
1234
|
+
Stripped("import java.util.Set;"),
|
|
1235
|
+
Stripped("import java.util.Spliterator;"),
|
|
1236
|
+
Stripped("import java.util.Spliterators;"),
|
|
1237
|
+
Stripped("import java.util.stream.IntStream;"),
|
|
1238
|
+
Stripped("import java.util.stream.Stream;"),
|
|
1239
|
+
Stripped("import java.util.stream.StreamSupport;"),
|
|
1240
|
+
Stripped("import aas_core.aas3_0.constants.*;"),
|
|
1241
|
+
Stripped("import aas_core.aas3_0.reporting.Reporting;"),
|
|
1242
|
+
Stripped("import aas_core.aas3_0.types.enums.*;"),
|
|
1243
|
+
Stripped("import aas_core.aas3_0.types.model.*;"),
|
|
1244
|
+
Stripped("import aas_core.aas3_0.visitation.AbstractTransformer;"),
|
|
1245
|
+
] # type: List[Stripped]
|
|
1246
|
+
|
|
1247
|
+
verification_blocks = [] # type: List[Stripped]
|
|
1248
|
+
errors = [] # type: List[Error]
|
|
1249
|
+
|
|
1250
|
+
base_environment = intermediate_type_inference.populate_base_environment(
|
|
1251
|
+
symbol_table=symbol_table
|
|
1252
|
+
)
|
|
1253
|
+
|
|
1254
|
+
for verification in symbol_table.verification_functions:
|
|
1255
|
+
if isinstance(verification, intermediate.ImplementationSpecificVerification):
|
|
1256
|
+
implementation_key = specific_implementations.ImplementationKey(
|
|
1257
|
+
f"Verification/{verification.name}.java"
|
|
1258
|
+
)
|
|
1259
|
+
|
|
1260
|
+
implementation = spec_impls.get(implementation_key, None)
|
|
1261
|
+
if implementation is None:
|
|
1262
|
+
errors.append(
|
|
1263
|
+
Error(
|
|
1264
|
+
None,
|
|
1265
|
+
f"The snippet for the verification function "
|
|
1266
|
+
f"{verification.name!r} is missing: {implementation_key}",
|
|
1267
|
+
)
|
|
1268
|
+
)
|
|
1269
|
+
else:
|
|
1270
|
+
verification_blocks.append(implementation)
|
|
1271
|
+
|
|
1272
|
+
elif isinstance(verification, intermediate.PatternVerification):
|
|
1273
|
+
implementation, error = _transpile_pattern_verification(
|
|
1274
|
+
verification=verification,
|
|
1275
|
+
package=package,
|
|
1276
|
+
)
|
|
1277
|
+
|
|
1278
|
+
if error is not None:
|
|
1279
|
+
errors.append(error)
|
|
1280
|
+
else:
|
|
1281
|
+
assert implementation is not None
|
|
1282
|
+
verification_blocks.append(implementation)
|
|
1283
|
+
|
|
1284
|
+
elif isinstance(verification, intermediate.TranspilableVerification):
|
|
1285
|
+
implementation, error = _transpile_transpilable_verification(
|
|
1286
|
+
verification=verification,
|
|
1287
|
+
symbol_table=symbol_table,
|
|
1288
|
+
environment=base_environment,
|
|
1289
|
+
package=package,
|
|
1290
|
+
)
|
|
1291
|
+
|
|
1292
|
+
if error is not None:
|
|
1293
|
+
errors.append(error)
|
|
1294
|
+
else:
|
|
1295
|
+
assert implementation is not None
|
|
1296
|
+
verification_blocks.append(implementation)
|
|
1297
|
+
|
|
1298
|
+
else:
|
|
1299
|
+
assert_never(verification)
|
|
1300
|
+
|
|
1301
|
+
verification_blocks.append(_generate_enum_value_sets(symbol_table=symbol_table))
|
|
1302
|
+
|
|
1303
|
+
verification_blocks.append(
|
|
1304
|
+
Stripped(
|
|
1305
|
+
"""\
|
|
1306
|
+
private static final Transformer transformer = new Transformer();"""
|
|
1307
|
+
)
|
|
1308
|
+
)
|
|
1309
|
+
|
|
1310
|
+
transformer_block, transformer_errors = _generate_transformer(
|
|
1311
|
+
symbol_table=symbol_table,
|
|
1312
|
+
base_environment=base_environment,
|
|
1313
|
+
spec_impls=spec_impls,
|
|
1314
|
+
)
|
|
1315
|
+
if transformer_errors is not None:
|
|
1316
|
+
errors.extend(transformer_errors)
|
|
1317
|
+
else:
|
|
1318
|
+
assert transformer_block is not None
|
|
1319
|
+
verification_blocks.append(transformer_block)
|
|
1320
|
+
|
|
1321
|
+
verification_blocks.append(
|
|
1322
|
+
Stripped(
|
|
1323
|
+
f"""\
|
|
1324
|
+
public static Stream<Reporting.Error> verifyToErrorStream(IClass that) {{
|
|
1325
|
+
{I}return transformer.transform(that);
|
|
1326
|
+
}}
|
|
1327
|
+
|
|
1328
|
+
private static class ValidationErrorIterable implements Iterable<Reporting.Error> {{
|
|
1329
|
+
{I}private final IClass element;
|
|
1330
|
+
|
|
1331
|
+
{I}public ValidationErrorIterable(IClass element) {{
|
|
1332
|
+
{II}this.element = element;
|
|
1333
|
+
}}
|
|
1334
|
+
|
|
1335
|
+
{I}@Override
|
|
1336
|
+
{I}public Iterator<Reporting.Error> iterator() {{
|
|
1337
|
+
{II}Stream<Reporting.Error> stream = stream();
|
|
1338
|
+
|
|
1339
|
+
{II}return stream.iterator();
|
|
1340
|
+
{I}}}
|
|
1341
|
+
|
|
1342
|
+
{I}@Override
|
|
1343
|
+
{I}public void forEach(Consumer<? super Reporting.Error> action) {{
|
|
1344
|
+
{II}Stream<Reporting.Error> stream = stream();
|
|
1345
|
+
|
|
1346
|
+
{II}stream.forEach(action);
|
|
1347
|
+
{I}}}
|
|
1348
|
+
|
|
1349
|
+
{I}@Override
|
|
1350
|
+
{I}public Spliterator<Reporting.Error> spliterator() {{
|
|
1351
|
+
{II}Stream<Reporting.Error> stream = stream();
|
|
1352
|
+
|
|
1353
|
+
{II}return stream.spliterator();
|
|
1354
|
+
{I}}}
|
|
1355
|
+
|
|
1356
|
+
{I}private Stream<Reporting.Error> stream() {{
|
|
1357
|
+
{II}return Verification.verifyToErrorStream(element);
|
|
1358
|
+
{I}}}
|
|
1359
|
+
}}
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* Verify the constraints of {{@code that}} recursively.
|
|
1363
|
+
*
|
|
1364
|
+
* @param that The instance of the meta-model to be verified
|
|
1365
|
+
*/
|
|
1366
|
+
public static Iterable<Reporting.Error> verify(IClass that) {{
|
|
1367
|
+
{I}return new ValidationErrorIterable(that);
|
|
1368
|
+
}}"""
|
|
1369
|
+
)
|
|
1370
|
+
)
|
|
1371
|
+
|
|
1372
|
+
for our_type in symbol_table.our_types:
|
|
1373
|
+
if isinstance(our_type, intermediate.Enumeration):
|
|
1374
|
+
verification_blocks.append(
|
|
1375
|
+
_generate_verify_enumeration(enumeration=our_type)
|
|
1376
|
+
)
|
|
1377
|
+
elif isinstance(our_type, intermediate.ConstrainedPrimitive):
|
|
1378
|
+
(
|
|
1379
|
+
constrained_primitive_block,
|
|
1380
|
+
constrained_primitive_errors,
|
|
1381
|
+
) = _generate_verify_constrained_primitive(
|
|
1382
|
+
constrained_primitive=our_type,
|
|
1383
|
+
symbol_table=symbol_table,
|
|
1384
|
+
base_environment=base_environment,
|
|
1385
|
+
)
|
|
1386
|
+
|
|
1387
|
+
if constrained_primitive_errors is not None:
|
|
1388
|
+
errors.extend(constrained_primitive_errors)
|
|
1389
|
+
else:
|
|
1390
|
+
assert constrained_primitive_block is not None
|
|
1391
|
+
verification_blocks.append(constrained_primitive_block)
|
|
1392
|
+
|
|
1393
|
+
elif isinstance(
|
|
1394
|
+
our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)
|
|
1395
|
+
):
|
|
1396
|
+
# We provide a general dispatch function.
|
|
1397
|
+
pass
|
|
1398
|
+
else:
|
|
1399
|
+
assert_never(our_type)
|
|
1400
|
+
|
|
1401
|
+
if len(errors) > 0:
|
|
1402
|
+
return None, errors
|
|
1403
|
+
|
|
1404
|
+
verification_blocks.append(
|
|
1405
|
+
Stripped(
|
|
1406
|
+
f"""\
|
|
1407
|
+
private static class Pair<A, B> {{
|
|
1408
|
+
{I}private final A first;
|
|
1409
|
+
{I}private final B second;
|
|
1410
|
+
|
|
1411
|
+
{I}public Pair(A first, B second) {{
|
|
1412
|
+
{II}this.first = first;
|
|
1413
|
+
{II}this.second = second;
|
|
1414
|
+
{I}}}
|
|
1415
|
+
|
|
1416
|
+
{I}public A getFirst() {{
|
|
1417
|
+
{II}return first;
|
|
1418
|
+
{I}}}
|
|
1419
|
+
|
|
1420
|
+
{I}public B getSecond() {{
|
|
1421
|
+
{II}return second;
|
|
1422
|
+
{I}}}
|
|
1423
|
+
}}
|
|
1424
|
+
|
|
1425
|
+
// Java 8 doesn't provide a split operation out of the box, so we have to ship our own.
|
|
1426
|
+
// Adapted from: https://stackoverflow.com/a/23529010
|
|
1427
|
+
private static <A, B> Stream<Pair<A, B>> zip(
|
|
1428
|
+
{I}Stream<? extends A> a,
|
|
1429
|
+
{I}Stream<? extends B> b) {{
|
|
1430
|
+
{I}Spliterator<? extends A> aSplit = Objects.requireNonNull(a).spliterator();
|
|
1431
|
+
{I}Spliterator<? extends B> bSplit = Objects.requireNonNull(b).spliterator();
|
|
1432
|
+
|
|
1433
|
+
{I}int characteristics = aSplit.characteristics() & bSplit.characteristics() &
|
|
1434
|
+
{II}~(Spliterator.DISTINCT | Spliterator.SORTED);
|
|
1435
|
+
|
|
1436
|
+
{I}long zipSize = ((characteristics & Spliterator.SIZED) != 0)
|
|
1437
|
+
{II}? Math.min(aSplit.getExactSizeIfKnown(), bSplit.getExactSizeIfKnown())
|
|
1438
|
+
{II}: -1;
|
|
1439
|
+
|
|
1440
|
+
{I}Iterator<A> aIter = Spliterators.iterator(aSplit);
|
|
1441
|
+
{I}Iterator<B> bIter = Spliterators.iterator(bSplit);
|
|
1442
|
+
{I}Iterator<Pair<A, B>> cIter = new Iterator<Pair<A, B>>() {{
|
|
1443
|
+
{II}@Override
|
|
1444
|
+
{II}public boolean hasNext() {{
|
|
1445
|
+
{III}return aIter.hasNext() && bIter.hasNext();
|
|
1446
|
+
{II}}}
|
|
1447
|
+
|
|
1448
|
+
{II}@Override
|
|
1449
|
+
{II}public Pair<A, B> next() {{
|
|
1450
|
+
{III}return new Pair<>(aIter.next(), bIter.next());
|
|
1451
|
+
{II}}}
|
|
1452
|
+
{I}}};
|
|
1453
|
+
|
|
1454
|
+
{I}Spliterator<Pair<A, B>> split = Spliterators.spliterator(cIter, zipSize, characteristics);
|
|
1455
|
+
{I}return StreamSupport.stream(split, false);
|
|
1456
|
+
}}"""
|
|
1457
|
+
)
|
|
1458
|
+
)
|
|
1459
|
+
|
|
1460
|
+
verification_writer = io.StringIO()
|
|
1461
|
+
verification_writer.write(
|
|
1462
|
+
f"""\
|
|
1463
|
+
{I}/*
|
|
1464
|
+
{I} * Verify that the instances of the meta-model satisfy the invariants.
|
|
1465
|
+
{I} *
|
|
1466
|
+
"""
|
|
1467
|
+
)
|
|
1468
|
+
|
|
1469
|
+
# region Write an example usage
|
|
1470
|
+
|
|
1471
|
+
first_cls = (
|
|
1472
|
+
symbol_table.classes[0] if len(symbol_table.classes) > 0 else None
|
|
1473
|
+
) # type: Optional[intermediate.ClassUnion]
|
|
1474
|
+
|
|
1475
|
+
if first_cls is not None:
|
|
1476
|
+
cls_name = None # type: Optional[str]
|
|
1477
|
+
if isinstance(first_cls, intermediate.AbstractClass):
|
|
1478
|
+
cls_name = java_naming.interface_name(first_cls.name)
|
|
1479
|
+
elif isinstance(first_cls, intermediate.ConcreteClass):
|
|
1480
|
+
cls_name = java_naming.class_name(first_cls.name)
|
|
1481
|
+
else:
|
|
1482
|
+
assert_never(first_cls)
|
|
1483
|
+
|
|
1484
|
+
an_instance_variable = java_naming.variable_name(Identifier("an_instance"))
|
|
1485
|
+
|
|
1486
|
+
verification_writer.write(
|
|
1487
|
+
# We can not use textwrap.dedent since we indent everything including the
|
|
1488
|
+
# first line.
|
|
1489
|
+
f"""\
|
|
1490
|
+
{I} * <p>Here is an example how to verify an instance of {cls_name}:
|
|
1491
|
+
{I} * {{@code
|
|
1492
|
+
{I} * {cls_name} {an_instance_variable} = new {cls_name}(
|
|
1493
|
+
{I} * // ... some constructor arguments ...
|
|
1494
|
+
{I} * );
|
|
1495
|
+
{I} * for (Reporting.Error error : Verification.verify({an_instance_variable})) {{
|
|
1496
|
+
{I} * {I}System.out.println(error.cause + " at: " +
|
|
1497
|
+
{I} * {II}Reporting.generateJsonPath(error.PathSegments));
|
|
1498
|
+
{I} * }}
|
|
1499
|
+
{I} */
|
|
1500
|
+
"""
|
|
1501
|
+
)
|
|
1502
|
+
|
|
1503
|
+
# endregion
|
|
1504
|
+
|
|
1505
|
+
verification_writer = io.StringIO()
|
|
1506
|
+
verification_writer.write(
|
|
1507
|
+
"""\
|
|
1508
|
+
public class Verification {
|
|
1509
|
+
"""
|
|
1510
|
+
)
|
|
1511
|
+
|
|
1512
|
+
for i, verification_block in enumerate(verification_blocks):
|
|
1513
|
+
if i > 0:
|
|
1514
|
+
verification_writer.write("\n\n")
|
|
1515
|
+
|
|
1516
|
+
verification_writer.write(textwrap.indent(verification_block, I))
|
|
1517
|
+
|
|
1518
|
+
verification_writer.write("\n}")
|
|
1519
|
+
|
|
1520
|
+
if len(errors) > 0:
|
|
1521
|
+
return None, errors
|
|
1522
|
+
|
|
1523
|
+
blocks = [
|
|
1524
|
+
java_common.WARNING,
|
|
1525
|
+
Stripped(f"package {package}.verification;"),
|
|
1526
|
+
Stripped("\n".join(imports)),
|
|
1527
|
+
Stripped(verification_writer.getvalue()),
|
|
1528
|
+
java_common.WARNING,
|
|
1529
|
+
] # type: List[Stripped]
|
|
1530
|
+
|
|
1531
|
+
code = "\n\n".join(blocks)
|
|
1532
|
+
|
|
1533
|
+
return f"{code}\n", None
|
|
1534
|
+
|
|
1535
|
+
|
|
1536
|
+
# endregion
|