Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif isinstance(child, Fortran2003.Structure_Constructor):
# This is a structure constructor. Make a node for it.
node_list.append(self.get_node(parent, name=str(child)))
elif isinstance(child, Fortran2003.Structure_Constructor_2):
# This is a structure constructor, e.g.
# mask = tmask_i(:, :). Make a node for it.
tmp_node = self.get_node(parent, name=str(child.items[0]))
node_list.append(tmp_node)
node_list += self.make_dag(tmp_node, child.items[2:], mapping)
elif (isinstance(child, Fortran2003.Level_3_Expr) or
isinstance(child, Fortran2003.Level_4_Expr)):
# Have an expression that is something like
# TRIM(ssnd(ji) % clname) // '_cat' // cli2. Carry on
# down to the children
node_list += self.make_dag(parent, child.items, mapping)
elif isinstance(child, Fortran2003.Data_Ref):
# Have an expression that is something like
# ssnd(ji) % clname. Make a node to represent it.
dvar = Variable()
dvar.load(child, mapping)
tmp_node = self.get_node(parent, variable=dvar)
node_list.append(tmp_node)
# TODO handle case where the component of the derived type
# is itself an array, e.g. ssnd % clname(ji,jj)
# node_list += self.make_dag(tmp_node,
# [child.items[1]], mapping)
elif isinstance(child, Fortran2003.Equiv_Operand):
# A logical expression c.f.
# kinfo == OASIS_Recvd .OR. kinfo == OASIS_FromRest
pass
else:
raise DAGError("Unrecognised child; type = {0}, str = '{1}'".
digraph.to_dot(show_weights=show_weights)
digraph.report()
# Fuse multiply-adds where possible
if apply_fma_transformation:
num_fused = digraph.fuse_multiply_adds()
if num_fused:
digraph.name = digraph.name + "_fused"
# Re-compute the critical path through this graph
digraph.calc_critical_path()
digraph.to_dot()
digraph.report()
else:
print("No opportunities to fuse multiply-adds")
except Fortran2003.NoMatchError:
# TODO log this error
print("Parsing '{0}' (starting at {1}) failed at {2}. "
"Is the file valid Fortran?".
format(filename, reader.fifo_item[0], reader.fifo_item[-1]))
# Carry on to next file
continue
def is_subexpression(expr):
''' Returns True if the supplied node is itself a sub-expression. '''
return (isinstance(expr, Fortran2003.Add_Operand) or
isinstance(expr, Fortran2003.Level_2_Expr) or
isinstance(expr, Fortran2003.Level_2_Unary_Expr) or
isinstance(expr, Fortran2003.Parenthesis))
if len(modules) > 1:
raise GenerationError(
"Could not process {0}. Just one module definition per file "
"supported.".format(str(module_ast)))
if not modules:
return None
module = modules[0].parent
mod_name = str(modules[0].children[1])
# Create a container to capture the module information
new_container = Container(mod_name)
# Parse the declarations if it has any
for child in module.children:
if isinstance(child, Fortran2003.Specification_Part):
self.process_declarations(new_container, child.children, [])
break
return new_container
does not match the extent of the array.
'''
# Ensure the classes are setup for the Fortran2003 parser
_ = ParserFactory().create()
# Fortran is not case sensitive so nor is our matching
lower_name = name.lower()
for statement, _ in fpapi.walk(self._ktype, -1):
if not isinstance(statement, fparser1.typedecl_statements.Integer):
# This isn't an integer declaration so skip it
continue
# fparser only goes down to the statement level. We use fparser2 to
# parse the statement itself.
assign = Fortran2003.Assignment_Stmt(statement.entity_decls[0])
names = walk(assign.children, Fortran2003.Name)
if not names:
raise InternalError("Unsupported assignment statement: '{0}'".
format(str(assign)))
if str(names[0]).lower() != lower_name:
# This is not the variable declaration we're looking for
continue
if not isinstance(assign.children[0], Fortran2003.Part_Ref):
# Not an array declaration
return []
if not isinstance(assign.children[0].children[1],
Fortran2003.Section_Subscript_List):
raise InternalError(
"get_integer_array: expected array declaration to have a "
if (sym.datatype.intrinsic !=
ScalarType.Intrinsic.INTEGER or
isinstance(sym.datatype, ArrayType)):
_unsupported_type_error(dimensions)
except KeyError:
# We haven't seen this symbol before so create a new
# one with a deferred interface (since we don't
# currently know where it is declared).
sym = DataSymbol(dim_name, default_integer_type(),
interface=UnresolvedInterface())
symbol_table.add(sym)
shape.append(sym)
else:
_unsupported_type_error(dimensions)
elif isinstance(dim, Fortran2003.Assumed_Size_Spec):
raise NotImplementedError(
"Could not process {0}. Assumed-size arrays"
" are not supported.".format(dimensions))
else:
raise InternalError(
"Reached end of loop body and array-shape specification "
"{0} has not been handled.".format(type(dim)))
return shape
for item in node.items[1].items:
self._index_exprns.append(str(item).replace(" ", ""))
# This recurses down and finds the names of all of
# the *variables* in the array-index expression
# (i.e. ignoring whether they are "+1" etc.)
array_index_vars = walk_ast(node.items[1].items,
[Fortran2003.Name])
elif (isinstance(node.items[1], Fortran2003.Name) or
isinstance(node.items[1],
Fortran2003.Int_Literal_Constant) or
isinstance(node.items[1], Fortran2003.Data_Ref)):
# There's only a single array index/argument
self._index_exprns.append(str(node.items[1]).replace(" ", ""))
array_index_vars = [node.items[1]]
elif isinstance(node.items[1], Fortran2003.Level_2_Expr):
# Array index expression itself contains an array access - i.e.
# this is an indirect access.
self._index_exprns.append(
''.join([str(item).replace(" ", "")
for item in node.items[1].items]))
# TODO currently if we get an array access of the form
# a(map(i)) then we will store 'map' and 'i' as the
# array-index variables. This needs to be extended to
# properly support indirect array accesses.
array_index_vars = walk_ast(node.items[1].items,
[Fortran2003.Name])
elif isinstance(node.items[1], Fortran2003.Part_Ref):
# Array index expression is itself an array access
# TODO don't flatten the array expression into a string
# so that we can handle loop-unrolling for such cases
self._index_exprns.append(str(node.items[1]).replace(" ", ""))