Commit ba122814 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[code gen] Generate new structures that will ease check for unhandled cardinalities

Those structures will be used as bases for hooks necessary to check for
unhandled cardinalities, that will be introduced by the following change set.

We have to watch composite relation that may lead to several children, and for
the entity types that are possible as children.

Related to #17098404
parent a671735e9217
......@@ -915,3 +915,51 @@ CHOICE_RTYPE = {
......@@ -44,15 +44,21 @@ class SEDAAnyEntity(AnyEntity):
self.altetype2rtype = {} # registry of rtype to children elements for all choices
self.altetype2rtype = {} # rtype to children elements for all choices
self.check_card_etypes = set() # entity types whose cardinality must be checked
self.check_card_rtypes = set() # relation types whose children cardinality must be checked
for mapping_element in mapping.ordered:
self._callback('register_alt_rtype_for', mapping_element)
eclass_code = self._callback('entity_class_for', mapping_element)
if eclass_code:
stream.write(eclass_code + '\n')
stream.write(u'CHOICE_RTYPE = ') # Write the registry as a constant
stream.write(json.dumps(self.altetype2rtype, sort_keys=True, indent=2,
separators=(',', ': ')).replace('"', "'") + '\n')
# Write pre-computed data structures as constants
for name, data in [('CHOICE_RTYPE', self.altetype2rtype),
('CHECK_CARD_ETYPES', sorted(self.check_card_etypes)),
('CHECK_CHILDREN_CARD_RTYPES', sorted(self.check_card_rtypes))]:
stream.write(u'{} = '.format(name))
stream.write(json.dumps(data, sort_keys=True, indent=2,
separators=(',', ': ')).replace('"', "'") + '\n')
def entity_class_for_e_type_mapping(self, mapping):
attributes = ordered_attributes(mapping)
......@@ -76,6 +82,10 @@ class SEDAAnyEntity(AnyEntity):
if altetype.startswith('SEDAAlt'):
self.altetype2rtype.setdefault(altetype, []).append((mapping.rtype, composite))
if mapping.card[1] in '*+':
if __name__ == '__main__':
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment