diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dfa7f6..3371357 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,51 +1,83 @@ # Changelog -Notable changes. +Elements marked as `collectable` means that they can be added directly to a package. +Non-collectable elements are various sub-elements to collectable elements. -## [Unreleased] +The name in the parenthesis after each element is the name used in the XML schema (XSD file). -### XML - Collectable elements +## [v0.5.0] -* ApplicationArrayDataType -* ApplicationPrimitiveDataType -* ApplicationRecordDataType -* CompuMethod -* DataConstraint -* ImplementationDataType -* SwBaseType -* Unit -* DataTypeMappingSet +### Added -### XML - Documentation elements +#### XML - Documentation elements -* DocumentationBlock -* EmphasisText -* MultiLanguageLongName -* MultiLanguageOverviewParagraph -* MultiLanguageParagraph -* MultiLanguageVerbatim -* Subscript -* Superscript -* TechnicalTerm +* DocumentationBlock | DOCUMENTATION-BLOCK +* EmphasisText | EMPHASIS-TEXT +* MultilanguageLongName | MULTILANGUAGE-LONG-NAME +* MultiLanguageOverviewParagraph | MULTI-LANGUAGE-OVERVIEW-PARAGRAPH +* MultiLanguageParagraph | MULTI-LANGUAGE-PARAGRAPH +* MultiLanguageVerbatim | MULTI-LANGUAGE-VERBATIM +* Subscript | SUPSCRIPT (This not a typo) +* Superscript | SUPSCRIPT +* TechnicalTerm | TT -### XML - DataDictionary elements +#### XML - Data type elements -* ApplicationArrayElement -* ApplicationRecordElement -* AutosarDataType -* ImplementationDataTypeElement -* SwBitRepresentation -* SwDataDefProps -* SwDataDefPropsConditional -* SwPointerTargetProps -* SwTextProps -* SymbolProps +* ApplicationArrayDataType | APPLICATION-ARRAY-DATA-TYPE | `collectable` +* ApplicationPrimitiveDataType | APPLICATION-PRIMITIVE-DATA-TYPE | `collectable` +* ApplicationRecordDataType | APPLICATION-RECORD-DATA-TYPE | `collectable` +* DataTypeMappingSet | DATA-TYPE-MAPPING-SET | `collectable` +* ImplementationDataType | IMPLEMENTATION-DATA-TYPE | `collectable` +* SwBaseType | SW-BASE-TYPE | `collectable` +* ApplicationArrayElement | APPLICATION-ARRAY-ELEMENT +* ApplicationRecordElement | APPLICATION-RECORD-ELEMENT +* AutosarDataType | AUTOSAR-DATA-TYPE +* DataTypeMap | DATA-TYPE-MAP +* ImplementationDataTypeElement | IMPLEMENTATION-DATA-TYPE-ELEMENT +* SwBitRepresentation | SW-BIT-REPRESENTATION +* SwDataDefProps | SW-DATA-DEF-PROPS +* SwDataDefPropsConditional | SW-DATA-DEF-PROPS-CONDITIONAL + SW-DATA-DEF-PROPS-CONTENT +* SwPointerTargetProps | SW-POINTER-TARGET-PROPS +* SwTextProps | SW-TEXT-PROPS +* SymbolProps | SYMBOL-PROPS -### XML - Datatype elements +#### XML - Unit elements -* DataTypeMap +* Unit | UNIT | `collectable` -### Implementation Model - Elements +#### XML - Computation and constraint elements + +* CompuMethod | COMPU-METHOD | `collectable` +* DataConstraint | DATA-CONSTR | `collectable` +* CompuConst | COMPU-CONST +* CompuRational | COMPU-RATIONAL-COEFFS +* CompuScale | COMPU-SCALE +* Computation | COMPU +* DataConstraintRule | DATA-CONSTR-RULE +* InternalConstraint | INTERNAL-CONSTRS +* PhysicalConstraint | PHYS-CONSTRS +* ScaleConstraint | SCALE-CONSTR + +#### XML - Reference elements + +These elements exist in Python only. They are returned as objects when calling +the `ref` method on various XML elements. + +Only a handful of XML element classes have their corresponding `ref` method implemented (will be fixed later). + +* ApplicationDataTypeRef +* AutosarDataTypeRef +* CompuMethodRef +* DataConstraintRef +* FunctionPtrSignatureRef +* ImplementationDataTypeRef +* IndexDataTypeRef +* PhysicalDimensionRef +* SwAddrMethodRef +* SwBaseTypeRef +* UnitRef + +#### Implementation Model - Elements * ArrayType * BaseType @@ -54,7 +86,7 @@ Notable changes. * RefType * ScalarType -### RTE Data Type Generator +#### RTE Data Type Generator * ArrayType * BaseType diff --git a/README.md b/README.md index 8670d0c..34002a1 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,10 @@ When saving, use the `schema_version` parameter to select desired version (integ Only Clasic AUTOSAR will be supported. +## Supported XML elements + +For currently supported XML elements, see the [CHANGELOG](CHANGELOG.md) file. + ## Requirements * Python 3.10+ diff --git a/src/autosar/xml/element.py b/src/autosar/xml/element.py index 1ea90fe..e2fb9ec 100644 --- a/src/autosar/xml/element.py +++ b/src/autosar/xml/element.py @@ -408,7 +408,7 @@ def _accepted_subtypes(self) -> set[ar_enum.IdentifiableSubTypes]: return {ar_enum.IdentifiableSubTypes.DATA_CONSTR} -class PhysicalDimentionRef(BaseRef): +class PhysicalDimensionRef(BaseRef): """ PhysicalDimension reference """ @@ -1548,11 +1548,11 @@ def __init__(self, name: str, display_name: str | SingleLanguageUnitNames | None = None, factor: float | None = None, offset: float | None = None, - physical_dimension_ref: str | PhysicalDimentionRef | None = None, + physical_dimension_ref: str | PhysicalDimensionRef | None = None, **kwargs: dict) -> None: super().__init__(name, **kwargs) self.display_name: SingleLanguageUnitNames | None = None # .DISPLAY-NAME - self.physical_dimension_ref: PhysicalDimentionRef | None = None # .PHYSICAL-DIMENSION-REF + self.physical_dimension_ref: PhysicalDimensionRef | None = None # .PHYSICAL-DIMENSION-REF self.factor: float | None = None # .FACTOR-SI-TO-UNIT self.offset: float | None = None # .OFFSET-SI-TO-UNIT if display_name is not None: @@ -1564,8 +1564,8 @@ def __init__(self, name: str, raise TypeError(f"display_name: Invalid type '{str(type(display_name))}'") if physical_dimension_ref is not None: if isinstance(physical_dimension_ref, str): - self.physical_dimension_ref = PhysicalDimentionRef(display_name) - elif isinstance(physical_dimension_ref, PhysicalDimentionRef): + self.physical_dimension_ref = PhysicalDimensionRef(display_name) + elif isinstance(physical_dimension_ref, PhysicalDimensionRef): self.physical_dimension_ref = physical_dimension_ref else: raise TypeError(f"physical_dimension_ref: Invalid type '{str(type(physical_dimension_ref))}'") @@ -1573,7 +1573,7 @@ def __init__(self, name: str, self._assign_optional('offset', offset, float) -# Data dictionary elements +# Data type elements class BaseType(ARElement): @@ -1947,7 +1947,7 @@ def append(self, elem: "ImplementationDataTypeElement") -> None: class ImplementationDataType(AutosarDataType): """ - IMPLEMENTATION-DATA-TYPE + AR: IMPLEMENTATION-DATA-TYPE Type: Concrete Tag Variants: 'IMPLEMENTATION-DATA-TYPE' """ @@ -2229,35 +2229,6 @@ def ref(self) -> ApplicationDataTypeRef | None: value = '/'.join(reversed(ref_parts)) return ApplicationDataTypeRef(value, ar_enum.IdentifiableSubTypes.APPLICATION_RECORD_DATA_TYPE) -# Software address method (partly implemented) - - -class SwAddrMethod(ARElement): - """ - Complex-type AR:SW-ADDR-METHOD - Type: Concrete: - Tag Variants: SW-ADDR-METHOD - """ - - def __init__(self, name: str, **kwargs) -> None: - super().__init__(name, **kwargs) - self.memory_allocation_keyword_policy = None # .MEMORY-ALLOCATION-KEYWORD-POLICY - self.options = [] # .OPTIONS - self.section_initialization_policy = None # .SECTION-INITIALIZATION-POLICY - self.section_type = None # .SECTION-TYPE - - def ref(self) -> SwAddrMethodRef: - """ - Reference - """ - assert self.parent is not None - ref_parts: list[str] = [self.name] - self.parent.update_ref_parts(ref_parts) - value = '/'.join(reversed(ref_parts)) - return SwAddrMethodRef(value) - -# Datatype elements - class DataTypeMap(ARObject): """ @@ -2308,6 +2279,34 @@ def append(self, element: DataTypeMap) -> None: else: raise TypeError(f'Unexpected type: "{str(type(element))}"') + +# Software address method (partly implemented) + + +class SwAddrMethod(ARElement): + """ + Complex-type AR:SW-ADDR-METHOD + Type: Concrete: + Tag Variants: SW-ADDR-METHOD + """ + + def __init__(self, name: str, **kwargs) -> None: + super().__init__(name, **kwargs) + self.memory_allocation_keyword_policy = None # .MEMORY-ALLOCATION-KEYWORD-POLICY + self.options = [] # .OPTIONS + self.section_initialization_policy = None # .SECTION-INITIALIZATION-POLICY + self.section_type = None # .SECTION-TYPE + + def ref(self) -> SwAddrMethodRef: + """ + Reference + """ + assert self.parent is not None + ref_parts: list[str] = [self.name] + self.parent.update_ref_parts(ref_parts) + value = '/'.join(reversed(ref_parts)) + return SwAddrMethodRef(value) + # !!UNFINISHED!! Port Interfaces diff --git a/src/autosar/xml/reader.py b/src/autosar/xml/reader.py index 455110a..cd66654 100644 --- a/src/autosar/xml/reader.py +++ b/src/autosar/xml/reader.py @@ -95,13 +95,14 @@ def __init__(self, # CompuMethod 'COMPU-METHOD': self._read_compu_method, - # Data Dictionary + # Data type elements 'APPLICATION-ARRAY-DATA-TYPE': self._read_application_array_data_type, 'APPLICATION-RECORD-DATA-TYPE': self._read_application_record_data_type, 'APPLICATION-PRIMITIVE-DATA-TYPE': self._read_application_primitive_data_type, 'SW-BASE-TYPE': self._read_sw_base_type, 'SW-ADDR-METHOD': self._read_sw_addr_method, 'IMPLEMENTATION-DATA-TYPE': self._read_implementation_data_type, + 'DATA-TYPE-MAPPING-SET': self._read_data_type_mapping_set, # Constraint elements 'DATA-CONSTR': self._read_data_constraint, @@ -111,9 +112,6 @@ def __init__(self, # Unit elements 'UNIT': self._read_unit, - - # Datatype elements - 'DATA-TYPE-MAPPING-SET': self._read_data_type_mapping_set, } self.switcher_non_collectable = { # Non-collectable, used only for unit testing # Documentation elements @@ -143,7 +141,7 @@ def __init__(self, 'INTERNAL-CONSTRS': self._read_internal_constraint, 'PHYS-CONSTRS': self._read_physical_constraint, 'DATA-CONSTR-RULE': self._read_data_constraint_rule, - # DataDictionary elements + # Data type elements 'BASE-TYPE-REF': self._read_sw_base_type_ref, 'SW-BIT-REPRESENTATION': self._read_sw_bit_representation, 'SW-DATA-DEF-PROPS-CONDITIONAL': self._read_sw_data_def_props_conditional, @@ -152,11 +150,10 @@ def __init__(self, 'SYMBOL-PROPS': self._read_symbol_props, 'IMPLEMENTATION-DATA-TYPE-ELEMENT': self._read_implementation_data_type_element, 'APPLICATION-RECORD-ELEMENT': self._read_application_record_element, + 'DATA-TYPE-MAP': self._read_data_type_map, # Reference elements 'PHYSICAL-DIMENSION-REF': self._read_physical_dimension_ref, 'APPLICATION-DATA-TYPE-REF': self._read_application_data_type_ref, - # Datatype elements - 'DATA-TYPE-MAP': self._read_data_type_map, } self.switcher_all = {} self.switcher_all.update(self.switcher_collectable) @@ -1264,7 +1261,7 @@ def _read_unit_group(self, child_elements: ChildElementMap, data: dict) -> None: if xml_child is not None: data["physical_dimension_ref"] = self._read_physical_dimension_ref(xml_child) - # DataDictionary elements + # Data type elements def _read_sw_addr_method(self, xml_element: ElementTree.Element) -> ar_element.SwAddrMethod: """ @@ -1894,7 +1891,7 @@ def _read_unit_ref(self, xml_elem: ElementTree.Element): self._raise_parse_error(xml_elem, f"Invalid DEST attribute '{dest_text}'. Expected 'UNIT'") return ar_element.UnitRef(xml_elem.text) - def _read_physical_dimension_ref(self, xml_elem: ElementTree.Element) -> ar_element.PhysicalDimentionRef: + def _read_physical_dimension_ref(self, xml_elem: ElementTree.Element) -> ar_element.PhysicalDimensionRef: """ Reads PHYSICAL-DIMENSION-REF Type: Concrete @@ -1904,7 +1901,7 @@ def _read_physical_dimension_ref(self, xml_elem: ElementTree.Element) -> ar_elem dest_enum = ar_enum.xml_to_enum('IdentifiableSubTypes', dest_text, self.schema_version) if dest_enum != ar_enum.IdentifiableSubTypes.PHYSICAL_DIMENSION: self._raise_parse_error(xml_elem, f"Invalid DEST attribute '{dest_text}'. Expected 'PHYSICAL-DIMENSION'") - return ar_element.PhysicalDimentionRef(xml_elem.text) + return ar_element.PhysicalDimensionRef(xml_elem.text) def _read_index_data_type_ref(self, xml_elem: ElementTree.Element) -> ar_element.IndexDataTypeRef: """ @@ -1949,8 +1946,6 @@ def _read_base_ref_attributes(self, attr: dict, data: dict) -> None: if data['dest'] is None: raise ar_exception.ParseError("Missing required attribute 'DEST'") - # DataType elements - def _read_data_type_map(self, xml_element: ElementTree.Element) -> ar_element.DataTypeMap: """ Reads AR:DATA-TYPE-MAP diff --git a/src/autosar/xml/writer.py b/src/autosar/xml/writer.py index 7eb05d8..ce9a34d 100644 --- a/src/autosar/xml/writer.py +++ b/src/autosar/xml/writer.py @@ -166,19 +166,18 @@ def __init__(self) -> None: 'Package': self._write_package, # CompuMethod elements 'CompuMethod': self._write_compu_method, - # DataDictionary elements + # Data type elements 'ApplicationArrayDataType': self._write_application_array_data_type, 'ApplicationRecordDataType': self._write_application_record_data_type, 'ApplicationPrimitiveDataType': self._write_application_primitive_data_type, 'SwBaseType': self._write_sw_base_type, 'SwAddrMethod': self._write_sw_addr_method, 'ImplementationDataType': self._write_implementation_data_type, + 'DataTypeMappingSet': self._write_data_type_mapping_set, # DataConstraint elements 'DataConstraint': self._write_data_constraint, # Unit elements 'Unit': self._write_unit, - # Datatype elements - 'DataTypeMappingSet': self._write_data_type_mapping_set, } # Elements used only for unit test purposes self.switcher_non_collectable = { @@ -209,7 +208,7 @@ def __init__(self) -> None: 'InternalConstraint': self._write_internal_constraint, 'PhysicalConstraint': self._write_physical_constraint, 'DataConstraintRule': self._write_data_constraint_rule, - # DataDictionary elements + # Data type elements 'SwDataDefPropsConditional': self._write_sw_data_def_props_conditional, 'SwBaseTypeRef': self._write_sw_base_type_ref, 'SwBitRepresentation': self._write_sw_bit_represenation, @@ -219,11 +218,10 @@ def __init__(self) -> None: 'ImplementationDataTypeElement': self._write_implementation_data_type_element, 'ApplicationArrayElement': self._write_application_array_element, 'ApplicationRecordElement': self._write_application_record_element, + 'DataTypeMap': self._write_data_type_map, # Reference elements - 'PhysicalDimentionRef': self._write_physical_dimension_ref, + 'PhysicalDimensionRef': self._write_physical_dimension_ref, 'ApplicationDataTypeRef': self._write_application_data_type_ref, - # Datatype elements - 'DataTypeMap': self._write_data_type_map, } self.switcher_all = {} # All concrete elements (used for unit testing) self.switcher_all.update(self.switcher_collectable) @@ -1070,7 +1068,7 @@ def _write_unit_group(self, elem: ar_element.Unit) -> None: if elem.physical_dimension_ref is not None: self._write_physical_dimension_ref(elem.physical_dimension_ref) - # DataDictionary elements + # Data type elements def _write_sw_addr_method(self, elem: ar_element.SwAddrMethod) -> None: """ @@ -1614,13 +1612,13 @@ def _write_unit_ref(self, elem: ar_element.UnitRef) -> None: self._collect_base_ref_attr(elem, attr) self._add_content('UNIT-REF', elem.value, attr) - def _write_physical_dimension_ref(self, elem: ar_element.PhysicalDimentionRef) -> None: + def _write_physical_dimension_ref(self, elem: ar_element.PhysicalDimensionRef) -> None: """ Writes PHYSICAL-DIMENSION-REF Type: Concrete Tag variants: 'PHYSICAL-DIMENSION-REF' """ - assert isinstance(elem, ar_element.PhysicalDimentionRef) + assert isinstance(elem, ar_element.PhysicalDimensionRef) attr: TupleList = [] self._collect_base_ref_attr(elem, attr) self._add_content('PHYSICAL-DIMENSION-REF', elem.value, attr) @@ -1647,8 +1645,6 @@ def _write_application_data_type_ref(self, elem: ar_element.ApplicationDataTypeR self._collect_base_ref_attr(elem, attr) self._add_content(tag, elem.value, attr) -# Datatype elements - def _write_data_type_map(self, elem: ar_element.DataTypeMap) -> None: """ Writes DataTypeMap diff --git a/tests/xml/test_data_constraints.py b/tests/xml/test_data_constraint.py similarity index 100% rename from tests/xml/test_data_constraints.py rename to tests/xml/test_data_constraint.py diff --git a/tests/xml/test_data_dictionary.py b/tests/xml/test_data_type.py similarity index 100% rename from tests/xml/test_data_dictionary.py rename to tests/xml/test_data_type.py diff --git a/tests/xml/test_documentation_elements.py b/tests/xml/test_documentation_element.py similarity index 100% rename from tests/xml/test_documentation_elements.py rename to tests/xml/test_documentation_element.py diff --git a/tests/xml/test_unit.py b/tests/xml/test_unit.py index caa1d67..a490ad6 100644 --- a/tests/xml/test_unit.py +++ b/tests/xml/test_unit.py @@ -11,13 +11,13 @@ class TestPhysicalDimensionRef(unittest.TestCase): def test_write_read_default(self): - element = ar_element.PhysicalDimentionRef("/PhysDimensions/Dimension") + element = ar_element.PhysicalDimensionRef("/PhysDimensions/Dimension") writer = autosar.xml.Writer() xml = '/PhysDimensions/Dimension' self.assertEqual(writer.write_str_elem(element), xml) reader = autosar.xml.Reader() - elem: ar_element.PhysicalDimentionRef = reader.read_str_elem(xml) - self.assertIsInstance(elem, ar_element.PhysicalDimentionRef) + elem: ar_element.PhysicalDimensionRef = reader.read_str_elem(xml) + self.assertIsInstance(elem, ar_element.PhysicalDimensionRef) self.assertEqual(str(elem), "/PhysDimensions/Dimension") class TestUnit(unittest.TestCase): # noqa D101 @@ -76,7 +76,7 @@ def test_write_read_offset(self): # noqa D102 def test_write_read_physical_dimension_ref(self): # noqa D102 element = ar_element.Unit("MyUnit", - physical_dimension_ref=ar_element.PhysicalDimentionRef("/Dimensions/Dim1")) + physical_dimension_ref=ar_element.PhysicalDimensionRef("/Dimensions/Dim1")) writer = autosar.xml.Writer() xml = ''' MyUnit