aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom/_Translate.py
blob: 502a94ad358017db307f20233e8d4c768582a5b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# =============================================================================
#               ____ _   _ ____  _          _
#  _ __  _   _ / ___| | | |  _ \| |      __| | ___  _ __ ___
# | '_ \| | | | |  _| |_| | | | | |     / _` |/ _ \| '_ ` _ \
# | |_) | |_| | |_| |  _  | |_| | |___ | (_| | (_) | | | | | |
# | .__/ \__, |\____|_| |_|____/|_____(_)__,_|\___/|_| |_| |_|
# |_|    |___/
# =============================================================================
# Authors:
#   Patrick Lehmann
#
# Package module:   DOM: Interface items (e.g. generic or port)
#
# License:
# ============================================================================
#  Copyright (C) 2019-2021 Tristan Gingold
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <gnu.org/licenses>.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
from typing import List, Generator

from pydecor import export

from pyGHDL.dom import Position, DOMException
from pyGHDL.dom.Object import Variable
from pyVHDLModel.VHDLModel import (
    Constraint,
    Direction,
    Expression,
    SubTypeOrSymbol,
    BaseType,
    GenericInterfaceItem,
    PortInterfaceItem,
    ParameterInterfaceItem,
    ModelEntity,
    Name,
)

from pyGHDL.libghdl import utils
from pyGHDL.libghdl._types import Iir
from pyGHDL.libghdl.vhdl import nodes
from pyGHDL.dom._Utils import (
    GetNameOfNode,
    GetIirKindOfNode,
)
from pyGHDL.dom.Names import (
    SimpleName,
    SelectedName,
    AttributeName,
    ParenthesisName,
    AllName,
)
from pyGHDL.dom.Symbol import (
    SimpleObjectOrFunctionCallSymbol,
    SimpleSubTypeSymbol,
    ConstrainedCompositeSubTypeSymbol,
    IndexedObjectOrFunctionCallSymbol,
    ConstrainedScalarSubTypeSymbol,
)
from pyGHDL.dom.Type import (
    IntegerType,
    SubType,
    ArrayType,
    RecordType,
    EnumeratedType,
    AccessType,
    ProtectedType,
    ProtectedTypeBody,
    FileType,
    PhysicalType,
)
from pyGHDL.dom.Range import Range
from pyGHDL.dom.Literal import (
    IntegerLiteral,
    CharacterLiteral,
    FloatingPointLiteral,
    StringLiteral,
    PhysicalIntegerLiteral,
    PhysicalFloatingLiteral,
    NullLiteral,
)
from pyGHDL.dom.Expression import (
    SubtractionExpression,
    AdditionExpression,
    MultiplyExpression,
    DivisionExpression,
    InverseExpression,
    ExponentiationExpression,
    Aggregate,
    NegationExpression,
    ParenthesisExpression,
    ConcatenationExpression,
    QualifiedExpression,
    ModuloExpression,
    RemainderExpression,
    AndExpression,
    NandExpression,
    OrExpression,
    NorExpression,
    XorExpression,
    XnorExpression,
    EqualExpression,
    UnequalExpression,
    LessThanExpression,
    GreaterThanExpression,
    GreaterEqualExpression,
    LessEqualExpression,
    ShiftLeftLogicExpression,
    ShiftRightLogicExpression,
    ShiftLeftArithmeticExpression,
    ShiftRightArithmeticExpression,
    RotateLeftExpression,
    RotateRightExpression,
    RangeExpression,
)
from pyGHDL.dom.Subprogram import Function, Procedure
from pyGHDL.dom.Misc import Alias


__all__ = []


@export
def GetNameFromNode(node: Iir) -> Name:
    kind = GetIirKindOfNode(node)
    if kind == nodes.Iir_Kind.Simple_Name:
        name = GetNameOfNode(node)
        return SimpleName(node, name)
    elif kind == nodes.Iir_Kind.Selected_Name:
        name = GetNameOfNode(node)
        prefixName = GetNameFromNode(nodes.Get_Prefix(node))
        return SelectedName(node, name, prefixName)
    elif kind == nodes.Iir_Kind.Attribute_Name:
        name = GetNameOfNode(node)
        prefixName = GetNameFromNode(nodes.Get_Prefix(node))
        return AttributeName(node, name, prefixName)
    elif kind == nodes.Iir_Kind.Parenthesis_Name:
        prefixName = GetNameFromNode(nodes.Get_Prefix(node))
        associations = GetAssociations(node)

        return ParenthesisName(node, prefixName, associations)
    elif kind == nodes.Iir_Kind.Selected_By_All_Name:
        prefixName = GetNameFromNode(nodes.Get_Prefix(node))
        return AllName(node, prefixName)
    else:
        raise DOMException("Unknown name kind '{kind}'".format(kind=kind.name))


def GetAssociations(node: Iir) -> List:
    associations = []
    for item in utils.chain_iter(nodes.Get_Association_Chain(node)):
        kind = GetIirKindOfNode(item)

        if kind == nodes.Iir_Kind.Association_Element_By_Expression:
            actual = nodes.Get_Actual(item)
            expr = GetExpressionFromNode(actual)

            associations.append(expr)
        else:
            raise DOMException(
                "Unknown association kind '{kindName}'({kind}) in array index/slice or function call '{node}'.".format(
                    kind=kind, kindName=kind.name, node=node
                )
            )

    return associations


@export
def GetArrayConstraintsFromSubtypeIndication(
    subTypeIndication: Iir,
) -> List[Constraint]:
    constraints = []
    for constraint in utils.flist_iter(
        nodes.Get_Index_Constraint_List(subTypeIndication)
    ):
        constraintKind = GetIirKindOfNode(constraint)
        if constraintKind == nodes.Iir_Kind.Range_Expression:
            constraints.append(RangeExpression.parse(constraint))
        elif constraintKind in (
            nodes.Iir_Kind.Simple_Name,
            nodes.Iir_Kind.Parenthesis_Name,
            nodes.Iir_Kind.Selected_Name,
            nodes.Iir_Kind.Attribute_Name,
        ):
            constraints.append(GetNameFromNode(constraint))
        else:
            position = Position.parse(constraint)
            raise DOMException(
                "Unknown constraint kind '{kind}' for constraint '{constraint}' in subtype indication '{indication}' at {file}:{line}:{column}.".format(
                    kind=constraintKind.name,
                    constraint=constraint,
                    indication=subTypeIndication,
                    file=position.Filename,
                    line=position.Line,
                    column=position.Column,
                )
            )

    return constraints


@export
def GetTypeFromNode(node: Iir) -> BaseType:
    typeName = GetNameOfNode(node)
    typeDefinition = nodes.Get_Type_Definition(node)

    kind = GetIirKindOfNode(typeDefinition)
    if kind == nodes.Iir_Kind.Range_Expression:
        r = GetRangeFromNode(typeDefinition)

        return IntegerType(node, typeName, r)
    elif kind == nodes.Iir_Kind.Physical_Type_Definition:
        return PhysicalType.parse(typeName, typeDefinition)
    elif kind == nodes.Iir_Kind.Enumeration_Type_Definition:
        return EnumeratedType.parse(typeName, typeDefinition)
    elif kind == nodes.Iir_Kind.Array_Type_Definition:
        return ArrayType.parse(typeName, typeDefinition)
    elif kind == nodes.Iir_Kind.Array_Subtype_Definition:
        print("[NOT IMPLEMENTED] Array_Subtype_Definition")

        return ArrayType(typeDefinition, "????", [], None)
    elif kind == nodes.Iir_Kind.Record_Type_Definition:
        return RecordType.parse(typeName, typeDefinition)
    elif kind == nodes.Iir_Kind.Access_Type_Definition:
        return AccessType.parse(typeName, typeDefinition)
    elif kind == nodes.Iir_Kind.File_Type_Definition:
        return FileType.parse(typeName, typeDefinition)
    elif kind == nodes.Iir_Kind.Protected_Type_Declaration:
        return ProtectedType.parse(typeName, typeDefinition)
    else:
        position = Position.parse(typeDefinition)
        raise DOMException(
            "Unknown type definition kind '{kindName}'({kind}) for type '{name}' at {file}:{line}:{column}.".format(
                kind=kind,
                kindName=kind.name,
                name=typeName,
                file=position.Filename,
                line=position.Line,
                column=position.Column,
            )
        )


@export
def GetSubTypeIndicationFromNode(node: Iir, entity: str, name: str) -> SubTypeOrSymbol:
    subTypeIndicationNode = nodes.Get_Subtype_Indication(node)
    #     if subTypeIndicationNode is nodes.Null_Iir:
    #         return None
    return GetSubTypeIndicationFromIndicationNode(subTypeIndicationNode, entity, name)


@export
def GetSubTypeIndicationFromIndicationNode(
    subTypeIndicationNode: Iir, entity: str, name: str
) -> SubTypeOrSymbol:
    if subTypeIndicationNode is nodes.Null_Iir:
        print(
            "[NOT IMPLEMENTED]: Unhandled multiple declarations for {entity} '{name}'.".format(
                entity=entity, name=name
            )
        )
        return None
    kind = GetIirKindOfNode(subTypeIndicationNode)
    if kind in (
        nodes.Iir_Kind.Simple_Name,
        nodes.Iir_Kind.Selected_Name,
        nodes.Iir_Kind.Attribute_Name,
    ):
        return GetSimpleTypeFromNode(subTypeIndicationNode)
    elif kind == nodes.Iir_Kind.Subtype_Definition:
        return GetScalarConstrainedSubTypeFromNode(subTypeIndicationNode)
    elif kind == nodes.Iir_Kind.Array_Subtype_Definition:
        return GetCompositeConstrainedSubTypeFromNode(subTypeIndicationNode)
    else:
        raise DOMException(
            "Unknown kind '{kind}' for an subtype indication in a {entity} of `{name}`.".format(
                kind=kind.name, entity=entity, name=name
            )
        )


@export
def GetSimpleTypeFromNode(subTypeIndicationNode: Iir) -> SimpleSubTypeSymbol:
    subTypeName = GetNameFromNode(subTypeIndicationNode)
    return SimpleSubTypeSymbol(subTypeIndicationNode, subTypeName)


@export
def GetScalarConstrainedSubTypeFromNode(
    subTypeIndicationNode: Iir,
) -> ConstrainedScalarSubTypeSymbol:
    typeMark = nodes.Get_Subtype_Type_Mark(subTypeIndicationNode)
    typeMarkName = GetNameOfNode(typeMark)
    rangeConstraint = nodes.Get_Range_Constraint(subTypeIndicationNode)
    r = GetRangeFromNode(rangeConstraint)
    return ConstrainedScalarSubTypeSymbol(subTypeIndicationNode, typeMarkName, r)


@export
def GetCompositeConstrainedSubTypeFromNode(
    subTypeIndicationNode: Iir,
) -> ConstrainedCompositeSubTypeSymbol:
    typeMark = nodes.Get_Subtype_Type_Mark(subTypeIndicationNode)
    typeMarkName = GetNameOfNode(typeMark)

    constraints = GetArrayConstraintsFromSubtypeIndication(subTypeIndicationNode)
    return ConstrainedCompositeSubTypeSymbol(
        subTypeIndicationNode, typeMarkName, constraints
    )


@export
def GetSubTypeFromNode(subTypeNode: Iir) -> SubTypeOrSymbol:
    subTypeName = GetNameOfNode(subTypeNode)

    return SubType(subTypeNode, subTypeName)


@export
def GetRangeFromNode(node: Iir) -> Range:
    direction = nodes.Get_Direction(node)
    leftBound = nodes.Get_Left_Limit_Expr(node)
    rightBound = nodes.Get_Right_Limit_Expr(node)

    return Range(
        GetExpressionFromNode(leftBound),
        GetExpressionFromNode(rightBound),
        Direction.DownTo if direction else Direction.To,
    )


__EXPRESSION_TRANSLATION = {
    nodes.Iir_Kind.Simple_Name: SimpleObjectOrFunctionCallSymbol,
    nodes.Iir_Kind.Selected_Name: IndexedObjectOrFunctionCallSymbol,
    nodes.Iir_Kind.Attribute_Name: IndexedObjectOrFunctionCallSymbol,
    nodes.Iir_Kind.Parenthesis_Name: IndexedObjectOrFunctionCallSymbol,
    nodes.Iir_Kind.Null_Literal: NullLiteral,
    nodes.Iir_Kind.Integer_Literal: IntegerLiteral,
    nodes.Iir_Kind.Floating_Point_Literal: FloatingPointLiteral,
    nodes.Iir_Kind.Physical_Int_Literal: PhysicalIntegerLiteral,
    nodes.Iir_Kind.Physical_Fp_Literal: PhysicalFloatingLiteral,
    nodes.Iir_Kind.Character_Literal: CharacterLiteral,
    nodes.Iir_Kind.String_Literal8: StringLiteral,
    nodes.Iir_Kind.Negation_Operator: NegationExpression,
    nodes.Iir_Kind.Range_Expression: RangeExpression,
    nodes.Iir_Kind.Addition_Operator: AdditionExpression,
    nodes.Iir_Kind.Concatenation_Operator: ConcatenationExpression,
    nodes.Iir_Kind.Not_Operator: InverseExpression,
    nodes.Iir_Kind.Parenthesis_Expression: ParenthesisExpression,
    nodes.Iir_Kind.Substraction_Operator: SubtractionExpression,
    nodes.Iir_Kind.Multiplication_Operator: MultiplyExpression,
    nodes.Iir_Kind.Division_Operator: DivisionExpression,
    nodes.Iir_Kind.Modulus_Operator: ModuloExpression,
    nodes.Iir_Kind.Remainder_Operator: RemainderExpression,
    nodes.Iir_Kind.Exponentiation_Operator: ExponentiationExpression,
    nodes.Iir_Kind.And_Operator: AndExpression,
    nodes.Iir_Kind.Nand_Operator: NandExpression,
    nodes.Iir_Kind.Or_Operator: OrExpression,
    nodes.Iir_Kind.Nor_Operator: NorExpression,
    nodes.Iir_Kind.Xor_Operator: XorExpression,
    nodes.Iir_Kind.Xnor_Operator: XnorExpression,
    nodes.Iir_Kind.Equality_Operator: EqualExpression,
    nodes.Iir_Kind.Inequality_Operator: UnequalExpression,
    nodes.Iir_Kind.Less_Than_Operator: LessThanExpression,
    nodes.Iir_Kind.Less_Than_Or_Equal_Operator: LessEqualExpression,
    nodes.Iir_Kind.Greater_Than_Operator: GreaterThanExpression,
    nodes.Iir_Kind.Greater_Than_Or_Equal_Operator: GreaterEqualExpression,
    nodes.Iir_Kind.Sll_Operator: ShiftLeftLogicExpression,
    nodes.Iir_Kind.Srl_Operator: ShiftRightLogicExpression,
    nodes.Iir_Kind.Sla_Operator: ShiftLeftArithmeticExpression,
    nodes.Iir_Kind.Sra_Operator: ShiftRightArithmeticExpression,
    nodes.Iir_Kind.Rol_Operator: RotateLeftExpression,
    nodes.Iir_Kind.Ror_Operator: RotateRightExpression,
    nodes.Iir_Kind.Qualified_Expression: QualifiedExpression,
    nodes.Iir_Kind.Aggregate: Aggregate,
}


@export
def GetExpressionFromNode(node: Iir) -> Expression:
    kind = GetIirKindOfNode(node)

    try:
        cls = __EXPRESSION_TRANSLATION[kind]
    except KeyError:
        position = Position.parse(node)
        raise DOMException(
            "Unknown expression kind '{kindName}'({kind}) in expression '{expr}' at {file}:{line}:{column}.".format(
                kind=kind,
                kindName=kind.name,
                expr=node,
                file=position.Filename,
                line=position.Line,
                column=position.Column,
            )
        )

    return cls.parse(node)


@export
def GetGenericsFromChainedNodes(
    nodeChain: Iir,
) -> Generator[GenericInterfaceItem, None, None]:
    for generic in utils.chain_iter(nodeChain):
        kind = GetIirKindOfNode(generic)
        if kind == nodes.Iir_Kind.Interface_Constant_Declaration:
            from pyGHDL.dom.InterfaceItem import GenericConstantInterfaceItem

            yield GenericConstantInterfaceItem.parse(generic)
        elif kind == nodes.Iir_Kind.Interface_Type_Declaration:
            print("[NOT IMPLEMENTED] generic type")
        elif kind == nodes.Iir_Kind.Interface_Package_Declaration:
            print("[NOT IMPLEMENTED] generic package")
        elif kind == nodes.Iir_Kind.Interface_Procedure_Declaration:
            print("[NOT IMPLEMENTED] generic procedure")
        elif kind == nodes.Iir_Kind.Interface_Function_Declaration:
            print("[NOT IMPLEMENTED] generic function")
        else:
            position = Position.parse(generic)
            raise DOMException(
                "Unknown generic kind '{kindName}'({kind}) in generic '{generic}' at {file}:{line}:{column}.".format(
                    kind=kind,
                    kindName=kind.name,
                    generic=generic,
                    file=position.Filename,
                    line=position.Line,
                    column=position.Column,
                )
            )


@export
def GetPortsFromChainedNodes(
    nodeChain: Iir,
) -> Generator[PortInterfaceItem, None, None]:
    for port in utils.chain_iter(nodeChain):
        kind = GetIirKindOfNode(port)
        if kind == nodes.Iir_Kind.Interface_Signal_Declaration:
            from pyGHDL.dom.InterfaceItem import PortSignalInterfaceItem

            portSignal = PortSignalInterfaceItem.parse(port)

            yield portSignal
        else:
            position = Position.parse(port)
            raise DOMException(
                "Unknown port kind '{kindName}'({kind}) in port '{port}' at {file}:{line}:{column}.".format(
                    kind=kind,
                    kindName=kind.name,
                    port=port,
                    file=position.Filename,
                    line=position.Line,
                    column=position.Column,
                )
            )


@export
def GetParameterFromChainedNodes(
    nodeChain: Iir,
) -> Generator[ParameterInterfaceItem, None, None]:
    for parameter in utils.chain_iter(nodeChain):
        kind = GetIirKindOfNode(parameter)
        if kind == nodes.Iir_Kind.Interface_Constant_Declaration:
            from pyGHDL.dom.InterfaceItem import ParameterConstantInterfaceItem

            yield ParameterConstantInterfaceItem.parse(parameter)
        elif kind == nodes.Iir_Kind.Interface_Variable_Declaration:
            from pyGHDL.dom.InterfaceItem import ParameterVariableInterfaceItem

            yield ParameterVariableInterfaceItem.parse(parameter)
        elif kind == nodes.Iir_Kind.Interface_Signal_Declaration:
            from pyGHDL.dom.InterfaceItem import ParameterSignalInterfaceItem

            yield ParameterSignalInterfaceItem.parse(parameter)
        elif kind == nodes.Iir_Kind.Interface_File_Declaration:
            from pyGHDL.dom.InterfaceItem import ParameterFileInterfaceItem

            yield ParameterFileInterfaceItem.parse(parameter)
        else:
            position = Position.parse(parameter)
            raise DOMException(
                "Unknown parameter kind '{kindName}'({kind}) in parameter '{param}' at {file}:{line}:{column}.".format(
                    kind=kind,
                    kindName=kind.name,
                    param=parameter,
                    file=position.Filename,
                    line=position.Line,
                    column=position.Column,
                )
            )


def GetDeclaredItemsFromChainedNodes(
    nodeChain: Iir, entity: str, name: str
) -> Generator[ModelEntity, None, None]:
    for item in utils.chain_iter(nodeChain):
        kind = GetIirKindOfNode(item)
        if kind == nodes.Iir_Kind.Constant_Declaration:
            from pyGHDL.dom.Object import Constant

            yield Constant.parse(item)

        elif kind == nodes.Iir_Kind.Variable_Declaration:
            from pyGHDL.dom.Object import SharedVariable

            if nodes.Get_Shared_Flag(item):
                yield SharedVariable.parse(item)
            else:
                yield Variable.parse(item)
        #                raise DOMException("Found non-shared variable.")
        elif kind == nodes.Iir_Kind.Signal_Declaration:
            from pyGHDL.dom.Object import Signal

            yield Signal.parse(item)
        elif kind == nodes.Iir_Kind.File_Declaration:
            from pyGHDL.dom.Object import File

            yield File.parse(item)
        elif kind == nodes.Iir_Kind.Type_Declaration:
            yield GetTypeFromNode(item)
        elif kind == nodes.Iir_Kind.Anonymous_Type_Declaration:
            yield GetTypeFromNode(item)
        elif kind == nodes.Iir_Kind.Subtype_Declaration:
            yield GetSubTypeFromNode(item)
        elif kind == nodes.Iir_Kind.Function_Declaration:
            yield Function.parse(item)
        elif kind == nodes.Iir_Kind.Function_Body:
            #                procedureName = NodeToName(item)
            print("found function body '{name}'".format(name="????"))
        elif kind == nodes.Iir_Kind.Procedure_Declaration:
            yield Procedure.parse(item)
        elif kind == nodes.Iir_Kind.Procedure_Body:
            #                procedureName = NodeToName(item)
            print("found procedure body '{name}'".format(name="????"))
        elif kind == nodes.Iir_Kind.Protected_Type_Body:
            yield ProtectedTypeBody.parse(item)
        elif kind == nodes.Iir_Kind.Object_Alias_Declaration:
            yield GetAliasFromNode(item)
        elif kind == nodes.Iir_Kind.Component_Declaration:
            from pyGHDL.dom.DesignUnit import Component

            yield Component.parse(item)
        elif kind == nodes.Iir_Kind.Attribute_Declaration:
            from pyGHDL.dom.Attribute import Attribute

            yield Attribute.parse(item)
        elif kind == nodes.Iir_Kind.Attribute_Specification:
            from pyGHDL.dom.Attribute import AttributeSpecification

            yield AttributeSpecification.parse(item)
        elif kind == nodes.Iir_Kind.Use_Clause:
            from pyGHDL.dom.DesignUnit import UseClause

            yield UseClause.parse(item)
        elif kind == nodes.Iir_Kind.Package_Instantiation_Declaration:
            from pyGHDL.dom.DesignUnit import PackageInstantiation

            yield PackageInstantiation.parse(item)
        elif kind == nodes.Iir_Kind.Configuration_Specification:
            print(
                "[NOT IMPLEMENTED] Configuration specification in {name}".format(
                    name=name
                )
            )
        else:
            position = Position.parse(item)
            raise DOMException(
                "Unknown declared item kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}.".format(
                    kind=kind.name,
                    entity=entity,
                    name=name,
                    file=position.Filename,
                    line=position.Line,
                    column=position.Column,
                )
            )


def GetAliasFromNode(aliasNode: Iir):
    aliasName = GetNameOfNode(aliasNode)

    return Alias(aliasNode, aliasName)