39 ''' This module contains the Container node implementation.'''
50 '''Node representing a set of Routine and/or Container nodes, as well
51 as a name and a SymbolTable. This construct can be used to scope
52 symbols of variables, Routine names and Container names. In
53 Fortran a container would naturally represent a module or a
56 :param str name: the name of the container.
57 :param parent: optional parent node of this Container in the PSyIR.
58 :type parent: :py:class:`psyclone.psyir.nodes.Node`
59 :param symbol_table: initialise the node with a given symbol table.
60 :type symbol_table: :py:class:`psyclone.psyir.symbols.SymbolTable` or \
65 _children_valid_format =
"[Container | Routine | CodeBlock]*"
66 _text_name =
"Container"
69 def __init__(self, name, **kwargs):
70 super().__init__(**kwargs)
71 self.
_name_name = name
74 '''Checks the equality of this Container with other. Containers are
75 equal if they are the same type, and have the same name.
77 :param object other: the object to check equality to.
79 :returns: whether other is equal to self.
82 is_eq = super().
__eq__(other)
87 def _validate_child(position, child):
89 :param int position: the position to be validated.
90 :param child: a child to be validated.
91 :type child: :py:class:`psyclone.psyir.nodes.Node`
93 :return: whether the given child and position are valid for this node.
98 return isinstance(child, (Container, Routine, CodeBlock))
101 def create(cls, name, symbol_table, children):
102 '''Create a Container instance given a name, a symbol table and a
105 :param str name: the name of the Container.
106 :param symbol_table: the symbol table associated with this \
108 :type symbol_table: :py:class:`psyclone.psyir.symbols.SymbolTable`
109 :param children: a list of PSyIR nodes contained in the \
110 Container. These must be Containers or Routines.
111 :type children: list of :py:class:`psyclone.psyir.nodes.Container` \
112 or :py:class:`psyclone.psyir.nodes.Routine`
114 :returns: an instance of `cls`.
115 :rtype: :py:class:`psyclone.psyir.nodes.Container` or subclass
118 :raises GenerationError: if the arguments to the create method \
119 are not of the expected type.
122 if not isinstance(name, str):
124 f
"name argument in create method of Container class "
125 f
"should be a string but found '{type(name).__name__}'.")
126 if not isinstance(symbol_table, SymbolTable):
128 f
"symbol_table argument in create method of Container class "
129 f
"should be a SymbolTable but found "
130 f
"'{type(symbol_table).__name__}'.")
131 if not isinstance(children, list):
133 f
"children argument in create method of Container class "
134 f
"should be a list but found '{type(children).__name__}'.")
136 container = cls(name, symbol_table=symbol_table)
137 container.children = children
143 :returns: name of the container.
147 return self.
_name_name
150 def name(self, new_name):
151 '''Sets a new name for the container.
153 :param str new_name: new name for the container.
156 self.
_name_name = new_name
160 Returns the name of this node with appropriate control codes
161 to generate coloured output in a terminal that supports it.
163 :param bool colour: whether or not to include colour control codes.
165 :returns: description of this node, possibly coloured.
168 return self.
coloured_namecoloured_name(colour) + f
"[{self.name}]"
171 return f
"Container[{self.name}]\n"
174 '''Returns the PSyIR for the routine with the given name, or None
175 if a routine with this name does not exist.
177 :param str name: name of the routine to find.
179 :returns: the PSyIR Routine instance of the subroutine, or None if
180 there is no routine with that name in this container.
181 :rtype: Union[None, psyclone.psyir.nodes.Routine]
185 for routine
in self.
walkwalk(Routine):
186 if routine.name.lower() == name:
192 __all__ = [
'Container']
def node_str(self, colour=True)
def create(cls, name, symbol_table, children)
def get_routine_psyir(self, name)
def coloured_name(self, colour=True)
def walk(self, my_type, stop_type=None, depth=None)