Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Fortran2003.Section_Subscript_List):
raise InternalError(
"get_integer_array: expected array declaration to have a "
"Section_Subscript_List but found '{0}' for: '{1}'".format(
type(assign.children[0].children[1]).__name__,
str(assign)))
dim_stmt = assign.children[0].children[1]
if len(dim_stmt.children) != 1:
raise ParseError(
"get_integer_array: array must be 1D but found an array "
"with {0} dimensions for name '{1}'".format(
len(dim_stmt.children), name))
if not isinstance(dim_stmt.children[0],
Fortran2003.Int_Literal_Constant):
raise ParseError(
"get_integer_array: array extent must be specified using "
"an integer literal but found '{0}' for array '{1}'".
format(str(dim_stmt.children[0]), name))
# Get the declared size of the array
array_extent = int(str(dim_stmt.children[0]))
if not isinstance(assign.children[2],
Fortran2003.Array_Constructor):
raise ParseError(
"get_integer_array: RHS of assignment is not "
"an array constructor: '{0}'".format(str(assign)))
# fparser2 AST for Array_Constructor is:
# Array_Constructor('[', Ac_Value_List(',', (Name('w0'),
# Name('w1'))), ']')
# Construct a list of the names in the array constructor
names = walk(assign.children[2].children, Fortran2003.Name)
called
:param args: a list of 'Arg' instances containing the required \
information for the arguments being passed from the algorithm \
layer. The list order is the same as the argument order.
:type arg: list of :py:class:`psyclone.parse.algorithm.Arg`
:returns: a KernelCall instance with information specific to \
the API.
:rtype: :py:class:`psyclone.parse.algorithm.KernelCall`
:raises ParseError: if the kernel is not specified in a use \
statement in the algorithm layer
'''
try:
module_name = self._arg_name_to_module_name[kernel_name.lower()]
except KeyError:
raise ParseError(
"kernel call '{0}' must either be named "
"in a use "
"statement (found {1}) or be a recognised built-in "
"(one of '{2}' for this API)".
format(kernel_name,
list(self._arg_name_to_module_name.values()),
list(self._builtin_name_map.keys())))
from psyclone.parse.kernel import get_kernel_ast
modast = get_kernel_ast(module_name, self._alg_filename,
self._kernel_path, self._line_length)
from psyclone.parse.kernel import KernelTypeFactory
return KernelCall(module_name,
KernelTypeFactory(api=self._api).create(
modast, name=kernel_name), args)
if not isinstance(parse_tree.items[1], Char_Literal_Constant):
raise ParseError(
"algorithm.py:Parser:get_invoke_label The (optional) name of an "
"invoke must be specified as a string, but found {0} in "
"{1}".format(str(parse_tree.items[1]), alg_filename))
invoke_label = parse_tree.items[1].items[0]
invoke_label = invoke_label.lower()
invoke_label = invoke_label.strip()
if invoke_label[0] == '"' and invoke_label[-1] == '"' or \
invoke_label[0] == "'" and invoke_label[-1] == "'":
invoke_label = invoke_label[1:-1]
invoke_label = invoke_label.replace(" ", "_")
if not pattern_tools.abs_name.match(invoke_label):
raise ParseError(
"algorithm.py:Parser:get_invoke_label the (optional) name of an "
"invoke must be a string containing a valid Fortran name (with "
"any spaces replaced by underscores) but got '{0}' in file "
"{1}".format(invoke_label, alg_filename))
return invoke_label
:rtype: string
:raises ParseError: if the supplied meta-data is not a recognised \
mesh identifier.
:raises ParseError: if the mesh type is unsupported.
'''
if not isinstance(metadata, expr.NamedArg) or \
metadata.name.lower() != "mesh_arg":
raise ParseError(
"{0} is not a valid mesh identifier (expected "
"mesh_arg=MESH_TYPE where MESH_TYPE is one of {1}))".
format(str(metadata), valid_mesh_types))
mesh = metadata.value.lower()
if mesh not in valid_mesh_types:
raise ParseError("mesh_arg must be one of {0} but got {1}".
format(valid_mesh_types, mesh))
return mesh
fname = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
builtin_defs_file)
if not os.path.isfile(fname):
raise ParseError(
"BuiltInKernelTypeFactory:create Kernel '{0}' is a recognised "
"Built-in but cannot find file '{1}' containing the meta-data "
"describing the Built-in operations for API '{2}'"
.format(name, fname, self._type))
# Attempt to parse the meta-data
try:
parsefortran.FortranParser.cache.clear()
fparser.logging.disable(fparser.logging.CRITICAL)
parse_tree = fpapi.parse(fname)
except Exception:
raise ParseError(
"BuiltInKernelTypeFactory:create: Failed to parse the meta-"
"data for PSyclone built-ins in file '{0}'.".format(fname))
# Now we have the parse tree, call our parent class to create \
# the object
return KernelTypeFactory.create(self, parse_tree, name)
# pylint: enable=too-few-public-methods
:raises ParseError: if the dimensions specified do not tally with \
the number of metadata arguments.
:raises ParseError: if var_type is specified and a structure \
constructor for a different type is found.
'''
descs = ast.get_variable(var_name)
if "INTEGER" in str(descs):
# INTEGER in above 'if' test is an fparser1 hack as get_variable()
# returns an integer if the variable is not found.
raise ParseError(
"No variable named '{0}' found in the metadata for kernel "
"'{1}': '{2}'.".format(var_name, name, str(ast).strip()))
try:
nargs = int(descs.shape[0])
except AttributeError:
raise ParseError(
"In kernel metadata '{0}': '{1}' variable must be an array.".
format(name, var_name))
if len(descs.shape) != 1:
raise ParseError(
"In kernel metadata '{0}': '{1}' variable must be a 1 dimensional "
"array.".format(name, var_name))
if descs.init.find("[") != -1 and descs.init.find("]") != -1:
# there is a bug in fparser1
raise ParseError(
"Parser does not currently support '[...]' initialisation for "
"'{0}', please use '(/.../)' instead.".format(var_name))
try:
inits = expr.FORT_EXPRESSION.parseString(descs.init)[0]
except ParseException:
raise ParseError("Kernel metadata has an invalid format {0}.".
format(descs.init))
"be at most two arguments inside the brackets {0}".
format(metadata))
if not isinstance(metadata.args[0], expr.FunctionVar):
if isinstance(metadata.args[0], six.string_types):
raise ParseError(
"Expecting format stencil([,]). However, "
"the specified '{0}' is a literal and therefore is "
"not one of the valid types '{1}'".
format(metadata.args[0], valid_types))
else:
raise ParseError(
"Internal error, expecting either FunctionVar or "
"str from the expression analyser but found {0}".
format(type(metadata.args[0])))
if metadata.args[0].args:
raise ParseError(
"Expected format stencil([,]). However, the "
"specified '{0}' includes brackets")
stencil_type = metadata.args[0].name
if stencil_type not in valid_types:
raise ParseError(
"Expected format stencil([,]). However, the "
"specified '{0}' is not one of the valid types '{1}'".
format(stencil_type, valid_types))
stencil_extent = None
if len(metadata.args) == 2:
if not isinstance(metadata.args[1], six.string_types):
raise ParseError(
"Expected format stencil([,]). However, the "
"specified '{0}' is not an integer".
format(metadata.args[1]))
:raises ParseError: if scalar arguments do not have a read-only or
a reduction access.
:raises ParseError: if a scalar argument that is not a real \
scalar has a reduction access.
'''
# Check whether something other than a scalar is passed in
if self._type not in LFRicArgDescriptor.VALID_SCALAR_NAMES:
raise InternalError(
"LFRicArgDescriptor._validate_scalar(): expecting a scalar "
"argument but got an argument of type '{0}'.".
format(arg_type.args[0]))
# There must be at least 2 arguments to describe a scalar
if len(arg_type.args) != 2:
raise ParseError(
"In the LFRic API each 'meta_arg' entry must have 2 "
"arguments if its first argument is 'gh_{{r,i}}scalar', but "
"found {0} in '{1}'.".format(len(arg_type.args), arg_type))
# Test allowed accesses for scalars (read_only or reduction)
scalar_accesses = [AccessType.READ] + \
AccessType.get_valid_reduction_modes()
# Convert generic access types to GH_* names for error messages
api_config = Config.get().api_conf(API)
rev_access_mapping = api_config.get_reverse_access_mapping()
if self._access_type not in scalar_accesses:
api_specific_name = rev_access_mapping[self._access_type]
valid_reductions = AccessType.get_valid_reduction_names()
raise ParseError(
"In the LFRic API scalar arguments must have read-only "
"('gh_read') or a reduction {0} access but found '{1}' "
def __init__(self, ast, name=None):
KernelType.__init__(self, ast, name=name)
self._arg_descriptors = []
for init in self._inits:
if init.name != 'arg':
raise ParseError(
"gocean0p1.py:GOKernelType:__init__: Each meta_arg value "
"must be of type 'arg' for the gocean0.1 api, but found "
"'{0}'.".format(init.name))
access = init.args[0].name
funcspace = init.args[1].name
stencil = init.args[2].name
if len(init.args) != 3:
raise ParseError(
"gocean0p1.py:GOKernelType:__init__: 'arg' type expects "
"3 arguments but found {0} in '{1}'".
format(str(len(init.args)), init.args))
self._arg_descriptors.append(GODescriptor(access, funcspace,
stencil))
:param metadata: node in parser ast
:type metadata: py:class:`psyclone.expression.NamedArg`
:param valid_mesh_types: List of valid mesh types
:type valid_mesh_types: list of strings
:return: the name of the mesh
:rtype: string
:raises ParseError: if the supplied meta-data is not a recognised \
mesh identifier.
:raises ParseError: if the mesh type is unsupported.
'''
if not isinstance(metadata, expr.NamedArg) or \
metadata.name.lower() != "mesh_arg":
raise ParseError(
"{0} is not a valid mesh identifier (expected "
"mesh_arg=MESH_TYPE where MESH_TYPE is one of {1}))".
format(str(metadata), valid_mesh_types))
mesh = metadata.value.lower()
if mesh not in valid_mesh_types:
raise ParseError("mesh_arg must be one of {0} but got {1}".
format(valid_mesh_types, mesh))
return mesh