Skip to content

Commit

Permalink
introduce short name reference resolution contexts
Browse files Browse the repository at this point in the history
this patch is quite large but also pretty simple: instead of passing
the relevant containers directly to the `_resolve_snref()` methods, we
put every object that is possibly required for short name resolution
into a new `SnRefContext` object. Those parts of the context which are
not available are simply `None` and the respective `_resolve_snref()`
are responsible of ensuring that the parts of the context which they
require are present...

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Christian Hackenbeck <[email protected]>
  • Loading branch information
andlaus committed Jun 11, 2024
1 parent b342f72 commit 33872c1
Show file tree
Hide file tree
Showing 74 changed files with 397 additions and 496 deletions.
8 changes: 3 additions & 5 deletions odxtools/additionalaudience.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List
from typing import Any, Dict, List
from xml.etree import ElementTree

from .element import IdentifiableElement
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId
from .snrefcontext import SnRefContext
from .utils import dataclass_fields_asdict

if TYPE_CHECKING:
from .diaglayer import DiagLayer


@dataclass
class AdditionalAudience(IdentifiableElement):
Expand All @@ -30,5 +28,5 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
pass

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
pass
12 changes: 5 additions & 7 deletions odxtools/admindata.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from typing import Any, Dict, List, Optional
from xml.etree import ElementTree

from .companydocinfo import CompanyDocInfo
from .docrevision import DocRevision
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId

if TYPE_CHECKING:
from .diaglayer import DiagLayer
from .snrefcontext import SnRefContext


@dataclass
Expand Down Expand Up @@ -54,9 +52,9 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
for dr in self.doc_revisions:
dr._resolve_odxlinks(odxlinks)

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
for cdi in self.company_doc_infos:
cdi._resolve_snrefs(diag_layer)
cdi._resolve_snrefs(context)

for dr in self.doc_revisions:
dr._resolve_snrefs(diag_layer)
dr._resolve_snrefs(context)
8 changes: 3 additions & 5 deletions odxtools/audience.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from typing import Any, Dict, List, Optional
from xml.etree import ElementTree

from .additionalaudience import AdditionalAudience
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId, OdxLinkRef
from .odxtypes import odxstr_to_bool

if TYPE_CHECKING:
from .diaglayer import DiagLayer
from .snrefcontext import SnRefContext


@dataclass
Expand Down Expand Up @@ -94,5 +92,5 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
odxlinks.resolve(ref, AdditionalAudience) for ref in self.disabled_audience_refs
]

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
pass
8 changes: 3 additions & 5 deletions odxtools/basecomparam.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from enum import Enum
from typing import TYPE_CHECKING, Any, Dict, List, Optional, cast
from typing import Any, Dict, List, Optional, cast
from xml.etree import ElementTree

from .element import IdentifiableElement
from .exceptions import odxraise, odxrequire
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId
from .snrefcontext import SnRefContext
from .utils import dataclass_fields_asdict

if TYPE_CHECKING:
from .diaglayer import DiagLayer


class StandardizationLevel(Enum):
STANDARD = "STANDARD"
Expand Down Expand Up @@ -74,5 +72,5 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
pass

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
pass
16 changes: 9 additions & 7 deletions odxtools/basicstructure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MIT
import warnings
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List, Optional, cast
from typing import Any, Dict, List, Optional, cast
from xml.etree import ElementTree

from typing_extensions import override
Expand All @@ -23,11 +23,9 @@
from .parameters.parameterwithdop import ParameterWithDOP
from .parameters.physicalconstantparameter import PhysicalConstantParameter
from .parameters.tablekeyparameter import TableKeyParameter
from .snrefcontext import SnRefContext
from .utils import dataclass_fields_asdict

if TYPE_CHECKING:
from .diaglayer import DiagLayer


@dataclass
class BasicStructure(ComplexDop):
Expand Down Expand Up @@ -292,9 +290,13 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
for param in self.parameters:
param._resolve_odxlinks(odxlinks)

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
"""Recursively resolve any references (odxlinks or sn-refs)"""
super()._resolve_snrefs(diag_layer)
context.parameters = self.parameters

super()._resolve_snrefs(context)

for param in self.parameters:
param._parameter_resolve_snrefs(diag_layer, param_list=self.parameters)
param._resolve_snrefs(context)

context.parameters = None
12 changes: 5 additions & 7 deletions odxtools/companydata.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from typing import Any, Dict, List, Optional
from xml.etree import ElementTree

from .companyspecificinfo import CompanySpecificInfo
from .element import IdentifiableElement
from .exceptions import odxrequire
from .nameditemlist import NamedItemList
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId
from .snrefcontext import SnRefContext
from .teammember import TeamMember
from .utils import dataclass_fields_asdict

if TYPE_CHECKING:
from .diaglayer import DiagLayer


@dataclass
class CompanyData(IdentifiableElement):
Expand Down Expand Up @@ -64,9 +62,9 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
if self.company_specific_info:
self.company_specific_info._resolve_odxlinks(odxlinks)

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
for tm in self.team_members:
tm._resolve_snrefs(diag_layer)
tm._resolve_snrefs(context)

if self.company_specific_info:
self.company_specific_info._resolve_snrefs(diag_layer)
self.company_specific_info._resolve_snrefs(context)
10 changes: 4 additions & 6 deletions odxtools/companydocinfo.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from typing import Any, Dict, List, Optional
from xml.etree import ElementTree

from .companydata import CompanyData
from .exceptions import odxrequire
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId, OdxLinkRef
from .snrefcontext import SnRefContext
from .specialdatagroup import SpecialDataGroup
from .teammember import TeamMember

if TYPE_CHECKING:
from .diaglayer import DiagLayer


@dataclass
class CompanyDocInfo:
Expand Down Expand Up @@ -65,6 +63,6 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
for sdg in self.sdgs:
sdg._resolve_odxlinks(odxlinks)

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
for sdg in self.sdgs:
sdg._resolve_snrefs(diag_layer)
sdg._resolve_snrefs(context)
8 changes: 3 additions & 5 deletions odxtools/companyrevisioninfo.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from typing import Any, Dict, List, Optional
from xml.etree import ElementTree

from .companydata import CompanyData
from .exceptions import odxrequire
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId, OdxLinkRef

if TYPE_CHECKING:
from .diaglayer import DiagLayer
from .snrefcontext import SnRefContext


@dataclass
Expand Down Expand Up @@ -39,5 +37,5 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
self._company_data = odxlinks.resolve(self.company_data_ref, CompanyData)

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
pass
12 changes: 5 additions & 7 deletions odxtools/companyspecificinfo.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List
from typing import Any, Dict, List
from xml.etree import ElementTree

from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId
from .relateddoc import RelatedDoc
from .snrefcontext import SnRefContext
from .specialdatagroup import SpecialDataGroup

if TYPE_CHECKING:
from .diaglayer import DiagLayer


@dataclass
class CompanySpecificInfo:
Expand Down Expand Up @@ -45,9 +43,9 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
for sdg in self.sdgs:
sdg._resolve_odxlinks(odxlinks)

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
for rd in self.related_docs:
rd._resolve_snrefs(diag_layer)
rd._resolve_snrefs(context)

for sdg in self.sdgs:
sdg._resolve_snrefs(diag_layer)
sdg._resolve_snrefs(context)
10 changes: 4 additions & 6 deletions odxtools/comparam.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List
from typing import Any, Dict, List
from xml.etree import ElementTree

from .basecomparam import BaseComparam
from .dataobjectproperty import DataObjectProperty
from .exceptions import odxrequire
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId, OdxLinkRef
from .snrefcontext import SnRefContext
from .utils import dataclass_fields_asdict

if TYPE_CHECKING:
from .diaglayer import DiagLayer


@dataclass
class Comparam(BaseComparam):
Expand Down Expand Up @@ -41,5 +39,5 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:

self._dop = odxlinks.resolve(self.dop_ref, DataObjectProperty)

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
super()._resolve_snrefs(diag_layer)
def _resolve_snrefs(self, context: SnRefContext) -> None:
super()._resolve_snrefs(context)
8 changes: 3 additions & 5 deletions odxtools/comparaminstance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MIT
import warnings
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Union
from xml.etree import ElementTree

from .basecomparam import BaseComparam
Expand All @@ -10,9 +10,7 @@
from .description import Description
from .exceptions import OdxWarning, odxraise, odxrequire
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId, OdxLinkRef

if TYPE_CHECKING:
from .diaglayer import DiagLayer
from .snrefcontext import SnRefContext


@dataclass
Expand Down Expand Up @@ -68,7 +66,7 @@ def _build_odxlinks(self) -> Dict[OdxLinkId, Any]:
def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
self._spec = odxlinks.resolve(self.spec_ref, BaseComparam)

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
pass

@property
Expand Down
16 changes: 7 additions & 9 deletions odxtools/comparamspec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from typing import Any, Dict, List, Optional
from xml.etree import ElementTree

from .admindata import AdminData
Expand All @@ -10,12 +10,10 @@
from .nameditemlist import NamedItemList
from .odxlink import OdxDocFragment, OdxLinkDatabase, OdxLinkId
from .protstack import ProtStack
from .snrefcontext import SnRefContext
from .specialdatagroup import SpecialDataGroup
from .utils import dataclass_fields_asdict

if TYPE_CHECKING:
from .diaglayer import DiagLayer


@dataclass
class ComparamSpec(IdentifiableElement):
Expand Down Expand Up @@ -83,15 +81,15 @@ def _resolve_odxlinks(self, odxlinks: OdxLinkDatabase) -> None:
for ps in self.prot_stacks:
ps._resolve_odxlinks(odxlinks)

def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:
def _resolve_snrefs(self, context: SnRefContext) -> None:
if self.admin_data is not None:
self.admin_data._resolve_snrefs(diag_layer)
self.admin_data._resolve_snrefs(context)

for cd in self.company_datas:
cd._resolve_snrefs(diag_layer)
cd._resolve_snrefs(context)

for sdg in self.sdgs:
sdg._resolve_snrefs(diag_layer)
sdg._resolve_snrefs(context)

for ps in self.prot_stacks:
ps._resolve_snrefs(diag_layer)
ps._resolve_snrefs(context)
Loading

0 comments on commit 33872c1

Please sign in to comment.