aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom/Literal.py
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-26 13:48:09 +0200
committerGitHub <noreply@github.com>2021-06-26 13:48:09 +0200
commit111fe055b2f0f3a0225d2553cf739572d691a14d (patch)
tree50d3a874bb78107627a6509fd4054c7fdc96cd25 /pyGHDL/dom/Literal.py
parent15c6de72bc8dd316cb5262e1b5f373ca45b05f68 (diff)
downloadghdl-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/Literal.py')
-rw-r--r--pyGHDL/dom/Literal.py99
1 files changed, 70 insertions, 29 deletions
diff --git a/pyGHDL/dom/Literal.py b/pyGHDL/dom/Literal.py
index a2e86b389..784039d45 100644
--- a/pyGHDL/dom/Literal.py
+++ b/pyGHDL/dom/Literal.py
@@ -30,10 +30,10 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
-from pyGHDL.libghdl._types import Iir
from pydecor import export
from pyVHDLModel.VHDLModel import (
+ NullLiteral as VHDLModel_NullLiteral,
EnumerationLiteral as VHDLModel_EnumerationLiteral,
IntegerLiteral as VHDLModel_IntegerLiteral,
FloatingPointLiteral as VHDLModel_FloatingPointLiteral,
@@ -43,71 +43,112 @@ from pyVHDLModel.VHDLModel import (
StringLiteral as VHDLModel_StringLiteral,
)
from pyGHDL.libghdl import name_table
+from pyGHDL.libghdl._types import Iir
from pyGHDL.libghdl.vhdl import nodes
+from pyGHDL.dom import DOMMixin
from pyGHDL.dom._Utils import GetNameOfNode
__all__ = []
@export
-class EnumerationLiteral(VHDLModel_EnumerationLiteral):
+class NullLiteral(VHDLModel_NullLiteral, DOMMixin):
+ def __init__(self, node: Iir):
+ super().__init__()
+ DOMMixin.__init__(self, node)
+
+ @classmethod
+ def parse(cls, node: Iir) -> "NullLiteral":
+ return cls(node)
+
+
+@export
+class EnumerationLiteral(VHDLModel_EnumerationLiteral, DOMMixin):
+ def __init__(self, node: Iir, value: str):
+ super().__init__(value)
+ DOMMixin.__init__(self, node)
+
@classmethod
def parse(cls, literalNode: Iir) -> "EnumerationLiteral":
literalName = GetNameOfNode(literalNode)
- return cls(literalName)
+ return cls(literalNode, literalName)
@export
-class IntegerLiteral(VHDLModel_IntegerLiteral):
+class IntegerLiteral(VHDLModel_IntegerLiteral, DOMMixin):
+ def __init__(self, node: Iir, value: int):
+ super().__init__(value)
+ DOMMixin.__init__(self, node)
+
@classmethod
- def parse(cls, node: Iir) -> "IntegerLiteral":
- value = nodes.Get_Value(node)
- return cls(value)
+ def parse(cls, literalNode: Iir) -> "IntegerLiteral":
+ value = nodes.Get_Value(literalNode)
+ return cls(literalNode, value)
@export
-class FloatingPointLiteral(VHDLModel_FloatingPointLiteral):
+class FloatingPointLiteral(VHDLModel_FloatingPointLiteral, DOMMixin):
+ def __init__(self, node: Iir, value: float):
+ super().__init__(value)
+ DOMMixin.__init__(self, node)
+
@classmethod
- def parse(cls, node: Iir) -> "FloatingPointLiteral":
- value = nodes.Get_Fp_Value(node)
- return cls(value)
+ def parse(cls, literalNode: Iir) -> "FloatingPointLiteral":
+ value = nodes.Get_Fp_Value(literalNode)
+ return cls(literalNode, value)
@export
-class PhysicalIntegerLiteral(VHDLModel_PhysicalIntegerLiteral):
+class PhysicalIntegerLiteral(VHDLModel_PhysicalIntegerLiteral, DOMMixin):
+ def __init__(self, node: Iir, value: int, unitName: str):
+ super().__init__(value, unitName)
+ DOMMixin.__init__(self, node)
+
@classmethod
- def parse(cls, node: Iir) -> "PhysicalIntegerLiteral":
- value = nodes.Get_Value(node)
- unit = nodes.Get_Unit_Name(node)
+ def parse(cls, literalNode: Iir) -> "PhysicalIntegerLiteral":
+ value = nodes.Get_Value(literalNode)
+ unit = nodes.Get_Unit_Name(literalNode)
unitName = GetNameOfNode(unit)
- return cls(value, unitName)
+ return cls(literalNode, value, unitName)
@export
-class PhysicalFloatingLiteral(VHDLModel_PhysicalFloatingLiteral):
+class PhysicalFloatingLiteral(VHDLModel_PhysicalFloatingLiteral, DOMMixin):
+ def __init__(self, node: Iir, value: int, unitName: float):
+ super().__init__(value, unitName)
+ DOMMixin.__init__(self, node)
+
@classmethod
- def parse(cls, node: Iir) -> "PhysicalFloatingLiteral":
- value = nodes.Get_Fp_Value(node)
- unit = nodes.Get_Unit_Name(node)
+ def parse(cls, literalNode: Iir) -> "PhysicalFloatingLiteral":
+ value = nodes.Get_Fp_Value(literalNode)
+ unit = nodes.Get_Unit_Name(literalNode)
unitName = GetNameOfNode(unit)
- return cls(value, unitName)
+ return cls(literalNode, value, unitName)
@export
-class CharacterLiteral(VHDLModel_CharacterLiteral):
+class CharacterLiteral(VHDLModel_CharacterLiteral, DOMMixin):
+ def __init__(self, node: Iir, value: str):
+ super().__init__(value)
+ DOMMixin.__init__(self, node)
+
@classmethod
- def parse(cls, node: Iir) -> "CharacterLiteral":
- identifier = nodes.Get_Identifier(node)
+ def parse(cls, literalNode: Iir) -> "CharacterLiteral":
+ identifier = nodes.Get_Identifier(literalNode)
value = name_table.Get_Character(identifier)
- return cls(value)
+ return cls(literalNode, value)
@export
-class StringLiteral(VHDLModel_StringLiteral):
+class StringLiteral(VHDLModel_StringLiteral, DOMMixin):
+ def __init__(self, node: Iir, value: str):
+ super().__init__(value)
+ DOMMixin.__init__(self, node)
+
@classmethod
- def parse(cls, node: Iir) -> "StringLiteral":
- stringID = nodes.Get_String8_Id(node)
+ def parse(cls, literalNode: Iir) -> "StringLiteral":
+ stringID = nodes.Get_String8_Id(literalNode)
value = name_table.Get_Name_Ptr(stringID)
- return cls(value)
+ return cls(literalNode, value)