def check(self, input, node):
     if iirs.Get_Kind(node) == iirs.Iir_Kind.Block_Statement:
         hdr = iirs.Get_Block_Header(node)
         if hdr != thin.Null_Iir:
             if iirs.Get_Generic_Chain(hdr) != thin.Null_Iir:
                 self.error(Location.from_node(node),
                            "block cannot declare generics")
             if iirs.Get_Port_Chain(hdr) != thin.Null_Iir:
                 self.error(Location.from_node(node),
                            "block cannot declare ports")
         if iirs.Get_Guard_Decl(node) != thin.Null_Iir:
             self.error(Location.from_node(node),
                        "block cannot have an implicit GUARD signal")
Example #2
0
def declarations_iter(n):
    """Iterator on all declarations in n."""
    k = iirs.Get_Kind(n)
    if nodes_meta.Has_Generic_Chain(k):
        for n1 in chain_iter(iirs.Get_Generic_Chain(n)):
            yield n1
    if nodes_meta.Has_Port_Chain(k):
        for n1 in chain_iter(iirs.Get_Port_Chain(n)):
            yield n1
    if nodes_meta.Has_Interface_Declaration_Chain(k):
        for n1 in chain_iter(iirs.Get_Interface_Declaration_Chain(n)):
            yield n1
    if nodes_meta.Has_Declaration_Chain(k):
        for n1 in chain_iter(iirs.Get_Declaration_Chain(n)):
            k1 = iirs.Get_Kind(n1)
            if k1 in iirs.Iir_Kinds.Specification \
               or k1 == iirs.Iir_Kind.Use_Clause:
                # Not a declaration
                pass
            elif k1 == iirs.Iir_Kind.Signal_Attribute_Declaration:
                # Not a declaration
                pass
            elif k1 in [
                    iirs.Iir_Kind.Type_Declaration,
                    iirs.Iir_Kind.Anonymous_Type_Declaration
            ]:
                yield n1
                # Handle nested declarations: record elements, physical units,
                # enumeration literals...
                typ = iirs.Get_Type_Definition(n1)
                for n2 in declarations_iter(n1):
                    yield n2
            else:
                yield n1
                # There can be nested declarations (subprograms)
                for n2 in declarations_iter(n1):
                    yield n2
    if nodes_meta.Has_Concurrent_Statement_Chain(k):
        for n1 in chain_iter(iirs.Get_Concurrent_Statement_Chain(n)):
            for n2 in declarations_iter(n1):
                yield n2
    if nodes_meta.Has_Sequential_Statement_Chain(k):
        for n1 in chain_iter(iirs.Get_Sequential_Statement_Chain(n)):
            for n2 in declarations_iter(n1):
                yield n2
    if nodes_meta.Has_Parameter_Specification(k):
        yield iirs.Get_Parameter_Specification(n)
    if nodes_meta.Has_Generate_Statement_Body(k):
        for n1 in declarations_iter(iirs.Get_Generate_Statement_Body(n)):
            yield n1
    if nodes_meta.Has_Else_Clause(k):
        n1 = iirs.Get_Else_Clause(n)
        if n1 != Null_Iir:
            for n2 in declarations_iter(n1):
                yield n2
    if nodes_meta.Has_Generate_Else_Clause(k):
        n1 = iirs.Get_Generate_Else_Clause(n)
        if n1 != Null_Iir:
            for n2 in declarations_iter(n1):
                yield n2
    if nodes_meta.Has_Block_Header(k):
        n1 = iirs.Get_Block_Header(n)
        if n1 != Null_Iir:
            for n2 in declarations_iter(n1):
                yield n2
    # All these nodes are handled:
    if k in [
            iirs.Iir_Kind.Entity_Declaration,
            iirs.Iir_Kind.Architecture_Body,
            iirs.Iir_Kind.Package_Declaration,
            iirs.Iir_Kind.Package_Body,
            iirs.Iir_Kind.Process_Statement,
            iirs.Iir_Kind.Sensitized_Process_Statement,
            iirs.Iir_Kind.Concurrent_Assertion_Statement,
            iirs.Iir_Kind.Concurrent_Simple_Signal_Assignment,
            iirs.Iir_Kind.Concurrent_Selected_Signal_Assignment,
            iirs.Iir_Kind.Concurrent_Conditional_Signal_Assignment,
            iirs.Iir_Kind.Concurrent_Procedure_Call_Statement,
            iirs.Iir_Kind.Block_Statement,
            iirs.Iir_Kind.Block_Header,
            iirs.Iir_Kind.For_Generate_Statement,
            iirs.Iir_Kind.If_Generate_Statement,
            iirs.Iir_Kind.Generate_Statement_Body,
            iirs.Iir_Kind.Assertion_Statement,
            iirs.Iir_Kind.Wait_Statement,
            iirs.Iir_Kind.Simple_Signal_Assignment_Statement,
            iirs.Iir_Kind.Variable_Assignment_Statement,
            iirs.Iir_Kind.For_Loop_Statement,
            iirs.Iir_Kind.While_Loop_Statement,
            iirs.Iir_Kind.Case_Statement,
            iirs.Iir_Kind.Null_Statement,
            iirs.Iir_Kind.Exit_Statement,
            iirs.Iir_Kind.Next_Statement,
            iirs.Iir_Kind.Procedure_Call_Statement,
            iirs.Iir_Kind.Signal_Declaration,
            iirs.Iir_Kind.Constant_Declaration,
            iirs.Iir_Kind.Variable_Declaration,
            iirs.Iir_Kind.File_Declaration,
            iirs.Iir_Kind.Object_Alias_Declaration,
            iirs.Iir_Kind.Attribute_Declaration,
            iirs.Iir_Kind.Component_Declaration,
            iirs.Iir_Kind.Use_Clause,
            iirs.Iir_Kind.If_Statement,
            iirs.Iir_Kind.Elsif,
            iirs.Iir_Kind.Return_Statement,
            iirs.Iir_Kind.Type_Declaration,
            iirs.Iir_Kind.Anonymous_Type_Declaration,
            iirs.Iir_Kind.Subtype_Declaration,
            iirs.Iir_Kind.Function_Declaration,
            iirs.Iir_Kind.Function_Body,
            iirs.Iir_Kind.Procedure_Declaration,
            iirs.Iir_Kind.Procedure_Body,
            iirs.Iir_Kind.Component_Instantiation_Statement,
    ]:
        return
    assert False, "unknown node of kind {}".format(kind_image(k))