f90wrap.transform module¶
- class f90wrap.transform.AccessUpdater(force_public=None)[source]¶
Bases:
FortranTransformerVisit 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 statement in types; (iv) public and private attributes of individual elements.
- class f90wrap.transform.ArgumentNameConflictResolver[source]¶
Bases:
FortranTransformerResolves name conflicts between procedure arguments and USE-imported symbols.
When f90wrap generates wrappers, it creates use module_name statements that import ALL symbols from a module. This can cause Fortran name collisions when an argument has the same name as another procedure in the same module.
This transformer detects such conflicts and renames arguments with an _in suffix.
- class f90wrap.transform.ArrayDimensionConverter[source]¶
Bases:
FortranVisitorTransform unspecified dimensions into additional dummy arguments
e.g. the following code
- subroutine foo(a)
integer a(:)
end subroutine foo
becomes:
- subroutine foo(a, n0)
integer a(n0) integer n0 !f2py intent(hide), depend(a) :: n0 = shape(a,0)
end subroutine foo
- valid_dim_re = re.compile('^(((\\d+:)?\\d+)|([-0-9.e]+)|(size\\([_a-zA-Z0-9\\+\\-\\*\\/,]*\\))|(len\\(.*\\)))$')¶
- class f90wrap.transform.BindConstructorInterfaces[source]¶
Bases:
FortranTransformerMoves interfaces named after a type into that type and marks as constructor.
The Fortran idiom for defining custom constructors is to create an interface with the same name as the type which references one or more free functions that return initialized instances of the type. This transformer locates such interfaces, moves them into the type, and marks them as constructors.
- class f90wrap.transform.ConstructorExcessToClassMethod[source]¶
Bases:
FortranTransformerHandle classes with multiple constructors
Count the number of constructors per class and choose only one. Method of choice: the one with the shortest name. The rest are relabeled to classmethods
- visit_Module(node)¶
- class f90wrap.transform.DuplicateAbstractImplementation[source]¶
Bases:
FortranVisitorDuplicate bound procedure node from abstract class to childs type
- class f90wrap.transform.FunctionToSubroutineConverter[source]¶
Bases:
FortranTransformerConvert all functions to subroutines, with return value as an intent(out) argument after the last non-optional argument
- class f90wrap.transform.IntentOutToReturnValues[source]¶
Bases:
FortranTransformerConvert all Subroutine and Function intent(out) arguments to return values
- class f90wrap.transform.LinkBoundDType[source]¶
Bases:
FortranVisitorAdd bound info in procedure nodes
- class f90wrap.transform.MethodFinder(types, constructor_names, destructor_names, short_names, move_methods, shorten_routine_names=True, modules_for_type=None)[source]¶
Bases:
FortranTransformer
- class f90wrap.transform.NormaliseTypes(kind_map)[source]¶
Bases:
FortranVisitorConvert all type names to standard form and resolve kind names
- visit_Argument(node)¶
- class f90wrap.transform.OnlyAndSkip(kept_subs, kept_mods)[source]¶
Bases:
FortranTransformerThis class does the job of removing nodes from the tree which are not necessary to write wrappers for (given user-supplied values for only and skip).
Currently it takes a list of subroutines and a list of modules to write wrappers for. If empty, it does all of them.
- class f90wrap.transform.PrivateSymbolsRemover[source]¶
Bases:
FortranTransformerTransform a tree by removing private symbols
- visit_Element(node)¶
- visit_Type(node)¶
- class f90wrap.transform.RenameArgumentsPython(types)[source]¶
Bases:
FortranVisitor
- class f90wrap.transform.RenameInterfacesBindingsPython[source]¶
Bases:
FortranVisitor
- class f90wrap.transform.RenameReservedWords(types, name_map=None)[source]¶
Bases:
FortranVisitor- visit_Element(node)¶
- visit_Module(node)¶
- visit_Procedure(node)¶
- visit_Type(node)¶
- class f90wrap.transform.ReorderForInheritance[source]¶
Bases:
FortranVisitorReorder so that parent classes are defined defore child
- class f90wrap.transform.ReorderOptionalArgumentsPython[source]¶
Bases:
FortranVisitorMove optional arguments after non-optional arguments: in Fortran they can come in any order, but in Python optional arguments must come at the end of argument list.
- class f90wrap.transform.ResolveBindingPrototypes[source]¶
Bases:
FortranTransformerReplaces prototypes in type binding declarations with referenced procedure.
- FIXME: Fortran allows module procedures to be bound to more than one type
procedure, i.e. x%fun1() and x%fun2() can both bind to module procedure x_fun(). The approach below only support 1-to-1 mappings.
- class f90wrap.transform.ResolveInterfacePrototypes[source]¶
Bases:
FortranTransformerReplaces prototypes in interface declarations with referenced procedure
- class f90wrap.transform.SetInterfaceProcedureCallNames[source]¶
Bases:
FortranVisitorSet call names of procedures within overloaded interfaces to the name of the interface
- class f90wrap.transform.StringLengthConverter(string_lengths, default_string_length)[source]¶
Bases:
FortranVisitorConvert lengths of all character strings to standard format
Looks in all Procedure arguments and Type elements. Changes from ‘(len=*)’ or ‘(*)’ syntax to () syntax.
- class f90wrap.transform.UnwrappablesRemover(callbacks, types, constructors, destructors, remove_optional_arguments)[source]¶
Bases:
FortranTransformer
- f90wrap.transform.collapse_single_interfaces(tree, keep_single_interfaces=False)[source]¶
Collapse interfaces which contain only a single procedure.
- f90wrap.transform.convert_array_intent_out_to_intent_inout(tree)[source]¶
Find all intent(out) array arguments and convert to intent(inout)
- f90wrap.transform.find_inheritence_relations(tree)[source]¶
Fill child and parent member with fortran inheritences
- f90wrap.transform.find_referenced_modules(mods, tree)[source]¶
Given a set of modules in a parse tree, find any modules (recursively) used by these.
- f90wrap.transform.find_referenced_types(mods, tree)[source]¶
Given a set of modules in a parse tree, find any types either defined in or referenced by the module, recursively.
- Parameters:
mods (set) – initial modules to search, must be included in the tree.
tree (fortran.Root object.)
tree – the full fortran parse tree from which the mods have been taken.
- Returns:
kept_types – modules given, or recursively referenced by those types.
- Return type:
set of Type() objects which are referenced or defined in the
- f90wrap.transform.fix_element_uses_clauses(tree, types)[source]¶
Add uses clauses to derived type elements in modules
- f90wrap.transform.fix_subroutine_uses_clauses(tree, types)[source]¶
Walk over all nodes in tree, updating subroutine uses clauses to include the parent module and all necessary modules from types
Also rename any arguments that clash with module names.
- f90wrap.transform.procedures_and_abstract_interfaces(procedure_map, node)[source]¶
Add procedures from abstract interfaces to the procedure map
This is needed because abstract interfaces are not included in the module interfaces list, and so are not resolved by ResolveInterfacePrototypes.
- f90wrap.transform.remove_private_symbols(node, force_public=None)[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.transform.set_intent(attributes, intent)[source]¶
Remove any current “intent” from attributes and replace with intent given
- f90wrap.transform.transform_to_f90_wrapper(tree, types, callbacks, constructors, destructors, short_names, init_lines, string_lengths, default_string_length, sizeof_fortran_t, kind_map)[source]¶
- Additional Fortran-specific transformations:
Conversion of derived type arguments to opaque integer arrays via Fortran transfer() intrinsic.
Normalise type declarations
- f90wrap.transform.transform_to_generic_wrapper(tree, types, callbacks, constructors, destructors, short_names, init_lines, kept_subs, kept_mods, argument_name_map, move_methods, shorten_routine_names, modules_for_type, remove_optional_arguments, force_public=None, keep_single_interfaces=False)[source]¶
Apply a number of rules to tree to make it suitable for passing to a F90 and Python wrapper generators. Transformations performed are:
Removal of procedures and modules not provided by the user
Removal of private symbols
Removal of unwrappable routines and optional arguments
Addition of missing constructor and destructor wrappers
Conversion of all functions to subroutines
Updating call names of procedures within interfaces
Update of subroutine uses clauses