f90wrap.fortran module

This module defines a series of classes which inherit an abstract base class. Each represents a node in a Fortran parse tree – Modules, Subroutines, Arguments etc. A Fortran parse tree will contain only these classes as nodes.

class f90wrap.fortran.AccessUpdater[source]

Bases: FortranTransformer

Visit module contents and update public_symbols and private_symbols lists to be consistent with (i) default module access; (ii) public and private statements at module level; (iii) public and private attibutes.

visit(node)[source]
visit_Module(mod)[source]
class f90wrap.fortran.Argument(name='', filename='', doc=None, lineno=0, attributes=None, type='', value='', doxygen='')[source]

Bases: Declaration

Represents a Procedure Argument.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • type (str , default "") – The type of the declaration

  • attributes (list of str , default None) – A list of attributes defined in the declaration (eg. intent(in), allocatable)

  • value (str) – A value given to the variable upon definition (eg. value=8 in "integer :: x = 8"

dims_list()[source]
static split_dimensions(dim)[source]

Given a string like “dimension(a,b,c)” return the list of dimensions [‘a’,’b’,’c’].

class f90wrap.fortran.Binding(name='', filename='', doc=None, lineno=0, type=None, attributes=None, procedures=None, mod_name=None, type_name=None)[source]

Bases: Fortran

Represents a type procedure binding.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

class f90wrap.fortran.Declaration(name='', filename='', doc=None, lineno=0, attributes=None, type='', value='', doxygen='')[source]

Bases: Fortran

Base class representing a declaration statement

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • type (str , default "") – The type of the declaration

  • attributes (list of str , default None) – A list of attributes defined in the declaration (eg. intent(in), allocatable)

  • value (str) – A value given to the variable upon definition (eg. value=8 in "integer :: x = 8"

class f90wrap.fortran.Element(name='', filename='', doc=None, lineno=0, attributes=None, type='', value='', doxygen='')[source]

Bases: Declaration

Represents a Module or Derived-Type Element.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • type (str , default "") – The type of the declaration

  • attributes (list of str , default None) – A list of attributes defined in the declaration (eg. intent(in), allocatable)

  • value (str) – A value given to the variable upon definition (eg. value=8 in "integer :: x = 8"

class f90wrap.fortran.Fortran(name='', filename='', doc=None, lineno=0, doxygen='')[source]

Bases: object

Abstract base class for all nodes in Fortran parser tree.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

class f90wrap.fortran.FortranTransformer[source]

Bases: FortranVisitor

Subclass of FortranVisitor which allows tree to be modified.

Walks the Fortran parse tree and uses the return value of the visitor methods to replace or remove old nodes. If the return value of the visitor method is None, the node will be removed.

generic_visit(node)[source]
class f90wrap.fortran.FortranTreeDumper[source]

Bases: FortranVisitor

Subclass of FortranVisitor which prints a textual representation of the Fortran parse tree.

generic_visit(node)[source]
class f90wrap.fortran.FortranVisitor[source]

Bases: object

Implementation of the Visitor pattern for a Fortran parse tree.

Walks the tree calling a visitor function for every node found. The visitor methods should be defined in subclasses as visit_ plus the class name of the node, e.g. ``visit_Module`. If no visitor function is found the generic_visit visitor is used instead.

generic_visit(node)[source]
visit(node)[source]
class f90wrap.fortran.Function(name='', filename='', doc=None, lineno=0, arguments=None, uses=None, attributes=None, ret_val=None, ret_val_doc=None, mod_name=None, type_name=None)[source]

Bases: Procedure

Represents a Fortran Function.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • arguments (list of fortran.Argument) – A list of arguments to the procedure

  • uses (list of str or tuple , default None) – A list of modules that this procedure uses. If the entry is a tuple, it should be in the form (uses,only,[only,..]), where the only entries are subroutines/elements in the used module.

  • attributes (list of str, default None) – Attributes of the procedure

  • mod_name (str , default None) – The name of the module in which the procedure is found, if any.

  • type_name (str , default None) – The name of the type in which the procedure is defined, if any.

  • ret_val (fortran.Argument) – The argument which is the returned value

  • ret_val_doc (str) – The documentation of the returned value

class f90wrap.fortran.Interface(name='', filename='', doc=None, lineno=0, procedures=None, attributes=None, mod_name=None, type_name=None)[source]

Bases: Fortran

Represents a Fortran Interface.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • procedures (list of fortran.Procedure) – The procedures listed in the interface.

  • mod_name (str , default None) – The name of the module in which the interface is found, if any.

  • type_name (str , default None) – The name of the type in which the interface is defined, if any.

class f90wrap.fortran.LowerCaseConverter[source]

Bases: FortranTransformer

Subclass of FortranTransformer which converts program, module, procedure, interface, type and declaration names and attributes to lower case. Original names are preserved in the orig_name attribute.

visit_Binding(node)[source]
visit_Declaration(node)[source]
visit_Element(node)[source]
visit_Interface(node)[source]
visit_Module(node)[source]
visit_Procedure(node)[source]
visit_Program(node)[source]
visit_Type(node)[source]
class f90wrap.fortran.Module(name='', filename='', doc=None, lineno=0, types=None, elements=None, procedures=None, interfaces=None, uses=None, default_access='public', public_symbols=None, private_symbols=None, mod_depends=None)[source]

Bases: Fortran

Represents a Fortran module.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • types (list of fortran.Type , default None) – Derived-types defined in the module

  • elements (list of fortran.Element , default None) – Module-level variables in the module

  • procedures (list of fortran.Procedure , default None) – A list of procedures defined in the module

  • interfaces (list of fortran.Interface , default None) – A list of interfaces defined in the module

  • uses (list of str or tuple , default None) – A list of modules that this module uses. If the entry is a tuple, it should be in the form (uses,only,[only,..]), where the only entries are subroutines/elements in the used module.

  • default_access (str, default "public") – The default access to the module (public or private)

  • public_symbols (list of str , default None) – The symbols within the module that are public

  • private_symbols (list of str , default None) – The symbols within the module that are private

  • mod_depends (list of fortran.Module , default None) – Module on which current module depends

class f90wrap.fortran.PrivateSymbolsRemover[source]

Bases: FortranTransformer

Transform a tree by removing private symbols.

visit(node)[source]
visit_Module(mod)[source]
class f90wrap.fortran.Procedure(name='', filename='', doc=None, lineno=0, arguments=None, uses=None, attributes=None, mod_name=None, type_name=None)[source]

Bases: Fortran

Represents a Fortran Function or Subroutine.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • arguments (list of fortran.Argument) – A list of arguments to the procedure

  • uses (list of str or tuple , default None) – A list of modules that this procedure uses. If the entry is a tuple, it should be in the form (uses,only,[only,..]), where the only entries are subroutines/elements in the used module.

  • attributes (list of str, default None) – Attributes of the procedure

  • mod_name (str , default None) – The name of the module in which the procedure is found, if any.

  • type_name (str , default None) – The name of the type in which the procedure is defined, if any.

class f90wrap.fortran.Program(name='', filename='', doc=None, lineno=0, procedures=None, uses=None)[source]

Bases: Fortran

Class to represent a Fortran main program.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • procedures (list of fortran.Procedure , default None) – A list of procedures within the program’s scope.

class f90wrap.fortran.Prototype(name='', filename='', doc=None, lineno=0, doxygen='')[source]

Bases: Fortran

Represents a Fortran Prototype.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

class f90wrap.fortran.RepeatedInterfaceCollapser[source]

Bases: FortranTransformer

Collapse repeated interfaces with the same name into a single interface

visit_Module(node)[source]
class f90wrap.fortran.Root(name='', filename='', doc=None, lineno=0, programs=None, modules=None, procedures=None)[source]

Bases: Fortran

The Root node of a Fortan parse tree

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • programs (list of fortran.Program, default None) – A list of Programs within the parse tree.

  • modules (list of fortran.Module, default None) – A list of modules within the parse tree

  • procedures (list of fortran.Procedure, default None) – A list of top-level procedures within the parse tree.

class f90wrap.fortran.Subroutine(name='', filename='', doc=None, lineno=0, arguments=None, uses=None, attributes=None, mod_name=None, type_name=None)[source]

Bases: Procedure

Represents a Fortran Subroutine.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • arguments (list of fortran.Argument) – A list of arguments to the procedure

  • uses (list of str or tuple , default None) – A list of modules that this procedure uses. If the entry is a tuple, it should be in the form (uses,only,[only,..]), where the only entries are subroutines/elements in the used module.

  • attributes (list of str, default None) – Attributes of the procedure

  • mod_name (str , default None) – The name of the module in which the procedure is found, if any.

  • type_name (str , default None) – The name of the type in which the procedure is defined, if any.

class f90wrap.fortran.Type(name='', filename='', doc=None, lineno=0, elements=None, procedures=None, bindings=None, interfaces=None, mod_name=None, parent=None)[source]

Bases: Fortran

Represents a Fortran Derived-type.

Parameters:
  • name (str, default "") – Name of the node

  • filename (str, default "") – Name of the file in which node is defined

  • doc (list of str, default None) – Documentation found in the node

  • lineno (int, default 0.) – Line number at which the node begins.

  • elements (list of fortran.Element) – Variables within the type

  • procedures (list of fortran.Procedure) – Procedures defined with the type.

  • parent (list of fortran.Type , default ``None`) – Type from which current type inherite.

f90wrap.fortran.derived_typename(typename)[source]

type(TYPE) -> TYPE class(TYPE) -> TYPE otherwise -> None

f90wrap.fortran.dump(node)[source]

Print contents of Fortran parse tree starting at node.

f90wrap.fortran.f2c_type(typename, kind_map)[source]

Convert string repr of Fortran type to equivalent C type

Kind constants defined in kind_map are expanded, and a RuntimeError is raised if a undefined (type, kind) combination is encountered.

f90wrap.fortran.f2numpy_type(typename, kind_map)[source]

Convert string repr of Fortran type to equivalent numpy array type

f90wrap.fortran.f2py_type(type, attributes=None)[source]

Convert string repr of Fortran type to equivalent Python type

f90wrap.fortran.find(tree, pattern)[source]

Find a node whose name includes pattern

f90wrap.fortran.find_procedure_module(tree, node)[source]

Find the module in tree that contains node

f90wrap.fortran.find_source(node)[source]

Locate source code for node. Returns a list of strings.

f90wrap.fortran.find_types(tree, skipped_types=None)[source]
Walk over all the nodes in tree, building up a dictionary:

types: maps type names to Type instances

Returns a pair (types, types_to_mod_names)

f90wrap.fortran.fix_argument_attributes(node)[source]

Walk over all procedures in the tree starting at node and fix the argument attributes.

f90wrap.fortran.fortran_array_type(typename, kind_map)[source]

Convert string repr of Fortran type to equivalent numpy array typenum

f90wrap.fortran.is_class(typename)[source]
f90wrap.fortran.is_derived_type(typename)[source]
f90wrap.fortran.iter_child_nodes(node)[source]

Yield all direct child nodes of node, that is, all fields that are nodes and all items of fields that are lists of nodes.

f90wrap.fortran.iter_fields(node)[source]

Yield a tuple of (fieldname, value) for each field in node._fields that is present on node.

f90wrap.fortran.normalise_type(typename, kind_map)[source]

Normalise Fortran type names, expanding kind constants defined in kind_map

real(kind=dp) -> real(8), etc.

f90wrap.fortran.print_source(node, out=None)[source]

Print source code for node to out (default is sys.stdout).

f90wrap.fortran.remove_private_symbols(node)[source]

Walk the tree starting at node, removing all private symbols.

This function first applies the AccessUpdater transformer to ensure module public_symbols and private_symbols are up to date with default_access and individual public and private attributes.

f90wrap.fortran.split_type_kind(typename)[source]

type*kind -> (type, kind) type(kind) -> (type, kind) type(kind=kind) -> (type, kind) character(len=*) -> (character, *)

f90wrap.fortran.strip_type(t)[source]

Return type name from type declaration

f90wrap.fortran.walk(node)[source]

Recursively yield all descendant nodes in the tree starting at node (including node itself), in no specified order. This is useful if you only want to modify nodes in place and don’t care about the context.

f90wrap.fortran.walk_modules(node)[source]

Recursively yield all modules in the tree starting at node.

f90wrap.fortran.walk_procedures(tree, include_ret_val=True)[source]

Walk over all nodes in tree and yield tuples (module, procedure, arguments).

If include_ret_val is true then Function return values are inserted after last non-optional argument.