psyclone.domain.lfric.kernel.common_declaration_metadata

Module containing the CommonDeclarationMetadata base class which captures the common functionality for the LFRic kernel declaration metadata i.e. metadata that is specified by the declaration of a variable within the Fortran derived type that captures the metadata.

Declaration metadata is captured as an fparser2 class hierarchy in the following form (the code in this file assumes this form when traversing an fparser2 tree):

Data_Component_Def_Stmt
    [0] Intrinsic_Type_Spec
        [0] <str> INTEGER
        [1] <NoneType>
    or
    [0] Declaration_Type_Spec
        [0] <str> TYPE
        [1] Type_Name.string: func_type

    [1] Component_Attr_Spec_List or <NoneType>
        ...
        Dimension_Component_Attr_Spec
            [0] <str> DIMENSION
            [1] Explicit_Shape_Spec_List
                ...
                Explicit_Shape_Spec
                    [0] <NoneType>
                    [1] Int_Literal_Constant
                        [0] <str> 1
                        [1] <NoneType>
                ...
        ...
    [2] Component_Decl_List
        ...
        Component_Decl
            [0] Name.string: gh_shape
            [1] Explicit_Shape_Spec_List or <NoneType>
                [0] <NoneType>
                [1] Int_Literal_Constant
                    [0] <str> 1
                    [1] <NoneType>
            [2] <NoneType>
            [3] Component_Initialization
                [0] <str> =
                [1] Name.string: gh_quadrature_face
                *OR*
                [1] Array_Constructor (/ ... /)
                    [0] <str> (/
                    [1] Ac_Value_List
                        Name.string: gh_quadrature_face
                        ...
                    [2] <str> /)
        ...

Classes

class psyclone.domain.lfric.kernel.common_declaration_metadata.CommonDeclarationMetadata

Class to capture common LFRic kernel declaration metadata.

Inheritance

Inheritance diagram of CommonDeclarationMetadata
static array_declaration_string(datatype, name, values)

Return the Fortran declaration associated with the datatype, name and value arguments.

Parameters:
  • datatype (str) – the name of the Fortran datatype.

  • name (str) – the name of the variable.

  • values (List[str]) – a list of variable values.

fparser2_class

alias of Data_Component_Def_Stmt

static get_derived_array_declaration(fparser2_tree, type_name, name, valid_values=None)

Return the array values. Also check that the supplied variable declaration captured as an fparser2 tree is an derived type array of type ‘type_name’ with the specified ‘name’ which is initialised to a set of values, each of which are one of the supplied ‘valid_values’ and if not, raise an exception.

Parameters:
  • fparser2_tree (fparser.two.Fortran2003.Data_Component_Def_Stmt) – an fparser2 tree.

  • type_name (str) – the expected derived type name.

  • name (str) – the expected variable name.

  • valid_values (Optional[List[str]]) – a list of values that the variable could be set to. Defaults to None.

Returns:

the values of the variable.

Return type:

List[str]

static get_intrinsic_array_declaration(fparser2_tree, datatype, name, valid_values)

Return the array values. Also check that the supplied variable declaration captured as an fparser2 tree is an intrinsic array of type ‘datatype’ with the specified ‘name’ which is initialised to a set of values, each of which are one of the supplied ‘valid_values’ and if not, raise an exception.

Parameters:
  • fparser2_tree (fparser.two.Fortran2003.Data_Component_Def_Stmt) – an fparser2 tree.

  • datatype (str) – the expected intrinsic type name.

  • name (str) – the expected variable name.

  • valid_values (List[str]) – a list of values that the variable could be set to.

Returns:

the values of the variable.

Return type:

List[str]

static get_intrinsic_scalar_declaration(fparser2_tree, datatype, name, valid_values)

Return the value of the variable. Also check that the supplied variable declaration captured as an fparser2 tree is an intrinsic of type ‘datatype’ with the specified ‘name’ which is initialised to a value that is one of the supplied ‘valid_values’ and if not, raise an exception.

Parameters:
  • fparser2_tree (fparser.two.Fortran2003.Data_Component_Def_Stmt) – an fparser2 tree.

  • datatype (str) – the expected intrinsic type name.

  • name (str) – the expected variable name.

  • valid_values (List[str]) – a list of values that the variable could be set to.

Returns:

the value of the variable.

Return type:

str

Raises:
  • ParseError – if the variable declaration has any unexpected attributes.

  • ParseError – if the scalar variable is initialised with an array of values.

static scalar_declaration_string(datatype, name, value)

Return the Fortran declaration associated with the datatype, name and value arguments.

Parameters:
  • datatype (str) – the name of the Fortran datatype.

  • name (str) – the name of the variable.

  • value (str) – the value of the variable.

static type_declaration_string(datatype, name, values)

Return the Fortran declaration associated with the datatype, name and values arguments.

Parameters:
  • datatype (str) – the name of the Fortran datatype.

  • name (str) – the name of the variable.

  • values (List[str]) – a list of variable values.

classmethod validate_list(values, expected_type)

Check that the values argument is a list with at least one entry and that its entries are the same type as the expected_type argument.

Parameters:
  • values (List[psyclone.domain.lfric.kernel.            CommonArgMetadata]) – a list of values.

  • expected_type (psyclone.domain.lfric.kernel.            CommonArgMetadata) – the type that the values are expected to be.

raises TypeError: if the supplied value is not a list. raises TypeError: if the supplied value is an empty list. raises TypeError: if any entry in the list is not of the required type.

static validate_name_value(fparser2_tree, name)

Check that the supplied variable declaration captured as an fparser2 tree declares a single variable with the name being the supplied ‘name’ argument and that this variable is initialised.

Parameters:
  • fparser2_tree (fparser.two.Fortran2003.Data_Component_Def_Stmt) – an fparser2 tree.

  • name (str) – the expected variable name.

Raises:
  • ParseError – if more than one variable is found in the declaration.

  • ValueError – if the variable name does not match the expected name.

  • ParseError – if the variable is not set to a value.

static validate_node(fparser2_node, encoding)

Check that the supplied fparser2_node is of the type specified by the encoding argument.

Parameters:
  • fparser2_node (subclass of fparser.two.Fortran2003.Base) – an fparser2 node.

  • encoding (subclass of fparser.two.Fortran2003.Base) – a type of fparser2 node.

Raises:

TypeError – if the type of the supplied fparser2 node is not the same as the supplied encoding.