loki.frontend.fparser

Module Attributes

HAVE_FP

Indicate whether fparser frontend is available.

Functions

extract_fparser_source(node, raw_source)

Extract the Source object for any fparser.two.utils.BlockBase from the raw source string.

get_fparser_node(ast, node_type_name[, ...])

Extract child nodes with type given by node_type_name from an fparser parse tree

node_sublist(nodelist, starttype, endtype)

Extract a subset of nodes from a list that sits between marked start and end nodes.

parse_fparser_ast(ast, raw_source[, ...])

Generate an internal IR from fparser parse tree

parse_fparser_expression(source, scope)

Parse an expression string into an expression tree.

parse_fparser_file(filename)

Generate a parse tree from file via fparser

parse_fparser_source(source)

Generate a parse tree from string

rget_child(node, node_type)

Searches for the last, immediate child of the supplied node that is of the specified type.

Classes

FParser2IR(raw_source[, definitions, ...])

HAVE_FP = True

Indicate whether fparser frontend is available.

class FParser2IR(raw_source, definitions=None, pp_info=None, scope=None)

Bases: GenericVisitor

static warn_or_fail(msg)
get_source(o, source)

Helper method that builds the source object for the node.

get_block_source(start_node, end_node)

Helper method that builds the source object for a block node.

get_label(o)

Helper method that returns the label of the node.

visit(o, **kwargs)

Generic dispatch method that tries to generate meta-data from source.

visit_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Intrinsic_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Specification_Part(o, **kwargs)

The specification part of a program-unit

fparser.two.Fortran2003.Specification_Part has variable number of children making up the body of the spec.

visit_Implicit_Part(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Program(o, **kwargs)

The specification part of a program-unit

fparser.two.Fortran2003.Specification_Part has variable number of children making up the body of the spec.

visit_Execution_Part(o, **kwargs)

The specification part of a program-unit

fparser.two.Fortran2003.Specification_Part has variable number of children making up the body of the spec.

visit_Internal_Subprogram_Part(o, **kwargs)

The specification part of a program-unit

fparser.two.Fortran2003.Specification_Part has variable number of children making up the body of the spec.

visit_Module_Subprogram_Part(o, **kwargs)

The specification part of a program-unit

fparser.two.Fortran2003.Specification_Part has variable number of children making up the body of the spec.

visit_Name(o, **kwargs)

A symbol name

fparser.two.Fortran2003.Name has no children.

visit_Type_Name(o, **kwargs)

A derived type name

fparser.two.Fortran2003.Type_Name has no children.

visit_Part_Ref(o, **kwargs)

A part of a data ref (e.g., flat variable or array name, or name of a derived type variable or member) and, optionally, a subscript list

fparser.two.Fortran2003.Part_Ref has two children:

visit_Data_Ref(o, **kwargs)

A fully qualified name for accessing a derived type or class member, composed from individual fparser.two.Fortran2003.Part_Ref as part-ref [% part-ref [% part-ref ...] ]

fparser.two.Fortran2003.Data_Ref has variable number of children, depending on the number of part-ref.

visit_Use_Stmt(o, **kwargs)

An import of symbol names via USE

fparser.two.Fortran2003.Use_Stmt has five children:

  • module-nature (str: ‘INTRINSIC’ or ‘NON_INTRINSIC’ or None if absent)

  • ‘::’ (str) if a double colon is used, otherwise None

  • module-name fparser.two.Fortran2003.Module_Name

followed by

  • ‘, ONLY:’ (str) and fparser.two.Fortran2003.Only_List, or

  • ‘,’ (str) and fparser.two.Fortran2003.Rename_List, or

  • ‘’ (str) and no only-list or rename-list

visit_Only_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Rename_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Rename(o, **kwargs)

A rename of an imported symbol

fparser.two.Fortran2003.Rename has three children:

visit_Type_Declaration_Stmt(o, **kwargs)

Variable declaration statement

fparser.two.Fortran2003.Type_Declaration_Stmt has 3 children:

visit_Intrinsic_Type_Spec(o, **kwargs)

An intrinsic type

fparser.two.Fortran2003.Intrinsic_Type_Spec has 2 children:

visit_Kind_Selector(o, **kwargs)

A kind selector of an intrinsic type

fparser.two.Fortran2003.Kind_Selector has 2 or 3 children:

visit_Length_Selector(o, **kwargs)

A length selector for intrinsic character type

fparser.two.Fortran2003.Length_Selector has 3 children:

visit_Char_Length(o, **kwargs)

Length specifier in the Length_Selector

fparser.two.Fortran2003.Length_Selector has one child:

  • length value (str)

visit_Char_Selector(o, **kwargs)

Length- and kind-selector for intrinsic character type

fparser.two.Fortran2003.Char_Selector has 2 children:

visit_Type_Param_Value(o, **kwargs)

The value of a type parameter in a type spefication (such as length of a CHARACTER)

fparser.two.Fortran2003.Type_Param_Value has only 1 attribute:

  • string : the value of the parameter (str)

visit_Declaration_Type_Spec(o, **kwargs)

A derived type specifier in a declaration

fparser.two.Fortran2003.Declaration_Type_Spec has 2 children:

visit_Dimension_Attr_Spec(o, **kwargs)

The dimension specification as attribute in a declaration

fparser.two.Fortran2003.Dimensions_Attr_Spec has 2 children:

visit_Intent_Attr_Spec(o, **kwargs)

The intent specification in a declaration

fparser.two.Fortran2003.Intent_Attr_Spec has 2 children:

visit_Attr_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Attr_Spec(o, **kwargs)

A declaration attribute

fparser.two.Fortran2003.Attr_Spec has no children.

visit_Access_Spec(o, **kwargs)

A declaration attribute for access specification (PRIVATE, PUBLIC)

fparser.two.Fortran2003.Access_Spec has no children.

visit_Entity_Decl_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Entity_Decl(o, **kwargs)

A variable entity in a declaration

fparser.two.Fortran2003.Entity_Decl has 4 children:

visit_Explicit_Shape_Spec(o, **kwargs)

Explicit shape specification for arrays

fparser.two.Fortran2003.Explicit_Shape_Spec has 2 children:

  • lower bound (if explicitly given)

  • upper bound

visit_Explicit_Shape_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Assumed_Shape_Spec(o, **kwargs)

Explicit shape specification for arrays

fparser.two.Fortran2003.Explicit_Shape_Spec has 2 children:

  • lower bound (if explicitly given)

  • upper bound

visit_Assumed_Shape_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Assumed_Size_Spec(o, **kwargs)

Explicit shape specification for arrays

fparser.two.Fortran2003.Explicit_Shape_Spec has 2 children:

  • lower bound (if explicitly given)

  • upper bound

visit_Deferred_Shape_Spec(o, **kwargs)

Explicit shape specification for arrays

fparser.two.Fortran2003.Explicit_Shape_Spec has 2 children:

  • lower bound (if explicitly given)

  • upper bound

visit_Deferred_Shape_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Initialization(o, **kwargs)

Variable initialization in declaration

fparser.two.Fortran2003.Initialization has 2 children:

  • ‘=’ or ‘=>’ (str)

  • init expr

visit_Component_Initialization(o, **kwargs)

Variable initialization in declaration

fparser.two.Fortran2003.Initialization has 2 children:

  • ‘=’ or ‘=>’ (str)

  • init expr

visit_External_Stmt(o, **kwargs)

An EXTERNAL statement to specify the external attribute for a list of names

fparser.two.Fortran2003.External_Stmt has 2 children:

  • keyword ‘EXTERNAL (str)

  • the list of names fparser.two.Fortran2003.External_Name_List

visit_External_Name_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Access_Stmt(o, **kwargs)

An access-spec statement that specifies accessibility of symbols in a module

faprser.two.Fortran2003.Access_Stmt has 2 children:

  • keyword PRIVATE or PUBLIC (str)

  • optional list of names (fparser.two.Fortran2003.Access_Id_List) or None

visit_Procedure_Declaration_Stmt(o, **kwargs)

Procedure declaration statement

fparser.two.Fortran2003.Procedure_Declaration_Stmt has 3 children:

  • fparser.two.Fortran2003.Name: the name of the procedure interface

  • fparser.two.Fortran2003.Proc_Attr_Spec_List or None: the declared attributes (if any)

  • fparser.two.Fortran2003.Proc_Decl_List: the local procedure names

visit_Proc_Attr_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Proc_Attr_Spec(o, **kwargs)

Procedure declaration attribute

fparser.two.Fortran2003.Proc_Attr_Spec has 2 children:

  • attribute name (str)

  • attribute value (such as IN, OUT, INOUT) or None

visit_Proc_Decl_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Proc_Decl(o, **kwargs)

A symbol entity in a procedure declaration with initialization

fparser.two.Fortran2003.Proc_Decl has 3 children:

visit_Array_Constructor(o, **kwargs)

An array constructor expression

fparser.two.Fortran2003.Array_Constructor has three children:

visit_Ac_Spec(o, **kwargs)

The spec in an array constructor

fparser.two.Fortran2003.Ac_Spec has two children: * fparser.two.Fortran2003.Type_Spec or None * fparser.two.Fortran2003.Ac_Value_List

visit_Ac_Value_List(o, **kwargs)

The list of values in an array constructor

visit_Ac_Implied_Do(o, **kwargs)

An implied-do for array constructors

fparser.two.Fortran2003.Ac_Implied_Do has two children: * the expression as fparser.two.Fortran2003.Ac_Value_List * the loop control as fparser.two.Fortran2003.Ac_Implied_Do_Control

visit_Ac_Implied_Do_Control(o, **kwargs)

The “loop control” for an implied-do

fparser.two.Fortran2003.Ac_Implied_Do_Control has two children: * the variable name * the loop bounds

visit_Data_Stmt(o, **kwargs)

A DATA statement

fparser.two.Fortran2003.Data_Stmt has variable number of children fparser.two.Fortran2003.Data_Stmt_Set.

visit_Data_Stmt_Set(o, **kwargs)

A data-stmt-set in a data-stmt

fparser.two.Fortran2003.Data_Stmt_Set has two children:

visit_Data_Implied_Do(o, **kwargs)

An implied-do for data-stmt

visit_Data_Stmt_Object_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Data_Stmt_Value_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Data_Stmt_Value(o, **kwargs)

A value in a data-stmt-set

fparser.two.Fortran2003.Data_Stmt_Value has two children:

visit_Section_Subscript_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Subscript_Triplet(o, **kwargs)

A subscript expression with [start] : [stop] [: stride]

fparser.two.Fortran2003.Subscript_Triplet has three children:

visit_Array_Section(o, **kwargs)

A subscript operation on a data-ref

This includes dereferences such as a%b%c or extracting a substring. In practice, the first are typically flattened in the Fparser AST and directly returned as Part_Ref, so we should see only the substring operation here.

fparser.two.Fortran2003.Array_Subscript has two children:

visit_Substring_Range(o, **kwargs)

The range of a substring operation

fparser.two.Fortran2003.Substring_Range has two children:

  • start fparser.two.Fortran2003.Scalar_Int_Expr or None

  • stop fparser.two.Fortran2003.Scalar_Int_Expr or None

visit_Stride(o, **kwargs)
visit_Derived_Type_Def(o, **kwargs)

A derived type definition

fparser.two.Fortran2003.Derived_Type_Def has variable number of children:

visit_Derived_Type_Stmt(o, **kwargs)

The block header for the derived type definition

fparser.two.Fortran2003.Derived_Type_Stmt has 3 children:

  • attribute spec list (fparser.two.Fortran2003.Type_Attr_Spec_List)

  • type name (fparser.two.Fortran2003.Type_Name)

  • parameter name list (fparser.two.Fortran2003.Type_Param_Name_List)

visit_Type_Attr_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Type_Attr_Spec(o, **kwargs)

A component declaration attribute

fparser.two.Fortran2003.Type_Attr_Spec has 2 children:

  • keyword (str)

  • value (str) or None

visit_Type_Param_Def_Stmt(o, **kwargs)
visit_Binding_Attr_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Binding_Attr(o, **kwargs)

A binding attribute

fparser.two.Fortran2003.Binding_Attr_Spec has no children

visit_Binding_PASS_Arg_Name(o, **kwargs)

Named PASS attribute

fparser.two.Fortran2003.Binding_PASS_Arg_Name has two children:

  • str: ‘PASS’

  • Name: the argument name

visit_Component_Part(o, **kwargs)

Derived type definition components

fparser.two.Fortran2003.Component_Part has a list of fparser.two.Fortran2003.Data_Component_Def_Stmt or fparser.two.Fortran2003.Proc_Component_Def_Stmt as children

visit_Data_Component_Def_Stmt(o, **kwargs)

Variable declaration statement

fparser.two.Fortran2003.Type_Declaration_Stmt has 3 children:

visit_Component_Attr_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Component_Attr_Spec(o, **kwargs)

A declaration attribute

fparser.two.Fortran2003.Attr_Spec has no children.

visit_Dimension_Component_Attr_Spec(o, **kwargs)

The dimension specification as attribute in a declaration

fparser.two.Fortran2003.Dimensions_Attr_Spec has 2 children:

visit_Component_Decl_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Component_Decl(o, **kwargs)

A variable entity in a declaration

fparser.two.Fortran2003.Entity_Decl has 4 children:

visit_Proc_Component_Def_Stmt(o, **kwargs)

Procedure declaration statement

fparser.two.Fortran2003.Procedure_Declaration_Stmt has 3 children:

  • fparser.two.Fortran2003.Name: the name of the procedure interface

  • fparser.two.Fortran2003.Proc_Attr_Spec_List or None: the declared attributes (if any)

  • fparser.two.Fortran2003.Proc_Decl_List: the local procedure names

visit_Proc_Component_Attr_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Proc_Component_Attr_Spec(o, **kwargs)

A declaration attribute

fparser.two.Fortran2003.Attr_Spec has no children.

visit_Type_Bound_Procedure_Part(o, **kwargs)

Procedure definitions part in a derived type definition

fparser.two.Fortran2003.Type_Bound_Procedure_Part starts with the contains-stmt (fparser.two.Fortran2003.Contains_Stmt) followed by (optionally) fparser.two.Fortran2003.Binding_Private_Stmt and a sequence of fparser.two.Fortran2003.Proc_Binding_Stmt

visit_Specific_Binding(o, **kwargs)

A specific binding for a type-bound procedure in a derived type

fparser.two.Fortran2003.Specific_Binding has five children:

  • interface name fparser.two.Fortran2003.Interface_Name

  • binding attr list fparser.two.Fortran2003.Binding_Attr_List

  • ‘::’ (str) or None

  • name fparser.two.Fortran2003.Binding_Name

  • procedure name fparser.two.Fortran2003.Procedure_Name

visit_Generic_Binding(o, **kwargs)

A generic binding for a type-bound procedure in a derived type

fparser.two.Fortran2003.Generic_Binding has three children:

visit_Final_Binding(o, **kwargs)

A final binding for type-bound procedures in a derived type

fparser.two.Fortran2003.Final_Binding has two children:

  • keyword 'FINAL' (str)

  • fparser.two.Fortran2003.Final_Subroutine_Name_List (the list of routines)

visit_Binding_Name_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Final_Subroutine_Name_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Contains_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Binding_Private_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Private_Components_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Sequence_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Associate_Construct(o, **kwargs)

The entire ASSOCIATE construct

fparser.two.Fortran2003.Associate_Construct has a variable number of children:

visit_Associate_Stmt(o, **kwargs)

The ASSOCIATE statement with the association list

fparser.two.Fortran2003.Associate_Stmt has two children:

  • The command ASSOCIATE (str)

  • The fparser.two.Fortran2003.Association_List defining the associations

visit_Association_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Association(o, **kwargs)

A single association in an associate-stmt

fparser.two.Fortran2003.Associate has two children:

visit_Interface_Block(o, **kwargs)

An INTERFACE block

fparser.two.Fortran2003.Interface_Block has variable number of children:

visit_Interface_Stmt(o, **kwargs)

The specification of the interface

fparser.two.Fortran2003.Interface_Stmt has one child, which is either:

visit_Generic_Spec(o, **kwargs)

The generic-spec of an interface

fparser.two.Fortran2003.Generic_Spec has two children, which is either:

-or-

  • 'ASSIGNMENT' (str) followed by

  • '=' (str)

visit_Procedure_Stmt(o, **kwargs)

Procedure statement

fparser.two.Fortran2003.Procedure_Stmt has 1 child:

  • fparser.two.Fortran2003.Procedure_Name_List: the names of the procedures

visit_Procedure_Name_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Procedure_Name(o, **kwargs)

A symbol name

fparser.two.Fortran2003.Name has no children.

visit_Import_Stmt(o, **kwargs)

An import statement for named entities in an interface body

fparser.two.Fortran2003.Import_Stmt has two children:

  • The string 'IMPORT'

  • fparser.two.Fortran2003.Import_Name_List with the names of imported entities

visit_Import_Name_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Import_Name(o, **kwargs)

A symbol name

fparser.two.Fortran2003.Name has no children.

visit_Main_Program(o, **kwargs)

The entire block that comprises a PROGRAM definition

Loki does currently not have support for PROGRAM blocks, and this will raise a NotImplementedError

visit_Subroutine_Subprogram(o, **kwargs)

The entire block that comprises a SUBROUTINE definition, i.e. everything from the subroutine-stmt to the end-stmt

fparser.two.Fortran2003.Subroutine_Subprogram has variable number of children, where the internal nodes may be optional:

visit_Function_Subprogram(o, **kwargs)

The entire block that comprises a SUBROUTINE definition, i.e. everything from the subroutine-stmt to the end-stmt

fparser.two.Fortran2003.Subroutine_Subprogram has variable number of children, where the internal nodes may be optional:

visit_Subroutine_Body(o, **kwargs)

The entire block that comprises a SUBROUTINE definition, i.e. everything from the subroutine-stmt to the end-stmt

fparser.two.Fortran2003.Subroutine_Subprogram has variable number of children, where the internal nodes may be optional:

visit_Function_Body(o, **kwargs)

The entire block that comprises a SUBROUTINE definition, i.e. everything from the subroutine-stmt to the end-stmt

fparser.two.Fortran2003.Subroutine_Subprogram has variable number of children, where the internal nodes may be optional:

visit_Subroutine_Stmt(o, **kwargs)

The SUBROUTINE statement

fparser.two.Fortran2003.Subroutine_Stmt has four children:

visit_Function_Stmt(o, **kwargs)

The SUBROUTINE statement

fparser.two.Fortran2003.Subroutine_Stmt has four children:

visit_Subroutine_Name(o, **kwargs)

A symbol name

fparser.two.Fortran2003.Name has no children.

visit_Function_Name(o, **kwargs)

A symbol name

fparser.two.Fortran2003.Name has no children.

visit_Dummy_Arg_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Prefix(o, **kwargs)

The prefix of a subprogram definition

fparser.two.Fortran2003.Prefix has variable number of children that have the type

visit_Prefix_Spec(o, **kwargs)

A prefix keyword in a subprogram definition

fparser.two.Fortran2003.Prefix_Spec has no children

visit_Suffix(o, **kwargs)

The suffix of a subprogram statement

fparser.two.Fortran2003.Suffix has two children:

visit_Language_Binding_Spec(o, **kwargs)

A language binding spec suffix

fparser.two.Fortran2003.Language_Binding_Spec has a single child:

visit_Module(o, **kwargs)

The definition of a Fortran module

fparser.two.Fortran2003.Module has up to four children:

visit_Module_Stmt(o, **kwargs)

The MODULE statement

fparser.two.Fortran2003.Module_Stmt has 2 children:
  • keyword MODULE (str)

  • name fparser.two.Fortran2003.Module_Name

visit_Module_Name(o, **kwargs)

A symbol name

fparser.two.Fortran2003.Name has no children.

visit_If_Construct(o, **kwargs)

The entire IF construct

fparser.two.Fortran2003.If_Construct has variable number of children:

visit_If_Then_Stmt(o, **kwargs)

The first conditional in a IF construct

fparser.two.Fortran2003.If_Then_Stmt has one child: the condition expression

visit_Else_If_Stmt(o, **kwargs)

The first conditional in a IF construct

fparser.two.Fortran2003.If_Then_Stmt has one child: the condition expression

visit_If_Stmt(o, **kwargs)

An inline IF statement with a single statement as body

fparser.two.Fortran2003.If_Stmt has two children:

  • the condition expression

  • the body

visit_Case_Construct(o, **kwargs)

The entire SELECT CASE construct

fparser.two.Fortran2003.Case_Construct has variable number of children:

visit_Select_Case_Stmt(o, **kwargs)

A SELECT CASE statement for a case-construct

fparser.two.Fortran2003.Select_Case_Stmt has only one child: the selection expression.

visit_Case_Stmt(o, **kwargs)

A CASE statement in a case-construct

fparser.two.Fortran2003.Case_Stmt has two children:

visit_Case_Selector(o, **kwargs)

The selector in a CASE statement

fparser.two.Fortran2003.Case_Selector has one child: the value-range-list fparser.two.Fortran2003.Case_Value_Range_List or None for the DEFAULT case.

visit_Case_Value_Range(o, **kwargs)

The range of values in a CASE statement

fparser.two.Fortran2003.Case_Value_Range has two children:

visit_Case_Value_Range_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Allocate_Stmt(o, **kwargs)

A call to ALLOCATE

fparser.two.Fortran2003.Allocate_Stmt has three children:

visit_Allocation_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Allocation(o, **kwargs)

An allocation specification in an allocate-stmt

fparser.two.Fortran2003.Allocation has two children:

visit_Allocate_Shape_Spec(o, **kwargs)

Explicit shape specification for arrays

fparser.two.Fortran2003.Explicit_Shape_Spec has 2 children:

  • lower bound (if explicitly given)

  • upper bound

visit_Allocate_Shape_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Alloc_Opt_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Dealloc_Opt_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Allocate_Object_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Alloc_Opt(o, **kwargs)

An allocation option in an allocate-stmt

fparser.two.Fortran2003.Alloc_Opt has two children:

  • the keyword (str)

  • the option value

visit_Deallocate_Stmt(o, **kwargs)

A call to DEALLOCATE

fparser.two.Fortran2003.Deallocate_Stmt has two children:

  • the list of objects fparser.two.Fortran2003.Allocate_Object_List

  • list of options fparser.two.Fortran2003.Dealloc_Opt_list

visit_Dealloc_Opt(o, **kwargs)

A deallocation option in a deallocate-stmt

fparser.two.Fortran2003.Dealloc_Opt has two children:

  • the keyword (str)

  • the option value

visit_Call_Stmt(o, **kwargs)

A CALL statement

fparser.two.Fortran2003.Call_Stmt has two children:

visit_Procedure_Designator(o, **kwargs)

The function or subroutine designator

This appears only when a type-bound procedure is called (as otherwise Fparser hands through the relevant names directly).

fparser.two.Fortran2003.Procedure_Designator has three children:

visit_Actual_Arg_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Actual_Arg_Spec(o, **kwargs)

A single argument in a subroutine call

fparser.two.Fortran2003.Actual_Arg_Spec has two children:

visit_Function_Reference(o, **kwargs)

An inline function call

fparser.two.Fortran2003.Actual_Arg_Spec has two children:

  • the function name :class:fparser.two.Fortran2003.ProcedureDesignator`

  • the argument list fparser.two.Fortran2003.Actual_Arg_Spec_List

visit_Intrinsic_Function_Reference(o, **kwargs)
visit_Intrinsic_Name(o, **kwargs)

A symbol name

fparser.two.Fortran2003.Name has no children.

visit_Structure_Constructor(o, **kwargs)

Call to the constructor of a derived type

fparser.two.Fortran2003.Structure_Constructor has two children:

visit_Component_Spec(o, **kwargs)

A single argument in a subroutine call

fparser.two.Fortran2003.Actual_Arg_Spec has two children:

visit_Component_Spec_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Enum_Def(o, **kwargs)

The definition of an ENUM

fparser.two.Fortran2003.Enum_Def has variable number of children:

visit_Enumerator_Def_Stmt(o, **kwargs)

A definition inside an ENUM

fparser.two.Fortran2003.Enumerator_Def_Stmt has 2 children:

  • 'ENUMERATOR' (str)

  • fparser.two.Fortran2003.Enumerator_List (the constants)

visit_Enumerator_List(o, **kwargs)

Universal routine for auto-generated *_List types in fparser

*_List types have their items children

visit_Enumerator(o, **kwargs)

A constant definition within an ENUM’s definition stmt

fparser.two.Fortran2003.Enumerator has 3 children:

  • fparser.two.Fortran2003.Name (the constant’s name)

  • '=' (str)

  • the constant’s value given as some constant expression that must evaluate to an integer

visit_Forall_Stmt(o, **kwargs)
Visit and process a single-line FORALL statement:

FORALL (<variable> = <bound>[, <variable> = <bound>] … [, <mask>]) assign-stmt

visit_Forall_Construct(o, **kwargs)
Visit and process a multi-line FORALL construct:
[name:] FORALL (<variable> = <bound>[, <variable> = <bound>] … [, <mask>])

…body…

END FORALL [name]

Notes

  • Optional name of the construct is stored by fparser only in the End_Forall_Stmt at the end, and not in the beginning of the whole statement.

  • The body can consist of not only assignment statements, but also comments and nested FORALLs

visit_Forall_Header(o, **kwargs)

Visit FORALL header consisting of variables with their bounds and an optional mask

visit_Forall_Triplet_Spec(o, **kwargs)

Visit a triplet specification consisting of named variable, =, and a range (hence, the triplet!)

visit_Where_Construct(o, **kwargs)

Fortran’s masked array assignment construct

fparser.two.Fortran2003.Where_Construct has variable number of children:

visit_Where_Construct_Stmt(o, **kwargs)

The WHERE statement that marks the beginning of a where-construct

fparser.two.Fortran2003.Where_Construct_Stmt has 1 child:

  • the expression that marks the condition

visit_Masked_Elsewhere_Stmt(o, **kwargs)

An ELSEWHERE statement with a condition in a where-construct

fparser.two.Fortran2003.Masked_Elsewhere_Stmt has 2 children:

  • the expression that marks the condition

  • the construct name or None

visit_Elsewhere_Stmt(o, **kwargs)

An unconditional ELSEWHERE statement

fparser.two.Fortran2003.Elsewhere_Stmt has 2 children:

  • 'ELSEWHERE' (str)

  • the construct name or None

visit_Where_Stmt(o, **kwargs)

An inline WHERE assignment

fparser.two.Fortran2003.Where_Stmt has 2 children:

  • the expression that marks the condition

  • the assignment

visit_Base(o, **kwargs)

Universal default for Base FParser-AST nodes

visit_BlockBase(o, **kwargs)

Universal default for BlockBase FParser-AST nodes

visit_literal(o, _type, kind=None, **kwargs)
visit_Char_Literal_Constant(o, **kwargs)
visit_Int_Literal_Constant(o, **kwargs)
visit_Signed_Int_Literal_Constant(o, **kwargs)
visit_Real_Literal_Constant(o, **kwargs)
visit_Signed_Real_Literal_Constant(o, **kwargs)
visit_Logical_Literal_Constant(o, **kwargs)
visit_Complex_Literal_Constant(o, **kwargs)
visit_Binary_Constant(o, **kwargs)
visit_Octal_Constant(o, **kwargs)
visit_Hex_Constant(o, **kwargs)
visit_Include_Stmt(o, **kwargs)
visit_Implicit_Stmt(o, **kwargs)
visit_Print_Stmt(o, **kwargs)
visit_Comment(o, **kwargs)
visit_Data_Pointer_Object(o, **kwargs)
visit_Proc_Component_Ref(o, **kwargs)

This is the compound object for accessing procedure components of a variable.

visit_Block_Nonlabel_Do_Construct(o, **kwargs)
visit_Block_Label_Do_Construct(o, **kwargs)
visit_Nonlabel_Do_Stmt(o, **kwargs)
visit_Label_Do_Stmt(o, **kwargs)
visit_Loop_Control(o, **kwargs)
visit_Assignment_Stmt(o, **kwargs)
visit_Pointer_Assignment_Stmt(o, **kwargs)
create_operation(op, exprs)

Construct expressions from individual operations.

visit_Add_Operand(o, **kwargs)
visit_Mult_Operand(o, **kwargs)
visit_And_Operand(o, **kwargs)
visit_Or_Operand(o, **kwargs)
visit_Equiv_Operand(o, **kwargs)
visit_Level_2_Expr(o, **kwargs)
visit_Level_2_Unary_Expr(o, **kwargs)
visit_Level_3_Expr(o, **kwargs)
visit_Level_4_Expr(o, **kwargs)
visit_Level_5_Expr(o, **kwargs)
visit_Parenthesis(o, **kwargs)
visit_Format_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Write_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Goto_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Return_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Continue_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Cycle_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Exit_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Save_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Read_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Open_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Close_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Inquire_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Namelist_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Parameter_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Dimension_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Equivalence_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Common_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Stop_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Error_Stop_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Backspace_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Rewind_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Entry_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Cray_Pointer_Stmt(o, **kwargs)

Universal routine to capture nodes as plain string in the IR

visit_Cpp_If_Stmt(o, **kwargs)
visit_Cpp_Elif_Stmt(o, **kwargs)
visit_Cpp_Else_Stmt(o, **kwargs)
visit_Cpp_Endif_Stmt(o, **kwargs)
visit_Cpp_Macro_Stmt(o, **kwargs)
visit_Cpp_Undef_Stmt(o, **kwargs)
visit_Cpp_Line_Stmt(o, **kwargs)
visit_Cpp_Warning_Stmt(o, **kwargs)
visit_Cpp_Error_Stmt(o, **kwargs)
visit_Cpp_Null_Stmt(o, **kwargs)
visit_Cpp_Include_Stmt(o, **kwargs)
visit_Select_Type_Construct(o, **kwargs)
visit_Nullify_Stmt(o, **kwargs)
parse_fparser_file(filename)

Generate a parse tree from file via fparser

parse_fparser_source(source)

Generate a parse tree from string

parse_fparser_ast(ast, raw_source, pp_info=None, definitions=None, scope=None)

Generate an internal IR from fparser parse tree

Parameters:
  • ast – The fparser parse tree as created by parse_fparser_source or parse_fparser_file

  • raw_source (str) – The raw source string from which ast was generated

  • pp_info (optional) – Information from internal preprocessing step that was applied to work around parser limitations and that should be re-inserted

  • definitions (list of Module, optional) – List of external module definitions to attach upon use

  • scope (Scope) – Scope object for which to parse the AST.

Returns:

The control flow tree

Return type:

Node

parse_fparser_expression(source, scope)

Parse an expression string into an expression tree.

This exploits Fparser’s internal parser structure that relies on recursively matching strings against a list of node types. Usually, this would start by matching against module, subroutine or program. Here, we shortcut this hierarchy by directly matching against a primary expression, thus this should be able to parse any syntactically correct Fortran expression.

Parameters:
  • source (str) – The expression as a string

  • scope (Scope) – The scope to which symbol names inside the expression belong

Returns:

The expression tree corresponding to the expression

Return type:

Expression

get_fparser_node(ast, node_type_name, first_only=True, recurse=False)

Extract child nodes with type given by node_type_name from an fparser parse tree

Parameters:
  • ast – The fparser parse tree as created by parse_fparser_source or parse_fparser_file

  • node_type_name (str or list of str) – The name of the node type to extract, e.g. Module, Specification_Part etc.

  • first_only (bool, optional) – Return only first instance matching node_type_name. Defaults to True.

  • recurse (bool, optional) – Walk the entire parse tree instead of looking only in the children of ast. Defaults to False.

Returns:

The node of requested type (or a list of these nodes if all is True)

Return type:

fparser.two.util.Base