loki.frontend.fparser
Module Attributes
Indicate whether fparser frontend is available. |
Functions
|
Extract child nodes with type given by |
|
Extract a subset of nodes from a list that sits between marked start and end nodes. |
|
Generate an internal IR from fparser parse tree |
|
Parse an expression string into an expression tree. |
|
Generate a parse tree from file via fparser |
|
Generate a parse tree from string |
|
Searches for the last, immediate child of the supplied node that is of the specified type. |
Classes
|
- 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(node, end_node=None)
Builds the source object for a given (pair of) AST node(s).
- 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
- create_contained_procedures(o, **kwargs)
Helper utility that creates
Subroutine
objects before the full parse to ensure the scope hierarchy is in place.Notes
We first make sure the procedure objects for all internal procedures are instantiated before parsing the actual spec and body of the parent routine.
This way, all procedure types should exist in the scope and any use of their symbol (e.g. in a
CallStatement
orInlineCall
) can be matched against a type.
- 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:fparser.two.Fortran2003.Name
: the part namefparser.two.Fortran2003.Section_Subscript_List
: the subscript (or None)
- 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
aspart-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:‘OPERATOR’ (str) or None
fparser.two.Fortran2003.Local_Name
orfparser.two.Fortran2003.Local_Defined_Operator
fparser.two.Fortran2003.Use_Name
orfparser.two.Fortran2003.Use_Defined_Operator
- visit_Type_Declaration_Stmt(o, **kwargs)
Variable declaration statement
fparser.two.Fortran2003.Type_Declaration_Stmt
has 3 children:fparser.two.Fortran2003.Declaration_Type_Spec
(fparser.two.Fortran2003.Intrinsic_Type_Spec
orfparser.two.Fortran2003.Derived_Type_Spec
)fparser.two.Fortran2003.Attr_Spec_List
fparser.two.Fortran2003.Entity_Decl_List
- visit_Intrinsic_Type_Spec(o, **kwargs)
An intrinsic type
fparser.two.Fortran2003.Intrinsic_Type_Spec
has 2 children:type name (str)
kind (
fparser.two.Fortran2003.Kind_Selector
) or length (fparser.two.Fortran2003.Length_Selector
)
- visit_Kind_Selector(o, **kwargs)
A kind selector of an intrinsic type
fparser.two.Fortran2003.Kind_Selector
has 2 or 3 children:'*'
(str) andfparser.two.Fortran2003.Char_Length
, or'('
(str),fparser.two.Fortran2003.Scalar_Int_Initialization_Expr
, and')'
(str)
- visit_Length_Selector(o, **kwargs)
A length selector for intrinsic character type
fparser.two.Fortran2003.Length_Selector
has 3 children:‘(’ (str)
fparser.two.Fortran2003.Char_Length
orfparser.two.Fortran2003.Type_Param_Value
‘)’ (str)
- 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:some scalar expression for the kind
- 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:keyword ‘TYPE’ or ‘CLASS’ (str)
- visit_Dimension_Attr_Spec(o, **kwargs)
The dimension specification as attribute in a declaration
fparser.two.Fortran2003.Dimensions_Attr_Spec
has 2 children:attribute name (str)
- visit_Intent_Attr_Spec(o, **kwargs)
The intent specification in a declaration
fparser.two.Fortran2003.Intent_Attr_Spec
has 2 children:‘INTENT’ keyword
- 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:object name (
fparser.two.Fortran2003.Name
)array spec (
fparser.two.Fortran2003.Array_Spec
)char length (
fparser.two.Fortran2003.Char_Length
)
- 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_Assumed_Size_Spec(o, **kwargs)
Assumed size specification for arrays
fparser.two.Fortran2003.Assumed_Size_Spec
has 2 children:An explicit shape specification preceding the assumed size specifier
lower bound (if explicitly given)
- 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_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 namesfparser.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
orPUBLIC
(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 interfacefparser.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:object name (
fparser.two.Fortran2003.Name
)operator
=>
(str)initializer (
fparser.two.Fortran2003.Function_Reference
)
- visit_Array_Constructor(o, **kwargs)
An array constructor expression
fparser.two.Fortran2003.Array_Constructor
has three children:left bracket (str):
(/
or[
the spec:
fparser.two.Fortran2003.Ac_Spec
right bracket (str):
/)
or]
- 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 asfparser.two.Fortran2003.Ac_Value_List
* the loop control asfparser.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
statementfparser.two.Fortran2003.Data_Stmt
has variable number of childrenfparser.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:the object to initialize
fparser.two.Fortran2003.Data_Stmt_Object
the value list
fparser.two.Fortran2003.Data_Stmt_Value_List
- 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:the repeat value
fparser.two.Fortran2003.Data_Stmt_Repeat
the constant
fparser.two.Fortran2003.Data_Stmt_Constant
- 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:start
fparser.two.Fortran2003.Subscript
or Nonestop
fparser.two.Fortran2003.Subscript
or Nonestride
fparser.two.Fortran2003.Stride
or None
- 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:the subscript data-ref
fparser.two.Fortran2003.Data_Ref
an optional substring range
fparser.two.Fortran2003.Substring_Range
- 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 Nonestop
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:header stmt (
fparser.two.Fortran2003.Derived_Type_Stmt
)all of body (list of
fparser.two.Fortran2003.Type_Param_Def_Stmt
,fparser.two.Fortran2003.Private_Or_Sequence
,fparser.two.Fortran2003.Component_Part
,fparser.two.Fortran2003.Type_Bound_Procedure_Part
)end stmt (
fparser.two.Fortran2003.End_Type_Stmt
)
- 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 offparser.two.Fortran2003.Data_Component_Def_Stmt
orfparser.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:fparser.two.Fortran2003.Declaration_Type_Spec
(fparser.two.Fortran2003.Intrinsic_Type_Spec
orfparser.two.Fortran2003.Derived_Type_Spec
)fparser.two.Fortran2003.Attr_Spec_List
fparser.two.Fortran2003.Entity_Decl_List
- 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:attribute name (str)
- 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:object name (
fparser.two.Fortran2003.Name
)array spec (
fparser.two.Fortran2003.Array_Spec
)char length (
fparser.two.Fortran2003.Char_Length
)
- 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 interfacefparser.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 offparser.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:fparser.two.Fortran2003.Access_Spec
or None (access specifier)fparser.two.Fortran2003.Generic_Spec
(the local name of the binding)fparser.two.Fortran2003.Binding_Name_List
(the names it binds to)
- 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:Any preceeding comments
fparser.two.Fortran2003.Comment
fparser.two.Fortran2003.Associate_Stmt
(the actual statement with the definition of associates)the body of the ASSOCIATE construct
- 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:fparser.two.Fortran2003.Name
(the new assigned name)the operator
=>
(str)fparser.two.Fortran2003.Name
(the associated expression)
- visit_Interface_Block(o, **kwargs)
An
INTERFACE
blockfparser.two.Fortran2003.Interface_Block
has variable number of children:Any preceeding comments
fparser.two.Fortran2003.Comment
fparser.two.Fortran2003.Interface_Stmt
(the actual statement that begins the construct)the body, made up of
fparser.two.Fortran2003.Subroutine_Body
,fparser.two.Fortran2003.Function_Body
,fparser.two.Fortran2003.Procedure_Stmt
and, potentially, any interleaving commentsfparser.two.Fortran2003.Comment
the closing
fparser.two.Fortran2003.End_Interface_Stmt
- visit_Interface_Stmt(o, **kwargs)
The specification of the interface
fparser.two.Fortran2003.Interface_Stmt
has one child, which is either:None, if no further specification exists
'ABSTRACT'
(str) for an abstract interfacefparser.two.Fortran2003.Generic_Spec
for other specifications
- visit_Generic_Spec(o, **kwargs)
The generic-spec of an interface
fparser.two.Fortran2003.Generic_Spec
has two children, which is either:'OPERATOR'
(str) followed by
-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
definitionLoki does currently not have support for
PROGRAM
blocks, and this will raise aNotImplementedError
- visit_Subroutine_Subprogram(o, **kwargs)
The entire block that comprises a
SUBROUTINE
definition, i.e. everything from the subroutine-stmt to the end-stmtfparser.two.Fortran2003.Subroutine_Subprogram
has variable number of children, where the internal nodes may be optional:fparser.two.Fortran2003.Subroutine_Stmt
(the opening statement)fparser.two.Fortran2003.Specification_Part
(variable declarations, module imports etc.); due to an fparser bug, this can appear multiple times interleaved with the execution-partfparser.two.Fortran2003.Execution_Part
(the body of the routine)fparser.two.Fortran2003.Internal_Subprogram_Part
(any member procedures declared inside the procedure)fparser.two.Fortran2003.End_Subroutine_Stmt
(the final statement)
- visit_Function_Subprogram(o, **kwargs)
The entire block that comprises a
SUBROUTINE
definition, i.e. everything from the subroutine-stmt to the end-stmtfparser.two.Fortran2003.Subroutine_Subprogram
has variable number of children, where the internal nodes may be optional:fparser.two.Fortran2003.Subroutine_Stmt
(the opening statement)fparser.two.Fortran2003.Specification_Part
(variable declarations, module imports etc.); due to an fparser bug, this can appear multiple times interleaved with the execution-partfparser.two.Fortran2003.Execution_Part
(the body of the routine)fparser.two.Fortran2003.Internal_Subprogram_Part
(any member procedures declared inside the procedure)fparser.two.Fortran2003.End_Subroutine_Stmt
(the final statement)
- visit_Subroutine_Body(o, **kwargs)
The entire block that comprises a
SUBROUTINE
definition, i.e. everything from the subroutine-stmt to the end-stmtfparser.two.Fortran2003.Subroutine_Subprogram
has variable number of children, where the internal nodes may be optional:fparser.two.Fortran2003.Subroutine_Stmt
(the opening statement)fparser.two.Fortran2003.Specification_Part
(variable declarations, module imports etc.); due to an fparser bug, this can appear multiple times interleaved with the execution-partfparser.two.Fortran2003.Execution_Part
(the body of the routine)fparser.two.Fortran2003.Internal_Subprogram_Part
(any member procedures declared inside the procedure)fparser.two.Fortran2003.End_Subroutine_Stmt
(the final statement)
- visit_Function_Body(o, **kwargs)
The entire block that comprises a
SUBROUTINE
definition, i.e. everything from the subroutine-stmt to the end-stmtfparser.two.Fortran2003.Subroutine_Subprogram
has variable number of children, where the internal nodes may be optional:fparser.two.Fortran2003.Subroutine_Stmt
(the opening statement)fparser.two.Fortran2003.Specification_Part
(variable declarations, module imports etc.); due to an fparser bug, this can appear multiple times interleaved with the execution-partfparser.two.Fortran2003.Execution_Part
(the body of the routine)fparser.two.Fortran2003.Internal_Subprogram_Part
(any member procedures declared inside the procedure)fparser.two.Fortran2003.End_Subroutine_Stmt
(the final statement)
- visit_Subroutine_Stmt(o, **kwargs)
The
SUBROUTINE
statementfparser.two.Fortran2003.Subroutine_Stmt
has four children:name
fparser.two.Fortran2003.Subroutine_Name
dummy argument list
fparser.two.Fortran2003.Dummy_Arg_List
suffix
fparser.two.Fortran2003.Suffix
or language binding specfparser.two.Fortran2003.Proc_Language_Binding_Spec
- visit_Function_Stmt(o, **kwargs)
The
SUBROUTINE
statementfparser.two.Fortran2003.Subroutine_Stmt
has four children:name
fparser.two.Fortran2003.Subroutine_Name
dummy argument list
fparser.two.Fortran2003.Dummy_Arg_List
suffix
fparser.two.Fortran2003.Suffix
or language binding specfparser.two.Fortran2003.Proc_Language_Binding_Spec
- 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 typefparser.two.Fortran2003.Prefix_Spec
to declare attributesfparser.two.Fortran2003.Declaration_Type_Spec
(or any of its variations) to declare the return type of a function
- 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:A
fparser.two.Fortran2003.Result_Name
if specified, or Nonea
fparser.two.Fortran2003.Language_Binding_Spec
if specified, or None
- visit_Language_Binding_Spec(o, **kwargs)
A language binding spec suffix
fparser.two.Fortran2003.Language_Binding_Spec
has a single child:fparser.two.Fortran2003.Char_Literal_Constant
with the name of the C routine it binds to
- visit_Module(o, **kwargs)
The definition of a Fortran module
fparser.two.Fortran2003.Module
has up to four children:The opening
fparser.two.Fortran2003.Module_Stmt
The specification part
fparser.two.Fortran2003.Specification_Part
The module subprogram part
fparser.two.Fortran2003.Module_Subprogram_Part
the closing
fparser.two.Fortran2003.End_Module_Stmt
- visit_Module_Stmt(o, **kwargs)
The
MODULE
statementfparser.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
constructfparser.two.Fortran2003.If_Construct
has variable number of children:Any preceeding comments
fparser.two.Fortran2003.Comment
fparser.two.Fortran2003.If_Then_Stmt
(the actual statement that begins the construct with the first condition)the body of the conditional branch
Optionally, one or more
fparser.two.Fortran2003.Else_If_Stmt
followed by their corresponding bodiesOptionally, a
fparser.two.Fortran2003.Else_Stmt
followed by its body
- visit_If_Then_Stmt(o, **kwargs)
The first conditional in a
IF
constructfparser.two.Fortran2003.If_Then_Stmt
has one child: the condition expression
- visit_Else_If_Stmt(o, **kwargs)
The first conditional in a
IF
constructfparser.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 bodyfparser.two.Fortran2003.If_Stmt
has two children:the condition expression
the body
- visit_Case_Construct(o, **kwargs)
The entire
SELECT CASE
constructfparser.two.Fortran2003.Case_Construct
has variable number of children:Any preceeding comments
fparser.two.Fortran2003.Comment
fparser.two.Fortran2003.Select_Case_Stmt
(the actual statement with the selection expression)the body of the case-construct, containing one or multiple
fparser.two.Fortran2003.Case_Stmt
followed by their corresponding bodies
- visit_Select_Case_Stmt(o, **kwargs)
A
SELECT CASE
statement for a case-constructfparser.two.Fortran2003.Select_Case_Stmt
has only one child: the selection expression.
- visit_Case_Stmt(o, **kwargs)
A
CASE
statement in a case-constructfparser.two.Fortran2003.Case_Stmt
has two children:the selection expression
fparser.two.Fortran2003.Case_Selector
.the construct name
fparser.two.Fortran2003.Case_Construct_Name
or None
- visit_Case_Selector(o, **kwargs)
The selector in a
CASE
statementfparser.two.Fortran2003.Case_Selector
has one child: the value-range-listfparser.two.Fortran2003.Case_Value_Range_List
or None for theDEFAULT
case.
- visit_Case_Value_Range(o, **kwargs)
The range of values in a
CASE
statementfparser.two.Fortran2003.Case_Value_Range
has two children:start
fparser.two.Fortran2003.Case_Value
or Nonestop
fparser.two.Fortran2003.Case_Value
or None
- visit_Case_Value_Range_List(o, **kwargs)
Universal routine for auto-generated
*_List
types in fparser*_List
types have their items children
- visit_Select_Type_Construct(o, **kwargs)
The entire
SELECT TYPE
constructfparser.two.Fortran2003.Select_Type_Construct
has variable number of children:Any preceeding comments
fparser.two.Fortran2003.Comment
fparser.two.Fortran2003.Select_Type_Stmt
(the actual statement with the selection expression)the body of the case-construct, containing one or multiple
fparser.two.Fortran2003.Type_Guard_Stmt
followed by their corresponding bodies
- visit_Select_Type_Stmt(o, **kwargs)
A
SELECT TYPE
statement for a select-type-constructfparser.two.Fortran2003.Select_Type_Stmt
has two children:the associate name or None
the selection expression
- visit_Type_Guard_Stmt(o, **kwargs)
A
CLASS
orTYPE
statement in a select-type-constructfparser.two.Fortran2003.Type_Guard_Stmt
has 3 children:the selection keyword
CLASS IS
orTYPE IS
orCLASS DEFAULT
the selection expression, a
fparser.two.Fortran2003.Type_Name
the construct name
fparser.two.Fortran2003.Select_Construct_Name
or None
- visit_Allocate_Stmt(o, **kwargs)
A call to
ALLOCATE
fparser.two.Fortran2003.Allocate_Stmt
has three children:fparser.two.Fortran2003.Allocation_List
fparser.two.Fortran2003.Alloc_Opt_List
or None
- 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:the name of the data object to be allocated:
fparser.two.Fortran2003.Allocate_Object
the shape of the object:
fparser.two.Fortran2003.Allocate_Shape_Spec_List
- 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
statementfparser.two.Fortran2003.Call_Stmt
has two children:the subroutine name
fparser.two.Fortran2003.Procedure_Designator
the argument list
fparser.two.Fortran2003.Actual_Arg_Spec_List
- 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:Parent name
fparser.two.Fortran2003.Data_Ref
‘%’ (str)
procedure name
fparser.two.Fortran2003.Binding_Name
- 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:keyword
fparser.two.Fortran2003.Keyword
argument
fparser.two.Fortran2003.Actual_Arg
- 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:the structure name
fparser.two.Fortran2003.Derived_Type_Spec
the argument list
fparser.two.Fortran2003.Component_Spec_List
- visit_Component_Spec(o, **kwargs)
A single argument in a subroutine call
fparser.two.Fortran2003.Actual_Arg_Spec
has two children:keyword
fparser.two.Fortran2003.Keyword
argument
fparser.two.Fortran2003.Actual_Arg
- 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:Any preceeding comments
fparser.two.Fortran2003.Comment
fparser.two.Fortran2003.Enum_Def_Stmt
(the statement indicating the beginning of the enum)the body of the enum, containing one or multiple
fparser.two.Fortran2003.Enumerator_Def_Stmt
- 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 stmtfparser.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:Any preceeding comments
fparser.two.Fortran2003.Comment
fparser.two.Fortran2003.Where_Construct_Stmt
(the statement that marks the beginning of the construct)body of the where-construct, usually an assignment
(optional)
fparser.two.Fortran2003.Masked_Elsewhere_Stmt
(essentially an “else-if”), followed by its body; this can appear more than once(optional)
fparser.two.Fortran2003.Elsewhere_Stmt
(essentially an “else”), followed by its body
- visit_Where_Construct_Stmt(o, **kwargs)
The
WHERE
statement that marks the beginning of a where-constructfparser.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-constructfparser.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
statementfparser.two.Fortran2003.Elsewhere_Stmt
has 2 children:'ELSEWHERE'
(str)the construct name or None
- visit_Where_Stmt(o, **kwargs)
An inline
WHERE
assignmentfparser.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_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
orparse_fparser_file
raw_source (str) – The raw source string from which
ast
was generatedpp_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 usescope (
Scope
) – Scope object for which to parse the AST.
- Returns:
The control flow tree
- Return type:
- 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:
- Returns:
The expression tree corresponding to the expression
- Return type:
- 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
orparse_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