From 2d84548e3827bd3d42c3e2bce159b68d70a8740d Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Fri, 18 Jun 2021 19:24:52 +0200 Subject: pyGHDL/dom: add some guards to avoid crash for optional fields --- pyGHDL/dom/InterfaceItem.py | 3 ++- pyGHDL/dom/Object.py | 3 ++- pyGHDL/dom/_Translate.py | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pyGHDL/dom/InterfaceItem.py b/pyGHDL/dom/InterfaceItem.py index fcb8b0ef3..a4a94ec2d 100644 --- a/pyGHDL/dom/InterfaceItem.py +++ b/pyGHDL/dom/InterfaceItem.py @@ -57,7 +57,8 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, GHDLM name = NodeToName(generic) mode = GetModeOfNode(generic) subTypeIndication = GetSubtypeIndicationFromNode(generic, "generic", name) - value = GetExpressionFromNode(nodes.Get_Default_Value(generic)) + default = nodes.Get_Default_Value(generic); + value = GetExpressionFromNode(default) if default else None generic = cls(name, mode, subTypeIndication, value) diff --git a/pyGHDL/dom/Object.py b/pyGHDL/dom/Object.py index a6d62e658..7250f7edd 100644 --- a/pyGHDL/dom/Object.py +++ b/pyGHDL/dom/Object.py @@ -105,7 +105,8 @@ class Signal(VHDLModel_Signal): def parse(cls, node): name = NodeToName(node) subTypeIndication = GetSubtypeIndicationFromNode(node, "signal", name) - defaultExpression = GetExpressionFromNode(nodes.Get_Default_Value(node)) + default = nodes.Get_Default_Value(node); + defaultExpression = GetExpressionFromNode(default) if default else None signal = cls(name, subTypeIndication, defaultExpression) diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py index 76e39f09f..9eb4937ec 100644 --- a/pyGHDL/dom/_Translate.py +++ b/pyGHDL/dom/_Translate.py @@ -62,6 +62,8 @@ __all__ = [] @export def GetSubtypeIndicationFromNode(node, entity: str, name: str) -> SubTypeOrSymbol: subTypeIndication = nodes.Get_Subtype_Indication(node) + if subTypeIndication is nodes.Null_Iir: + return None subTypeKind = GetIirKindOfNode(subTypeIndication) if subTypeKind == nodes.Iir_Kind.Simple_Name: -- cgit v1.2.3