39 ''' This module contains the CodeBlock node implementation.'''
42 from fparser.two
import Fortran2003
43 from fparser.two.utils
import walk
49 '''Node representing some generic Fortran code that PSyclone does not
50 attempt to manipulate. As such it is a leaf in the PSyIR and therefore
53 :param fp2_nodes: list of fparser2 AST nodes representing the Fortran \
54 code constituting the code block.
55 :type fp2_nodes: list of :py:class:`fparser.two.utils.Base`
56 :param structure: argument indicating whether this code block is a \
57 statement or an expression.
58 :type structure: :py:class:`psyclone.psyir.nodes.CodeBlock.Structure`
59 :param parent: the parent node of this code block in the PSyIR.
60 :type parent: :py:class:`psyclone.psyir.nodes.Node`
61 :param annotations: tags that provide additional information about \
62 the node. The node should still be functionally correct when \
64 :type annotations: list of str or NoneType
68 _children_valid_format =
"<LeafNode>"
69 _text_name =
"CodeBlock"
74 valid_annotations = (
"psy-data-start")
78 Enumeration that captures the structure of the code block which
79 may be required when processing.
88 def __init__(self, fp2_nodes, structure, parent=None, annotations=None):
89 super(CodeBlock, self).__init__(parent=parent, annotations=annotations)
94 self._fp2_nodes = fp2_nodes[:]
97 self.ast = self._fp2_nodes[0]
98 self.ast_end = self._fp2_nodes[-1]
103 self._structure = structure
107 Checks whether two nodes are equal. Two CodeBlock nodes are equal
108 if they are the same type, their ast_nodes lists are equal (which
109 means the same instance) and have the same structure.
111 :param object other: the object to check equality to.
113 :returns: whether other is equal to self.
116 is_eq = super().
__eq__(other)
125 :returns: whether this code block is a statement or an expression.
126 :rtype: :py:class:`psyclone.psyir.nodes.CodeBlock.Structure`
132 def get_ast_nodes(self):
134 :returns: the list of nodes associated with this code block in \
136 :rtype: list of subclass of \
137 `:py:classfparser.two.Fortran2003.Base`
143 ''' Create a text description of this node in the schedule, optionally
144 including control codes for colour.
146 :param bool colour: whether or not to include control codes for colour.
148 :return: text description of this node.
152 "[" + str(list(map(type, self.
_fp2_nodes_fp2_nodes))) +
"]"
156 :returns: the list of symbol names used inside the CodeBock.
160 return [node.string
for node
in walk(parse_tree, Fortran2003.Name)]
163 return f
"CodeBlock[{len(self._fp2_nodes)} nodes]"
def node_str(self, colour=True)
def get_symbol_names(self)
def coloured_name(self, colour=True)
def walk(self, my_type, stop_type=None, depth=None)