Reference Guide  2.5.0
psyclone.psyir.symbols.symbol.Symbol Class Reference
Inheritance diagram for psyclone.psyir.symbols.symbol.Symbol:

Classes

class  Visibility
 

Public Member Functions

def __init__ (self, name, visibility=DEFAULT_VISIBILITY, interface=None)
 
def copy (self)
 
def copy_properties (self, symbol_in)
 
def specialise (self, subclass, **kwargs)
 
def get_external_symbol (self)
 
def resolve_type (self)
 
def name (self)
 
def visibility (self)
 
def visibility (self, value)
 
def interface (self)
 
def interface (self, value)
 
def is_automatic (self)
 
def is_modulevar (self)
 
def is_import (self)
 
def is_argument (self)
 
def is_commonblock (self)
 
def is_static (self)
 
def is_unresolved (self)
 
def is_unknown_interface (self)
 
def find_symbol_table (self, node)
 
def __str__ (self)
 
def is_array (self)
 
def is_array_access (self, index_variable=None, access_info=None)
 

Public Attributes

 interface
 
 visibility
 

Static Public Attributes

 DEFAULT_VISIBILITY = Visibility.PUBLIC
 

Detailed Description

Generic Symbol item for the Symbol Table and PSyIR References.
It has an immutable name label because it must always match with the
key in the SymbolTable. If the symbol is private then it is only visible
to those nodes that are descendants of the Node to which its containing
Symbol Table belongs.

:param str name: name of the symbol.
:param visibility: the visibility of the symbol.
:type visibility: :py:class:`psyclone.psyir.symbols.Symbol.Visibility`
:param interface: optional object describing the interface to this \
    symbol (i.e. whether it is passed as a routine argument or \
    accessed in some other way). Defaults to \
    :py:class:`psyclone.psyir.symbols.AutomaticInterface`
:type interface: Optional[ \
    :py:class:`psyclone.psyir.symbols.symbol.SymbolInterface`]

:raises TypeError: if the name is not a str.

Definition at line 62 of file symbol.py.

Member Function Documentation

◆ copy()

def psyclone.psyir.symbols.symbol.Symbol.copy (   self)
Create and return a copy of this object. Any references to the
original will not be affected so the copy will not be referred
to by any other object.

:returns: A symbol object with the same properties as this \
          symbol object.
:rtype: :py:class:`psyclone.psyir.symbols.Symbol`

Reimplemented in psyclone.psyir.symbols.typed_symbol.TypedSymbol, psyclone.psyir.symbols.generic_interface_symbol.GenericInterfaceSymbol, psyclone.psyir.symbols.datasymbol.DataSymbol, psyclone.psyir.symbols.data_type_symbol.DataTypeSymbol, and psyclone.psyir.symbols.containersymbol.ContainerSymbol.

Definition at line 137 of file symbol.py.

137  def copy(self):
138  '''Create and return a copy of this object. Any references to the
139  original will not be affected so the copy will not be referred
140  to by any other object.
141 
142  :returns: A symbol object with the same properties as this \
143  symbol object.
144  :rtype: :py:class:`psyclone.psyir.symbols.Symbol`
145 
146  '''
147  # The constructors for all Symbol-based classes have 'name' as the
148  # first positional argument.
149  return type(self)(self.name, visibility=self.visibility,
150  interface=self.interface.copy())
151 

References psyclone.psyir.symbols.datasymbol.DataSymbol.interface, psyclone.psyir.symbols.symbol.Symbol.interface, psyclone.psyir.symbols.typed_symbol.TypedSymbol.interface, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.GridArg.name, psyclone.domain.gocean.transformations.gocean_const_loop_bounds_trans.GOConstLoopBoundsTrans.name(), psyclone.domain.gocean.transformations.gocean_move_iteration_boundaries_inside_kernel_trans.GOMoveIterationBoundariesInsideKernelTrans.name(), psyclone.domain.gocean.transformations.gocean_opencl_trans.GOOpenCLTrans.name(), psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata.name, psyclone.domain.nemo.transformations.create_nemo_invoke_schedule_trans.CreateNemoInvokeScheduleTrans.name(), psyclone.domain.nemo.transformations.create_nemo_psy_trans.CreateNemoPSyTrans.name(), psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans.name(), psyclone.domain.nemo.transformations.nemo_arrayrange2loop_trans.NemoArrayRange2LoopTrans.name(), psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans.name(), psyclone.dynamo0p3.DynamoPSy.name(), psyclone.expression.FunctionVar.name, psyclone.expression.NamedArg.name(), psyclone.gocean1p0.GOKernelGridArgument.name(), psyclone.gocean1p0.GOStencil.name(), psyclone.parse.algorithm.FileInfo.name(), psyclone.parse.algorithm.InvokeCall.name(), psyclone.parse.kernel.KernelProcedure.name(), psyclone.parse.kernel.KernelType.name(), psyclone.parse.module_info.ModuleInfo.name(), psyclone.psyad.transformations.assignment_trans.AssignmentTrans.name(), psyclone.psyGen.PSy.name(), psyclone.psyGen.Invoke.name(), psyclone.psyGen.Kern.name(), psyclone.psyGen.CodedKern.name, psyclone.psyGen.Argument.name(), psyclone.psyGen.Transformation.name(), psyclone.psyGen.DummyTransformation.name(), psyclone.psyir.nodes.container.Container.name, psyclone.psyir.nodes.member.Member.name, psyclone.psyir.nodes.reference.Reference.name(), psyclone.psyir.nodes.routine.Routine.name, psyclone.psyir.symbols.symbol.Symbol.name(), psyclone.psyir.transformations.allarrayaccess2loop_trans.AllArrayAccess2LoopTrans.name(), psyclone.psyir.transformations.arrayrange2loop_trans.ArrayRange2LoopTrans.name(), psyclone.psyir.transformations.fold_conditional_return_expressions_trans.FoldConditionalReturnExpressionsTrans.name(), psyclone.psyir.transformations.loop_trans.LoopTrans.name(), psyclone.psyir.transformations.omp_task_trans.OMPTaskTrans.name(), psyclone.psyir.transformations.psy_data_trans.PSyDataTrans.name(), psyclone.transformations.OMPSingleTrans.name(), psyclone.transformations.OMPMasterTrans.name(), psyclone.transformations.OMPParallelTrans.name(), psyclone.transformations.MoveTrans.name(), psyclone.transformations.Dynamo0p3AsyncHaloExchangeTrans.name(), psyclone.transformations.Dynamo0p3KernelConstTrans.name(), psyclone.transformations.ACCEnterDataTrans.name(), psyclone.transformations.ACCRoutineTrans.name(), psyclone.transformations.ACCKernelsTrans.name(), psyclone.transformations.ACCDataTrans.name(), psyclone.transformations.KernelImportsToArguments.name(), and psyclone.psyir.symbols.symbol.Symbol.visibility.

Here is the call graph for this function:

◆ copy_properties()

def psyclone.psyir.symbols.symbol.Symbol.copy_properties (   self,
  symbol_in 
)
Replace all properties in this object with the properties from
symbol_in, apart from the name (which is immutable) and visibility.

:param symbol_in: the symbol from which the properties are copied.
:type symbol_in: :py:class:`psyclone.psyir.symbols.Symbol`

:raises TypeError: if the argument is not the expected type.

Reimplemented in psyclone.psyir.symbols.typed_symbol.TypedSymbol, psyclone.psyir.symbols.datasymbol.DataSymbol, and psyclone.psyir.symbols.data_type_symbol.DataTypeSymbol.

Definition at line 152 of file symbol.py.

152  def copy_properties(self, symbol_in):
153  '''Replace all properties in this object with the properties from
154  symbol_in, apart from the name (which is immutable) and visibility.
155 
156  :param symbol_in: the symbol from which the properties are copied.
157  :type symbol_in: :py:class:`psyclone.psyir.symbols.Symbol`
158 
159  :raises TypeError: if the argument is not the expected type.
160 
161  '''
162  if not isinstance(symbol_in, Symbol):
163  raise TypeError(f"Argument should be of type 'Symbol' but "
164  f"found '{type(symbol_in).__name__}'.")
165  self._interface = symbol_in.interface
166 

References psyclone.psyir.symbols.symbol.Symbol._interface.

Here is the caller graph for this function:

◆ find_symbol_table()

def psyclone.psyir.symbols.symbol.Symbol.find_symbol_table (   self,
  node 
)
Searches back up the PSyIR tree for the SymbolTable that contains
this Symbol.

:param node: the PSyIR node from which to search.
:type node: :py:class:`psyclone.psyir.nodes.Node`

:returns: the SymbolTable containing this Symbol or None.
:rtype: :py:class:`psyclone.psyir.symbols.SymbolTable` or NoneType

:raises TypeError: if the supplied `node` argument is not a PSyIR Node.

Definition at line 384 of file symbol.py.

384  def find_symbol_table(self, node):
385  '''
386  Searches back up the PSyIR tree for the SymbolTable that contains
387  this Symbol.
388 
389  :param node: the PSyIR node from which to search.
390  :type node: :py:class:`psyclone.psyir.nodes.Node`
391 
392  :returns: the SymbolTable containing this Symbol or None.
393  :rtype: :py:class:`psyclone.psyir.symbols.SymbolTable` or NoneType
394 
395  :raises TypeError: if the supplied `node` argument is not a PSyIR Node.
396 
397  '''
398  # This import has to be local to this method to avoid circular
399  # dependencies.
400  # pylint: disable=import-outside-toplevel
401  from psyclone.psyir.nodes import Node
402  if not isinstance(node, Node):
403  raise TypeError(
404  f"find_symbol_table: expected to be passed an instance of "
405  f"psyir.nodes.Node but got '{type(node).__name__}'")
406 
407  try:
408  current = node.scope.symbol_table
409  while current:
410  if self.name in current:
411  return current
412  if current.node.parent:
413  current = current.node.parent.scope.symbol_table
414  else:
415  # We can't go any further up the hierarchy and we haven't
416  # found a SymbolTable that contains this symbol.
417  return None
418  except SymbolError:
419  # Failed to find any enclosing symbol table
420  return None
421 

References psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.GridArg.name, psyclone.domain.gocean.transformations.gocean_const_loop_bounds_trans.GOConstLoopBoundsTrans.name(), psyclone.domain.gocean.transformations.gocean_move_iteration_boundaries_inside_kernel_trans.GOMoveIterationBoundariesInsideKernelTrans.name(), psyclone.domain.gocean.transformations.gocean_opencl_trans.GOOpenCLTrans.name(), psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata.name, psyclone.domain.nemo.transformations.create_nemo_invoke_schedule_trans.CreateNemoInvokeScheduleTrans.name(), psyclone.domain.nemo.transformations.create_nemo_psy_trans.CreateNemoPSyTrans.name(), psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans.name(), psyclone.domain.nemo.transformations.nemo_arrayrange2loop_trans.NemoArrayRange2LoopTrans.name(), psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans.name(), psyclone.dynamo0p3.DynamoPSy.name(), psyclone.expression.FunctionVar.name, psyclone.expression.NamedArg.name(), psyclone.gocean1p0.GOKernelGridArgument.name(), psyclone.gocean1p0.GOStencil.name(), psyclone.parse.algorithm.FileInfo.name(), psyclone.parse.algorithm.InvokeCall.name(), psyclone.parse.kernel.KernelProcedure.name(), psyclone.parse.kernel.KernelType.name(), psyclone.parse.module_info.ModuleInfo.name(), psyclone.psyad.transformations.assignment_trans.AssignmentTrans.name(), psyclone.psyGen.PSy.name(), psyclone.psyGen.Invoke.name(), psyclone.psyGen.Kern.name(), psyclone.psyGen.CodedKern.name, psyclone.psyGen.Argument.name(), psyclone.psyGen.Transformation.name(), psyclone.psyGen.DummyTransformation.name(), psyclone.psyir.nodes.container.Container.name, psyclone.psyir.nodes.member.Member.name, psyclone.psyir.nodes.reference.Reference.name(), psyclone.psyir.nodes.routine.Routine.name, psyclone.psyir.symbols.symbol.Symbol.name(), psyclone.psyir.transformations.allarrayaccess2loop_trans.AllArrayAccess2LoopTrans.name(), psyclone.psyir.transformations.arrayrange2loop_trans.ArrayRange2LoopTrans.name(), psyclone.psyir.transformations.fold_conditional_return_expressions_trans.FoldConditionalReturnExpressionsTrans.name(), psyclone.psyir.transformations.loop_trans.LoopTrans.name(), psyclone.psyir.transformations.omp_task_trans.OMPTaskTrans.name(), psyclone.psyir.transformations.psy_data_trans.PSyDataTrans.name(), psyclone.transformations.OMPSingleTrans.name(), psyclone.transformations.OMPMasterTrans.name(), psyclone.transformations.OMPParallelTrans.name(), psyclone.transformations.MoveTrans.name(), psyclone.transformations.Dynamo0p3AsyncHaloExchangeTrans.name(), psyclone.transformations.Dynamo0p3KernelConstTrans.name(), psyclone.transformations.ACCEnterDataTrans.name(), psyclone.transformations.ACCRoutineTrans.name(), psyclone.transformations.ACCKernelsTrans.name(), psyclone.transformations.ACCDataTrans.name(), and psyclone.transformations.KernelImportsToArguments.name().

Here is the call graph for this function:

◆ get_external_symbol()

def psyclone.psyir.symbols.symbol.Symbol.get_external_symbol (   self)
Looks-up and returns the Symbol referred to by this Symbol's
Import Interface.

:raises SymbolError: if the module pointed to by the symbol interface \
                     does not contain the symbol (or the symbol is \
                     not public).
:raises NotImplementedError: if this symbol does not have an \
                             ImportInterface.

Definition at line 197 of file symbol.py.

197  def get_external_symbol(self):
198  '''
199  Looks-up and returns the Symbol referred to by this Symbol's
200  Import Interface.
201 
202  :raises SymbolError: if the module pointed to by the symbol interface \
203  does not contain the symbol (or the symbol is \
204  not public).
205  :raises NotImplementedError: if this symbol does not have an \
206  ImportInterface.
207  '''
208  if not self.is_import:
209  raise NotImplementedError(
210  f"Error trying to resolve symbol '{self.name}' properties, "
211  f"the lazy evaluation of '{self.interface}' interfaces is "
212  f"not supported.")
213 
214  module = self.interface.container_symbol
215  try:
216  return module.container.symbol_table.lookup(
217  self.name, visibility=self.Visibility.PUBLIC)
218  except KeyError as kerr:
219  raise SymbolError(
220  f"Error trying to resolve the properties of symbol "
221  f"'{self.name}'. The interface points to module "
222  f"'{module.name}' but could not find the definition of "
223  f"'{self.name}' in that module.") from kerr
224  except SymbolError as err:
225  raise SymbolError(
226  f"Error trying to resolve the properties of symbol "
227  f"'{self.name}' in module '{module.name}': {err.value}") from err
228 

References psyclone.psyir.symbols.datasymbol.DataSymbol.interface, psyclone.psyir.symbols.symbol.Symbol.interface, psyclone.psyir.symbols.typed_symbol.TypedSymbol.interface, psyclone.psyir.symbols.symbol.Symbol.is_import(), psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.GridArg.name, psyclone.domain.gocean.transformations.gocean_const_loop_bounds_trans.GOConstLoopBoundsTrans.name(), psyclone.domain.gocean.transformations.gocean_move_iteration_boundaries_inside_kernel_trans.GOMoveIterationBoundariesInsideKernelTrans.name(), psyclone.domain.gocean.transformations.gocean_opencl_trans.GOOpenCLTrans.name(), psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata.name, psyclone.domain.nemo.transformations.create_nemo_invoke_schedule_trans.CreateNemoInvokeScheduleTrans.name(), psyclone.domain.nemo.transformations.create_nemo_psy_trans.CreateNemoPSyTrans.name(), psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans.name(), psyclone.domain.nemo.transformations.nemo_arrayrange2loop_trans.NemoArrayRange2LoopTrans.name(), psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans.name(), psyclone.dynamo0p3.DynamoPSy.name(), psyclone.expression.FunctionVar.name, psyclone.expression.NamedArg.name(), psyclone.gocean1p0.GOKernelGridArgument.name(), psyclone.gocean1p0.GOStencil.name(), psyclone.parse.algorithm.FileInfo.name(), psyclone.parse.algorithm.InvokeCall.name(), psyclone.parse.kernel.KernelProcedure.name(), psyclone.parse.kernel.KernelType.name(), psyclone.parse.module_info.ModuleInfo.name(), psyclone.psyad.transformations.assignment_trans.AssignmentTrans.name(), psyclone.psyGen.PSy.name(), psyclone.psyGen.Invoke.name(), psyclone.psyGen.Kern.name(), psyclone.psyGen.CodedKern.name, psyclone.psyGen.Argument.name(), psyclone.psyGen.Transformation.name(), psyclone.psyGen.DummyTransformation.name(), psyclone.psyir.nodes.container.Container.name, psyclone.psyir.nodes.member.Member.name, psyclone.psyir.nodes.reference.Reference.name(), psyclone.psyir.nodes.routine.Routine.name, psyclone.psyir.symbols.symbol.Symbol.name(), psyclone.psyir.transformations.allarrayaccess2loop_trans.AllArrayAccess2LoopTrans.name(), psyclone.psyir.transformations.arrayrange2loop_trans.ArrayRange2LoopTrans.name(), psyclone.psyir.transformations.fold_conditional_return_expressions_trans.FoldConditionalReturnExpressionsTrans.name(), psyclone.psyir.transformations.loop_trans.LoopTrans.name(), psyclone.psyir.transformations.omp_task_trans.OMPTaskTrans.name(), psyclone.psyir.transformations.psy_data_trans.PSyDataTrans.name(), psyclone.transformations.OMPSingleTrans.name(), psyclone.transformations.OMPMasterTrans.name(), psyclone.transformations.OMPParallelTrans.name(), psyclone.transformations.MoveTrans.name(), psyclone.transformations.Dynamo0p3AsyncHaloExchangeTrans.name(), psyclone.transformations.Dynamo0p3KernelConstTrans.name(), psyclone.transformations.ACCEnterDataTrans.name(), psyclone.transformations.ACCRoutineTrans.name(), psyclone.transformations.ACCKernelsTrans.name(), psyclone.transformations.ACCDataTrans.name(), and psyclone.transformations.KernelImportsToArguments.name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interface() [1/2]

def psyclone.psyir.symbols.symbol.Symbol.interface (   self)
:returns: the an object describing the interface to this Symbol.
:rtype: Sub-class of \
    :py:class:`psyclone.psyir.symbols.symbol.SymbolInterface`

Definition at line 286 of file symbol.py.

286  def interface(self):
287  '''
288  :returns: the an object describing the interface to this Symbol.
289  :rtype: Sub-class of \
290  :py:class:`psyclone.psyir.symbols.symbol.SymbolInterface`
291  '''
292  return self._interface
293 

References psyclone.psyir.symbols.symbol.Symbol._interface.

Here is the caller graph for this function:

◆ interface() [2/2]

def psyclone.psyir.symbols.symbol.Symbol.interface (   self,
  value 
)
Setter for the Interface associated with this Symbol.

:param value: an Interface object describing how the Symbol is \
              accessed.
:type value: Sub-class of \
    :py:class:`psyclone.psyir.symbols.symbol.SymbolInterface`

:raises TypeError: if the supplied `value` is of the wrong type.

Definition at line 295 of file symbol.py.

295  def interface(self, value):
296  '''
297  Setter for the Interface associated with this Symbol.
298 
299  :param value: an Interface object describing how the Symbol is \
300  accessed.
301  :type value: Sub-class of \
302  :py:class:`psyclone.psyir.symbols.symbol.SymbolInterface`
303 
304  :raises TypeError: if the supplied `value` is of the wrong type.
305  '''
306  if not isinstance(value, SymbolInterface):
307  raise TypeError(f"The interface to a Symbol must be a "
308  f"SymbolInterface but got "
309  f"'{type(value).__name__}'")
310  self._interface = value
311 

References psyclone.psyir.symbols.symbol.Symbol._interface.

Here is the caller graph for this function:

◆ is_argument()

def psyclone.psyir.symbols.symbol.Symbol.is_argument (   self)
:returns: whether the Symbol has an ArgumentInterface.
:rtype: bool

Definition at line 340 of file symbol.py.

340  def is_argument(self):
341  '''
342  :returns: whether the Symbol has an ArgumentInterface.
343  :rtype: bool
344 
345  '''
346  return isinstance(self._interface, ArgumentInterface)
347 

References psyclone.psyir.symbols.symbol.Symbol._interface.

Here is the caller graph for this function:

◆ is_array()

def psyclone.psyir.symbols.symbol.Symbol.is_array (   self)
:returns: True if this symbol is an array and False if it is not or
    there is not enough symbol information to determine it.
:rtype: bool

Reimplemented in psyclone.psyir.symbols.typed_symbol.TypedSymbol.

Definition at line 426 of file symbol.py.

426  def is_array(self):
427  '''
428  :returns: True if this symbol is an array and False if it is not or
429  there is not enough symbol information to determine it.
430  :rtype: bool
431 
432  '''
433  return False
434 
Here is the caller graph for this function:

◆ is_array_access()

def psyclone.psyir.symbols.symbol.Symbol.is_array_access (   self,
  index_variable = None,
  access_info = None 
)
This method detects if a variable is used as an array or not.
If available, it will use the access information, i.e. how the
variable is used (e.g. if it has indices somewhere, like `a(i)%b`).
This can be incorrect in case of implicit loops (e.g. `a=b+1`,
where `a` and `b` are arrays) where the variable usage information
will not have information about indices. In this case this function
will fallback to querying the symbol itself.

This can cause significant slowdown if this symbol is imported
from a module, since then these modules need to be parsed.
# TODO #1213: Parsing modules is not yet supported.

If a `loop_variable` is specified, a variable access will only be
considered an array access if the specified variable is used in
at least one of the indices. For example:
>>> do i=1, n
>>>     a(j) = 2

the access to `a` is not considered an array if `loop_variable` is
set to `i`. If `loop_variable` is specified, `access_information`
must be specified.

:param str index_variable: optional loop variable that is used to \
    to determine if an access is an array access using this variable.
:param access_info: variable access information, optional.
:type access_info: \
    :py:class:`psyclone.core.SingleVariableAccessInfo`

:returns: if the variable is an array.
:rtype bool:

:raises InternalError: if a loop_variable is specified, but no \
    access information is given.

Definition at line 435 of file symbol.py.

435  def is_array_access(self, index_variable=None, access_info=None):
436  '''This method detects if a variable is used as an array or not.
437  If available, it will use the access information, i.e. how the
438  variable is used (e.g. if it has indices somewhere, like `a(i)%b`).
439  This can be incorrect in case of implicit loops (e.g. `a=b+1`,
440  where `a` and `b` are arrays) where the variable usage information
441  will not have information about indices. In this case this function
442  will fallback to querying the symbol itself.
443 
444  This can cause significant slowdown if this symbol is imported
445  from a module, since then these modules need to be parsed.
446  # TODO #1213: Parsing modules is not yet supported.
447 
448  If a `loop_variable` is specified, a variable access will only be
449  considered an array access if the specified variable is used in
450  at least one of the indices. For example:
451  >>> do i=1, n
452  >>> a(j) = 2
453 
454  the access to `a` is not considered an array if `loop_variable` is
455  set to `i`. If `loop_variable` is specified, `access_information`
456  must be specified.
457 
458  :param str index_variable: optional loop variable that is used to \
459  to determine if an access is an array access using this variable.
460  :param access_info: variable access information, optional.
461  :type access_info: \
462  :py:class:`psyclone.core.SingleVariableAccessInfo`
463 
464  :returns: if the variable is an array.
465  :rtype bool:
466 
467  :raises InternalError: if a loop_variable is specified, but no \
468  access information is given.
469 
470  '''
471  # TODO #1270: this function might either be better off elsewhere,
472  # or even do not implement one function that uses both access
473  # information and symbol table - if required, the user can
474  # query both in two simple statements anyway.
475  if index_variable and not access_info:
476  raise InternalError(f"In Symbol.is_array_access: index variable "
477  f"'{index_variable}' specified, but no access "
478  f"information given.")
479 
480  # TODO #1244: If as a result of 1244 we have more reliable
481  # information in the symbol table, the implementation here might
482  # be changed.
483 
484  # Prioritise access information, since this can take the index
485  # variable into account, and avoids potentially parsing other
486  # modules to find type information.
487  if access_info:
488  # Access Info might not have information if a variable is used
489  # as array (e.g. in case of an array expression). In this case
490  # we still need to check the type information in the symbol table.
491  is_array = access_info.is_array(index_variable=index_variable)
492 
493  # Access information might indicate that a variable is not an
494  # array if it is used in array expressions only. In order to
495  # verify, we need to check the symbol type information. But
496  # if an index variable is specified, an array used in an array
497  # expression without the index variable is not considered to
498  # be an array access, since it is independent of the loop
499  # variable. In this case also return the value from `is_array`.
500  if is_array or index_variable is not None:
501  return is_array
502 
503  # Either we don't have access information, or the access information
504  # does not indicate an array. In the latter case we still need to
505  # test the symbol table, since the variable might be used in array
506  # expressions only. Note that we cannot check for index variable usage
507  # in this case.
508  # TODO #1213: check for wildcard imports
509  return self.is_array

References psyclone.core.component_indices.ComponentIndices.is_array(), psyclone.core.single_variable_access_info.AccessInfo.is_array(), psyclone.psyir.nodes.array_mixin.ArrayMixin.is_array(), psyclone.psyir.nodes.member.Member.is_array(), psyclone.psyir.nodes.reference.Reference.is_array(), psyclone.psyir.symbols.symbol.Symbol.is_array(), psyclone.psyir.symbols.typed_symbol.TypedSymbol.is_array(), and psyclone.core.single_variable_access_info.SingleVariableAccessInfo.is_array().

Here is the call graph for this function:

◆ is_automatic()

def psyclone.psyir.symbols.symbol.Symbol.is_automatic (   self)
:returns: whether the Symbol has an AutomaticInterface.
:rtype: bool

Definition at line 313 of file symbol.py.

313  def is_automatic(self):
314  '''
315  :returns: whether the Symbol has an AutomaticInterface.
316  :rtype: bool
317 
318  '''
319  return isinstance(self._interface, AutomaticInterface)
320 

References psyclone.psyir.symbols.symbol.Symbol._interface.

◆ is_commonblock()

def psyclone.psyir.symbols.symbol.Symbol.is_commonblock (   self)
:returns: whether the Symbol has a CommonBlockInterface.
:rtype: bool

Definition at line 349 of file symbol.py.

349  def is_commonblock(self):
350  '''
351  :returns: whether the Symbol has a CommonBlockInterface.
352  :rtype: bool
353 
354  '''
355  return isinstance(self._interface, CommonBlockInterface)
356 

References psyclone.psyir.symbols.symbol.Symbol._interface.

◆ is_import()

def psyclone.psyir.symbols.symbol.Symbol.is_import (   self)
:returns: whether the Symbol has an ImportInterface.
:rtype: bool

Definition at line 331 of file symbol.py.

331  def is_import(self):
332  '''
333  :returns: whether the Symbol has an ImportInterface.
334  :rtype: bool
335 
336  '''
337  return isinstance(self._interface, ImportInterface)
338 

References psyclone.psyir.symbols.symbol.Symbol._interface.

Here is the caller graph for this function:

◆ is_modulevar()

def psyclone.psyir.symbols.symbol.Symbol.is_modulevar (   self)
:returns: whether the Symbol has a DefaultModuleInterface.
:rtype: bool

Definition at line 322 of file symbol.py.

322  def is_modulevar(self):
323  '''
324  :returns: whether the Symbol has a DefaultModuleInterface.
325  :rtype: bool
326 
327  '''
328  return isinstance(self._interface, DefaultModuleInterface)
329 

References psyclone.psyir.symbols.symbol.Symbol._interface.

◆ is_static()

def psyclone.psyir.symbols.symbol.Symbol.is_static (   self)
:returns: whether the Symbol has a StaticInterface.
:rtype: bool

Definition at line 358 of file symbol.py.

358  def is_static(self):
359  '''
360  :returns: whether the Symbol has a StaticInterface.
361  :rtype: bool
362 
363  '''
364  return isinstance(self._interface, StaticInterface)
365 

References psyclone.psyir.symbols.symbol.Symbol._interface.

◆ is_unknown_interface()

def psyclone.psyir.symbols.symbol.Symbol.is_unknown_interface (   self)
:returns: whether the Symbol has an UnknownInterface.
:rtype: bool

Definition at line 376 of file symbol.py.

376  def is_unknown_interface(self):
377  '''
378  :returns: whether the Symbol has an UnknownInterface.
379  :rtype: bool
380 
381  '''
382  return isinstance(self._interface, UnknownInterface)
383 

References psyclone.psyir.symbols.symbol.Symbol._interface.

◆ is_unresolved()

def psyclone.psyir.symbols.symbol.Symbol.is_unresolved (   self)
:returns: whether the Symbol has an UnresolvedInterface.
:rtype: bool

Definition at line 367 of file symbol.py.

367  def is_unresolved(self):
368  '''
369  :returns: whether the Symbol has an UnresolvedInterface.
370  :rtype: bool
371 
372  '''
373  return isinstance(self._interface, UnresolvedInterface)
374 

References psyclone.psyir.symbols.symbol.Symbol._interface.

Here is the caller graph for this function:

◆ name()

◆ resolve_type()

def psyclone.psyir.symbols.symbol.Symbol.resolve_type (   self)
Update the properties of this Symbol by using the definition imported
from the external Container. If this symbol does not have an
ImportInterface then there is no lookup needed and we just return this
symbol.

:returns: a symbol object with the class and type determined by
          examining the Container from which it is imported.
:rtype: subclass of :py:class:`psyclone.psyir.symbols.Symbol`

Reimplemented in psyclone.psyir.symbols.typed_symbol.TypedSymbol.

Definition at line 229 of file symbol.py.

229  def resolve_type(self):
230  '''
231  Update the properties of this Symbol by using the definition imported
232  from the external Container. If this symbol does not have an
233  ImportInterface then there is no lookup needed and we just return this
234  symbol.
235 
236  :returns: a symbol object with the class and type determined by
237  examining the Container from which it is imported.
238  :rtype: subclass of :py:class:`psyclone.psyir.symbols.Symbol`
239 
240  '''
241  if self.is_import:
242  extern_symbol = self.get_external_symbol()
243  init_value = None
244  if extern_symbol.initial_value:
245  init_value = extern_symbol.initial_value.copy()
246  # Specialise the existing Symbol in-place so that all References
247  # to it remain valid.
248  self.specialise(type(extern_symbol),
249  datatype=extern_symbol.datatype,
250  is_constant=extern_symbol.is_constant,
251  initial_value=init_value)
252  return self
253 

References psyclone.psyir.symbols.symbol.Symbol.get_external_symbol(), psyclone.psyir.symbols.symbol.Symbol.is_import(), and psyclone.psyir.symbols.symbol.Symbol.specialise().

Here is the call graph for this function:

◆ specialise()

def psyclone.psyir.symbols.symbol.Symbol.specialise (   self,
  subclass,
**  kwargs 
)
Specialise this symbol so that it becomes an instance of the class
provided in the subclass argument. This allows this instance
to become a subclass without any references to it becoming
invalid.

:param subclass: the class that this symbol will become.
:type subclass: type of sub-class of \
    :py:class:`psyclone.psyir.symbols.Symbol`

:raises TypeError: if subclass is not a sub-class of Symbol.

Definition at line 167 of file symbol.py.

167  def specialise(self, subclass, **kwargs):
168  '''Specialise this symbol so that it becomes an instance of the class
169  provided in the subclass argument. This allows this instance
170  to become a subclass without any references to it becoming
171  invalid.
172 
173  :param subclass: the class that this symbol will become.
174  :type subclass: type of sub-class of \
175  :py:class:`psyclone.psyir.symbols.Symbol`
176 
177  :raises TypeError: if subclass is not a sub-class of Symbol.
178 
179  '''
180  try:
181  is_subclass = issubclass(subclass, self.__class__)
182  except TypeError as info:
183  raise TypeError(
184  f"The specialise method in '{self.name}' expects the "
185  f"subclass argument to be a class.") from info
186  # pylint: disable = unidiomatic-typecheck
187  if not is_subclass or type(self) is subclass:
188  raise TypeError(
189  f"The specialise method in '{self.name}', an instance of "
190  f"'{type(self).__name__}', expects the subclass argument to "
191  f"be a subclass of '{type(self).__name__}', but found "
192  f"'{subclass.__name__}'.")
193  self.__class__ = subclass
194  self._process_arguments(**kwargs)
195 

References psyclone.psyir.symbols.symbol.Symbol.__class__, psyclone.psyir.symbols.containersymbol.ContainerSymbol._process_arguments(), psyclone.psyir.symbols.datasymbol.DataSymbol._process_arguments(), psyclone.psyir.symbols.routinesymbol.RoutineSymbol._process_arguments(), psyclone.psyir.symbols.typed_symbol.TypedSymbol._process_arguments(), and psyclone.psyir.symbols.symbol.Symbol._process_arguments().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ visibility() [1/2]

def psyclone.psyir.symbols.symbol.Symbol.visibility (   self)
:returns: the visibility of this Symbol.
:rtype: :py:class:`psyclone.psyir.symbol.Symbol.Visibility`

Definition at line 263 of file symbol.py.

263  def visibility(self):
264  '''
265  :returns: the visibility of this Symbol.
266  :rtype: :py:class:`psyclone.psyir.symbol.Symbol.Visibility`
267  '''
268  return self._visibility
269 

References psyclone.psyir.symbols.symbol.Symbol._visibility.

Here is the caller graph for this function:

◆ visibility() [2/2]

def psyclone.psyir.symbols.symbol.Symbol.visibility (   self,
  value 
)
Setter for the visibility attribute.

:raises TypeError: if the supplied value is not an instance of \
                   Symbol.Visibility.

Definition at line 271 of file symbol.py.

271  def visibility(self, value):
272  '''
273  Setter for the visibility attribute.
274 
275  :raises TypeError: if the supplied value is not an instance of \
276  Symbol.Visibility.
277  '''
278  if not isinstance(value, Symbol.Visibility):
279  raise TypeError(
280  f"{type(self).__name__} 'visibility' attribute should be of "
281  f"type psyir.symbols.Symbol.Visibility but got "
282  f"'{type(value).__name__}'.")
283  self._visibility = value
284 

References psyclone.psyir.symbols.symbol.Symbol._visibility.

Here is the caller graph for this function:

The documentation for this class was generated from the following file: