diff options
Diffstat (limited to 'pyGHDL/dom')
-rw-r--r-- | pyGHDL/dom/Symbol.py | 33 | ||||
-rw-r--r-- | pyGHDL/dom/_Translate.py | 7 |
2 files changed, 34 insertions, 6 deletions
diff --git a/pyGHDL/dom/Symbol.py b/pyGHDL/dom/Symbol.py index af9e59b1d..c82c39729 100644 --- a/pyGHDL/dom/Symbol.py +++ b/pyGHDL/dom/Symbol.py @@ -30,6 +30,10 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ +from pyGHDL.dom.Common import DOMException +from pyGHDL.libghdl import utils + +from pyGHDL.libghdl.vhdl import nodes from pydecor import export from typing import List @@ -40,7 +44,8 @@ from pyVHDLModel.VHDLModel import ( SimpleSubTypeSymbol as VHDLModel_SimpleSubTypeSymbol, ConstrainedSubTypeSymbol as VHDLModel_ConstrainedSubTypeSymbol, EnumerationLiteralSymbol as VHDLModel_EnumerationLiteralSymbol, - SimpleObjectSymbol as VHDLModel_SimpleObjectSymbol, + SimpleObjectOrFunctionCallSymbol as VHDLModel_SimpleObjectOrFunctionCallSymbol, + IndexedObjectOrFunctionCallSymbol as VHDLModel_IndexedObjectOrFunctionCallSymbol, Constraint, ) @@ -80,8 +85,30 @@ class ConstrainedSubTypeSymbol(VHDLModel_ConstrainedSubTypeSymbol): @export -class SimpleObjectSymbol(VHDLModel_SimpleObjectSymbol): +class SimpleObjectOrFunctionCallSymbol(VHDLModel_SimpleObjectOrFunctionCallSymbol): + @classmethod + def parse(cls, node): + name = GetNameOfNode(node) + return cls(name) + + +@export +class IndexedObjectOrFunctionCallSymbol(VHDLModel_IndexedObjectOrFunctionCallSymbol): @classmethod def parse(cls, node): - name = NodeToName(node) + prefix = nodes.Get_Prefix(node) + name = GetNameOfNode(prefix) + + for item in utils.chain_iter(nodes.Get_Association_Chain(node)): + kind = GetIirKindOfNode(item) + + if kind == nodes.Iir_Kind.Association_Element_By_Expression: + pass + else: + raise DOMException( + "Unknown association kind '{kindName}'({kind}) in array index or function call '{node}'.".format( + kind=kind, kindName=kind.name, node=node + ) + ) + return cls(name) diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py index 119f5816e..eed6a226b 100644 --- a/pyGHDL/dom/_Translate.py +++ b/pyGHDL/dom/_Translate.py @@ -42,9 +42,9 @@ from pyGHDL.dom._Utils import GetNameOfNode, GetIirKindOfNode from pyGHDL.dom.Common import DOMException from pyGHDL.dom.Range import Range, RangeExpression from pyGHDL.dom.Symbol import ( - SimpleObjectSymbol, + SimpleObjectOrFunctionCallSymbol, SimpleSubTypeSymbol, - ConstrainedSubTypeSymbol, + ConstrainedSubTypeSymbol, IndexedObjectOrFunctionCallSymbol, ) from pyGHDL.dom.Literal import IntegerLiteral, CharacterLiteral, FloatingPointLiteral, StringLiteral from pyGHDL.dom.Expression import ( @@ -135,7 +135,8 @@ def GetRangeFromNode(node) -> Range: __EXPRESSION_TRANSLATION = { - nodes.Iir_Kind.Simple_Name: SimpleObjectSymbol, + nodes.Iir_Kind.Simple_Name: SimpleObjectOrFunctionCallSymbol, + nodes.Iir_Kind.Parenthesis_Name: IndexedObjectOrFunctionCallSymbol, nodes.Iir_Kind.Integer_Literal: IntegerLiteral, nodes.Iir_Kind.Floating_Point_Literal: FloatingPointLiteral, nodes.Iir_Kind.Character_Literal: CharacterLiteral, |