40 ''' This module contains the implementation of the Reference node.'''
43 from psyclone.core import AccessType, Signature, VariablesAccessInfo
52 Node representing a Reference Expression.
54 :param symbol: the symbol being referenced.
55 :type symbol: :py:class:`psyclone.psyir.symbols.Symbol`
56 :param kwargs: additional keyword arguments provided to the super class.
57 :type kwargs: unwrapped dict.
61 _children_valid_format =
"<LeafNode>"
62 _text_name =
"Reference"
65 def __init__(self, symbol, **kwargs):
66 super().__init__(**kwargs)
71 Checks equivalence of two References. References are considered
72 equivalent if they are the same type of Reference and their symbol
75 :param object other: the object to check equality to.
77 :returns: whether other is equal to self.
80 is_eq = super().
__eq__(other)
90 :returns: whether this reference is an array, False if it can not be
99 ''' Return the referenced symbol.
101 :returns: the referenced symbol.
102 :rtype: :py:class:`psyclone.psyir.symbols.Symbol`
108 def symbol(self, symbol):
110 :param symbol: the new symbol being referenced.
111 :type symbol: :py:class:`psyclone.psyir.symbols.Symbol`
113 :raises TypeError: if the symbol argument is not of type Symbol.
116 if not isinstance(symbol, Symbol):
118 f
"The {type(self).__name__} symbol setter expects a PSyIR "
119 f
"Symbol object but found '{type(symbol).__name__}'.")
124 ''' Return the name of the referenced symbol.
126 :returns: Name of the referenced symbol.
130 return self.
_symbol_symbol.name
133 ''' Create a text description of this node in the schedule, optionally
134 including control codes for colour.
136 :param bool colour: whether or not to include colour control codes.
138 :return: text description of this node.
141 return f
"{self.coloured_name(colour)}[name:'{self.name}']"
147 ''':returns: the Signature of this reference, and \
148 an empty list of lists as 'indices' since this reference does \
149 not represent an array access.
150 :rtype: tuple(:py:class:`psyclone.core.Signature`, list of \
156 '''Get all variable access information from this node, i.e.
157 it sets this variable to be read. It relies on
158 `get_signature_and_indices` and will correctly handle
161 :param var_accesses: VariablesAccessInfo instance that stores the \
162 information about variable accesses.
163 :type var_accesses: \
164 :py:class:`psyclone.core.VariablesAccessInfo`
169 var_accesses.options(
"USE-ORIGINAL-NAMES")
and \
176 for indices
in all_indices:
177 for index
in indices:
178 index.reference_accesses(var_accesses)
179 var_accesses.add_access(sig, AccessType.READ, self, all_indices)
184 :returns: the datatype of this reference.
185 :rtype: :py:class:`psyclone.psyir.symbols.DataType`
197 :returns: the previous reference to the same symbol.
198 :rtype: Optional[:py:class:`psyclone.psyir.nodes.Node`]
205 routine = self.
ancestorancestor(Routine)
209 routine = self.
rootroot
212 all_accesses = var_access[signature].all_accesses
215 for i, access
in enumerate(all_accesses):
216 if access.node
is self:
221 return all_accesses[index-1].node
226 :returns: the next reference to the same symbol.
227 :rtype: Optional[:py:class:`psyclone.psyir.nodes.Node`]
234 routine = self.
ancestorancestor(Routine)
238 routine = self.
rootroot
241 all_accesses = var_access[signature].all_accesses
242 index = len(all_accesses)
244 for i, access
in enumerate(all_accesses):
245 if access.node
is self:
249 if len(all_accesses) > index+1:
250 return all_accesses[index+1].node
255 __all__ = [
'Reference']
def node_str(self, colour=True)
def ancestor(self, my_type, excluding=None, include_self=False, limit=None, shared_with=None)
def reference_accesses(self, var_accesses)
def previous_access(self)
def node_str(self, colour=True)
def get_signature_and_indices(self)