PyForTool
Python-fortran-tool
Loading...
Searching...
No Matches
Classes | Functions | Variables
pyfortool.util Namespace Reference

Classes

class  PYFTError
 

Functions

 debugDecor (func)
 
 noParallel (func)
 
 setVerbosity (level)
 
 printInfos ()
 
 fortran2xml (fortranSource, parserOptions=None, wrapH=False)
 
 tostring (doc)
 
 tofortran (doc)
 
 isint (string)
 Other.
 
 isfloat (string)
 
 tag (elem)
 Helper functions acting on the xml.
 
 n2name (nodeN)
 
 alltext (doc)
 
 nonCode (elem)
 
 isExecutable (elem)
 
 isConstruct (elem)
 
 isStmt (elem)
 

Variables

dict debugStats = {}
 Verbosity, decorators and Exception.
 
 SHARED_TREE
 

Detailed Description

Utility functions and classes for XML manipulation and debugging.

Provides helper functions for parsing, converting, and manipulating
FORTRAN source code represented as XML.

Function Documentation

◆ alltext()

pyfortool.util.alltext (   doc)
Get all text content from an XML element.

Parameters
----------
doc : Element
    XML element or fragment.

Returns
-------
str
    Concatenated text from element and all descendants.

Examples
--------
>>> alltext(element)  # Gets all text including nested elements

Definition at line 406 of file util.py.

◆ debugDecor()

pyfortool.util.debugDecor (   func)
Decorator to trace function calls with timing and argument logging.

When logging is enabled at DEBUG level, logs function calls with arguments.
When logging is enabled at INFO level, tracks call count and execution time.

Definition at line 25 of file util.py.

◆ fortran2xml()

pyfortool.util.fortran2xml (   fortranSource,
  parserOptions = None,
  wrapH = False 
)
Convert FORTRAN source code to XML using fxtran parser.

Parameters
----------
fortranSource : str
    FORTRAN source code string or path to a file.
parserOptions : list, optional
    Options passed to fxtran parser.
wrapH : bool, optional
    If True, wrap .h file content in a MODULE for free-form parsing.

Returns
-------
tuple
    (includesRemoved, xml) where:
    - includesRemoved (bool): True if include statements were processed.
    - xml (Element): XML document tree.

Examples
--------
>>> includesRemoved, xml = fortran2xml("REAL :: X\nX = 1.0")

Definition at line 146 of file util.py.

◆ isConstruct()

pyfortool.util.isConstruct (   elem)
Check if element is a construct.

Parameters
----------
elem : Element
    XML element.

Returns
-------
bool
    True if element tag ends with '-construct'.

Examples
--------
>>> isConstruct(if_construct_element)
True

Definition at line 477 of file util.py.

Here is the caller graph for this function:

◆ isExecutable()

pyfortool.util.isExecutable (   elem)
Check if element is an executable statement.

Parameters
----------
elem : Element
    XML element.

Returns
-------
bool
    True if element is a statement or construct (excluding declarations).

Examples
--------
>>> isExecutable(stmt_element)
True

Definition at line 449 of file util.py.

Here is the call graph for this function:

◆ isfloat()

pyfortool.util.isfloat (   string)
Check if string represents a floating-point number.

Parameters
----------
string : str
    String to test.

Returns
-------
bool
    True if string is a valid float.

Examples
--------
>>> isfloat('3.14')
True
>>> isfloat('42')
True

Definition at line 332 of file util.py.

◆ isint()

pyfortool.util.isint (   string)

Other.

Check if string represents an integer.

Parameters
----------
string : str
    String to test.

Returns
-------
bool
    True if string is a valid integer.

Examples
--------
>>> isint('42')
True
>>> isint('3.14')
False

Definition at line 303 of file util.py.

◆ isStmt()

pyfortool.util.isStmt (   elem)
Check if element is a statement.

Parameters
----------
elem : Element
    XML element.

Returns
-------
bool
    True if element tag ends with '-stmt'.

Examples
--------
>>> isStmt(call_element)
True

Definition at line 499 of file util.py.

◆ n2name()

pyfortool.util.n2name (   nodeN)
Extract entity name from N-tagged XML element.

Parameters
----------
nodeN : Element
    XML element with N tag containing 'n' child elements.

Returns
-------
str
    Concatenated name from all 'n' child elements.

Examples
--------
>>> n2name(element)  # <N><n>X</n><n>Y</n></N> -> 'XY'

Definition at line 385 of file util.py.

◆ nonCode()

pyfortool.util.nonCode (   elem)
Check if element is non-code (comment, text, etc.).

Parameters
----------
elem : Element
    XML element.

Returns
-------
bool
    True if element is non-code (cnt, C, cpp, filename, S).

Examples
--------
>>> nonCode(comment_element)
True

Definition at line 427 of file util.py.

◆ noParallel()

pyfortool.util.noParallel (   func)
Decorator to prevent parallel execution of a method.

Used for methods that modify the XML tree and need to prevent
concurrent execution across multiple files.

Definition at line 75 of file util.py.

◆ printInfos()

pyfortool.util.printInfos ( )
Print debug statistics on decorated function usage.

Displays a table with function names, call counts, min/max/total
execution times for functions decorated with @debugDecor.

Definition at line 119 of file util.py.

◆ setVerbosity()

pyfortool.util.setVerbosity (   level)
Set the logging verbosity level.

Parameters
----------
level : str or int
    Logging level: 'DEBUG', 'INFO', 'WARNING', 'ERROR', or numeric value.

Definition at line 103 of file util.py.

◆ tag()

pyfortool.util.tag (   elem)

Helper functions acting on the xml.

Get XML tag name without namespace.

Parameters
----------
elem : Element
    XML Element.

Returns
-------
str
    Tag name without namespace prefix.

Examples
--------
>>> tag(xml_element)  # '{http://fxtran.net}subroutine-stmt' -> 'subroutine-stmt'

Definition at line 364 of file util.py.

◆ tofortran()

pyfortool.util.tofortran (   doc)
Convert XML Element to FORTRAN source code.

Parameters
----------
doc : Element
    XML Element representing FORTRAN code.

Returns
-------
str
    FORTRAN source code string.

Examples
--------
>>> fortran_code = tofortran(xml_element)

Definition at line 269 of file util.py.

◆ tostring()

pyfortool.util.tostring (   doc)
Convert XML Element to string.

Parameters
----------
doc : Element
    XML Element object.

Returns
-------
str
    XML string representation.

Examples
--------
>>> xml_str = tostring(xml_element)

Definition at line 248 of file util.py.

Variable Documentation

◆ debugStats

dict pyfortool.util.debugStats = {}

Verbosity, decorators and Exception.

Definition at line 22 of file util.py.

◆ SHARED_TREE

pyfortool.util.SHARED_TREE

Definition at line 93 of file util.py.