From 3a3e8e5fded027c1dc6e3566c5ad9a30e8bc5297 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 28 Nov 2022 23:16:11 +0100 Subject: Added handling of associated documentation comments. --- pyGHDL/dom/InterfaceItem.py | 110 +++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 68 deletions(-) (limited to 'pyGHDL/dom/InterfaceItem.py') diff --git a/pyGHDL/dom/InterfaceItem.py b/pyGHDL/dom/InterfaceItem.py index 66a8fe37b..e42c8dcb2 100644 --- a/pyGHDL/dom/InterfaceItem.py +++ b/pyGHDL/dom/InterfaceItem.py @@ -13,7 +13,7 @@ # # License: # ============================================================================ -# Copyright (C) 2019-2021 Tristan Gingold +# Copyright (C) 2019-2022 Tristan Gingold # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -53,7 +53,7 @@ from pyVHDLModel.SyntaxModel import ( from pyGHDL.libghdl._types import Iir from pyGHDL.libghdl.vhdl import nodes from pyGHDL.dom import DOMMixin -from pyGHDL.dom._Utils import GetNameOfNode, GetModeOfNode +from pyGHDL.dom._Utils import GetNameOfNode, GetModeOfNode, GetDocumentationOfNode from pyGHDL.dom._Translate import GetSubtypeIndicationFromNode, GetExpressionFromNode @@ -69,27 +69,21 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, DOMMi mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: ExpressionUnion, + documentation: str = None ): - super().__init__(identifiers, mode, subtype, defaultExpression) + super().__init__(identifiers, mode, subtype, defaultExpression, documentation) DOMMixin.__init__(self, node) @classmethod def parse(cls, genericNode: Iir) -> "GenericConstantInterfaceItem": name = GetNameOfNode(genericNode) + documentation = GetDocumentationOfNode(genericNode) mode = GetModeOfNode(genericNode) subtypeIndication = GetSubtypeIndicationFromNode(genericNode, "generic", name) default = nodes.Get_Default_Value(genericNode) value = GetExpressionFromNode(default) if default else None - return cls( - genericNode, - [ - name, - ], - mode, - subtypeIndication, - value, - ) + return cls(genericNode, [name], mode, subtypeIndication, value, documentation) @export @@ -98,15 +92,17 @@ class GenericTypeInterfaceItem(VHDLModel_GenericTypeInterfaceItem, DOMMixin): self, node: Iir, identifier: str, + documentation: str = None ): - super().__init__(identifier) + super().__init__(identifier, documentation) DOMMixin.__init__(self, node) @classmethod def parse(cls, genericNode: Iir) -> "GenericTypeInterfaceItem": name = GetNameOfNode(genericNode) + documentation = GetDocumentationOfNode(genericNode) - return cls(genericNode, name) + return cls(genericNode, name, documentation) @export @@ -115,15 +111,17 @@ class GenericPackageInterfaceItem(VHDLModel_GenericPackageInterfaceItem, DOMMixi self, node: Iir, name: str, + documentation: str = None ): - super().__init__(name) + super().__init__(name, documentation) DOMMixin.__init__(self, node) @classmethod def parse(cls, genericNode: Iir) -> "GenericPackageInterfaceItem": name = GetNameOfNode(genericNode) + documentation = GetDocumentationOfNode(genericNode) - return cls(genericNode, name) + return cls(genericNode, name, documentation) @export @@ -132,15 +130,17 @@ class GenericProcedureInterfaceItem(VHDLModel_GenericProcedureInterfaceItem, DOM self, node: Iir, identifier: str, + documentation: str = None ): - super().__init__(identifier) + super().__init__(identifier, documentation) DOMMixin.__init__(self, node) @classmethod def parse(cls, genericNode: Iir) -> "GenericProcedureInterfaceItem": name = GetNameOfNode(genericNode) + documentation = GetDocumentationOfNode(genericNode) - return cls(genericNode, name) + return cls(genericNode, name, documentation) @export @@ -149,15 +149,17 @@ class GenericFunctionInterfaceItem(VHDLModel_GenericFunctionInterfaceItem, DOMMi self, node: Iir, identifier: str, + documentation: str = None ): - super().__init__(identifier) + super().__init__(identifier, documentation) DOMMixin.__init__(self, node) @classmethod def parse(cls, genericNode: Iir) -> "GenericFunctionInterfaceItem": name = GetNameOfNode(genericNode) + documentation = GetDocumentationOfNode(genericNode) - return cls(genericNode, name) + return cls(genericNode, name, documentation) @export @@ -169,28 +171,22 @@ class PortSignalInterfaceItem(VHDLModel_PortSignalInterfaceItem, DOMMixin): mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: ExpressionUnion = None, + documentation: str = None ): - super().__init__(identifiers, mode, subtype, defaultExpression) + super().__init__(identifiers, mode, subtype, defaultExpression, documentation) DOMMixin.__init__(self, node) @classmethod def parse(cls, portNode: Iir) -> "PortSignalInterfaceItem": name = GetNameOfNode(portNode) + documentation = GetDocumentationOfNode(portNode) mode = GetModeOfNode(portNode) subtypeIndication = GetSubtypeIndicationFromNode(portNode, "port", name) defaultValue = nodes.Get_Default_Value(portNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls( - portNode, - [ - name, - ], - mode, - subtypeIndication, - value, - ) + return cls(portNode, [name], mode, subtypeIndication, value, documentation) @export @@ -202,28 +198,22 @@ class ParameterConstantInterfaceItem(VHDLModel_ParameterConstantInterfaceItem, D mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: ExpressionUnion = None, + documentation: str = None ): - super().__init__(identifiers, mode, subtype, defaultExpression) + super().__init__(identifiers, mode, subtype, defaultExpression, documentation) DOMMixin.__init__(self, node) @classmethod def parse(cls, parameterNode: Iir) -> "ParameterConstantInterfaceItem": name = GetNameOfNode(parameterNode) + documentation = GetDocumentationOfNode(parameterNode) mode = GetModeOfNode(parameterNode) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) defaultValue = nodes.Get_Default_Value(parameterNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls( - parameterNode, - [ - name, - ], - mode, - subtypeIndication, - value, - ) + return cls(parameterNode, [name], mode, subtypeIndication, value, documentation) @export @@ -235,28 +225,22 @@ class ParameterVariableInterfaceItem(VHDLModel_ParameterVariableInterfaceItem, D mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: ExpressionUnion = None, + documentation: str = None ): - super().__init__(identifiers, mode, subtype, defaultExpression) + super().__init__(identifiers, mode, subtype, defaultExpression, documentation) DOMMixin.__init__(self, node) @classmethod def parse(cls, parameterNode: Iir) -> "ParameterVariableInterfaceItem": name = GetNameOfNode(parameterNode) + documentation = GetDocumentationOfNode(parameterNode) mode = GetModeOfNode(parameterNode) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) defaultValue = nodes.Get_Default_Value(parameterNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls( - parameterNode, - [ - name, - ], - mode, - subtypeIndication, - value, - ) + return cls(parameterNode, [name], mode, subtypeIndication, value, documentation) @export @@ -268,28 +252,22 @@ class ParameterSignalInterfaceItem(VHDLModel_ParameterSignalInterfaceItem, DOMMi mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: ExpressionUnion = None, + documentation: str = None ): - super().__init__(identifiers, mode, subtype, defaultExpression) + super().__init__(identifiers, mode, subtype, defaultExpression, documentation) DOMMixin.__init__(self, node) @classmethod def parse(cls, parameterNode: Iir) -> "ParameterSignalInterfaceItem": name = GetNameOfNode(parameterNode) + documentation = GetDocumentationOfNode(parameterNode) mode = GetModeOfNode(parameterNode) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) defaultValue = nodes.Get_Default_Value(parameterNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls( - parameterNode, - [ - name, - ], - mode, - subtypeIndication, - value, - ) + return cls(parameterNode, [name], mode, subtypeIndication, value, documentation) @export @@ -299,19 +277,15 @@ class ParameterFileInterfaceItem(VHDLModel_ParameterFileInterfaceItem, DOMMixin) node: Iir, identifiers: List[str], subtype: SubtypeOrSymbol, + documentation: str = None ): - super().__init__(identifiers, subtype) + super().__init__(identifiers, subtype, documentation) DOMMixin.__init__(self, node) @classmethod def parse(cls, parameterNode: Iir) -> "ParameterFileInterfaceItem": name = GetNameOfNode(parameterNode) + documentation = GetDocumentationOfNode(parameterNode) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) - return cls( - parameterNode, - [ - name, - ], - subtypeIndication, - ) + return cls(parameterNode, [name], subtypeIndication, documentation) -- cgit v1.2.3 From 75c3f850ce617b86fd1393d12638ebee32c516cc Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 6 Dec 2022 08:12:27 +0100 Subject: Here is blacks opinion. --- pyGHDL/dom/InterfaceItem.py | 46 ++++++++++----------------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) (limited to 'pyGHDL/dom/InterfaceItem.py') diff --git a/pyGHDL/dom/InterfaceItem.py b/pyGHDL/dom/InterfaceItem.py index e42c8dcb2..fb8a1b320 100644 --- a/pyGHDL/dom/InterfaceItem.py +++ b/pyGHDL/dom/InterfaceItem.py @@ -69,7 +69,7 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, DOMMi mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: ExpressionUnion, - documentation: str = None + documentation: str = None, ): super().__init__(identifiers, mode, subtype, defaultExpression, documentation) DOMMixin.__init__(self, node) @@ -88,12 +88,7 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, DOMMi @export class GenericTypeInterfaceItem(VHDLModel_GenericTypeInterfaceItem, DOMMixin): - def __init__( - self, - node: Iir, - identifier: str, - documentation: str = None - ): + def __init__(self, node: Iir, identifier: str, documentation: str = None): super().__init__(identifier, documentation) DOMMixin.__init__(self, node) @@ -107,12 +102,7 @@ class GenericTypeInterfaceItem(VHDLModel_GenericTypeInterfaceItem, DOMMixin): @export class GenericPackageInterfaceItem(VHDLModel_GenericPackageInterfaceItem, DOMMixin): - def __init__( - self, - node: Iir, - name: str, - documentation: str = None - ): + def __init__(self, node: Iir, name: str, documentation: str = None): super().__init__(name, documentation) DOMMixin.__init__(self, node) @@ -126,12 +116,7 @@ class GenericPackageInterfaceItem(VHDLModel_GenericPackageInterfaceItem, DOMMixi @export class GenericProcedureInterfaceItem(VHDLModel_GenericProcedureInterfaceItem, DOMMixin): - def __init__( - self, - node: Iir, - identifier: str, - documentation: str = None - ): + def __init__(self, node: Iir, identifier: str, documentation: str = None): super().__init__(identifier, documentation) DOMMixin.__init__(self, node) @@ -145,12 +130,7 @@ class GenericProcedureInterfaceItem(VHDLModel_GenericProcedureInterfaceItem, DOM @export class GenericFunctionInterfaceItem(VHDLModel_GenericFunctionInterfaceItem, DOMMixin): - def __init__( - self, - node: Iir, - identifier: str, - documentation: str = None - ): + def __init__(self, node: Iir, identifier: str, documentation: str = None): super().__init__(identifier, documentation) DOMMixin.__init__(self, node) @@ -171,7 +151,7 @@ class PortSignalInterfaceItem(VHDLModel_PortSignalInterfaceItem, DOMMixin): mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: ExpressionUnion = None, - documentation: str = None + documentation: str = None, ): super().__init__(identifiers, mode, subtype, defaultExpression, documentation) DOMMixin.__init__(self, node) @@ -198,7 +178,7 @@ class ParameterConstantInterfaceItem(VHDLModel_ParameterConstantInterfaceItem, D mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: ExpressionUnion = None, - documentation: str = None + documentation: str = None, ): super().__init__(identifiers, mode, subtype, defaultExpression, documentation) DOMMixin.__init__(self, node) @@ -225,7 +205,7 @@ class ParameterVariableInterfaceItem(VHDLModel_ParameterVariableInterfaceItem, D mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: ExpressionUnion = None, - documentation: str = None + documentation: str = None, ): super().__init__(identifiers, mode, subtype, defaultExpression, documentation) DOMMixin.__init__(self, node) @@ -252,7 +232,7 @@ class ParameterSignalInterfaceItem(VHDLModel_ParameterSignalInterfaceItem, DOMMi mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: ExpressionUnion = None, - documentation: str = None + documentation: str = None, ): super().__init__(identifiers, mode, subtype, defaultExpression, documentation) DOMMixin.__init__(self, node) @@ -272,13 +252,7 @@ class ParameterSignalInterfaceItem(VHDLModel_ParameterSignalInterfaceItem, DOMMi @export class ParameterFileInterfaceItem(VHDLModel_ParameterFileInterfaceItem, DOMMixin): - def __init__( - self, - node: Iir, - identifiers: List[str], - subtype: SubtypeOrSymbol, - documentation: str = None - ): + def __init__(self, node: Iir, identifiers: List[str], subtype: SubtypeOrSymbol, documentation: str = None): super().__init__(identifiers, subtype, documentation) DOMMixin.__init__(self, node) -- cgit v1.2.3 From d557b50e78e74801bf296b18a004a468555921be Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 6 Dec 2022 00:36:29 +0100 Subject: Updated for latest pyVHDLModel v0.17.x (cherry picked from commit fb6e98b119cc1bb94ba5ecca88d7533a00a2e3f6) --- pyGHDL/dom/InterfaceItem.py | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'pyGHDL/dom/InterfaceItem.py') diff --git a/pyGHDL/dom/InterfaceItem.py b/pyGHDL/dom/InterfaceItem.py index fb8a1b320..aa63f3094 100644 --- a/pyGHDL/dom/InterfaceItem.py +++ b/pyGHDL/dom/InterfaceItem.py @@ -30,7 +30,7 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ -from typing import List +from typing import List, Iterable from pyTooling.Decorators import export @@ -75,15 +75,18 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, DOMMi DOMMixin.__init__(self, node) @classmethod - def parse(cls, genericNode: Iir) -> "GenericConstantInterfaceItem": + def parse(cls, genericNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "GenericConstantInterfaceItem": name = GetNameOfNode(genericNode) documentation = GetDocumentationOfNode(genericNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) mode = GetModeOfNode(genericNode) subtypeIndication = GetSubtypeIndicationFromNode(genericNode, "generic", name) default = nodes.Get_Default_Value(genericNode) value = GetExpressionFromNode(default) if default else None - return cls(genericNode, [name], mode, subtypeIndication, value, documentation) + return cls(genericNode, identifiers, mode, subtypeIndication, value, documentation) @export @@ -157,16 +160,19 @@ class PortSignalInterfaceItem(VHDLModel_PortSignalInterfaceItem, DOMMixin): DOMMixin.__init__(self, node) @classmethod - def parse(cls, portNode: Iir) -> "PortSignalInterfaceItem": + def parse(cls, portNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "PortSignalInterfaceItem": name = GetNameOfNode(portNode) documentation = GetDocumentationOfNode(portNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) mode = GetModeOfNode(portNode) subtypeIndication = GetSubtypeIndicationFromNode(portNode, "port", name) defaultValue = nodes.Get_Default_Value(portNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls(portNode, [name], mode, subtypeIndication, value, documentation) + return cls(portNode, identifiers, mode, subtypeIndication, value, documentation) @export @@ -184,16 +190,19 @@ class ParameterConstantInterfaceItem(VHDLModel_ParameterConstantInterfaceItem, D DOMMixin.__init__(self, node) @classmethod - def parse(cls, parameterNode: Iir) -> "ParameterConstantInterfaceItem": + def parse(cls, parameterNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "ParameterConstantInterfaceItem": name = GetNameOfNode(parameterNode) documentation = GetDocumentationOfNode(parameterNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) mode = GetModeOfNode(parameterNode) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) defaultValue = nodes.Get_Default_Value(parameterNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls(parameterNode, [name], mode, subtypeIndication, value, documentation) + return cls(parameterNode, identifiers, mode, subtypeIndication, value, documentation) @export @@ -211,16 +220,19 @@ class ParameterVariableInterfaceItem(VHDLModel_ParameterVariableInterfaceItem, D DOMMixin.__init__(self, node) @classmethod - def parse(cls, parameterNode: Iir) -> "ParameterVariableInterfaceItem": + def parse(cls, parameterNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "ParameterVariableInterfaceItem": name = GetNameOfNode(parameterNode) documentation = GetDocumentationOfNode(parameterNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) mode = GetModeOfNode(parameterNode) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) defaultValue = nodes.Get_Default_Value(parameterNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls(parameterNode, [name], mode, subtypeIndication, value, documentation) + return cls(parameterNode, identifiers, mode, subtypeIndication, value, documentation) @export @@ -238,16 +250,19 @@ class ParameterSignalInterfaceItem(VHDLModel_ParameterSignalInterfaceItem, DOMMi DOMMixin.__init__(self, node) @classmethod - def parse(cls, parameterNode: Iir) -> "ParameterSignalInterfaceItem": + def parse(cls, parameterNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "ParameterSignalInterfaceItem": name = GetNameOfNode(parameterNode) documentation = GetDocumentationOfNode(parameterNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) mode = GetModeOfNode(parameterNode) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) defaultValue = nodes.Get_Default_Value(parameterNode) value = GetExpressionFromNode(defaultValue) if defaultValue != nodes.Null_Iir else None - return cls(parameterNode, [name], mode, subtypeIndication, value, documentation) + return cls(parameterNode, identifiers, mode, subtypeIndication, value, documentation) @export @@ -257,9 +272,12 @@ class ParameterFileInterfaceItem(VHDLModel_ParameterFileInterfaceItem, DOMMixin) DOMMixin.__init__(self, node) @classmethod - def parse(cls, parameterNode: Iir) -> "ParameterFileInterfaceItem": + def parse(cls, parameterNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "ParameterFileInterfaceItem": name = GetNameOfNode(parameterNode) documentation = GetDocumentationOfNode(parameterNode) + identifiers = [name] + if furtherIdentifiers is not None: + identifiers.extend(furtherIdentifiers) subtypeIndication = GetSubtypeIndicationFromNode(parameterNode, "parameter", name) - return cls(parameterNode, [name], subtypeIndication, documentation) + return cls(parameterNode, identifiers, subtypeIndication, documentation) -- cgit v1.2.3