Reference Guide  2.5.0
psyclone.parse.kernel.KernelProcedure Class Reference

Public Member Functions

def __init__ (self, ktype_ast, ktype_name, modast)
 
def name (self)
 
def ast (self)
 
def __repr__ (self)
 
def __str__ (self)
 

Static Public Member Functions

def get_procedure (ast, name, modast)
 

Detailed Description

Captures the parse tree and name of a kernel subroutine.

:param ktype_ast: the fparser1 parse tree for the Kernel meta-data.
:type ktype_ast: :py:class:`fparser.one.block_statements.Type`
:param str ktype_name: name of the Fortran type holding the Kernel \
                       meta-data.
:param modast: the fparser1 parse tree for the module containing the \
               Kernel routine.
:type modast: :py:class:`fparser.one.block_statements.BeginSource`

Definition at line 507 of file kernel.py.

Member Function Documentation

◆ ast()

def psyclone.parse.kernel.KernelProcedure.ast (   self)
:returns: the parse tree of the kernel subroutine
:rtype: :py:class:`fparser.one.block_statements.Subroutine`

Definition at line 621 of file kernel.py.

621  def ast(self):
622  '''
623  :returns: the parse tree of the kernel subroutine
624  :rtype: :py:class:`fparser.one.block_statements.Subroutine`
625 
626  '''
627  return self._ast
628 

References psyclone.alg_gen.Alg._ast, psyclone.parse.kernel.KernelType._ast, and psyclone.psyir.nodes.node.Node._ast.

Here is the caller graph for this function:

◆ get_procedure()

def psyclone.parse.kernel.KernelProcedure.get_procedure (   ast,
  name,
  modast 
)
static
Get the name of the subroutine associated with the Kernel. This is
a type-bound procedure in the meta-data which may take one of three
forms:
        PROCEDURE, nopass :: code => <proc_name>
or
        PROCEDURE, nopass :: <proc_name>
or if there is no type-bound procedure, an interface may be used:
        INTERFACE <proc_name>

:param ast: the fparser1 parse tree for the Kernel meta-data.
:type ast: :py:class:`fparser.one.block_statements.Type`
:param str name: the name of the Fortran type holding the Kernel \
                 meta-data.
:param modast: the fparser1 parse tree for the module containing the \
               Kernel routine.
:type modast: :py:class:`fparser.one.block_statements.BeginSource`

:returns: 2-tuple of the fparser1 parse tree of the Subroutine \
          statement and the name of that Subroutine.
:rtype: (:py:class:`fparser1.block_statements.Subroutine`, str)

:raises ParseError: if the supplied Kernel meta-data does not \
                    have a type-bound procedure or interface.
:raises ParseError: if no implementation is found for the \
                     type-bound procedure or interface module \
                     procedures.
:raises ParseError: if the type-bound procedure specifies a binding \
                    name but the generic name is not "code".
:raises InternalError: if we get an empty string for the name of the \
                       type-bound procedure.

Definition at line 526 of file kernel.py.

526  def get_procedure(ast, name, modast):
527  '''
528  Get the name of the subroutine associated with the Kernel. This is
529  a type-bound procedure in the meta-data which may take one of three
530  forms:
531  PROCEDURE, nopass :: code => <proc_name>
532  or
533  PROCEDURE, nopass :: <proc_name>
534  or if there is no type-bound procedure, an interface may be used:
535  INTERFACE <proc_name>
536 
537  :param ast: the fparser1 parse tree for the Kernel meta-data.
538  :type ast: :py:class:`fparser.one.block_statements.Type`
539  :param str name: the name of the Fortran type holding the Kernel \
540  meta-data.
541  :param modast: the fparser1 parse tree for the module containing the \
542  Kernel routine.
543  :type modast: :py:class:`fparser.one.block_statements.BeginSource`
544 
545  :returns: 2-tuple of the fparser1 parse tree of the Subroutine \
546  statement and the name of that Subroutine.
547  :rtype: (:py:class:`fparser1.block_statements.Subroutine`, str)
548 
549  :raises ParseError: if the supplied Kernel meta-data does not \
550  have a type-bound procedure or interface.
551  :raises ParseError: if no implementation is found for the \
552  type-bound procedure or interface module \
553  procedures.
554  :raises ParseError: if the type-bound procedure specifies a binding \
555  name but the generic name is not "code".
556  :raises InternalError: if we get an empty string for the name of the \
557  type-bound procedure.
558  '''
559  bname = None
560  # Search the the meta-data for a SpecificBinding
561  for statement in ast.content:
562  if isinstance(statement, fparser1.statements.SpecificBinding):
563  # We support:
564  # PROCEDURE, nopass :: code => <proc_name> or
565  # PROCEDURE, nopass :: <proc_name>
566  if statement.bname:
567  if statement.name.lower() != "code":
568  raise ParseError(
569  f"Kernel type {name} binds to a specific procedure"
570  f" but does not use 'code' as the generic name.")
571  bname = statement.bname.lower()
572  else:
573  bname = statement.name.lower()
574  break
575  if bname is None:
576  # If no type-bound procedure found, search for an explicit
577  # interface that has module procedures.
578  bname, subnames = get_kernel_interface(name, modast)
579  if bname is None:
580  # no interface found either
581  raise ParseError(
582  f"Kernel type {name} does not bind a specific procedure "
583  f"or provide an explicit interface")
584  elif bname == '':
585  raise InternalError(
586  f"Empty Kernel name returned for Kernel type {name}.")
587  else:
588  # add the name of the tbp to the list of strings to search for.
589  subnames = [bname]
590  # walk the AST to check the subroutine names exist.
591  procedure_count = 0
592  for subname in subnames:
593  for statement, _ in fpapi.walk(modast):
594  if isinstance(statement,
595  fparser1.block_statements.Subroutine) \
596  and statement.name.lower() \
597  == subname:
598  procedure_count = procedure_count + 1
599  if procedure_count == 1:
600  # set code to statement if there is one procedure.
601  code = statement
602  else:
603  code = None # set to None if there is more than one.
604  break
605  else:
606  raise ParseError(
607  f"kernel.py:KernelProcedure:get_procedure: Kernel "
608  f"subroutine '{subname}' not found.")
609  return code, bname
610 

◆ name()


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