PyForTool
Python-fortran-tool
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
pyfortool.pyfortool.PYFT Class Reference
Inheritance diagram for pyfortool.pyfortool.PYFT:
Inheritance graph
[legend]
Collaboration diagram for pyfortool.pyfortool.PYFT:
Collaboration graph
[legend]

Public Member Functions

 __init__ (self, filename, output=None, parserOptions=None, verbosity=None, wrapH=False, tree=None, enableCache=False)
 
 setParallel (cls, tree, clsLock=None, clsRLock=None)
 
 lockFile (cls, filename)
 
 unlockFile (cls, filename, silence=False)
 
 __enter__ (self)
 
 __exit__ (self, excType, excVal, excTb)
 
 close (self)
 
 xml (self)
 
 fortran (self)
 
 renameUpper (self)
 
 renameLower (self)
 
 write (self)
 
 writeXML (self, filename)
 
- Public Member Functions inherited from pyfortool.scope.PYFTscope
 __copy__ (self)
 
 __deepcopy__ (self, memo)
 
 __getattr__ (self, attr)
 
 path (self)
 
 mainScope (self)
 
 parentScope (self)
 
 getParent (self, item, level=1)
 
 getSiblings (self, item, before=True, after=True)
 
 showScopesList (self, includeItself=False)
 
 getScopes (self, level=-1, excludeContains=True, excludeKinds=None, includeItself=True)
 
 getScopeNode (self, scopePath, excludeContains=True, includeItself=True)
 
 isScopeNode (self, node)
 
 getParentScopeNode (self, item, mustRaise=True)
 
 getScopePath (self, item, includeItself=True)
 
 getFileName (self)
 
 empty (self, addStmt=None, simplify=False)
 
- Public Member Functions inherited from pyfortool.scope.ElementView
 tag (self)
 
 tail (self)
 
 text (self)
 
 findtext (self, *args, **kwargs)
 
 iterfind (self, *args, **kwargs)
 
 itertext (self, *args, **kwargs)
 
 __getitem__ (self, *args, **kwargs)
 
 __len__ (self, *args, **kwargs)
 
 __iter__ (self)
 
 find (self, *args, **kwargs)
 
 findall (self, *args, **kwargs)
 
 iter (self, *args, **kwargs)
 
 items (self, *args, **kwargs)
 
 clear (self)
 
 append (self, *args, **kwargs)
 
 extend (self, *args, **kwargs)
 
 __setitem__ (self, index, item)
 
 __delitem__ (self, index)
 
 insert (self, index, item)
 
 remove (self, node)
 
- Public Member Functions inherited from pyfortool.variables.Variables
 varList (self)
 
 attachArraySpecToEntity (self)
 
 checkImplicitNone (self, mustRaise=False)
 
 checkIntent (self, mustRaise=False)
 
 checkONLY (self, mustRaise=False)
 
 removeVar (self, varList, simplify=False)
 
 addVar (self, varList)
 
 addModuleVar (self, moduleVarList)
 
 showUnusedVar (self)
 
 checkUnusedLocalVar (self, mustRaise=False, excludeList=None)
 
 removeUnusedLocalVar (self, excludeList=None, simplify=False)
 
 addExplicitArrayBounds (self, node=None)
 
 addArrayParentheses (self)
 
 addArrayParenthesesInNode (self, node)
 
 removeArrayParenthesesInNode (self, node)
 
 modifyAutomaticArrays (self, declTemplate=None, startTemplate=None, endTemplate=None)
 
 findIndexArrayBounds (self, arr, index, loopVar)
 
 arrayR2parensR (self, namedE, table)
 
 findArrayBounds (self, arr, loopVar, extraVarList=None)
 
 renameVar (self, oldName, newName)
 
 removeVarIfUnused (self, varList, excludeDummy=False, excludeModule=False, simplify=False)
 
 isVarUsed (self, varList, exactScope=False, dummyAreAlwaysUsed=False)
 
 addONLY (self, parserOptions=None, wrapH=False)
 
 addArgInTree (self, varName, declStmt, pos, stopScopes, moduleVarList=None, otherNames=None, parserOptions=None, wrapH=False)
 
- Public Member Functions inherited from pyfortool.cosmetics.Cosmetics
 upperCase (self)
 
 lowerCase (self)
 
 indent (self, nodeToUpdate=None, indentProgramunit=0, indentBranch=2, exclDirectives=None)
 
 removeEmptyLines (self)
 
 removeComments (self, exclDirectives=None, pattern=None)
 
 updateContinuation (self, nodeToUpdate=None, align=True, removeALL=False, addBegin=True, removeBegin=False)
 
 updateSpaces (self, beforeOp=1, afterOp=1, inOperator=True, beforeComma=0, afterComma=1, beforeParenthesis=0, afterParenthesis=0, beforeAffectation=1, afterAffectation=1, inAffectation=True, beforeRangeDelim=0, afterRangeDelim=0, beforeUseDelim=0, afterUseDelim=1, beforeDeclDelim=1, afterDeclDelim=1, inDeclDelim=True, afterTypeDecl=1, beforeEqDo=0, afterEqDo=0, beforeEqCall=0, afterEqCall=0, beforeEqInit=0, afterEqInit=0, beforeEndcnt=1, afterBegincnt=1, afterIfwherecase=1, beforeThen=1, beforeIfaction=1, afterProgunit=1, endOfLine=True, afterName=0, inName=True, beforeCmdsep=0, afterCmdsep=1, adjacentKeywords=__NO_VALUE__, afterKeywords=__NO_VALUE__)
 
 changeIfStatementsInIfConstructs (self, singleItem=None)
 
 removeEmptyCONTAINS (self)
 
- Public Member Functions inherited from pyfortool.applications.Applications
 splitModuleRoutineFile (self)
 
 buildModi (self)
 
 deleteNonColumnCallsPHYEX (self, simplify=False)
 
 removeExtraDOinMnhDoConcurrent (self)
 
 convertuseModuleToIncludes (self)
 
 convertTypesInCompute (self)
 
 deleteDrHook (self, simplify=False)
 
 addDrHook (self)
 
 deleteBudgetDDH (self, simplify=False)
 
 deleteRoutineCallsMesoNHGPU (self, simplify=True)
 
 addSubmodulePHYEX (self)
 
 addMPPDB_CHECKS (self, printsMode=False)
 
 addStack (self, model, stopScopes, parserOptions=None, wrapH=False)
 
 inlineContainedSubroutinesPHYEX (self, simplify=False)
 
 removeIJDim (self, stopScopes, parserOptions=None, wrapH=False, simplify=False)
 
 removePHYEXUnusedLocalVar (self, excludeList=None, simplify=False)
 
 checkPHYEXUnusedLocalVar (self, mustRaise=False, excludeList=None)
 
 expandAllArraysPHYEX (self, concurrent=False)
 
 mathFunctoBRFunc (self)
 
 shumanFUNCtoCALL (self)
 
 buildACCTypeHelpers (self)
 
- Public Member Functions inherited from pyfortool.statements.Statements
 isNodeInProcedure (self, node, procList)
 
 isNodeInCall (self, node)
 
 removeCall (self, callName, simplify=False)
 
 removePrints (self, simplify=False)
 
 removeArraySyntax (self, concurrent=False, useMnhExpand=True, everywhere=True, loopVar=None, reuseLoop=True, funcList=None, updateMemSet=False, updateCopy=False, addAccIndependentCollapse=True)
 
 inlineContainedSubroutines (self, simplify=False, loopVar=None)
 
 inline (self, subContained, callStmt, mainScope, simplify=False, loopVar=None)
 
 setFalseIfStmt (self, flags, simplify=False)
 
 evalFalseIfStmt (self, nodes, simplify=False)
 
 checkOpInCall (self, mustRaise=False)
 
 checkEmptyParensInCall (self, mustRaise=False)
 
 insertStatement (self, stmt, first)
 
 removeStmtNode (self, nodes, simplifyVar, simplifyStruct)
 
 removeConstructNode (self, node, simplifyVar, simplifyStruct)
 
 removeFromList (self, item, itemPar)
 
- Public Member Functions inherited from pyfortool.cpp.Cpp
 applyCPPifdef (self, keys)
 
- Public Member Functions inherited from pyfortool.openacc.Openacc
 removeACC (self)
 
 removebyPassDOCONCURRENT (self)
 
 craybyPassDOCONCURRENT (self)
 
 allocatetoHIP (self)
 
 addACCData (self)
 
 addACCRoutineSeq (self, stopScopes)
 

Public Attributes

 fortran
 
 xml
 
- Public Attributes inherited from pyfortool.scope.PYFTscope
 tree
 
 path
 
- Public Attributes inherited from pyfortool.scope.ElementView
 text
 
 tail
 
- Public Attributes inherited from pyfortool.variables.Variables

Static Public Attributes

list DEFAULT_FXTRAN_OPTIONS = ['-construct-tag', '-no-include', '-no-cpp', '-line-length', '9999']
 
list MANDATORY_FXTRAN_OPTIONS = ['-construct-tag']
 
 SHARED_TREE = None
 
 NO_PARALLEL_LOCK = None
 
 PARALLEL_FILE_LOCKS = None
 
- Static Public Attributes inherited from pyfortool.scope.PYFTscope
dict SCOPE_STMT
 
dict SCOPE_CONSTRUCT
 

Protected Member Functions

 _rename (self, mod)
 
- Protected Member Functions inherited from pyfortool.scope.PYFTscope
 _getNodePath (self, node)
 
- Protected Member Functions inherited from pyfortool.scope.ElementView
 _virtual (self)
 
 _getIndex (self, index)
 
- Protected Member Functions inherited from pyfortool.variables.Variables
 _normalizeScopeVar (self, scopeVarList)
 
 _normalizeUniqVar (self, scopeVarList)
 
- Protected Member Functions inherited from pyfortool.applications.Applications
 _mnh_expand_var (self)
 

Protected Attributes

 _filename
 
 _originalName
 
 _output
 
 _parserOptions
 
- Protected Attributes inherited from pyfortool.scope.PYFTscope
 _mainScope
 
 _path
 
 _parentScope
 
 _cacheParent
 
- Protected Attributes inherited from pyfortool.scope.ElementView
 _excludeContains
 
 _xml
 
 _virtual
 
- Protected Attributes inherited from pyfortool.variables.Variables
 _varList
 
 _excludeContains
 

Additional Inherited Members

- Static Public Member Functions inherited from pyfortool.scope.PYFTscope
 normalizeScope (scopePath)
 
- Static Public Member Functions inherited from pyfortool.variables.Variables
 varSpec2stmt (varSpec, implicitDeclaration=False)
 
- Static Public Member Functions inherited from pyfortool.statements.Statements
 createDoConstruct (loopVariables, indent=0, concurrent=False)
 
 insertInList (pos, item, parent)
 
- Static Protected Member Functions inherited from pyfortool.scope.PYFTscope
 _getNodeName (node)
 

Detailed Description

Main class for FORTRAN file manipulation.

PYFT extends PYFTscope with file-level operations (read/write) and
integrates with the fxtran parser for FORTRAN source code analysis.

Class Attributes
----------------
DEFAULT_FXTRAN_OPTIONS : list
    Default options for fxtran parser: ['-construct-tag', '-no-include',
    '-no-cpp', '-line-length', '9999']
MANDATORY_FXTRAN_OPTIONS : list
    Required options: ['-construct-tag']

Examples
--------
Basic usage:
>>> pft = PYFT('myfile.F90')
>>> pft.upperCase()
>>> pft.write()

Using context manager:
>>> with PYFT('myfile.F90', output='output.F90') as pft:
...     pft.removeComments()
...     pft.indent()

Parallel processing:
>>> tree = Tree(['/path/to/src'])
>>> PYFT.setParallel(tree)

Definition at line 113 of file pyfortool.py.

Constructor & Destructor Documentation

◆ __init__()

pyfortool.pyfortool.PYFT.__init__ (   self,
  filename,
  output = None,
  parserOptions = None,
  verbosity = None,
  wrapH = False,
  tree = None,
  enableCache = False 
)
Initialize a PYFT instance from a FORTRAN source file.

Parameters
----------
filename : str
    Path to the input FORTRAN file.
output : str, optional
    Path for output file. If None, overwrites the input file.
parserOptions : list, optional
    Options for the fxtran parser. See DEFAULT_FXTRAN_OPTIONS.
verbosity : str or int, optional
    Logging level (e.g., 'DEBUG', 'INFO', 'WARNING').
wrapH : bool, optional
    If True, wrap .h file content in a MODULE to enable parsing
    as free-form FORTRAN.
tree : Tree, optional
    Tree instance for cross-file analysis. If None, creates a new Tree.
enableCache : bool, optional
    If True, cache parent nodes for faster traversal.

Raises
------
PYFTError
    If Python version < 3.8 or file does not exist.

Examples
--------
>>> pft = PYFT('myfile.F90')
>>> pft = PYFT('myfile.F90', output='newfile.F90')
>>> pft = PYFT('code.h', wrapH=True)

Reimplemented from pyfortool.scope.PYFTscope.

Definition at line 151 of file pyfortool.py.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ __enter__()

pyfortool.pyfortool.PYFT.__enter__ (   self)
Enter context manager.

Returns
-------
PYFT
    Self reference for use in with statement.

Definition at line 284 of file pyfortool.py.

◆ __exit__()

pyfortool.pyfortool.PYFT.__exit__ (   self,
  excType,
  excVal,
  excTb 
)
Exit context manager and close file.

Definition at line 295 of file pyfortool.py.

Here is the call graph for this function:

◆ _rename()

pyfortool.pyfortool.PYFT._rename (   self,
  mod 
)
protected
Apply a transformation function to the file extension.

Parameters
----------
mod : callable
    Function to apply to file extension (e.g., str.upper, str.lower).

Definition at line 357 of file pyfortool.py.

Here is the caller graph for this function:

◆ close()

pyfortool.pyfortool.PYFT.close (   self)
Close the FORTRAN file and release resources.

Prints debug statistics and releases file locks.
Automatically called when exiting context manager.

Definition at line 301 of file pyfortool.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fortran()

pyfortool.pyfortool.PYFT.fortran (   self)
Get the FORTRAN source code representation.

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

Definition at line 324 of file pyfortool.py.

Here is the caller graph for this function:

◆ lockFile()

pyfortool.pyfortool.PYFT.lockFile (   cls,
  filename 
)
Acquire file lock for parallel processing.

Parameters
----------
filename : str
    Path to the file to lock.

Definition at line 247 of file pyfortool.py.

Here is the caller graph for this function:

◆ renameLower()

pyfortool.pyfortool.PYFT.renameLower (   self)
Set output file extension to lowercase.

Examples
--------
>>> pft = PYFT('file.F90')
>>> pft.renameLower()  # Output will be file.f90

Definition at line 346 of file pyfortool.py.

Here is the call graph for this function:

◆ renameUpper()

pyfortool.pyfortool.PYFT.renameUpper (   self)
Set output file extension to uppercase.

Examples
--------
>>> pft = PYFT('file.F90')
>>> pft.renameUpper()  # Output will be file.F90

Definition at line 335 of file pyfortool.py.

Here is the call graph for this function:

◆ setParallel()

pyfortool.pyfortool.PYFT.setParallel (   cls,
  tree,
  clsLock = None,
  clsRLock = None 
)
Configure PYFT for parallel processing.

Must be called before creating PYFT instances for parallel execution.
Sets up shared tree and file locking mechanisms.

Parameters
----------
tree : Tree
    Tree object shared among all processes.
clsLock : type, optional
    Lock class to use. Defaults to multiprocessing.Lock.
clsRLock : type, optional
    Recursive lock class. Defaults to multiprocessing.RLock.

Examples
--------
>>> tree = Tree(['/path/to/src'], descTreeFile='tree.json')
>>> PYFT.setParallel(tree)
>>> # Now create PYFT instances in parallel processes

Definition at line 215 of file pyfortool.py.

◆ unlockFile()

pyfortool.pyfortool.PYFT.unlockFile (   cls,
  filename,
  silence = False 
)
Release file lock for parallel processing.

Parameters
----------
filename : str
    Path to the file to unlock.
silence : bool, optional
    If True, suppress ValueError when file is not locked.

Definition at line 263 of file pyfortool.py.

Here is the caller graph for this function:

◆ write()

pyfortool.pyfortool.PYFT.write (   self)
Write the transformed FORTRAN source to file.

Writes the current state of the code tree as FORTRAN source
to the output file (or overwrites input if no output specified).

Definition at line 374 of file pyfortool.py.

Here is the call graph for this function:

◆ writeXML()

pyfortool.pyfortool.PYFT.writeXML (   self,
  filename 
)
Write the internal XML representation to a file.

Parameters
----------
filename : str
    Path for the output XML file.

Examples
--------
>>> pft = PYFT('input.F90')
>>> pft.writeXML('output.xml')

Definition at line 392 of file pyfortool.py.

Here is the call graph for this function:

◆ xml()

pyfortool.pyfortool.PYFT.xml (   self)
Get the XML representation of the parsed code.

Returns
-------
str
    XML string representation of the FORTRAN source.

Definition at line 312 of file pyfortool.py.

Here is the caller graph for this function:

Member Data Documentation

◆ _filename

pyfortool.pyfortool.PYFT._filename
protected

Definition at line 190 of file pyfortool.py.

◆ _originalName

pyfortool.pyfortool.PYFT._originalName
protected

Definition at line 191 of file pyfortool.py.

◆ _output

pyfortool.pyfortool.PYFT._output
protected

Definition at line 193 of file pyfortool.py.

◆ _parserOptions

pyfortool.pyfortool.PYFT._parserOptions
protected

Definition at line 199 of file pyfortool.py.

◆ DEFAULT_FXTRAN_OPTIONS

list pyfortool.pyfortool.PYFT.DEFAULT_FXTRAN_OPTIONS = ['-construct-tag', '-no-include', '-no-cpp', '-line-length', '9999']
static

Definition at line 144 of file pyfortool.py.

◆ fortran

pyfortool.pyfortool.PYFT.fortran

Definition at line 383 of file pyfortool.py.

◆ MANDATORY_FXTRAN_OPTIONS

list pyfortool.pyfortool.PYFT.MANDATORY_FXTRAN_OPTIONS = ['-construct-tag']
static

Definition at line 145 of file pyfortool.py.

◆ NO_PARALLEL_LOCK

pyfortool.pyfortool.PYFT.NO_PARALLEL_LOCK = None
static

Definition at line 147 of file pyfortool.py.

◆ PARALLEL_FILE_LOCKS

pyfortool.pyfortool.PYFT.PARALLEL_FILE_LOCKS = None
static

Definition at line 148 of file pyfortool.py.

◆ SHARED_TREE

pyfortool.pyfortool.PYFT.SHARED_TREE = None
static

Definition at line 146 of file pyfortool.py.

◆ xml

pyfortool.pyfortool.PYFT.xml

Definition at line 407 of file pyfortool.py.


The documentation for this class was generated from the following file: