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,1341 @@
1
+ """Generate the C# data structures from the intermediate representation."""
2
+ import io
3
+ import textwrap
4
+ from typing import (
5
+ Optional,
6
+ Dict,
7
+ List,
8
+ Tuple,
9
+ cast,
10
+ Union,
11
+ Mapping,
12
+ Final,
13
+ )
14
+
15
+ from icontract import ensure, require
16
+
17
+ from aas_core_codegen import intermediate
18
+ from aas_core_codegen import specific_implementations
19
+ from aas_core_codegen.common import (
20
+ Error,
21
+ Identifier,
22
+ assert_never,
23
+ Stripped,
24
+ indent_but_first_line,
25
+ )
26
+ from aas_core_codegen.csharp import (
27
+ common as csharp_common,
28
+ naming as csharp_naming,
29
+ unrolling as csharp_unrolling,
30
+ description as csharp_description,
31
+ )
32
+ from aas_core_codegen.csharp.common import (
33
+ INDENT as I,
34
+ INDENT2 as II,
35
+ )
36
+ from aas_core_codegen.intermediate import (
37
+ construction as intermediate_construction,
38
+ )
39
+
40
+
41
+ # region Checks
42
+
43
+
44
+ def _human_readable_identifier(
45
+ something: Union[
46
+ intermediate.Enumeration, intermediate.AbstractClass, intermediate.ConcreteClass
47
+ ]
48
+ ) -> str:
49
+ """
50
+ Represent ``something`` in a human-readable text.
51
+
52
+ The reader should be able to trace ``something`` back to the meta-model.
53
+ """
54
+ result: str
55
+
56
+ if isinstance(something, intermediate.Enumeration):
57
+ result = f"meta-model enumeration {something.name!r}"
58
+ elif isinstance(something, intermediate.AbstractClass):
59
+ result = f"meta-model abstract class {something.name!r}"
60
+ elif isinstance(something, intermediate.ConcreteClass):
61
+ result = f"meta-model concrete class {something.name!r}"
62
+ else:
63
+ assert_never(something)
64
+
65
+ return result
66
+
67
+
68
+ def _verify_intra_structure_collisions(
69
+ our_type: intermediate.OurType,
70
+ ) -> Optional[Error]:
71
+ """Verify that no member names collide in the C# structure of our type."""
72
+ errors = [] # type: List[Error]
73
+
74
+ if isinstance(our_type, intermediate.Enumeration):
75
+ pass
76
+
77
+ elif isinstance(our_type, intermediate.ConstrainedPrimitive):
78
+ pass
79
+
80
+ elif isinstance(our_type, intermediate.Class):
81
+ observed_member_names = {} # type: Dict[Identifier, str]
82
+
83
+ for prop in our_type.properties:
84
+ prop_name = csharp_naming.property_name(prop.name)
85
+ if prop_name in observed_member_names:
86
+ errors.append(
87
+ Error(
88
+ prop.parsed.node,
89
+ f"C# property {prop_name!r} corresponding "
90
+ f"to the meta-model property {prop.name!r} collides with "
91
+ f"the {observed_member_names[prop_name]}",
92
+ )
93
+ )
94
+ else:
95
+ observed_member_names[prop_name] = (
96
+ f"C# property {prop_name!r} corresponding to "
97
+ f"the meta-model property {prop.name!r}"
98
+ )
99
+
100
+ for method in our_type.methods:
101
+ method_name = csharp_naming.method_name(method.name)
102
+
103
+ if method_name in observed_member_names:
104
+ errors.append(
105
+ Error(
106
+ method.parsed.node,
107
+ f"C# method {method_name!r} corresponding "
108
+ f"to the meta-model method {method.name!r} collides with "
109
+ f"the {observed_member_names[method_name]}",
110
+ )
111
+ )
112
+ else:
113
+ observed_member_names[method_name] = (
114
+ f"C# method {method_name!r} corresponding to "
115
+ f"the meta-model method {method.name!r}"
116
+ )
117
+
118
+ else:
119
+ assert_never(our_type)
120
+
121
+ if len(errors) > 0:
122
+ errors.append(
123
+ Error(
124
+ our_type.parsed.node,
125
+ f"Naming collision(s) in C# code for our type {our_type.name!r}",
126
+ underlying=errors,
127
+ )
128
+ )
129
+
130
+ return None
131
+
132
+
133
+ def _verify_structure_name_collisions(
134
+ symbol_table: intermediate.SymbolTable,
135
+ ) -> List[Error]:
136
+ """Verify that the C# names of the structures do not collide."""
137
+ observed_structure_names: Dict[
138
+ Identifier,
139
+ Union[
140
+ intermediate.Enumeration,
141
+ intermediate.AbstractClass,
142
+ intermediate.ConcreteClass,
143
+ ],
144
+ ] = dict()
145
+
146
+ errors = [] # type: List[Error]
147
+
148
+ # region Inter-structure collisions
149
+
150
+ for our_type in symbol_table.our_types:
151
+ if not isinstance(
152
+ our_type,
153
+ (
154
+ intermediate.Enumeration,
155
+ intermediate.AbstractClass,
156
+ intermediate.ConcreteClass,
157
+ ),
158
+ ):
159
+ continue
160
+
161
+ if isinstance(our_type, intermediate.Enumeration):
162
+ name = csharp_naming.enum_name(our_type.name)
163
+ other = observed_structure_names.get(name, None)
164
+
165
+ if other is not None:
166
+ errors.append(
167
+ Error(
168
+ our_type.parsed.node,
169
+ f"The C# name {name!r} for the enumeration {our_type.name!r} "
170
+ f"collides with the same C# name "
171
+ f"coming from the {_human_readable_identifier(other)}",
172
+ )
173
+ )
174
+ else:
175
+ observed_structure_names[name] = our_type
176
+
177
+ elif isinstance(
178
+ our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)
179
+ ):
180
+ interface_name = csharp_naming.interface_name(our_type.name)
181
+
182
+ other = observed_structure_names.get(interface_name, None)
183
+
184
+ if other is not None:
185
+ errors.append(
186
+ Error(
187
+ our_type.parsed.node,
188
+ f"The C# name {interface_name!r} of the interface "
189
+ f"for the class {our_type.name!r} "
190
+ f"collides with the same C# name "
191
+ f"coming from the {_human_readable_identifier(other)}",
192
+ )
193
+ )
194
+ else:
195
+ observed_structure_names[interface_name] = our_type
196
+
197
+ if isinstance(our_type, intermediate.ConcreteClass):
198
+ class_name = csharp_naming.class_name(our_type.name)
199
+
200
+ other = observed_structure_names.get(class_name, None)
201
+
202
+ if other is not None:
203
+ errors.append(
204
+ Error(
205
+ our_type.parsed.node,
206
+ f"The C# name {class_name!r} "
207
+ f"for the class {our_type.name!r} "
208
+ f"collides with the same C# name "
209
+ f"coming from the {_human_readable_identifier(other)}",
210
+ )
211
+ )
212
+ else:
213
+ observed_structure_names[class_name] = our_type
214
+ else:
215
+ assert_never(our_type)
216
+
217
+ # endregion
218
+
219
+ # region Intra-structure collisions
220
+
221
+ for our_type in symbol_table.our_types:
222
+ collision_error = _verify_intra_structure_collisions(our_type=our_type)
223
+
224
+ if collision_error is not None:
225
+ errors.append(collision_error)
226
+
227
+ # endregion
228
+
229
+ return errors
230
+
231
+
232
+ class VerifiedIntermediateSymbolTable(intermediate.SymbolTable):
233
+ """Represent a verified symbol table which can be used for code generation."""
234
+
235
+ # noinspection PyInitNewSignature
236
+ def __new__(
237
+ cls, symbol_table: intermediate.SymbolTable
238
+ ) -> "VerifiedIntermediateSymbolTable":
239
+ raise AssertionError("Only for type annotation")
240
+
241
+
242
+ @ensure(lambda result: (result[0] is None) ^ (result[1] is None))
243
+ def verify(
244
+ symbol_table: intermediate.SymbolTable,
245
+ ) -> Tuple[Optional[VerifiedIntermediateSymbolTable], Optional[List[Error]]]:
246
+ """Verify that C# code can be generated from the ``symbol_table``."""
247
+ errors = [] # type: List[Error]
248
+
249
+ structure_name_collisions = _verify_structure_name_collisions(
250
+ symbol_table=symbol_table
251
+ )
252
+
253
+ errors.extend(structure_name_collisions)
254
+
255
+ if len(errors) > 0:
256
+ return None, errors
257
+
258
+ return cast(VerifiedIntermediateSymbolTable, symbol_table), None
259
+
260
+
261
+ # endregion
262
+
263
+ # region Generation
264
+
265
+
266
+ @ensure(lambda result: (result[0] is None) ^ (result[1] is None))
267
+ def _generate_enum(
268
+ enum: intermediate.Enumeration,
269
+ ) -> Tuple[Optional[Stripped], Optional[Error]]:
270
+ """Generate the C# code for the enum."""
271
+ writer = io.StringIO()
272
+
273
+ if enum.description is not None:
274
+ comment, comment_errors = csharp_description.generate_comment_for_our_type(
275
+ enum.description
276
+ )
277
+ if comment_errors:
278
+ return None, Error(
279
+ enum.description.parsed.node,
280
+ "Failed to generate the documentation comment",
281
+ comment_errors,
282
+ )
283
+
284
+ assert comment is not None
285
+
286
+ writer.write(comment)
287
+ writer.write("\n")
288
+
289
+ name = csharp_naming.enum_name(enum.name)
290
+ if len(enum.literals) == 0:
291
+ writer.write(f"public enum {name}\n{{\n}}")
292
+ return Stripped(writer.getvalue()), None
293
+
294
+ writer.write(f"public enum {name}\n{{\n")
295
+ for i, literal in enumerate(enum.literals):
296
+ if i > 0:
297
+ writer.write(",\n\n")
298
+
299
+ if literal.description:
300
+ (
301
+ literal_comment,
302
+ literal_comment_errors,
303
+ ) = csharp_description.generate_comment_for_enumeration_literal(
304
+ literal.description
305
+ )
306
+
307
+ if literal_comment_errors:
308
+ return None, Error(
309
+ literal.description.parsed.node,
310
+ f"Failed to generate the comment "
311
+ f"for the enumeration literal {literal.name!r}",
312
+ literal_comment_errors,
313
+ )
314
+
315
+ assert literal_comment is not None
316
+
317
+ writer.write(textwrap.indent(literal_comment, I))
318
+ writer.write("\n")
319
+
320
+ writer.write(
321
+ textwrap.indent(
322
+ f"[EnumMember(Value = {csharp_common.string_literal(literal.value)})]\n"
323
+ f"{csharp_naming.enum_literal_name(literal.name)}",
324
+ I,
325
+ )
326
+ )
327
+
328
+ writer.write("\n}")
329
+
330
+ return Stripped(writer.getvalue()), None
331
+
332
+
333
+ @ensure(lambda result: (result[0] is None) ^ (result[1] is None))
334
+ def _generate_interface(
335
+ cls: intermediate.ClassUnion,
336
+ ) -> Tuple[Optional[Stripped], Optional[Error]]:
337
+ """Generate C# interface for the given class ``cls``."""
338
+ writer = io.StringIO()
339
+
340
+ if cls.description is not None:
341
+ comment, comment_errors = csharp_description.generate_comment_for_our_type(
342
+ cls.description
343
+ )
344
+
345
+ if comment_errors is not None:
346
+ return None, Error(
347
+ cls.description.parsed.node,
348
+ "Failed to generate the documentation comment",
349
+ comment_errors,
350
+ )
351
+
352
+ assert comment is not None
353
+
354
+ writer.write(comment)
355
+ writer.write("\n")
356
+
357
+ name = csharp_naming.interface_name(cls.name)
358
+
359
+ inheritances = [inheritance.name for inheritance in cls.inheritances]
360
+ if len(inheritances) == 0:
361
+ # NOTE (mristin, 2022-05-05):
362
+ # We need to include "IClass" only if there are no other parents.
363
+ # Otherwise, one of the parents will already implement "IClass" so specifying
364
+ # that this descendant implements "IClass" is redundant.
365
+ inheritances = [Identifier("Class")]
366
+
367
+ inheritance_names = list(map(csharp_naming.interface_name, inheritances))
368
+
369
+ assert len(inheritances) > 0
370
+ if len(inheritances) == 1:
371
+ writer.write(f"public interface {name} : {inheritance_names[0]}\n{{\n")
372
+ else:
373
+ writer.write(f"public interface {name} :\n")
374
+ for i, inheritance_name in enumerate(inheritance_names):
375
+ if i > 0:
376
+ writer.write(",\n")
377
+
378
+ writer.write(textwrap.indent(inheritance_name, II))
379
+
380
+ writer.write("\n{\n")
381
+
382
+ # Code blocks separated by double newlines and indented once
383
+ blocks = [] # type: List[Stripped]
384
+
385
+ # region Getters and setters
386
+
387
+ for prop in cls.properties:
388
+ if prop.specified_for is not cls:
389
+ continue
390
+
391
+ prop_type = csharp_common.generate_type(type_annotation=prop.type_annotation)
392
+ prop_name = csharp_naming.property_name(prop.name)
393
+
394
+ if prop.description is not None:
395
+ (
396
+ prop_comment,
397
+ prop_comment_errors,
398
+ ) = csharp_description.generate_comment_for_property(prop.description)
399
+
400
+ if prop_comment_errors is not None:
401
+ return None, Error(
402
+ prop.description.parsed.node,
403
+ f"Failed to generate the documentation comment "
404
+ f"for the property {prop.name!r}",
405
+ prop_comment_errors,
406
+ )
407
+
408
+ blocks.append(
409
+ Stripped(
410
+ f"{prop_comment}\n"
411
+ f"public {prop_type} {prop_name} {{ get; set; }}"
412
+ )
413
+ )
414
+ else:
415
+ blocks.append(Stripped(f"public {prop_type} {prop_name} {{ get; set; }}"))
416
+
417
+ # endregion
418
+
419
+ # region Signatures
420
+
421
+ for method in cls.methods:
422
+ if method.specified_for is not cls:
423
+ continue
424
+
425
+ signature_blocks = [] # type: List[Stripped]
426
+
427
+ if method.description is not None:
428
+ (
429
+ signature_comment,
430
+ signature_comment_errors,
431
+ ) = csharp_description.generate_comment_for_signature(method.description)
432
+
433
+ if signature_comment_errors is not None:
434
+ return None, Error(
435
+ method.description.parsed.node,
436
+ f"Failed to generate the documentation comment "
437
+ f"for the method {method.name!r}",
438
+ signature_comment_errors,
439
+ )
440
+
441
+ assert signature_comment is not None
442
+
443
+ signature_blocks.append(signature_comment)
444
+
445
+ # fmt: off
446
+ returns = (
447
+ csharp_common.generate_type(type_annotation=method.returns)
448
+ if method.returns is not None else "void"
449
+ )
450
+ # fmt: on
451
+
452
+ arg_codes = [] # type: List[Stripped]
453
+ for arg in method.arguments:
454
+ arg_type = csharp_common.generate_type(type_annotation=arg.type_annotation)
455
+ arg_name = csharp_naming.argument_name(arg.name)
456
+ arg_codes.append(Stripped(f"{arg_type} {arg_name}"))
457
+
458
+ signature_name = csharp_naming.method_name(method.name)
459
+ if len(arg_codes) > 2:
460
+ arg_block = ",\n".join(arg_codes)
461
+ arg_block_indented = textwrap.indent(arg_block, I)
462
+ signature_blocks.append(
463
+ Stripped(f"public {returns} {signature_name}(\n{arg_block_indented});")
464
+ )
465
+ elif len(arg_codes) == 1:
466
+ signature_blocks.append(
467
+ Stripped(f"public {returns} {signature_name}({arg_codes[0]});")
468
+ )
469
+ else:
470
+ assert len(arg_codes) == 0
471
+ signature_blocks.append(Stripped(f"public {returns} {signature_name}();"))
472
+
473
+ blocks.append(Stripped("\n".join(signature_blocks)))
474
+
475
+ for prop in cls.properties:
476
+ if prop.specified_for is not cls:
477
+ continue
478
+
479
+ if isinstance(
480
+ prop.type_annotation, intermediate.OptionalTypeAnnotation
481
+ ) and isinstance(prop.type_annotation.value, intermediate.ListTypeAnnotation):
482
+ prop_name = csharp_naming.property_name(prop.name)
483
+ items_type = csharp_common.generate_type(prop.type_annotation.value.items)
484
+ blocks.append(
485
+ Stripped(
486
+ f"""\
487
+ /// <summary>
488
+ /// Iterate over {prop_name}, if set, and otherwise return an empty enumerable.
489
+ /// </summary>
490
+ public IEnumerable<{items_type}> Over{prop_name}OrEmpty();"""
491
+ )
492
+ )
493
+
494
+ # endregion
495
+
496
+ if len(blocks) == 0:
497
+ blocks = [Stripped("// Intentionally empty.")]
498
+
499
+ for i, code in enumerate(blocks):
500
+ if i > 0:
501
+ writer.write("\n\n")
502
+
503
+ writer.write(textwrap.indent(code, I))
504
+
505
+ writer.write("\n}")
506
+
507
+ return Stripped(writer.getvalue()), None
508
+
509
+
510
+ class _DescendBodyUnroller(csharp_unrolling.AbstractUnroller):
511
+ """Generate the code that unrolls descent into an element."""
512
+
513
+ #: If set, generates the code with unrolled yields.
514
+ #: Otherwise, we do not unroll recursively.
515
+ _recurse: Final[bool]
516
+
517
+ #: Pre-computed descendability map. A type is descendable if we should unroll it
518
+ #: further.
519
+ _descendability: Final[Mapping[intermediate.TypeAnnotationUnion, bool]]
520
+
521
+ def __init__(
522
+ self,
523
+ recurse: bool,
524
+ descendability: Mapping[intermediate.TypeAnnotationUnion, bool],
525
+ ) -> None:
526
+ """Initialize with the given values."""
527
+ self._recurse = recurse
528
+ self._descendability = descendability
529
+
530
+ def _unroll_primitive_type_annotation(
531
+ self,
532
+ unrollee_expr: str,
533
+ type_annotation: intermediate.PrimitiveTypeAnnotation,
534
+ path: List[str],
535
+ item_level: int,
536
+ key_value_level: int,
537
+ ) -> List[csharp_unrolling.Node]:
538
+ """Generate code for the given specific ``type_annotation``."""
539
+ # We can not descend into a primitive type.
540
+ return []
541
+
542
+ def _unroll_our_type_annotation(
543
+ self,
544
+ unrollee_expr: str,
545
+ type_annotation: intermediate.OurTypeAnnotation,
546
+ path: List[str],
547
+ item_level: int,
548
+ key_value_level: int,
549
+ ) -> List[csharp_unrolling.Node]:
550
+ """Generate code for the given specific ``type_annotation``."""
551
+ our_type = type_annotation.our_type
552
+
553
+ if isinstance(our_type, intermediate.Enumeration):
554
+ return []
555
+
556
+ elif isinstance(our_type, intermediate.ConstrainedPrimitive):
557
+ # We can not descend into a primitive type.
558
+ return []
559
+
560
+ assert isinstance(our_type, intermediate.Class) # Exhaustively match
561
+
562
+ result = [csharp_unrolling.Node(f"yield return {unrollee_expr};", children=[])]
563
+
564
+ if self._recurse:
565
+ if self._descendability[type_annotation]:
566
+ recurse_var = csharp_unrolling.AbstractUnroller._loop_var_name(
567
+ level=item_level, suffix="Item"
568
+ )
569
+
570
+ result.append(
571
+ csharp_unrolling.Node(
572
+ text=textwrap.dedent(
573
+ f"""\
574
+ // Recurse
575
+ foreach (var {recurse_var} in {unrollee_expr}.Descend())
576
+ {{
577
+ yield return {recurse_var};
578
+ }}"""
579
+ ),
580
+ children=[],
581
+ )
582
+ )
583
+ else:
584
+ result.append(
585
+ csharp_unrolling.Node(
586
+ text="// Recursive descent ends here.", children=[]
587
+ )
588
+ )
589
+
590
+ return result
591
+
592
+ def _unroll_list_type_annotation(
593
+ self,
594
+ unrollee_expr: str,
595
+ type_annotation: intermediate.ListTypeAnnotation,
596
+ path: List[str],
597
+ item_level: int,
598
+ key_value_level: int,
599
+ ) -> List[csharp_unrolling.Node]:
600
+ """Generate code for the given specific ``type_annotation``."""
601
+ item_var = csharp_unrolling.AbstractUnroller._loop_var_name(
602
+ level=item_level, suffix="Item"
603
+ )
604
+
605
+ children = self.unroll(
606
+ unrollee_expr=item_var,
607
+ type_annotation=type_annotation.items,
608
+ path=[], # Path is unused in this context
609
+ item_level=item_level + 1,
610
+ key_value_level=key_value_level,
611
+ )
612
+
613
+ if len(children) == 0:
614
+ return []
615
+
616
+ node = csharp_unrolling.Node(
617
+ text=f"foreach (var {item_var} in {unrollee_expr})",
618
+ children=children,
619
+ )
620
+
621
+ return [node]
622
+
623
+ def _unroll_optional_type_annotation(
624
+ self,
625
+ unrollee_expr: str,
626
+ type_annotation: intermediate.OptionalTypeAnnotation,
627
+ path: List[str],
628
+ item_level: int,
629
+ key_value_level: int,
630
+ ) -> List[csharp_unrolling.Node]:
631
+ """Generate code for the given specific ``type_annotation``."""
632
+ children = self.unroll(
633
+ unrollee_expr=unrollee_expr,
634
+ type_annotation=type_annotation.value,
635
+ path=path,
636
+ item_level=item_level,
637
+ key_value_level=key_value_level,
638
+ )
639
+
640
+ if len(children) == 0:
641
+ return []
642
+
643
+ return [
644
+ csharp_unrolling.Node(
645
+ text=f"if ({unrollee_expr} != null)", children=children
646
+ )
647
+ ]
648
+
649
+
650
+ def _generate_descend_body(cls: intermediate.ConcreteClass, recurse: bool) -> Stripped:
651
+ """
652
+ Generate the body of the ``Descend`` and ``DescendOnce`` methods.
653
+
654
+ With this function, we can unroll the recursion as a simple optimization
655
+ in the recursive case.
656
+ """
657
+ blocks = [] # type: List[Stripped]
658
+
659
+ for prop in cls.properties:
660
+ descendability = intermediate.map_descendability(
661
+ type_annotation=prop.type_annotation
662
+ )
663
+
664
+ if not descendability[prop.type_annotation]:
665
+ continue
666
+
667
+ # region Unroll
668
+
669
+ unroller = _DescendBodyUnroller(recurse=recurse, descendability=descendability)
670
+
671
+ roots = unroller.unroll(
672
+ unrollee_expr=csharp_naming.property_name(prop.name),
673
+ type_annotation=prop.type_annotation,
674
+ path=[], # We do not use path in this context
675
+ item_level=0,
676
+ key_value_level=0,
677
+ )
678
+
679
+ assert len(roots) > 0, (
680
+ "Since the type annotation was descendable, we must have obtained "
681
+ "at least one unrolling node"
682
+ )
683
+
684
+ blocks.extend(Stripped(csharp_unrolling.render(root)) for root in roots)
685
+
686
+ # endregion
687
+
688
+ if len(blocks) == 0:
689
+ blocks.append(Stripped("// No descendable properties\nyield break;"))
690
+
691
+ return Stripped("\n\n".join(blocks))
692
+
693
+
694
+ def _generate_descend_once_method(cls: intermediate.ConcreteClass) -> Stripped:
695
+ """Generate the ``DescendOnce`` method for the concrete class ``cls``."""
696
+
697
+ body = _generate_descend_body(cls=cls, recurse=False)
698
+
699
+ indented_body = textwrap.indent(body, I)
700
+
701
+ return Stripped(
702
+ f"""\
703
+ /// <summary>
704
+ /// Iterate over all the class instances referenced from this instance
705
+ /// without further recursion.
706
+ /// </summary>
707
+ public IEnumerable<IClass> DescendOnce()
708
+ {{
709
+ {indented_body}
710
+ }}"""
711
+ )
712
+
713
+
714
+ def _generate_descend_method(cls: intermediate.ConcreteClass) -> Stripped:
715
+ """Generate the recursive ``Descend`` method for the concrete class ``cls``."""
716
+
717
+ body = _generate_descend_body(cls=cls, recurse=True)
718
+
719
+ indented_body = textwrap.indent(body, I)
720
+
721
+ return Stripped(
722
+ f"""\
723
+ /// <summary>
724
+ /// Iterate recursively over all the class instances referenced from this instance.
725
+ /// </summary>
726
+ public IEnumerable<IClass> Descend()
727
+ {{
728
+ {indented_body}
729
+ }}"""
730
+ )
731
+
732
+
733
+ def _generate_default_value(default: intermediate.Default) -> Stripped:
734
+ """Generate the C# code representing the default value of an argument."""
735
+ code = None # type: Optional[str]
736
+
737
+ if default is not None:
738
+ if isinstance(default, intermediate.DefaultPrimitive):
739
+ if default.value is None:
740
+ code = "null"
741
+ elif isinstance(default.value, bool):
742
+ code = "true" if default.value else "false"
743
+ elif isinstance(default.value, str):
744
+ code = csharp_common.string_literal(default.value)
745
+ elif isinstance(default.value, int):
746
+ code = str(default.value)
747
+ elif isinstance(default.value, float):
748
+ code = f"{default}d"
749
+ else:
750
+ assert_never(default.value)
751
+ elif isinstance(default, intermediate.DefaultEnumerationLiteral):
752
+ code = ".".join(
753
+ [
754
+ csharp_naming.enum_name(default.enumeration.name),
755
+ csharp_naming.enum_literal_name(default.literal.name),
756
+ ]
757
+ )
758
+ else:
759
+ assert_never(default)
760
+
761
+ assert code is not None
762
+ return Stripped(code)
763
+
764
+
765
+ @require(lambda cls: not cls.is_implementation_specific)
766
+ @require(lambda cls: not cls.constructor.is_implementation_specific)
767
+ @ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
768
+ def _generate_constructor(
769
+ cls: intermediate.ConcreteClass,
770
+ ) -> Tuple[Optional[Stripped], Optional[Error]]:
771
+ """
772
+ Generate the constructor function for the given concrete class ``cls``.
773
+
774
+ Return empty string if there is an empty constructor.
775
+ """
776
+ if (
777
+ len(cls.constructor.arguments) == 0
778
+ and len(cls.constructor.inlined_statements) == 0
779
+ ):
780
+ return Stripped(""), None
781
+
782
+ cls_name = csharp_naming.class_name(cls.name)
783
+
784
+ blocks = [] # type: List[str]
785
+
786
+ arg_codes = [] # type: List[str]
787
+ for arg in cls.constructor.arguments:
788
+ arg_type = csharp_common.generate_type(type_annotation=arg.type_annotation)
789
+ arg_name = csharp_naming.argument_name(arg.name)
790
+
791
+ if arg.default is None:
792
+ arg_codes.append(Stripped(f"{arg_type} {arg_name}"))
793
+ else:
794
+ arg_codes.append(
795
+ Stripped(
796
+ f"{arg_type} {arg_name} = {_generate_default_value(arg.default)}"
797
+ )
798
+ )
799
+
800
+ if len(arg_codes) == 0:
801
+ blocks.append(f"public {cls_name}()\n{{")
802
+ if len(arg_codes) == 1:
803
+ blocks.append(f"public {cls_name}({arg_codes[0]})\n{{")
804
+ else:
805
+ arg_block = ",\n".join(arg_codes)
806
+ arg_block_indented = textwrap.indent(arg_block, I)
807
+ blocks.append(Stripped(f"public {cls_name}(\n{arg_block_indented})\n{{"))
808
+
809
+ body = [] # type: List[str]
810
+ for stmt in cls.constructor.inlined_statements:
811
+ if isinstance(stmt, intermediate_construction.AssignArgument):
812
+ if stmt.default is None:
813
+ body.append(
814
+ f"{csharp_naming.property_name(stmt.name)} = "
815
+ f"{csharp_naming.argument_name(stmt.argument)};"
816
+ )
817
+ else:
818
+ if isinstance(stmt.default, intermediate_construction.EmptyList):
819
+ prop = cls.properties_by_name[stmt.name]
820
+
821
+ type_anno = prop.type_annotation
822
+ while isinstance(type_anno, intermediate.OptionalTypeAnnotation):
823
+ type_anno = type_anno.value
824
+
825
+ prop_type = csharp_common.generate_type(type_annotation=type_anno)
826
+
827
+ arg_name = csharp_naming.argument_name(stmt.argument)
828
+
829
+ # Write the assignment as a ternary operator
830
+ writer = io.StringIO()
831
+ writer.write(f"{csharp_naming.property_name(stmt.name)} = ")
832
+ writer.write(f"({arg_name} != null)\n")
833
+ writer.write(textwrap.indent(f"? {arg_name}\n", I))
834
+ writer.write(textwrap.indent(f": new {prop_type}();", I))
835
+
836
+ body.append(writer.getvalue())
837
+ elif isinstance(
838
+ stmt.default, intermediate_construction.DefaultEnumLiteral
839
+ ):
840
+ literal_code = ".".join(
841
+ [
842
+ csharp_naming.enum_name(stmt.default.enum.name),
843
+ csharp_naming.enum_literal_name(stmt.default.literal.name),
844
+ ]
845
+ )
846
+
847
+ arg_name = csharp_naming.argument_name(stmt.argument)
848
+
849
+ body.append(
850
+ Stripped(
851
+ f"""\
852
+ {csharp_naming.property_name(stmt.name)} = {arg_name} ?? {literal_code};"""
853
+ )
854
+ )
855
+ else:
856
+ assert_never(stmt.default)
857
+
858
+ else:
859
+ assert_never(stmt)
860
+
861
+ blocks.append("\n".join(textwrap.indent(stmt_code, I) for stmt_code in body))
862
+
863
+ blocks.append("}")
864
+
865
+ return Stripped("\n".join(blocks)), None
866
+
867
+
868
+ @require(lambda cls: not cls.is_implementation_specific)
869
+ @ensure(lambda result: (result[0] is None) ^ (result[1] is None))
870
+ def _generate_class(
871
+ cls: intermediate.ConcreteClass,
872
+ spec_impls: specific_implementations.SpecificImplementations,
873
+ ) -> Tuple[Optional[Stripped], Optional[Error]]:
874
+ """Generate C# code for the given concrete class ``cls``."""
875
+ # Code blocks to be later joined by double newlines and indented once
876
+ blocks = [] # type: List[Stripped]
877
+
878
+ # region Getters and setters
879
+
880
+ for prop in cls.properties:
881
+ prop_type = csharp_common.generate_type(type_annotation=prop.type_annotation)
882
+
883
+ prop_name = csharp_naming.property_name(prop.name)
884
+
885
+ prop_blocks = [] # type: List[Stripped]
886
+
887
+ if prop.description is not None:
888
+ (
889
+ prop_comment,
890
+ prop_comment_errors,
891
+ ) = csharp_description.generate_comment_for_property(prop.description)
892
+ if prop_comment_errors:
893
+ return None, Error(
894
+ prop.description.parsed.node,
895
+ f"Failed to generate the documentation comment "
896
+ f"for the property {prop.name!r}",
897
+ prop_comment_errors,
898
+ )
899
+
900
+ assert prop_comment is not None
901
+
902
+ prop_blocks.append(prop_comment)
903
+
904
+ prop_blocks.append(Stripped(f"public {prop_type} {prop_name} {{ get; set; }}"))
905
+
906
+ blocks.append(Stripped("\n".join(prop_blocks)))
907
+
908
+ # endregion
909
+
910
+ # region OverXOrEmpty getter
911
+
912
+ for prop in cls.properties:
913
+ if isinstance(
914
+ prop.type_annotation, intermediate.OptionalTypeAnnotation
915
+ ) and isinstance(prop.type_annotation.value, intermediate.ListTypeAnnotation):
916
+ prop_name = csharp_naming.property_name(prop.name)
917
+ items_type = csharp_common.generate_type(prop.type_annotation.value.items)
918
+
919
+ blocks.append(
920
+ Stripped(
921
+ f"""\
922
+ /// <summary>
923
+ /// Iterate over {prop_name}, if set, and otherwise return an empty enumerable.
924
+ /// </summary>
925
+ public IEnumerable<{items_type}> Over{prop_name}OrEmpty()
926
+ {{
927
+ {I}return {prop_name}
928
+ {II}?? System.Linq.Enumerable.Empty<{items_type}>();
929
+ }}"""
930
+ )
931
+ )
932
+
933
+ # endregion
934
+
935
+ # region Methods
936
+
937
+ errors = [] # type: List[Error]
938
+
939
+ for method in cls.methods:
940
+ if isinstance(method, intermediate.ImplementationSpecificMethod):
941
+ # NOTE (mristin, 2022-05-18):
942
+ # We have to repeat the implementation of the method in all the descendants
943
+ # since we share only interfaces between the classes, but not
944
+ # the implementations.
945
+ #
946
+ # This makes the code a bit larger, but the class hierarchy is much simpler
947
+ # and the individual classes are much easier to grasp.
948
+ implementation_key = specific_implementations.ImplementationKey(
949
+ f"Types/{method.specified_for.name}/{method.name}.cs"
950
+ )
951
+
952
+ implementation = spec_impls.get(implementation_key, None)
953
+
954
+ if implementation is None:
955
+ errors.append(
956
+ Error(
957
+ method.parsed.node,
958
+ f"The implementation is missing for "
959
+ f"the implementation-specific method: {implementation_key}",
960
+ )
961
+ )
962
+ continue
963
+
964
+ blocks.append(implementation)
965
+ else:
966
+ # NOTE (mristin, 2021-09-16):
967
+ # At the moment, we do not transpile the method body and its contracts.
968
+ # We want to finish the meta-model for the V3 and fix de/serialization
969
+ # before taking on this rather hard task.
970
+
971
+ errors.append(
972
+ Error(
973
+ cls.parsed.node,
974
+ "At the moment, we do not transpile the method body and "
975
+ "its contracts. We want to finish the meta-model for the V3 and "
976
+ "fix de/serialization before taking on this rather hard task.",
977
+ )
978
+ )
979
+
980
+ blocks.append(_generate_descend_once_method(cls=cls))
981
+
982
+ blocks.append(_generate_descend_method(cls=cls))
983
+
984
+ visit_name = csharp_naming.method_name(Identifier(f"visit_{cls.name}"))
985
+
986
+ blocks.append(
987
+ Stripped(
988
+ f"""\
989
+ /// <summary>
990
+ /// Accept the <paramref name="visitor" /> to visit this instance
991
+ /// for double dispatch.
992
+ /// </summary>
993
+ public void Accept(Visitation.IVisitor visitor)
994
+ {{
995
+ {I}visitor.{visit_name}(this);
996
+ }}"""
997
+ )
998
+ )
999
+
1000
+ blocks.append(
1001
+ Stripped(
1002
+ f"""\
1003
+ /// <summary>
1004
+ /// Accept the visitor to visit this instance for double dispatch
1005
+ /// with the <paramref name="context" />.
1006
+ /// </summary>
1007
+ public void Accept<TContext>(
1008
+ {I}Visitation.IVisitorWithContext<TContext> visitor,
1009
+ {I}TContext context)
1010
+ {{
1011
+ {I}visitor.{visit_name}(this, context);
1012
+ }}"""
1013
+ )
1014
+ )
1015
+
1016
+ transform_name = csharp_naming.method_name(Identifier(f"transform_{cls.name}"))
1017
+
1018
+ blocks.append(
1019
+ Stripped(
1020
+ f"""\
1021
+ /// <summary>
1022
+ /// Accept the <paramref name="transformer" /> to transform this instance
1023
+ /// for double dispatch.
1024
+ /// </summary>
1025
+ public T Transform<T>(Visitation.ITransformer<T> transformer)
1026
+ {{
1027
+ {I}return transformer.{transform_name}(this);
1028
+ }}"""
1029
+ )
1030
+ )
1031
+
1032
+ blocks.append(
1033
+ Stripped(
1034
+ f"""\
1035
+ /// <summary>
1036
+ /// Accept the <paramref name="transformer" /> to visit this instance
1037
+ /// for double dispatch with the <paramref name="context" />.
1038
+ /// </summary>
1039
+ public T Transform<TContext, T>(
1040
+ {I}Visitation.ITransformerWithContext<TContext, T> transformer,
1041
+ {I}TContext context)
1042
+ {{
1043
+ {I}return transformer.{transform_name}(this, context);
1044
+ }}"""
1045
+ )
1046
+ )
1047
+
1048
+ # endregion
1049
+
1050
+ # region Constructor
1051
+
1052
+ if cls.constructor.is_implementation_specific:
1053
+ implementation_key = specific_implementations.ImplementationKey(
1054
+ f"Types/{cls.name}/{cls.name}.cs"
1055
+ )
1056
+ implementation = spec_impls.get(implementation_key, None)
1057
+
1058
+ if implementation is None:
1059
+ errors.append(
1060
+ Error(
1061
+ cls.parsed.node,
1062
+ f"The implementation of the implementation-specific constructor "
1063
+ f"is missing: {implementation_key}",
1064
+ )
1065
+ )
1066
+ else:
1067
+ blocks.append(implementation)
1068
+ else:
1069
+ constructor_block, error = _generate_constructor(cls=cls)
1070
+
1071
+ if error is not None:
1072
+ errors.append(error)
1073
+ else:
1074
+ # NOTE (mristin, 2022-06-21):
1075
+ # Empty constructor will be automatically generated by the compiler.
1076
+ if constructor_block != "":
1077
+ assert constructor_block is not None
1078
+ blocks.append(constructor_block)
1079
+
1080
+ # endregion
1081
+
1082
+ if len(errors) > 0:
1083
+ return None, Error(
1084
+ cls.parsed.node,
1085
+ f"Failed to generate the code for the class {cls.name}",
1086
+ errors,
1087
+ )
1088
+
1089
+ # NOTE (mristin, 2023-02-08):
1090
+ # Since C# does not support multiple inheritance, we model all the abstract classes
1091
+ # as interfaces. Hence, a class only implements interfaces and does not extend
1092
+ # any abstract class.
1093
+ #
1094
+ # Moreover, we generate an interface for *each* concrete class. This is necessary
1095
+ # for two reasons. First, if a concrete class has descendants, we have to allow
1096
+ # for polymorphism and multiple inheritance from multiple concrete classes (which
1097
+ # is allowed in the meta-model). Second, we want to allow the downstream users to
1098
+ # introduce custom enhancements and wrap our data structures. To that end, we
1099
+ # generate an interface for each concrete class, even if it has no descendants.
1100
+ # This allows the downstream users to still use our interfaces, but provide
1101
+ # custom extensions.
1102
+ #
1103
+ # Finally, every class of the meta-model also implements the general
1104
+ # ``IClass`` interface.
1105
+
1106
+ interface_name = csharp_naming.interface_name(cls.name)
1107
+
1108
+ name = csharp_naming.class_name(cls.name)
1109
+
1110
+ writer = io.StringIO()
1111
+
1112
+ if cls.description is not None:
1113
+ comment, comment_errors = csharp_description.generate_comment_for_our_type(
1114
+ cls.description
1115
+ )
1116
+ if comment_errors is not None:
1117
+ return None, Error(
1118
+ cls.description.parsed.node,
1119
+ "Failed to generate the comment description",
1120
+ comment_errors,
1121
+ )
1122
+
1123
+ assert comment is not None
1124
+
1125
+ writer.write(comment)
1126
+ writer.write("\n")
1127
+
1128
+ writer.write(f"public class {name} : {interface_name}\n{{\n")
1129
+
1130
+ for i, block in enumerate(blocks):
1131
+ if i > 0:
1132
+ writer.write("\n\n")
1133
+
1134
+ writer.write(textwrap.indent(block, I))
1135
+
1136
+ writer.write("\n}")
1137
+
1138
+ return Stripped(writer.getvalue()), None
1139
+
1140
+
1141
+ # fmt: off
1142
+ @ensure(lambda result: (result[0] is not None) ^ (result[1] is not None))
1143
+ @ensure(
1144
+ lambda result:
1145
+ not (result[0] is not None) or result[0].endswith('\n'),
1146
+ "Trailing newline mandatory for valid end-of-files"
1147
+ )
1148
+ # fmt: on
1149
+ def generate(
1150
+ symbol_table: VerifiedIntermediateSymbolTable,
1151
+ namespace: csharp_common.NamespaceIdentifier,
1152
+ spec_impls: specific_implementations.SpecificImplementations,
1153
+ ) -> Tuple[Optional[str], Optional[List[Error]]]:
1154
+ """
1155
+ Generate the C# code of the structures based on the symbol table.
1156
+
1157
+ The ``namespace`` defines the AAS C# namespace.
1158
+ """
1159
+ code_blocks = [
1160
+ Stripped(
1161
+ f"""\
1162
+ /// <summary>
1163
+ /// Represent a general class of an AAS model.
1164
+ /// </summary>
1165
+ public interface IClass
1166
+ {{
1167
+ {I}/// <summary>
1168
+ {I}/// Iterate over all the class instances referenced from this instance
1169
+ {I}/// without further recursion.
1170
+ {I}/// </summary>
1171
+ {I}public IEnumerable<IClass> DescendOnce();
1172
+
1173
+ {I}/// <summary>
1174
+ {I}/// Iterate recursively over all the class instances referenced from this instance.
1175
+ {I}/// </summary>
1176
+ {I}public IEnumerable<IClass> Descend();
1177
+
1178
+ {I}/// <summary>
1179
+ {I}/// Accept the <paramref name="visitor" /> to visit this instance
1180
+ {I}/// for double dispatch.
1181
+ {I}/// </summary>
1182
+ {I}public void Accept(Visitation.IVisitor visitor);
1183
+
1184
+ {I}/// <summary>
1185
+ {I}/// Accept the visitor to visit this instance for double dispatch
1186
+ {I}/// with the <paramref name="context" />.
1187
+ {I}/// </summary>
1188
+ {I}public void Accept<TContext>(
1189
+ {II}Visitation.IVisitorWithContext<TContext> visitor,
1190
+ {II}TContext context);
1191
+
1192
+ {I}/// <summary>
1193
+ {I}/// Accept the <paramref name="transformer" /> to transform this instance
1194
+ {I}/// for double dispatch.
1195
+ {I}/// </summary>
1196
+ {I}public T Transform<T>(Visitation.ITransformer<T> transformer);
1197
+
1198
+ {I}/// <summary>
1199
+ {I}/// Accept the <paramref name="transformer" /> to visit this instance
1200
+ {I}/// for double dispatch with the <paramref name="context" />.
1201
+ {I}/// </summary>
1202
+ {I}public T Transform<TContext, T>(
1203
+ {II}Visitation.ITransformerWithContext<TContext, T> transformer,
1204
+ {II}TContext context);
1205
+ }}"""
1206
+ )
1207
+ ] # type: List[Stripped]
1208
+
1209
+ errors = [] # type: List[Error]
1210
+
1211
+ for our_type in symbol_table.our_types:
1212
+ if not isinstance(
1213
+ our_type,
1214
+ (
1215
+ intermediate.Enumeration,
1216
+ intermediate.AbstractClass,
1217
+ intermediate.ConcreteClass,
1218
+ ),
1219
+ ):
1220
+ continue
1221
+
1222
+ if (
1223
+ isinstance(our_type, intermediate.Class)
1224
+ and our_type.is_implementation_specific
1225
+ ):
1226
+ implementation_key = specific_implementations.ImplementationKey(
1227
+ f"Types/{our_type.name}.cs"
1228
+ )
1229
+
1230
+ code = spec_impls.get(implementation_key, None)
1231
+ if code is None:
1232
+ errors.append(
1233
+ Error(
1234
+ our_type.parsed.node,
1235
+ f"The implementation is missing "
1236
+ f"for the implementation-specific class: {implementation_key}",
1237
+ )
1238
+ )
1239
+ continue
1240
+
1241
+ code_blocks.append(code)
1242
+ continue
1243
+
1244
+ if isinstance(our_type, intermediate.Enumeration):
1245
+ code, error = _generate_enum(enum=our_type)
1246
+ if error is not None:
1247
+ errors.append(
1248
+ Error(
1249
+ our_type.parsed.node,
1250
+ f"Failed to generate the code for "
1251
+ f"the enumeration {our_type.name!r}",
1252
+ [error],
1253
+ )
1254
+ )
1255
+ continue
1256
+
1257
+ assert code is not None
1258
+ code_blocks.append(code)
1259
+
1260
+ elif isinstance(
1261
+ our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)
1262
+ ):
1263
+ code, error = _generate_interface(cls=our_type)
1264
+ if error is not None:
1265
+ errors.append(
1266
+ Error(
1267
+ our_type.parsed.node,
1268
+ f"Failed to generate the interface code for "
1269
+ f"the class {our_type.name!r}",
1270
+ [error],
1271
+ )
1272
+ )
1273
+ continue
1274
+
1275
+ assert code is not None
1276
+ code_blocks.append(code)
1277
+
1278
+ if isinstance(our_type, intermediate.ConcreteClass):
1279
+ code, error = _generate_class(cls=our_type, spec_impls=spec_impls)
1280
+ if error is not None:
1281
+ errors.append(
1282
+ Error(
1283
+ our_type.parsed.node,
1284
+ f"Failed to generate the code for "
1285
+ f"the concrete class {our_type.name!r}",
1286
+ [error],
1287
+ )
1288
+ )
1289
+ continue
1290
+
1291
+ assert code is not None
1292
+ code_blocks.append(code)
1293
+
1294
+ else:
1295
+ assert_never(our_type)
1296
+
1297
+ if len(errors) > 0:
1298
+ return None, errors
1299
+
1300
+ using_directives = [] # type: List[Stripped]
1301
+ using_directives.extend(
1302
+ csharp_common.generate_using_aas_directive_if_necessary(namespace)
1303
+ )
1304
+
1305
+ using_directives.append(
1306
+ Stripped(
1307
+ """\
1308
+ using EnumMemberAttribute = System.Runtime.Serialization.EnumMemberAttribute;
1309
+
1310
+ using System.Collections.Generic; // can't alias"""
1311
+ )
1312
+ )
1313
+
1314
+ code_blocks_joined = "\n\n".join(code_blocks)
1315
+
1316
+ blocks = [
1317
+ csharp_common.WARNING,
1318
+ Stripped("\n".join(using_directives)),
1319
+ Stripped(
1320
+ f"""\
1321
+ namespace {namespace}
1322
+ {{
1323
+ {I}{indent_but_first_line(code_blocks_joined, I)}
1324
+ }} // namespace {namespace}"""
1325
+ ),
1326
+ csharp_common.WARNING,
1327
+ ] # type: List[Stripped]
1328
+
1329
+ out = io.StringIO()
1330
+ for i, block in enumerate(blocks):
1331
+ if i > 0:
1332
+ out.write("\n\n")
1333
+
1334
+ out.write(block)
1335
+
1336
+ out.write("\n")
1337
+
1338
+ return out.getvalue(), None
1339
+
1340
+
1341
+ # endregion