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:
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 attibutes.
- class f90wrap.fortran.Argument(name='', filename='', doc=None, lineno=0, attributes=None, type='', value='', doxygen='')[source]¶
Bases:
DeclarationRepresents a Procedure Argument.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.type (str , default
"") – The type of the declarationattributes (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.Binding(name='', filename='', doc=None, lineno=0, type=None, attributes=None, procedures=None, mod_name=None, type_name=None)[source]¶
Bases:
FortranRepresents a type procedure binding.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (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:
FortranBase class representing a declaration statement
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.type (str , default
"") – The type of the declarationattributes (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:
DeclarationRepresents a Module or Derived-Type Element.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.type (str , default
"") – The type of the declarationattributes (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:
objectAbstract base class for all nodes in Fortran parser tree.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.
- class f90wrap.fortran.FortranTransformer[source]¶
Bases:
FortranVisitorSubclass 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.
- class f90wrap.fortran.FortranTreeDumper[source]¶
Bases:
FortranVisitorSubclass of FortranVisitor which prints a textual representation of the Fortran parse tree.
- class f90wrap.fortran.FortranVisitor[source]¶
Bases:
objectImplementation 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.
- 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:
ProcedureRepresents a Fortran Function.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.arguments (list of
fortran.Argument) – A list of arguments to the procedureuses (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 proceduremod_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 valueret_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:
FortranRepresents a Fortran Interface.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (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:
FortranTransformerSubclass 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.
- 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:
FortranRepresents a Fortran module.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.types (list of
fortran.Type, defaultNone) – Derived-types defined in the moduleelements (list of
fortran.Element, defaultNone) – Module-level variables in the moduleprocedures (list of
fortran.Procedure, defaultNone) – A list of procedures defined in the moduleinterfaces (list of
fortran.Interface, defaultNone) – A list of interfaces defined in the moduleuses (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 publicprivate_symbols (list of str , default
None) – The symbols within the module that are privatemod_depends (list of
fortran.Module, defaultNone) – Module on which current module depends
- class f90wrap.fortran.PrivateSymbolsRemover[source]¶
Bases:
FortranTransformerTransform a tree by removing private symbols.
- class f90wrap.fortran.Procedure(name='', filename='', doc=None, lineno=0, arguments=None, uses=None, attributes=None, mod_name=None, type_name=None)[source]¶
Bases:
FortranRepresents a Fortran Function or Subroutine.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.arguments (list of
fortran.Argument) – A list of arguments to the procedureuses (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 proceduremod_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:
FortranClass to represent a Fortran main program.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.procedures (list of
fortran.Procedure, defaultNone) – A list of procedures within the program’s scope.
- class f90wrap.fortran.Prototype(name='', filename='', doc=None, lineno=0, doxygen='')[source]¶
Bases:
FortranRepresents a Fortran Prototype.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.
- class f90wrap.fortran.RepeatedInterfaceCollapser[source]¶
Bases:
FortranTransformerCollapse repeated interfaces with the same name into a single interface
- class f90wrap.fortran.Root(name='', filename='', doc=None, lineno=0, programs=None, modules=None, procedures=None)[source]¶
Bases:
FortranThe Root node of a Fortan parse tree
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (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 treeprocedures (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:
ProcedureRepresents a Fortran Subroutine.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.arguments (list of
fortran.Argument) – A list of arguments to the procedureuses (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 proceduremod_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:
FortranRepresents a Fortran Derived-type.
- Parameters:
name (str, default
"") – Name of the nodefilename (str, default
"") – Name of the file in which node is defineddoc (list of str, default
None) – Documentation found in the nodelineno (int, default
0.) – Line number at which the node begins.elements (list of
fortran.Element) – Variables within the typeprocedures (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.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_procedure_module(tree, node)[source]¶
Find the module in tree that contains node
- 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.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 innode._fieldsthat 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.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.