aas-core-codegen 0.0.16__py3-none-any.whl → 0.0.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aas_core_codegen/__init__.py +1 -1
- aas_core_codegen/cpp/pattern/_generate.py +8 -7
- aas_core_codegen/cpp/revm/_generate.py +2 -2
- aas_core_codegen/intermediate/__init__.py +2 -0
- aas_core_codegen/intermediate/_stringify.py +9 -0
- aas_core_codegen/intermediate/_types.py +374 -44
- aas_core_codegen/python/xmlization/_generate.py +3 -1
- {aas_core_codegen-0.0.16.dist-info → aas_core_codegen-0.0.17.dist-info}/METADATA +2 -2
- {aas_core_codegen-0.0.16.dist-info → aas_core_codegen-0.0.17.dist-info}/RECORD +19 -17
- {aas_core_codegen-0.0.16.dist-info → aas_core_codegen-0.0.17.dist-info}/WHEEL +1 -1
- dev/dev_scripts/run_tests_with_rerecord.py +5 -1
- dev/test_data/intermediate/expected/constrained_primitive/inheritance/meta_model.py +17 -0
- dev/tests/cpp/test_pattern.py +31 -31
- dev/tests/intermediate/test_pickle.py +1871 -0
- dev/tests/intermediate/test_types.py +454 -0
- {aas_core_codegen-0.0.16.dist-info → aas_core_codegen-0.0.17.dist-info}/entry_points.txt +0 -0
- {aas_core_codegen-0.0.16.dist-info → aas_core_codegen-0.0.17.dist-info}/licenses/AUTHORS +0 -0
- {aas_core_codegen-0.0.16.dist-info → aas_core_codegen-0.0.17.dist-info}/licenses/LICENSE +0 -0
- {aas_core_codegen-0.0.16.dist-info → aas_core_codegen-0.0.17.dist-info}/top_level.txt +0 -0
|
@@ -15,6 +15,8 @@ from typing import (
|
|
|
15
15
|
OrderedDict,
|
|
16
16
|
Type,
|
|
17
17
|
get_args,
|
|
18
|
+
Dict,
|
|
19
|
+
Any,
|
|
18
20
|
)
|
|
19
21
|
|
|
20
22
|
import docutils.nodes
|
|
@@ -53,12 +55,15 @@ STR_TO_PRIMITIVE_TYPE = {
|
|
|
53
55
|
} # type: Mapping[str, PrimitiveType]
|
|
54
56
|
|
|
55
57
|
# fmt: off
|
|
56
|
-
PRIMITIVE_TYPE_TO_PYTHON_TYPE:
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
PRIMITIVE_TYPE_TO_PYTHON_TYPE: Final[
|
|
59
|
+
Mapping[
|
|
60
|
+
PrimitiveType,
|
|
61
|
+
Union[Type[bool], Type[int], Type[float], Type[str], Type[bytearray]
|
|
62
|
+
]
|
|
63
|
+
]
|
|
59
64
|
] = {
|
|
60
65
|
PrimitiveType.BOOL: bool,
|
|
61
|
-
PrimitiveType.INT
|
|
66
|
+
PrimitiveType.INT: int,
|
|
62
67
|
PrimitiveType.FLOAT: float,
|
|
63
68
|
PrimitiveType.STR: str,
|
|
64
69
|
PrimitiveType.BYTEARRAY: bytearray,
|
|
@@ -834,7 +839,7 @@ class Method(SignatureLike):
|
|
|
834
839
|
arg in arg_set
|
|
835
840
|
for snapshot in contracts.snapshots
|
|
836
841
|
for arg in snapshot.args
|
|
837
|
-
if arg
|
|
842
|
+
if arg != 'self'
|
|
838
843
|
)
|
|
839
844
|
)[1],
|
|
840
845
|
"All arguments of contracts defined in method arguments except ``self``"
|
|
@@ -1066,6 +1071,9 @@ class Enumeration:
|
|
|
1066
1071
|
#: Collect IDs (with :py:func:`id`) of the literal objects in a set
|
|
1067
1072
|
literal_id_set: Final[FrozenSet[int]]
|
|
1068
1073
|
|
|
1074
|
+
#: Set of all the literal values
|
|
1075
|
+
literal_value_set: Final[FrozenSet[str]]
|
|
1076
|
+
|
|
1069
1077
|
def __init__(
|
|
1070
1078
|
self,
|
|
1071
1079
|
name: Identifier,
|
|
@@ -1086,7 +1094,30 @@ class Enumeration:
|
|
|
1086
1094
|
literal.value: literal for literal in self.literals
|
|
1087
1095
|
}
|
|
1088
1096
|
|
|
1089
|
-
self.literal_id_set =
|
|
1097
|
+
self.literal_id_set = self.__class__._compute_literal_id_set(literals)
|
|
1098
|
+
self.literal_value_set = frozenset(literal.value for literal in literals)
|
|
1099
|
+
|
|
1100
|
+
@staticmethod
|
|
1101
|
+
def _compute_literal_id_set(
|
|
1102
|
+
literals: Sequence[EnumerationLiteral],
|
|
1103
|
+
) -> FrozenSet[int]:
|
|
1104
|
+
return frozenset(id(literal) for literal in literals)
|
|
1105
|
+
|
|
1106
|
+
def __getstate__(self) -> Dict[str, Any]:
|
|
1107
|
+
state = self.__dict__.copy()
|
|
1108
|
+
|
|
1109
|
+
state.pop("literal_id_set", None)
|
|
1110
|
+
|
|
1111
|
+
return state
|
|
1112
|
+
|
|
1113
|
+
def __setstate__(self, state: Dict[str, Any]) -> None:
|
|
1114
|
+
self.__dict__.update(state)
|
|
1115
|
+
|
|
1116
|
+
# NOTE (mristin):
|
|
1117
|
+
# We rebuild what we could not pickle.
|
|
1118
|
+
setattr(
|
|
1119
|
+
self, "literal_id_set", Enumeration._compute_literal_id_set(self.literals)
|
|
1120
|
+
)
|
|
1090
1121
|
|
|
1091
1122
|
def __repr__(self) -> str:
|
|
1092
1123
|
"""Represent the instance as a string for easier debugging."""
|
|
@@ -1132,6 +1163,8 @@ class ConstrainedPrimitive:
|
|
|
1132
1163
|
# ``@property`` so that the translation code is forced to use
|
|
1133
1164
|
# ``_set_descendants``.
|
|
1134
1165
|
|
|
1166
|
+
_descendants: Sequence["ConstrainedPrimitive"]
|
|
1167
|
+
|
|
1135
1168
|
_descendant_id_set: FrozenSet[int]
|
|
1136
1169
|
|
|
1137
1170
|
# endregion
|
|
@@ -1169,8 +1202,7 @@ class ConstrainedPrimitive:
|
|
|
1169
1202
|
This method is expected to be called only during the translation phase.
|
|
1170
1203
|
"""
|
|
1171
1204
|
self._ancestors = ancestors
|
|
1172
|
-
|
|
1173
|
-
self._ancestor_id_set = frozenset(id(ancestor) for ancestor in ancestors)
|
|
1205
|
+
self._ancestor_id_set = self.__class__._compute_ancestor_id_set(ancestors)
|
|
1174
1206
|
|
|
1175
1207
|
@require(lambda self, descendants: self not in descendants)
|
|
1176
1208
|
def _set_descendants(self, descendants: Sequence["ConstrainedPrimitive"]) -> None:
|
|
@@ -1179,9 +1211,8 @@ class ConstrainedPrimitive:
|
|
|
1179
1211
|
|
|
1180
1212
|
This method is expected to be called only during the translation phase.
|
|
1181
1213
|
"""
|
|
1182
|
-
self.
|
|
1183
|
-
|
|
1184
|
-
)
|
|
1214
|
+
self._descendants = descendants
|
|
1215
|
+
self._descendant_id_set = self.__class__._compute_descendant_id_set(descendants)
|
|
1185
1216
|
|
|
1186
1217
|
def _set_invariants(self, invariants: Sequence[Invariant]) -> None:
|
|
1187
1218
|
"""
|
|
@@ -1190,7 +1221,7 @@ class ConstrainedPrimitive:
|
|
|
1190
1221
|
This method is expected to be called only during the translation phase.
|
|
1191
1222
|
"""
|
|
1192
1223
|
self._invariants = invariants
|
|
1193
|
-
self._invariant_id_set =
|
|
1224
|
+
self._invariant_id_set = self.__class__._compute_invariant_id_set(invariants)
|
|
1194
1225
|
|
|
1195
1226
|
# fmt: off
|
|
1196
1227
|
@require(
|
|
@@ -1206,9 +1237,8 @@ class ConstrainedPrimitive:
|
|
|
1206
1237
|
This method is expected to be called only during the translation phase.
|
|
1207
1238
|
"""
|
|
1208
1239
|
self._inheritances = inheritances
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
id(inheritance) for inheritance in self._inheritances
|
|
1240
|
+
self._inheritance_id_set = self.__class__._compute_inheritance_id_set(
|
|
1241
|
+
self._inheritances
|
|
1212
1242
|
)
|
|
1213
1243
|
|
|
1214
1244
|
# fmt: off
|
|
@@ -1273,6 +1303,28 @@ class ConstrainedPrimitive:
|
|
|
1273
1303
|
self.description = description
|
|
1274
1304
|
self.parsed = parsed
|
|
1275
1305
|
|
|
1306
|
+
@staticmethod
|
|
1307
|
+
def _compute_ancestor_id_set(
|
|
1308
|
+
ancestors: Sequence["ConstrainedPrimitive"],
|
|
1309
|
+
) -> FrozenSet[int]:
|
|
1310
|
+
return frozenset(id(ancestor) for ancestor in ancestors)
|
|
1311
|
+
|
|
1312
|
+
@staticmethod
|
|
1313
|
+
def _compute_descendant_id_set(
|
|
1314
|
+
descendants: Sequence["ConstrainedPrimitive"],
|
|
1315
|
+
) -> FrozenSet[int]:
|
|
1316
|
+
return frozenset(id(descendant) for descendant in descendants)
|
|
1317
|
+
|
|
1318
|
+
@staticmethod
|
|
1319
|
+
def _compute_invariant_id_set(invariants: Sequence[Invariant]) -> FrozenSet[int]:
|
|
1320
|
+
return frozenset(id(inv) for inv in invariants)
|
|
1321
|
+
|
|
1322
|
+
@staticmethod
|
|
1323
|
+
def _compute_inheritance_id_set(
|
|
1324
|
+
inheritances: Sequence["ConstrainedPrimitive"],
|
|
1325
|
+
) -> FrozenSet[int]:
|
|
1326
|
+
return frozenset(id(inheritance) for inheritance in inheritances)
|
|
1327
|
+
|
|
1276
1328
|
@property
|
|
1277
1329
|
def inheritances(self) -> Sequence["ConstrainedPrimitive"]:
|
|
1278
1330
|
"""Return direct parents that this class inherits from."""
|
|
@@ -1288,8 +1340,8 @@ class ConstrainedPrimitive:
|
|
|
1288
1340
|
"""
|
|
1289
1341
|
Return the ancestor constrained primitives.
|
|
1290
1342
|
|
|
1291
|
-
|
|
1292
|
-
|
|
1343
|
+
These are the constrained primitives that this one directly or indirectly
|
|
1344
|
+
inherits from.
|
|
1293
1345
|
"""
|
|
1294
1346
|
return self._ancestors
|
|
1295
1347
|
|
|
@@ -1313,6 +1365,16 @@ class ConstrainedPrimitive:
|
|
|
1313
1365
|
|
|
1314
1366
|
return id(constrained_primitive) in self._ancestor_id_set
|
|
1315
1367
|
|
|
1368
|
+
@property
|
|
1369
|
+
def descendants(self) -> Sequence["ConstrainedPrimitive"]:
|
|
1370
|
+
"""
|
|
1371
|
+
Return the ancestor constrained primitives.
|
|
1372
|
+
|
|
1373
|
+
These are the constrained primitives that directly or indirectly inherit from
|
|
1374
|
+
this one.
|
|
1375
|
+
"""
|
|
1376
|
+
return self._descendants
|
|
1377
|
+
|
|
1316
1378
|
@property
|
|
1317
1379
|
def descendant_id_set(self) -> FrozenSet[int]:
|
|
1318
1380
|
"""List the IDs (as in Python's ``id`` built-in) of the descendants."""
|
|
@@ -1328,6 +1390,40 @@ class ConstrainedPrimitive:
|
|
|
1328
1390
|
"""Collect IDs (with :py:func:`id`) of the invariant objects in a set."""
|
|
1329
1391
|
return self._invariant_id_set
|
|
1330
1392
|
|
|
1393
|
+
def __getstate__(self) -> Dict[str, Any]:
|
|
1394
|
+
state = self.__dict__.copy()
|
|
1395
|
+
|
|
1396
|
+
state.pop("_inheritance_id_set", None)
|
|
1397
|
+
state.pop("_ancestor_id_set", None)
|
|
1398
|
+
state.pop("_descendant_id_set", None)
|
|
1399
|
+
state.pop("_invariant_id_set", None)
|
|
1400
|
+
|
|
1401
|
+
return state
|
|
1402
|
+
|
|
1403
|
+
def __setstate__(self, state: Dict[str, Any]) -> None:
|
|
1404
|
+
self.__dict__.update(state)
|
|
1405
|
+
|
|
1406
|
+
setattr(
|
|
1407
|
+
self,
|
|
1408
|
+
"_inheritance_id_set",
|
|
1409
|
+
self.__class__._compute_inheritance_id_set(self._inheritances),
|
|
1410
|
+
)
|
|
1411
|
+
setattr(
|
|
1412
|
+
self,
|
|
1413
|
+
"_ancestor_id_set",
|
|
1414
|
+
self.__class__._compute_ancestor_id_set(self._ancestors),
|
|
1415
|
+
)
|
|
1416
|
+
setattr(
|
|
1417
|
+
self,
|
|
1418
|
+
"_descendant_id_set",
|
|
1419
|
+
self.__class__._compute_descendant_id_set(self._descendants),
|
|
1420
|
+
)
|
|
1421
|
+
setattr(
|
|
1422
|
+
self,
|
|
1423
|
+
"_invariant_id_set",
|
|
1424
|
+
ConstrainedPrimitive._compute_invariant_id_set(self._invariants),
|
|
1425
|
+
)
|
|
1426
|
+
|
|
1331
1427
|
def __repr__(self) -> str:
|
|
1332
1428
|
"""Represent the instance as a string for easier debugging."""
|
|
1333
1429
|
return (
|
|
@@ -1457,9 +1553,8 @@ class Class(DBC):
|
|
|
1457
1553
|
This method is expected to be called only during the translation phase.
|
|
1458
1554
|
"""
|
|
1459
1555
|
self._inheritances = inheritances
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
id(inheritance) for inheritance in self._inheritances
|
|
1556
|
+
self._inheritance_id_set = self.__class__._compute_inheritance_id_set(
|
|
1557
|
+
self._inheritances
|
|
1463
1558
|
)
|
|
1464
1559
|
|
|
1465
1560
|
@require(lambda self, ancestors: self not in ancestors)
|
|
@@ -1469,8 +1564,7 @@ class Class(DBC):
|
|
|
1469
1564
|
|
|
1470
1565
|
This method is expected to be called only during the translation phase.
|
|
1471
1566
|
"""
|
|
1472
|
-
self._ancestor_id_set =
|
|
1473
|
-
|
|
1567
|
+
self._ancestor_id_set = self.__class__._compute_ancestor_id_set(ancestors)
|
|
1474
1568
|
self._ancestors = ancestors
|
|
1475
1569
|
|
|
1476
1570
|
@require(lambda self, descendants: self not in descendants)
|
|
@@ -1480,9 +1574,7 @@ class Class(DBC):
|
|
|
1480
1574
|
|
|
1481
1575
|
This method is expected to be called only during the translation phase.
|
|
1482
1576
|
"""
|
|
1483
|
-
self._descendant_id_set =
|
|
1484
|
-
id(descendant) for descendant in descendants
|
|
1485
|
-
)
|
|
1577
|
+
self._descendant_id_set = self.__class__._compute_descendant_id_set(descendants)
|
|
1486
1578
|
|
|
1487
1579
|
self._descendants = descendants
|
|
1488
1580
|
|
|
@@ -1492,8 +1584,10 @@ class Class(DBC):
|
|
|
1492
1584
|
if isinstance(descendant, ConcreteClass)
|
|
1493
1585
|
]
|
|
1494
1586
|
|
|
1495
|
-
self._concrete_descendant_id_set =
|
|
1496
|
-
|
|
1587
|
+
self._concrete_descendant_id_set = (
|
|
1588
|
+
self.__class__._compute_concrete_descendant_id_set(
|
|
1589
|
+
self._concrete_descendants
|
|
1590
|
+
)
|
|
1497
1591
|
)
|
|
1498
1592
|
|
|
1499
1593
|
# fmt: off
|
|
@@ -1511,7 +1605,7 @@ class Class(DBC):
|
|
|
1511
1605
|
"""
|
|
1512
1606
|
self._properties = properties
|
|
1513
1607
|
self._properties_by_name = {prop.name: prop for prop in properties}
|
|
1514
|
-
self._property_id_set =
|
|
1608
|
+
self._property_id_set = self.__class__._compute_property_id_set(properties)
|
|
1515
1609
|
|
|
1516
1610
|
# fmt: off
|
|
1517
1611
|
@require(
|
|
@@ -1528,7 +1622,7 @@ class Class(DBC):
|
|
|
1528
1622
|
"""
|
|
1529
1623
|
self._methods = methods
|
|
1530
1624
|
self._methods_by_name = {method.name: method for method in methods}
|
|
1531
|
-
self._method_id_set =
|
|
1625
|
+
self._method_id_set = self.__class__._compute_method_id_set(methods)
|
|
1532
1626
|
|
|
1533
1627
|
def _set_invariants(self, invariants: Sequence[Invariant]) -> None:
|
|
1534
1628
|
"""
|
|
@@ -1537,7 +1631,7 @@ class Class(DBC):
|
|
|
1537
1631
|
This method is expected to be called only during the translation phase.
|
|
1538
1632
|
"""
|
|
1539
1633
|
self._invariants = invariants
|
|
1540
|
-
self._invariant_id_set =
|
|
1634
|
+
self._invariant_id_set = self.__class__._compute_invariant_id_set(invariants)
|
|
1541
1635
|
|
|
1542
1636
|
# fmt: off
|
|
1543
1637
|
@require(
|
|
@@ -1632,6 +1726,40 @@ class Class(DBC):
|
|
|
1632
1726
|
self.description = description
|
|
1633
1727
|
self.parsed = parsed
|
|
1634
1728
|
|
|
1729
|
+
@staticmethod
|
|
1730
|
+
def _compute_inheritance_id_set(
|
|
1731
|
+
inheritances: Sequence["ClassUnion"],
|
|
1732
|
+
) -> FrozenSet[int]:
|
|
1733
|
+
return frozenset(id(inheritance) for inheritance in inheritances)
|
|
1734
|
+
|
|
1735
|
+
@staticmethod
|
|
1736
|
+
def _compute_ancestor_id_set(ancestors: Sequence["ClassUnion"]) -> FrozenSet[int]:
|
|
1737
|
+
return frozenset(id(ancestor) for ancestor in ancestors)
|
|
1738
|
+
|
|
1739
|
+
@staticmethod
|
|
1740
|
+
def _compute_descendant_id_set(
|
|
1741
|
+
descendants: Sequence["ClassUnion"],
|
|
1742
|
+
) -> FrozenSet[int]:
|
|
1743
|
+
return frozenset(id(descendant) for descendant in descendants)
|
|
1744
|
+
|
|
1745
|
+
@staticmethod
|
|
1746
|
+
def _compute_concrete_descendant_id_set(
|
|
1747
|
+
concrete_descendants: Sequence["ConcreteClass"],
|
|
1748
|
+
) -> FrozenSet[int]:
|
|
1749
|
+
return frozenset(id(descendant) for descendant in concrete_descendants)
|
|
1750
|
+
|
|
1751
|
+
@staticmethod
|
|
1752
|
+
def _compute_property_id_set(properties: Sequence[Property]) -> FrozenSet[int]:
|
|
1753
|
+
return frozenset(id(prop) for prop in properties)
|
|
1754
|
+
|
|
1755
|
+
@staticmethod
|
|
1756
|
+
def _compute_method_id_set(methods: Sequence["MethodUnion"]) -> FrozenSet[int]:
|
|
1757
|
+
return frozenset(id(method) for method in methods)
|
|
1758
|
+
|
|
1759
|
+
@staticmethod
|
|
1760
|
+
def _compute_invariant_id_set(invariants: Sequence[Invariant]) -> FrozenSet[int]:
|
|
1761
|
+
return frozenset(id(inv) for inv in invariants)
|
|
1762
|
+
|
|
1635
1763
|
@property
|
|
1636
1764
|
def inheritances(self) -> Sequence["ClassUnion"]:
|
|
1637
1765
|
"""Return direct parents that this class inherits from."""
|
|
@@ -1732,6 +1860,48 @@ class Class(DBC):
|
|
|
1732
1860
|
"""Collect IDs (with :py:func:`id`) of the invariant objects in a set."""
|
|
1733
1861
|
return self._invariant_id_set
|
|
1734
1862
|
|
|
1863
|
+
def __getstate__(self) -> Dict[str, Any]:
|
|
1864
|
+
state = self.__dict__.copy()
|
|
1865
|
+
|
|
1866
|
+
state.pop("_inheritance_id_set", None)
|
|
1867
|
+
state.pop("_ancestor_id_set", None)
|
|
1868
|
+
state.pop("_descendant_id_set", None)
|
|
1869
|
+
state.pop("_concrete_descendant_id_set", None)
|
|
1870
|
+
state.pop("_property_id_set", None)
|
|
1871
|
+
state.pop("_method_id_set", None)
|
|
1872
|
+
state.pop("_invariant_id_set", None)
|
|
1873
|
+
|
|
1874
|
+
return state
|
|
1875
|
+
|
|
1876
|
+
def __setstate__(self, state: Dict[str, Any]) -> None:
|
|
1877
|
+
self.__dict__.update(state)
|
|
1878
|
+
|
|
1879
|
+
setattr(
|
|
1880
|
+
self,
|
|
1881
|
+
"_inheritance_id_set",
|
|
1882
|
+
Class._compute_inheritance_id_set(self._inheritances),
|
|
1883
|
+
)
|
|
1884
|
+
setattr(
|
|
1885
|
+
self, "_ancestor_id_set", Class._compute_ancestor_id_set(self._ancestors)
|
|
1886
|
+
)
|
|
1887
|
+
setattr(
|
|
1888
|
+
self,
|
|
1889
|
+
"_descendant_id_set",
|
|
1890
|
+
Class._compute_descendant_id_set(self._descendants),
|
|
1891
|
+
)
|
|
1892
|
+
setattr(
|
|
1893
|
+
self,
|
|
1894
|
+
"_concrete_descendant_id_set",
|
|
1895
|
+
Class._compute_concrete_descendant_id_set(self._concrete_descendants),
|
|
1896
|
+
)
|
|
1897
|
+
setattr(
|
|
1898
|
+
self, "_property_id_set", Class._compute_property_id_set(self._properties)
|
|
1899
|
+
)
|
|
1900
|
+
setattr(self, "_method_id_set", Class._compute_method_id_set(self._methods))
|
|
1901
|
+
setattr(
|
|
1902
|
+
self, "_invariant_id_set", Class._compute_invariant_id_set(self._invariants)
|
|
1903
|
+
)
|
|
1904
|
+
|
|
1735
1905
|
@abc.abstractmethod
|
|
1736
1906
|
def __repr__(self) -> str:
|
|
1737
1907
|
# Signal that this is a purely abstract class.
|
|
@@ -1926,7 +2096,7 @@ class ConstantSetOfPrimitives(Constant):
|
|
|
1926
2096
|
parsed: Final[parse.ConstantSet]
|
|
1927
2097
|
|
|
1928
2098
|
#: Set of all the literal values
|
|
1929
|
-
literal_value_set: Final[
|
|
2099
|
+
literal_value_set: Final[FrozenSet[Union[bool, int, float, str, bytearray]]]
|
|
1930
2100
|
|
|
1931
2101
|
# fmt: off
|
|
1932
2102
|
# noinspection PyTypeHints
|
|
@@ -1972,7 +2142,7 @@ class ConstantSetOfPrimitives(Constant):
|
|
|
1972
2142
|
self.subsets = subsets
|
|
1973
2143
|
self.parsed = parsed
|
|
1974
2144
|
|
|
1975
|
-
self.literal_value_set =
|
|
2145
|
+
self.literal_value_set = frozenset(literal.value for literal in literals)
|
|
1976
2146
|
|
|
1977
2147
|
def __repr__(self) -> str:
|
|
1978
2148
|
"""Represent the instance as a string for easier debugging."""
|
|
@@ -1997,7 +2167,10 @@ class ConstantSetOfEnumerationLiterals(Constant):
|
|
|
1997
2167
|
parsed: Final[parse.ConstantSet]
|
|
1998
2168
|
|
|
1999
2169
|
#: Set of all the IDs (as in Python objects) of the literals
|
|
2000
|
-
literal_id_set: Final[
|
|
2170
|
+
literal_id_set: Final[FrozenSet[int]]
|
|
2171
|
+
|
|
2172
|
+
#: Set of all the literal values
|
|
2173
|
+
literal_value_set: Final[FrozenSet[str]]
|
|
2001
2174
|
|
|
2002
2175
|
# fmt: off
|
|
2003
2176
|
@require(
|
|
@@ -2038,7 +2211,31 @@ class ConstantSetOfEnumerationLiterals(Constant):
|
|
|
2038
2211
|
self.subsets = subsets
|
|
2039
2212
|
self.parsed = parsed
|
|
2040
2213
|
|
|
2041
|
-
self.literal_id_set =
|
|
2214
|
+
self.literal_id_set = self.__class__._compute_literal_id_set(self.literals)
|
|
2215
|
+
self.literal_value_set = frozenset(literal.value for literal in self.literals)
|
|
2216
|
+
|
|
2217
|
+
@staticmethod
|
|
2218
|
+
def _compute_literal_id_set(
|
|
2219
|
+
literals: Sequence[EnumerationLiteral],
|
|
2220
|
+
) -> FrozenSet[int]:
|
|
2221
|
+
return frozenset(id(literal) for literal in literals)
|
|
2222
|
+
|
|
2223
|
+
def __getstate__(self) -> Dict[str, Any]:
|
|
2224
|
+
state = self.__dict__.copy()
|
|
2225
|
+
|
|
2226
|
+
state.pop("literal_id_set", None)
|
|
2227
|
+
|
|
2228
|
+
return state
|
|
2229
|
+
|
|
2230
|
+
def __setstate__(self, state: Dict[str, Any]) -> None:
|
|
2231
|
+
self.__dict__.update(state)
|
|
2232
|
+
|
|
2233
|
+
# We rebuild what we did not pickle.
|
|
2234
|
+
setattr(
|
|
2235
|
+
self,
|
|
2236
|
+
"literal_id_set",
|
|
2237
|
+
self.__class__._compute_literal_id_set(self.literals),
|
|
2238
|
+
)
|
|
2042
2239
|
|
|
2043
2240
|
def __repr__(self) -> str:
|
|
2044
2241
|
"""Represent the instance as a string for easier debugging."""
|
|
@@ -2383,7 +2580,25 @@ class Interface:
|
|
|
2383
2580
|
prop.name: prop for prop in self.properties
|
|
2384
2581
|
}
|
|
2385
2582
|
|
|
2386
|
-
self.property_id_set =
|
|
2583
|
+
self.property_id_set = self.__class__._compute_property_id_set(self.properties)
|
|
2584
|
+
|
|
2585
|
+
@staticmethod
|
|
2586
|
+
def _compute_property_id_set(properties: Sequence[Property]) -> FrozenSet[int]:
|
|
2587
|
+
return frozenset(id(prop) for prop in properties)
|
|
2588
|
+
|
|
2589
|
+
def __getstate__(self) -> Dict[str, Any]:
|
|
2590
|
+
state = self.__dict__.copy()
|
|
2591
|
+
|
|
2592
|
+
state.pop("property_id_set", None)
|
|
2593
|
+
|
|
2594
|
+
return state
|
|
2595
|
+
|
|
2596
|
+
def __setstate__(self, state: Dict[str, Any]) -> None:
|
|
2597
|
+
self.__dict__.update(state)
|
|
2598
|
+
|
|
2599
|
+
setattr(
|
|
2600
|
+
self, "property_id_set", Interface._compute_property_id_set(self.properties)
|
|
2601
|
+
)
|
|
2387
2602
|
|
|
2388
2603
|
def __repr__(self) -> str:
|
|
2389
2604
|
"""Represent the instance as a string for easier debugging."""
|
|
@@ -2741,6 +2956,130 @@ class SymbolTable:
|
|
|
2741
2956
|
|
|
2742
2957
|
return result
|
|
2743
2958
|
|
|
2959
|
+
def must_find_constant(self, name: Identifier) -> "ConstantUnion":
|
|
2960
|
+
"""
|
|
2961
|
+
Find the constant with the given ``name``.
|
|
2962
|
+
|
|
2963
|
+
:raise: :py:class:`KeyError` if the ``name`` is not in our constants.
|
|
2964
|
+
"""
|
|
2965
|
+
result = self.constants_by_name.get(name, None)
|
|
2966
|
+
if result is None:
|
|
2967
|
+
raise KeyError(name)
|
|
2968
|
+
|
|
2969
|
+
return result
|
|
2970
|
+
|
|
2971
|
+
def must_find_constant_primitive(self, name: Identifier) -> ConstantPrimitive:
|
|
2972
|
+
"""
|
|
2973
|
+
Find the primitive constant with the given ``name``.
|
|
2974
|
+
|
|
2975
|
+
:raise: :py:class:`KeyError` if the ``name`` is not in the constants.
|
|
2976
|
+
:raise:
|
|
2977
|
+
:py:class:`TypeError` if the ``name`` is in the constants, but it is not
|
|
2978
|
+
a constant primitive.
|
|
2979
|
+
"""
|
|
2980
|
+
result = self.constants_by_name.get(name, None)
|
|
2981
|
+
if result is None:
|
|
2982
|
+
raise KeyError(name)
|
|
2983
|
+
|
|
2984
|
+
if not isinstance(result, ConstantPrimitive):
|
|
2985
|
+
raise TypeError(
|
|
2986
|
+
f"Found {name} in the constants; "
|
|
2987
|
+
f"expected an instance of {ConstantPrimitive.__name__},"
|
|
2988
|
+
f"but got {type(result)}: {result}"
|
|
2989
|
+
)
|
|
2990
|
+
|
|
2991
|
+
return result
|
|
2992
|
+
|
|
2993
|
+
def must_find_constant_set_of_primitives(
|
|
2994
|
+
self, name: Identifier
|
|
2995
|
+
) -> ConstantSetOfPrimitives:
|
|
2996
|
+
"""
|
|
2997
|
+
Find the constant set of primitives with the given ``name``.
|
|
2998
|
+
|
|
2999
|
+
:raise: :py:class:`KeyError` if the ``name`` is not in the constants.
|
|
3000
|
+
:raise:
|
|
3001
|
+
:py:class:`TypeError` if the ``name`` is in the constants, but it is not
|
|
3002
|
+
a constant set of primitives.
|
|
3003
|
+
"""
|
|
3004
|
+
result = self.constants_by_name.get(name, None)
|
|
3005
|
+
if result is None:
|
|
3006
|
+
raise KeyError(name)
|
|
3007
|
+
|
|
3008
|
+
if not isinstance(result, ConstantSetOfPrimitives):
|
|
3009
|
+
raise TypeError(
|
|
3010
|
+
f"Found {name} in the constants; "
|
|
3011
|
+
f"expected an instance of {ConstantSetOfPrimitives.__name__},"
|
|
3012
|
+
f"but got {type(result)}: {result}"
|
|
3013
|
+
)
|
|
3014
|
+
|
|
3015
|
+
return result
|
|
3016
|
+
|
|
3017
|
+
def must_find_constant_set_of_enumeration_literals(
|
|
3018
|
+
self, name: Identifier
|
|
3019
|
+
) -> ConstantSetOfEnumerationLiterals:
|
|
3020
|
+
"""
|
|
3021
|
+
Find the constant set of enumeration literals with the given ``name``.
|
|
3022
|
+
|
|
3023
|
+
:raise: :py:class:`KeyError` if the ``name`` is not in the constants.
|
|
3024
|
+
:raise:
|
|
3025
|
+
:py:class:`TypeError` if the ``name`` is in the constants, but it is not
|
|
3026
|
+
a constant set of enumeration literals.
|
|
3027
|
+
"""
|
|
3028
|
+
result = self.constants_by_name.get(name, None)
|
|
3029
|
+
if result is None:
|
|
3030
|
+
raise KeyError(name)
|
|
3031
|
+
|
|
3032
|
+
if not isinstance(result, ConstantSetOfEnumerationLiterals):
|
|
3033
|
+
raise TypeError(
|
|
3034
|
+
f"Found {name} in the constants; "
|
|
3035
|
+
f"expected an instance of {ConstantSetOfEnumerationLiterals.__name__},"
|
|
3036
|
+
f"but got {type(result)}: {result}"
|
|
3037
|
+
)
|
|
3038
|
+
|
|
3039
|
+
return result
|
|
3040
|
+
|
|
3041
|
+
def is_enumeration_literal_of(
|
|
3042
|
+
self, literal: EnumerationLiteral, enumeration_or_constant_set_name: Identifier
|
|
3043
|
+
) -> bool:
|
|
3044
|
+
"""
|
|
3045
|
+
Check that the given ``literal`` is a member of the enumeration or constant set.
|
|
3046
|
+
|
|
3047
|
+
We assume that the enumeration or the constant set of enumeration literals
|
|
3048
|
+
exists in the symbol table.
|
|
3049
|
+
|
|
3050
|
+
:raises:
|
|
3051
|
+
:py:class:`KeyError` if the ``enumeration_or_constant_set_name`` is neither
|
|
3052
|
+
in our types nor in constants
|
|
3053
|
+
|
|
3054
|
+
:raises:
|
|
3055
|
+
:py:class:`TypeError` if the ``enumeration_or_constant_set_name`` is
|
|
3056
|
+
neither an enumeration nor a constant set of enumeration literals, but
|
|
3057
|
+
exists in our types or in the constants.
|
|
3058
|
+
"""
|
|
3059
|
+
our_type = self._name_to_our_type.get(enumeration_or_constant_set_name, None)
|
|
3060
|
+
if our_type is not None:
|
|
3061
|
+
if not isinstance(our_type, Enumeration):
|
|
3062
|
+
raise TypeError(
|
|
3063
|
+
f"Expected an enumeration "
|
|
3064
|
+
f"under the name {enumeration_or_constant_set_name!r}, "
|
|
3065
|
+
f"but got {type(our_type)}: {our_type}"
|
|
3066
|
+
)
|
|
3067
|
+
|
|
3068
|
+
return id(literal) in our_type.literal_id_set
|
|
3069
|
+
|
|
3070
|
+
constant = self.constants_by_name.get(enumeration_or_constant_set_name, None)
|
|
3071
|
+
if constant is not None:
|
|
3072
|
+
if not isinstance(constant, ConstantSetOfEnumerationLiterals):
|
|
3073
|
+
raise TypeError(
|
|
3074
|
+
f"Expected a constant set of enumeration literals "
|
|
3075
|
+
f"under the name {enumeration_or_constant_set_name!r}, "
|
|
3076
|
+
f"but got {type(constant)}: {constant}"
|
|
3077
|
+
)
|
|
3078
|
+
|
|
3079
|
+
return id(literal) in constant.literal_id_set
|
|
3080
|
+
|
|
3081
|
+
raise KeyError(enumeration_or_constant_set_name)
|
|
3082
|
+
|
|
2744
3083
|
|
|
2745
3084
|
def try_primitive_type(type_annotation: TypeAnnotationUnion) -> Optional[PrimitiveType]:
|
|
2746
3085
|
"""
|
|
@@ -2817,15 +3156,6 @@ def map_descendability(
|
|
|
2817
3156
|
return mapping
|
|
2818
3157
|
|
|
2819
3158
|
|
|
2820
|
-
class _ConstructorArgumentOfClass:
|
|
2821
|
-
"""Represent a constructor argument with its corresponding class."""
|
|
2822
|
-
|
|
2823
|
-
def __init__(self, arg: Argument, cls: Class) -> None:
|
|
2824
|
-
"""Initialize with the given values."""
|
|
2825
|
-
self.arg = arg
|
|
2826
|
-
self.cls = cls
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
3159
|
def collect_ids_of_our_types_in_properties(symbol_table: SymbolTable) -> Set[int]:
|
|
2830
3160
|
"""
|
|
2831
3161
|
Collect the IDs of our types occurring in type annotations of the properties.
|
|
@@ -2117,7 +2117,9 @@ def _write_float_property(
|
|
|
2117
2117
|
{II}else:
|
|
2118
2118
|
{III}self.stream.write('0.0')
|
|
2119
2119
|
{I}else:
|
|
2120
|
-
{II}self.stream.write(str(value))
|
|
2120
|
+
{II}self.stream.write(str(value))
|
|
2121
|
+
|
|
2122
|
+
{I}self._write_end_element(name)"""
|
|
2121
2123
|
),
|
|
2122
2124
|
Stripped(
|
|
2123
2125
|
f"""\
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aas-core-codegen
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.17
|
|
4
4
|
Summary: Generate implementations and schemas based on an AAS meta-model.
|
|
5
5
|
Author-email: Marko Ristin <marko@ristin.ch>, Nico Braunisch <nico.braunisch@tu-dresden.de>
|
|
6
6
|
License: MIT
|
|
@@ -17,7 +17,7 @@ Description-Content-Type: text/x-rst
|
|
|
17
17
|
License-File: LICENSE
|
|
18
18
|
License-File: AUTHORS
|
|
19
19
|
Requires-Dist: asttokens<3,>=2.0.8
|
|
20
|
-
Requires-Dist: icontract<3,>=2.
|
|
20
|
+
Requires-Dist: icontract<3,>=2.7.3
|
|
21
21
|
Requires-Dist: sortedcontainers<3,>=2.4.0
|
|
22
22
|
Requires-Dist: docutils==0.22.3
|
|
23
23
|
Requires-Dist: more-itertools<9,>=8
|