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.
Files changed (604) hide show
  1. aas_core_codegen/__init__.py +6 -0
  2. aas_core_codegen/__main__.py +8 -0
  3. aas_core_codegen/common.py +500 -0
  4. aas_core_codegen/cpp/__init__.py +1 -0
  5. aas_core_codegen/cpp/aas_common/__init__.py +6 -0
  6. aas_core_codegen/cpp/aas_common/_generate.py +713 -0
  7. aas_core_codegen/cpp/common.py +681 -0
  8. aas_core_codegen/cpp/constants/__init__.py +6 -0
  9. aas_core_codegen/cpp/constants/_generate.py +568 -0
  10. aas_core_codegen/cpp/description.py +654 -0
  11. aas_core_codegen/cpp/enhancing/__init__.py +4 -0
  12. aas_core_codegen/cpp/enhancing/_generate.py +993 -0
  13. aas_core_codegen/cpp/iteration/__init__.py +6 -0
  14. aas_core_codegen/cpp/iteration/_generate.py +2332 -0
  15. aas_core_codegen/cpp/jsonization/__init__.py +6 -0
  16. aas_core_codegen/cpp/jsonization/_generate.py +2619 -0
  17. aas_core_codegen/cpp/main.py +694 -0
  18. aas_core_codegen/cpp/naming.py +170 -0
  19. aas_core_codegen/cpp/optionaling.py +557 -0
  20. aas_core_codegen/cpp/pattern/__init__.py +6 -0
  21. aas_core_codegen/cpp/pattern/_generate.py +508 -0
  22. aas_core_codegen/cpp/revm/__init__.py +6 -0
  23. aas_core_codegen/cpp/revm/_generate.py +1149 -0
  24. aas_core_codegen/cpp/stringification/__init__.py +5 -0
  25. aas_core_codegen/cpp/stringification/_generate.py +955 -0
  26. aas_core_codegen/cpp/structure/__init__.py +7 -0
  27. aas_core_codegen/cpp/structure/_generate.py +1503 -0
  28. aas_core_codegen/cpp/transpilation.py +1383 -0
  29. aas_core_codegen/cpp/unrolling.py +159 -0
  30. aas_core_codegen/cpp/verification/__init__.py +6 -0
  31. aas_core_codegen/cpp/verification/_generate.py +3073 -0
  32. aas_core_codegen/cpp/visitation/__init__.py +6 -0
  33. aas_core_codegen/cpp/visitation/_generate.py +521 -0
  34. aas_core_codegen/cpp/wstringification/__init__.py +5 -0
  35. aas_core_codegen/cpp/wstringification/_generate.py +586 -0
  36. aas_core_codegen/cpp/xmlization/__init__.py +6 -0
  37. aas_core_codegen/cpp/xmlization/_generate.py +5373 -0
  38. aas_core_codegen/cpp/yielding.py +201 -0
  39. aas_core_codegen/csharp/__init__.py +1 -0
  40. aas_core_codegen/csharp/common.py +224 -0
  41. aas_core_codegen/csharp/constants/__init__.py +5 -0
  42. aas_core_codegen/csharp/constants/_generate.py +409 -0
  43. aas_core_codegen/csharp/copying/__init__.py +4 -0
  44. aas_core_codegen/csharp/copying/_generate.py +498 -0
  45. aas_core_codegen/csharp/description.py +1103 -0
  46. aas_core_codegen/csharp/enhancing/__init__.py +4 -0
  47. aas_core_codegen/csharp/enhancing/_generate.py +667 -0
  48. aas_core_codegen/csharp/jsonization/__init__.py +4 -0
  49. aas_core_codegen/csharp/jsonization/_generate.py +1630 -0
  50. aas_core_codegen/csharp/main.py +421 -0
  51. aas_core_codegen/csharp/naming.py +157 -0
  52. aas_core_codegen/csharp/reporting/__init__.py +4 -0
  53. aas_core_codegen/csharp/reporting/_generate.py +266 -0
  54. aas_core_codegen/csharp/stringification/__init__.py +4 -0
  55. aas_core_codegen/csharp/stringification/_generate.py +243 -0
  56. aas_core_codegen/csharp/structure/__init__.py +6 -0
  57. aas_core_codegen/csharp/structure/_generate.py +1341 -0
  58. aas_core_codegen/csharp/transpilation.py +990 -0
  59. aas_core_codegen/csharp/unrolling.py +211 -0
  60. aas_core_codegen/csharp/verification/__init__.py +6 -0
  61. aas_core_codegen/csharp/verification/_generate.py +1457 -0
  62. aas_core_codegen/csharp/visitation/__init__.py +5 -0
  63. aas_core_codegen/csharp/visitation/_generate.py +579 -0
  64. aas_core_codegen/csharp/xmlization/__init__.py +4 -0
  65. aas_core_codegen/csharp/xmlization/_generate.py +1980 -0
  66. aas_core_codegen/golang/__init__.py +1 -0
  67. aas_core_codegen/golang/aas_common/__init__.py +4 -0
  68. aas_core_codegen/golang/aas_common/_generate.py +152 -0
  69. aas_core_codegen/golang/common.py +303 -0
  70. aas_core_codegen/golang/constants/__init__.py +5 -0
  71. aas_core_codegen/golang/constants/_generate.py +339 -0
  72. aas_core_codegen/golang/description.py +501 -0
  73. aas_core_codegen/golang/enhancing/__init__.py +4 -0
  74. aas_core_codegen/golang/enhancing/_generate.py +527 -0
  75. aas_core_codegen/golang/jsonization/__init__.py +4 -0
  76. aas_core_codegen/golang/jsonization/_generate.py +1740 -0
  77. aas_core_codegen/golang/main.py +368 -0
  78. aas_core_codegen/golang/naming.py +412 -0
  79. aas_core_codegen/golang/pointering.py +631 -0
  80. aas_core_codegen/golang/reporting/__init__.py +4 -0
  81. aas_core_codegen/golang/reporting/_generate.py +218 -0
  82. aas_core_codegen/golang/stringification/__init__.py +4 -0
  83. aas_core_codegen/golang/stringification/_generate.py +394 -0
  84. aas_core_codegen/golang/structure/__init__.py +6 -0
  85. aas_core_codegen/golang/structure/_generate.py +1493 -0
  86. aas_core_codegen/golang/transpilation.py +1191 -0
  87. aas_core_codegen/golang/unrolling.py +159 -0
  88. aas_core_codegen/golang/verification/__init__.py +6 -0
  89. aas_core_codegen/golang/verification/_generate.py +1513 -0
  90. aas_core_codegen/golang/xmlization/__init__.py +4 -0
  91. aas_core_codegen/golang/xmlization/_generate.py +2507 -0
  92. aas_core_codegen/infer_for_schema/__init__.py +21 -0
  93. aas_core_codegen/infer_for_schema/_inline.py +693 -0
  94. aas_core_codegen/infer_for_schema/_len.py +527 -0
  95. aas_core_codegen/infer_for_schema/_pattern.py +311 -0
  96. aas_core_codegen/infer_for_schema/_set.py +394 -0
  97. aas_core_codegen/infer_for_schema/_stringify.py +201 -0
  98. aas_core_codegen/infer_for_schema/_types.py +135 -0
  99. aas_core_codegen/infer_for_schema/match.py +122 -0
  100. aas_core_codegen/intermediate/__init__.py +78 -0
  101. aas_core_codegen/intermediate/_hierarchy.py +397 -0
  102. aas_core_codegen/intermediate/_stringify.py +989 -0
  103. aas_core_codegen/intermediate/_translate.py +5128 -0
  104. aas_core_codegen/intermediate/_types.py +2901 -0
  105. aas_core_codegen/intermediate/construction.py +750 -0
  106. aas_core_codegen/intermediate/doc.py +344 -0
  107. aas_core_codegen/intermediate/pattern_verification.py +428 -0
  108. aas_core_codegen/intermediate/revm.py +985 -0
  109. aas_core_codegen/intermediate/type_inference.py +2266 -0
  110. aas_core_codegen/java/__init__.py +1 -0
  111. aas_core_codegen/java/common.py +197 -0
  112. aas_core_codegen/java/constants/__init__.py +5 -0
  113. aas_core_codegen/java/constants/_generate.py +334 -0
  114. aas_core_codegen/java/copying/__init__.py +4 -0
  115. aas_core_codegen/java/copying/_generate.py +502 -0
  116. aas_core_codegen/java/description.py +774 -0
  117. aas_core_codegen/java/enhancing/__init__.py +4 -0
  118. aas_core_codegen/java/enhancing/_generate.py +820 -0
  119. aas_core_codegen/java/generation/__init__.py +5 -0
  120. aas_core_codegen/java/generation/_generate.py +285 -0
  121. aas_core_codegen/java/jsonization/__init__.py +4 -0
  122. aas_core_codegen/java/jsonization/_generate.py +1472 -0
  123. aas_core_codegen/java/main.py +438 -0
  124. aas_core_codegen/java/naming.py +187 -0
  125. aas_core_codegen/java/optional.py +514 -0
  126. aas_core_codegen/java/reporting/__init__.py +4 -0
  127. aas_core_codegen/java/reporting/_generate.py +248 -0
  128. aas_core_codegen/java/stringification/__init__.py +4 -0
  129. aas_core_codegen/java/stringification/_generate.py +212 -0
  130. aas_core_codegen/java/structure/__init__.py +6 -0
  131. aas_core_codegen/java/structure/_generate.py +1767 -0
  132. aas_core_codegen/java/transpilation.py +1111 -0
  133. aas_core_codegen/java/verification/__init__.py +6 -0
  134. aas_core_codegen/java/verification/_generate.py +1536 -0
  135. aas_core_codegen/java/visitation/__init__.py +5 -0
  136. aas_core_codegen/java/visitation/_generate.py +689 -0
  137. aas_core_codegen/java/xmlization/__init__.py +4 -0
  138. aas_core_codegen/java/xmlization/_generate.py +2274 -0
  139. aas_core_codegen/jsonld/__init__.py +1 -0
  140. aas_core_codegen/jsonld/main.py +455 -0
  141. aas_core_codegen/jsonschema/__init__.py +1 -0
  142. aas_core_codegen/jsonschema/main.py +982 -0
  143. aas_core_codegen/main.py +245 -0
  144. aas_core_codegen/naming.py +133 -0
  145. aas_core_codegen/opcua/__init__.py +1 -0
  146. aas_core_codegen/opcua/main.py +1525 -0
  147. aas_core_codegen/opcua/naming.py +126 -0
  148. aas_core_codegen/parse/__init__.py +46 -0
  149. aas_core_codegen/parse/_rules.py +796 -0
  150. aas_core_codegen/parse/_stringify.py +532 -0
  151. aas_core_codegen/parse/_translate.py +3940 -0
  152. aas_core_codegen/parse/_types.py +973 -0
  153. aas_core_codegen/parse/retree/__init__.py +46 -0
  154. aas_core_codegen/parse/retree/_fix.py +434 -0
  155. aas_core_codegen/parse/retree/_parse.py +1143 -0
  156. aas_core_codegen/parse/retree/_render.py +298 -0
  157. aas_core_codegen/parse/retree/_stringify.py +199 -0
  158. aas_core_codegen/parse/retree/_types.py +362 -0
  159. aas_core_codegen/parse/retree/_visitor.py +70 -0
  160. aas_core_codegen/parse/tree.py +1303 -0
  161. aas_core_codegen/protobuf/__init__.py +1 -0
  162. aas_core_codegen/protobuf/common.py +225 -0
  163. aas_core_codegen/protobuf/description.py +1102 -0
  164. aas_core_codegen/protobuf/main.py +115 -0
  165. aas_core_codegen/protobuf/naming.py +143 -0
  166. aas_core_codegen/protobuf/structure/__init__.py +6 -0
  167. aas_core_codegen/protobuf/structure/_generate.py +502 -0
  168. aas_core_codegen/py.typed +1 -0
  169. aas_core_codegen/python/__init__.py +1 -0
  170. aas_core_codegen/python/aas_common/__init__.py +4 -0
  171. aas_core_codegen/python/aas_common/_generate.py +63 -0
  172. aas_core_codegen/python/common.py +406 -0
  173. aas_core_codegen/python/constants/__init__.py +5 -0
  174. aas_core_codegen/python/constants/_generate.py +377 -0
  175. aas_core_codegen/python/description.py +508 -0
  176. aas_core_codegen/python/jsonization/__init__.py +4 -0
  177. aas_core_codegen/python/jsonization/_generate.py +1391 -0
  178. aas_core_codegen/python/main.py +323 -0
  179. aas_core_codegen/python/naming.py +255 -0
  180. aas_core_codegen/python/stringification/__init__.py +4 -0
  181. aas_core_codegen/python/stringification/_generate.py +129 -0
  182. aas_core_codegen/python/structure/__init__.py +6 -0
  183. aas_core_codegen/python/structure/_generate.py +1801 -0
  184. aas_core_codegen/python/transpilation.py +958 -0
  185. aas_core_codegen/python/unrolling.py +156 -0
  186. aas_core_codegen/python/verification/__init__.py +6 -0
  187. aas_core_codegen/python/verification/_generate.py +1471 -0
  188. aas_core_codegen/python/xmlization/__init__.py +4 -0
  189. aas_core_codegen/python/xmlization/_generate.py +3003 -0
  190. aas_core_codegen/python_protobuf/__init__.py +1 -0
  191. aas_core_codegen/python_protobuf/main.py +1424 -0
  192. aas_core_codegen/python_protobuf/naming.py +85 -0
  193. aas_core_codegen/rdf_shacl/__init__.py +1 -0
  194. aas_core_codegen/rdf_shacl/_description.py +351 -0
  195. aas_core_codegen/rdf_shacl/common.py +206 -0
  196. aas_core_codegen/rdf_shacl/main.py +114 -0
  197. aas_core_codegen/rdf_shacl/naming.py +145 -0
  198. aas_core_codegen/rdf_shacl/rdf.py +435 -0
  199. aas_core_codegen/rdf_shacl/shacl.py +453 -0
  200. aas_core_codegen/run.py +124 -0
  201. aas_core_codegen/smoke/__init__.py +1 -0
  202. aas_core_codegen/smoke/main.py +219 -0
  203. aas_core_codegen/specific_implementations.py +72 -0
  204. aas_core_codegen/stringify.py +333 -0
  205. aas_core_codegen/typescript/__init__.py +1 -0
  206. aas_core_codegen/typescript/aas_common/__init__.py +4 -0
  207. aas_core_codegen/typescript/aas_common/_generate.py +472 -0
  208. aas_core_codegen/typescript/common.py +340 -0
  209. aas_core_codegen/typescript/constants/__init__.py +5 -0
  210. aas_core_codegen/typescript/constants/_generate.py +347 -0
  211. aas_core_codegen/typescript/description.py +530 -0
  212. aas_core_codegen/typescript/jsonization/__init__.py +4 -0
  213. aas_core_codegen/typescript/jsonization/_generate.py +1510 -0
  214. aas_core_codegen/typescript/main.py +258 -0
  215. aas_core_codegen/typescript/naming.py +189 -0
  216. aas_core_codegen/typescript/stringification/__init__.py +4 -0
  217. aas_core_codegen/typescript/stringification/_generate.py +367 -0
  218. aas_core_codegen/typescript/structure/__init__.py +6 -0
  219. aas_core_codegen/typescript/structure/_generate.py +2500 -0
  220. aas_core_codegen/typescript/transpilation.py +1051 -0
  221. aas_core_codegen/typescript/unrolling.py +159 -0
  222. aas_core_codegen/typescript/verification/__init__.py +6 -0
  223. aas_core_codegen/typescript/verification/_generate.py +1578 -0
  224. aas_core_codegen/xsd/__init__.py +1 -0
  225. aas_core_codegen/xsd/main.py +1187 -0
  226. aas_core_codegen/xsd/naming.py +83 -0
  227. aas_core_codegen/yielding/__init__.py +1 -0
  228. aas_core_codegen/yielding/flow.py +139 -0
  229. aas_core_codegen/yielding/linear.py +754 -0
  230. aas_core_codegen-0.0.16.dist-info/METADATA +211 -0
  231. aas_core_codegen-0.0.16.dist-info/RECORD +604 -0
  232. aas_core_codegen-0.0.16.dist-info/WHEEL +5 -0
  233. aas_core_codegen-0.0.16.dist-info/entry_points.txt +3 -0
  234. aas_core_codegen-0.0.16.dist-info/licenses/AUTHORS +9 -0
  235. aas_core_codegen-0.0.16.dist-info/licenses/LICENSE +23 -0
  236. aas_core_codegen-0.0.16.dist-info/top_level.txt +2 -0
  237. dev/continuous_integration/__init__.py +1 -0
  238. dev/continuous_integration/check_help_in_readme.py +208 -0
  239. dev/continuous_integration/check_init_and_pyproject_consistent.py +154 -0
  240. dev/continuous_integration/precommit.py +400 -0
  241. dev/dev_scripts/__init__.py +1 -0
  242. dev/dev_scripts/compare_rendered_regexes_against_source_py.py +42 -0
  243. dev/dev_scripts/copy_to_aas_core3_cpp.py +100 -0
  244. dev/dev_scripts/copy_to_aas_core3_java.py +90 -0
  245. dev/dev_scripts/download_latest_aas_core_meta_v3.py +114 -0
  246. dev/dev_scripts/draw_bipartite_graph_based_on_lines.py +37 -0
  247. dev/dev_scripts/run_tests_with_rerecord.py +69 -0
  248. dev/dev_scripts/update_to_aas_core_meta.py +174 -0
  249. dev/integration_tests/input/jsonschema/boilerplate/main.py +55 -0
  250. dev/integration_tests/input/meta_model.py +38 -0
  251. dev/integration_tests/input/python/boilerplate/main.py +153 -0
  252. dev/integration_tests/main.py +258 -0
  253. dev/test_data/csharp/test_structure/concrete_class_with_descendants/meta_model.py +15 -0
  254. dev/test_data/csharp/test_structure/constructor_without_arguments/all_properties_optional/meta_model.py +9 -0
  255. dev/test_data/csharp/test_structure/constructor_without_arguments/no_properties/meta_model.py +6 -0
  256. dev/test_data/csharp/test_verification/builtin_functions/len/on_list/meta_model.py +20 -0
  257. dev/test_data/csharp/test_verification/builtin_functions/len/on_str/meta_model.py +16 -0
  258. dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/as_prefix/meta_model.py +8 -0
  259. dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/as_suffix/meta_model.py +8 -0
  260. dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_group_with_quantifier/meta_model.py +8 -0
  261. dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_the_middle/meta_model.py +8 -0
  262. dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/in_union/meta_model.py +8 -0
  263. dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/single_utf32_literal/meta_model.py +8 -0
  264. dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/with_quantifier_within_group/meta_model.py +8 -0
  265. dev/test_data/csharp/test_verification/pattern_verification/utf32_as_literal/with_quantifier_without_group/meta_model.py +8 -0
  266. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/at_the_beginning/meta_model.py +8 -0
  267. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/at_the_end/meta_model.py +8 -0
  268. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/in_the_middle/meta_model.py +8 -0
  269. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/multiple/meta_model.py +8 -0
  270. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/single/meta_model.py +8 -0
  271. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/literal/single_with_quantifier/meta_model.py +8 -0
  272. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/mixed_with_non_utf32/meta_model.py +8 -0
  273. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/more_than_two_high_surrogates/meta_model.py +8 -0
  274. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/multiple_utf32_ranges/meta_model.py +8 -0
  275. 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
  276. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/same_high_surrogate/meta_model.py +8 -0
  277. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/same_high_surrogate_with_quantifier/meta_model.py +8 -0
  278. dev/test_data/csharp/test_verification/pattern_verification/utf32_in_character_set/range/two_high_surrogates/meta_model.py +8 -0
  279. dev/test_data/intermediate/expected/class/empty/meta_model.py +6 -0
  280. dev/test_data/intermediate/expected/class/implementation_specific_method/meta_model.py +8 -0
  281. dev/test_data/intermediate/expected/class/inheritance/meta_model.py +41 -0
  282. dev/test_data/intermediate/expected/class/methods_with_contracts/meta_model.py +15 -0
  283. dev/test_data/intermediate/expected/class/only_method_no_property/meta_model.py +7 -0
  284. dev/test_data/intermediate/expected/class/only_property_no_method/meta_model.py +9 -0
  285. dev/test_data/intermediate/expected/constant/constant_set/of_enum/meta_model.py +12 -0
  286. dev/test_data/intermediate/expected/constant/constant_set/of_str/meta_model.py +4 -0
  287. dev/test_data/intermediate/expected/constant/constant_set/with_description/meta_model.py +6 -0
  288. dev/test_data/intermediate/expected/constant/constant_set/with_superset_of/meta_model.py +14 -0
  289. dev/test_data/intermediate/expected/constant/constant_str/only_value/meta_model.py +7 -0
  290. dev/test_data/intermediate/expected/constant/constant_str/with_description/meta_model.py +5 -0
  291. dev/test_data/intermediate/expected/documentation/docstring_with_special_characters_in_literal/meta_model.py +20 -0
  292. dev/test_data/intermediate/expected/documentation/docstring_with_special_characters_outside_literal/meta_model.py +20 -0
  293. dev/test_data/intermediate/expected/empty/meta_model.py +2 -0
  294. dev/test_data/intermediate/expected/enumeration/meta_model.py +9 -0
  295. dev/test_data/intermediate/expected/interface/basic/meta_model.py +14 -0
  296. dev/test_data/intermediate/expected/interface/empty/meta_model.py +7 -0
  297. dev/test_data/intermediate/expected/interface/inheritance/meta_model.py +27 -0
  298. dev/test_data/intermediate/expected/interface/method_signature/meta_model.py +10 -0
  299. dev/test_data/intermediate/expected/interface/only_constructor/meta_model.py +11 -0
  300. dev/test_data/intermediate/expected/method/non_mutating/implementation_specific/meta_model.py +12 -0
  301. dev/test_data/intermediate/expected/method/non_mutating/understood/meta_model.py +11 -0
  302. dev/test_data/intermediate/expected/type_annotation/atomic/meta_model.py +9 -0
  303. dev/test_data/intermediate/expected/type_annotation/subscripted/class/meta_model.py +13 -0
  304. dev/test_data/intermediate/expected/type_annotation/subscripted/primitive/meta_model.py +9 -0
  305. dev/test_data/intermediate/unexpected/constant_set/of_enum/enumeration_literals_in_subset_outside_of_superset/meta_model.py +20 -0
  306. dev/test_data/intermediate/unexpected/constant_set/of_enum/invalid_literal/meta_model.py +11 -0
  307. dev/test_data/intermediate/unexpected/constant_set/of_enum/mismatch_between_enumeration_and_literal/meta_model.py +30 -0
  308. dev/test_data/intermediate/unexpected/constant_set/of_enum/mismatch_in_enumerations_between_subset_and_superset/meta_model.py +21 -0
  309. dev/test_data/intermediate/unexpected/constant_set/of_str/literals_in_subset_outside_of_superset/meta_model.py +18 -0
  310. dev/test_data/intermediate/unexpected/constant_set/of_str/mismatch_between_type_annotation_and_literals/meta_model.py +10 -0
  311. dev/test_data/intermediate/unexpected/constant_set/of_str/superset_and_subset_mismatch_in_type/meta_model.py +12 -0
  312. dev/test_data/intermediate/unexpected/constraints/dangling_constraintref/meta_model.py +18 -0
  313. dev/test_data/intermediate/unexpected/constraints/duplicate_constraints/meta_model.py +20 -0
  314. dev/test_data/intermediate/unexpected/documentation/unexpected_documentation_elements/meta_model.py +34 -0
  315. dev/test_data/intermediate/unexpected/invariant/class_invariant_uses_re/meta_model.py +10 -0
  316. dev/test_data/intermediate/unexpected/invariant/invariant_of_constrained_primitive_uses_re/meta_model.py +7 -0
  317. dev/test_data/intermediate/unexpected/invariant/unexpected_argument_count_to_len/meta_model.py +20 -0
  318. dev/test_data/intermediate/unexpected/invariant/unhandled_built_in_function/meta_model.py +16 -0
  319. dev/test_data/intermediate/unexpected/method_definitions/non_constant_default/meta_model.py +7 -0
  320. dev/test_data/intermediate/unexpected/optional_constructor_arguments_wo_default/default_non_none/meta_model.py +16 -0
  321. dev/test_data/intermediate/unexpected/optional_constructor_arguments_wo_default/no_default/meta_model.py +16 -0
  322. dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/after_inheritance/meta_model.py +58 -0
  323. dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/type_missmatch/meta_model.py +9 -0
  324. dev/test_data/intermediate/unexpected/properties_and_constructor_arguments_do_not_match/within_class/meta_model.py +22 -0
  325. dev/test_data/jsonschema/test_main/regression_when_len_constraints_on_inherited_property/meta_model.py +28 -0
  326. dev/test_data/opcua/test_main/abstract_and_concrete_classes/meta_model.py +37 -0
  327. dev/test_data/opcua/test_main/classes_with_invariants/meta_model.py +21 -0
  328. dev/test_data/opcua/test_main/concrete_class_with_descendant/meta_model.py +27 -0
  329. dev/test_data/opcua/test_main/concrete_class_with_enum/meta_model.py +21 -0
  330. dev/test_data/opcua/test_main/concrete_class_with_list_of_instances/meta_model.py +21 -0
  331. dev/test_data/opcua/test_main/concrete_class_with_primitive_attributes/meta_model.py +41 -0
  332. dev/test_data/opcua/test_main/concrete_class_with_string/meta_model.py +13 -0
  333. dev/test_data/opcua/test_main/constrained_primitive/meta_model.py +20 -0
  334. dev/test_data/opcua/test_main/multiple_inheritance/meta_model.py +25 -0
  335. dev/test_data/parse/expected/constant/constant_set/of_enum/meta_model.py +12 -0
  336. dev/test_data/parse/expected/constant/constant_set/of_str/meta_model.py +4 -0
  337. dev/test_data/parse/expected/constant/constant_set/with_description/meta_model.py +6 -0
  338. dev/test_data/parse/expected/constant/constant_set/with_superset_of/meta_model.py +14 -0
  339. dev/test_data/parse/expected/constant/constant_str/only_value/meta_model.py +7 -0
  340. dev/test_data/parse/expected/constant/constant_str/with_description/meta_model.py +5 -0
  341. dev/test_data/parse/expected/enum/ok/meta_model.py +15 -0
  342. dev/test_data/parse/expected/implementation_specific_class/properties_and_methods_in_implementation_specific_class/meta_model.py +17 -0
  343. dev/test_data/parse/expected/inheritance/basic/meta_model.py +11 -0
  344. dev/test_data/parse/expected/inheritance/diamond/meta_model.py +26 -0
  345. dev/test_data/parse/expected/inheritance/inheritance_from_concrete_class/meta_model.py +10 -0
  346. dev/test_data/parse/expected/invariants/in_relation/meta_model.py +16 -0
  347. dev/test_data/parse/expected/method/arguments/meta_model.py +7 -0
  348. dev/test_data/parse/expected/method/basic/meta_model.py +7 -0
  349. dev/test_data/parse/expected/method/contracts/condition_as_keyword_argument/meta_model.py +8 -0
  350. dev/test_data/parse/expected/method/contracts/condition_as_positional_argument/meta_model.py +8 -0
  351. dev/test_data/parse/expected/method/contracts/description_as_keyword_argument/meta_model.py +8 -0
  352. dev/test_data/parse/expected/method/contracts/description_as_positional_argument/meta_model.py +8 -0
  353. dev/test_data/parse/expected/method/contracts/multiple_contracts_in_order/meta_model.py +17 -0
  354. dev/test_data/parse/expected/method/contracts/postcondition/basic/meta_model.py +10 -0
  355. dev/test_data/parse/expected/method/contracts/postcondition/snapshot/with_keyword_arguments/meta_model.py +9 -0
  356. dev/test_data/parse/expected/method/contracts/postcondition/snapshot/with_positional_arguments/meta_model.py +9 -0
  357. dev/test_data/parse/expected/method/default/meta_model.py +9 -0
  358. dev/test_data/parse/expected/method/description/meta_model.py +8 -0
  359. dev/test_data/parse/expected/method/is_implementation_specific/meta_model.py +8 -0
  360. dev/test_data/parse/expected/method/non_mutating/meta_model.py +11 -0
  361. dev/test_data/parse/expected/method/returns_none/meta_model.py +7 -0
  362. dev/test_data/parse/expected/method/returns_something/meta_model.py +7 -0
  363. dev/test_data/parse/expected/single_class/description/meta_model.py +12 -0
  364. dev/test_data/parse/expected/single_class/empty/meta_model.py +6 -0
  365. dev/test_data/parse/expected/single_class/property/description/meta_model.py +14 -0
  366. dev/test_data/parse/expected/single_class/property/mandatory/meta_model.py +6 -0
  367. dev/test_data/parse/expected/single_class/property/optional/meta_model.py +6 -0
  368. dev/test_data/parse/expected/single_class/property/recursion_to_entity/meta_model.py +6 -0
  369. dev/test_data/parse/unexpected/class_decorators/non_name_decorator/meta_model.py +7 -0
  370. dev/test_data/parse/unexpected/class_decorators/unknown_decorator/meta_model.py +7 -0
  371. dev/test_data/parse/unexpected/class_definitions/is_abstract_and_implementation_specific/meta_model.py +8 -0
  372. dev/test_data/parse/unexpected/class_definitions/unexpected_docstring_before_a_method/meta_model.py +11 -0
  373. dev/test_data/parse/unexpected/class_definitions/unexpected_docstring_for_a_pass/meta_model.py +9 -0
  374. dev/test_data/parse/unexpected/class_definitions/unexpected_double_description_for_a_property/meta_model.py +10 -0
  375. dev/test_data/parse/unexpected/class_inheritances/inheriting_from_implementation_specific_parent/meta_model.py +20 -0
  376. dev/test_data/parse/unexpected/class_inheritances/non_name_super_class/meta_model.py +6 -0
  377. dev/test_data/parse/unexpected/enum/expression_as_assignment_value/meta_model.py +6 -0
  378. dev/test_data/parse/unexpected/enum/non_assignment/meta_model.py +8 -0
  379. dev/test_data/parse/unexpected/enum/non_string_literal/meta_model.py +6 -0
  380. dev/test_data/parse/unexpected/enum/unexpected_inheritance/meta_model.py +6 -0
  381. dev/test_data/parse/unexpected/method_contracts/contract/non_lambda_condition/meta_model.py +8 -0
  382. dev/test_data/parse/unexpected/method_contracts/contract/non_string_literal_description/meta_model.py +8 -0
  383. dev/test_data/parse/unexpected/method_contracts/contract/without_any_arguments/meta_model.py +8 -0
  384. dev/test_data/parse/unexpected/method_contracts/contract/without_condition/meta_model.py +8 -0
  385. dev/test_data/parse/unexpected/method_contracts/postcondition/OLD_in_postcondition_without_snapshot/meta_model.py +8 -0
  386. dev/test_data/parse/unexpected/method_contracts/postcondition/argument_missing_in_function/meta_model.py +8 -0
  387. dev/test_data/parse/unexpected/method_contracts/precondition/argument_missing_in_function/meta_model.py +8 -0
  388. dev/test_data/parse/unexpected/method_contracts/snapshot/argument_missing_in_function/meta_model.py +8 -0
  389. dev/test_data/parse/unexpected/method_contracts/snapshot/capture_not_a_lambda/meta_model.py +8 -0
  390. dev/test_data/parse/unexpected/method_contracts/snapshot/invalid_name/meta_model.py +8 -0
  391. dev/test_data/parse/unexpected/method_contracts/snapshot/name_not_a_string_literal/meta_model.py +8 -0
  392. dev/test_data/parse/unexpected/method_contracts/snapshot/without_a_capture/meta_model.py +8 -0
  393. dev/test_data/parse/unexpected/method_contracts/snapshot/without_a_name/meta_model.py +8 -0
  394. dev/test_data/parse/unexpected/method_decorators/non_mutating/non_mutating_constructor/meta_model.py +8 -0
  395. dev/test_data/parse/unexpected/method_decorators/non_mutating/non_mutating_verification_function/meta_model.py +8 -0
  396. dev/test_data/parse/unexpected/method_decorators/non_name_decorator/meta_model.py +8 -0
  397. dev/test_data/parse/unexpected/method_decorators/unknown_call_decorator/meta_model.py +8 -0
  398. dev/test_data/parse/unexpected/method_decorators/unknown_name_decorator/meta_model.py +8 -0
  399. dev/test_data/parse/unexpected/method_definitions/argument_with_final/meta_model.py +7 -0
  400. dev/test_data/parse/unexpected/method_definitions/argument_without_a_type_annotation/meta_model.py +7 -0
  401. dev/test_data/parse/unexpected/method_definitions/default_for_self/meta_model.py +7 -0
  402. dev/test_data/parse/unexpected/method_definitions/dunder/meta_model.py +7 -0
  403. dev/test_data/parse/unexpected/method_definitions/init_with_return_type/meta_model.py +7 -0
  404. dev/test_data/parse/unexpected/method_definitions/with_keyword_only_arguments/meta_model.py +7 -0
  405. dev/test_data/parse/unexpected/method_definitions/with_positional_arguments/meta_model.py +7 -0
  406. dev/test_data/parse/unexpected/method_definitions/with_type_annotation_for_self/meta_model.py +7 -0
  407. dev/test_data/parse/unexpected/method_definitions/with_variable_arguments/meta_model.py +7 -0
  408. dev/test_data/parse/unexpected/method_definitions/with_variable_keyword_arguments/meta_model.py +7 -0
  409. dev/test_data/parse/unexpected/method_definitions/without_arguments/meta_model.py +7 -0
  410. dev/test_data/parse/unexpected/method_definitions/without_self/meta_model.py +7 -0
  411. dev/test_data/parse/unexpected/method_definitions/without_type_annotation_for_result/meta_model.py +7 -0
  412. dev/test_data/parse/unexpected/property_definitions/final_without_subscript/meta_model.py +6 -0
  413. dev/test_data/parse/unexpected/property_definitions/nested_final/meta_model.py +6 -0
  414. dev/test_data/parse/unexpected/property_definitions/non_simple/meta_model.py +6 -0
  415. dev/test_data/parse/unexpected/property_definitions/unexpected_assignment/meta_model.py +6 -0
  416. dev/test_data/parse/unexpected/property_definitions/unexpected_non_name_property/meta_model.py +6 -0
  417. dev/test_data/parse/unexpected/property_definitions/without_type_annotation/meta_model.py +6 -0
  418. dev/test_data/parse/unexpected/symbol_table/constant_set_with_a_non_set_subset/meta_model.py +6 -0
  419. dev/test_data/parse/unexpected/symbol_table/dangling_inheritance/meta_model.py +6 -0
  420. dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_a_property/meta_model.py +6 -0
  421. dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_an_argument/meta_model.py +7 -0
  422. dev/test_data/parse/unexpected/symbol_table/dangling_reference_in_type_annotation_of_constant_set/meta_model.py +6 -0
  423. dev/test_data/parse/unexpected/symbol_table/dangling_subset_in_constant_set/meta_model.py +4 -0
  424. dev/test_data/parse/unexpected/symbol_table/inheritance_from_non_class/meta_model.py +10 -0
  425. dev/test_data/parse_retree/expected/character_set/common_escaping/source.py +1 -0
  426. dev/test_data/parse_retree/expected/character_set/complementing/double_caret/source.py +1 -0
  427. dev/test_data/parse_retree/expected/character_set/complementing/multiple_ranges/source.py +1 -0
  428. dev/test_data/parse_retree/expected/character_set/complementing/suffix_dash/source.py +1 -0
  429. dev/test_data/parse_retree/expected/character_set/escape_first_caret/source.py +1 -0
  430. dev/test_data/parse_retree/expected/character_set/literals_which_need_no_escaping_in_characters_set_but_need_escaping_outside/source.py +1 -0
  431. dev/test_data/parse_retree/expected/character_set/multiple_ranges/source.py +1 -0
  432. dev/test_data/parse_retree/expected/character_set/single_literal/source.py +1 -0
  433. dev/test_data/parse_retree/expected/character_set/single_range/source.py +1 -0
  434. dev/test_data/parse_retree/expected/character_set/unescaped_dash/only_dash/source.py +1 -0
  435. dev/test_data/parse_retree/expected/character_set/unescaped_dash/prefix_dash/source.py +1 -0
  436. dev/test_data/parse_retree/expected/character_set/unescaped_dash/suffix_dash/source.py +1 -0
  437. dev/test_data/parse_retree/expected/dot/source.py +1 -0
  438. dev/test_data/parse_retree/expected/empty/group/source.py +1 -0
  439. dev/test_data/parse_retree/expected/empty/group_in_a_group/source.py +1 -0
  440. dev/test_data/parse_retree/expected/empty/group_of_union_of_empty_concatenations/source.py +1 -0
  441. dev/test_data/parse_retree/expected/empty/regex/source.py +1 -0
  442. dev/test_data/parse_retree/expected/empty/union_of_empty_concatenations/source.py +1 -0
  443. dev/test_data/parse_retree/expected/escaped_literals/source.py +1 -0
  444. dev/test_data/parse_retree/expected/formatted_value/at_the_beginning/source.py +1 -0
  445. dev/test_data/parse_retree/expected/formatted_value/at_the_end/source.py +1 -0
  446. dev/test_data/parse_retree/expected/formatted_value/in_the_middle/source.py +1 -0
  447. dev/test_data/parse_retree/expected/formatted_value/single_formatted_value/source.py +1 -0
  448. dev/test_data/parse_retree/expected/literal/source.py +1 -0
  449. dev/test_data/parse_retree/expected/quantifier/greedy/at_least_3/source.py +1 -0
  450. dev/test_data/parse_retree/expected/quantifier/greedy/at_least_one/source.py +1 -0
  451. dev/test_data/parse_retree/expected/quantifier/greedy/at_most_3/source.py +1 -0
  452. dev/test_data/parse_retree/expected/quantifier/greedy/exactly_3/source.py +1 -0
  453. dev/test_data/parse_retree/expected/quantifier/greedy/maybe/source.py +1 -0
  454. dev/test_data/parse_retree/expected/quantifier/greedy/zero_or_more/source.py +1 -0
  455. dev/test_data/parse_retree/expected/quantifier/non_greedy/at_least_3/source.py +1 -0
  456. dev/test_data/parse_retree/expected/quantifier/non_greedy/at_least_one/source.py +1 -0
  457. dev/test_data/parse_retree/expected/quantifier/non_greedy/at_most_3/source.py +1 -0
  458. dev/test_data/parse_retree/expected/quantifier/non_greedy/exactly_3/source.py +1 -0
  459. dev/test_data/parse_retree/expected/quantifier/non_greedy/maybe/source.py +1 -0
  460. dev/test_data/parse_retree/expected/quantifier/non_greedy/zero_or_more/source.py +1 -0
  461. dev/test_data/parse_retree/expected/quantifier/on_a_character_set/source.py +1 -0
  462. dev/test_data/parse_retree/expected/quantifier/on_a_formatted_value/source.py +1 -0
  463. dev/test_data/parse_retree/expected/quantifier/on_a_group/source.py +1 -0
  464. dev/test_data/parse_retree/expected/quantifier/on_a_literal/source.py +1 -0
  465. dev/test_data/parse_retree/expected/start_and_stop_symbols/double_end_symbol/source.py +1 -0
  466. dev/test_data/parse_retree/expected/start_and_stop_symbols/double_start_symbol/source.py +1 -0
  467. dev/test_data/parse_retree/expected/start_and_stop_symbols/end_symbol_in_the_middle/source.py +1 -0
  468. dev/test_data/parse_retree/expected/start_and_stop_symbols/only_start_symbol/source.py +1 -0
  469. dev/test_data/parse_retree/expected/start_and_stop_symbols/only_stop_symbol/source.py +1 -0
  470. dev/test_data/parse_retree/expected/start_and_stop_symbols/start_symbol_at_the_beginning/source.py +1 -0
  471. dev/test_data/parse_retree/expected/start_and_stop_symbols/start_symbol_in_the_middle/source.py +1 -0
  472. dev/test_data/parse_retree/expected/start_and_stop_symbols/stop_symbol_at_the_end/source.py +1 -0
  473. dev/test_data/parse_retree/expected/union/of_character_sets/source.py +1 -0
  474. dev/test_data/parse_retree/expected/union/of_groups/source.py +1 -0
  475. dev/test_data/parse_retree/expected/union/of_string_literals/source.py +1 -0
  476. dev/test_data/parse_retree/expected/union/within_group/source.py +1 -0
  477. dev/test_data/parse_retree/expected/whitespace/source.py +1 -0
  478. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/Uxxxxxxxx_out_of_range/source.py +1 -0
  479. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/only_backslash/source.py +1 -0
  480. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_Uxxxxxxxx/source.py +1 -0
  481. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_uxxxx/source.py +1 -0
  482. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/short_x/source.py +1 -0
  483. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unexpected_escaping/source.py +1 -0
  484. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/digit/source.py +1 -0
  485. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_digit/source.py +1 -0
  486. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_whitespace/source.py +1 -0
  487. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/not_word/source.py +1 -0
  488. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/whitespace/source.py +1 -0
  489. dev/test_data/parse_retree/unexpected/improper_escaping/character_literal/unhandled/word/source.py +1 -0
  490. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/Uxxxxxxxx_out_of_range/source.py +1 -0
  491. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/only_backslash/source.py +1 -0
  492. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_Uxxxxxxxx/source.py +1 -0
  493. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_uxxxx/source.py +1 -0
  494. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/short_x/source.py +1 -0
  495. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unexpected_escaping/source.py +1 -0
  496. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/digit/source.py +1 -0
  497. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_digit/source.py +1 -0
  498. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_whitespace/source.py +1 -0
  499. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/not_word/source.py +1 -0
  500. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/whitespace/source.py +1 -0
  501. dev/test_data/parse_retree/unexpected/improper_escaping/range_character/unhandled/word/source.py +1 -0
  502. dev/test_data/parse_retree/unexpected/invalid_character_range/source.py +1 -0
  503. dev/test_data/parse_retree/unexpected/invalid_quantifier/at_least_x/source.py +1 -0
  504. dev/test_data/parse_retree/unexpected/invalid_quantifier/between_3_and_x/source.py +1 -0
  505. dev/test_data/parse_retree/unexpected/invalid_quantifier/exactly_x/source.py +1 -0
  506. dev/test_data/parse_retree/unexpected/unhandled_group_directives/source.py +1 -0
  507. dev/test_data/parse_retree/unexpected/unterminated/character_set/source.py +1 -0
  508. dev/test_data/parse_retree/unexpected/unterminated/group/source.py +1 -0
  509. dev/test_data/parse_retree/unexpected/unterminated/group_of_union_of_empty_concatenations/source.py +1 -0
  510. dev/test_data/parse_retree/unexpected/unterminated/quantifier/source.py +1 -0
  511. dev/test_data/parse_retree/unexpected/unterminated/quantifier_with_comma/source.py +1 -0
  512. dev/test_data/parse_retree/unexpected/unterminated/quantifier_with_number_and_comma/source.py +1 -0
  513. dev/test_data/proto/test_main/expected/abstract_and_concrete_classes/meta_model.py +37 -0
  514. dev/test_data/proto/test_main/expected/concrete_class_with_descendants/meta_model.py +30 -0
  515. dev/test_data/proto/test_main/expected/concrete_class_with_enum/meta_model.py +21 -0
  516. dev/test_data/proto/test_main/expected/concrete_class_with_list_of_instances/meta_model.py +21 -0
  517. dev/test_data/proto/test_main/expected/concrete_class_with_primitive_attributes/meta_model.py +41 -0
  518. dev/test_data/python_protobuf/test_main/abstract_and_concrete_classes/expected_output/pbization.py +532 -0
  519. dev/test_data/python_protobuf/test_main/abstract_and_concrete_classes/meta_model.py +37 -0
  520. dev/test_data/python_protobuf/test_main/concrete_class_with_descendant/expected_output/pbization.py +527 -0
  521. dev/test_data/python_protobuf/test_main/concrete_class_with_descendant/meta_model.py +27 -0
  522. dev/test_data/python_protobuf/test_main/concrete_class_with_enum/expected_output/pbization.py +290 -0
  523. dev/test_data/python_protobuf/test_main/concrete_class_with_enum/meta_model.py +21 -0
  524. dev/test_data/python_protobuf/test_main/concrete_class_with_list_of_instances/expected_output/pbization.py +328 -0
  525. dev/test_data/python_protobuf/test_main/concrete_class_with_list_of_instances/meta_model.py +23 -0
  526. dev/test_data/python_protobuf/test_main/concrete_class_with_primitive_attributes/expected_output/pbization.py +274 -0
  527. dev/test_data/python_protobuf/test_main/concrete_class_with_primitive_attributes/meta_model.py +41 -0
  528. dev/test_data/rdf_shacl/test_main/expected/regression_when_lang_string_class_is_missing/meta_model.py +29 -0
  529. dev/test_data/rdf_shacl/test_main/expected/regression_when_len_constraints_on_inherited_property/meta_model.py +27 -0
  530. dev/test_data/rdf_shacl/test_main/unexpected/regression_len_constraint_on_class_property/meta_model.py +61 -0
  531. dev/test_data/real_meta_models/aas_core_meta.v3.py +5721 -0
  532. dev/test_data/smoke/test_main/unexpected/infer_for_schema_error/meta_model.py +12 -0
  533. dev/test_data/smoke/test_main/unexpected/intermediate_error/meta_model.py +18 -0
  534. dev/test_data/smoke/test_main/unexpected/parse_error/meta_model.py +5 -0
  535. dev/test_data/smoke/test_main/unexpected/pattern_verification_unparsable_regex/direct_match/meta_model.py +8 -0
  536. dev/test_data/smoke/test_main/unexpected/type_error/meta_model.py +18 -0
  537. dev/tests/__init__.py +1 -0
  538. dev/tests/common.py +197 -0
  539. dev/tests/cpp/__init__.py +0 -0
  540. dev/tests/cpp/test_common.py +32 -0
  541. dev/tests/cpp/test_main.py +144 -0
  542. dev/tests/cpp/test_pattern.py +188 -0
  543. dev/tests/cpp/test_verification.py +189 -0
  544. dev/tests/cpp/test_yielding.py +225 -0
  545. dev/tests/csharp/__init__.py +0 -0
  546. dev/tests/csharp/live_test_main.py +109 -0
  547. dev/tests/csharp/test_common.py +28 -0
  548. dev/tests/csharp/test_description.py +684 -0
  549. dev/tests/csharp/test_main.py +129 -0
  550. dev/tests/csharp/test_structure.py +93 -0
  551. dev/tests/csharp/test_verification.py +82 -0
  552. dev/tests/description.py +29 -0
  553. dev/tests/golang/__init__.py +0 -0
  554. dev/tests/golang/test_common.py +78 -0
  555. dev/tests/golang/test_main.py +128 -0
  556. dev/tests/infer_for_schema/__init__.py +0 -0
  557. dev/tests/infer_for_schema/common.py +47 -0
  558. dev/tests/infer_for_schema/test_len_on_properties.py +955 -0
  559. dev/tests/infer_for_schema/test_len_on_self.py +580 -0
  560. dev/tests/infer_for_schema/test_patterns_on_properties.py +686 -0
  561. dev/tests/infer_for_schema/test_patterns_on_self.py +258 -0
  562. dev/tests/infer_for_schema/test_property_in_set_of_enumeration_literals.py +600 -0
  563. dev/tests/infer_for_schema/test_property_in_set_of_primitives.py +549 -0
  564. dev/tests/intermediate/__init__.py +0 -0
  565. dev/tests/intermediate/test_constructor.py +719 -0
  566. dev/tests/intermediate/test_hierarchy.py +221 -0
  567. dev/tests/intermediate/test_revm.py +134 -0
  568. dev/tests/intermediate/test_translate.py +337 -0
  569. dev/tests/intermediate/test_type_inference.py +333 -0
  570. dev/tests/intermediate/test_types.py +169 -0
  571. dev/tests/java/__init__.py +0 -0
  572. dev/tests/java/test_common.py +20 -0
  573. dev/tests/java/test_description.py +128 -0
  574. dev/tests/java/test_main.py +234 -0
  575. dev/tests/jsonld_context/test_main.py +79 -0
  576. dev/tests/opcua/__init__.py +3 -0
  577. dev/tests/opcua/test_main.py +110 -0
  578. dev/tests/our_jsonschema/__init__.py +3 -0
  579. dev/tests/our_jsonschema/test_main.py +232 -0
  580. dev/tests/parse/__init__.py +0 -0
  581. dev/tests/parse/test_parse.py +503 -0
  582. dev/tests/parse/test_retree.py +272 -0
  583. dev/tests/proto/__init__.py +0 -0
  584. dev/tests/proto/test_main.py +112 -0
  585. dev/tests/python/__init__.py +0 -0
  586. dev/tests/python/test_common.py +124 -0
  587. dev/tests/python/test_main.py +126 -0
  588. dev/tests/python/test_xml_playground.py +254 -0
  589. dev/tests/python_protobuf/__init__.py +0 -0
  590. dev/tests/python_protobuf/test_main.py +111 -0
  591. dev/tests/rdf_shacl/__init__.py +0 -0
  592. dev/tests/rdf_shacl/test_common.py +32 -0
  593. dev/tests/rdf_shacl/test_description.py +223 -0
  594. dev/tests/rdf_shacl/test_main.py +194 -0
  595. dev/tests/smoke/__init__.py +0 -0
  596. dev/tests/smoke/test_main.py +83 -0
  597. dev/tests/test_common.py +94 -0
  598. dev/tests/typescript/__init__.py +0 -0
  599. dev/tests/typescript/test_common.py +108 -0
  600. dev/tests/typescript/test_main.py +125 -0
  601. dev/tests/xsd/__init__.py +0 -0
  602. dev/tests/xsd/test_main.py +227 -0
  603. dev/tests/yielding/__init__.py +0 -0
  604. dev/tests/yielding/test_linear.py +558 -0
@@ -0,0 +1,1493 @@
1
+ """Generate the Golang data structures from the intermediate representation."""
2
+ import io
3
+ import itertools
4
+ import textwrap
5
+ from typing import (
6
+ Optional,
7
+ Dict,
8
+ List,
9
+ Tuple,
10
+ cast,
11
+ Union,
12
+ )
13
+
14
+ from icontract import ensure, require
15
+
16
+ from aas_core_codegen import intermediate
17
+ from aas_core_codegen import specific_implementations
18
+ from aas_core_codegen.common import (
19
+ Error,
20
+ Identifier,
21
+ assert_never,
22
+ Stripped,
23
+ indent_but_first_line,
24
+ )
25
+ from aas_core_codegen.golang import (
26
+ common as golang_common,
27
+ naming as golang_naming,
28
+ description as golang_description,
29
+ )
30
+ from aas_core_codegen.golang.common import (
31
+ INDENT as I,
32
+ INDENT2 as II,
33
+ )
34
+
35
+
36
+ # region Checks
37
+
38
+
39
+ def _human_readable_identifier(
40
+ something: Union[
41
+ intermediate.Enumeration,
42
+ intermediate.AbstractClass,
43
+ intermediate.ConcreteClass,
44
+ intermediate.EnumerationLiteral,
45
+ ]
46
+ ) -> str:
47
+ """
48
+ Represent ``something`` in a human-readable text.
49
+
50
+ The reader should be able to trace ``something`` back to the meta-model.
51
+ """
52
+ # NOTE (mristin, 2023-03-29):
53
+ # This function has been copy-pasted from
54
+ # :py:mod:`aas_core_codegen.python.structure._generate`. We tried to refactor it to
55
+ # :py:mod:`aas_core_codegen.intermediate`, but it turned out that the refactored
56
+ # code was nigh unreadable. So we preferred a little bit of copying to a little
57
+ # bit of complexity.
58
+
59
+ result: str
60
+
61
+ if isinstance(something, intermediate.Enumeration):
62
+ result = f"meta-model enumeration {something.name!r}"
63
+ elif isinstance(something, intermediate.EnumerationLiteral):
64
+ result = f"meta-model enumeration literal {something.name!r}"
65
+ elif isinstance(something, intermediate.AbstractClass):
66
+ result = f"meta-model abstract class {something.name!r}"
67
+ elif isinstance(something, intermediate.ConcreteClass):
68
+ result = f"meta-model concrete class {something.name!r}"
69
+ else:
70
+ assert_never(something)
71
+
72
+ assert result is not None
73
+ return result
74
+
75
+
76
+ def _verify_intra_structure_collisions(
77
+ our_type: intermediate.OurType,
78
+ ) -> Optional[Error]:
79
+ """Verify that no member names collide in the Golang structure of our type."""
80
+ errors = [] # type: List[Error]
81
+
82
+ if isinstance(our_type, intermediate.Enumeration):
83
+ # NOTE (mristin, 2023-03-29):
84
+ # We already checked for collisions of enumeration literals in
85
+ # the inter-structure collision checks.
86
+ pass
87
+ elif isinstance(our_type, intermediate.ConstrainedPrimitive):
88
+ pass
89
+
90
+ elif isinstance(our_type, intermediate.Class):
91
+ observed_member_names = {} # type: Dict[Identifier, str]
92
+
93
+ for prop in our_type.properties:
94
+ name = golang_naming.getter_name(prop.name)
95
+ if name in observed_member_names:
96
+ errors.append(
97
+ Error(
98
+ prop.parsed.node,
99
+ f"Golang getter {name!r} corresponding "
100
+ f"to the meta-model property {prop.name!r} collides with "
101
+ f"the {observed_member_names[name]}",
102
+ )
103
+ )
104
+ else:
105
+ observed_member_names[name] = (
106
+ f"Golang getter {name!r} corresponding to "
107
+ f"the meta-model property {prop.name!r}"
108
+ )
109
+
110
+ name = golang_naming.setter_name(prop.name)
111
+ if name in observed_member_names:
112
+ errors.append(
113
+ Error(
114
+ prop.parsed.node,
115
+ f"Golang setter {name!r} corresponding "
116
+ f"to the meta-model property {prop.name!r} collides with "
117
+ f"the {observed_member_names[name]}",
118
+ )
119
+ )
120
+ else:
121
+ observed_member_names[name] = (
122
+ f"Golang setter {name!r} corresponding to "
123
+ f"the meta-model property {prop.name!r}"
124
+ )
125
+
126
+ for method in our_type.methods:
127
+ method_name = golang_naming.method_name(method.name)
128
+
129
+ if method_name in observed_member_names:
130
+ errors.append(
131
+ Error(
132
+ method.parsed.node,
133
+ f"Golang method {method_name!r} corresponding "
134
+ f"to the meta-model method {method.name!r} collides with "
135
+ f"the {observed_member_names[method_name]}",
136
+ )
137
+ )
138
+ else:
139
+ observed_member_names[method_name] = (
140
+ f"Golang method {method_name!r} corresponding to "
141
+ f"the meta-model method {method.name!r}"
142
+ )
143
+
144
+ else:
145
+ assert_never(our_type)
146
+
147
+ if len(errors) > 0:
148
+ errors.append(
149
+ Error(
150
+ our_type.parsed.node,
151
+ f"Naming collision(s) in Golang code for our type {our_type.name!r}",
152
+ underlying=errors,
153
+ )
154
+ )
155
+
156
+ return None
157
+
158
+
159
+ def _verify_structure_name_collisions(
160
+ symbol_table: intermediate.SymbolTable,
161
+ ) -> List[Error]:
162
+ """Verify that the Golang names of the structures do not collide."""
163
+ observed_structure_names: Dict[
164
+ Identifier,
165
+ Union[
166
+ intermediate.Enumeration,
167
+ intermediate.AbstractClass,
168
+ intermediate.ConcreteClass,
169
+ intermediate.EnumerationLiteral,
170
+ ],
171
+ ] = dict()
172
+
173
+ errors = [] # type: List[Error]
174
+
175
+ # region Inter-structure collisions
176
+
177
+ for enum_or_cls in itertools.chain(symbol_table.enumerations, symbol_table.classes):
178
+ names: List[Identifier]
179
+
180
+ if isinstance(enum_or_cls, intermediate.Enumeration):
181
+ names = [golang_naming.enum_name(enum_or_cls.name)]
182
+ elif isinstance(enum_or_cls, intermediate.AbstractClass):
183
+ names = [golang_naming.interface_name(enum_or_cls.name)]
184
+ elif isinstance(enum_or_cls, intermediate.ConcreteClass):
185
+ names = [
186
+ golang_naming.interface_name(enum_or_cls.name),
187
+ golang_naming.struct_name(enum_or_cls.name),
188
+ ]
189
+ else:
190
+ assert_never(enum_or_cls)
191
+
192
+ for name in names:
193
+ other = observed_structure_names.get(name, None)
194
+
195
+ if other is not None:
196
+ errors.append(
197
+ Error(
198
+ enum_or_cls.parsed.node,
199
+ f"The Golang name {name!r} "
200
+ f"of the {_human_readable_identifier(enum_or_cls)} "
201
+ f"collides with the Golang name "
202
+ f"of the {_human_readable_identifier(other)}",
203
+ )
204
+ )
205
+ else:
206
+ observed_structure_names[name] = enum_or_cls
207
+
208
+ # NOTE (mristin, 2023-03-29):
209
+ # Enumeration literals are global constants in Go, so we have to consider them
210
+ # for collisions as well.
211
+ for enum in symbol_table.enumerations:
212
+ for literal in enum.literals:
213
+ name = golang_naming.enum_literal_name(enum.name, literal.name)
214
+
215
+ other = observed_structure_names.get(name, None)
216
+
217
+ if other is not None:
218
+ errors.append(
219
+ Error(
220
+ literal.parsed.node,
221
+ f"The Golang name {name!r} "
222
+ f"of the {_human_readable_identifier(literal)} "
223
+ f"collides with the Golang name "
224
+ f"of the {_human_readable_identifier(other)}",
225
+ )
226
+ )
227
+ else:
228
+ observed_structure_names[name] = literal
229
+
230
+ # endregion
231
+
232
+ # region Intra-structure collisions
233
+
234
+ for our_type in symbol_table.our_types:
235
+ collision_error = _verify_intra_structure_collisions(our_type=our_type)
236
+
237
+ if collision_error is not None:
238
+ errors.append(collision_error)
239
+
240
+ # endregion
241
+
242
+ return errors
243
+
244
+
245
+ class VerifiedIntermediateSymbolTable(intermediate.SymbolTable):
246
+ """Represent a verified symbol table which can be used for code generation."""
247
+
248
+ # noinspection PyInitNewSignature
249
+ def __new__(
250
+ cls, symbol_table: intermediate.SymbolTable
251
+ ) -> "VerifiedIntermediateSymbolTable":
252
+ raise AssertionError("Only for type annotation")
253
+
254
+
255
+ @ensure(lambda result: (result[0] is None) ^ (result[1] is None))
256
+ def verify(
257
+ symbol_table: intermediate.SymbolTable,
258
+ ) -> Tuple[Optional[VerifiedIntermediateSymbolTable], Optional[List[Error]]]:
259
+ """Verify that Golang code can be generated from the ``symbol_table``."""
260
+ errors = [] # type: List[Error]
261
+
262
+ structure_name_collisions = _verify_structure_name_collisions(
263
+ symbol_table=symbol_table
264
+ )
265
+
266
+ errors.extend(structure_name_collisions)
267
+
268
+ if len(errors) > 0:
269
+ return None, errors
270
+
271
+ return cast(VerifiedIntermediateSymbolTable, symbol_table), None
272
+
273
+
274
+ # endregion
275
+
276
+ # region Generation
277
+
278
+
279
+ @require(lambda enumeration, literal: id(literal) in enumeration.literal_id_set)
280
+ @require(lambda literal: literal.description is not None)
281
+ def _generate_comment_for_enumeration_literal(
282
+ enumeration: intermediate.Enumeration,
283
+ literal: intermediate.EnumerationLiteral,
284
+ ) -> Tuple[Optional[Stripped], Optional[List[Error]]]:
285
+ """Generate the documentation comment for the given enumeration literal."""
286
+ # NOTE (mristin, 2023-03-29):
287
+ # We need to state the pre-condition for the second time for mypy.
288
+ assert literal.description is not None
289
+
290
+ # fmt: off
291
+ comment, errors = (
292
+ golang_description.generate_comment_for_summary_remarks(
293
+ description=literal.description,
294
+ context=golang_description.Context(
295
+ package=golang_common.TYPES_PACKAGE,
296
+ cls_or_enum=enumeration
297
+ )
298
+ )
299
+ )
300
+ # fmt: on
301
+
302
+ if errors is not None:
303
+ return None, errors
304
+
305
+ assert comment is not None
306
+
307
+ return comment, None
308
+
309
+
310
+ @require(lambda cls_or_enum: cls_or_enum.description is not None)
311
+ def _generate_comment_for_cls_or_enum(
312
+ cls_or_enum: Union[intermediate.Enumeration, intermediate.ClassUnion],
313
+ ) -> Tuple[Optional[Stripped], Optional[List[Error]]]:
314
+ """Generate the documentation comment for our type."""
315
+ # NOTE (mristin, 2023-03-29):
316
+ # We need to state the pre-condition for the second time for mypy.
317
+ assert cls_or_enum.description is not None
318
+
319
+ # fmt: off
320
+ comment, errors = (
321
+ golang_description
322
+ .generate_comment_for_summary_remarks_constraints(
323
+ description=cls_or_enum.description,
324
+ context=golang_description.Context(
325
+ package=golang_common.TYPES_PACKAGE, cls_or_enum=None
326
+ )
327
+ )
328
+ )
329
+ # fmt: on
330
+
331
+ if errors is not None:
332
+ return None, errors
333
+
334
+ assert comment is not None
335
+
336
+ return comment, None
337
+
338
+
339
+ @ensure(lambda result: (result[0] is None) ^ (result[1] is None))
340
+ def _generate_enum(
341
+ enum: intermediate.Enumeration,
342
+ ) -> Tuple[Optional[Stripped], Optional[Error]]:
343
+ """Generate the Golang code for the enum."""
344
+ writer = io.StringIO()
345
+
346
+ errors = [] # type: List[Error]
347
+
348
+ comment = None # type: Optional[Stripped]
349
+ if enum.description is not None:
350
+ comment, comment_errors = _generate_comment_for_cls_or_enum(cls_or_enum=enum)
351
+
352
+ if comment_errors:
353
+ errors.append(
354
+ Error(
355
+ enum.description.parsed.node,
356
+ f"Failed to generate the comment "
357
+ f"for the enumeration {enum.name!r}",
358
+ comment_errors,
359
+ )
360
+ )
361
+ else:
362
+ assert comment is not None
363
+
364
+ if comment is not None:
365
+ writer.write(comment)
366
+ writer.write("\n")
367
+
368
+ name = golang_naming.enum_name(enum.name)
369
+
370
+ writer.write(f"type {name} int;")
371
+ if len(enum.literals) > 0:
372
+ writer.write("const (\n")
373
+
374
+ for i, literal in enumerate(enum.literals):
375
+ if literal.description is not None:
376
+ comment, comment_errors = _generate_comment_for_enumeration_literal(
377
+ enumeration=enum, literal=literal
378
+ )
379
+ if comment_errors is not None:
380
+ errors.append(
381
+ Error(
382
+ literal.description.parsed.node,
383
+ f"Failed to generate the documentation comment "
384
+ f"for enumeration literal {literal.name!r}",
385
+ comment_errors,
386
+ )
387
+ )
388
+ else:
389
+ assert comment is not None
390
+ writer.write(textwrap.indent(comment, I))
391
+ writer.write("\n")
392
+
393
+ literal_name = golang_naming.enum_literal_name(enum.name, literal.name)
394
+
395
+ # NOTE (mristin, 2023-03-29):
396
+ # We optimize for comparisons instead of stringification.
397
+ # The stringification is delegated to a separate module.
398
+
399
+ if i == 0:
400
+ writer.write(textwrap.indent(f"{literal_name} {name} = iota", I))
401
+ else:
402
+ writer.write(textwrap.indent(literal_name, I))
403
+
404
+ writer.write("\n")
405
+
406
+ writer.write(")")
407
+
408
+ if len(errors) > 0:
409
+ return None, Error(
410
+ enum.parsed.node,
411
+ f"Failed to generate the Golang code for the enumeration {enum.name!r}",
412
+ errors,
413
+ )
414
+
415
+ return Stripped(writer.getvalue()), None
416
+
417
+
418
+ def _literals_of_enum(enum: intermediate.Enumeration) -> Stripped:
419
+ """Generate the Golang code for the constant array listing the literals."""
420
+ name = golang_naming.enum_name(enum.name)
421
+ array_name = golang_naming.constant_name(Identifier(f"literals_of_{enum.name}"))
422
+
423
+ literals = []
424
+ for literal in enum.literals:
425
+ literals.append(golang_naming.enum_literal_name(enum.name, literal.name))
426
+
427
+ literals_joined = "\n".join(f"{literal}," for literal in literals)
428
+
429
+ return Stripped(
430
+ f"""\
431
+ // List the literals of [{name}].
432
+ //
433
+ // Golang does not provide an elegant way to iterate over the literals, so
434
+ // this array helps you avoid common errors and pitfalls.
435
+ //
436
+ // Please do not modify the array in the caller's code.
437
+ var {array_name} = [...]{name} {{
438
+ {I}{indent_but_first_line(literals_joined, I)}
439
+ }}"""
440
+ )
441
+
442
+
443
+ def _generate_definition_for_model_type(
444
+ symbol_table: intermediate.SymbolTable,
445
+ ) -> Stripped:
446
+ """
447
+ Generate the enumeration corresponding to the model types.
448
+
449
+ This is necessary so that we can have fast switches on instance types.
450
+ """
451
+ enum_name = golang_naming.enum_name(Identifier("Model_type"))
452
+
453
+ literal_specs = [] # type: List[Stripped]
454
+ for i, cls in enumerate(symbol_table.concrete_classes):
455
+ literal_name = golang_naming.enum_literal_name(
456
+ Identifier("Model_type"), cls.name
457
+ )
458
+
459
+ if i == 0:
460
+ literal_specs.append(Stripped(f"{literal_name} {enum_name} = iota"))
461
+ else:
462
+ literal_specs.append(literal_name)
463
+
464
+ literal_specs_joined = "\n".join(literal_specs)
465
+
466
+ if len(literal_specs) == 0:
467
+ return Stripped(f"type {enum_name} int")
468
+
469
+ return Stripped(
470
+ f"""\
471
+ // Enumerate the model types for faster type switches.
472
+ //
473
+ // For example, you can use an array of function pointers to
474
+ // implement such a switch.
475
+ type {enum_name} int
476
+ const (
477
+ {I}{indent_but_first_line(literal_specs_joined, I)}
478
+ )"""
479
+ )
480
+
481
+
482
+ def _generate_descend_body(
483
+ cls: intermediate.ConcreteClass, recurse: bool, receiver: Identifier
484
+ ) -> Stripped:
485
+ """
486
+ Generate the body of the `descend and descend-once methods.
487
+ """
488
+ blocks = [] # type: List[Stripped]
489
+
490
+ generator_for_loop_variables = golang_common.GeneratorForLoopVariables()
491
+
492
+ for prop in cls.properties:
493
+ prop_name = golang_naming.private_property_name(prop.name)
494
+
495
+ prop_blocks = [] # type: List[Stripped]
496
+
497
+ type_anno = intermediate.beneath_optional(prop.type_annotation)
498
+
499
+ if isinstance(type_anno, intermediate.PrimitiveTypeAnnotation):
500
+ continue
501
+ elif isinstance(type_anno, intermediate.OurTypeAnnotation):
502
+ if isinstance(type_anno.our_type, intermediate.Enumeration):
503
+ continue
504
+ elif isinstance(type_anno.our_type, intermediate.ConstrainedPrimitive):
505
+ continue
506
+ elif isinstance(
507
+ type_anno.our_type,
508
+ (intermediate.AbstractClass, intermediate.ConcreteClass),
509
+ ):
510
+ prop_blocks.append(
511
+ Stripped(
512
+ f"""\
513
+ abort = action(
514
+ {I}{receiver}.{prop_name},
515
+ )
516
+ if abort {{
517
+ {I}return
518
+ }}"""
519
+ )
520
+ )
521
+
522
+ if recurse:
523
+ prop_blocks.append(
524
+ Stripped(
525
+ f"""\
526
+ abort = {receiver}.{prop_name}.Descend(
527
+ {I}action,
528
+ )
529
+ if abort {{
530
+ {I}return
531
+ }}"""
532
+ )
533
+ )
534
+
535
+ else:
536
+ assert_never(type_anno.our_type)
537
+
538
+ elif isinstance(type_anno, intermediate.ListTypeAnnotation):
539
+ assert isinstance(
540
+ type_anno.items, intermediate.OurTypeAnnotation
541
+ ) and isinstance(
542
+ type_anno.items.our_type,
543
+ (intermediate.AbstractClass, intermediate.ConcreteClass),
544
+ ), (
545
+ f"NOTE (mristin, 2023-03-29): We expect only lists of classes "
546
+ f"at the moment, but you specified {type_anno}. "
547
+ f"Please contact the developers if you need this feature."
548
+ )
549
+
550
+ loop_var = next(generator_for_loop_variables)
551
+
552
+ if not recurse:
553
+ prop_blocks.append(
554
+ Stripped(
555
+ f"""\
556
+ for _, {loop_var} := range {receiver}.{prop_name} {{
557
+ {I}abort = action({loop_var});
558
+ {I}if abort {{
559
+ {II}return
560
+ {I}}}
561
+ }}"""
562
+ )
563
+ )
564
+ else:
565
+ prop_blocks.append(
566
+ Stripped(
567
+ f"""\
568
+ for _, {loop_var} := range {receiver}.{prop_name} {{
569
+ {I}abort = action({loop_var});
570
+ {I}if abort {{
571
+ {II}return
572
+ {I}}}
573
+
574
+ {I}abort = {loop_var}.Descend(
575
+ {II}action,
576
+ {I});
577
+ {I}if abort {{
578
+ {II}return
579
+ {I}}}
580
+ }}"""
581
+ )
582
+ )
583
+ else:
584
+ assert_never(type_anno)
585
+
586
+ block = Stripped("\n".join(prop_blocks))
587
+ if isinstance(prop.type_annotation, intermediate.OptionalTypeAnnotation):
588
+ block = Stripped(
589
+ f"""\
590
+ if {receiver}.{prop_name} != nil {{
591
+ {I}{indent_but_first_line(block, I)}
592
+ }}"""
593
+ )
594
+
595
+ blocks.append(block)
596
+
597
+ if len(blocks) == 0:
598
+ blocks.append(Stripped("// No descendable properties"))
599
+
600
+ blocks.append(Stripped("return"))
601
+
602
+ return Stripped("\n\n".join(blocks))
603
+
604
+
605
+ def _generate_descend_once_method(
606
+ cls: intermediate.ConcreteClass, receiver: Identifier
607
+ ) -> Stripped:
608
+ """Generate the descend-once method for the concrete class ``cls``."""
609
+ body = _generate_descend_body(cls=cls, recurse=False, receiver=receiver)
610
+
611
+ struct_name = golang_naming.struct_name(cls.name)
612
+
613
+ return Stripped(
614
+ f"""\
615
+ // Apply the action on the instances referenced from {receiver}.
616
+ //
617
+ // If any of the actions returns abort `true`, the descent is immediately
618
+ // stopped, and abort `true` is also returned. Otherwise, return abort `false`.
619
+ //
620
+ // We do not recurse into the referenced instances.
621
+ //
622
+ // The action is not applied on {receiver}.
623
+ func ({receiver} *{struct_name}) DescendOnce(
624
+ {I}action func(IClass) bool,
625
+ ) (abort bool) {{
626
+ {I}{indent_but_first_line(body, I)}
627
+ }}"""
628
+ )
629
+
630
+
631
+ def _generate_descend_method(
632
+ cls: intermediate.ConcreteClass, receiver: Identifier
633
+ ) -> Stripped:
634
+ """Generate the recursive ``descend`` method for the concrete class ``cls``."""
635
+ body = _generate_descend_body(cls=cls, recurse=True, receiver=receiver)
636
+
637
+ struct_name = golang_naming.struct_name(cls.name)
638
+
639
+ return Stripped(
640
+ f"""\
641
+ // Apply the action recursively on the instances referenced from {receiver}.
642
+ //
643
+ // If any of the actions returns abort `true`, the descent is immediately
644
+ // stopped, and abort `true` is also returned. Otherwise, return abort `false`.
645
+ //
646
+ // The action is not applied on {receiver}.
647
+ func ({receiver} *{struct_name}) Descend(
648
+ {I}action func(IClass) bool,
649
+ ) (abort bool) {{
650
+ {I}{indent_but_first_line(body, I)}
651
+ }}"""
652
+ )
653
+
654
+
655
+ @require(lambda cls: not cls.is_implementation_specific)
656
+ @require(lambda cls: not cls.constructor.is_implementation_specific)
657
+ @ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
658
+ def _generate_constructor(
659
+ cls: intermediate.ClassUnion,
660
+ ) -> Tuple[Optional[Stripped], Optional[Error]]:
661
+ """Generate the constructor function for the given concrete class ``cls``."""
662
+ property_names = [prop.name for prop in cls.properties]
663
+ constructor_argument_names = [arg.name for arg in cls.constructor.arguments]
664
+
665
+ # fmt: off
666
+ assert (
667
+ set(prop.name for prop in cls.properties)
668
+ == set(arg.name for arg in cls.constructor.arguments)
669
+ ), (
670
+ f"Expected the properties to coincide with constructor arguments, "
671
+ f"but they do not for {cls.name!r}:"
672
+ f"{property_names=}, {constructor_argument_names=}"
673
+ )
674
+ # fmt: on
675
+
676
+ # NOTE (mristin, 2023-03-31):
677
+ # Golang is peculiar, so we do not transpile the in-lined statements, but simply set
678
+ # the required properties to argument values and optional values to default argument
679
+ # values, if any were specified.
680
+ #
681
+ # It is not clear at this moment whether the SDK clients would really appreciate
682
+ # the added complexity of the code, so we wait till we get some feedback on it.
683
+
684
+ blocks = [] # type: List[str]
685
+
686
+ struct_specs = [] # type: List[Stripped]
687
+
688
+ for arg in cls.constructor.arguments:
689
+ if isinstance(arg.type_annotation, intermediate.OptionalTypeAnnotation):
690
+ continue
691
+
692
+ arg_name = golang_naming.argument_name(arg.name)
693
+ private_prop_name = golang_naming.private_property_name(arg.name)
694
+
695
+ struct_specs.append(Stripped(f"{private_prop_name}: {arg_name}"))
696
+
697
+ if arg.default is not None:
698
+ return None, Error(
699
+ arg.default.parsed.node,
700
+ f"(mristin, 2023-03-31): "
701
+ f"The argument {arg.name!r} is a required argument, "
702
+ f"but the default value is also specified. At the moment when we "
703
+ f"wrote the generator, we did not know how this use case should "
704
+ f"work out in Golang. Please contact the developers and "
705
+ f"discuss how this should be implemented.",
706
+ )
707
+
708
+ for arg in cls.constructor.arguments:
709
+ if not isinstance(arg.type_annotation, intermediate.OptionalTypeAnnotation):
710
+ continue
711
+
712
+ if arg.default is None:
713
+ continue
714
+
715
+ private_prop_name = golang_naming.private_property_name(arg.name)
716
+
717
+ # NOTE (mristin, 2023-03-31):
718
+ # We have to be careful: an optional property will be generated with a pointer
719
+ # type.
720
+
721
+ if isinstance(arg.default, intermediate.DefaultPrimitive):
722
+ if arg.default.value is None:
723
+ struct_specs.append(Stripped(f"{private_prop_name}: nil"))
724
+ elif isinstance(arg.default.value, bool):
725
+ literal = golang_common.boolean_literal(arg.default.value)
726
+ struct_specs.append(
727
+ Stripped(
728
+ f"""\
729
+ {private_prop_name}: aascommon.NewBool(
730
+ {I}{literal}
731
+ )"""
732
+ )
733
+ )
734
+ elif isinstance(arg.default.value, int):
735
+ literal = Stripped(str(arg.default.value))
736
+ struct_specs.append(
737
+ Stripped(
738
+ f"""\
739
+ {private_prop_name}: aascommon.NewInt64(
740
+ {I}{literal}
741
+ )"""
742
+ )
743
+ )
744
+ elif isinstance(arg.default.value, float):
745
+ literal = golang_common.float_literal(arg.default.value)
746
+ struct_specs.append(
747
+ Stripped(
748
+ f"""\
749
+ {private_prop_name}: aascommon.NewFloat64(
750
+ {I}{literal}
751
+ )"""
752
+ )
753
+ )
754
+ elif isinstance(arg.default.value, str):
755
+ literal = golang_common.string_literal(arg.default.value)
756
+ struct_specs.append(
757
+ Stripped(
758
+ f"""\
759
+ {private_prop_name}: aascommon.NewString(
760
+ {I}{literal}
761
+ )"""
762
+ )
763
+ )
764
+ else:
765
+ assert_never(arg.default.value)
766
+ elif isinstance(arg.default, intermediate.DefaultEnumerationLiteral):
767
+ literal = golang_naming.enum_literal_name(
768
+ arg.default.enumeration.name, arg.default.literal.name
769
+ )
770
+ enum_name = golang_naming.enum_name(arg.default.enumeration.name)
771
+ struct_specs.append(
772
+ Stripped(
773
+ f"""\
774
+ {private_prop_name}: (*{enum_name})(
775
+ {I}aascommon.NewInt(
776
+ {II}int({literal})
777
+ {I})
778
+ )"""
779
+ )
780
+ )
781
+ else:
782
+ assert_never(arg.default)
783
+
784
+ struct_name = golang_naming.struct_name(cls.name)
785
+
786
+ if len(struct_specs) == 0:
787
+ blocks.append(
788
+ Stripped(
789
+ f"""\
790
+ // Intentionally empty.
791
+ return &{struct_name}{{}}"""
792
+ )
793
+ )
794
+ else:
795
+ struct_specs_joined = "\n".join(
796
+ f"{struct_spec}," for struct_spec in struct_specs
797
+ )
798
+
799
+ blocks.append(
800
+ Stripped(
801
+ f"""\
802
+ return &{struct_name}{{
803
+ {I}{indent_but_first_line(struct_specs_joined, I)}
804
+ }}"""
805
+ )
806
+ )
807
+
808
+ body = "\n\n".join(blocks)
809
+
810
+ arg_codes = [] # type: List[str]
811
+ for arg in cls.constructor.arguments:
812
+ if isinstance(arg.type_annotation, intermediate.OptionalTypeAnnotation):
813
+ continue
814
+
815
+ arg_type = golang_common.generate_type(type_annotation=arg.type_annotation)
816
+ arg_name = golang_naming.argument_name(arg.name)
817
+
818
+ arg_codes.append(Stripped(f"{arg_name} {arg_type}"))
819
+
820
+ function_name = golang_naming.function_name(Identifier(f"new_{cls.name}"))
821
+
822
+ comment = f"""\
823
+ // Create a new instance of {struct_name} with
824
+ // the given properties."""
825
+
826
+ if len(arg_codes) == 0:
827
+ return (
828
+ Stripped(
829
+ f"""\
830
+ {comment}
831
+ func {function_name}() *{struct_name} {{
832
+ {I}{indent_but_first_line(body, I)}
833
+ }}"""
834
+ ),
835
+ None,
836
+ )
837
+
838
+ arg_codes_joined = "\n".join(f"{arg_code}," for arg_code in arg_codes)
839
+ return (
840
+ Stripped(
841
+ f"""\
842
+ {comment}
843
+ func {function_name}(
844
+ {I}{indent_but_first_line(arg_codes_joined, I)}
845
+ ) *{struct_name} {{
846
+ {I}{indent_but_first_line(body, I)}
847
+ }}"""
848
+ ),
849
+ None,
850
+ )
851
+
852
+
853
+ @require(lambda cls, prop: id(prop) in cls.property_id_set)
854
+ @require(lambda prop: prop.description is not None)
855
+ def _generate_comment_for_property(
856
+ cls: intermediate.ClassUnion,
857
+ prop: intermediate.Property,
858
+ ) -> Tuple[Optional[Stripped], Optional[List[Error]]]:
859
+ """Generate the documentation comment for the given property."""
860
+ # NOTE (mristin, 2022-10-29):
861
+ # We need to write a double assertion for mypy.
862
+ assert prop.description is not None
863
+
864
+ # fmt: off
865
+ comment, errors = (
866
+ golang_description
867
+ .generate_comment_for_summary_remarks_constraints(
868
+ description=prop.description,
869
+ context=golang_description.Context(
870
+ package=golang_common.TYPES_PACKAGE,
871
+ cls_or_enum=cls,
872
+ )
873
+ )
874
+ )
875
+ # fmt: on
876
+
877
+ if errors is not None:
878
+ return None, errors
879
+
880
+ assert comment is not None
881
+
882
+ return comment, None
883
+
884
+
885
+ @ensure(lambda result: (result[0] is None) ^ (result[1] is None))
886
+ def _generate_interface(
887
+ cls: intermediate.ClassUnion,
888
+ ) -> Tuple[Optional[Stripped], Optional[Error]]:
889
+ """Generate the Golang code of the interface corresponding to ``cls``."""
890
+ # Code blocks separated by double newlines and indented once
891
+ blocks = [] # type: List[Stripped]
892
+
893
+ # region Inheritance
894
+
895
+ if len(cls.inheritances) > 0:
896
+ for inheritance in cls.inheritances:
897
+ inheritance_name = golang_naming.interface_name(inheritance.name)
898
+ blocks.append(inheritance_name)
899
+ else:
900
+ blocks.append(Stripped("IClass"))
901
+
902
+ # endregion
903
+
904
+ # region Getters and Setters
905
+
906
+ for prop in cls.properties:
907
+ if prop.specified_for is not cls:
908
+ continue
909
+
910
+ prop_type = golang_common.generate_type(type_annotation=prop.type_annotation)
911
+
912
+ prop_comment = None # type: Optional[Stripped]
913
+ if prop.description is not None:
914
+ (
915
+ prop_comment,
916
+ prop_comment_errors,
917
+ ) = _generate_comment_for_property(cls=cls, prop=prop)
918
+
919
+ if prop_comment_errors is not None:
920
+ return None, Error(
921
+ prop.description.parsed.node,
922
+ f"Failed to generate the documentation comment "
923
+ f"for the property {prop.name!r}",
924
+ prop_comment_errors,
925
+ )
926
+
927
+ assert prop_comment is not None
928
+
929
+ getter_name = golang_naming.getter_name(prop.name)
930
+ if prop_comment:
931
+ blocks.append(
932
+ Stripped(
933
+ f"""\
934
+ {prop_comment}
935
+ {getter_name}() {prop_type};"""
936
+ )
937
+ )
938
+ else:
939
+ blocks.append(Stripped(f"func {getter_name}() {prop_type};"))
940
+
941
+ setter_name = golang_naming.setter_name(prop.name)
942
+ blocks.append(
943
+ Stripped(
944
+ f"""\
945
+ {setter_name}(
946
+ {I}value {prop_type},
947
+ );"""
948
+ )
949
+ )
950
+
951
+ # endregion
952
+
953
+ # region Methods
954
+
955
+ for method in cls.methods:
956
+ method_blocks = [] # type: List[Stripped]
957
+
958
+ if method.description is not None:
959
+ (
960
+ method_comment,
961
+ method_comment_errors,
962
+ ) = golang_description.generate_comment_for_signature(
963
+ method.description,
964
+ context=golang_description.Context(
965
+ package=golang_common.TYPES_PACKAGE, cls_or_enum=cls
966
+ ),
967
+ )
968
+
969
+ if method_comment_errors is not None:
970
+ return None, Error(
971
+ method.description.parsed.node,
972
+ f"Failed to generate the documentation comment "
973
+ f"for method {method.name!r}",
974
+ method_comment_errors,
975
+ )
976
+
977
+ assert method_comment is not None
978
+
979
+ method_blocks.append(method_comment)
980
+
981
+ # fmt: off
982
+ returns = (
983
+ f" {golang_common.generate_type(type_annotation=method.returns)}"
984
+ if method.returns is not None else ""
985
+ )
986
+ # fmt: on
987
+
988
+ arg_codes = [] # type: List[Stripped]
989
+ for arg in method.arguments:
990
+ arg_type = golang_common.generate_type(type_annotation=arg.type_annotation)
991
+ arg_name = golang_naming.argument_name(arg.name)
992
+ arg_codes.append(Stripped(f"{arg_name} {arg_type}"))
993
+
994
+ method_name = golang_naming.method_name(method.name)
995
+
996
+ if len(arg_codes) == 0:
997
+ method_blocks.append(Stripped(f"{method_name}(){returns};"))
998
+ else:
999
+ arg_codes_joined = "\n".join(f"{arg_code}," for arg_code in arg_codes)
1000
+ method_blocks.append(
1001
+ Stripped(
1002
+ f"""\
1003
+ {method_name}(
1004
+ {I}{indent_but_first_line(arg_codes_joined, I)}
1005
+ ){returns};"""
1006
+ )
1007
+ )
1008
+
1009
+ blocks.append(Stripped("\n".join(method_blocks)))
1010
+
1011
+ comment = None # type: Optional[Stripped]
1012
+ if cls.description is not None:
1013
+ # fmt: off
1014
+ comment, comment_errors = (
1015
+ golang_description
1016
+ .generate_comment_for_summary_remarks_constraints(
1017
+ cls.description,
1018
+ context=golang_description.Context(
1019
+ package=golang_common.TYPES_PACKAGE,
1020
+ cls_or_enum=cls
1021
+ )
1022
+ )
1023
+ )
1024
+ # fmt: on
1025
+
1026
+ if comment_errors is not None:
1027
+ return None, Error(
1028
+ cls.description.parsed.node,
1029
+ "Failed to generate the documentation comment",
1030
+ comment_errors,
1031
+ )
1032
+
1033
+ assert comment is not None
1034
+
1035
+ if len(blocks) == 0:
1036
+ blocks = [Stripped("// Intentionally empty.")]
1037
+
1038
+ writer = io.StringIO()
1039
+ if comment is not None:
1040
+ writer.write(comment)
1041
+ writer.write("\n")
1042
+
1043
+ interface_name = golang_naming.interface_name(cls.name)
1044
+
1045
+ blocks_joined = "\n\n".join(blocks)
1046
+
1047
+ writer.write(
1048
+ f"""\
1049
+ type {interface_name} interface {{
1050
+ {I}{indent_but_first_line(blocks_joined, I)}
1051
+ }}"""
1052
+ )
1053
+
1054
+ return Stripped(writer.getvalue()), None
1055
+
1056
+
1057
+ def _generate_is_interface(
1058
+ cls: intermediate.ClassUnion, symbol_table: intermediate.SymbolTable
1059
+ ) -> Tuple[Optional[Stripped], Optional[Error]]:
1060
+ """Generate the function to check the model type against ``cls``."""
1061
+ interface_name = golang_naming.interface_name(cls.name)
1062
+ function_name = golang_naming.function_name(Identifier(f"is_{cls.name}"))
1063
+
1064
+ if len(cls.concrete_descendants) == 0:
1065
+ if isinstance(cls, intermediate.AbstractClass):
1066
+ return None, Error(
1067
+ cls.parsed.node,
1068
+ f"Unexpected abstract class with no concrete descendants: {cls.name!r}",
1069
+ )
1070
+
1071
+ model_type_literal = golang_naming.enum_literal_name(
1072
+ enumeration_name=Identifier("Model_type"), literal_name=cls.name
1073
+ )
1074
+ body = Stripped(f"ok = that.ModelType() == {model_type_literal}")
1075
+ else:
1076
+ case_statements = [] # type: List[Stripped]
1077
+
1078
+ for another_cls in symbol_table.concrete_classes:
1079
+ model_type_literal = golang_naming.enum_literal_name(
1080
+ Identifier("Model_type"), another_cls.name
1081
+ )
1082
+
1083
+ if id(another_cls) in cls.concrete_descendant_id_set or another_cls is cls:
1084
+ case_statements.append(
1085
+ Stripped(
1086
+ f"""\
1087
+ case {model_type_literal}:
1088
+ {I}ok = true"""
1089
+ )
1090
+ )
1091
+
1092
+ case_statements_joined = "\n".join(case_statements)
1093
+ body = Stripped(
1094
+ f"""\
1095
+ switch that.ModelType() {{
1096
+ {case_statements_joined}
1097
+ }}"""
1098
+ )
1099
+
1100
+ return (
1101
+ Stripped(
1102
+ f"""\
1103
+ // Check whether the instance corresponds to [aastypes.{interface_name}]
1104
+ // based on its run-time model type.
1105
+ //
1106
+ // The implementation uses a switch statements which is
1107
+ // most probably compiled as an efficient jump table by the compiler.
1108
+ func {function_name}(
1109
+ {I}that IClass,
1110
+ ) (ok bool) {{
1111
+ {I}{indent_but_first_line(body, I)}
1112
+ {I}return
1113
+ }}"""
1114
+ ),
1115
+ None,
1116
+ )
1117
+
1118
+
1119
+ @require(lambda cls: not cls.is_implementation_specific)
1120
+ def _generate_struct(cls: intermediate.ConcreteClass) -> Stripped:
1121
+ blocks = [] # type: List[Stripped]
1122
+
1123
+ for prop in cls.properties:
1124
+ prop_type = golang_common.generate_type(type_annotation=prop.type_annotation)
1125
+ private_prop_name = golang_naming.private_property_name(prop.name)
1126
+
1127
+ blocks.append(Stripped(f"{private_prop_name} {prop_type}"))
1128
+
1129
+ body = "\n".join(blocks)
1130
+
1131
+ struct_name = golang_naming.struct_name(cls.name)
1132
+ interface_name = golang_naming.interface_name(cls.name)
1133
+
1134
+ return Stripped(
1135
+ f"""\
1136
+ // Implements {interface_name}.
1137
+ type {struct_name} struct {{
1138
+ {I}{indent_but_first_line(body, I)}
1139
+ }}"""
1140
+ )
1141
+
1142
+
1143
+ @require(lambda cls: not cls.is_implementation_specific)
1144
+ @ensure(lambda result: (result[0] is None) ^ (result[1] is None))
1145
+ def _generate_struct_methods(
1146
+ cls: intermediate.ConcreteClass,
1147
+ spec_impls: specific_implementations.SpecificImplementations,
1148
+ ) -> Tuple[Optional[List[Stripped]], Optional[Error]]:
1149
+ """Generate the Golang methods for the struct corresponding to ``cls``."""
1150
+ methods = [] # type: List[Stripped]
1151
+
1152
+ receiver = golang_naming.receiver_name(cls)
1153
+
1154
+ # region Setter and getter implementations
1155
+
1156
+ struct_name = golang_naming.struct_name(cls.name)
1157
+
1158
+ for prop in cls.properties:
1159
+ prop_type = golang_common.generate_type(prop.type_annotation)
1160
+ private_prop_name = golang_naming.private_property_name(prop.name)
1161
+
1162
+ getter_name = golang_naming.getter_name(prop.name)
1163
+
1164
+ methods.append(
1165
+ Stripped(
1166
+ f"""\
1167
+ func ({receiver} *{struct_name}) {getter_name}(
1168
+ ) {prop_type} {{
1169
+ {I}return {receiver}.{private_prop_name}
1170
+ }}"""
1171
+ )
1172
+ )
1173
+
1174
+ setter_name = golang_naming.setter_name(prop.name)
1175
+
1176
+ methods.append(
1177
+ Stripped(
1178
+ f"""\
1179
+ func ({receiver} *{struct_name}) {setter_name}(
1180
+ {I}value {prop_type},
1181
+ ) {{
1182
+ {I}{receiver}.{private_prop_name} = value
1183
+ }}"""
1184
+ )
1185
+ )
1186
+
1187
+ # endregion
1188
+
1189
+ # region Getter of Model Type
1190
+
1191
+ model_type_literal = golang_naming.enum_literal_name(
1192
+ enumeration_name=Identifier("Model_type"), literal_name=cls.name
1193
+ )
1194
+
1195
+ model_type_enum = golang_naming.enum_name(Identifier("Model_type"))
1196
+ model_type_getter = golang_naming.getter_name(Identifier("model_type"))
1197
+
1198
+ methods.append(
1199
+ Stripped(
1200
+ f"""\
1201
+ func ({receiver} *{struct_name}) {model_type_getter}(
1202
+ ) {model_type_enum} {{
1203
+ {I}return {model_type_literal}
1204
+ }}"""
1205
+ )
1206
+ )
1207
+
1208
+ # endregion
1209
+
1210
+ # region Methods
1211
+
1212
+ errors = [] # type: List[Error]
1213
+
1214
+ for method in cls.methods:
1215
+ if isinstance(method, intermediate.ImplementationSpecificMethod):
1216
+ implementation_key = specific_implementations.ImplementationKey(
1217
+ f"Types/{method.specified_for.name}/{method.name}.go"
1218
+ )
1219
+
1220
+ implementation = spec_impls.get(implementation_key, None)
1221
+
1222
+ if implementation is None:
1223
+ errors.append(
1224
+ Error(
1225
+ method.parsed.node,
1226
+ f"The implementation is missing for "
1227
+ f"the implementation-specific method: {implementation_key}",
1228
+ )
1229
+ )
1230
+ continue
1231
+
1232
+ # fmt: off
1233
+ methods.append(
1234
+ Stripped(
1235
+ implementation
1236
+ .replace("_RECEIVER_", receiver)
1237
+ .replace("_STRUCT_NAME_", struct_name)
1238
+ )
1239
+ )
1240
+ # fmt: on
1241
+ else:
1242
+ errors.append(
1243
+ Error(
1244
+ cls.parsed.node,
1245
+ "(mristin, 2023-03-31) "
1246
+ "At the moment, we do not transpile the method body and "
1247
+ "its contracts. We want to finish the meta-model for the V3, "
1248
+ "fix de/serialization and generate SDKs for a couple of languages "
1249
+ "before taking on this rather hard task.",
1250
+ )
1251
+ )
1252
+
1253
+ methods.append(_generate_descend_once_method(cls=cls, receiver=receiver))
1254
+
1255
+ methods.append(_generate_descend_method(cls=cls, receiver=receiver))
1256
+
1257
+ # endregion
1258
+
1259
+ # region Constructor
1260
+
1261
+ if cls.constructor.is_implementation_specific:
1262
+ implementation_key = specific_implementations.ImplementationKey(
1263
+ f"Types/{cls.name}/{cls.name}.go"
1264
+ )
1265
+ implementation = spec_impls.get(implementation_key, None)
1266
+
1267
+ if implementation is None:
1268
+ errors.append(
1269
+ Error(
1270
+ cls.parsed.node,
1271
+ f"The implementation of the implementation-specific constructor "
1272
+ f"is missing: {implementation_key}",
1273
+ )
1274
+ )
1275
+ else:
1276
+ methods.append(implementation)
1277
+ else:
1278
+ constructor_block, error = _generate_constructor(cls=cls)
1279
+
1280
+ if error is not None:
1281
+ errors.append(error)
1282
+ else:
1283
+ assert constructor_block is not None
1284
+
1285
+ methods.append(constructor_block)
1286
+
1287
+ # endregion
1288
+
1289
+ if len(errors) > 0:
1290
+ return None, Error(
1291
+ cls.parsed.node,
1292
+ f"Failed to generate the methods for the class {cls.name}",
1293
+ errors,
1294
+ )
1295
+
1296
+ return methods, None
1297
+
1298
+
1299
+ def _generate_comment_for_meta_model(
1300
+ description: intermediate.DescriptionOfMetaModel,
1301
+ ) -> Tuple[Optional[Stripped], Optional[List[Error]]]:
1302
+ """Generate the docstring for the given meta-model."""
1303
+ # fmt: off
1304
+ comment, errors = (
1305
+ golang_description
1306
+ .generate_comment_for_summary_remarks_constraints(
1307
+ description=description,
1308
+ context=golang_description.Context(
1309
+ package=golang_common.TYPES_PACKAGE, cls_or_enum=None
1310
+ )
1311
+ )
1312
+ )
1313
+ # fmt: on
1314
+
1315
+ if errors is not None:
1316
+ return None, errors
1317
+
1318
+ assert comment is not None
1319
+
1320
+ return comment, None
1321
+
1322
+
1323
+ # fmt: off
1324
+ @ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
1325
+ @ensure(
1326
+ lambda result:
1327
+ not (result[0] is not None) or result[0].endswith('\n'),
1328
+ "Trailing newline mandatory for valid end-of-files"
1329
+ )
1330
+ # fmt: on
1331
+ def generate(
1332
+ symbol_table: VerifiedIntermediateSymbolTable,
1333
+ spec_impls: specific_implementations.SpecificImplementations,
1334
+ ) -> Tuple[Optional[str], Optional[List[Error]]]:
1335
+ """
1336
+ Generate the Golang code of the structures based on the symbol table.
1337
+
1338
+ The ``aas_module`` indicates the fully-qualified name of the base module.
1339
+ """
1340
+ errors = [] # type: List[Error]
1341
+
1342
+ blocks = [] # type: List[Stripped]
1343
+
1344
+ if symbol_table.meta_model.description is not None:
1345
+ # fmt: off
1346
+ comment, comment_errors = (
1347
+ _generate_comment_for_meta_model(
1348
+ description=symbol_table.meta_model.description
1349
+ )
1350
+ )
1351
+ # fmt: on
1352
+
1353
+ if comment_errors is not None:
1354
+ errors.extend(comment_errors)
1355
+ else:
1356
+ assert comment is not None
1357
+ blocks.append(
1358
+ Stripped(
1359
+ f"""\
1360
+ // Package types provides the data structures corresponding to the meta-model.
1361
+ //
1362
+ {comment}
1363
+ package types"""
1364
+ )
1365
+ )
1366
+
1367
+ model_type_getter = golang_naming.getter_name(Identifier("model_type"))
1368
+ model_type_enum = golang_naming.enum_name(Identifier("Model_type"))
1369
+
1370
+ blocks.extend(
1371
+ [
1372
+ golang_common.WARNING,
1373
+ _generate_definition_for_model_type(symbol_table=symbol_table),
1374
+ Stripped(
1375
+ f"""\
1376
+ // Represent the most general interface of an AAS model.
1377
+ type IClass interface {{
1378
+ {I}// Return the concrete model type at run-time.
1379
+ {I}//
1380
+ {I}// Use the model type if you want to switch on the concrete model type
1381
+ {I}// in efficient manner, as the compiler will most probably implement
1382
+ {I}// the switch in form of a jump table.
1383
+ {I}{model_type_getter}() {model_type_enum}
1384
+
1385
+ {I}// Apply the action on the instances referenced from this instance.
1386
+ {I}//
1387
+ {I}// If any of the actions returns abort `true`, the descent is immediately
1388
+ {I}// stopped, and abort `true` is also returned. Otherwise, return abort `false`.
1389
+ {I}//
1390
+ {I}// We do not recurse into the referenced instances.
1391
+ {I}//
1392
+ {I}// The action is not applied on this instance.
1393
+ {I}DescendOnce(action func(IClass) bool) (abort bool)
1394
+
1395
+ {I}// Apply the action recursively on the instances referenced from this instance.
1396
+ {I}//
1397
+ {I}// If any of the actions returns abort `true`, the descent is immediately
1398
+ {I}// stopped, and abort `true` is also returned. Otherwise, return abort `false`.
1399
+ {I}//
1400
+ {I}// The action is not applied on this instance.
1401
+ {I}Descend(action func(IClass) bool) (abort bool)
1402
+ }}"""
1403
+ ),
1404
+ ]
1405
+ )
1406
+
1407
+ for our_type in symbol_table.our_types:
1408
+ if isinstance(our_type, intermediate.Enumeration):
1409
+ block, error = _generate_enum(enum=our_type)
1410
+ if error is not None:
1411
+ errors.append(error)
1412
+ continue
1413
+ else:
1414
+ assert block is not None
1415
+ blocks.append(block)
1416
+ blocks.append(_literals_of_enum(enum=our_type))
1417
+
1418
+ elif isinstance(our_type, intermediate.ConstrainedPrimitive):
1419
+ # NOTE (mristin, 2023-03-31):
1420
+ # We do not generate the constrained primitives as types. We only
1421
+ # consider them in the verification.
1422
+ continue
1423
+
1424
+ elif isinstance(
1425
+ our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)
1426
+ ):
1427
+ if our_type.is_implementation_specific:
1428
+ implementation_key = specific_implementations.ImplementationKey(
1429
+ f"Types/{our_type.name}.go"
1430
+ )
1431
+
1432
+ block = spec_impls.get(implementation_key, None)
1433
+ if block is None:
1434
+ errors.append(
1435
+ Error(
1436
+ our_type.parsed.node,
1437
+ f"The implementation is missing "
1438
+ f"for the implementation-specific "
1439
+ f"class: {implementation_key}",
1440
+ )
1441
+ )
1442
+ else:
1443
+ blocks.append(block)
1444
+ else:
1445
+ block, error = _generate_interface(cls=our_type)
1446
+ if error is not None:
1447
+ errors.append(error)
1448
+ else:
1449
+ assert block is not None
1450
+ blocks.append(block)
1451
+
1452
+ block, error = _generate_is_interface(
1453
+ cls=our_type, symbol_table=symbol_table
1454
+ )
1455
+ if error is not None:
1456
+ errors.append(error)
1457
+ else:
1458
+ assert block is not None
1459
+ blocks.append(block)
1460
+
1461
+ if isinstance(our_type, intermediate.ConcreteClass):
1462
+ block = _generate_struct(cls=our_type)
1463
+ blocks.append(block)
1464
+
1465
+ methods, error = _generate_struct_methods(
1466
+ cls=our_type, spec_impls=spec_impls
1467
+ )
1468
+ if error is not None:
1469
+ errors.append(error)
1470
+ else:
1471
+ assert methods is not None
1472
+ blocks.extend(methods)
1473
+ else:
1474
+ assert_never(our_type)
1475
+
1476
+ if len(errors) > 0:
1477
+ return None, errors
1478
+
1479
+ blocks.append(golang_common.WARNING)
1480
+
1481
+ out = io.StringIO()
1482
+ for i, block in enumerate(blocks):
1483
+ if i > 0:
1484
+ out.write("\n\n")
1485
+
1486
+ out.write(block)
1487
+
1488
+ out.write("\n")
1489
+
1490
+ return out.getvalue(), None
1491
+
1492
+
1493
+ # endregion