diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-26 13:48:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-26 13:48:09 +0200 |
commit | 111fe055b2f0f3a0225d2553cf739572d691a14d (patch) | |
tree | 50d3a874bb78107627a6509fd4054c7fdc96cd25 /pyGHDL/dom/Symbol.py | |
parent | 15c6de72bc8dd316cb5262e1b5f373ca45b05f68 (diff) | |
download | ghdl-111fe055b2f0f3a0225d2553cf739572d691a14d.tar.gz ghdl-111fe055b2f0f3a0225d2553cf739572d691a14d.tar.bz2 ghdl-111fe055b2f0f3a0225d2553cf739572d691a14d.zip |
More DOM improvements (#1806)
* First try to handle names.
* Reworked names.
* Reworked range expressions.
* Handle AttributeNames.
* Added handling of file declaration and attribute declarations.
* Improved error outputs.
* Handle protected types.
* Make black happy with ugly code.
* Handle Null literal and File parameters.
* File type and physical type.
* Don't fail on reported syntax errors.
Catch call errors into libghdl.
* Improved Sanity checks for pyGHDL.dom.
* Load sourcecode via Python and process in-memory.
Fixed testcases.
* Added package instantiations and packages with generics.
* Added UseClause, AttributeSpecification and PhysicalTypes.
* Improved pretty-printing.
* Fixed AttributeName in subtype indication.
* Get code position of IIR nodes.
* Added DOMMixin into all derived classes.
* Mark as not yet implemented.
* Pinned pyVHDLModel version to v0.10.4.
* Removed xfail in LSP test.
Bumped requirement of pyVHDLModel to v0.10.4.
Fixed some Codacy issues.
(cherry picked from commit f64e7ed7c3d69cbf84cd60db8e9b085e90b846cb)
Diffstat (limited to 'pyGHDL/dom/Symbol.py')
-rw-r--r-- | pyGHDL/dom/Symbol.py | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/pyGHDL/dom/Symbol.py b/pyGHDL/dom/Symbol.py index d6d348f14..85d1c637b 100644 --- a/pyGHDL/dom/Symbol.py +++ b/pyGHDL/dom/Symbol.py @@ -31,9 +31,9 @@ # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ from typing import List, Iterator + from pydecor import export -from pyGHDL.dom.Range import Range from pyVHDLModel.VHDLModel import ( EntitySymbol as VHDLModel_EntitySymbol, SimpleSubTypeSymbol as VHDLModel_SimpleSubTypeSymbol, @@ -43,91 +43,91 @@ from pyVHDLModel.VHDLModel import ( SimpleObjectOrFunctionCallSymbol as VHDLModel_SimpleObjectOrFunctionCallSymbol, IndexedObjectOrFunctionCallSymbol as VHDLModel_IndexedObjectOrFunctionCallSymbol, Constraint, + Name, ) +from pyGHDL.libghdl._types import Iir +from pyGHDL.dom import DOMMixin +from pyGHDL.dom._Utils import GetNameOfNode +from pyGHDL.dom.Range import Range -from pyGHDL.libghdl import utils -from pyGHDL.libghdl.vhdl import nodes -from pyGHDL.dom._Utils import GetIirKindOfNode, GetNameOfNode -from pyGHDL.dom.Common import DOMException __all__ = [] @export -class EntitySymbol(VHDLModel_EntitySymbol): - def __init__(self, entityName: str): +class EntitySymbol(VHDLModel_EntitySymbol, DOMMixin): + def __init__(self, node: Iir, entityName: str): super().__init__(entityName) + DOMMixin.__init__(self, node) @export -class EnumerationLiteralSymbol(VHDLModel_EnumerationLiteralSymbol): - def __init__(self, literalName: str): +class EnumerationLiteralSymbol(VHDLModel_EnumerationLiteralSymbol, DOMMixin): + def __init__(self, node: Iir, literalName: str): super().__init__(symbolName=literalName) + DOMMixin.__init__(self, node) @export -class SimpleSubTypeSymbol(VHDLModel_SimpleSubTypeSymbol): - def __init__(self, subTypeName: str): +class SimpleSubTypeSymbol(VHDLModel_SimpleSubTypeSymbol, DOMMixin): + def __init__(self, node: Iir, subTypeName: Name): if isinstance(subTypeName, (List, Iterator)): subTypeName = ".".join(subTypeName) super().__init__(subTypeName=subTypeName) + DOMMixin.__init__(self, node) @export -class ConstrainedScalarSubTypeSymbol(VHDLModel_ConstrainedScalarSubTypeSymbol): - def __init__(self, subTypeName: str, range: Range = None): +class ConstrainedScalarSubTypeSymbol( + VHDLModel_ConstrainedScalarSubTypeSymbol, DOMMixin +): + def __init__(self, node: Iir, subTypeName: str, range: Range = None): super().__init__(subTypeName=subTypeName, range=range) + DOMMixin.__init__(self, node) @classmethod - def parse(cls, node): + def parse(cls, node: Iir): pass @export -class ConstrainedCompositeSubTypeSymbol(VHDLModel_ConstrainedCompositeSubTypeSymbol): - def __init__(self, subTypeName: str, constraints: List[Constraint] = None): +class ConstrainedCompositeSubTypeSymbol( + VHDLModel_ConstrainedCompositeSubTypeSymbol, DOMMixin +): + def __init__( + self, node: Iir, subTypeName: str, constraints: List[Constraint] = None + ): super().__init__(subTypeName=subTypeName, constraints=constraints) + DOMMixin.__init__(self, node) @classmethod - def parse(cls, node): + def parse(cls, node: Iir): pass @export -class SimpleObjectOrFunctionCallSymbol(VHDLModel_SimpleObjectOrFunctionCallSymbol): +class SimpleObjectOrFunctionCallSymbol( + VHDLModel_SimpleObjectOrFunctionCallSymbol, DOMMixin +): @classmethod - def parse(cls, node): + def parse(cls, node: Iir): name = GetNameOfNode(node) return cls(name) @export -class IndexedObjectOrFunctionCallSymbol(VHDLModel_IndexedObjectOrFunctionCallSymbol): - def __init__(self, name: str, associations: List): +class IndexedObjectOrFunctionCallSymbol( + VHDLModel_IndexedObjectOrFunctionCallSymbol, DOMMixin +): + def __init__(self, node: Iir, name: str): super().__init__(objectName=name) + DOMMixin.__init__(self, node) @classmethod - def parse(cls, node): - from pyGHDL.dom._Translate import GetExpressionFromNode - - prefix = nodes.Get_Prefix(node) - name = GetNameOfNode(prefix) - - associations = [] - for item in utils.chain_iter(nodes.Get_Association_Chain(node)): - kind = GetIirKindOfNode(item) - - if kind == nodes.Iir_Kind.Association_Element_By_Expression: - actual = nodes.Get_Actual(item) - expr = GetExpressionFromNode(actual) + def parse(cls, node: Iir): + from pyGHDL.dom._Translate import GetExpressionFromNode, GetNameFromNode - associations.append(expr) - else: - raise DOMException( - "Unknown association kind '{kindName}'({kind}) in array index/slice or function call '{node}'.".format( - kind=kind, kindName=kind.name, node=node - ) - ) + name = GetNameFromNode(node) - return cls(name, associations) + return cls(node, name) |