aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom/Object.py
diff options
context:
space:
mode:
authortgingold <tgingold@users.noreply.github.com>2022-12-24 08:56:55 +0100
committerGitHub <noreply@github.com>2022-12-24 08:56:55 +0100
commit26bb3c572eaffafafd8de8ef09b8acc34f91656f (patch)
tree2d70696f4f8bb78f9a4fda7a6d596775fdf080cc /pyGHDL/dom/Object.py
parent8845f761ed2299e595afd5eee2444fed7fb79639 (diff)
parent5d9897770cb16494c6379cce85ed5935532c0cd1 (diff)
downloadghdl-26bb3c572eaffafafd8de8ef09b8acc34f91656f.tar.gz
ghdl-26bb3c572eaffafafd8de8ef09b8acc34f91656f.tar.bz2
ghdl-26bb3c572eaffafafd8de8ef09b8acc34f91656f.zip
Merge pull request #2265 from Paebbels/paebbels/DOM-with-documentation
pyGHDL.dom with Documentation
Diffstat (limited to 'pyGHDL/dom/Object.py')
-rw-r--r--pyGHDL/dom/Object.py124
1 files changed, 54 insertions, 70 deletions
diff --git a/pyGHDL/dom/Object.py b/pyGHDL/dom/Object.py
index 6d3472a6f..1079eae4a 100644
--- a/pyGHDL/dom/Object.py
+++ b/pyGHDL/dom/Object.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
@@ -30,7 +30,7 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
-from typing import Union, List
+from typing import Union, List, Iterable
from pyTooling.Decorators import export
@@ -48,7 +48,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
+from pyGHDL.dom._Utils import GetNameOfNode, GetDocumentationOfNode
__all__ = []
@@ -61,61 +61,53 @@ class Constant(VHDLModel_Constant, DOMMixin):
identifiers: List[str],
subtype: SubtypeOrSymbol,
defaultExpression: ExpressionUnion,
+ documentation: str = None,
):
- super().__init__(identifiers, subtype, defaultExpression)
+ super().__init__(identifiers, subtype, defaultExpression, documentation)
DOMMixin.__init__(self, node)
@classmethod
- def parse(cls, constantNode: Iir) -> Union["Constant", "DeferredConstant"]:
+ def parse(
+ cls, constantNode: Iir, furtherIdentifiers: Iterable[str] = None
+ ) -> Union["Constant", "DeferredConstant"]:
from pyGHDL.dom._Translate import (
GetSubtypeIndicationFromNode,
GetExpressionFromNode,
)
name = GetNameOfNode(constantNode)
+ documentation = GetDocumentationOfNode(constantNode)
+ identifiers = [name]
+ if furtherIdentifiers is not None:
+ identifiers.extend(furtherIdentifiers)
subtypeIndication = GetSubtypeIndicationFromNode(constantNode, "constant", name)
defaultValue = nodes.Get_Default_Value(constantNode)
if defaultValue != nodes.Null_Iir:
defaultExpression = GetExpressionFromNode(defaultValue)
- return cls(
- constantNode,
- [
- name,
- ],
- subtypeIndication,
- defaultExpression,
- )
+ return cls(constantNode, identifiers, subtypeIndication, defaultExpression, documentation)
else:
- return DeferredConstant(
- constantNode,
- [
- name,
- ],
- subtypeIndication,
- )
+ return DeferredConstant(constantNode, identifiers, subtypeIndication, documentation)
@export
class DeferredConstant(VHDLModel_DeferredConstant, DOMMixin):
- def __init__(self, node: Iir, identifiers: List[str], subtype: SubtypeOrSymbol):
- super().__init__(identifiers, subtype)
+ def __init__(self, node: Iir, identifiers: List[str], subtype: SubtypeOrSymbol, documentation: str = None):
+ super().__init__(identifiers, subtype, documentation)
DOMMixin.__init__(self, node)
@classmethod
- def parse(cls, constantNode: Iir) -> "DeferredConstant":
+ def parse(cls, constantNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "DeferredConstant":
from pyGHDL.dom._Translate import GetSubtypeIndicationFromNode
name = GetNameOfNode(constantNode)
+ documentation = GetDocumentationOfNode(constantNode)
+ identifiers = [name]
+ if furtherIdentifiers is not None:
+ identifiers.extend(furtherIdentifiers)
subtypeIndication = GetSubtypeIndicationFromNode(constantNode, "deferred constant", name)
- return cls(
- constantNode,
- [
- name,
- ],
- subtypeIndication,
- )
+ return cls(constantNode, identifiers, subtypeIndication, documentation)
@export
@@ -126,54 +118,50 @@ class Variable(VHDLModel_Variable, DOMMixin):
identifiers: List[str],
subtype: SubtypeOrSymbol,
defaultExpression: ExpressionUnion,
+ documentation: str = None,
):
- super().__init__(identifiers, subtype, defaultExpression)
+ super().__init__(identifiers, subtype, defaultExpression, documentation)
DOMMixin.__init__(self, node)
@classmethod
- def parse(cls, variableNode: Iir) -> "Variable":
+ def parse(cls, variableNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "Variable":
from pyGHDL.dom._Translate import (
GetSubtypeIndicationFromNode,
GetExpressionFromNode,
)
name = GetNameOfNode(variableNode)
+ documentation = GetDocumentationOfNode(variableNode)
+ identifiers = [name]
+ if furtherIdentifiers is not None:
+ identifiers.extend(furtherIdentifiers)
subtypeIndication = GetSubtypeIndicationFromNode(variableNode, "variable", name)
defaultValue = nodes.Get_Default_Value(variableNode)
defaultExpression = None
if defaultValue != nodes.Null_Iir:
defaultExpression = GetExpressionFromNode(defaultValue)
- return cls(
- variableNode,
- [
- name,
- ],
- subtypeIndication,
- defaultExpression,
- )
+ return cls(variableNode, identifiers, subtypeIndication, defaultExpression, documentation)
@export
class SharedVariable(VHDLModel_SharedVariable, DOMMixin):
- def __init__(self, node: Iir, identifiers: List[str], subtype: SubtypeOrSymbol):
- super().__init__(identifiers, subtype)
+ def __init__(self, node: Iir, identifiers: List[str], subtype: SubtypeOrSymbol, documentation: str = None):
+ super().__init__(identifiers, subtype, documentation)
DOMMixin.__init__(self, node)
@classmethod
- def parse(cls, variableNode: Iir) -> "SharedVariable":
+ def parse(cls, variableNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "SharedVariable":
from pyGHDL.dom._Translate import GetSubtypeIndicationFromNode
name = GetNameOfNode(variableNode)
+ documentation = GetDocumentationOfNode(variableNode)
+ identifiers = [name]
+ if furtherIdentifiers is not None:
+ identifiers.extend(furtherIdentifiers)
subtypeIndication = GetSubtypeIndicationFromNode(variableNode, "variable", name)
- return cls(
- variableNode,
- [
- name,
- ],
- subtypeIndication,
- )
+ return cls(variableNode, identifiers, subtypeIndication, documentation)
@export
@@ -184,51 +172,47 @@ class Signal(VHDLModel_Signal, DOMMixin):
identifiers: List[str],
subtype: SubtypeOrSymbol,
defaultExpression: ExpressionUnion,
+ documentation: str = None,
):
- super().__init__(identifiers, subtype, defaultExpression)
+ super().__init__(identifiers, subtype, defaultExpression, documentation)
DOMMixin.__init__(self, node)
@classmethod
- def parse(cls, signalNode: Iir) -> "Signal":
+ def parse(cls, signalNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "Signal":
from pyGHDL.dom._Translate import (
GetSubtypeIndicationFromNode,
GetExpressionFromNode,
)
name = GetNameOfNode(signalNode)
+ documentation = GetDocumentationOfNode(signalNode)
+ identifiers = [name]
+ if furtherIdentifiers is not None:
+ identifiers.extend(furtherIdentifiers)
subtypeIndication = GetSubtypeIndicationFromNode(signalNode, "signal", name)
default = nodes.Get_Default_Value(signalNode)
defaultExpression = GetExpressionFromNode(default) if default else None
- return cls(
- signalNode,
- [
- name,
- ],
- subtypeIndication,
- defaultExpression,
- )
+ return cls(signalNode, identifiers, subtypeIndication, defaultExpression, documentation)
@export
class File(VHDLModel_File, DOMMixin):
- def __init__(self, node: Iir, identifiers: List[str], subtype: SubtypeOrSymbol):
- super().__init__(identifiers, subtype)
+ def __init__(self, node: Iir, identifiers: List[str], subtype: SubtypeOrSymbol, documentation: str = None):
+ super().__init__(identifiers, subtype, documentation)
DOMMixin.__init__(self, node)
@classmethod
- def parse(cls, fileNode: Iir) -> "File":
+ def parse(cls, fileNode: Iir, furtherIdentifiers: Iterable[str] = None) -> "File":
from pyGHDL.dom._Translate import GetSubtypeIndicationFromNode
name = GetNameOfNode(fileNode)
+ documentation = GetDocumentationOfNode(fileNode)
+ identifiers = [name]
+ if furtherIdentifiers is not None:
+ identifiers.extend(furtherIdentifiers)
subtypeIndication = GetSubtypeIndicationFromNode(fileNode, "file", name)
# FIXME: handle file open stuff
- return cls(
- fileNode,
- [
- name,
- ],
- subtypeIndication,
- )
+ return cls(fileNode, identifiers, subtypeIndication, documentation)