f90wrap.f90wrapgen module

class f90wrap.f90wrapgen.F90WrapperGenerator(prefix, sizeof_fortran_t, string_lengths, abort_func, kind_map, types, default_to_inout, max_length=None, auto_raise=None, default_string_length=None, direct_c_interop=None, toplevel_basename='toplevel')[source]

Bases: FortranVisitor, CodeGenerator

Creates the Fortran90 code necessary to wrap a given Fortran parse tree suitable for input to f2py.

Each node of the tree (Module, Subroutine etc.) is wrapped according to the rules in this class when visited (using F90WrapperGenerator.visit()).

Each module’s wrapper is written to a separate file, with top-level procedures written to another separate file. Derived-types and arrays (both of normal types and derive-types) are specially treated. For each, a number of subroutines allowing the getting/setting of items, and retrieval of array length are written. Furthermore, derived-types are treated as opaque references to enable wrapping with f2py.

Parameters:
  • prefix (str) – A string with which to prefix module, subroutine and type names.

  • sizeof_fortran_t (int) – The size, in bytes, of a pointer to a fortran derived type ??

  • string_lengths (dict) – This is never used…

  • abort_func (str) – Name of a Fortran function to be invoked when a fatal error occurs

  • kind_map (dict) – Dictionary mapping Fortran types and kinds to C-types

  • types (dict) – Dictionary mapping type names to Fortran modules where they are defined

is_class(tname)[source]
visit_Module(node)[source]

Wrap modules. Each Fortran module generates one wrapper source file.

Subroutines and elements within each module are properly wrapped.

visit_Procedure(node)[source]

Write wrapper code necessary for a Fortran subroutine or function

visit_Root(node)[source]

Write a wrapper for top-level procedures.

visit_Type(node)[source]

Properly wraps derived types, including derived-type arrays.

write_arg_decl_lines(node, helper_forward=False)[source]

Write argument declaration lines to the code

Takes care of argument attributes, and opaque references for derived types, as well as f2py-specific lines.

write_call_lines(node, func_name, helper_forward=False)[source]

Write line that calls a single wrapped Fortran routine

write_class_lines(cname, recursive=False, *, pointer=False)[source]

Write a pointer type for a given class name

Parameters:

tname (str) – Should be the name of a class in the wrapped code.

write_finalise_lines(node)[source]

Deallocate the opaque reference to clean up.

write_init_lines(node)[source]

Write special user-provided init lines to a node.

write_super_type_lines(ty)[source]
write_transfer_in_lines(node)[source]

Write transfer of opaque references.

write_transfer_out_lines(node)[source]

Write transfer from opaque reference.

write_type_lines(tname, recursive=False, tname_inner=None, *, pointer=False)[source]

Write a pointer type for a given type name

Parameters:
  • tname (str) – Should be the name of a derived type in the wrapped code.

  • recursive (boolean) – Adjusts array pointer for recursive derived type array

write_type_or_class_lines(tname, recursive=False, *, pointer=False)[source]
write_uses_lines(node, extra_uses_dict=None)[source]

Write “uses mod, only: sub” lines to the code.

Parameters:

node (Node of parse tree)