PyForTool
Python-fortran-tool
Loading...
Searching...
No Matches
Functions
pyfortool.expressions Namespace Reference

Functions

 createElem (tagName, text=None, tail=None, childs=None)
 
 _cachedCreateExprPart (value)
 
 createExprPart (value)
 
 _cachedCreateExpr (value)
 
 createExpr (value)
 
 simplifyExpr (expr, add=None, sub=None)
 
 createArrayBounds (lowerBoundstr, upperBoundstr, context)
 

Detailed Description

Expression manipulation functions.

These functions are independent of PYFT and PYFTscope objects and provide
low-level utilities for creating and manipulating FORTRAN expression XML nodes.

Function Documentation

◆ _cachedCreateExpr()

pyfortool.expressions._cachedCreateExpr (   value)
protected
Internal cached function for createExpr.

Parameters
----------
value : str
    FORTRAN statement(s) to convert.

Returns
-------
list
    List of XML nodes from the statement.

Definition at line 137 of file expressions.py.

Here is the caller graph for this function:

◆ _cachedCreateExprPart()

pyfortool.expressions._cachedCreateExprPart (   value)
protected
:param value: expression part to put in a *-E node

If value is:
  - a FORTRAN string (python sting containing a ' or a "), returns
    <f:string-E><f:S>...
  - a FORTRAN value (python string convertible in real or int, or .FALSE./.TRUE.), returns
    <f:literal-E><f:l>...
  - a FORTRAN variable name (pyhon string with only alphanumerical characters and _), returns
    <named-E/><N><n>...
  - a FORTRAN operation (other python string), returns the right part of
    the X affectation statement of the code:
    "SUBROUTINE T; X=" + value + "; END". The xml is obtained by calling fxtran.

Definition at line 57 of file expressions.py.

Here is the caller graph for this function:

◆ createArrayBounds()

pyfortool.expressions.createArrayBounds (   lowerBoundstr,
  upperBoundstr,
  context 
)
Return a lower-bound and upper-bound node
:param lowerBoundstr: string for the fortran lower bound of an array
:param upperBoundstr: string for the fortran upper bound of an array
:param context: 'DO' for DO loops
                'DOCONCURRENT' for DO CONCURRENT loops
                'ARRAY' for arrays

Definition at line 266 of file expressions.py.

◆ createElem()

pyfortool.expressions.createElem (   tagName,
  text = None,
  tail = None,
  childs = None 
)
Create an XML element with the given tag and attributes.

Parameters
----------
tagName : str
    XML tag name (without namespace).
text : str, optional
    Text content for the element.
tail : str, optional
    Tail text (text after element).
childs : Element or list, optional
    Child element(s) to append.

Returns
-------
Element
    Created XML element.

Examples
--------
>>> elem = createElem('named-E')
>>> elem = createElem('literal-E', text='42')
>>> elem = createElem('n', text='X', tail='\\n')

Definition at line 17 of file expressions.py.

◆ createExpr()

pyfortool.expressions.createExpr (   value)
Convert FORTRAN statements to XML nodes.

Parameters
----------
value : str
    One or more FORTRAN statements to convert.

Returns
-------
list
    List of XML nodes representing the statements.

Examples
--------
>>> nodes = createExpr('X = 42')
>>> nodes = createExpr('CALL SUB(X, Y)')
>>> nodes = createExpr('IF (A > B) THEN\\n  X = 1\\nEND IF')

Definition at line 155 of file expressions.py.

Here is the call graph for this function:

◆ createExprPart()

pyfortool.expressions.createExprPart (   value)
Create an XML node from a FORTRAN expression part.

Parameters
----------
value : str
    Expression part value to convert.

Returns
-------
Element
    XML element representing the expression:
    - Integer/float: <literal-E><l>value</l></literal-E>
    - String: <string-E><S>value</S></string-E>
    - Variable: <named-E><N><n>value</n></N></named-E>
    - Structure member:
      <named-E><N><n>A</n></N><R-LT><component-R>%B</component-R></R-LT></named-E>
    - Expression: parsed via fxtran

Examples
--------
>>> createExprPart('42')  # Literal
>>> createExprPart('X')   # Variable
>>> createExprPart('A%B') # Structure member

Definition at line 107 of file expressions.py.

Here is the call graph for this function:

◆ simplifyExpr()

pyfortool.expressions.simplifyExpr (   expr,
  add = None,
  sub = None 
)
Simplify a numeric expression by combining constants.

Parameters
----------
expr : str
    Expression to simplify (e.g., '1+I+2+JI-I').
add : str, optional
    Expression to add to the result.
sub : str, optional
    Expression to subtract from the result.

Returns
-------
str
    Simplified expression string.

Examples
--------
>>> simplifyExpr('1+1+I+JI-I')
'2+JI'
>>> simplifyExpr('X+1', add='Y')
'X+Y+1'

Notes
-----
- Only handles addition and subtraction.
- Does not simplify expressions within parentheses.

Definition at line 179 of file expressions.py.