aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/pyunit/dom/Expressions.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 /testsuite/pyunit/dom/Expressions.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 'testsuite/pyunit/dom/Expressions.py')
-rw-r--r--testsuite/pyunit/dom/Expressions.py61
1 files changed, 45 insertions, 16 deletions
diff --git a/testsuite/pyunit/dom/Expressions.py b/testsuite/pyunit/dom/Expressions.py
index f9c066f52..4de36a2b2 100644
--- a/testsuite/pyunit/dom/Expressions.py
+++ b/testsuite/pyunit/dom/Expressions.py
@@ -30,17 +30,20 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
+import ctypes
+from inspect import currentframe
from pathlib import Path
from textwrap import dedent
from unittest import TestCase
-from pyGHDL.dom.DesignUnit import Package
from pyGHDL.dom import Expression
from pyGHDL.dom.NonStandard import Design, Document
+from pyGHDL.dom.DesignUnit import Package
from pyGHDL.dom.Symbol import SimpleObjectOrFunctionCallSymbol
from pyGHDL.dom.Object import Constant
-from pyGHDL.dom.Expression import InverseExpression
+from pyGHDL.dom.Expression import InverseExpression, AbsoluteExpression
+
if __name__ == "__main__":
print("ERROR: you called a testcase declaration file as an executable module.")
@@ -50,34 +53,60 @@ if __name__ == "__main__":
class Expressions(TestCase):
_root = Path(__file__).resolve().parent.parent
-
- def test_NotExpression(self):
- self._filename: Path = self._root / "{className}.vhdl".format(
- className=self.__class__.__name__
- )
-
- sourceCode = dedent(
+ _design = Design()
+ _packageTemplate = dedent(
"""\
package package_1 is
- constant c0 : boolean := not true;
+ {code}
end package;
"""
)
- with self._filename.open(mode="w", encoding="utf-8") as file:
- file.write(sourceCode)
+ def parse(self, filename: Path, code: str) -> Expression:
+ sourceCode = self._packageTemplate.format(code=code)
- design = Design()
- document = Document(self._filename)
- design.Documents.append(document)
+ document = Document(filename, sourceCode)
+ self._design.Documents.append(document)
- package: Package = design.Documents[0].Packages[0]
+ # Traverse already to default value expression
+ package: Package = document.Packages[0]
item: Constant = package.DeclaredItems[0]
default: Expression = item.DefaultExpression
+
+ return default
+
+ def test_NotExpression(self):
+ filename: Path = self._root / "{className}_{funcName}.vhdl".format(
+ className=self.__class__.__name__, funcName= currentframe().f_code.co_name[5:]
+ )
+
+ # Define test data
+ constantDeclartion = "constant c0 : boolean := not true;"
+
+ # Parse in-memory
+ default: Expression = self.parse(filename, constantDeclartion)
+
+ # Start checks
self.assertTrue(isinstance(default, InverseExpression))
self.assertTrue(isinstance(default.Operand, SimpleObjectOrFunctionCallSymbol))
self.assertTrue(default.Operand.SymbolName == "true")
+ # def test_AbsExpression(self):
+ # filename: Path = self._root / "{className}_{funcName}.vhdl".format(
+ # className=self.__class__.__name__, funcName= currentframe().f_code.co_name[5:]
+ # )
+ #
+ # # Define test data
+ # constantDeclartion = "constant c0 : integer := abs 3;"
+ #
+ # # Parse in-memory
+ # default: Expression = self.parse(filename, constantDeclartion)
+ #
+ # # Start checks
+ # self.assertTrue(isinstance(default, AbsoluteExpression))
+ # self.assertTrue(isinstance(default.Operand, SimpleObjectOrFunctionCallSymbol))
+ # self.assertTrue(default.Operand.SymbolName == "-3")
+
# def test_Aggregare(self):
# self._filename: Path = self._root / "{className}.vhdl".format(className=self.__class__.__name__)
#