def parse(cls, node: Iir) -> "QualifiedExpression": from pyGHDL.dom._Translate import GetExpressionFromNode, GetNameOfNode typeMarkName = GetNameOfNode(nodes.Get_Type_Mark(node)) subtype = SimpleSubtypeSymbol(node, typeMarkName) operand = GetExpressionFromNode(nodes.Get_Expression(node)) return cls(node, subtype, operand)
def parse(cls, attributeNode: Iir) -> "AttributeSpecification": attributeDesignator = nodes.Get_Attribute_Designator(attributeNode) attributeName = GetNameFromNode(attributeDesignator) names = [] entityNameList = nodes.Get_Entity_Name_List(attributeNode) for name in utils.flist_iter(entityNameList): nameKind = GetIirKindOfNode(name) if nameKind == nodes.Iir_Kind.Simple_Name: names.append(SimpleName(name, GetNameOfNode(name))) elif nameKind == nodes.Iir_Kind.Signature: print( "[NOT IMPLEMENTED] Signature name in attribute specifications." ) else: position = Position.parse(name) raise DOMException( "Unknown name kind '{kind}' in attribute specification '{attr}' at {file}:{line}:{column}." .format( kind=nameKind.name, attr=attributeNode, file=position.Filename, line=position.Line, column=position.Column, )) entityClassToken = nodes.Get_Entity_Class(attributeNode) try: entityClass = _TOKEN_TRANSLATION[entityClassToken] except KeyError: position = Position.parse(attributeNode) raise DOMException( "Unknown token '{token}' in attribute specification for entity class '{entityClass}' at {file}:{line}:{column}." .format( token=entityClassToken.name, entityClass=attributeNode, file=position.Filename, line=position.Line, column=position.Column, )) expression = GetExpressionFromNode(nodes.Get_Expression(attributeNode)) return cls(attributeNode, names, attributeName, entityClass, expression)
def parse(cls, caseNode: Iir, label: str) -> "CaseStatement": from pyGHDL.dom._Utils import GetIirKindOfNode from pyGHDL.dom._Translate import ( GetExpressionFromNode, GetRangeFromNode, GetNameFromNode, ) expression = GetExpressionFromNode(nodes.Get_Expression(caseNode)) cases = [] choices = None alternative = nodes.Get_Case_Statement_Alternative_Chain(caseNode) cNode = alternative while alternative != nodes.Null_Iir: choiceKind = GetIirKindOfNode(alternative) sameAlternative = nodes.Get_Same_Alternative_Flag(alternative) if choiceKind in ( nodes.Iir_Kind.Choice_By_Name, nodes.Iir_Kind.Choice_By_Expression, ): choiceExpression = GetExpressionFromNode(nodes.Get_Choice_Expression(alternative)) choice = IndexedChoice(alternative, choiceExpression) if sameAlternative: choices.append(choice) alternative = nodes.Get_Chain(alternative) continue elif choiceKind is nodes.Iir_Kind.Choice_By_Range: choiceRange = nodes.Get_Choice_Range(alternative) choiceRangeKind = GetIirKindOfNode(choiceRange) if choiceRangeKind == nodes.Iir_Kind.Range_Expression: rng = GetRangeFromNode(choiceRange) elif choiceRangeKind in ( nodes.Iir_Kind.Attribute_Name, nodes.Iir_Kind.Parenthesis_Name, ): rng = GetNameFromNode(choiceRange) else: pos = Position.parse(alternative) raise DOMException( "Unknown choice range kind '{kind}' in case statement at line {line}.".format( kind=choiceRangeKind.name, line=pos.Line ) ) choice = RangedChoice(alternative, rng) if sameAlternative: choices.append(choice) alternative = nodes.Get_Chain(alternative) continue elif choiceKind is nodes.Iir_Kind.Choice_By_Others: if choices is not None: cases.append(Case.parse(alternative, choices, label)) choices = None cases.append(OthersCase.parse(alternative, label)) alternative = nodes.Get_Chain(alternative) cNode = alternative continue else: pos = Position.parse(alternative) raise DOMException( "Unknown choice kind '{kind}' in case statement at line {line}.".format( kind=choiceKind.name, line=pos.Line ) ) if choices is not None: cases.append(Case.parse(cNode, choices, label)) cNode = alternative choices = [ choice, ] alternative = nodes.Get_Chain(alternative) if choices is not None: cases.append(Case.parse(cNode, choices, label)) return cls(caseNode, label, expression, cases)
def parse(cls, node: Iir) -> "QualifiedExpressionAllocation": from pyGHDL.dom._Translate import GetExpressionFromNode expression = GetExpressionFromNode(nodes.Get_Expression(node)) return cls(node, expression)
def parse(cls, node: Iir) -> "ParenthesisExpression": from pyGHDL.dom._Translate import GetExpressionFromNode operand = GetExpressionFromNode(nodes.Get_Expression(node)) return cls(node, operand)